62 decltype(MPI_COMM_WORLD) cHndl;
75 void bcast(
const CmMod& cm_mod,
bool* data)
const;
76 void bcast(
const CmMod& cm_mod, std::vector<bool>& data)
const;
78 void bcast(
const CmMod& cm_mod, std::string& data)
const;
80 void bcast(
const CmMod& cm_mod,
double* data)
const;
82 void bcast(
const CmMod& cm_mod, Array<double>& data,
const std::string& name=
"")
const;
84 void bcast(
const CmMod& cm_mod,
int* data)
const;
87 void bcast(
const CmMod &cm_mod,
unsigned int *data)
const;
89 void bcast(
const CmMod& cm_mod, Array<int>& data,
const std::string& name=
"")
const;
92 void gather(
const CmMod& cm_mod,
const int* send_data,
int send_count,
int* recv_data,
int recv_count,
int root)
const;
93 void gather(
const CmMod& cm_mod,
const double* send_data,
int send_count,
double* recv_data,
int recv_count,
int root)
const;
106 void scatter(
const CmMod& cm_mod,
const int* send_data,
int send_count,
int* recv_data,
int recv_count,
int root)
const;
107 void scatter(
const CmMod& cm_mod,
const double* send_data,
int send_count,
double* recv_data,
int recv_count,
int root)
const;
115 template <
typename T>
116 void bcast_enum(
const CmMod& cm_mod, T* data)
const
118 int idata =
static_cast<int>(*data);
120 MPI_Bcast(&idata, 1, cm_mod::mpint, cm_mod.master,
com());
122 *data =
static_cast<T
>(idata);
129 template <
typename T>
130 void bcast_prop(
const CmMod& cm_mod, std::map<T,double>& props)
const
132 static const int MAX_SIZE = 100;
134 if (2*props.size() > MAX_SIZE) {
135 throw std::runtime_error(
"bcast prop is larger than " + std::to_string(MAX_SIZE) +
".");
138 double prop_array[MAX_SIZE];
139 std::fill_n(prop_array, MAX_SIZE, -1.0);
142 for (
auto& entry : props) {
143 prop_array[n++] =
static_cast<int>(entry.first);
144 prop_array[n++] = entry.second;
147 MPI_Bcast(prop_array, MAX_SIZE, cm_mod::mpreal, cm_mod.master,
com());
150 int num_props = MAX_SIZE / 2;;
152 for (
int i = 0; i < num_props; i++) {
153 int iprop =
static_cast<int>(prop_array[2*i]);
157 auto prop =
static_cast<T
>(iprop);
158 props[prop] = prop_array[2*i+1];
163 cm_mod::MpiCommWorldType
com()
const;
166 int idcm()
const {
return taskId; };
167 int id() {
return taskId; };
168 bool mas(
const CmMod& cm_mod)
const {
return (taskId == cm_mod.master); };
171 void new_cm(
decltype(MPI_COMM_WORLD) comHandle);
173 int np()
const {
return nProcs; };
175 int nT() {
return nThreads; };
184 T reduce(
const CmMod& cm_mod, T u, MPI_Op op = MPI_SUM)
const
188 MPI_Datatype data_type;
189 if (
typeid(T) ==
typeid(
double)) {
190 data_type = MPI_DOUBLE_PRECISION;
191 }
else if (
typeid(T) ==
typeid(
int)) {
192 data_type = MPI_INTEGER;
194 throw std::runtime_error(
"[cm_mod::reduce called with unknown data type.");
200 MPI_Allreduce(&u, &gU, 1, data_type, op,
com());
217 MPI_Datatype data_type;
218 if (
typeid(T) ==
typeid(
double)) {
219 data_type = MPI_DOUBLE_PRECISION;
220 }
if (
typeid(T) ==
typeid(
int)) {
221 data_type = MPI_INTEGER;
227 MPI_Allreduce(u.data(), gU.data(), size, data_type, op,
com());
233 bool seq()
const {
return (nProcs == 1); };
235 bool slv(
const CmMod& cm_mod)
const {
return (taskId != cm_mod.master); };
238 int tF(
const CmMod& cm_mod)
const {
return taskId + 1; };
void gatherv(const CmMod &cm_mod, const Vector< int > &send_data, Vector< int > &recv_data, const Vector< int > &recv_counts, const Vector< int > &displs, int root) const
gatherv int Vector
Definition CmMod.cpp:199
void scatterv(const CmMod &cm_mod, const Vector< int > &send_data, const Vector< int > &send_counts, const Vector< int > &displs, Vector< int > &recv_data, int root) const
scatterv int Vector
Definition CmMod.cpp:213
void gather(const CmMod &cm_mod, const int *send_data, int send_count, int *recv_data, int recv_count, int root) const
gather int array
Definition CmMod.cpp:147
void scatter(const CmMod &cm_mod, const int *send_data, int send_count, int *recv_data, int recv_count, int root) const
scatter int array
Definition CmMod.cpp:173