47 using MpiCommWorldType = MPI_Comm;
51 const decltype(MPI_CXX_BOOL) mplog = MPI_CXX_BOOL;
53 const decltype(MPI_INTEGER) mpint = MPI_INTEGER;
54 const decltype(MPI_DOUBLE_PRECISION) mpreal = MPI_DOUBLE_PRECISION;
55 const decltype(MPI_CHARACTER) mpchar = MPI_CHARACTER;
75 decltype(MPI_LOGICAL) mplog = MPI_LOGICAL;
76 decltype(MPI_INTEGER) mpint = MPI_INTEGER;
77 decltype(MPI_DOUBLE_PRECISION) mpreal = MPI_DOUBLE_PRECISION;
78 decltype(MPI_CHARACTER) mpchar = MPI_CHARACTER;
88 decltype(MPI_COMM_WORLD) cHndl;
101 void bcast(
const CmMod& cm_mod,
bool* data)
const;
102 void bcast(
const CmMod& cm_mod, std::vector<bool>& data)
const;
104 void bcast(
const CmMod& cm_mod, std::string& data)
const;
106 void bcast(
const CmMod& cm_mod,
double* data)
const;
108 void bcast(
const CmMod& cm_mod, Array<double>& data,
const std::string& name=
"")
const;
110 void bcast(
const CmMod& cm_mod,
int* data)
const;
117 template <
typename T>
118 void bcast_enum(
const CmMod& cm_mod, T* data)
const
120 int idata =
static_cast<int>(*data);
122 MPI_Bcast(&idata, 1, cm_mod::mpint, cm_mod.master, com());
124 *data =
static_cast<T
>(idata);
131 template <
typename T>
132 void bcast_prop(
const CmMod& cm_mod, std::map<T,double>& props)
const
134 static const int MAX_SIZE = 100;
136 if (2*props.size() > MAX_SIZE) {
137 throw std::runtime_error(
"bcast prop is larger than " + std::to_string(MAX_SIZE) +
".");
140 double prop_array[MAX_SIZE];
141 std::fill_n(prop_array, MAX_SIZE, -1.0);
144 for (
auto& entry : props) {
145 prop_array[n++] =
static_cast<int>(entry.first);
146 prop_array[n++] = entry.second;
149 MPI_Bcast(prop_array, MAX_SIZE, cm_mod::mpreal, cm_mod.master, com());
152 int num_props = MAX_SIZE / 2;;
154 for (
int i = 0; i < num_props; i++) {
155 int iprop =
static_cast<int>(prop_array[2*i]);
159 auto prop =
static_cast<T
>(iprop);
160 props[prop] = prop_array[2*i+1];
165 cm_mod::MpiCommWorldType com()
const;
168 int idcm()
const {
return taskId; };
169 int id() {
return taskId; };
170 bool mas(
const CmMod& cm_mod)
const {
return (taskId == cm_mod.master); };
173 void new_cm(decltype(MPI_COMM_WORLD) comHandle);
175 int np()
const {
return nProcs; };
177 int nT() {
return nThreads; };
186 T reduce(
const CmMod& cm_mod, T u, MPI_Op op = MPI_SUM)
const
190 MPI_Datatype data_type;
191 if (
typeid(T) ==
typeid(
double)) {
192 data_type = MPI_DOUBLE_PRECISION;
193 }
else if (
typeid(T) ==
typeid(
int)) {
194 data_type = MPI_INTEGER;
196 throw std::runtime_error(
"[cm_mod::reduce called with unknown data type.");
202 MPI_Allreduce(&u, &gU, 1, data_type, op, com());
219 MPI_Datatype data_type;
220 if (
typeid(T) ==
typeid(
double)) {
221 data_type = MPI_DOUBLE_PRECISION;
222 }
if (
typeid(T) ==
typeid(
int)) {
223 data_type = MPI_INTEGER;
229 MPI_Allreduce(u.data(), gU.data(), size, data_type, op, com());
235 bool seq()
const {
return (nProcs == 1); };
237 bool slv(
const CmMod& cm_mod)
const {
return (taskId != cm_mod.master); };
240 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:62
The cmType class stores data and defines methods used for mpi communication.
Definition: CmMod.h:82
void bcast(const CmMod &cm_mod, bool *data) const
bcast bool.
Definition: CmMod.cpp:80