Boost logo

Boost Users :

Subject: Re: [Boost-users] boost transfer pointers by serialize
From: Jack Bryan (dtustudy68_at_[hidden])
Date: 2010-08-29 12:52:32


Thanks
Is the m_sd a pointer that points to a double variable ?
How to refer to the values pointed by m_sd ?

For example, I transfer myClass from process 1 to process 2 :
In process 1, I declear
myClass{serializable_double m_sd;
serializable_int m_sint;
template<class Archive>void serialize(Archive &ar, const unsigned int version){ar & m_sd & m_sint;; }} myObject;
In process 1 , I use
world.isend(destRank, downStreamTaskTag, myObject);
In process 2, I use
world.recv(sourceRank, downStreamTaskTag, myObjectRecv);
How to refer to the values pointed by m_sd in myClass ?
May I use it in this way ?
*(myObjectRecv.m_sd) ;
If myObjectRecv.m_sd is an address of a primitive variable, the address should be in process 1's memory space.
How does the process 2 can modify the value of the variablepointed by a pointer with address in process 1's memory space ?

I can use the similar way to do it for pointer's pointer ?such as double** ?
Any help is appreciated ?

JACK
Aug. 29 2010

To: boost-users_at_[hidden]
From: ramey_at_[hidden]
Date: Sun, 29 Aug 2010 09:05:01 -0800
Subject: Re: [Boost-users] boost transfer pointers by serialize

Jack Bryan wrote:
> Dear All,
>
>
> I need to transfer some pointers from one process to another process
> on Open MPI cluster.
>
>
> These pointers are members of a class.
>
>
> They are like:
>
>
> class myClass
> {
> double *;
> int *;
> double**;
> }
>
>
> When I use serialize in boost , I got errors:
>
>
> /boost/serialization/access.hpp:118: error: request for member
> âserializeâ in âtâ, which is of non-class type âdoubleâ
 
pointers to primitives are not serializable. The problem is that
serializing pointers
requires tracking to detect and manage duplicates. If tracker were
implemented
for doubles it would automatically track ALL the doubles - probably not what
one would want.
 
But the solution is easy.
 
define your own double like this
 
struct serializable_double {
    double m_d;
    serializable_double(d) : m_d {}
    ...
}
 
The above can be done automatically with
BOOST_SERIALIZATION_STRONGTYPEDEF(serializable_double, double)
 
now you can use
 
class myClass {
    serializable_double m_sd;
    ...
    template<class Archive>
    void serialize(Archive &ar, const unsigned int version){
        ar & m_sd;
    }
};
 
this should work as one expects.
 
Robert Ramey
 
 
 
 
 

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net