80 #ifndef ARRAYUDF_MPI_H
81 #define ARRAYUDF_MPI_H
91 #define MPI_COMM_TYPE MPI_Comm
92 #define AU_WTIME_TYPE double
93 #define AU_WTIME MPI_Wtime()
94 #define MPI_COMM_WORLD_DEFAULT MPI_COMM_WORLD
95 #define MPI_INFO_NULL_DEFAULT MPI_INFO_NULL
96 #define AU_MPI_Datatype MPI_Datatype
97 #define AU_MPI_Op MPI_Op
98 #define MPI_INIT(argc, argv, au_mpi_comm_global, au_mpi_rank_global, au_mpi_size_global) \
100 int mpi_init_flag = 0; \
101 MPI_Initialized(&mpi_init_flag); \
102 if (!mpi_init_flag) \
104 MPI_Init(&argc, &argv); \
106 MPI_Comm_rank(au_mpi_comm_global, &au_mpi_rank_global); \
107 MPI_Comm_size(au_mpi_comm_global, &au_mpi_size_global); \
110 #define MPI_FINALIZE() \
112 int mpi_finalize_flag = 0; \
113 MPI_Finalized(&mpi_finalize_flag); \
114 if (!mpi_finalize_flag) \
120 template <
typename T>
123 if (std::is_same<T, int>::value)
127 else if (std::is_same<T, short>::value)
131 else if (std::is_same<T, long>::value)
135 else if (std::is_same<T, long long>::value)
137 return MPI_LONG_LONG;
139 else if (std::is_same<T, unsigned int>::value)
143 else if (std::is_same<T, unsigned short>::value)
145 return MPI_UNSIGNED_SHORT;
147 else if (std::is_same<T, unsigned long>::value)
149 return MPI_UNSIGNED_LONG;
151 else if (std::is_same<T, unsigned long long>::value)
153 return MPI_UNSIGNED_LONG_LONG;
155 else if (std::is_same<T, float>::value)
159 else if (std::is_same<T, double>::value)
163 else if (std::is_same<T, std::complex<double>>::value)
165 return MPI_CXX_DOUBLE_COMPLEX;
169 AU_EXIT(
"Not supporte MPI data type");
178 std::istringstream reader(opt_str);
223 AU_EXIT(
"Not supported type in MPI_Reduce");
230 #define AU_Reduce(local_buffer_p, reduced_buffer_p, size, type, op, root, comm) \
232 MPI_Reduce(local_buffer_p, reduced_buffer_p, size, type, op, root, comm); \
234 #define AU_Bcast(data_bffer_p, count_p, datatype_p, root_p, comm_p) \
236 MPI_Bcast(data_bffer_p, count_p, datatype_p, root_p, comm_p); \
246 template <
typename T>
249 MPI_Datatype mpi_type = InferMPIType<T>();
250 T value_max, value_min, value_sum;
251 MPI_Allreduce(&local_value, &value_max, 1, mpi_type, MPI_MAX, MPI_COMM_WORLD);
252 MPI_Allreduce(&local_value, &value_min, 1, mpi_type, MPI_MIN, MPI_COMM_WORLD);
253 MPI_Allreduce(&local_value, &value_sum, 1, mpi_type, MPI_SUM, MPI_COMM_WORLD);
255 stats_vector.resize(3);
256 stats_vector[0] = value_max;
257 stats_vector[1] = value_min;
258 stats_vector[2] = value_sum;
262 #define MPI_COMM_TYPE int
263 #define AU_WTIME_TYPE time_t
264 #define AU_WTIME time(NULL)
265 #define MPI_COMM_WORLD_DEFAULT 0
266 #define MPI_INFO_NULL_DEFAULT 0
267 #define AU_MPI_Datatype int
268 #define AU_MPI_Op int
270 #define MPI_INIT(argc, argv, au_mpi_comm_global, au_mpi_rank_global, au_mpi_size_global) \
272 au_mpi_rank_global = 0; \
273 au_mpi_size_global = 1; \
275 #define MPI_FINALIZE() \
286 template <
typename T>
287 inline void MPIReduceStats(
const T local_value, std::vector<T> &stats_vector)
289 stats_vector.resize(3);
290 stats_vector[0] = local_value;
291 stats_vector[1] = local_value;
292 stats_vector[2] = local_value;
295 template <
typename T>
298 AU_EXIT(
"No MPI used to compile wihtout MPI compiled !");
303 AU_EXIT(
"Should not be here wihtout MPI compiled !");
306 #define AU_Reduce(local_buffer_p, reduced_buffer_p, size, type, op, root, comm) \
308 AU_EXIT("Should not be here wihtout MPI compiled !"); \
311 #define AU_Bcast(data_bffer_p, count_p, datatype_p, root_p, comm_p) \
313 AU_EXIT("Should not be here wihtout MPI compiled !"); \
#define AU_MAXLOC
Definition: ft_merge.h:101
#define AU_LOR
Definition: ft_merge.h:96
#define AU_BOR
Definition: ft_merge.h:97
#define AU_BXOR
Definition: ft_merge.h:99
#define AU_BAND
Definition: ft_merge.h:95
#define AU_PROD
Definition: ft_merge.h:93
#define AU_MAX
Definition: ft_merge.h:90
#define AU_LXOR
Definition: ft_merge.h:98
#define AU_SUM
Definition: ft_merge.h:92
#define AU_LAND
Definition: ft_merge.h:94
#define AU_MINLOC
Definition: ft_merge.h:100
#define AU_REPLACE
Definition: ft_merge.h:102
#define AU_MIN
Definition: ft_merge.h:91
int AU_Op
Definition: ft_merge.h:88
MPI_Datatype InferMPIType()
Definition: ft_mpi.h:121
MPI_Op InferMPIMergeOp(std::string &opt_str)
Definition: ft_mpi.h:175
void MPIReduceStats(const T local_value, std::vector< T > &stats_vector)
get max/min/sum of local_value
Definition: ft_mpi.h:247
#define AU_EXIT(info)
Definition: ft_utility_macro.h:147