Most MPI implementations (MPICH, Intel MPI) are defining MPI datatypes
(MPI_INT, MPI_FLOAT etc.) as constants; in OpenMPI, these are practically
pointers to corresponding internal structures (for example MPI_FLOAT is
defined as pointer to mpi_float structure, etc.).  In trying to employ some
C++ templates to automate mapping between C types and MPI datatypes (code
provided below), I've encountered a problem with this, so I'm wondering -
is OpenMPI approach in accordance with MPI standard?

Here is the code I'm trying to use:

// ----------------------------------------------------------------
#include <mpi.h>

#define TYPEMAP_CREATE(NAME) template<typename T> struct NAME ## _typemap;
#define TYPEMAP_ENTRY(NAME, FROM, DATA, TO) template<> struct NAME ##
_typemap<FROM> : register_id<FROM, DATA, TO> { };

template<typename T>
struct marker_type
{
    typedef T type;
};

template<class ValueType, ValueType N>
struct marker_id {
    static ValueType const value = N;
};


template<typename T, class ValueType, ValueType N>
struct register_id : marker_id<ValueType, N>, marker_type<T> {
private:
    friend marker_type<T> marked_id(marker_id<ValueType, N>) {
        return marker_type<T>();
    }
};

TYPEMAP_CREATE(mpi)
TYPEMAP_ENTRY(mpi, float, MPI_Datatype, MPI_FLOAT);
// ----------------------------------------------------------------

When put in a file (say foo.cpp), and compiled (with g++ 4.7.2, through
plain "g++ -c foo.cpp"), following errors are reported:

------------------------------------------------------------------
foo.cpp:27:1: error: ‘ompi_mpi_float’ cannot appear in a constant-expression
foo.cpp:27:1: error: ‘&’ cannot appear in a constant-expression
foo.cpp:27:1: error: a cast to a type other than an integral or enumeration
type cannot appear in a constant-expression
foo.cpp:27:1: error: a cast to a type other than an integral or enumeration
type cannot appear in a constant-expression
foo.cpp:27:1: error: template argument 3 is invalid
------------------------------------------------------------------

Thanks.

Reply via email to