none
How to transmit an Integer array wrapped in a user-defined class within a MPI message RRS feed

  • Question

  • Here is what I need to do:

    InitMsg is a user-defined subclass of BasicMsg. In the InitMsg class, I need to include an array of integers (the number of integers and their values are determined at runtime when an instance of the InitMsg is created).

    Several processes are involved in the parallel computation. A process P1 needs to create an instance of InitMsg and set the integer array in it, and send this InitMsg to another process P2 using MPI_Bsend. P2 will receive the msg using MPI_Recv. P2 then casts the received msg (a buffer of type MPI_BYTE) into an InitMsg object, and extracts the integer values contained in the array defined in the message.

    The problem is that you can easily send basic data types within a MPI msg as a stream of MPI_BYTE. But how can I send an InitMsg (which has both basic data types like the size of the array, and complex data like the array) to the destination process, while allowing the receiving process to check the type of the received message and cast it to an InitMsg object, and then recover the array in this object.

    I know MPI allows for definition of user-specified data types (such as Create_contiguous, Create_vector, and Create_struct). But can I define such types within a class (i.e. InitMsg), and send an object of this class as a stream of MPI_BYTE?

    Thanks!!!

    Jacky

    Thursday, January 31, 2008 4:43 PM

Answers

  • Dear Jacky

     

    boost.mpi works very well with MPICH; its is an upper C++ layer that abstract some of the MPI issues and simplifies it usage for C++ programers.

     

    If you rather go with the C bindings directly; I suggest defining a struct that describes your data layout; embed it in your C++ object and describe this struct to MPI. when you are about to send this using MPI, reference the struct member in your class.

     

    hope this helps,

    .Erez

    Saturday, February 16, 2008 7:54 PM

All replies

  • This can be done with MPI by defining a user specific data type. but a much better way to do it would be to use the boost.mpi library. You don't loose performance if serialization is not neccessary.

     

    taks a look at

    http://www.osl.iu.edu/~dgregor/boost.mpi/doc/

     

    thanks,

    .Erez

    Saturday, February 2, 2008 7:50 PM
  • Hi,

    Thanks for your reply.

    However, I have to use MPICH (see http://www-unix.mcs.anl.gov/mpi/mpich1/download.html) as the communication middleware. My project is written in C++ and targets Linux clusters.

    Could you please comment on how to do the job using standard MPI library (e.g., libmpich.a in MPICH)?

    Thanks!

    Jacky
    Sunday, February 3, 2008 11:33 PM
  • Dear Jacky

     

    boost.mpi works very well with MPICH; its is an upper C++ layer that abstract some of the MPI issues and simplifies it usage for C++ programers.

     

    If you rather go with the C bindings directly; I suggest defining a struct that describes your data layout; embed it in your C++ object and describe this struct to MPI. when you are about to send this using MPI, reference the struct member in your class.

     

    hope this helps,

    .Erez

    Saturday, February 16, 2008 7:54 PM