Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] Send data structures
From: Ed Peddycoart (EPeddycoart_at_[hidden])
Date: 2010-10-12 12:28:20


The data that I want to send via MPI is in the form of a struct:
 
struct myDataStruct {
   struct subData1 {
      int position[2];
      int length[2];
   };
   struct subData2 {
      float *data1;
      float *data2;
      float *data3;
      float *data4;
   };
   struct subData3 {
      float *data;
   };
};
 
 
At first I thought I could simply send the data as follows:
 
struct myDataStruct data = new myDataStruct;
// allocate and fill in data for sub structs
 
MPI_SEND(data, sizeof(data), MPI_BYTE, 0, 19, MPI_COMM_WORLD);
 
but apparently, for several reasons, that isn't going to work. What is the best way to accomplish this? MPI_PACK/MPI_UNPACK?
 
Would I do something like this?
 
MPI_PACK(data->subData1->position, 2, MPI_INT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_PACK(data->subData1->length, 2, MPI_INT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_PACK(data->subData2->data1, sizeof(data->subDat2->data1), MPI_FLOAT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_PACK(data->subData2->data2, sizeof(data->subDat2->data1), MPI_FLOAT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_PACK(data->subData2->data3, sizeof(data->subDat2->data1), MPI_FLOAT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_PACK(data->subData2->data4, sizeof(data->subDat2->data1), MPI_FLOAT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_PACK(data->subData3->data1, sizeof(data->subDat2->data1), MPI_FLOAT, packBuffer, PACKBUFFER_SIZE, &packSize, MPI_COMM_WORLD);
MPI_Send(packBuffer, packSize, MPI_PACKED, 1, 100, , MPI_COMM_WORLD);
 
Ed