ASPECT
compat.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2022 by the authors of the ASPECT code.
3 
4  This file is part of ASPECT.
5 
6  ASPECT is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  ASPECT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with ASPECT; see the file LICENSE. If not see
18  <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef _aspect_compat_h
22 #define _aspect_compat_h
23 
24 #include <aspect/global.h>
25 
26 // C++11 related includes.
27 #include <array>
28 #include <functional>
29 #include <memory>
30 
31 namespace big_mpi
32 {
33 
34 #if DEAL_II_VERSION_GTE(9,4,0)
35 
37 
38 #else
39 
40  inline MPI_Datatype
41  mpi_type_id(const char *)
42  {
43  return MPI_CHAR;
44  }
45 
50  template <typename T>
51  void
52  broadcast(T *buffer,
53  const size_t count,
54  const unsigned int root,
55  const MPI_Comm &comm)
56  {
57  Assert(root < ::Utilities::MPI::n_mpi_processes(comm),
58  ::ExcMessage("Invalid root rank specified."));
59 
60  // MPI_Bcast's count is a signed int, so send at most 2^31 in each
61  // iteration:
62  const size_t max_send_count = std::numeric_limits<signed int>::max();
63 
64  size_t total_sent_count = 0;
65  while (total_sent_count < count)
66  {
67  const size_t current_count =
68  std::min(count - total_sent_count, max_send_count);
69 
70  const int ierr = MPI_Bcast(buffer + total_sent_count,
71  current_count,
72  mpi_type_id(buffer),
73  root,
74  comm);
75  AssertThrowMPI(ierr);
76  total_sent_count += current_count;
77  }
78 
79  }
80 #endif
81 
82 }
83 
84 #endif
void broadcast(T *buffer, const size_t count, const unsigned int root, const MPI_Comm &comm)
Definition: compat.h:52
Definition: compat.h:31
MPI_Datatype mpi_type_id(const char *)
Definition: compat.h:41