1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
#ifndef HPC_MPI_VECTOR_H
#define HPC_MPI_VECTOR_H 1

#include <mpi.h>
#include <hpc/matvec/densevector.hpp>
#include <hpc/mpi/fundamental.hpp>

namespace hpc { namespace mpi {

template<typename T, template<typename> typename Vector,
   Require<Dense<Vector<T>>> = true>
MPI_Datatype get_type(const Vector<T>& vector) {
   MPI_Datatype datatype;
   MPI_Type_vector(
      /* count = */ vector.length(),
      /* blocklength = */ 1,
      /* stride = */ vector.inc(),
      /* element type = */ get_type(vector(0)),
      /* newly created type = */ &datatype);
   MPI_Type_commit(&datatype);
   return datatype;
}

} } // namespaces mpi, hpc

#endif // HPC_MPI_VECTOR_H