Re: [OMPI users] MPI and C++ - now Send and Receive of Classes and STL containers
Thank you very much John, the explanation of &v[0], was the kind of think that I was looking for, thank you very much. This kind of approach solves my problems. Le 09-07-05 à 22:20, John Phillips a écrit : Luis Vitorio Cargnini wrote: Hi, So, after some explanation I start to use the bindings of C inside my C++ code, then comme my new doubt: How to send a object through Send and Recv of MPI ? Because the types are CHAR, int, double, long double, you got. Someone have any suggestion ? Thanks. Vitorio. Vitorio, If you are sending collections of built in data types (ints, doubles, that sort of thing), then it may be easy, and it isn't awful. You want the data in a single stretch of continuous memory. If you are using an STL vector, this is already true. If you are using some other container, then no guarantees are provided for whether the memory is continuous. Imagine you are using a vector, and you know the number of entries in that vector. You want to send that vector to processor 2 on the world communicator with tag 0. Then, the code snippet would be; std::vector v; ... code that fills v with something ... int send_error; send_error = MPI_Send(&v[0], v.size(), MPI_DOUBLE, 2, 0, MPI_COMM_WORLD); The &v[0] part provides a pointer to the first member of the array that holds the data for the vector. If you know how long it will be, you could use that constant instead of using the v.size() function. Knowing the length also simplifies the send, since the remote process also knows the length and doesn't need a separate send to provide that information. It is also possible to provide a pointer to the start of storage for the character array that makes up a string. Both of these legacy friendly interfaces are part of the standard, and should be available on any reasonable implementation of the STL. If you are using a container that is not held in continuous memory, and the data is all of a single built in data type, then you need to first serialize the data into a block of continuous memory before sending it. (If the data block is large, then you may actually have to divide it into pieces and send them separately.) If the data is not a block of all a single built in type, (It may include several built in types, or it may be a custom data class with complex internal structure, for example.) then the serialization problem gets harder. In this case, look at the MPI provided facilities for dealing with complex data types and compare to the boost provided facilities. There is an initial learning curve for the boost facilities, but in the long run it may provide a substantial development time savings if you need to transmit and receive several complex types. In most cases, the run time cost is small for using the boost facilities. (according to the tests run during library development and documented with the library) John Phillips ___ users mailing list us...@open-mpi.org http://www.open-mpi.org/mailman/listinfo.cgi/users smime.p7s Description: S/MIME cryptographic signature PGP.sig Description: Ceci est une signature électronique PGP
Re: [OMPI users] MPI and C++ - now Send and Receive of Classes and STL containers
Luis Vitorio Cargnini wrote: Hi, So, after some explanation I start to use the bindings of C inside my C++ code, then comme my new doubt: How to send a object through Send and Recv of MPI ? Because the types are CHAR, int, double, long double, you got. Someone have any suggestion ? Thanks. Vitorio. Vitorio, If you are sending collections of built in data types (ints, doubles, that sort of thing), then it may be easy, and it isn't awful. You want the data in a single stretch of continuous memory. If you are using an STL vector, this is already true. If you are using some other container, then no guarantees are provided for whether the memory is continuous. Imagine you are using a vector, and you know the number of entries in that vector. You want to send that vector to processor 2 on the world communicator with tag 0. Then, the code snippet would be; std::vector v; ... code that fills v with something ... int send_error; send_error = MPI_Send(&v[0], v.size(), MPI_DOUBLE, 2, 0, MPI_COMM_WORLD); The &v[0] part provides a pointer to the first member of the array that holds the data for the vector. If you know how long it will be, you could use that constant instead of using the v.size() function. Knowing the length also simplifies the send, since the remote process also knows the length and doesn't need a separate send to provide that information. It is also possible to provide a pointer to the start of storage for the character array that makes up a string. Both of these legacy friendly interfaces are part of the standard, and should be available on any reasonable implementation of the STL. If you are using a container that is not held in continuous memory, and the data is all of a single built in data type, then you need to first serialize the data into a block of continuous memory before sending it. (If the data block is large, then you may actually have to divide it into pieces and send them separately.) If the data is not a block of all a single built in type, (It may include several built in types, or it may be a custom data class with complex internal structure, for example.) then the serialization problem gets harder. In this case, look at the MPI provided facilities for dealing with complex data types and compare to the boost provided facilities. There is an initial learning curve for the boost facilities, but in the long run it may provide a substantial development time savings if you need to transmit and receive several complex types. In most cases, the run time cost is small for using the boost facilities. (according to the tests run during library development and documented with the library) John Phillips
Re: [OMPI users] MPI and C++ - now Send and Receive of Classes and STL containers
Regardless of MPI, when sending C++ object over the network you have to serialize their contents. The structures, or classes, have to be coded to a stream of bytes, sent over the network, then recoded into their complex object types by the receiving application. There is no way to send object instances in their original memory format because the object layout is dependent on the machine/memory/compiler (plus a number of other things, I'm simplifying here). boost offers a library to easy the serialization work, but you still have to provide hooks to convert the object to a network format. http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/index.html On Jul 5, 2009, at 8:54 PM, Luis Vitorio Cargnini wrote: Hi, So, after some explanation I start to use the bindings of C inside my C++ code, then comme my new doubt: How to send a object through Send and Recv of MPI ? Because the types are CHAR, int, double, long double, you got. Someone have any suggestion ? Thanks. Vitorio.___ users mailing list us...@open-mpi.org http://www.open-mpi.org/mailman/listinfo.cgi/users
[OMPI users] MPI and C++ - now Send and Receive of Classes and STL containers
Hi, So, after some explanation I start to use the bindings of C inside my C ++ code, then comme my new doubt: How to send a object through Send and Recv of MPI ? Because the types are CHAR, int, double, long double, you got. Someone have any suggestion ? Thanks. Vitorio. smime.p7s Description: S/MIME cryptographic signature PGP.sig Description: Ceci est une signature électronique PGP
Re: [OMPI users] MPI and C++
On Jul 4, 2009, at 9:20 AM, Robert Kubrick wrote: > There is a proposal that has passed one vote so far to deprecate > the C++ bindings in MPI-2.2 (meaning: still have them, but advise > against using them). This opens the door for potentially removing > the C++ bindings in MPI-3.0. Is it the reason for this to boost the 'boost' library adoption? It is one reason, yes. Another reason is that the C++ bindings haven't really delivered what was expected. They were intended to be the baseline for implementing higher-level C++ abstraction (such as boost.MPI). But that didn't really happen -- the C++ bindings don't give enough extra functionality to be useful to a C++ programmer in this regard. This is the key reason that the Forum is voting to deprecate the C++ bindings: people are simply using the C bindings instead of the C++ bindings. That Boost.MPI is implemented on the C bindings instead of the C++ bindings speaks volumes to this effect. :-) -- Jeff Squyres Cisco Systems