17 #ifndef __deal2__mpi_h 18 #define __deal2__mpi_h 20 #include <deal.II/base/config.h> 23 #if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC) 29 # error "The buildsystem included an insufficient mpi.h header that does not export MPI_SEEK_SET" 37 const int MPI_COMM_SELF = 0;
38 typedef int MPI_Datatype;
42 static const unsigned int UNSIGNED = 0;
43 static const unsigned int LONG_DOUBLE = 0;
44 static const unsigned int LONG_DOUBLE_COMPLEX = 0;
45 static const unsigned int MAX = 0;
46 static const unsigned int MIN = 0;
47 static const unsigned int SUM = 0;
126 std::vector<unsigned int>
128 const std::vector<unsigned int> &destinations);
170 template <
typename T>
172 const MPI_Comm &mpi_communicator);
184 template <
typename T,
unsigned int N>
186 void sum (
const T (&values)[N],
187 const MPI_Comm &mpi_communicator,
199 template <
typename T>
201 void sum (
const std::vector<T> &values,
202 const MPI_Comm &mpi_communicator,
203 std::vector<T> &sums);
225 template <
typename T>
227 const MPI_Comm &mpi_communicator);
239 template <
typename T,
unsigned int N>
241 void max (
const T (&values)[N],
242 const MPI_Comm &mpi_communicator,
254 template <
typename T>
256 void max (
const std::vector<T> &values,
257 const MPI_Comm &mpi_communicator,
258 std::vector<T> &maxima);
269 unsigned int min_index;
270 unsigned int max_index;
295 const MPI_Comm &mpi_communicator);
356 unsigned int max_num_threads);
383 void do_init(
int &argc,
385 unsigned int max_num_threads);
390 #ifdef DEAL_II_WITH_MPI 395 inline MPI_Datatype mpi_type_id (
const int *)
401 inline MPI_Datatype mpi_type_id (
const long int *)
407 inline MPI_Datatype mpi_type_id (
const unsigned int *)
413 inline MPI_Datatype mpi_type_id (
const unsigned long int *)
415 return MPI_UNSIGNED_LONG;
419 inline MPI_Datatype mpi_type_id (
const unsigned long long int *)
421 return MPI_UNSIGNED_LONG_LONG;
425 inline MPI_Datatype mpi_type_id (
const float *)
431 inline MPI_Datatype mpi_type_id (
const double *)
437 inline MPI_Datatype mpi_type_id (
const long double *)
439 return MPI_LONG_DOUBLE;
445 template <
typename T>
448 const MPI_Comm &mpi_communicator)
450 #ifdef DEAL_II_WITH_MPI 452 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&t)),
453 &sum, 1, internal::mpi_type_id(&t), MPI_SUM,
457 (void)mpi_communicator;
463 template <
typename T,
unsigned int N>
465 void sum (
const T (&values)[N],
466 const MPI_Comm &mpi_communicator,
469 #ifdef DEAL_II_WITH_MPI 470 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
471 &sums[0], N, internal::mpi_type_id(values), MPI_SUM,
474 (void)mpi_communicator;
475 for (
unsigned int i=0; i<N; ++i)
481 template <
typename T>
483 void sum (
const std::vector<T> &values,
484 const MPI_Comm &mpi_communicator,
485 std::vector<T> &sums)
487 #ifdef DEAL_II_WITH_MPI 488 sums.resize (values.size());
489 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
490 &sums[0], values.size(), internal::mpi_type_id((T *)0), MPI_SUM,
493 (void)mpi_communicator;
499 template <
typename T>
502 const MPI_Comm &mpi_communicator)
504 #ifdef DEAL_II_WITH_MPI 506 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&t)),
507 &sum, 1, internal::mpi_type_id(&t), MPI_MAX,
511 (void)mpi_communicator;
517 template <
typename T,
unsigned int N>
519 void max (
const T (&values)[N],
520 const MPI_Comm &mpi_communicator,
523 #ifdef DEAL_II_WITH_MPI 524 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
525 &maxima[0], N, internal::mpi_type_id(values), MPI_MAX,
528 (void)mpi_communicator;
529 for (
unsigned int i=0; i<N; ++i)
530 maxima[i] = values[i];
535 template <
typename T>
537 void max (
const std::vector<T> &values,
538 const MPI_Comm &mpi_communicator,
539 std::vector<T> &maxima)
541 #ifdef DEAL_II_WITH_MPI 542 maxima.resize (values.size());
543 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
544 &maxima[0], values.size(), internal::mpi_type_id((T *)0), MPI_MAX,
547 (void)mpi_communicator;
555 DEAL_II_NAMESPACE_CLOSE
std::vector< unsigned int > compute_point_to_point_communication_pattern(const MPI_Comm &mpi_comm, const std::vector< unsigned int > &destinations)
T sum(const T &t, const MPI_Comm &mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
MPI_Comm duplicate_communicator(const MPI_Comm &mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &mpi_communicator)