Reference documentation for deal.II version Git 497f915867 2021-09-17 22:46:48 +0200
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
mpi.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2021 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_mpi_h
17 #define dealii_mpi_h
18 
19 #include <deal.II/base/config.h>
20 
22 #include <deal.II/base/index_set.h>
23 #include <deal.II/base/mpi_tags.h>
24 #include <deal.II/base/numbers.h>
25 
26 #include <boost/signals2.hpp>
27 
28 #include <map>
29 #include <numeric>
30 #include <set>
31 #include <vector>
32 
33 #if !defined(DEAL_II_WITH_MPI) && !defined(DEAL_II_WITH_PETSC)
34 // without MPI, we would still like to use
35 // some constructs with MPI data
36 // types. Therefore, create some dummies
37 using MPI_Comm = int;
38 using MPI_Request = int;
39 using MPI_Datatype = int;
40 using MPI_Op = int;
41 # ifndef MPI_COMM_WORLD
42 # define MPI_COMM_WORLD 0
43 # endif
44 # ifndef MPI_COMM_SELF
45 # define MPI_COMM_SELF 0
46 # endif
47 # ifndef MPI_REQUEST_NULL
48 # define MPI_REQUEST_NULL 0
49 # endif
50 # ifndef MPI_MIN
51 # define MPI_MIN 0
52 # endif
53 # ifndef MPI_MAX
54 # define MPI_MAX 0
55 # endif
56 # ifndef MPI_SUM
57 # define MPI_SUM 0
58 # endif
59 # ifndef MPI_LOR
60 # define MPI_LOR 0
61 # endif
62 #endif
63 
64 
65 
79 #ifdef DEAL_II_WITH_MPI
80 # if DEAL_II_MPI_VERSION_GTE(3, 0)
81 
82 # define DEAL_II_MPI_CONST_CAST(expr) (expr)
83 
84 # else
85 
86 # include <type_traits>
87 
88 # define DEAL_II_MPI_CONST_CAST(expr) \
89  const_cast<typename std::remove_const< \
90  typename std::remove_pointer<decltype(expr)>::type>::type *>(expr)
91 
92 # endif
93 #endif
94 
95 
96 
98 
99 
100 // Forward type declarations to allow MPI sums over tensorial types
101 #ifndef DOXYGEN
102 template <int rank, int dim, typename Number>
103 class Tensor;
104 template <int rank, int dim, typename Number>
105 class SymmetricTensor;
106 template <typename Number>
107 class SparseMatrix;
108 class IndexSet;
109 #endif
110 
111 namespace Utilities
112 {
125  IndexSet
126  create_evenly_distributed_partitioning(const unsigned int my_partition_id,
127  const unsigned int n_partitions,
128  const IndexSet::size_type total_size);
129 
137  namespace MPI
138  {
147  unsigned int
148  n_mpi_processes(const MPI_Comm &mpi_communicator);
149 
158  unsigned int
159  this_mpi_process(const MPI_Comm &mpi_communicator);
160 
165  const std::vector<unsigned int>
167  const MPI_Comm &comm_small);
168 
190  std::vector<unsigned int>
192  const MPI_Comm & mpi_comm,
193  const std::vector<unsigned int> &destinations);
194 
214  unsigned int
216  const MPI_Comm & mpi_comm,
217  const std::vector<unsigned int> &destinations);
218 
235  MPI_Comm
236  duplicate_communicator(const MPI_Comm &mpi_communicator);
237 
247  void
248  free_communicator(MPI_Comm &mpi_communicator);
249 
263  {
264  public:
268  explicit DuplicatedCommunicator(const MPI_Comm &communicator)
269  : comm(duplicate_communicator(communicator))
270  {}
271 
276 
281  {
283  }
284 
288  const MPI_Comm &
289  operator*() const
290  {
291  return comm;
292  }
293 
294 
299  operator=(const DuplicatedCommunicator &) = delete;
300 
301  private:
306  };
307 
338  {
339  public:
346  {
347  public:
351  explicit ScopedLock(CollectiveMutex &mutex, const MPI_Comm &comm)
352  : mutex(mutex)
353  , comm(comm)
354  {
355  mutex.lock(comm);
356  }
357 
362  {
363  mutex.unlock(comm);
364  }
365 
366  private:
374  const MPI_Comm comm;
375  };
376 
380  explicit CollectiveMutex();
381 
385  ~CollectiveMutex();
386 
393  void
394  lock(const MPI_Comm &comm);
395 
402  void
403  unlock(const MPI_Comm &comm);
404 
405  private:
409  bool locked;
410 
415  };
416 
417 
418 
446 #ifdef DEAL_II_WITH_MPI
447  int
448  create_group(const MPI_Comm & comm,
449  const MPI_Group &group,
450  const int tag,
451  MPI_Comm * new_comm);
452 #endif
453 
462  std::vector<IndexSet>
464  const IndexSet::size_type locally_owned_size);
465 
473  IndexSet
475  const MPI_Comm & comm,
476  const IndexSet::size_type total_size);
477 
478 #ifdef DEAL_II_WITH_MPI
479 
494  template <class Iterator, typename Number = long double>
495  std::pair<Number, typename numbers::NumberTraits<Number>::real_type>
496  mean_and_standard_deviation(const Iterator begin,
497  const Iterator end,
498  const MPI_Comm &comm);
499 #endif
500 
520  template <typename T>
521  T
522  sum(const T &t, const MPI_Comm &mpi_communicator);
523 
533  template <typename T, typename U>
534  void
535  sum(const T &values, const MPI_Comm &mpi_communicator, U &sums);
536 
546  template <typename T>
547  void
549  const MPI_Comm & mpi_communicator,
550  const ArrayView<T> & sums);
551 
557  template <int rank, int dim, typename Number>
560  const MPI_Comm & mpi_communicator);
561 
567  template <int rank, int dim, typename Number>
569  sum(const Tensor<rank, dim, Number> &local,
570  const MPI_Comm & mpi_communicator);
571 
580  template <typename Number>
581  void
582  sum(const SparseMatrix<Number> &local,
583  const MPI_Comm & mpi_communicator,
584  SparseMatrix<Number> & global);
585 
605  template <typename T>
606  T
607  max(const T &t, const MPI_Comm &mpi_communicator);
608 
618  template <typename T, typename U>
619  void
620  max(const T &values, const MPI_Comm &mpi_communicator, U &maxima);
621 
631  template <typename T>
632  void
634  const MPI_Comm & mpi_communicator,
635  const ArrayView<T> & maxima);
636 
656  template <typename T>
657  T
658  min(const T &t, const MPI_Comm &mpi_communicator);
659 
669  template <typename T, typename U>
670  void
671  min(const T &values, const MPI_Comm &mpi_communicator, U &minima);
672 
682  template <typename T>
683  void
685  const MPI_Comm & mpi_communicator,
686  const ArrayView<T> & minima);
687 
711  template <typename T>
712  T
713  logical_or(const T &t, const MPI_Comm &mpi_communicator);
714 
729  template <typename T, typename U>
730  void
731  logical_or(const T &values, const MPI_Comm &mpi_communicator, U &results);
732 
742  template <typename T>
743  void
745  const MPI_Comm & mpi_communicator,
746  const ArrayView<T> & results);
747 
762  struct MinMaxAvg
763  {
768  double sum;
769 
774  double min;
775 
780  double max;
781 
790  unsigned int min_index;
791 
800  unsigned int max_index;
801 
806  double avg;
807  };
808 
823  MinMaxAvg
824  min_max_avg(const double my_value, const MPI_Comm &mpi_communicator);
825 
837  std::vector<MinMaxAvg>
838  min_max_avg(const std::vector<double> &my_value,
839  const MPI_Comm & mpi_communicator);
840 
841 
854  void
855  min_max_avg(const ArrayView<const double> &my_values,
856  const ArrayView<MinMaxAvg> & result,
857  const MPI_Comm & mpi_communicator);
858 
859 
904  {
905  public:
952  int & argc,
953  char **& argv,
954  const unsigned int max_num_threads = numbers::invalid_unsigned_int);
955 
960  ~MPI_InitFinalize();
961 
988  static void
989  register_request(MPI_Request &request);
990 
994  static void
995  unregister_request(MPI_Request &request);
996 
1004  struct Signals
1005  {
1010  boost::signals2::signal<void()> at_mpi_init;
1011 
1018  boost::signals2::signal<void()> at_mpi_finalize;
1019  };
1020 
1022 
1023  private:
1027  static std::set<MPI_Request *> requests;
1028  };
1029 
1041  bool
1042  job_supports_mpi();
1043 
1061  template <typename T>
1062  std::map<unsigned int, T>
1063  some_to_some(const MPI_Comm & comm,
1064  const std::map<unsigned int, T> &objects_to_send);
1065 
1079  template <typename T>
1080  std::vector<T>
1081  all_gather(const MPI_Comm &comm, const T &object_to_send);
1082 
1098  template <typename T>
1099  std::vector<T>
1100  gather(const MPI_Comm & comm,
1101  const T & object_to_send,
1102  const unsigned int root_process = 0);
1103 
1122  template <typename T>
1123  T
1124  broadcast(const MPI_Comm & comm,
1125  const T & object_to_send,
1126  const unsigned int root_process = 0);
1127 
1140  template <typename T>
1141  T
1142  reduce(const T & local_value,
1143  const MPI_Comm & comm,
1144  const std::function<T(const T &, const T &)> &combiner,
1145  const unsigned int root_process = 0);
1146 
1156  template <typename T>
1157  T
1158  all_reduce(const T & local_value,
1159  const MPI_Comm & comm,
1160  const std::function<T(const T &, const T &)> &combiner);
1161 
1204  std::vector<unsigned int>
1205  compute_index_owner(const IndexSet &owned_indices,
1206  const IndexSet &indices_to_look_up,
1207  const MPI_Comm &comm);
1208 
1216  template <typename T>
1217  std::vector<T>
1218  compute_set_union(const std::vector<T> &vec, const MPI_Comm &comm);
1219 
1223  template <typename T>
1224  std::set<T>
1225  compute_set_union(const std::set<T> &set, const MPI_Comm &comm);
1226 
1227 #ifndef DOXYGEN
1228  // declaration for an internal function that lives in mpi.templates.h
1229  namespace internal
1230  {
1231  template <typename T>
1232  void
1233  all_reduce(const MPI_Op & mpi_op,
1234  const ArrayView<const T> &values,
1235  const MPI_Comm & mpi_communicator,
1236  const ArrayView<T> & output);
1237  }
1238 
1239  // Since these depend on N they must live in the header file
1240  template <typename T, unsigned int N>
1241  void
1242  sum(const T (&values)[N], const MPI_Comm &mpi_communicator, T (&sums)[N])
1243  {
1244  internal::all_reduce(MPI_SUM,
1246  mpi_communicator,
1247  ArrayView<T>(sums, N));
1248  }
1249 
1250  template <typename T, unsigned int N>
1251  void
1252  max(const T (&values)[N], const MPI_Comm &mpi_communicator, T (&maxima)[N])
1253  {
1254  internal::all_reduce(MPI_MAX,
1256  mpi_communicator,
1257  ArrayView<T>(maxima, N));
1258  }
1259 
1260  template <typename T, unsigned int N>
1261  void
1262  min(const T (&values)[N], const MPI_Comm &mpi_communicator, T (&minima)[N])
1263  {
1264  internal::all_reduce(MPI_MIN,
1266  mpi_communicator,
1267  ArrayView<T>(minima, N));
1268  }
1269 
1270  template <typename T, unsigned int N>
1271  void
1272  logical_or(const T (&values)[N],
1273  const MPI_Comm &mpi_communicator,
1274  T (&results)[N])
1275  {
1276  static_assert(std::is_integral<T>::value,
1277  "The MPI_LOR operation only allows integral data types.");
1278 
1279  internal::all_reduce(MPI_LOR,
1281  mpi_communicator,
1282  ArrayView<T>(results, N));
1283  }
1284 
1285  template <typename T>
1286  std::map<unsigned int, T>
1287  some_to_some(const MPI_Comm & comm,
1288  const std::map<unsigned int, T> &objects_to_send)
1289  {
1290 # ifndef DEAL_II_WITH_MPI
1291  (void)comm;
1292  Assert(objects_to_send.size() < 2,
1293  ExcMessage("Cannot send to more than one processor."));
1294  Assert(objects_to_send.find(0) != objects_to_send.end() ||
1295  objects_to_send.size() == 0,
1296  ExcMessage("Can only send to myself or to nobody."));
1297  return objects_to_send;
1298 # else
1299  const auto my_proc = this_mpi_process(comm);
1300 
1301  std::map<unsigned int, T> received_objects;
1302 
1303  std::vector<unsigned int> send_to;
1304  send_to.reserve(objects_to_send.size());
1305  for (const auto &m : objects_to_send)
1306  if (m.first == my_proc)
1307  received_objects[my_proc] = m.second;
1308  else
1309  send_to.emplace_back(m.first);
1310 
1311  const unsigned int n_point_point_communications =
1313 
1314  // Protect the following communication:
1315  static CollectiveMutex mutex;
1316  CollectiveMutex::ScopedLock lock(mutex, comm);
1317 
1318  // If we have something to send, or we expect something from other
1319  // processors, we need to visit one of the two scopes below. Otherwise,
1320  // no other action is required by this mpi process, and we can safely
1321  // return.
1322  if (send_to.size() == 0 && n_point_point_communications == 0)
1323  return received_objects;
1324 
1325  const int mpi_tag =
1327 
1328  // Sending buffers
1329  std::vector<std::vector<char>> buffers_to_send(send_to.size());
1330  std::vector<MPI_Request> buffer_send_requests(send_to.size());
1331  {
1332  unsigned int i = 0;
1333  for (const auto &rank_obj : objects_to_send)
1334  if (rank_obj.first != my_proc)
1335  {
1336  const auto &rank = rank_obj.first;
1337  buffers_to_send[i] = Utilities::pack(rank_obj.second,
1338  /*allow_compression=*/false);
1339  const int ierr = MPI_Isend(buffers_to_send[i].data(),
1340  buffers_to_send[i].size(),
1341  MPI_CHAR,
1342  rank,
1343  mpi_tag,
1344  comm,
1345  &buffer_send_requests[i]);
1346  AssertThrowMPI(ierr);
1347  ++i;
1348  }
1349  }
1350 
1351  // Fill the output map
1352  {
1353  std::vector<char> buffer;
1354  // We do this on a first come/first served basis
1355  for (unsigned int i = 0; i < n_point_point_communications; ++i)
1356  {
1357  // Probe what's going on. Take data from the first available sender
1358  MPI_Status status;
1359  int ierr = MPI_Probe(MPI_ANY_SOURCE, mpi_tag, comm, &status);
1360  AssertThrowMPI(ierr);
1361 
1362  // Length of the message
1363  int len;
1364  ierr = MPI_Get_count(&status, MPI_CHAR, &len);
1365  AssertThrowMPI(ierr);
1366  buffer.resize(len);
1367 
1368  // Source rank
1369  const unsigned int rank = status.MPI_SOURCE;
1370 
1371  // Actually receive the message
1372  ierr = MPI_Recv(buffer.data(),
1373  len,
1374  MPI_CHAR,
1375  status.MPI_SOURCE,
1376  status.MPI_TAG,
1377  comm,
1378  MPI_STATUS_IGNORE);
1379  AssertThrowMPI(ierr);
1380  Assert(received_objects.find(rank) == received_objects.end(),
1382  "I should not receive again from this rank"));
1383  received_objects[rank] =
1384  Utilities::unpack<T>(buffer,
1385  /*allow_compression=*/false);
1386  }
1387  }
1388 
1389  // Wait to have sent all objects.
1390  const int ierr = MPI_Waitall(send_to.size(),
1391  buffer_send_requests.data(),
1392  MPI_STATUSES_IGNORE);
1393  AssertThrowMPI(ierr);
1394 
1395  return received_objects;
1396 # endif // deal.II with MPI
1397  }
1398 
1399  template <typename T>
1400  std::vector<T>
1401  all_gather(const MPI_Comm &comm, const T &object)
1402  {
1403  if (job_supports_mpi() == false)
1404  return {object};
1405 
1406 # ifndef DEAL_II_WITH_MPI
1407  (void)comm;
1408  std::vector<T> v(1, object);
1409  return v;
1410 # else
1411  const auto n_procs = ::Utilities::MPI::n_mpi_processes(comm);
1412 
1413  std::vector<char> buffer = Utilities::pack(object);
1414 
1415  int n_local_data = buffer.size();
1416 
1417  // Vector to store the size of loc_data_array for every process
1418  std::vector<int> size_all_data(n_procs, 0);
1419 
1420  // Exchanging the size of each buffer
1421  int ierr = MPI_Allgather(
1422  &n_local_data, 1, MPI_INT, size_all_data.data(), 1, MPI_INT, comm);
1423  AssertThrowMPI(ierr);
1424 
1425  // Now computing the displacement, relative to recvbuf,
1426  // at which to store the incoming buffer
1427  std::vector<int> rdispls(n_procs);
1428  rdispls[0] = 0;
1429  for (unsigned int i = 1; i < n_procs; ++i)
1430  rdispls[i] = rdispls[i - 1] + size_all_data[i - 1];
1431 
1432  // Step 3: exchange the buffer:
1433  std::vector<char> received_unrolled_buffer(rdispls.back() +
1434  size_all_data.back());
1435 
1436  ierr = MPI_Allgatherv(buffer.data(),
1437  n_local_data,
1438  MPI_CHAR,
1439  received_unrolled_buffer.data(),
1440  size_all_data.data(),
1441  rdispls.data(),
1442  MPI_CHAR,
1443  comm);
1444  AssertThrowMPI(ierr);
1445 
1446  std::vector<T> received_objects(n_procs);
1447  for (unsigned int i = 0; i < n_procs; ++i)
1448  {
1449  std::vector<char> local_buffer(received_unrolled_buffer.begin() +
1450  rdispls[i],
1451  received_unrolled_buffer.begin() +
1452  rdispls[i] + size_all_data[i]);
1453  received_objects[i] = Utilities::unpack<T>(local_buffer);
1454  }
1455 
1456  return received_objects;
1457 # endif
1458  }
1459 
1460  template <typename T>
1461  std::vector<T>
1462  gather(const MPI_Comm & comm,
1463  const T & object_to_send,
1464  const unsigned int root_process)
1465  {
1466 # ifndef DEAL_II_WITH_MPI
1467  (void)comm;
1468  (void)root_process;
1469  std::vector<T> v(1, object_to_send);
1470  return v;
1471 # else
1472  const auto n_procs = ::Utilities::MPI::n_mpi_processes(comm);
1473  const auto my_rank = ::Utilities::MPI::this_mpi_process(comm);
1474 
1475  AssertIndexRange(root_process, n_procs);
1476 
1477  std::vector<char> buffer = Utilities::pack(object_to_send);
1478  int n_local_data = buffer.size();
1479 
1480  // Vector to store the size of loc_data_array for every process
1481  // only the root process needs to allocate memory for that purpose
1482  std::vector<int> size_all_data;
1483  if (my_rank == root_process)
1484  size_all_data.resize(n_procs, 0);
1485 
1486  // Exchanging the size of each buffer
1487  int ierr = MPI_Gather(&n_local_data,
1488  1,
1489  MPI_INT,
1490  size_all_data.data(),
1491  1,
1492  MPI_INT,
1493  root_process,
1494  comm);
1495  AssertThrowMPI(ierr);
1496 
1497  // Now computing the displacement, relative to recvbuf,
1498  // at which to store the incoming buffer; only for root
1499  std::vector<int> rdispls;
1500  if (my_rank == root_process)
1501  {
1502  rdispls.resize(n_procs, 0);
1503  for (unsigned int i = 1; i < n_procs; ++i)
1504  rdispls[i] = rdispls[i - 1] + size_all_data[i - 1];
1505  }
1506  // exchange the buffer:
1507  std::vector<char> received_unrolled_buffer;
1508  if (my_rank == root_process)
1509  received_unrolled_buffer.resize(rdispls.back() + size_all_data.back());
1510 
1511  ierr = MPI_Gatherv(buffer.data(),
1512  n_local_data,
1513  MPI_CHAR,
1514  received_unrolled_buffer.data(),
1515  size_all_data.data(),
1516  rdispls.data(),
1517  MPI_CHAR,
1518  root_process,
1519  comm);
1520  AssertThrowMPI(ierr);
1521 
1522  std::vector<T> received_objects;
1523 
1524  if (my_rank == root_process)
1525  {
1526  received_objects.resize(n_procs);
1527 
1528  for (unsigned int i = 0; i < n_procs; ++i)
1529  {
1530  const std::vector<char> local_buffer(
1531  received_unrolled_buffer.begin() + rdispls[i],
1532  received_unrolled_buffer.begin() + rdispls[i] +
1533  size_all_data[i]);
1534  received_objects[i] = Utilities::unpack<T>(local_buffer);
1535  }
1536  }
1537  return received_objects;
1538 # endif
1539  }
1540 
1541 
1542 
1543  template <typename T>
1544  T
1545  broadcast(const MPI_Comm & comm,
1546  const T & object_to_send,
1547  const unsigned int root_process)
1548  {
1549 # ifndef DEAL_II_WITH_MPI
1550  (void)comm;
1551  (void)root_process;
1552  return object_to_send;
1553 # else
1554  const auto n_procs = ::Utilities::MPI::n_mpi_processes(comm);
1555  AssertIndexRange(root_process, n_procs);
1556  (void)n_procs;
1557 
1558  std::vector<char> buffer;
1559  unsigned int buffer_size = numbers::invalid_unsigned_int;
1560 
1561  // On the root process, pack the data and determine what the
1562  // buffer size needs to be.
1563  if (this_mpi_process(comm) == root_process)
1564  {
1565  buffer = Utilities::pack(object_to_send, false);
1566  buffer_size = buffer.size();
1567  }
1568 
1569  // Exchange the size of buffer
1570  int ierr = MPI_Bcast(&buffer_size, 1, MPI_UNSIGNED, root_process, comm);
1571  AssertThrowMPI(ierr);
1572 
1573  // If not on the root process, correctly size the buffer to
1574  // receive the data, then do exactly that.
1575  if (this_mpi_process(comm) != root_process)
1576  buffer.resize(buffer_size);
1577 
1578  ierr =
1579  MPI_Bcast(buffer.data(), buffer_size, MPI_CHAR, root_process, comm);
1580  AssertThrowMPI(ierr);
1581 
1582  if (Utilities::MPI::this_mpi_process(comm) == root_process)
1583  return object_to_send;
1584  else
1585  return Utilities::unpack<T>(buffer, false);
1586 # endif
1587  }
1588 
1589 
1590 # ifdef DEAL_II_WITH_MPI
1591  template <class Iterator, typename Number>
1592  std::pair<Number, typename numbers::NumberTraits<Number>::real_type>
1593  mean_and_standard_deviation(const Iterator begin,
1594  const Iterator end,
1595  const MPI_Comm &comm)
1596  {
1597  // below we do simple and straight-forward implementation. More elaborate
1598  // options are:
1599  // http://dx.doi.org/10.1145/2807591.2807644 section 3.1.2
1600  // https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm
1601  // https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online
1602  using Std = typename numbers::NumberTraits<Number>::real_type;
1603  const Number sum = std::accumulate(begin, end, Number(0.));
1604 
1605  const auto size = Utilities::MPI::sum(std::distance(begin, end), comm);
1606  Assert(size > 0, ExcDivideByZero());
1607  const Number mean =
1608  Utilities::MPI::sum(sum, comm) / static_cast<Std>(size);
1609  Std sq_sum = 0.;
1610  std::for_each(begin, end, [&mean, &sq_sum](const Number &v) {
1611  sq_sum += numbers::NumberTraits<Number>::abs_square(v - mean);
1612  });
1613  sq_sum = Utilities::MPI::sum(sq_sum, comm);
1614  return std::make_pair(mean,
1615  std::sqrt(sq_sum / static_cast<Std>(size - 1)));
1616  }
1617 # endif
1618 
1619 #endif
1620  } // end of namespace MPI
1621 } // end of namespace Utilities
1622 
1623 
1625 
1626 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:196
IndexSet create_evenly_distributed_partitioning(const MPI_Comm &comm, const IndexSet::size_type total_size)
Definition: mpi.cc:285
unsigned int compute_n_point_to_point_communications(const MPI_Comm &mpi_comm, const std::vector< unsigned int > &destinations)
Definition: mpi.cc:436
static constexpr std::enable_if< std::is_same< Dummy, number >::value &&is_cuda_compatible< Dummy >::value, real_type >::type abs_square(const number &x)
Definition: numbers.h:587
T logical_or(const T &t, const MPI_Comm &mpi_communicator)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1718
static const char U
const std::vector< unsigned int > mpi_processes_within_communicator(const MPI_Comm &comm_large, const MPI_Comm &comm_small)
Definition: mpi.cc:140
boost::signals2::signal< void()> at_mpi_finalize
Definition: mpi.h:1018
std::vector< IndexSet > create_ascending_partitioning(const MPI_Comm &comm, const IndexSet::size_type locally_owned_size)
Definition: mpi.cc:263
static ::ExceptionBase & ExcDivideByZero()
std::pair< Number, typename numbers::NumberTraits< Number >::real_type > mean_and_standard_deviation(const Iterator begin, const Iterator end, const MPI_Comm &comm)
ScopedLock(CollectiveMutex &mutex, const MPI_Comm &comm)
Definition: mpi.h:351
void free_communicator(MPI_Comm &mpi_communicator)
Definition: mpi.cc:171
static ::ExceptionBase & ExcMessage(std::string arg1)
static const char T
T sum(const T &t, const MPI_Comm &mpi_communicator)
#define Assert(cond, exc)
Definition: exceptions.h:1461
void lock(const MPI_Comm &comm)
Definition: mpi.cc:1059
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
T all_reduce(const T &local_value, const MPI_Comm &comm, const std::function< T(const T &, const T &)> &combiner)
std::vector< T > gather(const MPI_Comm &comm, const T &object_to_send, const unsigned int root_process=0)
int create_group(const MPI_Comm &comm, const MPI_Group &group, const int tag, MPI_Comm *new_comm)
Definition: mpi.cc:181
VectorType::value_type * end(VectorType &V)
std::vector< T > compute_set_union(const std::vector< T > &vec, const MPI_Comm &comm)
const MPI_Comm & operator*() const
Definition: mpi.h:289
static Signals signals
Definition: mpi.h:1021
std::vector< unsigned int > compute_index_owner(const IndexSet &owned_indices, const IndexSet &indices_to_look_up, const MPI_Comm &comm)
Definition: mpi.cc:1001
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
Definition: utilities.h:1218
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
Definition: mpi.cc:117
#define AssertThrowMPI(error_code)
Definition: exceptions.h:1776
Utilities::MPI::compute_point_to_point_communication_pattern()
Definition: mpi_tags.h:57
IndexSet create_evenly_distributed_partitioning(const unsigned int my_partition_id, const unsigned int n_partitions, const IndexSet::size_type total_size)
Definition: mpi.cc:71
MPI_Comm duplicate_communicator(const MPI_Comm &mpi_communicator)
Definition: mpi.cc:160
Definition: tensor.h:506
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
VectorType::value_type * begin(VectorType &V)
T min(const T &t, const MPI_Comm &mpi_communicator)
T broadcast(const MPI_Comm &comm, const T &object_to_send, const unsigned int root_process=0)
static std::set< MPI_Request * > requests
Definition: mpi.h:1027
static const char N
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
Definition: mpi.cc:128
boost::signals2::signal< void()> at_mpi_init
Definition: mpi.h:1010
std::vector< T > all_gather(const MPI_Comm &comm, const T &object_to_send)
T reduce(const T &local_value, const MPI_Comm &comm, const std::function< T(const T &, const T &)> &combiner, const unsigned int root_process=0)
DuplicatedCommunicator(const MPI_Comm &communicator)
Definition: mpi.h:268
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &mpi_communicator)
Definition: mpi.cc:91
std::vector< unsigned int > compute_point_to_point_communication_pattern(const MPI_Comm &mpi_comm, const std::vector< unsigned int > &destinations)
Definition: mpi.cc:299
bool job_supports_mpi()
Definition: mpi.cc:985
std::map< unsigned int, T > some_to_some(const MPI_Comm &comm, const std::map< unsigned int, T > &objects_to_send)
unsigned int min_index
Definition: mpi.h:790
T max(const T &t, const MPI_Comm &mpi_communicator)
unsigned int max_index
Definition: mpi.h:800
static ::ExceptionBase & ExcInternalError()
DuplicatedCommunicator & operator=(const DuplicatedCommunicator &)=delete