changed: move variadic broadcast into EclMpiSerializer

This commit is contained in:
Arne Morten Kvarving
2022-09-07 13:43:23 +02:00
parent 9e6574115a
commit 6e83e349d6
5 changed files with 56 additions and 66 deletions

View File

@@ -237,59 +237,6 @@ void unpack(std::bitset<Size>& data, std::vector<char>& buffer, int& position,
ADD_PACK_PROTOTYPES(std::string)
ADD_PACK_PROTOTYPES(time_point)
template<typename T, typename... Args>
void variadic_packsize(size_t& size, Parallel::Communication comm, T& first, Args&&... args)
{
size += packSize(first, comm);
if constexpr (sizeof...(args) > 0)
variadic_packsize(size, comm, std::forward<Args>(args)...);
}
template<typename T, typename... Args>
void variadic_pack(int& pos, std::vector<char>& buffer, Parallel::Communication comm, T& first, Args&&... args)
{
pack(first, buffer, pos, comm);
if constexpr (sizeof...(args) > 0)
variadic_pack(pos, buffer, comm, std::forward<Args>(args)...);
}
template<typename T, typename... Args>
void variadic_unpack(int& pos, std::vector<char>& buffer, Parallel::Communication comm, T& first, Args&&... args)
{
unpack(first, buffer, pos, comm);
if constexpr (sizeof...(args) > 0)
variadic_unpack(pos, buffer, comm, std::forward<Args>(args)...);
}
#if HAVE_MPI
template<typename... Args>
void broadcast(Parallel::Communication comm, int root, Args&&... args)
{
if (comm.size() == 1)
return;
size_t size = 0;
if (comm.rank() == root)
variadic_packsize(size, comm, args...);
comm.broadcast(&size, 1, root);
std::vector<char> buffer(size);
if (comm.rank() == root) {
int pos = 0;
variadic_pack(pos, buffer, comm, args...);
}
comm.broadcast(buffer.data(), size, root);
if (comm.rank() != root) {
int pos = 0;
variadic_unpack(pos, buffer, comm, std::forward<Args>(args)...);
}
}
#else
template<typename... Args>
void broadcast(Parallel::Communication, int, Args&&...)
{}
#endif
} // end namespace Mpi
} // end namespace Opm

View File

@@ -42,7 +42,6 @@
namespace Opm {
void eclStateBroadcast(Parallel::Communication comm, EclipseState& eclState, Schedule& schedule,
SummaryConfig& summaryConfig,
UDQState& udqState,
@@ -50,12 +49,7 @@ void eclStateBroadcast(Parallel::Communication comm, EclipseState& eclState, Sch
WellTestState& wtestState)
{
Opm::EclMpiSerializer ser(comm);
ser.broadcast(eclState);
ser.broadcast(schedule);
ser.broadcast(summaryConfig);
ser.broadcast(udqState);
ser.broadcast(actionState);
ser.broadcast(wtestState);
ser.broadcast(0, eclState, schedule, summaryConfig, udqState, actionState, wtestState);
}
template <class T>
@@ -65,7 +59,6 @@ void eclBroadcast(Parallel::Communication comm, T& data)
ser.broadcast(data);
}
template void eclBroadcast<TransMult>(Parallel::Communication, TransMult&);
template void eclBroadcast<Schedule>(Parallel::Communication, Schedule&);