48 using MpiCommWorldType = MPI_Comm;
52 const decltype(MPI_CXX_BOOL) mplog = MPI_CXX_BOOL;
54 const decltype(MPI_INTEGER) mpint = MPI_INTEGER;
55 const decltype(MPI_DOUBLE_PRECISION) mpreal = MPI_DOUBLE_PRECISION;
56 const decltype(MPI_CHARACTER) mpchar = MPI_CHARACTER;
76 decltype(MPI_LOGICAL) mplog = MPI_LOGICAL;
77 decltype(MPI_INTEGER) mpint = MPI_INTEGER;
78 decltype(MPI_DOUBLE_PRECISION) mpreal = MPI_DOUBLE_PRECISION;
79 decltype(MPI_CHARACTER) mpchar = MPI_CHARACTER;
89 decltype(MPI_COMM_WORLD) cHndl;
109 void bcast(
const CmMod&
cm_mod, Array<double>& data,
const std::string& name=
"")
const;
118 template <
typename T>
119 void bcast_enum(
const CmMod&
cm_mod, T* data)
const
121 int idata =
static_cast<int>(*data);
123 MPI_Bcast(&idata, 1, cm_mod::mpint,
cm_mod.master, com());
125 *data =
static_cast<T
>(idata);
132 template <
typename T>
133 void bcast_prop(
const CmMod&
cm_mod, std::map<T,double>& props)
const
135 static const int MAX_SIZE = 100;
137 if (2*props.size() > MAX_SIZE) {
138 throw std::runtime_error(
"bcast prop is larger than " + std::to_string(MAX_SIZE) +
".");
141 double prop_array[MAX_SIZE];
142 std::fill_n(prop_array, MAX_SIZE, -1.0);
145 for (
auto& entry : props) {
146 prop_array[n++] =
static_cast<int>(entry.first);
147 prop_array[n++] = entry.second;
150 MPI_Bcast(prop_array, MAX_SIZE, cm_mod::mpreal,
cm_mod.master, com());
153 int num_props = MAX_SIZE / 2;;
155 for (
int i = 0; i < num_props; i++) {
156 int iprop =
static_cast<int>(prop_array[2*i]);
160 auto prop =
static_cast<T
>(iprop);
161 props[prop] = prop_array[2*i+1];
166 cm_mod::MpiCommWorldType com()
const;
169 int idcm()
const {
return taskId; };
170 int id() {
return taskId; };
174 void new_cm(decltype(MPI_COMM_WORLD) comHandle);
176 int np()
const {
return nProcs; };
178 int nT() {
return nThreads; };
187 T reduce(
const CmMod&
cm_mod, T u, MPI_Op op = MPI_SUM)
const
191 MPI_Datatype data_type;
192 if (
typeid(T) ==
typeid(
double)) {
193 data_type = MPI_DOUBLE_PRECISION;
194 }
else if (
typeid(T) ==
typeid(
int)) {
195 data_type = MPI_INTEGER;
197 throw std::runtime_error(
"[cm_mod::reduce called with unknown data type.");
203 MPI_Allreduce(&u, &gU, 1, data_type, op, com());
220 MPI_Datatype data_type;
221 if (
typeid(T) ==
typeid(
double)) {
222 data_type = MPI_DOUBLE_PRECISION;
223 }
if (
typeid(T) ==
typeid(
int)) {
224 data_type = MPI_INTEGER;
230 MPI_Allreduce(u.data(), gU.data(), size, data_type, op, com());
236 bool seq()
const {
return (nProcs == 1); };
241 int tF(
const CmMod&
cm_mod)
const {
return taskId + 1; };
The CmMod class duplicates the data structures in the Fortran CMMOD module defined in COMU....
Definition: CmMod.h:63
CmMod()
Definition: CmMod.cpp:39
The cmType class stores data and defines methods used for mpi communication.
Definition: CmMod.h:83
void bcast(const CmMod &cm_mod, bool *data) const
bcast bool.
Definition: CmMod.cpp:81