18 typedef std::map<std::type_info const*, MPI_Op, type_info_compare> stored_map_type;
25 MPI_Finalized(&is_finalized);
29 for (stored_map_type::iterator it=map.begin(); it != map.end(); ++it)
31 MPI_Op_free(&(it->second));
39 MPI_Op
get(
const std::type_info* t)
41 stored_map_type::iterator pos = map.find(t);
48 void set(
const std::type_info* t, MPI_Op datatype)
51 if (map.find(t) != map.end()) map.erase(t);
52 map.insert(std::make_pair(t, datatype));
67 template <
typename Op,
typename T,
typename Enable =
void>
70 static void funcmpi(
void * invec,
void * inoutvec,
int * len, MPI_Datatype *datatype)
73 T * pinvec =
static_cast<T*
>(invec);
74 T * pinoutvec =
static_cast<T*
>(inoutvec);
75 for (
int i = 0; i < *len; i++)
77 pinoutvec[i] = myop(pinvec[i], pinoutvec[i]);
82 std::type_info
const* t = &
typeid(Op);
83 MPI_Op foundop = mpioc.
get(t);
85 if (foundop == MPI_OP_NULL)
87 MPI_Op_create(funcmpi,
false, &foundop);
90 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
92 std::cout <<
"Creating a new MPI Op for " << t->name() << std::endl;
94 mpioc.
set(t, foundop);
100 template<
typename T>
struct MPIOp<
maximum<T>,T,typename
std::
enable_if<std::is_pod<T>::value, void>::type > {
static MPI_Op
op() {
return MPI_MAX; } };
101 template<
typename T>
struct MPIOp<
minimum<T>,T,typename
std::
enable_if<std::is_pod<T>::value, void>::type > {
static MPI_Op
op() {
return MPI_MIN; } };
102 template<
typename T>
struct MPIOp<
std::plus<T>,T,typename std::enable_if<std::is_pod<T>::value, void>::type > {
static MPI_Op
op() {
return MPI_SUM; } };
103 template<
typename T>
struct MPIOp<
std::multiplies<T>,T,typename std::enable_if<std::is_pod<T>::value, void>::type > {
static MPI_Op
op() {
return MPI_PROD; } };
104 template<
typename T>
struct MPIOp<
std::logical_and<T>,T,typename std::enable_if<std::is_pod<T>::value, void>::type > {
static MPI_Op
op() {
return MPI_LAND; } };
105 template<
typename T>
struct MPIOp<
std::logical_or<T>,T,typename std::enable_if<std::is_pod<T>::value, void>::type > {
static MPI_Op
op() {
return MPI_LOR; } };
Compute the minimum of two values.
Compute the bitwise AND of two integral values.
Compute the maximum of two values.
void set(const std::type_info *t, MPI_Op datatype)
MPI_Op get(const std::type_info *t)
Compute the bitwise OR of two integral values.
Compute the bitwise exclusive OR of two integral values.
Compute the logical exclusive OR of two integral values.
static void funcmpi(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)