Open MPI logo

Open MPI User's Mailing List Archives

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

Subject: Re: [OMPI users] Send data structures
From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2010-10-12 13:15:34


Have a look at MPI_Type_create_struct().

     http://www.open-mpi.org/doc/v1.5/man3/MPI_Type_create_struct.3.php

On Oct 12, 2010, at 11:28 AM, Ed Peddycoart wrote:

> 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
>
>
> _______________________________________________
> users mailing list
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users

-- 
Jeff Squyres
jsquyres_at_[hidden]
For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/