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;
113 void bcast(
const CmMod& cm_mod, Array<int>& data,
const std::string& name=
"")
const;
119 template <
typename T>
120 void bcast_enum(
const CmMod& cm_mod, T* data)
const
122 int idata =
static_cast<int>(*data);
124 MPI_Bcast(&idata, 1, cm_mod::mpint, cm_mod.master,
com());
126 *data =
static_cast<T
>(idata);
133 template <
typename T>
134 void bcast_prop(
const CmMod& cm_mod, std::map<T,double>& props)
const
136 static const int MAX_SIZE = 100;
138 if (2*props.size() > MAX_SIZE) {
139 throw std::runtime_error(
"bcast prop is larger than " + std::to_string(MAX_SIZE) +
".");
142 double prop_array[MAX_SIZE];
143 std::fill_n(prop_array, MAX_SIZE, -1.0);
146 for (
auto& entry : props) {
147 prop_array[n++] =
static_cast<int>(entry.first);
148 prop_array[n++] = entry.second;
151 MPI_Bcast(prop_array, MAX_SIZE, cm_mod::mpreal, cm_mod.master,
com());
154 int num_props = MAX_SIZE / 2;;
156 for (
int i = 0; i < num_props; i++) {
157 int iprop =
static_cast<int>(prop_array[2*i]);
161 auto prop =
static_cast<T
>(iprop);
162 props[prop] = prop_array[2*i+1];
167 cm_mod::MpiCommWorldType
com()
const;
170 int idcm()
const {
return taskId; };
171 int id() {
return taskId; };
172 bool mas(
const CmMod& cm_mod)
const {
return (taskId == cm_mod.master); };
175 void new_cm(
decltype(MPI_COMM_WORLD) comHandle);
177 int np()
const {
return nProcs; };
179 int nT() {
return nThreads; };
188 T reduce(
const CmMod& cm_mod, T u, MPI_Op op = MPI_SUM)
const
192 MPI_Datatype data_type;
193 if (
typeid(T) ==
typeid(
double)) {
194 data_type = MPI_DOUBLE_PRECISION;
195 }
else if (
typeid(T) ==
typeid(
int)) {
196 data_type = MPI_INTEGER;
198 throw std::runtime_error(
"[cm_mod::reduce called with unknown data type.");
204 MPI_Allreduce(&u, &gU, 1, data_type, op,
com());
221 MPI_Datatype data_type;
222 if (
typeid(T) ==
typeid(
double)) {
223 data_type = MPI_DOUBLE_PRECISION;
224 }
if (
typeid(T) ==
typeid(
int)) {
225 data_type = MPI_INTEGER;
231 MPI_Allreduce(u.data(), gU.data(), size, data_type, op,
com());
237 bool seq()
const {
return (nProcs == 1); };
239 bool slv(
const CmMod& cm_mod)
const {
return (taskId != cm_mod.master); };
242 int tF(
const CmMod& cm_mod)
const {
return taskId + 1; };