@@ -126,6 +126,24 @@ void Parallel_Reduce::reduce_pool<double>(double* object, const int n)
126126 return ;
127127}
128128
129+ template <>
130+ void Parallel_Reduce::reduce_pool<int >(int & object)
131+ {
132+ #ifdef __MPI
133+ MPI_Allreduce (MPI_IN_PLACE, &object, 1 , MPI_INT, MPI_SUM, POOL_WORLD);
134+ #endif
135+ return ;
136+ }
137+
138+ template <>
139+ void Parallel_Reduce::reduce_pool<int >(int * object, const int n)
140+ {
141+ #ifdef __MPI
142+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_INT, MPI_SUM, POOL_WORLD);
143+ #endif
144+ return ;
145+ }
146+
129147// (1) the value is same in each pool.
130148// (2) we need to reduce the value from different pool.
131149void Parallel_Reduce::reduce_double_allpool (const int & npool, const int & nproc_in_pool, double & object)
@@ -314,4 +332,95 @@ void Parallel_Reduce::gather_min_double_all(const int& nproc, double& v)
314332 }
315333 }
316334#endif
317- }
335+ }
336+
337+ void Parallel_Reduce::gather_max_int_all (const int & nproc, int & v)
338+ {
339+ #ifdef __MPI
340+ std::vector<int > value (nproc, 0 );
341+ MPI_Allgather (&v, 1 , MPI_INT, value.data (), 1 , MPI_INT, MPI_COMM_WORLD);
342+ for (int i = 0 ; i < nproc; i++)
343+ {
344+ if (v < value[i])
345+ {
346+ v = value[i];
347+ }
348+ }
349+ #endif
350+ }
351+
352+ void Parallel_Reduce::gather_max_int_pool (const int & nproc_in_pool, int & v)
353+ {
354+ #ifdef __MPI
355+ if (nproc_in_pool == 1 )
356+ {
357+ return ;
358+ }
359+ std::vector<int > value (nproc_in_pool, 0 );
360+ MPI_Allgather (&v, 1 , MPI_INT, value.data (), 1 , MPI_INT, POOL_WORLD);
361+ for (int i = 0 ; i < nproc_in_pool; i++)
362+ {
363+ if (v < value[i])
364+ {
365+ v = value[i];
366+ }
367+ }
368+ #endif
369+ }
370+ void Parallel_Reduce::gather_or_bool_all (bool & v)
371+ {
372+ #ifdef __MPI
373+ MPI_Allreduce (MPI_IN_PLACE, &v, 1 , MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD);
374+ #endif
375+ }
376+
377+ void Parallel_Reduce::gather_or_bool_bp (bool & v)
378+ {
379+ #ifdef __MPI
380+ MPI_Allreduce (MPI_IN_PLACE, &v, 1 , MPI_C_BOOL, MPI_LOR, BP_WORLD);
381+ #endif
382+ }
383+
384+ void Parallel_Reduce::reduce_kp (double * object, const int n)
385+ {
386+ #ifdef __MPI
387+ if (KP_WORLD != MPI_COMM_NULL)
388+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_DOUBLE, MPI_SUM, KP_WORLD);
389+ #endif
390+ }
391+
392+ void Parallel_Reduce::reduce_bp (double * object, const int n)
393+ {
394+ #ifdef __MPI
395+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_DOUBLE, MPI_SUM, BP_WORLD);
396+ #endif
397+ }
398+
399+ void Parallel_Reduce::reduce_bgroup (double * object, const int n)
400+ {
401+ #ifdef __MPI
402+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_DOUBLE, MPI_SUM, INT_BGROUP);
403+ #endif
404+ }
405+
406+ void Parallel_Reduce::reduce_kp (int * object, const int n)
407+ {
408+ #ifdef __MPI
409+ if (KP_WORLD != MPI_COMM_NULL)
410+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_INT, MPI_SUM, KP_WORLD);
411+ #endif
412+ }
413+
414+ void Parallel_Reduce::reduce_bp (int * object, const int n)
415+ {
416+ #ifdef __MPI
417+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_INT, MPI_SUM, BP_WORLD);
418+ #endif
419+ }
420+
421+ void Parallel_Reduce::reduce_bgroup (int * object, const int n)
422+ {
423+ #ifdef __MPI
424+ MPI_Allreduce (MPI_IN_PLACE, object, n, MPI_INT, MPI_SUM, INT_BGROUP);
425+ #endif
426+ }
0 commit comments