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;
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;
136 template <
typename T>
void all_gather(std::vector<T> &my_values, std::vector<T> &result)
const;
137 template <
typename T>
138 int gather(
int vals_count,
int size_per_val, std::vector<T> &my_values,
139 std::vector<T> &result)
const;
141 void progress(
const std::string &output)
const;
147 #ifdef SEACAS_HAVE_MPI 148 inline MPI_Datatype mpi_type(
double ) {
return MPI_DOUBLE; }
149 inline MPI_Datatype mpi_type(
float ) {
return MPI_FLOAT; }
150 inline MPI_Datatype mpi_type(
int ) {
return MPI_INT; }
151 inline MPI_Datatype mpi_type(
char ) {
return MPI_CHAR; }
152 inline MPI_Datatype mpi_type(
long int ) {
return MPI_LONG_LONG_INT; }
153 inline MPI_Datatype mpi_type(
long long int ) {
return MPI_LONG_LONG_INT; }
154 inline MPI_Datatype mpi_type(
unsigned int ) {
return MPI_UNSIGNED; }
155 inline MPI_Datatype mpi_type(
unsigned long int ) {
return MPI_UNSIGNED_LONG; }
157 template <
typename T>
158 int MY_Alltoallv64(
const std::vector<T> &sendbuf,
const std::vector<int64_t> &sendcounts,
159 const std::vector<int64_t> &senddisp, std::vector<T> &recvbuf,
160 const std::vector<int64_t> &recvcounts,
const std::vector<int64_t> &recvdisp,
163 int processor_count = 0;
164 int my_processor = 0;
165 MPI_Comm_size(comm, &processor_count);
166 MPI_Comm_rank(comm, &my_processor);
170 for (
int i = 0; i < processor_count; i++) {
171 int snd_cnt =
static_cast<int>(sendcounts[i]);
172 if (static_cast<int64_t>(snd_cnt) != sendcounts[i]) {
173 std::ostringstream errmsg;
174 errmsg <<
"ERROR: The number of items that must be communicated via MPI calls from\n" 175 <<
" processor " << my_processor <<
" to processor " << i <<
" is " 177 <<
"\n which exceeds the storage capacity of the integers " 178 "used by MPI functions.\n";
179 std::cerr << errmsg.str();
186 for (
size_t i = 1; i < pow_2; i++) {
190 size_t exchange_proc = i ^ my_processor;
191 if (exchange_proc < static_cast<size_t>(processor_count)) {
192 int snd_cnt =
static_cast<int>(
193 sendcounts[exchange_proc]);
194 int rcv_cnt =
static_cast<int>(recvcounts[exchange_proc]);
195 if (static_cast<size_t>(my_processor) < exchange_proc) {
196 MPI_Send((
void *)&sendbuf[senddisp[exchange_proc]], snd_cnt, mpi_type(T(0)),
197 exchange_proc, tag, comm);
198 MPI_Recv(&recvbuf[recvdisp[exchange_proc]], rcv_cnt, mpi_type(T(0)), exchange_proc, tag,
202 MPI_Recv(&recvbuf[recvdisp[exchange_proc]], rcv_cnt, mpi_type(T(0)), exchange_proc, tag,
204 MPI_Send((
void *)&sendbuf[senddisp[exchange_proc]], snd_cnt, mpi_type(T(0)),
205 exchange_proc, tag, comm);
211 std::copy(&sendbuf[senddisp[my_processor]],
212 &sendbuf[senddisp[my_processor] + sendcounts[my_processor]],
213 &recvbuf[recvdisp[my_processor]]);
217 template <
typename T>
218 int MY_Alltoallv(
const std::vector<T> &sendbuf,
const std::vector<int64_t> &sendcnts,
219 const std::vector<int64_t> &senddisp, std::vector<T> &recvbuf,
220 const std::vector<int64_t> &recvcnts,
const std::vector<int64_t> &recvdisp,
230 int processor_count = 0;
231 MPI_Comm_size(comm, &processor_count);
232 size_t max_comm = sendcnts[processor_count - 1] + senddisp[processor_count - 1];
234 if (max_comm < one << 31) {
236 std::vector<int> send_cnt(sendcnts.begin(), sendcnts.end());
237 std::vector<int> send_dis(senddisp.begin(), senddisp.end());
238 std::vector<int> recv_cnt(recvcnts.begin(), recvcnts.end());
239 std::vector<int> recv_dis(recvdisp.begin(), recvdisp.end());
240 return MPI_Alltoallv((
void *)sendbuf.data(), send_cnt.data(), send_dis.data(), mpi_type(T(0)),
241 (
void *)recvbuf.data(), recv_cnt.data(), recv_dis.data(), mpi_type(T(0)),
250 return MY_Alltoallv64(sendbuf, sendcnts, senddisp, recvbuf, recvcnts, recvdisp, comm);
256 template <
typename T>
257 int MY_Alltoallv(
const std::vector<T> &sendbuf,
const std::vector<int> &sendcnts,
258 const std::vector<int> &senddisp, std::vector<T> &recvbuf,
259 const std::vector<int> &recvcnts,
const std::vector<int> &recvdisp,
262 return MPI_Alltoallv((
void *)sendbuf.data(),
const_cast<int *
>(sendcnts.data()),
263 const_cast<int *>(senddisp.data()), mpi_type(T(0)), recvbuf.data(),
264 const_cast<int *
>(recvcnts.data()), const_cast<int *>(recvdisp.data()),
265 mpi_type(T(0)), comm);
T global_minmax(T local_minmax, MinMax which) const
Definition: Ioss_ParallelUtils.C:386
int64_t generate_guid(size_t id, int rank=-1) const
Definition: Ioss_ParallelUtils.C:276
static int power_2(int count)
Definition: Ioss_Utils.h:174
void attribute_reduction(int length, char buffer[]) const
Definition: Ioss_ParallelUtils.C:292
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
int parallel_rank() const
Definition: Ioss_ParallelUtils.C:234
int parallel_size() const
Definition: Ioss_ParallelUtils.C:223
void hwm_memory_stats(int64_t &min, int64_t &max, int64_t &avg) const
Definition: Ioss_ParallelUtils.C:259
std::vector< int > IntVector
Definition: Ioss_CodeTypes.h:43
std::string decode_filename(const std::string &filename, bool is_parallel) const
Definition: Ioss_ParallelUtils.C:207
Definition: Ioss_ParallelUtils.h:54
Definition: Ioss_ParallelUtils.h:45
void add_environment_properties(Ioss::PropertyManager &properties, bool do_print)
Definition: Ioss_ParallelUtils.C:74
Definition: Ioss_ParallelUtils.h:54
void global_array_minmax(std::vector< T > &local_minmax, MinMax which) const
Definition: Ioss_ParallelUtils.C:455
std::vector< int64_t > Int64Vector
Definition: Ioss_CodeTypes.h:44
void memory_stats(int64_t &min, int64_t &max, int64_t &avg) const
Definition: Ioss_ParallelUtils.C:245
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:538
int rank
Definition: Iocgns_DecompositionData.C:54
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:88
void global_count(const IntVector &local_counts, IntVector &global_counts) const
Definition: Ioss_ParallelUtils.C:312
bool get_environment(const std::string &name, std::string &value, bool sync_parallel) const
Definition: Ioss_ParallelUtils.C:117
ParallelUtils(MPI_Comm the_communicator)
Definition: Ioss_ParallelUtils.C:72
int MPI_Comm
Definition: Ioss_CodeTypes.h:80
MPI_Comm communicator_
Definition: Ioss_ParallelUtils.h:144
void gather(T my_value, std::vector< T > &result) const
Definition: Ioss_ParallelUtils.C:468
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:491