- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
![](/skins/images/D2683F18326913BBA0436CB7114DD569/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page