33 #ifndef IOSS_Ioss_ParallelUtils_h 34 #define IOSS_Ioss_ParallelUtils_h 62 bool get_environment(
const std::string &
name, std::string &value,
bool sync_parallel)
const;
81 bool get_environment(
const std::string &name,
int &value,
bool sync_parallel)
const;
89 bool get_environment(
const std::string &name,
bool sync_parallel)
const;
91 std::string
decode_filename(
const std::string &filename,
bool is_parallel)
const;
113 void memory_stats(int64_t &min, int64_t &max, int64_t &avg)
const;
128 template <
typename T>
130 template <
typename T>
133 template <
typename T>
void gather(T my_value, std::vector<T> &result)
const;
134 template <
typename T>
void all_gather(T my_value, std::vector<T> &result)
const;
135 template <
typename T>
void gather(std::vector<T> &my_values, std::vector<T> &result)
const;
137 void progress(
const std::string &output)
const;
143 #ifdef SEACAS_HAVE_MPI 144 inline MPI_Datatype mpi_type(
double ) {
return MPI_DOUBLE; }
145 inline MPI_Datatype mpi_type(
float ) {
return MPI_FLOAT; }
146 inline MPI_Datatype mpi_type(
int ) {
return MPI_INT; }
147 inline MPI_Datatype mpi_type(
long int ) {
return MPI_LONG_LONG_INT; }
148 inline MPI_Datatype mpi_type(
long long int ) {
return MPI_LONG_LONG_INT; }
149 inline MPI_Datatype mpi_type(
unsigned int ) {
return MPI_UNSIGNED; }
150 inline MPI_Datatype mpi_type(
unsigned long int ) {
return MPI_UNSIGNED_LONG; }
152 template <
typename T>
153 int MY_Alltoallv64(
const std::vector<T> &sendbuf,
const std::vector<int64_t> &sendcounts,
154 const std::vector<int64_t> &senddisp, std::vector<T> &recvbuf,
155 const std::vector<int64_t> &recvcounts,
const std::vector<int64_t> &recvdisp,
158 int processor_count = 0;
159 int my_processor = 0;
160 MPI_Comm_size(comm, &processor_count);
161 MPI_Comm_rank(comm, &my_processor);
165 for (
int i = 0; i < processor_count; i++) {
166 int snd_cnt =
static_cast<int>(sendcounts[i]);
167 if (static_cast<int64_t>(snd_cnt) != sendcounts[i]) {
168 std::ostringstream errmsg;
169 errmsg <<
"ERROR: The number of items that must be communicated via MPI calls from\n" 170 <<
" processor " << my_processor <<
" to processor " << i <<
" is " 172 <<
"\n which exceeds the storage capacity of the integers " 173 "used by MPI functions.\n";
174 std::cerr << errmsg.str();
181 for (
size_t i = 1; i < pow_2; i++) {
185 size_t exchange_proc = i ^ my_processor;
186 if (exchange_proc < static_cast<size_t>(processor_count)) {
187 int snd_cnt =
static_cast<int>(
188 sendcounts[exchange_proc]);
189 int rcv_cnt =
static_cast<int>(recvcounts[exchange_proc]);
190 if (static_cast<size_t>(my_processor) < exchange_proc) {
191 MPI_Send((
void *)&sendbuf[senddisp[exchange_proc]], snd_cnt, mpi_type(T(0)),
192 exchange_proc, tag, comm);
193 MPI_Recv(&recvbuf[recvdisp[exchange_proc]], rcv_cnt, mpi_type(T(0)), exchange_proc, tag,
197 MPI_Recv(&recvbuf[recvdisp[exchange_proc]], rcv_cnt, mpi_type(T(0)), exchange_proc, tag,
199 MPI_Send((
void *)&sendbuf[senddisp[exchange_proc]], snd_cnt, mpi_type(T(0)),
200 exchange_proc, tag, comm);
206 std::copy(&sendbuf[senddisp[my_processor]],
207 &sendbuf[senddisp[my_processor] + sendcounts[my_processor]],
208 &recvbuf[recvdisp[my_processor]]);
212 template <
typename T>
213 int MY_Alltoallv(
const std::vector<T> &sendbuf,
const std::vector<int64_t> &sendcnts,
214 const std::vector<int64_t> &senddisp, std::vector<T> &recvbuf,
215 const std::vector<int64_t> &recvcnts,
const std::vector<int64_t> &recvdisp,
225 int processor_count = 0;
226 MPI_Comm_size(comm, &processor_count);
227 size_t max_comm = sendcnts[processor_count - 1] + senddisp[processor_count - 1];
229 if (max_comm < one << 31) {
231 std::vector<int> send_cnt(sendcnts.begin(), sendcnts.end());
232 std::vector<int> send_dis(senddisp.begin(), senddisp.end());
233 std::vector<int> recv_cnt(recvcnts.begin(), recvcnts.end());
234 std::vector<int> recv_dis(recvdisp.begin(), recvdisp.end());
235 return MPI_Alltoallv((
void *)sendbuf.data(), send_cnt.data(), send_dis.data(), mpi_type(T(0)),
236 (
void *)recvbuf.data(), recv_cnt.data(), recv_dis.data(), mpi_type(T(0)),
245 return MY_Alltoallv64(sendbuf, sendcnts, senddisp, recvbuf, recvcnts, recvdisp, comm);
251 template <
typename T>
252 int MY_Alltoallv(
const std::vector<T> &sendbuf,
const std::vector<int> &sendcnts,
253 const std::vector<int> &senddisp, std::vector<T> &recvbuf,
254 const std::vector<int> &recvcnts,
const std::vector<int> &recvdisp,
257 return MPI_Alltoallv((
void *)sendbuf.data(),
const_cast<int *
>(sendcnts.data()),
258 const_cast<int *>(senddisp.data()), mpi_type(T(0)), recvbuf.data(),
259 const_cast<int *
>(recvcnts.data()), const_cast<int *>(recvdisp.data()),
260 mpi_type(T(0)), comm);
T global_minmax(T local_minmax, MinMax which) const
Definition: Ioss_ParallelUtils.C:366
int64_t generate_guid(size_t id, int rank=-1) const
Definition: Ioss_ParallelUtils.C:256
static int power_2(int count)
Definition: Ioss_Utils.h:174
void attribute_reduction(int length, char buffer[]) const
Definition: Ioss_ParallelUtils.C:272
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
int parallel_rank() const
Definition: Ioss_ParallelUtils.C:214
int parallel_size() const
Definition: Ioss_ParallelUtils.C:203
void hwm_memory_stats(int64_t &min, int64_t &max, int64_t &avg) const
Definition: Ioss_ParallelUtils.C:239
std::vector< int > IntVector
Definition: Ioss_CodeTypes.h:42
std::string decode_filename(const std::string &filename, bool is_parallel) const
Definition: Ioss_ParallelUtils.C:187
Definition: Ioss_ParallelUtils.h:54
Definition: Ioss_ParallelUtils.h:45
void add_environment_properties(Ioss::PropertyManager &properties, bool do_print)
Definition: Ioss_ParallelUtils.C:54
Definition: Ioss_ParallelUtils.h:54
void global_array_minmax(std::vector< T > &local_minmax, MinMax which) const
Definition: Ioss_ParallelUtils.C:453
std::vector< int64_t > Int64Vector
Definition: Ioss_CodeTypes.h:43
void memory_stats(int64_t &min, int64_t &max, int64_t &avg) const
Definition: Ioss_ParallelUtils.C:225
Definition: Ioss_ParallelUtils.h:54
MinMax
Definition: Ioss_ParallelUtils.h:54
MPI_Comm communicator() const
Definition: Ioss_ParallelUtils.h:93
void progress(const std::string &output) const
Definition: Ioss_ParallelUtils.C:512
int rank
Definition: Iocgns_DecompositionData.C:52
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:71
void global_count(const IntVector &local_counts, IntVector &global_counts) const
Definition: Ioss_ParallelUtils.C:292
bool get_environment(const std::string &name, std::string &value, bool sync_parallel) const
Definition: Ioss_ParallelUtils.C:97
ParallelUtils(MPI_Comm the_communicator)
Definition: Ioss_ParallelUtils.C:52
int MPI_Comm
Definition: Ioss_CodeTypes.h:79
MPI_Comm communicator_
Definition: Ioss_ParallelUtils.h:140
void gather(T my_value, std::vector< T > &result) const
Definition: Ioss_ParallelUtils.C:465
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
void all_gather(T my_value, std::vector< T > &result) const
Definition: Ioss_ParallelUtils.C:488