On 02/14/2018 11:19 AM, Florian Lindner wrote:
Hello,

I have this example code:

#include <vector>
#include <mpi.h>

int main(int argc, char *argv[])
{
   MPI_Init(&argc, &argv);
   {
     MPI_Request req1, req2;
     std::vector<int> vec = {1, 2, 3};
     int packSize = sizeof(int) * vec.size();

Why don't you use MPI_Pack_size for sizing of packSendBuf here? The way you write it is not guaranteed to work.

     int position = 0;
     std::vector<char> packSendBuf(packSize);
     int vecSize = vec.size();
     MPI_Pack(vec.data(), vec.size(), MPI_INT, packSendBuf.data(), packSize, 
&position, MPI_COMM_WORLD);

     int estimatedPackSize = 0;
     MPI_Pack_size(vec.size(), MPI_INT, MPI_COMM_WORLD, &estimatedPackSize);
     std::cout << "packSize = " << packSize << ", estimatedPackSize = " << 
estimatedPackSize << std::endl;

     MPI_Isend(&vecSize, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &req1);
     MPI_Isend(packSendBuf.data(), position, MPI_PACKED, 0, 0, MPI_COMM_WORLD, 
&req2);
   }

At the above you asynchronously send data which then goes out of scope. That's pretty much guaranteed to not work, have you tried to run your program with valgrind?

[...]
Which gives an MPI_ERR_TRUNCATE even when running on 1 rank only. Background is 
that I want to send multiple differently

Which routine gives MPI_ERR_TRUNCATE?

sized objects, also with more complex types that to not map to MPI_*, for which 
I plan to use MPI_BYTES. I plan to pack
them into one stream and unpack them one after one.

Which elemental type does not map to an MPI datatype? You are aware that for all derived types except pointer components there are ways to build corresponding data types?

I suspect I got somthig with the sizes wrong. The lines

     int estimatedPackSize = 0;
     MPI_Pack_size(vec.size(), MPI_INT, MPI_COMM_WORLD, &estimatedPackSize);
     std::cout << "packSize = " << packSize << ", estimatedPackSize = " << 
estimatedPackSize << std::endl;

Return the same number, that is 12, the packSize from get_cont is also 12.

But see above: a pack size must be computed with MPI_Pack_size.

Regards, Thomas

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
users mailing list
users@lists.open-mpi.org
https://lists.open-mpi.org/mailman/listinfo/users

Reply via email to