boost transfer pointers by serialize
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â Any help is appreciated. JACK Aug. 29 2010
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
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@lists.boost.org From: ramey@rrsd.com 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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Jack Bryan wrote:
Thanks
Is the m_sd a pointer that points to a double variable ?
no
How to refer to the values pointed by m_sd ?
if you use BOOST_SERIALIZE_STRONG_TYPEDEF then the serializable_double can be handled exactly like a double. (note: this is the way it is for integer types. As I write this I'm not sure it applies to floating point types but I think it does. think of strong typedef as the same as a typedef except that it actually creates a new identifiable type.
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;
so far so good.
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 ?
just like you would doubles.
May I use it in this way ?
*(myObjectRecv.m_sd) ;
you could.
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 variable pointed by a pointer with address in process 1's memory space ?
no it will be in the address space of the process that does the de-serialization.
I can use the similar way to do it for pointer's pointer ? such as double** ?
unfortunately, pointers to pointers are not currently serializable. There is a track item on this. This is an oversight in the implementation which is non-trivial to fix.
Any help is appreciated ?
it is? Robert Ramey
Thanks
Is the m_sd a
thanks, In this way, in myClass, I replace " double* myDouble" with " serializable_double myDouble". Can the " myDouble " be accessed as the original " double* " ? I need to assign some values to myDouble at first and then use boost MPI to transfer it to another process. For example, if I use double* double myVar =2.1 ;double* myDouble = &myVar ; if I use serializable_double , I need to do it in this way : double myVar = 2.1 ;serializable_double myDouble = &myVar ; If I am wrong, please correct me. The following is the data structure that I want to transfer from one process to another process : ------------------------------------------------------------------------------- typedef struct { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; }individual; typedef struct { individual *ind;}population;----------------------------------------------------------------------------------- I need to trasfer population from process 1 to process 2 such that the data members in population->ind can be operated in process 2. Then, the process 2 returns the population->ind with new results to process 1. Becasue the population and individual data structure are also used by other programs in the same project, I do not want to change double8 to serializable_double inside them. May I use assignment to do it ? for example, myClass{ int rank; double constr_violation; serializable_double xreal; serializable_int *gene; serializable_double xbin; serializable_double obj; serializable_double constr; double crowd_dist;} myObject; myObject.xreal = (population->ind)->xreal; Any help is appreciated. thanks Jack Aug. 29 2010 To: boost-users@lists.boost.org From: ramey@rrsd.com Date: Sun, 29 Aug 2010 10:27:57 -0800 Subject: Re: [Boost-users] boost transfer pointers by serialize Jack Bryan wrote: pointer that points to a double variable ? no
How to refer to the values pointed by m_sd
? if you use BOOST_SERIALIZE_STRONG_TYPEDEF then the serializable_double can be handled exactly like a double. (note: this is the way it is for integer types. As I write this I'm not sure it applies to floating point types but I think it does. think of strong typedef as the same as a typedef except that it actually creates a new identifiable type.
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
Archive>
void serialize(Archive &ar, const unsigned int version){ ar & m_sd & m_sint;; } } myObject;
so far so good.
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 ? just like you would doubles.
May I use it in this way ?
*(myObjectRecv.m_sd) ;
you could.
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
variable
pointed by a pointer with address in process 1's memory space ?
no it will be in the address space of the process that does the de-serialization.
I can
use the similar way to do it for pointer's pointer ?
such as double** ?
unfortunately, pointers to pointers are not currently serializable. There is a track item on this. This is an oversight in the implementation which is non-trivial to fix.
Any help is appreciated ?
it is? Robert Ramey _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hmmm - have you read the documenaton on BOOST_SERIALIZATION_STRONGTYPEDEF? If it's not clear let me know. I don't remember much about other than no one has ever complained about it. Robert Ramey Jack Bryan wrote:
thanks,
In this way, in myClass, I replace " double* myDouble" with " serializable_double myDouble". Can the " myDouble " be accessed as the original " double* " ?
I need to assign some values to myDouble at first and then use boost MPI to transfer it to another process.
For example,
if I use double*
double myVar =2.1 ; double* myDouble = &myVar ;
if I use serializable_double , I need to do it in this way :
double myVar = 2.1 ; serializable_double myDouble = &myVar ;
If I am wrong, please correct me.
The following is the data structure that I want to transfer from one process to another process : -------------------------------------------------------------------------------
typedef struct { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist;
} individual;
typedef struct { individual *ind; } population; -----------------------------------------------------------------------------------
I need to trasfer population from process 1 to process 2 such that the data members in population->ind can be operated in process 2.
Then, the process 2 returns the population->ind with new results to process 1.
Becasue the population and individual data structure are also used by other programs in the same project, I do not want to change double8 to serializable_double inside them.
May I use assignment to do it ?
for example,
myClass {
int rank; double constr_violation; serializable_double xreal; serializable_int *gene; serializable_double xbin; serializable_double obj; serializable_double constr; double crowd_dist; } myObject;
myObject.xreal = (population->ind)->xreal;
Any help is appreciated.
thanks
Jack
Aug. 29 2010
To: boost-users@lists.boost.org From: ramey@rrsd.com Date: Sun, 29 Aug 2010 10:27:57 -0800 Subject: Re: [Boost-users] boost transfer pointers by serialize
Jack Bryan wrote:
Thanks
Is the m_sd a pointer that points to a double variable ?
no
How to refer to the values pointed by m_sd ?
if you use BOOST_SERIALIZE_STRONG_TYPEDEF then the serializable_double can be handled exactly like a double. (note: this is the way it is for integer types. As I write this I'm not sure it applies to floating point types but I think it does.
think of strong typedef as the same as a typedef except that it actually creates a new identifiable type.
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;
so far so good.
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 ?
just like you would doubles.
May I use it in this way ?
*(myObjectRecv.m_sd) ;
you could.
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 variable pointed by a pointer with address in process 1's memory space ?
no it will be in the address space of the process that does the de-serialization.
I can use the similar way to do it for pointer's pointer ? such as double** ?
unfortunately, pointers to pointers are not currently serializable. There is a track item on this. This is an oversight in the implementation which is non-trivial to fix.
Any help is appreciated ?
it is?
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Jack Bryan
-
Robert Ramey