Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] MPI Template Datatype?
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-08-09 17:02:51


Hi Alexandru,

you can read all about Boost.MPI at:

  http://www.boost.org/doc/libs/1_43_0/doc/html/mpi.html

On Mon, Aug 9, 2010 at 10:27 PM, Alexandru Blidaru <alexsb92_at_[hidden]> wrote:
> I basically have to implement a 4D vector. An additional goal of my project
> is to support char, int, float and double datatypes in the vector.

If your "vector" is fixed-size (i.e., all vectors are comprised of
4 elements), then you can likely dispose of std::vector, use
C-style arrays with templated send/receive calls (that would
be just interfaces to MPI_Send/MPI_Recv)

   // BEWARE: untested code!!!

   template <typename T>
   int send(T* vector, int dest, int tag, MPI_Comm comm) {
       throw std::logic_error("called generic MyVector::send");
   };

   template <typename T>
   int recv(T* vector, int source, int tag, MPI_Comm comm) {
       throw std::logic_error("called generic MyVector::send");
   };

and then you specialize the template for the types you actually use:

  template <>
  int send<double>(int* vector, int dest, int tag, MPI_Comm comm)
  {
    return MPI_Send(vector, 4, MPI_DOUBLE, dest, tag, comm);
  };

  template <>
  int recv<double>(int* vector, int src, int tag, MPI_Comm comm)
  {
    return MPI_Recv(vector, 4, MPI_DOUBLE, dest, tag, comm);
  };

  // etc.

However, let me warn you that it would likely take more time and
effort to write all the template specializations and get them working
than just use Boost.MPI.

Best regards,
Riccardo