19 #include <deal.II/base/config.h> 22 #if !defined(DEAL_II_WITH_MPI) && !defined(DEAL_II_WITH_PETSC) 27 const int MPI_COMM_SELF = 0;
28 typedef int MPI_Datatype;
32 static const unsigned int UNSIGNED = 0;
33 static const unsigned int LONG_DOUBLE = 0;
34 static const unsigned int LONG_DOUBLE_COMPLEX = 0;
35 static const unsigned int MAX = 0;
36 static const unsigned int MIN = 0;
37 static const unsigned int SUM = 0;
39 static const int MPI_MIN = 0;
40 static const int MPI_MAX = 0;
41 static const int MPI_SUM = 0;
44 DEAL_II_NAMESPACE_OPEN
48 template <
int rank,
int dim,
typename Number>
class Tensor;
52 template <
typename Number>
class Vector;
104 std::vector<unsigned int>
106 const std::vector<unsigned int> &destinations);
142 template <
typename T>
144 const MPI_Comm &mpi_communicator);
154 template <
typename T,
unsigned int N>
156 void sum (
const T (&values)[N],
157 const MPI_Comm &mpi_communicator,
167 template <
typename T>
169 void sum (
const std::vector<T> &values,
170 const MPI_Comm &mpi_communicator,
171 std::vector<T> &sums);
179 template <
typename T>
182 const MPI_Comm &mpi_communicator,
191 template <
int rank,
int dim,
typename Number>
195 const MPI_Comm &mpi_communicator);
202 template <
int rank,
int dim,
typename Number>
206 const MPI_Comm &mpi_communicator);
227 template <
typename T>
229 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,
253 template <
typename T>
255 void max (
const std::vector<T> &values,
256 const MPI_Comm &mpi_communicator,
257 std::vector<T> &maxima);
278 template <
typename T>
280 const MPI_Comm &mpi_communicator);
290 template <
typename T,
unsigned int N>
292 void min (
const T (&values)[N],
293 const MPI_Comm &mpi_communicator,
304 template <
typename T>
306 void min (
const std::vector<T> &values,
307 const MPI_Comm &mpi_communicator,
308 std::vector<T> &minima);
321 unsigned int min_index;
322 unsigned int max_index;
342 const MPI_Comm &mpi_communicator);
438 #ifdef DEAL_II_WITH_MPI 442 inline MPI_Datatype mpi_type_id (
const int *)
448 inline MPI_Datatype mpi_type_id (
const long int *)
454 inline MPI_Datatype mpi_type_id (
const unsigned int *)
460 inline MPI_Datatype mpi_type_id (
const unsigned long int *)
462 return MPI_UNSIGNED_LONG;
466 inline MPI_Datatype mpi_type_id (
const unsigned long long int *)
468 return MPI_UNSIGNED_LONG_LONG;
472 inline MPI_Datatype mpi_type_id (
const float *)
478 inline MPI_Datatype mpi_type_id (
const double *)
484 inline MPI_Datatype mpi_type_id (
const long double *)
486 return MPI_LONG_DOUBLE;
490 template <
typename T>
492 T all_reduce (
const MPI_Op &mpi_op,
494 const MPI_Comm &mpi_communicator)
496 #ifdef DEAL_II_WITH_MPI 497 if (job_supports_mpi())
500 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&t)),
501 &output, 1, internal::mpi_type_id(&t), mpi_op,
509 (void)mpi_communicator;
514 template <
typename T,
unsigned int N>
516 void all_reduce (
const MPI_Op &mpi_op,
517 const T (&values)[N],
518 const MPI_Comm &mpi_communicator,
521 #ifdef DEAL_II_WITH_MPI 522 if (job_supports_mpi())
524 MPI_Allreduce ((&values[0] != &output[0]
526 const_cast<void *>(static_cast<const void *>(&values[0]))
529 &output[0], N, internal::mpi_type_id(values), mpi_op,
536 (void)mpi_communicator;
537 for (
unsigned int i=0; i<N; ++i)
538 output[i] = values[i];
542 template <
typename T>
544 void all_reduce (
const MPI_Op &mpi_op,
545 const std::vector<T> &values,
546 const MPI_Comm &mpi_communicator,
547 std::vector<T> &output)
549 #ifdef DEAL_II_WITH_MPI 550 if (job_supports_mpi())
552 output.resize (values.size());
553 MPI_Allreduce ((&values[0] != &output[0]
555 const_cast<void *>(static_cast<const void *>(&values[0]))
558 &output[0], values.size(), internal::mpi_type_id((T *)0), mpi_op,
565 (void)mpi_communicator;
570 template <
typename T>
572 void all_reduce (
const MPI_Op &mpi_op,
574 const MPI_Comm &mpi_communicator,
577 #ifdef DEAL_II_WITH_MPI 578 if (job_supports_mpi())
583 MPI_Allreduce ((values.
begin() != output.
begin()
585 const_cast<void *
>(
static_cast<const void *
>(values.
begin()))
588 output.
begin(), values.
size(), internal::mpi_type_id((T *)0), mpi_op,
595 (void)mpi_communicator;
605 template <
typename T>
608 const MPI_Comm &mpi_communicator)
610 return internal::all_reduce(MPI_SUM, t, mpi_communicator);
614 template <
typename T,
unsigned int N>
616 void sum (
const T (&values)[N],
617 const MPI_Comm &mpi_communicator,
620 internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
624 template <
typename T>
626 void sum (
const std::vector<T> &values,
627 const MPI_Comm &mpi_communicator,
628 std::vector<T> &sums)
630 internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
633 template <
typename T>
636 const MPI_Comm &mpi_communicator,
639 internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
643 template <
int rank,
int dim,
typename Number>
647 const MPI_Comm &mpi_communicator)
652 for (
unsigned int i=0; i< n_entries; ++i)
656 ::Utilities::MPI::sum( entries, mpi_communicator, global_entries );
659 for (
unsigned int i=0; i< n_entries; ++i)
665 template <
int rank,
int dim,
typename Number>
669 const MPI_Comm &mpi_communicator)
674 for (
unsigned int i=0; i< n_entries; ++i)
678 ::Utilities::MPI::sum( entries, mpi_communicator, global_entries );
681 for (
unsigned int i=0; i< n_entries; ++i)
687 template <
typename T>
690 const MPI_Comm &mpi_communicator)
692 return internal::all_reduce(MPI_MAX, t, mpi_communicator);
696 template <
typename T,
unsigned int N>
698 void max (
const T (&values)[N],
699 const MPI_Comm &mpi_communicator,
702 internal::all_reduce(MPI_MAX, values, mpi_communicator, maxima);
706 template <
typename T>
708 void max (
const std::vector<T> &values,
709 const MPI_Comm &mpi_communicator,
710 std::vector<T> &maxima)
712 internal::all_reduce(MPI_MAX, values, mpi_communicator, maxima);
716 template <
typename T>
719 const MPI_Comm &mpi_communicator)
721 return internal::all_reduce(MPI_MIN, t, mpi_communicator);
725 template <
typename T,
unsigned int N>
727 void min (
const T (&values)[N],
728 const MPI_Comm &mpi_communicator,
731 internal::all_reduce(MPI_MIN, values, mpi_communicator, minima);
735 template <
typename T>
737 void min (
const std::vector<T> &values,
738 const MPI_Comm &mpi_communicator,
739 std::vector<T> &minima)
741 internal::all_reduce(MPI_MIN, values, mpi_communicator, minima);
746 bool job_supports_mpi ()
748 #ifdef DEAL_II_WITH_MPI 749 int MPI_has_been_started = 0;
750 MPI_Initialized(&MPI_has_been_started);
752 return (MPI_has_been_started > 0);
761 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
static TableIndices< rank > unrolled_to_component_indices(const unsigned int i)
T sum(const T &t, const MPI_Comm &mpi_communicator)
static TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
MPI_Comm duplicate_communicator(const MPI_Comm &mpi_communicator)
T min(const T &t, const MPI_Comm &mpi_communicator)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &mpi_communicator)
std::vector< unsigned int > compute_point_to_point_communication_pattern(const MPI_Comm &mpi_comm, const std::vector< unsigned int > &destinations)
T max(const T &t, const MPI_Comm &mpi_communicator)