Unverified Commit 2ab43e85 authored by pnorbert's avatar pnorbert Committed by GitHub
Browse files

Merge pull request #1466 from germasch/pr/mpidummy

MPICommOnly / mpidummy cleanup; no-MPI_Init support
parents 3e2361f7 9d87fd63
......@@ -13,8 +13,6 @@
#include "adios2_c_types.h"
#include "adios2/ADIOSMPICommOnly.h"
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -25,14 +25,13 @@ ADIOS::ADIOS(MPI_Comm comm, const bool debugMode) : ADIOS("", comm, debugMode)
{
}
#else
#endif
ADIOS::ADIOS(const std::string &configFile, const bool debugMode)
: m_ADIOS(std::make_shared<core::ADIOS>(configFile, debugMode, "C++"))
{
}
ADIOS::ADIOS(const bool debugMode) : ADIOS("", debugMode) {}
#endif
ADIOS::operator bool() const noexcept { return m_ADIOS ? true : false; }
......
......@@ -64,9 +64,9 @@ public:
* @exception std::invalid_argument in debugMode = true if user input is
* incorrect
*/
ADIOS(const std::string &configFile = "", MPI_Comm comm = MPI_COMM_SELF,
ADIOS(const std::string &configFile, MPI_Comm comm,
const bool debugMode = true);
#else
#endif
/**
* Starting point for non-MPI serial apps. Creates an ADIOS object allowing
......@@ -87,7 +87,6 @@ public:
* incorrect
*/
ADIOS(const bool debugMode = true);
#endif
/** object inspection true: valid object, false: invalid object */
explicit operator bool() const noexcept;
......
......@@ -17,7 +17,6 @@
#include <memory> //std::shared_ptr
#include <string>
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/core/ADIOS.h"
namespace adios2
......
......@@ -13,7 +13,6 @@
#include <pybind11/numpy.h>
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/ADIOSTypes.h"
#include "adios2/core/Stream.h"
......
......@@ -8,12 +8,7 @@
#include "adios2/ADIOSConfig.h"
#ifdef ADIOS2_HAVE_MPI
#include <mpi.h>
#else
#include "adios2/helper/mpidummy.h"
using namespace adios2::helper::mpi;
#endif
#include "adios2/helper/mpiwrap.h"
#include <climits> //UXXX_MAX
#include <cstdint> //SIZE_MAX
......
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*/
#ifndef ADIOS2_ADIOSMPICOMMONLY_H_
#define ADIOS2_ADIOSMPICOMMONLY_H_
#include "adios2/ADIOSConfig.h"
#ifdef ADIOS2_HAVE_MPI
#include <mpi.h>
#else
#ifdef __cplusplus
namespace adios2
{
namespace helper
{
namespace mpi
{
using MPI_Comm = int;
} // end namespace mpi
} // end namespace helper
} // end namespace adios2
namespace adios2
{
using helper::mpi::MPI_Comm;
}
#else
typedef int MPI_Comm;
#endif
#endif
#endif /* ADIOS2_ADIOSMPICOMMONLY_H_ */
......@@ -186,10 +186,10 @@ if(ADIOS2_HAVE_MPI)
engine/insitumpi/InSituMPIFunctions.cpp engine/insitumpi/InSituMPISchedules.cpp
)
target_link_libraries(adios2 PUBLIC MPI::MPI_C)
else()
target_sources(adios2 PRIVATE helper/mpidummy.cpp)
endif()
target_sources(adios2 PRIVATE helper/mpidummy.cpp helper/mpiwrap.cpp)
if(ADIOS2_HAVE_HDF5)
if(HDF5_C_INCLUDE_DIRS)
target_include_directories(adios2 PRIVATE ${HDF5_C_INCLUDE_DIRS})
......@@ -223,7 +223,7 @@ set_target_properties(adios2 PROPERTIES
SOVERSION ${ADIOS2_VERSION_MAJOR}
)
install(FILES ADIOSMacros.h ADIOSTypes.h ADIOSTypes.inl ADIOSMPICommOnly.h
install(FILES ADIOSMacros.h ADIOSTypes.h ADIOSTypes.inl
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/adios2
)
......
......@@ -19,7 +19,7 @@
/// \endcond
#include "adios2/ADIOSConfig.h"
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/ADIOSMPI.h"
#include "adios2/ADIOSTypes.h"
#include "adios2/core/Operator.h"
......
......@@ -69,7 +69,7 @@ void Engine::Close(const int transportIndex)
if (transportIndex == -1)
{
helper::CheckMPIReturn(MPI_Comm_free(&m_MPIComm),
helper::CheckMPIReturn(SMPI_Comm_free(&m_MPIComm),
"freeing comm in Engine " + m_Name +
", in call to Close");
m_IsClosed = true;
......
......@@ -24,7 +24,6 @@
/// \endcond
#include "adios2/ADIOSConfig.h"
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/ADIOSMacros.h"
#include "adios2/ADIOSTypes.h"
#include "adios2/core/IO.h"
......
......@@ -438,7 +438,7 @@ Engine &IO::Open(const std::string &name, const Mode mode,
}
MPI_Comm mpiComm;
MPI_Comm_dup(mpiComm_orig, &mpiComm);
SMPI_Comm_dup(mpiComm_orig, &mpiComm);
std::shared_ptr<Engine> engine;
const bool isDefaultEngine = m_EngineType.empty() ? true : false;
std::string engineTypeLC = m_EngineType;
......
......@@ -21,7 +21,6 @@
/// \endcond
#include "adios2/ADIOSConfig.h"
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/ADIOSMacros.h"
#include "adios2/ADIOSTypes.h"
#include "adios2/core/ADIOS.h"
......
......@@ -13,7 +13,6 @@
#include <memory> //std::shared_ptr
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/ADIOSMacros.h"
#include "adios2/ADIOSTypes.h"
#include "adios2/core/ADIOS.h"
......
......@@ -14,7 +14,6 @@
#include <hdf5.h>
#include "adios2/ADIOSConfig.h"
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/core/Engine.h"
#include "adios2/core/IO.h"
#include "adios2/toolkit/interop/hdf5/HDF5Common.h"
......
......@@ -27,8 +27,8 @@ std::vector<T> GatherValues(const T source, MPI_Comm mpiComm,
const int rankDestination)
{
int rank, size;
MPI_Comm_rank(mpiComm, &rank);
MPI_Comm_size(mpiComm, &size);
SMPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_size(mpiComm, &size);
std::vector<T> output;
......@@ -47,7 +47,7 @@ template <class T>
std::vector<T> AllGatherValues(const T source, MPI_Comm mpiComm)
{
int size;
MPI_Comm_size(mpiComm, &size);
SMPI_Comm_size(mpiComm, &size);
std::vector<T> output(size);
T sourceCopy = source; // so we can have an address for rvalues
......@@ -67,7 +67,7 @@ void GathervVectors(const std::vector<T> &in, std::vector<T> &out,
size_t gatheredSize = 0;
int rank;
MPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_rank(mpiComm, &rank);
if (rank == rankDestination) // pre-allocate vector
{
......
......@@ -32,7 +32,7 @@ size_t BroadcastValue(const size_t &input, MPI_Comm mpiComm,
const int rankSource)
{
int rank;
MPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_rank(mpiComm, &rank);
size_t output = 0;
if (rank == rankSource)
......@@ -40,7 +40,7 @@ size_t BroadcastValue(const size_t &input, MPI_Comm mpiComm,
output = input;
}
MPI_Bcast(&output, 1, ADIOS2_MPI_SIZE_T, rankSource, mpiComm);
SMPI_Bcast(&output, 1, ADIOS2_MPI_SIZE_T, rankSource, mpiComm);
return output;
}
......@@ -50,7 +50,7 @@ std::string BroadcastValue(const std::string &input, MPI_Comm mpiComm,
const int rankSource)
{
int rank;
MPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_rank(mpiComm, &rank);
const size_t inputSize = input.size();
const size_t length = BroadcastValue(inputSize, mpiComm, rankSource);
std::string output;
......@@ -64,8 +64,8 @@ std::string BroadcastValue(const std::string &input, MPI_Comm mpiComm,
output.resize(length);
}
MPI_Bcast(const_cast<char *>(output.data()), static_cast<int>(length),
MPI_CHAR, rankSource, mpiComm);
SMPI_Bcast(const_cast<char *>(output.data()), static_cast<int>(length),
MPI_CHAR, rankSource, mpiComm);
return output;
}
......@@ -77,8 +77,8 @@ unsigned int ReduceValues(const unsigned int source, MPI_Comm mpiComm,
{
unsigned int sourceLocal = source;
unsigned int reduceValue = 0;
MPI_Reduce(&sourceLocal, &reduceValue, 1, MPI_UNSIGNED, operation,
rankDestination, mpiComm);
SMPI_Reduce(&sourceLocal, &reduceValue, 1, MPI_UNSIGNED, operation,
rankDestination, mpiComm);
return reduceValue;
}
......@@ -88,8 +88,8 @@ unsigned long int ReduceValues(const unsigned long int source, MPI_Comm mpiComm,
{
unsigned long int sourceLocal = source;
unsigned long int reduceValue = 0;
MPI_Reduce(&sourceLocal, &reduceValue, 1, MPI_UNSIGNED_LONG, operation,
rankDestination, mpiComm);
SMPI_Reduce(&sourceLocal, &reduceValue, 1, MPI_UNSIGNED_LONG, operation,
rankDestination, mpiComm);
return reduceValue;
}
......@@ -100,8 +100,8 @@ unsigned long long int ReduceValues(const unsigned long long int source,
{
unsigned long long int sourceLocal = source;
unsigned long long int reduceValue = 0;
MPI_Reduce(&sourceLocal, &reduceValue, 1, MPI_UNSIGNED_LONG_LONG, operation,
rankDestination, mpiComm);
SMPI_Reduce(&sourceLocal, &reduceValue, 1, MPI_UNSIGNED_LONG_LONG,
operation, rankDestination, mpiComm);
return reduceValue;
}
......@@ -111,7 +111,7 @@ void BroadcastVector(std::vector<char> &vector, MPI_Comm mpiComm,
const int rankSource)
{
int size;
MPI_Comm_size(mpiComm, &size);
SMPI_Comm_size(mpiComm, &size);
if (size == 1)
{
......@@ -121,7 +121,7 @@ void BroadcastVector(std::vector<char> &vector, MPI_Comm mpiComm,
// First Broadcast the size, then the contents
size_t inputSize = BroadcastValue(vector.size(), mpiComm, rankSource);
int rank;
MPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_rank(mpiComm, &rank);
if (rank != rankSource)
{
......@@ -133,8 +133,8 @@ void BroadcastVector(std::vector<char> &vector, MPI_Comm mpiComm,
char *buffer = vector.data();
while (inputSize > 0)
{
MPI_Bcast(buffer, static_cast<int>(blockSize), MPI_CHAR, rankSource,
mpiComm);
SMPI_Bcast(buffer, static_cast<int>(blockSize), MPI_CHAR, rankSource,
mpiComm);
buffer += blockSize;
inputSize -= blockSize;
blockSize = (inputSize > MAXBCASTSIZE ? MAXBCASTSIZE : inputSize);
......@@ -149,8 +149,8 @@ void GatherArrays(const char *source, const size_t sourceCount,
{
int countsInt = static_cast<int>(sourceCount);
int result =
MPI_Gather(const_cast<char *>(source), countsInt, MPI_CHAR, destination,
countsInt, MPI_CHAR, rankDestination, mpiComm);
SMPI_Gather(const_cast<char *>(source), countsInt, MPI_CHAR,
destination, countsInt, MPI_CHAR, rankDestination, mpiComm);
if (result != MPI_SUCCESS)
{
......@@ -165,9 +165,9 @@ void GatherArrays(const size_t *source, const size_t sourceCount,
const int rankDestination)
{
int countsInt = static_cast<int>(sourceCount);
int result = MPI_Gather(const_cast<size_t *>(source), countsInt,
ADIOS2_MPI_SIZE_T, destination, countsInt,
ADIOS2_MPI_SIZE_T, rankDestination, mpiComm);
int result = SMPI_Gather(const_cast<size_t *>(source), countsInt,
ADIOS2_MPI_SIZE_T, destination, countsInt,
ADIOS2_MPI_SIZE_T, rankDestination, mpiComm);
if (result != MPI_SUCCESS)
{
......@@ -202,7 +202,7 @@ void GathervArrays(const char *source, const size_t sourceCount,
{
int result = 0;
int rank;
MPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_rank(mpiComm, &rank);
std::vector<int> countsInt, displacementsInt;
......@@ -213,9 +213,10 @@ void GathervArrays(const char *source, const size_t sourceCount,
}
int sourceCountInt = static_cast<int>(sourceCount);
result = MPI_Gatherv(const_cast<char *>(source), sourceCountInt, MPI_CHAR,
destination, countsInt.data(), displacementsInt.data(),
MPI_CHAR, rankDestination, mpiComm);
result =
SMPI_Gatherv(const_cast<char *>(source), sourceCountInt, MPI_CHAR,
destination, countsInt.data(), displacementsInt.data(),
MPI_CHAR, rankDestination, mpiComm);
if (result != MPI_SUCCESS)
{
......@@ -232,7 +233,7 @@ void GathervArrays(const size_t *source, const size_t sourceCount,
{
int result = 0;
int rank;
MPI_Comm_rank(mpiComm, &rank);
SMPI_Comm_rank(mpiComm, &rank);
std::vector<int> countsInt =
NewVectorTypeFromArray<size_t, int>(counts, countsSize);
......@@ -242,10 +243,10 @@ void GathervArrays(const size_t *source, const size_t sourceCount,
int sourceCountInt = static_cast<int>(sourceCount);
result = MPI_Gatherv(const_cast<size_t *>(source), sourceCountInt,
ADIOS2_MPI_SIZE_T, destination, countsInt.data(),
displacementsInt.data(), ADIOS2_MPI_SIZE_T,
rankDestination, mpiComm);
result = SMPI_Gatherv(const_cast<size_t *>(source), sourceCountInt,
ADIOS2_MPI_SIZE_T, destination, countsInt.data(),
displacementsInt.data(), ADIOS2_MPI_SIZE_T,
rankDestination, mpiComm);
if (result != MPI_SUCCESS)
{
......
......@@ -31,22 +31,12 @@ namespace adios2
{
namespace helper
{
namespace mpi
namespace mpidummy
{
static char mpierrmsg[MPI_MAX_ERROR_STRING];
int MPI_Init(int * /*argc*/, char *** /*argv*/) { return MPI_SUCCESS; }
int MPI_Init(int * /*argc*/, char *** /*argv*/)
{
mpierrmsg[0] = '\0';
return MPI_SUCCESS;
}
int MPI_Finalize()
{
mpierrmsg[0] = '\0';
return MPI_SUCCESS;
}
int MPI_Finalize() { return MPI_SUCCESS; }
int MPI_Initialized(int *flag)
{
......@@ -98,64 +88,45 @@ int MPI_Comm_free(MPI_Comm *comm)
return MPI_SUCCESS;
}
#ifndef ADIOS2_HAVE_MPI
MPI_Comm MPI_Comm_f2c(MPI_Fint comm) { return comm; }
#endif
int MPI_Gather(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root,
MPI_Comm comm)
{
int ier = MPI_SUCCESS;
size_t n = 0, nsent = 0, nrecv = 0;
if (!sendbuf && !recvbuf)
int n;
size_t nsent = 0, nrecv = 0;
if (sendcnt > 0 && !sendbuf)
{
return ier;
return MPI_ERR_BUFFER;
}
if (comm == MPI_COMM_NULL || root)
{
ier = MPI_ERR_COMM;
}
switch (sendtype)
{
case MPI_CHAR:
n = sizeof(char);
break;
case MPI_INT:
n = sizeof(int);
break;
case MPI_UNSIGNED:
n = sizeof(unsigned int);
break;
case MPI_UNSIGNED_LONG:
n = sizeof(unsigned long);
break;
case MPI_UNSIGNED_LONG_LONG:
n = sizeof(unsigned long long);
break;
default:
return MPI_ERR_TYPE;
if (recvcnt > 0 && !recvbuf)
{
return MPI_ERR_BUFFER;
}
if (root != 0)
{
return MPI_ERR_ROOT;
}
if (comm == MPI_COMM_NULL)
{
return MPI_ERR_COMM;
}
ier = mpidummy::MPI_Type_size(sendtype, &n);
if (ier != MPI_SUCCESS)
{
return ier;
}
nsent = n * sendcnt;
switch (recvtype)
{
case MPI_CHAR:
nrecv = sizeof(char);
break;
case MPI_INT:
nrecv = sizeof(int);
break;
case MPI_UNSIGNED:
nrecv = sizeof(unsigned int);
break;
case MPI_UNSIGNED_LONG:
nrecv = sizeof(unsigned long);
break;
case MPI_UNSIGNED_LONG_LONG:
nrecv = sizeof(unsigned long long);
break;
default:
return MPI_ERR_TYPE;
ier = mpidummy::MPI_Type_size(recvtype, &n);
if (ier != MPI_SUCCESS)
{
return ier;
}
nrecv = n * recvcnt;
......@@ -168,11 +139,6 @@ int MPI_Gather(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
{
std::memcpy(recvbuf, sendbuf, nsent);
}
else
{
std::snprintf(mpierrmsg, MPI_MAX_ERROR_STRING,
"could not gather data\n");
}
return ier;
}
......@@ -184,12 +150,12 @@ int MPI_Gatherv(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
int ier = MPI_SUCCESS;
if (*recvcnts != sendcnt)
{
ier = MPI_ERR_BUFFER;
ier = MPI_ERR_COUNT;
return ier;
}
ier = MPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, *recvcnts, recvtype,
root, comm);
ier = mpidummy::MPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, *recvcnts,
recvtype, root, comm);
return ier;
}
......@@ -197,8 +163,8 @@ int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm)
{
return MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
recvtype, 0, comm);
return mpidummy::MPI_Gather(sendbuf, sendcount, sendtype, recvbuf,
recvcount, recvtype, 0, comm);
}
int MPI_Scatter(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
......@@ -206,34 +172,36 @@ int MPI_Scatter(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
MPI_Comm comm)
{
int ier = MPI_SUCCESS;
size_t n = 0, nsent = 0, nrecv = 0;
if (!sendbuf || !recvbuf)
int n;
size_t nsent = 0, nrecv = 0;
if (sendcnt > 0 && !sendbuf)
{
ier = MPI_ERR_BUFFER;
return MPI_ERR_BUFFER;
}
if (comm == MPI_COMM_NULL || root)
if (recvcnt > 0 && !recvbuf)
{
return MPI_ERR_BUFFER;
}
if (root != 0)
{
return MPI_ERR_ROOT;
}
if (comm == MPI_COMM_NULL)
{
ier = MPI_ERR_COMM;
return MPI_ERR_COMM;
}
switch (sendtype)
ier = mpidummy::MPI_Type_size(sendtype, &n);
if (ier != MPI_SUCCESS)
{
case MPI_INT:
n = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
return ier;
}
nsent = n * sendcnt;
switch (recvtype)
ier = mpidummy::MPI_Type_size(recvtype, &n);
if (ier != MPI_SUCCESS)
{
case MPI_INT:
nrecv = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
return ier;
}
nrecv = n * recvcnt;
......@@ -246,11 +214,6 @@ int MPI_Scatter(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
{
std::memcpy(recvbuf, sendbuf, nsent);
}
else
{
std::snprintf(mpierrmsg, MPI_MAX_ERROR_STRING,
"could not scatter data\n");
}
return ier;
}
......@@ -267,8 +230,8 @@ int MPI_Scatterv(const void *sendbuf, const int *sendcnts, const int *displs,
if (ier == MPI_SUCCESS)
{
ier = MPI_Scatter(sendbuf, *sendcnts, sendtype, recvbuf, recvcnt,
recvtype, root, comm);
ier = mpidummy::MPI_Scatter(sendbuf, *sendcnts, sendtype, recvbuf,
recvcnt, recvtype, root, comm);
}
return ier;
......@@ -304,6 +267,8 @@ int MPI_Isend(const void * /*recvbuffer*/, int /*count*/, MPI_Datatype /*type*/,