Commit 33715618 authored by Brad King's avatar Brad King
Browse files

helper: Factor out MPI-specific Comm interfaces

Create a dedicated header to hold functions to convert between the Comm
encapsulation and MPI_Comm.  In the future the main Comm header will not
need to include raw MPI interfaces at all.
parent 1c62294c
...@@ -33,6 +33,7 @@ add_library(adios2 ...@@ -33,6 +33,7 @@ add_library(adios2
#helper #helper
helper/adiosComm.h helper/adiosComm.cpp helper/adiosComm.h helper/adiosComm.cpp
helper/adiosCommMPI.h helper/adiosCommMPI.cpp
helper/adiosDynamicBinder.h helper/adiosDynamicBinder.cpp helper/adiosDynamicBinder.h helper/adiosDynamicBinder.cpp
helper/adiosMath.cpp helper/adiosMath.cpp
helper/adiosMemory.cpp helper/adiosMemory.cpp
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include <algorithm> // std::transform #include <algorithm> // std::transform
#include <ios> //std::ios_base::failure #include <ios> //std::ios_base::failure
#include "adios2/common/ADIOSMPI.h"
#include "adios2/core/IO.h" #include "adios2/core/IO.h"
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" //InquireKey, BroadcastFile #include "adios2/helper/adiosFunctions.h" //InquireKey, BroadcastFile
// OPERATORS // OPERATORS
...@@ -60,7 +60,7 @@ namespace core ...@@ -60,7 +60,7 @@ namespace core
ADIOS::ADIOS(const std::string configFile, MPI_Comm mpiComm, ADIOS::ADIOS(const std::string configFile, MPI_Comm mpiComm,
const bool debugMode, const std::string hostLanguage) const bool debugMode, const std::string hostLanguage)
: m_ConfigFile(configFile), m_DebugMode(debugMode), : m_ConfigFile(configFile), m_DebugMode(debugMode),
m_HostLanguage(hostLanguage), m_Comm(helper::Comm::Duplicate(mpiComm)) m_HostLanguage(hostLanguage), m_Comm(helper::CommFromMPI(mpiComm))
{ {
if (!configFile.empty()) if (!configFile.empty())
{ {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "adios2/engine/skeleton/SkeletonWriter.h" #include "adios2/engine/skeleton/SkeletonWriter.h"
#include "adios2/helper/adiosComm.h" #include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" //BuildParametersMap #include "adios2/helper/adiosFunctions.h" //BuildParametersMap
#include "adios2/toolkit/profiling/taustubs/tautimer.hpp" #include "adios2/toolkit/profiling/taustubs/tautimer.hpp"
#include <adios2sys/SystemTools.hxx> // FileIsDirectory() #include <adios2sys/SystemTools.hxx> // FileIsDirectory()
...@@ -504,7 +505,7 @@ Engine &IO::Open(const std::string &name, const Mode mode, MPI_Comm mpiComm) ...@@ -504,7 +505,7 @@ Engine &IO::Open(const std::string &name, const Mode mode, MPI_Comm mpiComm)
} }
} }
auto comm = helper::Comm::Duplicate(mpiComm); auto comm = helper::CommFromMPI(mpiComm);
std::shared_ptr<Engine> engine; std::shared_ptr<Engine> engine;
const bool isDefaultEngine = m_EngineType.empty() ? true : false; const bool isDefaultEngine = m_EngineType.empty() ? true : false;
std::string engineTypeLC = m_EngineType; std::string engineTypeLC = m_EngineType;
...@@ -765,7 +766,7 @@ Engine &IO::Open(const std::string &name, const Mode mode, MPI_Comm mpiComm) ...@@ -765,7 +766,7 @@ Engine &IO::Open(const std::string &name, const Mode mode, MPI_Comm mpiComm)
Engine &IO::Open(const std::string &name, const Mode mode) Engine &IO::Open(const std::string &name, const Mode mode)
{ {
return Open(name, mode, m_ADIOS.GetComm().AsMPI()); return Open(name, mode, CommAsMPI(m_ADIOS.GetComm()));
} }
Engine &IO::GetEngine(const std::string &name) Engine &IO::GetEngine(const std::string &name)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "DataSpacesReader.h" #include "DataSpacesReader.h"
#include "DataSpacesReader.tcc" #include "DataSpacesReader.tcc"
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" //CSVToVector #include "adios2/helper/adiosFunctions.h" //CSVToVector
#include "adios2/toolkit/dataspaces/ds_data.h" #include "adios2/toolkit/dataspaces/ds_data.h"
#include "dataspaces.h" #include "dataspaces.h"
...@@ -52,7 +53,7 @@ DataSpacesReader::DataSpacesReader(IO &io, const std::string &name, ...@@ -52,7 +53,7 @@ DataSpacesReader::DataSpacesReader(IO &io, const std::string &name,
{ {
m_ProvideLatest = false; m_ProvideLatest = false;
} }
MPI_Comm mpiComm = m_Comm.AsMPI(); MPI_Comm mpiComm = CommAsMPI(m_Comm);
ret = adios_read_dataspaces_init(&mpiComm, &m_data); ret = adios_read_dataspaces_init(&mpiComm, &m_data);
if (ret < 0) if (ret < 0)
{ {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "DataSpacesWriter.h" #include "DataSpacesWriter.h"
#include "DataSpacesWriter.tcc" #include "DataSpacesWriter.tcc"
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" //CSVToVector #include "adios2/helper/adiosFunctions.h" //CSVToVector
#include "adios2/toolkit/dataspaces/ds_data.h" #include "adios2/toolkit/dataspaces/ds_data.h"
#include "dataspaces.h" #include "dataspaces.h"
...@@ -40,7 +41,7 @@ DataSpacesWriter::DataSpacesWriter(IO &io, const std::string &name, ...@@ -40,7 +41,7 @@ DataSpacesWriter::DataSpacesWriter(IO &io, const std::string &name,
{ {
m_data.appid = 0; m_data.appid = 0;
} }
MPI_Comm mpiComm = m_Comm.AsMPI(); MPI_Comm mpiComm = CommAsMPI(m_Comm);
ret = adios_dataspaces_init(&mpiComm, &m_data); ret = adios_dataspaces_init(&mpiComm, &m_data);
if (ret < 0) if (ret < 0)
fprintf(stderr, "Unable to connect to DataSpaces. Err: %d\n", ret); fprintf(stderr, "Unable to connect to DataSpaces. Err: %d\n", ret);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "HDF5ReaderP.h" #include "HDF5ReaderP.h"
#include "HDF5ReaderP.tcc" #include "HDF5ReaderP.tcc"
#include "adios2/common/ADIOSMPI.h" #include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" //CSVToVector #include "adios2/helper/adiosFunctions.h" //CSVToVector
#include <vector> #include <vector>
...@@ -62,7 +62,7 @@ void HDF5ReaderP::Init() ...@@ -62,7 +62,7 @@ void HDF5ReaderP::Init()
", in call to Open\n"); ", in call to Open\n");
} }
m_H5File.Init(m_Name, m_Comm.AsMPI(), false); m_H5File.Init(m_Name, CommAsMPI(m_Comm), false);
m_H5File.ParseParameters(m_IO); m_H5File.ParseParameters(m_IO);
/* /*
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "HDF5WriterP.h" #include "HDF5WriterP.h"
#include "adios2/common/ADIOSMPI.h" #include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" //CSVToVector #include "adios2/helper/adiosFunctions.h" //CSVToVector
namespace adios2 namespace adios2
...@@ -58,7 +58,7 @@ void HDF5WriterP::Init() ...@@ -58,7 +58,7 @@ void HDF5WriterP::Init()
} }
#ifdef NEVER #ifdef NEVER
m_H5File.Init(m_Name, m_Comm.AsMPI(), true); m_H5File.Init(m_Name, CommAsMPI(m_Comm), true);
#else #else
// enforce .h5 ending // enforce .h5 ending
std::string suffix = ".h5"; std::string suffix = ".h5";
...@@ -71,11 +71,11 @@ void HDF5WriterP::Init() ...@@ -71,11 +71,11 @@ void HDF5WriterP::Init()
{ {
// is a file with .bp ending // is a file with .bp ending
std::string updatedName = m_Name.substr(0, wpos) + suffix; std::string updatedName = m_Name.substr(0, wpos) + suffix;
m_H5File.Init(updatedName, m_Comm.AsMPI(), true); m_H5File.Init(updatedName, CommAsMPI(m_Comm), true);
} }
else else
{ {
m_H5File.Init(m_Name, m_Comm.AsMPI(), true); m_H5File.Init(m_Name, CommAsMPI(m_Comm), true);
} }
m_H5File.ParseParameters(m_IO); m_H5File.ParseParameters(m_IO);
#endif #endif
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "InSituMPIReader.tcc" #include "InSituMPIReader.tcc"
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" // CSVToVector #include "adios2/helper/adiosFunctions.h" // CSVToVector
#include "adios2/toolkit/profiling/taustubs/tautimer.hpp" #include "adios2/toolkit/profiling/taustubs/tautimer.hpp"
...@@ -38,7 +39,7 @@ InSituMPIReader::InSituMPIReader(IO &io, const std::string &name, ...@@ -38,7 +39,7 @@ InSituMPIReader::InSituMPIReader(IO &io, const std::string &name,
Init(); Init();
m_RankAllPeers = m_RankAllPeers =
insitumpi::FindPeers(m_Comm.AsMPI(), m_Name, false, m_CommWorld); insitumpi::FindPeers(CommAsMPI(m_Comm), m_Name, false, m_CommWorld);
MPI_Comm_rank(m_CommWorld, &m_GlobalRank); MPI_Comm_rank(m_CommWorld, &m_GlobalRank);
MPI_Comm_size(m_CommWorld, &m_GlobalNproc); MPI_Comm_size(m_CommWorld, &m_GlobalNproc);
m_ReaderRank = m_Comm.Rank(); m_ReaderRank = m_Comm.Rank();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* Author: Norbert Podhorszki pnorbert@ornl.gov * Author: Norbert Podhorszki pnorbert@ornl.gov
*/ */
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosMath.h" #include "adios2/helper/adiosMath.h"
#include "adios2/toolkit/profiling/taustubs/tautimer.hpp" #include "adios2/toolkit/profiling/taustubs/tautimer.hpp"
...@@ -39,7 +40,7 @@ InSituMPIWriter::InSituMPIWriter(IO &io, const std::string &name, ...@@ -39,7 +40,7 @@ InSituMPIWriter::InSituMPIWriter(IO &io, const std::string &name,
m_BP3Serializer.Init(m_IO.m_Parameters, "in call to InSituMPI::Open write"); m_BP3Serializer.Init(m_IO.m_Parameters, "in call to InSituMPI::Open write");
m_RankAllPeers = m_RankAllPeers =
insitumpi::FindPeers(m_Comm.AsMPI(), m_Name, true, m_CommWorld); insitumpi::FindPeers(CommAsMPI(m_Comm), m_Name, true, m_CommWorld);
for (int i = 0; i < m_RankAllPeers.size(); i++) for (int i = 0; i < m_RankAllPeers.size(); i++)
{ {
m_RankToPeerID[m_RankAllPeers[i]] = i; m_RankToPeerID[m_RankAllPeers[i]] = i;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <cstring> #include <cstring>
#include <string> #include <string>
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosFunctions.h" #include "adios2/helper/adiosFunctions.h"
#include "adios2/toolkit/profiling/taustubs/tautimer.hpp" #include "adios2/toolkit/profiling/taustubs/tautimer.hpp"
...@@ -34,7 +35,7 @@ SstReader::SstReader(IO &io, const std::string &name, const Mode mode, ...@@ -34,7 +35,7 @@ SstReader::SstReader(IO &io, const std::string &name, const Mode mode,
Init(); Init();
m_Input = SstReaderOpen(cstr, &Params, m_Comm.AsMPI()); m_Input = SstReaderOpen(cstr, &Params, CommAsMPI(m_Comm));
if (!m_Input) if (!m_Input)
{ {
throw std::runtime_error( throw std::runtime_error(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Author: Greg Eisenhauer * Author: Greg Eisenhauer
*/ */
#include "adios2/helper/adiosCommMPI.h"
#include <memory> #include <memory>
#include "SstParamParser.h" #include "SstParamParser.h"
...@@ -108,7 +109,7 @@ SstWriter::SstWriter(IO &io, const std::string &name, const Mode mode, ...@@ -108,7 +109,7 @@ SstWriter::SstWriter(IO &io, const std::string &name, const Mode mode,
Init(); Init();
m_Output = SstWriterOpen(name.c_str(), &Params, m_Comm.AsMPI()); m_Output = SstWriterOpen(name.c_str(), &Params, CommAsMPI(m_Comm));
if (m_MarshalMethod == SstMarshalBP) if (m_MarshalMethod == SstMarshalBP)
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See * Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details. * accompanying file Copyright.txt for details.
* *
* Comm.cpp * adiosComm.cpp
*/ */
#include "adiosComm.h" #include "adiosComm.h"
...@@ -54,7 +54,7 @@ Comm &Comm::operator=(Comm &&comm) ...@@ -54,7 +54,7 @@ Comm &Comm::operator=(Comm &&comm)
void Comm::swap(Comm &comm) { std::swap(this->m_MPIComm, comm.m_MPIComm); } void Comm::swap(Comm &comm) { std::swap(this->m_MPIComm, comm.m_MPIComm); }
Comm Comm::Duplicate(MPI_Comm mpiComm) Comm Comm::FromMPI(MPI_Comm mpiComm)
{ {
MPI_Comm newComm; MPI_Comm newComm;
SMPI_Comm_dup(mpiComm, &newComm); SMPI_Comm_dup(mpiComm, &newComm);
......
...@@ -65,16 +65,6 @@ public: ...@@ -65,16 +65,6 @@ public:
*/ */
void swap(Comm &comm); void swap(Comm &comm);
/**
* @brief Get the underlying raw MPI communicator.
*/
MPI_Comm AsMPI() const { return m_MPIComm; }
/**
* @brief Create a communicator by duplicating a MPI communicator.
*/
static Comm Duplicate(MPI_Comm mpiComm);
/** /**
* @brief Free the communicator. * @brief Free the communicator.
* @param hint Description of std::runtime_error exception on error. * @param hint Description of std::runtime_error exception on error.
...@@ -291,6 +281,11 @@ private: ...@@ -291,6 +281,11 @@ private:
/** Return MPI datatype id for type T. */ /** Return MPI datatype id for type T. */
template <typename T> template <typename T>
static MPI_Datatype Datatype(); static MPI_Datatype Datatype();
friend Comm CommFromMPI(MPI_Comm mpiComm);
friend MPI_Comm CommAsMPI(Comm const &comm);
MPI_Comm AsMPI() const { return m_MPIComm; }
static Comm FromMPI(MPI_Comm mpiComm);
}; };
class Comm::Req class Comm::Req
......
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adiosCommMPI.cpp
*/
#include "adiosCommMPI.h"
#include <utility>
#include "adiosComm.h"
#include "adios2/common/ADIOSMPI.h"
namespace adios2
{
namespace helper
{
Comm CommFromMPI(MPI_Comm mpiComm)
{
// Forward to the private API.
return Comm::FromMPI(mpiComm);
}
MPI_Comm CommAsMPI(Comm const &comm)
{
// Forward to the private API.
return comm.AsMPI();
}
} // end namespace helper
} // end namespace adios2
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adiosCommMPI.h : MPI-specific Comm APIs
*/
#ifndef ADIOS2_HELPER_ADIOSCOMMMPI_H_
#define ADIOS2_HELPER_ADIOSCOMMMPI_H_
#include "adiosComm.h"
#include "adios2/common/ADIOSMPI.h"
namespace adios2
{
namespace helper
{
/**
* @brief Create a communicator by duplicating a MPI communicator.
*/
Comm CommFromMPI(MPI_Comm mpiComm);
/**
* @brief Get the underlying raw MPI communicator.
*
* Returns MPI_COMM_NULL if the communicator is empty or is not
* backed by MPI.
*/
MPI_Comm CommAsMPI(Comm const &comm);
} // end namespace helper
} // end namespace adios2
#endif // ADIOS2_HELPER_ADIOSCOMMMPI_H_
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment