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);
442 #ifdef DEAL_II_WITH_MPI 446 inline MPI_Datatype mpi_type_id (
const int *)
452 inline MPI_Datatype mpi_type_id (
const long int *)
458 inline MPI_Datatype mpi_type_id (
const unsigned int *)
464 inline MPI_Datatype mpi_type_id (
const unsigned long int *)
466 return MPI_UNSIGNED_LONG;
470 inline MPI_Datatype mpi_type_id (
const unsigned long long int *)
472 return MPI_UNSIGNED_LONG_LONG;
476 inline MPI_Datatype mpi_type_id (
const float *)
482 inline MPI_Datatype mpi_type_id (
const double *)
488 inline MPI_Datatype mpi_type_id (
const long double *)
490 return MPI_LONG_DOUBLE;
494 template <
typename T>
496 T all_reduce (
const MPI_Op &mpi_op,
498 const MPI_Comm &mpi_communicator)
500 #ifdef DEAL_II_WITH_MPI 501 if (job_supports_mpi())
504 MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&t)),
505 &output, 1, internal::mpi_type_id(&t), mpi_op,
513 (void)mpi_communicator;
518 template <
typename T,
unsigned int N>
520 void all_reduce (
const MPI_Op &mpi_op,
521 const T (&values)[N],
522 const MPI_Comm &mpi_communicator,
525 #ifdef DEAL_II_WITH_MPI 526 if (job_supports_mpi())
528 MPI_Allreduce ((&values[0] != &output[0]
530 const_cast<void *>(static_cast<const void *>(&values[0]))
533 &output[0], N, internal::mpi_type_id(values), mpi_op,
540 (void)mpi_communicator;
541 for (
unsigned int i=0; i<N; ++i)
542 output[i] = values[i];
546 template <
typename T>
548 void all_reduce (
const MPI_Op &mpi_op,
549 const std::vector<T> &values,
550 const MPI_Comm &mpi_communicator,
551 std::vector<T> &output)
553 #ifdef DEAL_II_WITH_MPI 554 if (job_supports_mpi())
556 output.resize (values.size());
557 MPI_Allreduce ((&values[0] != &output[0]
559 const_cast<void *>(static_cast<const void *>(&values[0]))
562 &output[0], values.size(), internal::mpi_type_id((T *)0), mpi_op,
569 (void)mpi_communicator;
574 template <
typename T>
576 void all_reduce (
const MPI_Op &mpi_op,
578 const MPI_Comm &mpi_communicator,
581 #ifdef DEAL_II_WITH_MPI 582 if (job_supports_mpi())
587 MPI_Allreduce ((values.
begin() != output.
begin()
589 const_cast<void *
>(
static_cast<const void *
>(values.
begin()))
592 output.
begin(), values.
size(), internal::mpi_type_id((T *)0), mpi_op,
599 (void)mpi_communicator;
609 template <
typename T>
612 const MPI_Comm &mpi_communicator)
614 return internal::all_reduce(MPI_SUM, t, mpi_communicator);
618 template <
typename T,
unsigned int N>
620 void sum (
const T (&values)[N],
621 const MPI_Comm &mpi_communicator,
624 internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
628 template <
typename T>
630 void sum (
const std::vector<T> &values,
631 const MPI_Comm &mpi_communicator,
632 std::vector<T> &sums)
634 internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
637 template <
typename T>
640 const MPI_Comm &mpi_communicator,
643 internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
647 template <
int rank,
int dim,
typename Number>
651 const MPI_Comm &mpi_communicator)
656 for (
unsigned int i=0; i< n_entries; ++i)
660 ::Utilities::MPI::sum( entries, mpi_communicator, global_entries );
663 for (
unsigned int i=0; i< n_entries; ++i)
669 template <
int rank,
int dim,
typename Number>
673 const MPI_Comm &mpi_communicator)
678 for (
unsigned int i=0; i< n_entries; ++i)
682 ::Utilities::MPI::sum( entries, mpi_communicator, global_entries );
685 for (
unsigned int i=0; i< n_entries; ++i)
691 template <
typename T>
694 const MPI_Comm &mpi_communicator)
696 return internal::all_reduce(MPI_MAX, t, mpi_communicator);
700 template <
typename T,
unsigned int N>
702 void max (
const T (&values)[N],
703 const MPI_Comm &mpi_communicator,
706 internal::all_reduce(MPI_MAX, values, mpi_communicator, maxima);
710 template <
typename T>
712 void max (
const std::vector<T> &values,
713 const MPI_Comm &mpi_communicator,
714 std::vector<T> &maxima)
716 internal::all_reduce(MPI_MAX, values, mpi_communicator, maxima);
720 template <
typename T>
723 const MPI_Comm &mpi_communicator)
725 return internal::all_reduce(MPI_MIN, t, mpi_communicator);
729 template <
typename T,
unsigned int N>
731 void min (
const T (&values)[N],
732 const MPI_Comm &mpi_communicator,
735 internal::all_reduce(MPI_MIN, values, mpi_communicator, minima);
739 template <
typename T>
741 void min (
const std::vector<T> &values,
742 const MPI_Comm &mpi_communicator,
743 std::vector<T> &minima)
745 internal::all_reduce(MPI_MIN, values, mpi_communicator, minima);
750 bool job_supports_mpi ()
752 #ifdef DEAL_II_WITH_MPI 753 int MPI_has_been_started = 0;
754 MPI_Initialized(&MPI_has_been_started);
756 return (MPI_has_been_started > 0);
765 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)