Newsgroups: comp.parallel.pvm,comp.parallel.mpi
From: gl@mdy.univie.ac.at (Gerald Loeffler)
Subject: Re: Passing C++ objects
Organization: Univ. of Vienna, Inst. for Theoretical Chemistry
Date: 29 Feb 1996 09:31:15 GMT
Message-ID: <4h3rp3$1k3u@ftp.univie.ac.at>

Hi!

(Warning: This is a Theory-only answer, i.e. I haven't done this myself!)

1) Let's start with the simplest case: Your class contains only direct data items
   (i.e. no references or pointers) and methods.
   Then you would have to generate an "MPI derived datatype" (via MPI_TYPE_STRUCT),
   which could be done by a static method of the class.
   Then, include a send() method in your class and a corresponding receive()
   method (and/or a constructor that receives and simultaneously constructs the
   object) and you are done: The sender calls send() - which calls MPI_Send() or
   a corresponding function using the "MPI derived datatype" for this class - and 
   the receiver calls receive() or the constructor - which call MPI_Recv() or 
   a corresponding function using the same "MPI derived datatype".

2) If there are virtual functions in you class, then you can't deduce the
   memory layout of the objects of this class in a compiler-independent
   way. In other words: I can't think of an approach that works if virtual functions
   are present!

3) If your class contains data members that are pointers and/or references:
   You have to define each of the referenced classes in the same way as under
   point 1) above (if they are primitive data types you have to wrap them in
   objects to be able to do that).
   Then: the send() and receive() methods of your primary class have to be defined
   in a way that they first send() and receive() the pointed-to objects and then
   the primary object itself, the pointers and references of which can then be 
   initialized to point to the just-sent objects.
   Please note that in that way the pointed-to objects are not shared by the 
   sender and the receiver, but instead the receiver creates copies of them in 
   its own address space.

	hope that helps,
	good luck,
	gerald

In article <4gdik0$5do@nntp.Stanford.EDU>, tjb <byer@pangea.stanford.edu> writes:
|> The examples for passing data between processes have shown how it is 
|> possible to pass variables and arrays of specific types.  How is this 
|> accomplished when you need to send a object, containing several data types 
|> of which some may be dynamically allocated,  to another process. 
|> 
|> The worst case could be that the object needs the functionallity to send 
|> and recieve its variable/array components such that it could reconstruct 
|> itself.
|> 
|> Any comments or examples ??
|> 
|> Thanks
|> Tom
|> 

-- 
Gerald Loeffler
PhD student in Theoretical Biochemistry

EMail: Gerald.Loeffler@mdy.univie.ac.at
Phone: +43 1 40480 612
Fax:   +43 1 4028525
SMail: University of Vienna
       Institute for Theoretical Chemistry
       Theoretical Biochemistry Group
       Waehringerstrasse 17/Parterre
       A-1090 Wien, Austria


