MPI_IallreduceW.hpp 5.3 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef MPI_IALLREDUCEW_HPP
#define MPI_IALLREDUCEW_HPP

#include <mpi.h>

/*! \brief Set of wrapping classing for MPI_Iallreduce
 *
 * The purpose of these classes is to correctly choose the right call based on the type we want to reduce
 *
 */


/*! \brief General reduction
 *
 * \tparam any type
 *
 */

template<typename T> class MPI_IallreduceW
{
public:
incardon's avatar
incardon committed
22
	static inline void reduce(T & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
23 24 25 26 27 28 29 30 31 32 33 34
	{
		std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " cannot recognize " << typeid(T).name() << "\n";
	}
};


/*! \brief specialization for integer
 *
 */
template<> class MPI_IallreduceW<int>
{
public:
incardon's avatar
incardon committed
35
	static inline void reduce(int & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
36
	{
incardon's avatar
incardon committed
37
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_INT, op, ext_comm,&req));
incardon's avatar
incardon committed
38 39 40 41 42 43 44 45 46
	}
};

/*! \brief specialization for unsigned integer
 *
 */
template<> class MPI_IallreduceW<unsigned int>
{
public:
incardon's avatar
incardon committed
47
	static inline void reduce(unsigned int & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
48
	{
incardon's avatar
incardon committed
49
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED, op, ext_comm,&req));
incardon's avatar
incardon committed
50 51 52 53 54 55 56 57 58
	}
};

/*! \brief specialization for short
 *
 */
template<> class MPI_IallreduceW<short>
{
public:
incardon's avatar
incardon committed
59
	static inline void reduce(short & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
60
	{
incardon's avatar
incardon committed
61
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_SHORT, op, ext_comm,&req));
incardon's avatar
incardon committed
62 63 64 65 66 67 68 69 70
	}
};

/*! \brief specialization for short
 *
 */
template<> class MPI_IallreduceW<unsigned short>
{
public:
incardon's avatar
incardon committed
71
	static inline void reduce(unsigned short & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
72
	{
incardon's avatar
incardon committed
73
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED_SHORT, op, ext_comm,&req));
incardon's avatar
incardon committed
74 75 76 77 78 79 80 81 82
	}
};

/*! \brief specialization for char
 *
 */
template<> class MPI_IallreduceW<char>
{
public:
incardon's avatar
incardon committed
83
	static inline void reduce(char & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
84
	{
incardon's avatar
incardon committed
85
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_CHAR, op, ext_comm,&req));
incardon's avatar
incardon committed
86 87 88 89 90 91 92 93 94
	}
};

/*! \brief specialization for char
 *
 */
template<> class MPI_IallreduceW<unsigned char>
{
public:
incardon's avatar
incardon committed
95
	static inline void reduce(unsigned char & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
96
	{
incardon's avatar
incardon committed
97
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED_CHAR, op, ext_comm,&req));
incardon's avatar
incardon committed
98 99 100 101 102 103 104 105 106
	}
};

/*! \brief specialization for size_t
 *
 */
template<> class MPI_IallreduceW<size_t>
{
public:
incardon's avatar
incardon committed
107
	static inline void reduce(size_t & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
108
	{
incardon's avatar
incardon committed
109
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED_LONG, op, ext_comm,&req));
incardon's avatar
incardon committed
110 111 112 113 114 115 116 117 118
	}
};

/*! \brief specialization for size_t
 *
 */
template<> class MPI_IallreduceW<long int>
{
public:
incardon's avatar
incardon committed
119
	static inline void reduce(long int & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
120
	{
incardon's avatar
incardon committed
121
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_LONG, op, ext_comm,&req));
incardon's avatar
incardon committed
122 123 124 125 126 127 128 129 130
	}
};

/*! \brief specialization for float
 *
 */
template<> class MPI_IallreduceW<float>
{
public:
incardon's avatar
incardon committed
131
	static inline void reduce(float & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
132
	{
incardon's avatar
incardon committed
133
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_FLOAT, op, ext_comm,&req));
incardon's avatar
incardon committed
134 135 136 137 138 139 140 141 142
	}
};

/*! \brief specialization for double
 *
 */
template<> class MPI_IallreduceW<double>
{
public:
incardon's avatar
incardon committed
143
	static inline void reduce(double & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
144
	{
incardon's avatar
incardon committed
145
		MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_DOUBLE, op, ext_comm,&req));
incardon's avatar
incardon committed
146 147 148 149 150 151 152 153 154 155 156
	}
};

////////////////// Specialization for vectors ///////////////

/*! \brief specialization for vector integer
 *
 */
/*template<> class MPI_IallreduceW<openfpm::vector<int>>
{
public:
incardon's avatar
incardon committed
157
	static inline void reduce(openfpm::vector<int> & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
158
	{
incardon's avatar
incardon committed
159
		MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_INT, op, ext_comm,&req);
incardon's avatar
incardon committed
160 161 162 163 164 165 166 167 168
	}
};*/

/*! \brief specialization for vector short
 *
 */
/*template<> class MPI_IallreduceW<openfpm::vector<short>>
{
public:
incardon's avatar
incardon committed
169
	static inline void reduce(openfpm::vector<short> & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
170
	{
incardon's avatar
incardon committed
171
		MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_SHORT, op, ext_comm,&req);
incardon's avatar
incardon committed
172 173 174 175 176 177 178 179 180
	}
};*/

/*! \brief specialization for vector char
 *
 */
/*template<> class MPI_IallreduceW<openfpm::vector<char>>
{
public:
incardon's avatar
incardon committed
181
	static inline void reduce(openfpm::vector<char> & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
182
	{
incardon's avatar
incardon committed
183
		MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_CHAR, op, ext_comm,&req);
incardon's avatar
incardon committed
184 185 186 187 188 189 190 191 192
	}
};*/

/*! \brief specialization for vector size_t
 *
 */
/*template<> class MPI_IallreduceW<openfpm::vector<size_t>>
{
public:
incardon's avatar
incardon committed
193
	static inline void reduce(openfpm::vector<size_t> & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
194
	{
incardon's avatar
incardon committed
195
		MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_UNSIGNED_LONG, op, ext_comm,&req);
incardon's avatar
incardon committed
196 197 198 199 200 201 202 203 204
	}
};*/

/*! \brief specialization for vector float
 *
 */
/*template<> class MPI_IallreduceW<openfpm::vector<float>>
{
public:
incardon's avatar
incardon committed
205
	static inline void reduce(openfpm::vector<float> & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
206
	{
incardon's avatar
incardon committed
207
		MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_FLOAT, op, ext_comm,&req);
incardon's avatar
incardon committed
208 209 210 211 212 213 214 215 216 217
	}
};*/

/*! \brief specialization for vector double
 *
 */

/*template<> class MPI_IallreduceW<openfpm::vector<double>>
{
public:
incardon's avatar
incardon committed
218
	static inline void reduce(openfpm::vector<double> & buf,MPI_Op op, MPI_Request & req, MPI_Comm ext_comm)
incardon's avatar
incardon committed
219
	{
incardon's avatar
incardon committed
220
		MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_DOUBLE, op, ext_comm,&req);
incardon's avatar
incardon committed
221 222 223 224
	}
};*/

#endif