Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.

MPI_Send

prabhugobi
Beginner
650 Views

how to send a structure with a pointer variable as one of its members..

for eg, i've to send the following structure

struct sample

{

int a;

char *b;

struct sample *l,*r;

}s;

can u pls tell me how to send the atructure like one above,in MPI.

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
650 Views
Quoting - prabhugobi

how to send a structure with a pointer variable as one of its members..

for eg, i've to send the following structure

struct sample

{

int a;

char *b;

struct sample *l,*r;

}s;

can u pls tell me how to send the atructure like one above,in MPI.


On MPI the recepient, unless sending to self, runs as a different process whether it be on the same computer or different computer, and therefore the pointers would be to data located within the virtual address of one process (presumably the sending process). That address, though may be a valid address on the receiving process, would not point to the data contained within the sending process (unless the processes had sharable memory and the sharable memory appears at the same virtual address within both (all) processes sharaing the memory). This pointer would be useless in the receiving process. However, you could save the address (pointer) then return the pointer to originator for its use.

If you intend to use the data pointed to by the pointers within the struct, then you will have to send the data itself to a proceedure which re-constitutes the struct on the recipient's system using the sent data. i.e. The remote system will have a struct s containing pointers to local copies of the senders struct s data.

Jim Dempsey

0 Kudos
prabhugobi
Beginner
650 Views


On MPI the recepient, unless sending to self, runs as a different process whether it be on the same computer or different computer, and therefore the pointers would be to data located within the virtual address of one process (presumably the sending process). That address, though may be a valid address on the receiving process, would not point to the data contained within the sending process (unless the processes had sharable memory and the sharable memory appears at the same virtual address within both (all) processes sharaing the memory). This pointer would be useless in the receiving process. However, you could save the address (pointer) then return the pointer to originator for its use.

If you intend to use the data pointed to by the pointers within the struct, then you will have to send the data itself to a proceedure which re-constitutes the struct on the recipient's system using the sent data. i.e. The remote system will have a struct s containing pointers to local copies of the senders struct s data.

Jim Dempsey

thank u for the reply..

but,i need to know the syntax for sending the above structure..

for eg, shall i use MPI_Pack or MPI_Type_struct, things like these... what shall i use ?

if possible pls mention the syntax to send the above structure.

with regards,

PRABHU

0 Kudos
Andres_M_Intel4
Employee
650 Views

I would recommend you to learn the serialization concept (http://en.wikipedia.org/wiki/Serialization), it will be useful when programming on most low level languages (and many high level ones).

Before sending information through the network you need to 'serialize' your data types, not only when using MPI but also when using other remote IPC mechanisms (as the usual sockets).

C data types having pointers can not be transferred as they will end up pointing to invalid memory addresses.
The easiest approach is to avoid using pointers on your data structures, if it is not your case you will need to implement an intermediate representation to use with the MPI calls.

Hope it helps,

-- Andres
0 Kudos
Reply