61 decltype(MPI_COMM_WORLD) cHndl;
74 void bcast(
const CmMod& cm_mod,
bool* data)
const;
75 void bcast(
const CmMod& cm_mod, std::vector<bool>& data)
const;
77 void bcast(
const CmMod& cm_mod, std::string& data)
const;
79 void bcast(
const CmMod& cm_mod,
double* data)
const;
81 void bcast(
const CmMod& cm_mod, Array<double>& data,
const std::string& name=
"")
const;
83 void bcast(
const CmMod& cm_mod,
int* data)
const;
86 void bcast(
const CmMod& cm_mod, Array<int>& data,
const std::string& name=
"")
const;
89 void gather(
const CmMod& cm_mod,
const int* send_data,
int send_count,
int* recv_data,
int recv_count,
int root)
const;
90 void gather(
const CmMod& cm_mod,
const double* send_data,
int send_count,
double* recv_data,
int recv_count,
int root)
const;
103 void scatter(
const CmMod& cm_mod,
const int* send_data,
int send_count,
int* recv_data,
int recv_count,
int root)
const;
104 void scatter(
const CmMod& cm_mod,
const double* send_data,
int send_count,
double* recv_data,
int recv_count,
int root)
const;
112 template <
typename T>
113 void bcast_enum(
const CmMod& cm_mod, T* data)
const
115 int idata =
static_cast<int>(*data);
117 MPI_Bcast(&idata, 1, cm_mod::mpint, cm_mod.master,
com());
119 *data =
static_cast<T
>(idata);
126 template <
typename T>
127 void bcast_prop(
const CmMod& cm_mod, std::map<T,double>& props)
const
129 static const int MAX_SIZE = 100;
131 if (2*props.size() > MAX_SIZE) {
132 throw std::runtime_error(
"bcast prop is larger than " + std::to_string(MAX_SIZE) +
".");
135 double prop_array[MAX_SIZE];
136 std::fill_n(prop_array, MAX_SIZE, -1.0);
139 for (
auto& entry : props) {
140 prop_array[n++] =
static_cast<int>(entry.first);
141 prop_array[n++] = entry.second;
144 MPI_Bcast(prop_array, MAX_SIZE, cm_mod::mpreal, cm_mod.master,
com());
147 int num_props = MAX_SIZE / 2;;
149 for (
int i = 0; i < num_props; i++) {
150 int iprop =
static_cast<int>(prop_array[2*i]);
154 auto prop =
static_cast<T
>(iprop);
155 props[prop] = prop_array[2*i+1];
160 cm_mod::MpiCommWorldType
com()
const;
163 int idcm()
const {
return taskId; };
164 int id() {
return taskId; };
165 bool mas(
const CmMod& cm_mod)
const {
return (taskId == cm_mod.master); };
168 void new_cm(
decltype(MPI_COMM_WORLD) comHandle);
170 int np()
const {
return nProcs; };
172 int nT() {
return nThreads; };
181 T reduce(
const CmMod& cm_mod, T u, MPI_Op op = MPI_SUM)
const
185 MPI_Datatype data_type;
186 if (
typeid(T) ==
typeid(
double)) {
187 data_type = MPI_DOUBLE_PRECISION;
188 }
else if (
typeid(T) ==
typeid(
int)) {
189 data_type = MPI_INTEGER;
191 throw std::runtime_error(
"[cm_mod::reduce called with unknown data type.");
197 MPI_Allreduce(&u, &gU, 1, data_type, op,
com());
214 MPI_Datatype data_type;
215 if (
typeid(T) ==
typeid(
double)) {
216 data_type = MPI_DOUBLE_PRECISION;
217 }
if (
typeid(T) ==
typeid(
int)) {
218 data_type = MPI_INTEGER;
224 MPI_Allreduce(u.data(), gU.data(), size, data_type, op,
com());
230 bool seq()
const {
return (nProcs == 1); };
232 bool slv(
const CmMod& cm_mod)
const {
return (taskId != cm_mod.master); };
235 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:194
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:208
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:142
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:168