Skip to content

Commit

Permalink
Add MPI_CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 19, 2024
1 parent 1250cda commit 2ba06f6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ std::optional<size_t> joinedDimension(adios2::Dims const &dims)

#if openPMD_HAVE_MPI

#define MPI_CHECK(cmd) \
do \
{ \
int error = cmd; \
if (error != MPI_SUCCESS) \
{ \
std::cerr << "<" << __FILE__ << ">:" << __LINE__; \
throw std::runtime_error(std::string("[MPI] Error")); \
} \
} while (false);

ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
AbstractIOHandler *handler,
MPI_Comm communicator,
Expand Down Expand Up @@ -1461,8 +1472,8 @@ namespace
std::get<std::vector<T>>(put_result_here_in);
std::cout << "INIT VECTOR SIZE: " << put_result_here.size() << '\n';
size_t num_items = put_result_here.size();
MPI_Bcast(
&num_items, 1, auxiliary::openPMD_MPI_type<size_t>(), 0, comm);
MPI_CHECK(MPI_Bcast(
&num_items, 1, auxiliary::openPMD_MPI_type<size_t>(), 0, comm));
std::cout << "WILL_COMMUNICATE: " << num_items << '\n';
if constexpr (
std::is_same_v<T, std::string> ||
Expand Down Expand Up @@ -1492,12 +1503,12 @@ namespace
[](T const &arr) { return arr.size(); });
}
sizes.resize(num_items);
MPI_Bcast(
MPI_CHECK(MPI_Bcast(
sizes.data(),
num_items,
auxiliary::openPMD_MPI_type<size_t>(),
0,
comm);
comm));
std::cout << "SIZES: " << vec_as_string(sizes) << '\n';
size_t total_flat_size =
std::accumulate(sizes.begin(), sizes.end(), size_t(0));
Expand All @@ -1515,12 +1526,12 @@ namespace
}
}
flat_vector.resize(total_flat_size);
MPI_Bcast(
MPI_CHECK(MPI_Bcast(
flat_vector.data(),
total_flat_size,
auxiliary::openPMD_MPI_type<flat_type>(),
0,
comm);
comm));
if (rank != 0)
{
std::cout << "RECEIVED: " << vec_as_string(flat_vector)
Expand All @@ -1543,12 +1554,12 @@ namespace
{
receive.resize(num_items);
}
MPI_Bcast(
MPI_CHECK(MPI_Bcast(
rank == 0 ? put_result_here.data() : receive.data(),
num_items,
auxiliary::openPMD_MPI_type<T>(),
0,
comm);
comm));
if (rank != 0)
{
std::cout << "RECEIVED: " << vec_as_string(receive) << '\n';
Expand Down Expand Up @@ -1596,7 +1607,7 @@ void ADIOS2IOHandlerImpl::readAttributeAllsteps(
{
type = read_from_file_in_serial();
}
MPI_Bcast(&type, 1, MPI_INT, 0, *m_communicator);
MPI_CHECK(MPI_Bcast(&type, 1, MPI_INT, 0, *m_communicator));
switchType<DistributeToAllRanks>(
type, *param.resource, *m_communicator, rank);
#else
Expand Down

0 comments on commit 2ba06f6

Please sign in to comment.