diff --git a/.clang-format b/.clang-format index b684a9d53eb8568ec9dd9656cbeb954219932d55..455bf99fe1ea498f7868b65c0949ca1b9135754d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,7 @@ Language: Cpp BasedOnStyle: LLVM BreakBeforeBraces: Allman -IndentCaseLabels: true ConstructorInitializerIndentWidth: 0 +IndentWidth: 4 +ContinuationIndentWidth: 4 +AccessModifierOffset: -4 diff --git a/bindings/python/include/ADIOSPy.h b/bindings/python/include/ADIOSPy.h index 925e7f24455ae4ef605447ed5d551c1778f7c104..f6d6ebb742ce1144a2c93dbf1f2db41ee504392b 100644 --- a/bindings/python/include/ADIOSPy.h +++ b/bindings/python/include/ADIOSPy.h @@ -48,25 +48,25 @@ class ADIOSPy : public ADIOS { public: - ADIOSPy(MPI_Comm mpiComm, const bool debug); - ~ADIOSPy(); + ADIOSPy(MPI_Comm mpiComm, const bool debug); + ~ADIOSPy(); - void HelloMPI(); ///< says hello from rank/size for testing + void HelloMPI(); ///< says hello from rank/size for testing - VariablePy DefineVariablePy(const std::string name, - const pyList localDimensionsPy = pyList(), - const pyList globalDimensionsPy = pyList(), - const pyList globalOffsetsPy = pyList()); + VariablePy DefineVariablePy(const std::string name, + const pyList localDimensionsPy = pyList(), + const pyList globalDimensionsPy = pyList(), + const pyList globalOffsetsPy = pyList()); - MethodPy &DeclareMethodPy(const std::string methodName); + MethodPy &DeclareMethodPy(const std::string methodName); - EnginePy OpenPy(const std::string name, const std::string accessMode, - const MethodPy &method, pyObject py_comm = pyObject()); + EnginePy OpenPy(const std::string name, const std::string accessMode, + const MethodPy &method, pyObject py_comm = pyObject()); - void DefineVariableType(VariablePy &variablePy); + void DefineVariableType(VariablePy &variablePy); private: - std::set<std::string> m_VariablesPyNames; + std::set<std::string> m_VariablesPyNames; }; } // end namespace diff --git a/bindings/python/include/EnginePy.h b/bindings/python/include/EnginePy.h index 8e4be5c15e44f4f4a2a100eb2f72042cb7b02dc4..437247f5be634fff88d27a9ffda705ed1a95bafe 100644 --- a/bindings/python/include/EnginePy.h +++ b/bindings/python/include/EnginePy.h @@ -42,39 +42,40 @@ class EnginePy { public: - EnginePy(ADIOSPy &adiosPy); + EnginePy(ADIOSPy &adiosPy); - ~EnginePy(); + ~EnginePy(); - std::shared_ptr<Engine> m_Engine; + std::shared_ptr<Engine> m_Engine; - void WritePy(VariablePy &variable, const pyArray &array); + void WritePy(VariablePy &variable, const pyArray &array); - void Advance(); + void Advance(); - void Close(); + void Close(); - void GetEngineType() const; + void GetEngineType() const; private: - ADIOSPy &m_ADIOSPy; - bool m_IsVariableTypeDefined = false; - - template <class T> void DefineVariableInADIOS(VariablePy &variable) - { - auto &var = m_ADIOSPy.DefineVariable<T>( - variable.m_Name, variable.m_LocalDimensions, - variable.m_GlobalDimensions, variable.m_GlobalOffsets); - variable.m_VariablePtr = &var; - variable.m_IsVariableDefined = true; - } - - template <class T> - void WriteVariableInADIOS(VariablePy &variable, const pyArray &array) - { - m_Engine->Write(*reinterpret_cast<Variable<T> *>(variable.m_VariablePtr), - PyArrayToPointer<T>(array)); - } + ADIOSPy &m_ADIOSPy; + bool m_IsVariableTypeDefined = false; + + template <class T> void DefineVariableInADIOS(VariablePy &variable) + { + auto &var = m_ADIOSPy.DefineVariable<T>( + variable.m_Name, variable.m_LocalDimensions, + variable.m_GlobalDimensions, variable.m_GlobalOffsets); + variable.m_VariablePtr = &var; + variable.m_IsVariableDefined = true; + } + + template <class T> + void WriteVariableInADIOS(VariablePy &variable, const pyArray &array) + { + m_Engine->Write( + *reinterpret_cast<Variable<T> *>(variable.m_VariablePtr), + PyArrayToPointer<T>(array)); + } }; } // end namespace diff --git a/bindings/python/include/MethodPy.h b/bindings/python/include/MethodPy.h index 3ab8b003196b9443e0338ede51a25b34d4ddb3ed..5bdb9a3aa082aeccd2c5d254e0036e36e981066d 100644 --- a/bindings/python/include/MethodPy.h +++ b/bindings/python/include/MethodPy.h @@ -41,21 +41,21 @@ class MethodPy : public Method { public: - MethodPy(const std::string type, const bool debugMode); + MethodPy(const std::string type, const bool debugMode); - ~MethodPy(); + ~MethodPy(); #ifdef HAVE_BOOSTPYTHON - static pyObject SetParametersPy(pyTuple args, pyDict kwargs); - static pyObject AddTransportPy(pyTuple args, pyDict kwargs); + static pyObject SetParametersPy(pyTuple args, pyDict kwargs); + static pyObject AddTransportPy(pyTuple args, pyDict kwargs); #endif #ifdef HAVE_PYBIND11 - void SetParametersPyBind11(pybind11::kwargs kwargs); - void AddTransportPyBind11(const std::string type, pybind11::kwargs kwargs); + void SetParametersPyBind11(pybind11::kwargs kwargs); + void AddTransportPyBind11(const std::string type, pybind11::kwargs kwargs); #endif - void PrintAll() const; + void PrintAll() const; }; } diff --git a/bindings/python/include/VariablePy.h b/bindings/python/include/VariablePy.h index 8d843bae20b5a0a2a4c36f230ebe38a809a8659b..91b71be593dac143c5505111ac525aa4e2f5cc69 100644 --- a/bindings/python/include/VariablePy.h +++ b/bindings/python/include/VariablePy.h @@ -29,25 +29,25 @@ class VariablePy { public: - VariablePy(const std::string name, const pyList localDimensionsPy, - const pyList globalDimensionsPy, const pyList globalOffsetsPy); + VariablePy(const std::string name, const pyList localDimensionsPy, + const pyList globalDimensionsPy, const pyList globalOffsetsPy); - ~VariablePy(); + ~VariablePy(); - void SetLocalDimensions(const pyList list); + void SetLocalDimensions(const pyList list); - void SetGlobalDimensionsAndOffsets(const pyList globalDimensions, - const pyList globalOffsets); + void SetGlobalDimensionsAndOffsets(const pyList globalDimensions, + const pyList globalOffsets); - Dims GetLocalDimensions(); + Dims GetLocalDimensions(); - void *m_VariablePtr = nullptr; - bool m_IsVariableDefined = false; + void *m_VariablePtr = nullptr; + bool m_IsVariableDefined = false; - const std::string m_Name; - Dims m_LocalDimensions; - Dims m_GlobalDimensions; - Dims m_GlobalOffsets; + const std::string m_Name; + Dims m_LocalDimensions; + Dims m_GlobalDimensions; + Dims m_GlobalOffsets; }; } // end namespace diff --git a/bindings/python/include/adiosPyFunctions.h b/bindings/python/include/adiosPyFunctions.h index e64a798b4a6513679b195437c053dc6cf4da3689..8ef0ff9f66c7e1c15f48fcfb627d87b3ee300f5b 100644 --- a/bindings/python/include/adiosPyFunctions.h +++ b/bindings/python/include/adiosPyFunctions.h @@ -67,37 +67,37 @@ KwargsToMap(const pybind11::kwargs &dictionary); template <class T> const T *PyArrayToPointer(const pyArray &array) { #ifdef HAVE_BOOSTPYTHON - return reinterpret_cast<const T *>(array.get_data()); + return reinterpret_cast<const T *>(array.get_data()); #endif #ifdef HAVE_PYBIND11 - return reinterpret_cast<const T *>(array.data()); + return reinterpret_cast<const T *>(array.data()); #endif } template <class T> bool IsType(const pyArray &array) { #ifdef HAVE_BOOSTPYTHON - if (array.get_dtype() == dtype::get_builtin<T>()) - return true; + if (array.get_dtype() == dtype::get_builtin<T>()) + return true; #endif #ifdef HAVE_PYBIND11 - if (pybind11::isinstance<pybind11::array_t<T>>(array)) - return true; + if (pybind11::isinstance<pybind11::array_t<T>>(array)) + return true; #endif - return false; + return false; } template <class T, class U> T PyCast(U object) { #ifdef HAVE_BOOSTPYTHON - return boost::python::extract<T>(object); + return boost::python::extract<T>(object); #endif #ifdef HAVE_PYBIND11 - return pybind11::cast<T>(object); + return pybind11::cast<T>(object); #endif } diff --git a/bindings/python/src/ADIOSPy.cpp b/bindings/python/src/ADIOSPy.cpp index e8dd0e0a0f22df439ab850348156566717272649..6e45ce3970e59404c5b979b20418cd2f71e50141 100644 --- a/bindings/python/src/ADIOSPy.cpp +++ b/bindings/python/src/ADIOSPy.cpp @@ -27,14 +27,14 @@ ADIOSPy::~ADIOSPy() {} void ADIOSPy::HelloMPI() { - std::cout << "Hello ADIOSPy from rank " << m_RankMPI << "/" << m_SizeMPI - << "\n"; + std::cout << "Hello ADIOSPy from rank " << m_RankMPI << "/" << m_SizeMPI + << "\n"; } MethodPy &ADIOSPy::DeclareMethodPy(const std::string methodName) { - Method &method = DeclareMethod(methodName); - return *reinterpret_cast<MethodPy *>(&method); + Method &method = DeclareMethod(methodName); + return *reinterpret_cast<MethodPy *>(&method); } VariablePy ADIOSPy::DefineVariablePy(const std::string name, @@ -42,16 +42,16 @@ VariablePy ADIOSPy::DefineVariablePy(const std::string name, const pyList globalDimensionsPy, const pyList globalOffsetsPy) { - if (m_DebugMode == true) - { - if (m_VariablesPyNames.count(name) == 1) - throw std::invalid_argument("ERROR: Variable " + name + - " is already defined\n"); - } - - m_VariablesPyNames.insert(name); - return VariablePy(name, localDimensionsPy, globalDimensionsPy, - globalOffsetsPy); + if (m_DebugMode == true) + { + if (m_VariablesPyNames.count(name) == 1) + throw std::invalid_argument("ERROR: Variable " + name + + " is already defined\n"); + } + + m_VariablesPyNames.insert(name); + return VariablePy(name, localDimensionsPy, globalDimensionsPy, + globalOffsetsPy); } void ADIOSPy::DefineVariableType(VariablePy &variablePy) {} @@ -59,28 +59,29 @@ void ADIOSPy::DefineVariableType(VariablePy &variablePy) {} EnginePy ADIOSPy::OpenPy(const std::string name, const std::string accessMode, const MethodPy &method, pyObject py_comm) { - EnginePy enginePy(*this); - - bool isEmpty = IsEmpty(py_comm); - - if (isEmpty == true) // None - { - enginePy.m_Engine = Open(name, accessMode, method); - } - else - { - if (import_mpi4py() < 0) - throw std::logic_error( - "ERROR: could not import mpi4py communicator in Open " + name + "\n"); - MPI_Comm *comm_p = PyMPIComm_Get(py_comm.ptr()); - if (comm_p == nullptr) - throw std::invalid_argument( - "ERROR: MPI communicator is nullptr in Open " + name + "\n"); - - enginePy.m_Engine = Open(name, accessMode, *comm_p, method); - } - - return enginePy; + EnginePy enginePy(*this); + + bool isEmpty = IsEmpty(py_comm); + + if (isEmpty == true) // None + { + enginePy.m_Engine = Open(name, accessMode, method); + } + else + { + if (import_mpi4py() < 0) + throw std::logic_error( + "ERROR: could not import mpi4py communicator in Open " + name + + "\n"); + MPI_Comm *comm_p = PyMPIComm_Get(py_comm.ptr()); + if (comm_p == nullptr) + throw std::invalid_argument( + "ERROR: MPI communicator is nullptr in Open " + name + "\n"); + + enginePy.m_Engine = Open(name, accessMode, *comm_p, method); + } + + return enginePy; } } // end namespace diff --git a/bindings/python/src/EnginePy.cpp b/bindings/python/src/EnginePy.cpp index 581d0580d98c74700c908a30491d5f41b3272287..20826731f42d8916a8be02d01eadd123df6005dd 100644 --- a/bindings/python/src/EnginePy.cpp +++ b/bindings/python/src/EnginePy.cpp @@ -24,74 +24,74 @@ EnginePy::~EnginePy() {} void EnginePy::WritePy(VariablePy &variable, const pyArray &array) { - if (variable.m_IsVariableDefined == false) // here define variable - { + if (variable.m_IsVariableDefined == false) // here define variable + { + if (IsType<char>(array)) + DefineVariableInADIOS<char>(variable); + else if (IsType<unsigned char>(array)) + DefineVariableInADIOS<unsigned char>(variable); + else if (IsType<short>(array)) + DefineVariableInADIOS<short>(variable); + else if (IsType<unsigned short>(array)) + DefineVariableInADIOS<unsigned short>(variable); + else if (IsType<int>(array)) + DefineVariableInADIOS<int>(variable); + else if (IsType<unsigned int>(array)) + DefineVariableInADIOS<unsigned int>(variable); + else if (IsType<long int>(array)) + DefineVariableInADIOS<long int>(variable); + else if (IsType<unsigned long int>(array)) + DefineVariableInADIOS<unsigned long int>(variable); + else if (IsType<long long int>(array)) + DefineVariableInADIOS<long long int>(variable); + else if (IsType<unsigned long long int>(array)) + DefineVariableInADIOS<unsigned long long int>(variable); + else if (IsType<float>(array)) + DefineVariableInADIOS<float>(variable); + else if (IsType<double>(array)) + DefineVariableInADIOS<double>(variable); + else if (IsType<long double>(array)) + DefineVariableInADIOS<long double>(variable); + else if (IsType<std::complex<float>>(array)) + DefineVariableInADIOS<std::complex<float>>(variable); + else if (IsType<std::complex<double>>(array)) + DefineVariableInADIOS<std::complex<double>>(variable); + else if (IsType<std::complex<long double>>(array)) + DefineVariableInADIOS<std::complex<long double>>(variable); + } + if (IsType<char>(array)) - DefineVariableInADIOS<char>(variable); + WriteVariableInADIOS<char>(variable, array); else if (IsType<unsigned char>(array)) - DefineVariableInADIOS<unsigned char>(variable); + WriteVariableInADIOS<unsigned char>(variable, array); else if (IsType<short>(array)) - DefineVariableInADIOS<short>(variable); + WriteVariableInADIOS<short>(variable, array); else if (IsType<unsigned short>(array)) - DefineVariableInADIOS<unsigned short>(variable); + WriteVariableInADIOS<unsigned short>(variable, array); else if (IsType<int>(array)) - DefineVariableInADIOS<int>(variable); + WriteVariableInADIOS<int>(variable, array); else if (IsType<unsigned int>(array)) - DefineVariableInADIOS<unsigned int>(variable); + WriteVariableInADIOS<unsigned int>(variable, array); else if (IsType<long int>(array)) - DefineVariableInADIOS<long int>(variable); + WriteVariableInADIOS<long int>(variable, array); else if (IsType<unsigned long int>(array)) - DefineVariableInADIOS<unsigned long int>(variable); + WriteVariableInADIOS<unsigned long int>(variable, array); else if (IsType<long long int>(array)) - DefineVariableInADIOS<long long int>(variable); + WriteVariableInADIOS<long long int>(variable, array); else if (IsType<unsigned long long int>(array)) - DefineVariableInADIOS<unsigned long long int>(variable); + WriteVariableInADIOS<unsigned long long int>(variable, array); else if (IsType<float>(array)) - DefineVariableInADIOS<float>(variable); + WriteVariableInADIOS<float>(variable, array); else if (IsType<double>(array)) - DefineVariableInADIOS<double>(variable); + WriteVariableInADIOS<double>(variable, array); else if (IsType<long double>(array)) - DefineVariableInADIOS<long double>(variable); + WriteVariableInADIOS<long double>(variable, array); else if (IsType<std::complex<float>>(array)) - DefineVariableInADIOS<std::complex<float>>(variable); + WriteVariableInADIOS<std::complex<float>>(variable, array); else if (IsType<std::complex<double>>(array)) - DefineVariableInADIOS<std::complex<double>>(variable); + WriteVariableInADIOS<std::complex<double>>(variable, array); else if (IsType<std::complex<long double>>(array)) - DefineVariableInADIOS<std::complex<long double>>(variable); - } - - if (IsType<char>(array)) - WriteVariableInADIOS<char>(variable, array); - else if (IsType<unsigned char>(array)) - WriteVariableInADIOS<unsigned char>(variable, array); - else if (IsType<short>(array)) - WriteVariableInADIOS<short>(variable, array); - else if (IsType<unsigned short>(array)) - WriteVariableInADIOS<unsigned short>(variable, array); - else if (IsType<int>(array)) - WriteVariableInADIOS<int>(variable, array); - else if (IsType<unsigned int>(array)) - WriteVariableInADIOS<unsigned int>(variable, array); - else if (IsType<long int>(array)) - WriteVariableInADIOS<long int>(variable, array); - else if (IsType<unsigned long int>(array)) - WriteVariableInADIOS<unsigned long int>(variable, array); - else if (IsType<long long int>(array)) - WriteVariableInADIOS<long long int>(variable, array); - else if (IsType<unsigned long long int>(array)) - WriteVariableInADIOS<unsigned long long int>(variable, array); - else if (IsType<float>(array)) - WriteVariableInADIOS<float>(variable, array); - else if (IsType<double>(array)) - WriteVariableInADIOS<double>(variable, array); - else if (IsType<long double>(array)) - WriteVariableInADIOS<long double>(variable, array); - else if (IsType<std::complex<float>>(array)) - WriteVariableInADIOS<std::complex<float>>(variable, array); - else if (IsType<std::complex<double>>(array)) - WriteVariableInADIOS<std::complex<double>>(variable, array); - else if (IsType<std::complex<long double>>(array)) - WriteVariableInADIOS<std::complex<long double>>(variable, array); + WriteVariableInADIOS<std::complex<long double>>(variable, array); } void EnginePy::Advance() { m_Engine->Advance(); } @@ -100,7 +100,7 @@ void EnginePy::Close() { m_Engine->Close(-1); } void EnginePy::GetEngineType() const { - std::cout << "Engine type " << m_Engine->m_EngineType << "\n"; + std::cout << "Engine type " << m_Engine->m_EngineType << "\n"; } } // end namespace diff --git a/bindings/python/src/MethodPy.cpp b/bindings/python/src/MethodPy.cpp index 4310de6739be79c1495574d36e54e0229af0fa34..937df58fb72a55456b0f65b6e0be0c0820994793 100644 --- a/bindings/python/src/MethodPy.cpp +++ b/bindings/python/src/MethodPy.cpp @@ -34,66 +34,68 @@ MethodPy::~MethodPy() {} #ifdef HAVE_BOOSTPYTHON pyObject MethodPy::SetParametersPy(pyTuple args, pyDict kwargs) { - if (py::len(args) > 1) - throw std::invalid_argument("ERROR: syntax of Method SetParameters " - "function is incorrect, only use dictionary\n"); - - MethodPy &self = PyCast<MethodPy &>(args[0]); - self.m_Parameters = DictToMap(kwargs); - return args[0]; + if (py::len(args) > 1) + throw std::invalid_argument( + "ERROR: syntax of Method SetParameters " + "function is incorrect, only use dictionary\n"); + + MethodPy &self = PyCast<MethodPy &>(args[0]); + self.m_Parameters = DictToMap(kwargs); + return args[0]; } pyObject MethodPy::AddTransportPy(pyTuple args, pyDict kwargs) { - if (py::len(args) != 2) - throw std::invalid_argument( - "ERROR: syntax of Method AddTransport function is incorrect, only use " - "one string for transport followed by a dictionary for parameters\n"); - - MethodPy &self = PyCast<MethodPy &>(args[0]); - const std::string type = PyCast<std::string>(args[1]); - - auto parameters = DictToMap(kwargs); - parameters.insert(std::make_pair("transport", type)); - self.m_TransportParameters.push_back(parameters); - return args[0]; + if (py::len(args) != 2) + throw std::invalid_argument("ERROR: syntax of Method AddTransport " + "function is incorrect, only use " + "one string for transport followed by a " + "dictionary for parameters\n"); + + MethodPy &self = PyCast<MethodPy &>(args[0]); + const std::string type = PyCast<std::string>(args[1]); + + auto parameters = DictToMap(kwargs); + parameters.insert(std::make_pair("transport", type)); + self.m_TransportParameters.push_back(parameters); + return args[0]; } #endif #ifdef HAVE_PYBIND11 void MethodPy::SetParametersPyBind11(pybind11::kwargs kwargs) { - this->m_Parameters = KwargsToMap(kwargs); + this->m_Parameters = KwargsToMap(kwargs); } void MethodPy::AddTransportPyBind11(const std::string type, pybind11::kwargs kwargs) { - auto parameters = KwargsToMap(kwargs); - parameters.insert(std::make_pair("transport", type)); - this->m_TransportParameters.push_back(parameters); + auto parameters = KwargsToMap(kwargs); + parameters.insert(std::make_pair("transport", type)); + this->m_TransportParameters.push_back(parameters); } #endif void MethodPy::PrintAll() const { - std::cout << "Method parameters\n"; - for (const auto ¶m : m_Parameters) - std::cout << "Parameter: " << param.first << "\t Value: " << param.second - << "\n"; + std::cout << "Method parameters\n"; + for (const auto ¶m : m_Parameters) + std::cout << "Parameter: " << param.first + << "\t Value: " << param.second << "\n"; - std::cout << "\n"; - std::cout << "Transport Parameters\n"; + std::cout << "\n"; + std::cout << "Transport Parameters\n"; - for (const auto &transportParameters : m_TransportParameters) - { - std::cout << "Transport:\n"; - for (const auto ¶m : transportParameters) - std::cout << "Parameter: " << param.first << "\t Value: " << param.second - << "\n"; + for (const auto &transportParameters : m_TransportParameters) + { + std::cout << "Transport:\n"; + for (const auto ¶m : transportParameters) + std::cout << "Parameter: " << param.first + << "\t Value: " << param.second << "\n"; - std::cout << "\n"; - } + std::cout << "\n"; + } } } // end namespace diff --git a/bindings/python/src/VariablePy.cpp b/bindings/python/src/VariablePy.cpp index 7d677d567e1f3a645490300d5bbf90a3fc744117..09d92899e844848a723284f2900b5c6f48ad7076 100644 --- a/bindings/python/src/VariablePy.cpp +++ b/bindings/python/src/VariablePy.cpp @@ -26,14 +26,14 @@ VariablePy::~VariablePy() {} void VariablePy::SetLocalDimensions(const pyList list) { - // this->m_Dimensions = ListToVector( list ); + // this->m_Dimensions = ListToVector( list ); } void VariablePy::SetGlobalDimensionsAndOffsets(const pyList globalDimensions, const pyList globalOffsets) { - // this->m_GlobalDimensions = ListToVector( globalDimensions ); - // this->m_GlobalOffsets = ListToVector( globalOffsets ); + // this->m_GlobalDimensions = ListToVector( globalDimensions ); + // this->m_GlobalOffsets = ListToVector( globalOffsets ); } Dims VariablePy::GetLocalDimensions() { return this->m_LocalDimensions; } diff --git a/bindings/python/src/adiosPyFunctions.cpp b/bindings/python/src/adiosPyFunctions.cpp index 778134179a353f2ba64b2552c24866c8fd199170..92d18b4c0dfe0fe37e959fb4eccafc10632f869f 100644 --- a/bindings/python/src/adiosPyFunctions.cpp +++ b/bindings/python/src/adiosPyFunctions.cpp @@ -24,64 +24,64 @@ namespace py = pybind11; Dims ListToVector(const pyList &list) { - const unsigned int length = py::len(list); - Dims vec; - vec.reserve(length); + const unsigned int length = py::len(list); + Dims vec; + vec.reserve(length); - for (unsigned int i = 0; i < length; i++) - vec.push_back(PyCast<std::size_t>(list[i])); + for (unsigned int i = 0; i < length; i++) + vec.push_back(PyCast<std::size_t>(list[i])); - return vec; + return vec; } #ifdef HAVE_BOOSTPYTHON std::map<std::string, std::string> DictToMap(const pyDict &dictionary) { - std::map<std::string, std::string> parameters; + std::map<std::string, std::string> parameters; - pyList keys = dictionary.keys(); - const unsigned int length = py::len(keys); + pyList keys = dictionary.keys(); + const unsigned int length = py::len(keys); - for (unsigned int k = 0; k < length; ++k) - { - const std::string key(PyCast<std::string>(keys[k])); - const std::string value(PyCast<std::string>(dictionary[keys[k]])); - parameters.insert(std::make_pair(key, value)); - } + for (unsigned int k = 0; k < length; ++k) + { + const std::string key(PyCast<std::string>(keys[k])); + const std::string value(PyCast<std::string>(dictionary[keys[k]])); + parameters.insert(std::make_pair(key, value)); + } - return parameters; + return parameters; } #endif #ifdef HAVE_PYBIND11 std::map<std::string, std::string> KwargsToMap(const pybind11::kwargs &kwargs) { - std::map<std::string, std::string> parameters; - - for (const auto &pair : kwargs) - { - const std::string key(PyCast<std::string>(pair.first)); - const std::string value(PyCast<std::string>(pair.second)); - parameters.insert(std::make_pair(key, value)); - } - return parameters; + std::map<std::string, std::string> parameters; + + for (const auto &pair : kwargs) + { + const std::string key(PyCast<std::string>(pair.first)); + const std::string value(PyCast<std::string>(pair.second)); + parameters.insert(std::make_pair(key, value)); + } + return parameters; } #endif bool IsEmpty(pyObject object) { - bool isEmpty = false; + bool isEmpty = false; #ifdef HAVE_BOOSTPYTHON - if (object == boost::python::object()) - isEmpty = true; + if (object == boost::python::object()) + isEmpty = true; #endif #ifdef HAVE_PYBIND11 - if (object == pybind11::none()) - isEmpty = true; + if (object == pybind11::none()) + isEmpty = true; #endif - return isEmpty; + return isEmpty; } } // end namespace diff --git a/bindings/python/src/glueBoostPython.cpp b/bindings/python/src/glueBoostPython.cpp index 532cec900ed71e7c16266e4974f5e36cf65c81c1..1718700b47dbcfa66a29524b7a437a6aae3eedb4 100644 --- a/bindings/python/src/glueBoostPython.cpp +++ b/bindings/python/src/glueBoostPython.cpp @@ -24,10 +24,10 @@ namespace np = boost::python::numpy; adios::ADIOSPy ADIOSPy(py::object py_comm, const bool debug) { - MPI_Comm *comm_p = PyMPIComm_Get(py_comm.ptr()); - if (comm_p == NULL) - py::throw_error_already_set(); - return adios::ADIOSPy(*comm_p, debug); + MPI_Comm *comm_p = PyMPIComm_Get(py_comm.ptr()); + if (comm_p == NULL) + py::throw_error_already_set(); + return adios::ADIOSPy(*comm_p, debug); } using ReturnInternalReference = py::return_internal_reference<>; @@ -36,39 +36,39 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(open_overloads, adios::ADIOSPy::OpenPy, BOOST_PYTHON_MODULE(ADIOSPy) { - if (import_mpi4py() < 0) - return; /* Python 2.X */ + if (import_mpi4py() < 0) + return; /* Python 2.X */ - Py_Initialize(); - np::initialize(); + Py_Initialize(); + np::initialize(); - py::class_<adios::Dims>("Dims").def( - boost::python::vector_indexing_suite<adios::Dims>()); - // functions - py::def("ADIOSPy", ADIOSPy); + py::class_<adios::Dims>("Dims").def( + boost::python::vector_indexing_suite<adios::Dims>()); + // functions + py::def("ADIOSPy", ADIOSPy); - // classes - py::class_<adios::ADIOSPy>("ADIOS", py::no_init) - .def("HelloMPI", &adios::ADIOSPy::HelloMPI) - .def("DefineVariable", &adios::ADIOSPy::DefineVariablePy) - .def("DeclareMethod", &adios::ADIOSPy::DeclareMethodPy, - ReturnInternalReference()) - .def("Open", &adios::ADIOSPy::OpenPy, open_overloads()); + // classes + py::class_<adios::ADIOSPy>("ADIOS", py::no_init) + .def("HelloMPI", &adios::ADIOSPy::HelloMPI) + .def("DefineVariable", &adios::ADIOSPy::DefineVariablePy) + .def("DeclareMethod", &adios::ADIOSPy::DeclareMethodPy, + ReturnInternalReference()) + .def("Open", &adios::ADIOSPy::OpenPy, open_overloads()); - py::class_<adios::VariablePy>("Variable", py::no_init) - .def("SetLocalDimensions", &adios::VariablePy::SetLocalDimensions) - .def("GetLocalDimensions", &adios::VariablePy::GetLocalDimensions); + py::class_<adios::VariablePy>("Variable", py::no_init) + .def("SetLocalDimensions", &adios::VariablePy::SetLocalDimensions) + .def("GetLocalDimensions", &adios::VariablePy::GetLocalDimensions); - py::class_<adios::MethodPy>("Method", py::no_init) - .def("SetParameters", - py::raw_function(&adios::MethodPy::SetParametersPy, 1)) - .def("AddTransport", - py::raw_function(&adios::MethodPy::AddTransportPy, 1)) - .def("PrintAll", &adios::MethodPy::PrintAll); + py::class_<adios::MethodPy>("Method", py::no_init) + .def("SetParameters", + py::raw_function(&adios::MethodPy::SetParametersPy, 1)) + .def("AddTransport", + py::raw_function(&adios::MethodPy::AddTransportPy, 1)) + .def("PrintAll", &adios::MethodPy::PrintAll); - // Engine - py::class_<adios::EnginePy>("EnginePy", py::no_init) - .def("Write", &adios::EnginePy::WritePy) - .def("Advance", &adios::EnginePy::WritePy) - .def("Close", &adios::EnginePy::Close); + // Engine + py::class_<adios::EnginePy>("EnginePy", py::no_init) + .def("Write", &adios::EnginePy::WritePy) + .def("Advance", &adios::EnginePy::WritePy) + .def("Close", &adios::EnginePy::Close); } diff --git a/bindings/python/src/gluePyBind11.cpp b/bindings/python/src/gluePyBind11.cpp index cd3cc32f700a07d853eb479e53c21d4b10a4228c..dd76c295c061c1b7ae81d776612de46d8412b821 100644 --- a/bindings/python/src/gluePyBind11.cpp +++ b/bindings/python/src/gluePyBind11.cpp @@ -21,43 +21,43 @@ namespace py = pybind11; adios::ADIOSPy ADIOSPy(py::object py_comm, const bool debug) { - MPI_Comm *comm_p = PyMPIComm_Get(py_comm.ptr()); - if (comm_p == NULL) - py::error_already_set(); - return adios::ADIOSPy(*comm_p, debug); + MPI_Comm *comm_p = PyMPIComm_Get(py_comm.ptr()); + if (comm_p == NULL) + py::error_already_set(); + return adios::ADIOSPy(*comm_p, debug); } PYBIND11_PLUGIN(ADIOSPy) { - if (import_mpi4py() < 0) - throw std::runtime_error( - "ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ + if (import_mpi4py() < 0) + throw std::runtime_error( + "ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ - py::module m("ADIOSPy", "ADIOS Python bindings using pybind11"); + py::module m("ADIOSPy", "ADIOS Python bindings using pybind11"); - m.def("ADIOSPy", &ADIOSPy, "Function that creates an ADIOS object"); + m.def("ADIOSPy", &ADIOSPy, "Function that creates an ADIOS object"); - py::class_<adios::ADIOSPy>(m, "ADIOS") - .def("HelloMPI", &adios::ADIOSPy::HelloMPI) - .def("DefineVariable", &adios::ADIOSPy::DefineVariablePy) - .def("DeclareMethod", &adios::ADIOSPy::DeclareMethodPy, - py::return_value_policy::reference_internal) - .def("Open", &adios::ADIOSPy::OpenPy); + py::class_<adios::ADIOSPy>(m, "ADIOS") + .def("HelloMPI", &adios::ADIOSPy::HelloMPI) + .def("DefineVariable", &adios::ADIOSPy::DefineVariablePy) + .def("DeclareMethod", &adios::ADIOSPy::DeclareMethodPy, + py::return_value_policy::reference_internal) + .def("Open", &adios::ADIOSPy::OpenPy); - py::class_<adios::VariablePy>(m, "Variable") - .def("SetLocalDimensions", &adios::VariablePy::SetLocalDimensions) - .def("GetLocalDimensions", &adios::VariablePy::GetLocalDimensions); + py::class_<adios::VariablePy>(m, "Variable") + .def("SetLocalDimensions", &adios::VariablePy::SetLocalDimensions) + .def("GetLocalDimensions", &adios::VariablePy::GetLocalDimensions); - py::class_<adios::MethodPy>(m, "Method") - .def("SetParameters", &adios::MethodPy::SetParametersPyBind11) - .def("AddTransport", &adios::MethodPy::AddTransportPyBind11) - .def("PrintAll", &adios::MethodPy::PrintAll); + py::class_<adios::MethodPy>(m, "Method") + .def("SetParameters", &adios::MethodPy::SetParametersPyBind11) + .def("AddTransport", &adios::MethodPy::AddTransportPyBind11) + .def("PrintAll", &adios::MethodPy::PrintAll); - // Engine - py::class_<adios::EnginePy>(m, "Engine") - .def("Write", &adios::EnginePy::WritePy) - .def("Advance", &adios::EnginePy::WritePy) - .def("Close", &adios::EnginePy::Close); + // Engine + py::class_<adios::EnginePy>(m, "Engine") + .def("Write", &adios::EnginePy::WritePy) + .def("Advance", &adios::EnginePy::WritePy) + .def("Close", &adios::EnginePy::Close); - return m.ptr(); + return m.ptr(); } diff --git a/doc/API_design/API_example_use.cpp b/doc/API_design/API_example_use.cpp index af3fbdbdd7e5db586166bc696f40b3ac9df9cadd..a35146935cf564dea610accee6ad67efdfbe6ce6 100644 --- a/doc/API_design/API_example_use.cpp +++ b/doc/API_design/API_example_use.cpp @@ -6,428 +6,458 @@ void cb_AsyncWriteAdvanceCompleted(std::shared_ptr<adios::Engine> writer) { - std::cout - << "AdvanceAsync() completed. We can modify our zero-copy variables\n"; + std::cout << "AdvanceAsync() completed. We can modify our zero-copy " + "variables\n"; } void cb_AsyncReadAdvanceCompleted(std::shared_ptr<adios::Engine> writer) { - std::cout << "AdvanceAsync() completed. We have new data to read and we have " - "the lock on it\n"; + std::cout + << "AdvanceAsync() completed. We have new data to read and we have " + "the lock on it\n"; } int main(int argc, char *argv[]) { - // Application variables - MPI_Comm comm = MPI_COMM_WORLD; - const unsigned int NX = 10; - double Temperature[1][NX + 2]; // We will want to write only Nx elements, - // skipping the first and last (think ghost - // cells) - std::vector<float> RaggedArray; - - int Nparts, nproc; - - // Global class/object that serves for init, finalize and provides ADIOS - // functions - adios::ADIOS adios("config.xml", comm, /*verbose=*/adios::INFO, - /*debugflag=*/false); - - /************* - * WRITE API - *************/ - - /* Method - * We associate Engines and Transports and user settings into an object called - * Method. - * ADIOS checks if it is defined by the user in the config file, and fills it - * out if it is. - */ - - adios::Method &wmethod = adios.DeclareMethod("WriteMethod"); - if (!wmethod.isUserDefined()) - { - // if not defined by user, we can change the default settings - wmethod.SetEngine("BP"); // BP is the default engine - wmethod.AllowThreads( - 1); // no threading for data processing (except for staging) - wmethod.AddTransport( - "File", "lucky=yes"); // ISO-POSIX file is the default transport - wmethod.AddTransport("Staging"); //"The" staging method developed in ECP - wmethod.SetParameters("have_metadata_file", - "yes"); // Passing parameters to the engine - wmethod.SetParameters("Aggregation", - (nproc + 1) / 2); // number of aggregators - wmethod.SetParameters("verbose", adios::Verbose::WARN); // Verbosity level - // for this engine - // and what it calls - } - - // Define variables with transformations. - adios::Variable<unsigned int> &varNX = adios.DefineVariable<unsigned int>( - "NX"); // global single-value across processes - auto &varNproc = adios.DefineVariable<int>( - "nproc", adios::Dims{adios::GLOBAL_VALUE}); // same def for global value - adios::Variable<int> &varNparts = adios.DefineVariable<int>( - "Nparts", - adios::Dims{ - adios::LOCAL_VALUE}); // a single-value different on every process - adios::Variable<double> &var2D = adios.DefineVariable<double>( - "Temperature", - adios::Dims{nproc, NX}); // 2D global array, 1D decomposition - adios::Variable<float> &varRagged = adios.DefineVariable<float>( - "Ragged", adios::Dims{nproc, adios::VARYING_DIMENSION}); // ragged array - - // add transform to variable - adios::Transform zfp = adios::transform::ZFP(); - var2D.AddTransform(zfp, "accuracy=0.001"); - - // open...write.write.write...advance...write.write.write...advance... - // ...close cycle - // "w" create/overwrite on open, "a" append at open, "u" open for update (does - // not increase step), "r" open for read. - std::shared_ptr<adios::Engine> writer = adios.Open( - "myNumbers.bp", "w", comm, wmethod, adios::IOMode::INDEPENDENT); - - if (writer == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS writer\n"); - - // Zero-Copy API: Define a variable with local dimensions now, and make ADIOS - // allocate it inside its buffers - // This requires an engine created. The variable will be deallocated in - // writer->Close() - // Calling varZeroCopy.SetSelection() later should throw an exception, i.e. - // modification is not allowed - // 2D global array, 1D decomposition - adios::Variable<double> &varZeroCopy = adios.DefineVariable<double>( - "ZC", adios::Dims{nproc, NX}, adios::Dims{1, NX}, adios::Dims{rank, 0}); - double fillValue = -1.0; - double *const myVarZC = - writer->AllocateVariable<double>(varZeroCopy, fillValue); - - for (int step = 0; step < 10; ++step) - { - // write scalar value - writer->Write<int>(varNparts, Nparts); - - // Make a selection to describe the local dimensions of the variable we - // write and - // its offsets in the global spaces. This could have been done in - // adios.DefineVariable() - adios::Selection sel = adios.SelectionBoundingBox( - {1, NX}, {rank, NX}); // local dims and offsets; both as list - var2D.SetSelection( - sel); // Shall we call it SetSpaceSelection, SetOutputSelection? - - // Select the area that we want to write from the data pointer we pass to - // the writer - // Think HDF5 memspace, just not hyperslabs yet, only a bounding box - // selection - // Engine will copy this bounding box from the data pointer into the buffer. - // Size of the bounding box should match the - // "space" selection which was given above. Default memspace is the full - // selection. - adios::Selection memspace = adios.SelectionBoundingBox( - {1, NX}, {0, 1}); // local dims and offsets; both as list - var2D.SetMemorySelection(memspace); - - writer->Write<double>(var2D, *Temperature); - - // Indicate we are done for this step. - // N-to-M Aggregation, disk I/O will be performed during this call, unless - // time aggregation postpones all of that to some later step. - // When Advance() returns, user can overwrite its Zero Copy variables. - // Internal buffer is freed only if there are no Zero Copy variables and - // there is no time aggregation going on - writer->Advance(); // same as AppendMode - writer->Advance(adios::APPEND, 0.0); // append new step at next write - writer->Advance(adios::UPDATE); // do not increase step; - - // When AdvanceAsync returns, user need to wait for notification that he can - // overwrite the Zero Copy variables. - writer->AdvanceAsync(adios::APPEND, cb_AsyncWriteAdvanceCompleted); - } - - // Called once: indicate that we are done with this output for the run - // Zero Copy variables will be deallocated - writer->Close(); - - /************* - * READ API - *************/ - adios::Method &rmethod = adios.DeclareMethod("ReadMethod"); - if (!rmethod.isUserDefined()) - { - // if not defined by user, we can change the default settings - rmethod.SetEngine("BP"); // BP is the default engine - rmethod.AddTransport("Staging"); //"The" staging method developed in ECP - rmethod.SetParameters("Aggregation", - (nproc + 1) / 2); // number of aggregators - rmethod.SetParameters("verbose", adios::Verbose::WARN); // Verbosity level - // for this engine - // and what it calls - } - - // 1. Open a stream, where every reader can see everything in a stream (so - // that they can read a global array) - // Blocking read of a variable - try - { - // These method settings are developer-only, not available to the user - rmethod.SetReadMultiplexPattern(adios::GLOBAL_READERS); // Each reader - // process sees - // everything from - // the stream - rmethod.SetStreamOpenMode(adios::WAITFORSTREAM); // In Open(), wait for the - // first step appear - // (default) - - // Open a stream - std::shared_ptr<adios::Engine> reader = - adios.Open("filename.bp", "r", comm, rmethod, adios::IOMode::COLLECTIVE, - /*timeout_sec=*/300.0); // wait this long for the stream, - // return error afterwards - - /* Variable names are available as a vector of strings */ - std::cout << "List of variables in file: " << reader->VariableNames() - << "\n"; - /* read a Global scalar which has a single value in a step */ - reader->Read<unsigned int>("NX", NX); - - // inquiry about a variable, whose name we know - adios::Variable<double> var2D = - reader->InquireVariableDouble("Temperature"); - std::vector<std::size_t> gdims = var2D.GetGlobalDimensions(); - int nsteps = var2D.GetSteps(); - - struct adios::BlockInfo blocks = reader.InquiryVariableBlockInfo( - reader, var2D); // get per-writer size info - // this is adios1 ADIOS_VARBLOCK - struct adios::Statistics stats = reader.InquiryVariableStat( - reader, var2D, perstepstat, perblockstat); // get min/max statistics - // this is adios1 ADIOS_VARSTAT - - while (true) + // Application variables + MPI_Comm comm = MPI_COMM_WORLD; + const unsigned int NX = 10; + double Temperature[1][NX + 2]; // We will want to write only Nx elements, + // skipping the first and last (think ghost + // cells) + std::vector<float> RaggedArray; + + int Nparts, nproc; + + // Global class/object that serves for init, finalize and provides ADIOS + // functions + adios::ADIOS adios("config.xml", comm, /*verbose=*/adios::INFO, + /*debugflag=*/false); + + /************* + * WRITE API + *************/ + + /* Method + * We associate Engines and Transports and user settings into an object + * called + * Method. + * ADIOS checks if it is defined by the user in the config file, and fills + * it + * out if it is. + */ + + adios::Method &wmethod = adios.DeclareMethod("WriteMethod"); + if (!wmethod.isUserDefined()) { - // Make a selection to describe the local dimensions of the variable we - // READ and - // its offsets in the global spaces - adios::Selection bbsel = adios.SelectionBoundingBox( - {1, NX}, {0, 0}); // local dims and offsets; both as list - var2D.SetSelection(bbsel); - adios::Selection memspace = adios.SelectionBoundingBox( - {1, NX}, {0, 1}); // local dims and offsets; both as list - var2D.SetMemorySelection(memspace); - reader->Read<double>(var2D, *Temperature); - // var2D, Temperature ); - - // Better for staging to schedule several reads at once - reader->ScheduleRead<double>(var2D, *Temperature); - reader->PerformReads(adios::BLOCKINGREAD); - - // promise to not read more from this step/item - reader->Release(); - - // want to move on to the next available step/item - reader->Advance(adios::NEXT_AVAILABLE); // default - reader->Advance( - adios::LATEST_AVAILABLE); // interested only in the latest data + // if not defined by user, we can change the default settings + wmethod.SetEngine("BP"); // BP is the default engine + wmethod.AllowThreads( + 1); // no threading for data processing (except for staging) + wmethod.AddTransport( + "File", "lucky=yes"); // ISO-POSIX file is the default transport + wmethod.AddTransport("Staging"); //"The" staging method developed in ECP + wmethod.SetParameters("have_metadata_file", + "yes"); // Passing parameters to the engine + wmethod.SetParameters("Aggregation", + (nproc + 1) / 2); // number of aggregators + wmethod.SetParameters("verbose", + adios::Verbose::WARN); // Verbosity level + // for this engine + // and what it calls } - // Close file/stream - reader->Close(); - } - catch (adios::end_of_stream &e) - { - // Reached end of stream, end processing loop - // Close file/stream - reader->Close(); - } - catch (adios::file_not_found &e) - { - // File/stream does not exist, quit - } - - // 2. Open a stream, where each item from the writers will get to a single - // reader only - // If the writers are collective, that means a whole steps go to different - // readers - // If the writers are independent, that means each writer's output goes to - // different readers - // Also show here ScheduleRead/PerformRead - // try - { - rmethod.SetReadMultiplexPattern(adios::FIFO_READERS); // Each reader process - // sees everything - // from the stream - rmethod.SetStreamOpenMode(adios::WAITFORSTREAM); // In Open(), wait for the - // first step appear - // (default) - - // Open a stream - std::shared_ptr<adios::Engine> reader = adios.Open( - "filename.bp", "r", comm, rmethod, adios::IOMode::INDEPENDENT, - /*timeout_sec=*/300.0); // wait this long for the stream, return error - // afterwards - - while (true) + + // Define variables with transformations. + adios::Variable<unsigned int> &varNX = adios.DefineVariable<unsigned int>( + "NX"); // global single-value across processes + auto &varNproc = adios.DefineVariable<int>( + "nproc", adios::Dims{adios::GLOBAL_VALUE}); // same def for global value + adios::Variable<int> &varNparts = adios.DefineVariable<int>( + "Nparts", adios::Dims{adios::LOCAL_VALUE}); // a single-value + // different on every + // process + adios::Variable<double> &var2D = adios.DefineVariable<double>( + "Temperature", + adios::Dims{nproc, NX}); // 2D global array, 1D decomposition + adios::Variable<float> &varRagged = adios.DefineVariable<float>( + "Ragged", adios::Dims{nproc, adios::VARYING_DIMENSION}); // ragged array + + // add transform to variable + adios::Transform zfp = adios::transform::ZFP(); + var2D.AddTransform(zfp, "accuracy=0.001"); + + // open...write.write.write...advance...write.write.write...advance... + // ...close cycle + // "w" create/overwrite on open, "a" append at open, "u" open for update + // (does + // not increase step), "r" open for read. + std::shared_ptr<adios::Engine> writer = adios.Open( + "myNumbers.bp", "w", comm, wmethod, adios::IOMode::INDEPENDENT); + + if (writer == nullptr) + throw std::ios_base::failure("ERROR: failed to open ADIOS writer\n"); + + // Zero-Copy API: Define a variable with local dimensions now, and make + // ADIOS + // allocate it inside its buffers + // This requires an engine created. The variable will be deallocated in + // writer->Close() + // Calling varZeroCopy.SetSelection() later should throw an exception, i.e. + // modification is not allowed + // 2D global array, 1D decomposition + adios::Variable<double> &varZeroCopy = adios.DefineVariable<double>( + "ZC", adios::Dims{nproc, NX}, adios::Dims{1, NX}, adios::Dims{rank, 0}); + double fillValue = -1.0; + double *const myVarZC = + writer->AllocateVariable<double>(varZeroCopy, fillValue); + + for (int step = 0; step < 10; ++step) { - // Make a selection to describe the local dimensions of the variable we - // READ and - // its offsets in the global spaces if we know this somehow - adios::Selection bbsel = adios.SelectionBoundingBox( - {1, NX}, {0, 0}); // local dims and offsets; both as list - var2D->SetSelection(bbsel); - reader->Read<double>(var2D, *Temperature); - - // Let ADIOS allocate space for the incoming (per-writer) item - double *data = reader->Read<double>(var2D); - - // promise to not read more from this step/item - reader->Release(); - - // want to move on to the next available step/item - reader->Advance(); // default - reader->Advance(adios::LATEST_AVAILABLE); // This should be an error, or - // could it make sense? + // write scalar value + writer->Write<int>(varNparts, Nparts); + + // Make a selection to describe the local dimensions of the variable we + // write and + // its offsets in the global spaces. This could have been done in + // adios.DefineVariable() + adios::Selection sel = adios.SelectionBoundingBox( + {1, NX}, {rank, NX}); // local dims and offsets; both as list + var2D.SetSelection( + sel); // Shall we call it SetSpaceSelection, SetOutputSelection? + + // Select the area that we want to write from the data pointer we pass + // to + // the writer + // Think HDF5 memspace, just not hyperslabs yet, only a bounding box + // selection + // Engine will copy this bounding box from the data pointer into the + // buffer. + // Size of the bounding box should match the + // "space" selection which was given above. Default memspace is the full + // selection. + adios::Selection memspace = adios.SelectionBoundingBox( + {1, NX}, {0, 1}); // local dims and offsets; both as list + var2D.SetMemorySelection(memspace); + + writer->Write<double>(var2D, *Temperature); + + // Indicate we are done for this step. + // N-to-M Aggregation, disk I/O will be performed during this call, + // unless + // time aggregation postpones all of that to some later step. + // When Advance() returns, user can overwrite its Zero Copy variables. + // Internal buffer is freed only if there are no Zero Copy variables and + // there is no time aggregation going on + writer->Advance(); // same as AppendMode + writer->Advance(adios::APPEND, 0.0); // append new step at next write + writer->Advance(adios::UPDATE); // do not increase step; + + // When AdvanceAsync returns, user need to wait for notification that he + // can + // overwrite the Zero Copy variables. + writer->AdvanceAsync(adios::APPEND, cb_AsyncWriteAdvanceCompleted); } - reader->Close(); - } - - // 3. Open a stream and return immediately, not waiting for data to appear - // In this mode we cannot inquiry variables, but can schedule reads - // try - { - rmethod.SetReadMultiplexPattern(adios::GLOBAL_READERS); // Each reader - // process sees - // everything from - // the stream - rmethod.SetStreamOpenMode(adios::NOWAITFORSTREAM); // In Open(), wait for - // the first step appear - // (default) - - // Open a stream - std::shared_ptr<adios::Engine> reader = adios.Open( - "filename.bp", "r", comm, rmethod, adios::IOMode::INDEPENDENT); - - while (true) + + // Called once: indicate that we are done with this output for the run + // Zero Copy variables will be deallocated + writer->Close(); + + /************* + * READ API + *************/ + adios::Method &rmethod = adios.DeclareMethod("ReadMethod"); + if (!rmethod.isUserDefined()) { + // if not defined by user, we can change the default settings + rmethod.SetEngine("BP"); // BP is the default engine + rmethod.AddTransport("Staging"); //"The" staging method developed in ECP + rmethod.SetParameters("Aggregation", + (nproc + 1) / 2); // number of aggregators + rmethod.SetParameters("verbose", + adios::Verbose::WARN); // Verbosity level + // for this engine + // and what it calls + } - // Let ADIOS allocate space for the incoming (per-writer) item - reader->ScheduleRead(); // read whatever comes - - // One way is to handle the incoming data through a callback (which will - // be called in a thread) - // void cb( const void *data, std::string doid, std::string var, - // std::string dtype, std::vector<std::size_t> varshape ); - // void cb( adios::VARCHUNK * chunk ); // see adios1 for VARCHUNK - reader->SetReadCallback(cb); - reader->PerformReads(adios::NONBLOCKINGREAD); - - // Another way is checking back manually like in adios1 and processing - // chunks - reader->PerformReads(adios::NONBLOCKINGREAD); - int ck; - adios::VARCHUNK *chunk; - try - { - while ((ck = reader->CheckReads(&chunk)) > 0) + // 1. Open a stream, where every reader can see everything in a stream (so + // that they can read a global array) + // Blocking read of a variable + try + { + // These method settings are developer-only, not available to the user + rmethod.SetReadMultiplexPattern(adios::GLOBAL_READERS); // Each reader + // process sees + // everything from + // the stream + rmethod.SetStreamOpenMode( + adios::WAITFORSTREAM); // In Open(), wait for the + // first step appear + // (default) + + // Open a stream + std::shared_ptr<adios::Engine> reader = adios.Open( + "filename.bp", "r", comm, rmethod, adios::IOMode::COLLECTIVE, + /*timeout_sec=*/300.0); // wait this long for the stream, + // return error afterwards + + /* Variable names are available as a vector of strings */ + std::cout << "List of variables in file: " << reader->VariableNames() + << "\n"; + /* read a Global scalar which has a single value in a step */ + reader->Read<unsigned int>("NX", NX); + + // inquiry about a variable, whose name we know + adios::Variable<double> var2D = + reader->InquireVariableDouble("Temperature"); + std::vector<std::size_t> gdims = var2D.GetGlobalDimensions(); + int nsteps = var2D.GetSteps(); + + struct adios::BlockInfo blocks = reader.InquiryVariableBlockInfo( + reader, var2D); // get per-writer size info + // this is adios1 ADIOS_VARBLOCK + struct adios::Statistics stats = + reader.InquiryVariableStat(reader, var2D, perstepstat, + perblockstat); // get min/max statistics + // this is adios1 ADIOS_VARSTAT + + while (true) { - if (chunk) - { - // process the chunk first - // ... - // free memory of chunk (not the data!) - adios::FreeChunk(chunk); - } - else - { - // no chunk was returned, slow down a little - sleep(1); - } + // Make a selection to describe the local dimensions of the variable + // we + // READ and + // its offsets in the global spaces + adios::Selection bbsel = adios.SelectionBoundingBox( + {1, NX}, {0, 0}); // local dims and offsets; both as list + var2D.SetSelection(bbsel); + adios::Selection memspace = adios.SelectionBoundingBox( + {1, NX}, {0, 1}); // local dims and offsets; both as list + var2D.SetMemorySelection(memspace); + reader->Read<double>(var2D, *Temperature); + // var2D, Temperature ); + + // Better for staging to schedule several reads at once + reader->ScheduleRead<double>(var2D, *Temperature); + reader->PerformReads(adios::BLOCKINGREAD); + + // promise to not read more from this step/item + reader->Release(); + + // want to move on to the next available step/item + reader->Advance(adios::NEXT_AVAILABLE); // default + reader->Advance(adios::LATEST_AVAILABLE); // interested only in the + // latest data } - } - catch (std::exception &e) - { - // some error happened while getting a chunk - } - - reader->Release(); - - // When AdvanceAsync returns new data is not yet available. - // A callback will tell us when we have the new data (and we have the lock - // on it to read) - writer->AdvanceAsync(adios::NEXT_AVAILABLE, cb_AsyncReadAdvanceCompleted); - // Do we need more fine grained control? Like this function does not get - // the lock and so - // do we need to call Advance() to get the lock? + // Close file/stream + reader->Close(); } - reader->Close(); - } - // Note: chunk reading also works if scheduling reads for specific variables - - // 4. Open it as file and see all steps at once. - // Allow for reading multiple steps of a variable into a contiguous array - try - { - rmethod.AddTransport( - "BP"); // Set a file engine here. Shall we have RemoveTransport() too? - - // Open a file with all steps immediately available - std::shared_ptr<adios::Engine> reader = adios.OpenFileReader( - "filename.bp", comm, rmethod, adios::COLLECTIVE_IO); - - /* NX */ - /* There is a single value for each step. We can read all into a 1D array - * with a step selection. - * Steps are not automatically presented as an array dimension and read does - * not read it as array. - */ - // We can also just conveniently get the first step with a simple read - // statement. - reader->Read<unsigned int>( - "NX", &NX); // read a Global scalar which has a single value in a step - reader->Read<unsigned int>( - varNX, &NX); // read a Global scalar which has a single value in a step - - adios::Variable<void> varNXread = reader->InquireVariable("NX"); - adios::Variable<unsigned int> varNXreadint = - reader->InquireVariableInt("NX"); - std::vector<unsigned int> Nxs( - varNXread.GetSteps()); // number of steps available - // make a StepSelection to select multiple steps. Args: From, #of - // consecutive steps - adios::StepSelection stepsNx(0, varNXread.GetSteps()); - // ? How do we make a selection for an arbitrary list of steps ? - varNXread.SetStepSelection(stepsNx); - reader->Read<unsigned int>(varNXreadint, Nxs.data()); - reader->Read<void>(varNXread, Nxs.data()); - - auto itmax = std::max_element(std::begin(Nxs), std::end(Nxs)); - auto itmin = std::min_element(std::begin(Nxs), std::end(Nxs)); - if (*itmin != *itmax) + catch (adios::end_of_stream &e) + { + // Reached end of stream, end processing loop + // Close file/stream + reader->Close(); + } + catch (adios::file_not_found &e) + { + // File/stream does not exist, quit + } + + // 2. Open a stream, where each item from the writers will get to a single + // reader only + // If the writers are collective, that means a whole steps go to different + // readers + // If the writers are independent, that means each writer's output goes to + // different readers + // Also show here ScheduleRead/PerformRead + // try + { + rmethod.SetReadMultiplexPattern( + adios::FIFO_READERS); // Each reader process + // sees everything + // from the stream + rmethod.SetStreamOpenMode( + adios::WAITFORSTREAM); // In Open(), wait for the + // first step appear + // (default) + + // Open a stream + std::shared_ptr<adios::Engine> reader = adios.Open( + "filename.bp", "r", comm, rmethod, adios::IOMode::INDEPENDENT, + /*timeout_sec=*/300.0); // wait this long for the stream, return + // error + // afterwards + + while (true) + { + // Make a selection to describe the local dimensions of the variable + // we + // READ and + // its offsets in the global spaces if we know this somehow + adios::Selection bbsel = adios.SelectionBoundingBox( + {1, NX}, {0, 0}); // local dims and offsets; both as list + var2D->SetSelection(bbsel); + reader->Read<double>(var2D, *Temperature); + + // Let ADIOS allocate space for the incoming (per-writer) item + double *data = reader->Read<double>(var2D); + + // promise to not read more from this step/item + reader->Release(); + + // want to move on to the next available step/item + reader->Advance(); // default + reader->Advance( + adios::LATEST_AVAILABLE); // This should be an error, or + // could it make sense? + } + reader->Close(); + } + + // 3. Open a stream and return immediately, not waiting for data to appear + // In this mode we cannot inquiry variables, but can schedule reads + // try + { + rmethod.SetReadMultiplexPattern(adios::GLOBAL_READERS); // Each reader + // process sees + // everything from + // the stream + rmethod.SetStreamOpenMode( + adios::NOWAITFORSTREAM); // In Open(), wait for + // the first step appear + // (default) + + // Open a stream + std::shared_ptr<adios::Engine> reader = adios.Open( + "filename.bp", "r", comm, rmethod, adios::IOMode::INDEPENDENT); + + while (true) + { + + // Let ADIOS allocate space for the incoming (per-writer) item + reader->ScheduleRead(); // read whatever comes + + // One way is to handle the incoming data through a callback (which + // will + // be called in a thread) + // void cb( const void *data, std::string doid, std::string var, + // std::string dtype, std::vector<std::size_t> varshape ); + // void cb( adios::VARCHUNK * chunk ); // see adios1 for VARCHUNK + reader->SetReadCallback(cb); + reader->PerformReads(adios::NONBLOCKINGREAD); + + // Another way is checking back manually like in adios1 and + // processing + // chunks + reader->PerformReads(adios::NONBLOCKINGREAD); + int ck; + adios::VARCHUNK *chunk; + try + { + while ((ck = reader->CheckReads(&chunk)) > 0) + { + if (chunk) + { + // process the chunk first + // ... + // free memory of chunk (not the data!) + adios::FreeChunk(chunk); + } + else + { + // no chunk was returned, slow down a little + sleep(1); + } + } + } + catch (std::exception &e) + { + // some error happened while getting a chunk + } + + reader->Release(); + + // When AdvanceAsync returns new data is not yet available. + // A callback will tell us when we have the new data (and we have + // the lock + // on it to read) + writer->AdvanceAsync(adios::NEXT_AVAILABLE, + cb_AsyncReadAdvanceCompleted); + // Do we need more fine grained control? Like this function does not + // get + // the lock and so + // do we need to call Advance() to get the lock? + } + reader->Close(); + } + // Note: chunk reading also works if scheduling reads for specific variables + + // 4. Open it as file and see all steps at once. + // Allow for reading multiple steps of a variable into a contiguous array + try + { + rmethod.AddTransport("BP"); // Set a file engine here. Shall we have + // RemoveTransport() too? + + // Open a file with all steps immediately available + std::shared_ptr<adios::Engine> reader = adios.OpenFileReader( + "filename.bp", comm, rmethod, adios::COLLECTIVE_IO); + + /* NX */ + /* There is a single value for each step. We can read all into a 1D + * array + * with a step selection. + * Steps are not automatically presented as an array dimension and read + * does + * not read it as array. + */ + // We can also just conveniently get the first step with a simple read + // statement. + reader->Read<unsigned int>( + "NX", + &NX); // read a Global scalar which has a single value in a step + reader->Read<unsigned int>( + varNX, + &NX); // read a Global scalar which has a single value in a step + + adios::Variable<void> varNXread = reader->InquireVariable("NX"); + adios::Variable<unsigned int> varNXreadint = + reader->InquireVariableInt("NX"); + std::vector<unsigned int> Nxs( + varNXread.GetSteps()); // number of steps available + // make a StepSelection to select multiple steps. Args: From, #of + // consecutive steps + adios::StepSelection stepsNx(0, varNXread.GetSteps()); + // ? How do we make a selection for an arbitrary list of steps ? + varNXread.SetStepSelection(stepsNx); + reader->Read<unsigned int>(varNXreadint, Nxs.data()); + reader->Read<void>(varNXread, Nxs.data()); + + auto itmax = std::max_element(std::begin(Nxs), std::end(Nxs)); + auto itmin = std::min_element(std::begin(Nxs), std::end(Nxs)); + if (*itmin != *itmax) + { + throw std::ios_base::failure( + "ERROR: NX is not the same at all steps!\n"); + } + + /* Nparts */ + // Nparts local scalar is presented as a 1D array of nproc elements. + // We can read all steps into a 2D array of nproc * nsteps + adios::Variable<void> varNpartsread = reader->InquireVariable("Nparts"); + std::vector<int> partsV(Nproc * varNpartsread->GetSteps()); + varNpartsread->SetStepSelection( + adios.StepSelection(0, varNpartsread.GetSteps())); + reader->Read<int>("Nparts", partsV.data()); + reader->Read<void>(varNpartsread, + partsV.data()); // missing spatial selection = whole + // array at each step + + // Close file/stream + reader->Close(); + } + catch (adios::file_not_found &e) { - throw std::ios_base::failure("ERROR: NX is not the same at all steps!\n"); + // File/stream does not exist, quit } - /* Nparts */ - // Nparts local scalar is presented as a 1D array of nproc elements. - // We can read all steps into a 2D array of nproc * nsteps - adios::Variable<void> varNpartsread = reader->InquireVariable("Nparts"); - std::vector<int> partsV(Nproc * varNpartsread->GetSteps()); - varNpartsread->SetStepSelection( - adios.StepSelection(0, varNpartsread.GetSteps())); - reader->Read<int>("Nparts", partsV.data()); - reader->Read<void>( - varNpartsread, - partsV.data()); // missing spatial selection = whole array at each step - - // Close file/stream - reader->Close(); - } - catch (adios::file_not_found &e) - { - // File/stream does not exist, quit - } - - return 0; + return 0; } diff --git a/examples/globalArray/globalArrayNoXML.cpp b/examples/globalArray/globalArrayNoXML.cpp index e8f96975ee3f22a19ec21cc8389edc2b967088bc..64f33e42dce0cf2e0b66427b17d6abf7661477d0 100644 --- a/examples/globalArray/globalArrayNoXML.cpp +++ b/examples/globalArray/globalArrayNoXML.cpp @@ -19,105 +19,108 @@ int main(int argc, char *argv[]) { - int rank, size; - const int NX = 10; - double t[NX]; - std::vector<double> p(NX); - MPI_Comm comm = MPI_COMM_WORLD; + int rank, size; + const int NX = 10; + double t[NX]; + std::vector<double> p(NX); + MPI_Comm comm = MPI_COMM_WORLD; - MPI_Init(&argc, &argv); - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &size); + MPI_Init(&argc, &argv); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); - try - { - // ADIOS manager object creation. MPI must be initialized - adios::ADIOS adios("globalArrayNoXML.xml", comm, true); - - // set a maximum buffersize that ADIOS can use (for one group). - // multiple groups may use each such buffersize if they are overlapped or - // use time-aggregation or use zero-copy staging - - // Define Group and its variables - // The group's transport can be defined at runtime in the input XML file - adios.CreateGroup("arrays"); - - // Set the maximum buffersize for this group. This must happen before - // defining a zero copy variable, which will cause the group's internal - // buffer - // allocated (during the variable definition call) - // adios.SetMaxBuffersize ("arrays", 10000000); - - adios.CreateVariable("arrays", "NX", "int"); // scalar variable - adios.CreateVariable("arrays", "size", "int"); - adios.CreateVariable("arrays", "size", "rank"); - - // define a 2D array with 1D decomposition - adios.CreateVariable("arrays", "temperature", "double", "1,NX", "NONE", - "size,NX", "rank,0"); - - // // set a variable-level transformation for this variable - // adios.SetVariableTransform ("arrays", "temperature", "none"); - - adios.CreateVariable("arrays", "pressure", "std::vector<double>", "1,NX", - "size,NX", "rank,0"); - - // set a group-level transport - adios.SetTransport("arrays", "time-aggregate"); // no options passed here - - // Get Monitor info - std::ofstream logStream("info_" + std::to_string(rank) + ".log"); - adios.MonitorGroups(logStream); - - adios.Open("arrays", "globalArray.bp", "w", 100000000); - - for (int it = 1; it <= 13; it++) + try { - - for (int i = 0; i < NX; i++) - { - t[i] = it * 100.0 + rank * NX + i; - p[i] = it * 1000.0 + rank * NX + i; - } - - // if (it==1) - // - // else - // adios.Open("arrays", "globalArray.bp", "a", 100000000 ); - - // uint64_t adios_groupsize, adios_totalsize; - // adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double); - // adios_totalsize = adios.GroupSize("arrays", adios_groupsize); - - adios.Write("arrays", "NX", &NX); - adios.Write("arrays", "size", &size); - adios.Write("arrays", "rank", &rank); - adios.Write("arrays", "temperature", t); - adios.Write("arrays", "pressure", &p); - - MPI_Barrier(comm); - if (rank == 0) - printf("Timestep %d written\n", it); + // ADIOS manager object creation. MPI must be initialized + adios::ADIOS adios("globalArrayNoXML.xml", comm, true); + + // set a maximum buffersize that ADIOS can use (for one group). + // multiple groups may use each such buffersize if they are overlapped + // or + // use time-aggregation or use zero-copy staging + + // Define Group and its variables + // The group's transport can be defined at runtime in the input XML file + adios.CreateGroup("arrays"); + + // Set the maximum buffersize for this group. This must happen before + // defining a zero copy variable, which will cause the group's internal + // buffer + // allocated (during the variable definition call) + // adios.SetMaxBuffersize ("arrays", 10000000); + + adios.CreateVariable("arrays", "NX", "int"); // scalar variable + adios.CreateVariable("arrays", "size", "int"); + adios.CreateVariable("arrays", "size", "rank"); + + // define a 2D array with 1D decomposition + adios.CreateVariable("arrays", "temperature", "double", "1,NX", "NONE", + "size,NX", "rank,0"); + + // // set a variable-level transformation for this variable + // adios.SetVariableTransform ("arrays", "temperature", "none"); + + adios.CreateVariable("arrays", "pressure", "std::vector<double>", + "1,NX", "size,NX", "rank,0"); + + // set a group-level transport + adios.SetTransport("arrays", + "time-aggregate"); // no options passed here + + // Get Monitor info + std::ofstream logStream("info_" + std::to_string(rank) + ".log"); + adios.MonitorGroups(logStream); + + adios.Open("arrays", "globalArray.bp", "w", 100000000); + + for (int it = 1; it <= 13; it++) + { + + for (int i = 0; i < NX; i++) + { + t[i] = it * 100.0 + rank * NX + i; + p[i] = it * 1000.0 + rank * NX + i; + } + + // if (it==1) + // + // else + // adios.Open("arrays", "globalArray.bp", "a", + // 100000000 ); + + // uint64_t adios_groupsize, adios_totalsize; + // adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double); + // adios_totalsize = adios.GroupSize("arrays", adios_groupsize); + + adios.Write("arrays", "NX", &NX); + adios.Write("arrays", "size", &size); + adios.Write("arrays", "rank", &rank); + adios.Write("arrays", "temperature", t); + adios.Write("arrays", "pressure", &p); + + MPI_Barrier(comm); + if (rank == 0) + printf("Timestep %d written\n", it); + } + + adios.Close("arrays"); + + MPI_Barrier(comm); + // need barrier before we destroy the ADIOS object here automatically + if (rank == 0) + printf("Finalize adios\n"); } - - adios.Close("arrays"); - - MPI_Barrier(comm); - // need barrier before we destroy the ADIOS object here automatically - if (rank == 0) - printf("Finalize adios\n"); - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking { - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << e.what() << "\n"; + } } - } - if (rank == 0) - printf("Finalize MPI\n"); - MPI_Finalize(); - return 0; + if (rank == 0) + printf("Finalize MPI\n"); + MPI_Finalize(); + return 0; } diff --git a/examples/globalArray/globalArrayXML.cpp b/examples/globalArray/globalArrayXML.cpp index 9d3285df6295b0d6b605bcfc0f92b8d49872a779..c25d046e32cb1fcef4a77c8049d3ebef6444108b 100644 --- a/examples/globalArray/globalArrayXML.cpp +++ b/examples/globalArray/globalArrayXML.cpp @@ -19,80 +19,81 @@ int main(int argc, char *argv[]) { - int rank, size; - const int NX = 10; - double t[NX]; - std::vector<double> p(NX); - MPI_Comm comm = MPI_COMM_WORLD; + int rank, size; + const int NX = 10; + double t[NX]; + std::vector<double> p(NX); + MPI_Comm comm = MPI_COMM_WORLD; - MPI_Init(&argc, &argv); - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &size); + MPI_Init(&argc, &argv); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); - try - { - // ADIOS manager object creation. MPI must be initialized - adios::ADIOS adios("globalArrayXML.xml", comm, true); + try + { + // ADIOS manager object creation. MPI must be initialized + adios::ADIOS adios("globalArrayXML.xml", comm, true); - adios::ADIOS_OUTPUT &ckptfile = - adios.Open("globalArray.bp", comm, "a", "POSIX"); + adios::ADIOS_OUTPUT &ckptfile = + adios.Open("globalArray.bp", comm, "a", "POSIX"); - adios::ADIOS_OUTPUT ckptfile("globalArray.bp", subcomm, "a", "POSIX"); - // adios::ADIOS_OUTPUT *ckptfile = adios.Open( "globalArray.bp", "POSIX"); + adios::ADIOS_OUTPUT ckptfile("globalArray.bp", subcomm, "a", "POSIX"); + // adios::ADIOS_OUTPUT *ckptfile = adios.Open( "globalArray.bp", + // "POSIX"); - // Get Monitor info - std::ofstream logStream("info_" + std::to_string(rank) + ".log"); - adios.MonitorGroups(logStream); + // Get Monitor info + std::ofstream logStream("info_" + std::to_string(rank) + ".log"); + adios.MonitorGroups(logStream); - for (int it = 1; it <= 13; it++) - { + for (int it = 1; it <= 13; it++) + { - for (int i = 0; i < NX; i++) - { - t[i] = it * 100.0 + rank * NX + i; - p[i] = it * 1000.0 + rank * NX + i; - } + for (int i = 0; i < NX; i++) + { + t[i] = it * 100.0 + rank * NX + i; + p[i] = it * 1000.0 + rank * NX + i; + } - // if (it==1) - // adios.Open("arrays", "globalArray.bp", "w"); - // else - // adios.Open("arrays", "globalArray.bp", "a"); + // if (it==1) + // adios.Open("arrays", "globalArray.bp", "w"); + // else + // adios.Open("arrays", "globalArray.bp", "a"); - // uint64_t adios_groupsize, adios_totalsize; - // adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double); - // adios_totalsize = adios.GroupSize("arrays", adios_groupsize); + // uint64_t adios_groupsize, adios_totalsize; + // adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double); + // adios_totalsize = adios.GroupSize("arrays", adios_groupsize); - ckptfile.Write("NX", &NX); - ckptfile.Write("pressure", &p); - // adios.Write ("arrays", "NX", &NX); - // adios.Write ("arrays", "size", &size); - // adios.Write ("arrays", "rank", &rank); - // adios.Write ("arrays", "temperature", t); - // adios.Write ("arrays", "pressure", &p); + ckptfile.Write("NX", &NX); + ckptfile.Write("pressure", &p); + // adios.Write ("arrays", "NX", &NX); + // adios.Write ("arrays", "size", &size); + // adios.Write ("arrays", "rank", &rank); + // adios.Write ("arrays", "temperature", t); + // adios.Write ("arrays", "pressure", &p); - // adios.Close ("arrays"); - ckptfile.PerformIO(); - MPI_Barrier(comm); - if (rank == 0) - printf("Timestep %d written\n", it); + // adios.Close ("arrays"); + ckptfile.PerformIO(); + MPI_Barrier(comm); + if (rank == 0) + printf("Timestep %d written\n", it); + } + MPI_Barrier(comm); + ckptfile.Close(); + // need barrier before we destroy the ADIOS object here automatically + if (rank == 0) + printf("Finalize adios\n"); } - MPI_Barrier(comm); - ckptfile.Close(); - // need barrier before we destroy the ADIOS object here automatically - if (rank == 0) - printf("Finalize adios\n"); - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking { - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << e.what() << "\n"; + } } - } - if (rank == 0) - printf("Finalize MPI\n"); - MPI_Finalize(); - return 0; + if (rank == 0) + printf("Finalize MPI\n"); + MPI_Finalize(); + return 0; } diff --git a/examples/globalArray/globalArrayZeroCopy.cpp b/examples/globalArray/globalArrayZeroCopy.cpp index 8206c131aa9388f39618f064c8b98ecdfacf2c42..a85b5dc56e77f55430e8c21920248cf196c22a2f 100644 --- a/examples/globalArray/globalArrayZeroCopy.cpp +++ b/examples/globalArray/globalArrayZeroCopy.cpp @@ -19,109 +19,111 @@ int main(int argc, char *argv[]) { - int rank, size; - const int NX = 10; - MPI_Comm comm = MPI_COMM_WORLD; - - MPI_Init(&argc, &argv); - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &size); - - try - { - // ADIOS manager object creation. MPI must be initialized - adios::ADIOS adios("globalArrayNoXML.xml", comm, true); - - // set a maximum buffersize that ADIOS can use (for one group). - // multiple groups may use each such buffersize if they are overlapped or - // use time-aggregation or use zero-copy staging - adios.SetMaxBuffersize(100000000); - - // Define Group and its variables - // The group's transport can be defined at runtime in the input XML file - adios.CreateGroup("arrays", adios_stat_default); - - // Set the maximum buffersize for this group. This must happen before - // defining a zero copy variable, which will cause the group's internal - // buffer - // allocated (during the variable definition call) - adios.SetMaxBuffersize("arrays", 10000000); - - adios.DefineVariable("arrays", "NX", "int"); // scalar variable - adios.DefineVariable("arrays", "size", "int"); - adios.DefineVariable("arrays", "size", "rank"); - - // Define and allocate a 2D array with 1D decomposition and get back a - // pre-allocated typed pointer. - // The size of the array must be known at this point, so no scalar variables - // can - // be used for its dimensions. - std::string ldim = "1," + std::to_string(NX); // == "1,10" if NX==10 - std::string gdim = std::to_string(size) + "," + std::to_string(NX); - std::string offs = std::to_string(rank) + ",0"; - - double *t = adios.DefineZeroCopyVariable("arrays", "temperature", "double", - ldim, gdim, offs); - - // set a variable-level transformation for this variable - adios.SetVariableTransform("arrays", "temperature", "none"); - - std::vector<double> p = adios.DefineZeroCopyVariable( - "arrays", "pressure", "std::vector<double>", ldim, gdim, offs); - - // set a group-level transformation - adios.SetGroupTransform("arrays", "time-aggregate", - ""); // no options passed here - - // Get Monitor info - std::ofstream logStream("info_" + std::to_string(rank) + ".log"); - adios.MonitorGroups(logStream); - - for (int it = 1; it <= 13; it++) - { + int rank, size; + const int NX = 10; + MPI_Comm comm = MPI_COMM_WORLD; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); - for (int i = 0; i < NX; i++) - { - t[i] = it * 100.0 + rank * NX + i; - p[i] = it * 1000.0 + rank * NX + i; - } - - if (it == 1) - adios.Open("arrays", "globalArray.bp", "w"); - else - adios.Open("arrays", "globalArray.bp", "a"); - - // uint64_t adios_groupsize, adios_totalsize; - // adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double); - // adios_totalsize = adios.GroupSize("arrays", adios_groupsize); - - adios.Write("arrays", "NX", &NX); - adios.Write("arrays", "size", &size); - adios.Write("arrays", "rank", &rank); - adios.Write("arrays", "temperature", t); - adios.Write("arrays", "pressure", &p); - - adios.Close("arrays"); - MPI_Barrier(comm); - if (rank == 0) - printf("Timestep %d written\n", it); + try + { + // ADIOS manager object creation. MPI must be initialized + adios::ADIOS adios("globalArrayNoXML.xml", comm, true); + + // set a maximum buffersize that ADIOS can use (for one group). + // multiple groups may use each such buffersize if they are overlapped + // or + // use time-aggregation or use zero-copy staging + adios.SetMaxBuffersize(100000000); + + // Define Group and its variables + // The group's transport can be defined at runtime in the input XML file + adios.CreateGroup("arrays", adios_stat_default); + + // Set the maximum buffersize for this group. This must happen before + // defining a zero copy variable, which will cause the group's internal + // buffer + // allocated (during the variable definition call) + adios.SetMaxBuffersize("arrays", 10000000); + + adios.DefineVariable("arrays", "NX", "int"); // scalar variable + adios.DefineVariable("arrays", "size", "int"); + adios.DefineVariable("arrays", "size", "rank"); + + // Define and allocate a 2D array with 1D decomposition and get back a + // pre-allocated typed pointer. + // The size of the array must be known at this point, so no scalar + // variables + // can + // be used for its dimensions. + std::string ldim = "1," + std::to_string(NX); // == "1,10" if NX==10 + std::string gdim = std::to_string(size) + "," + std::to_string(NX); + std::string offs = std::to_string(rank) + ",0"; + + double *t = adios.DefineZeroCopyVariable("arrays", "temperature", + "double", ldim, gdim, offs); + + // set a variable-level transformation for this variable + adios.SetVariableTransform("arrays", "temperature", "none"); + + std::vector<double> p = adios.DefineZeroCopyVariable( + "arrays", "pressure", "std::vector<double>", ldim, gdim, offs); + + // set a group-level transformation + adios.SetGroupTransform("arrays", "time-aggregate", + ""); // no options passed here + + // Get Monitor info + std::ofstream logStream("info_" + std::to_string(rank) + ".log"); + adios.MonitorGroups(logStream); + + for (int it = 1; it <= 13; it++) + { + + for (int i = 0; i < NX; i++) + { + t[i] = it * 100.0 + rank * NX + i; + p[i] = it * 1000.0 + rank * NX + i; + } + + if (it == 1) + adios.Open("arrays", "globalArray.bp", "w"); + else + adios.Open("arrays", "globalArray.bp", "a"); + + // uint64_t adios_groupsize, adios_totalsize; + // adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double); + // adios_totalsize = adios.GroupSize("arrays", adios_groupsize); + + adios.Write("arrays", "NX", &NX); + adios.Write("arrays", "size", &size); + adios.Write("arrays", "rank", &rank); + adios.Write("arrays", "temperature", t); + adios.Write("arrays", "pressure", &p); + + adios.Close("arrays"); + MPI_Barrier(comm); + if (rank == 0) + printf("Timestep %d written\n", it); + } + MPI_Barrier(comm); + // need barrier before we destroy the ADIOS object here automatically + if (rank == 0) + printf("Finalize adios\n"); } - MPI_Barrier(comm); - // need barrier before we destroy the ADIOS object here automatically - if (rank == 0) - printf("Finalize adios\n"); - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking { - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << e.what() << "\n"; + } } - } - if (rank == 0) - printf("Finalize MPI\n"); - MPI_Finalize(); - return 0; + if (rank == 0) + printf("Finalize MPI\n"); + MPI_Finalize(); + return 0; } diff --git a/examples/groupless/basic/reader.cpp b/examples/groupless/basic/reader.cpp index ea8832438a92fc97b1ceb5c78efe033079d18b4c..1e91476b27d48444819de5f303b1f1dcdf82f576 100644 --- a/examples/groupless/basic/reader.cpp +++ b/examples/groupless/basic/reader.cpp @@ -16,178 +16,183 @@ int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - std::vector<double> NiceArray; - std::vector<float> RaggedArray; - unsigned int Nx; - int Nparts; - int Nwriters; - - try - { - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpReaderSettings = adios.GetMethod("input"); - if (bpReaderSettings.undeclared()) + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + + // Application variable + std::vector<double> NiceArray; + std::vector<float> RaggedArray; + unsigned int Nx; + int Nparts; + int Nwriters; + + try { - // if not defined by user, we can change the default settings - bpReaderSettings.SetEngine("BP"); // BP is the default engine - } - - // Create engine smart pointer due to polymorphism, - // Default behavior - // auto bpReader = adios.Open( "myNumbers.bp", "r" ); - // this would just open with a default transport, which is "BP" - auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); - - // All the above is same as default use: - // auto bpReader = adios.Open( "myNumbers.bp", "r"); - - if (bpReader == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpReader\n"); - - /* Variable names are available as a vector of strings */ - std::cout << "List of variables in file: " << bpReader->VariableNames - << "\n"; - - /* NX */ - bpReader->Read<unsigned int>( - "NX", Nx); // read a Global scalar which has a single value in a step - - /* nproc */ - bpReader->Read<int>("nproc", Nwriters); // also a global scalar - - /* Nparts */ - // Nparts local scalar is presented as a 1D array of Nwriters elements. - // We need to read a specific value the same way as reading from any 1D - // array. - // Make a single-value selection to describe our rank's position in the - // 1D array of Nwriters values. - if (rank < Nwriters) - { - std::shared_ptr<adios::Variable> varNparts = - bpReader.InquiryVariable("Nparts"); - std::unique_ptr<adios::Selection> selNparts = - adios.SelectionBoundingBox({1}, {rank}); - varNparts->SetSelection(selNparts); - bpReader->Read<int>(varNparts, Nparts); - } - // or we could just read the whole array by every process - std::vector<int> partsV(Nwriters); - bpReader->Read<int>( - "Nparts", - partsV - .data()); // read with string name, no selection => read whole array - - std::vector<int> partsV; - bpReader->Read<int>( - "Nparts", - partsV); // read with string name, no selection => read whole array - (Nwriters == partsV.size()) - - /* Nice */ + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpReaderSettings = adios.GetMethod("input"); + if (bpReaderSettings.undeclared()) + { + // if not defined by user, we can change the default settings + bpReaderSettings.SetEngine("BP"); // BP is the default engine + } + + // Create engine smart pointer due to polymorphism, + // Default behavior + // auto bpReader = adios.Open( "myNumbers.bp", "r" ); + // this would just open with a default transport, which is "BP" + auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); + + // All the above is same as default use: + // auto bpReader = adios.Open( "myNumbers.bp", "r"); + + if (bpReader == nullptr) + throw std::ios_base::failure( + "ERROR: failed to open ADIOS bpReader\n"); + + /* Variable names are available as a vector of strings */ + std::cout << "List of variables in file: " << bpReader->VariableNames + << "\n"; + + /* NX */ + bpReader->Read<unsigned int>( + "NX", + Nx); // read a Global scalar which has a single value in a step + + /* nproc */ + bpReader->Read<int>("nproc", Nwriters); // also a global scalar + + /* Nparts */ + // Nparts local scalar is presented as a 1D array of Nwriters elements. + // We need to read a specific value the same way as reading from any 1D + // array. + // Make a single-value selection to describe our rank's position in the + // 1D array of Nwriters values. + if (rank < Nwriters) + { + std::shared_ptr<adios::Variable> varNparts = + bpReader.InquiryVariable("Nparts"); + std::unique_ptr<adios::Selection> selNparts = + adios.SelectionBoundingBox({1}, {rank}); + varNparts->SetSelection(selNparts); + bpReader->Read<int>(varNparts, Nparts); + } + // or we could just read the whole array by every process + std::vector<int> partsV(Nwriters); + bpReader->Read<int>("Nparts", + partsV.data()); // read with string name, no + // selection => read whole array + + std::vector<int> partsV; + bpReader->Read<int>("Nparts", + partsV); // read with string name, no selection => + // read whole array + (Nwriters == partsV.size()) + + /* Nice */ + // inquiry about a variable, whose name we know + std::shared_ptr<adios::Variable> + varNice = bpReader.InquiryVariable("Nice"); + + if (varNice == nullptr) + throw std::ios_base::failure("ERROR: failed to find variable " + "'myDoubles' in input file\n"); + + // ? how do we know about the type? std::string varNice->m_Type + uint64_t gdim = + varNice->m_GlobalDimensions[0]; // ?member var or member func? + uint64_t ldim = gdim / nproc; + uint64_t offs = rank * ldim; + if (rank == nproc - 1) + { + ldim = gdim - (ldim * gdim); + } + + NiceArray.reserve(ldim); + + // Make a 1D selection to describe the local dimensions of the variable + // we + // READ and + // its offsets in the global spaces + std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( + {ldim}, {offs}); // local dims and offsets; both as list + varNice->SetSelection(bbsel); + bpReader->Read<double>(varNice, NiceArray.data()); + + /* Ragged */ // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable> - varNice = bpReader.InquiryVariable("Nice"); - - if (varNice == nullptr) - throw std::ios_base::failure( - "ERROR: failed to find variable 'myDoubles' in input file\n"); - - // ? how do we know about the type? std::string varNice->m_Type - uint64_t gdim = - varNice->m_GlobalDimensions[0]; // ?member var or member func? - uint64_t ldim = gdim / nproc; - uint64_t offs = rank * ldim; - if (rank == nproc - 1) - { - ldim = gdim - (ldim * gdim); - } - - NiceArray.reserve(ldim); - - // Make a 1D selection to describe the local dimensions of the variable we - // READ and - // its offsets in the global spaces - std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( - {ldim}, {offs}); // local dims and offsets; both as list - varNice->SetSelection(bbsel); - bpReader->Read<double>(varNice, NiceArray.data()); - - /* Ragged */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varRagged = - bpReader.InquiryVariable("Ragged"); - if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) - { - throw std::ios_base::failure( - "Unexpected condition: Ragged array's fast dimension " - "is supposed to be VARYING_DIMENSION\n"); - } - // We have here varRagged->sum_nblocks, nsteps, nblocks[], global - if (rank < varRagged->nblocks[0]) // same as rank < Nwriters in this example - { - // get per-writer size information - varRagged->InquiryBlocks(); - // now we have the dimensions per block - - unsigned long long int ldim = varRagged->blockinfo[rank].m_Dimensions[1]; - RaggedArray.resize(ldim); - - std::unique_ptr<adios::Selection> wbsel = adios.SelectionWriteblock(rank); - varRagged->SetSelection(wbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); - - // We can use bounding box selection as well - std::unique_ptr<adios::Selection> rbbsel = - adios.SelectionBoundingBox({1, ldim}, {rank, 0}); - varRagged->SetSelection(rbbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); + std::shared_ptr<adios::Variable<void>> varRagged = + bpReader.InquiryVariable("Ragged"); + if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) + { + throw std::ios_base::failure( + "Unexpected condition: Ragged array's fast dimension " + "is supposed to be VARYING_DIMENSION\n"); + } + // We have here varRagged->sum_nblocks, nsteps, nblocks[], global + if (rank < + varRagged->nblocks[0]) // same as rank < Nwriters in this example + { + // get per-writer size information + varRagged->InquiryBlocks(); + // now we have the dimensions per block + + unsigned long long int ldim = + varRagged->blockinfo[rank].m_Dimensions[1]; + RaggedArray.resize(ldim); + + std::unique_ptr<adios::Selection> wbsel = + adios.SelectionWriteblock(rank); + varRagged->SetSelection(wbsel); + bpReader->Read<float>(varRagged, RaggedArray.data()); + + // We can use bounding box selection as well + std::unique_ptr<adios::Selection> rbbsel = + adios.SelectionBoundingBox({1, ldim}, {rank, 0}); + varRagged->SetSelection(rbbsel); + bpReader->Read<float>(varRagged, RaggedArray.data()); + } + + /* Extra help to process Ragged */ + int maxRaggedDim = + varRagged->GetMaxGlobalDimensions(1); // contains the largest + std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( + 1); // contains all individual sizes in that dimension + + // Close file/stream + bpReader->Close(); } - - /* Extra help to process Ragged */ - int maxRaggedDim = - varRagged->GetMaxGlobalDimensions(1); // contains the largest - std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( - 1); // contains all individual sizes in that dimension - - // Close file/stream - bpReader->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/groupless/basic/writer.cpp b/examples/groupless/basic/writer.cpp index 33debd164199378814b12c12af7c74462e65d057..cbd556ccc1cabf313b470b22fd84da2ca8ca9409 100644 --- a/examples/groupless/basic/writer.cpp +++ b/examples/groupless/basic/writer.cpp @@ -21,143 +21,158 @@ typedef enum { VARYING_DIMENSION = -1, LOCAL_VALUE = 0, GLOBAL_VALUE = 1 }; int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - const unsigned int Nx = 10; - const int Nparts = rand() % 6 + 5; // random size per process, 5..10 each - - std::vector<double> NiceArray(Nx); - for (int i = 0; i < Nx; i++) - { - NiceArray[i] = rank * Nx + (double)i; - } - - std::vector<float> RaggedArray(Nparts); - for (int i = 0; i < Nparts; i++) - { - RaggedArray[i] = rank * Nx + (float)i; - } - - try - { - // Define group and variables with transforms, variables don't have - // functions, only group can access variables - adios::Variable<unsigned int> &varNX = adios.DefineVariable<unsigned int>( - "NX"); // global single-value across processes - adios::Variable<int> &varNproc = adios.DefineVariable<int>( - "nproc", adios::GLOBAL_VALUE); // same def for global value - adios::Variable<int> &varNparts = adios.DefineVariable<int>( - "Nparts", - adios::LOCAL_VALUE); // a single-value different on every process - adios::Variable<double> &varNice = - adios.DefineVariable<double>("Nice", {nproc * Nx}); // 1D global array - adios::Variable<float> &varRagged = adios.DefineVariable<float>( - "Ragged", {nproc, adios::VARYING_DIMENSION}); // ragged array - - // add transform to variable in group...not executed (just testing API) - adios::Transform bzip2 = adios::transform::BZIP2(); - varNice->AddTransform(bzip2, 1); - - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpWriterSettings = adios.GetMethod("output"); - if (bpWriterSettings.undeclared()) + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + + // Application variable + const unsigned int Nx = 10; + const int Nparts = rand() % 6 + 5; // random size per process, 5..10 each + + std::vector<double> NiceArray(Nx); + for (int i = 0; i < Nx; i++) { - // if not defined by user, we can change the default settings - bpWriterSettings.SetEngine("BP"); // BP is the default engine - bpWriterSettings.AddTransport( - "File", "lucky=yes"); // ISO-POSIX file is the default transport - // Passing parameters to the transport - bpWriterSettings.SetParameters("have_metadata_file", - "yes"); // Passing parameters to the engine - bpWriterSettings.SetParameters("Aggregation", - (nproc + 1) / 2); // number of aggregators + NiceArray[i] = rank * Nx + (double)i; } - // Open returns a smart pointer to Engine containing the Derived class - // Writer - // "w" means we overwrite any existing file on disk, but AdvanceStep will - // append steps later. - auto bpWriter = adios.Open("myNumbers.bp", "w", bpWriterSettings); - - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpWriter\n"); + std::vector<float> RaggedArray(Nparts); + for (int i = 0; i < Nparts; i++) + { + RaggedArray[i] = rank * Nx + (float)i; + } - if (rank == 0) + try { - // Writing a global scalar from only one process - bpWriter->Write<unsigned int>(varNX, Nx); + // Define group and variables with transforms, variables don't have + // functions, only group can access variables + adios::Variable<unsigned int> &varNX = + adios.DefineVariable<unsigned int>( + "NX"); // global single-value across processes + adios::Variable<int> &varNproc = adios.DefineVariable<int>( + "nproc", adios::GLOBAL_VALUE); // same def for global value + adios::Variable<int> &varNparts = + adios.DefineVariable<int>("Nparts", + adios::LOCAL_VALUE); // a single-value + // different on + // every process + adios::Variable<double> &varNice = adios.DefineVariable<double>( + "Nice", {nproc * Nx}); // 1D global array + adios::Variable<float> &varRagged = adios.DefineVariable<float>( + "Ragged", {nproc, adios::VARYING_DIMENSION}); // ragged array + + // add transform to variable in group...not executed (just testing API) + adios::Transform bzip2 = adios::transform::BZIP2(); + varNice->AddTransform(bzip2, 1); + + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpWriterSettings = adios.GetMethod("output"); + if (bpWriterSettings.undeclared()) + { + // if not defined by user, we can change the default settings + bpWriterSettings.SetEngine("BP"); // BP is the default engine + bpWriterSettings.AddTransport( + "File", + "lucky=yes"); // ISO-POSIX file is the default transport + // Passing parameters to the transport + bpWriterSettings.SetParameters( + "have_metadata_file", + "yes"); // Passing parameters to the engine + bpWriterSettings.SetParameters("Aggregation", + (nproc + 1) / + 2); // number of aggregators + } + + // Open returns a smart pointer to Engine containing the Derived class + // Writer + // "w" means we overwrite any existing file on disk, but AdvanceStep + // will + // append steps later. + auto bpWriter = adios.Open("myNumbers.bp", "w", bpWriterSettings); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: failed to open ADIOS bpWriter\n"); + + if (rank == 0) + { + // Writing a global scalar from only one process + bpWriter->Write<unsigned int>(varNX, Nx); + } + // Writing a local scalar on every process. Will be shown at reading as + // a 1D + // array + bpWriter->Write<int>(varNparts, Nparts); + + // Writing a global scalar on every process is useless. Information will + // be + // thrown away + // and only rank 0's data will be in the output + bpWriter->Write<int>(varNproc, nproc); + + // Make a 1D selection to describe the local dimensions of the variable + // we + // write and + // its offsets in the global spaces + adios::Selection &sel = adios.SelectionBoundingBox( + {Nx}, {rank * Nx}); // local dims and offsets; both as list + varNice.SetSelection(sel); + bpWriter->Write<double>(varNice, + NiceArray.data()); // Base class Engine own + // the Write<T> that + // will call overloaded + // Write from Derived + + adios::Selection &lsel = + adios.SelectionBoundingBox({1, Nparts}, {rank, 0}); + varRagged.SetSelection(sel); + bpWriter->Write<float>(varRagged, + RaggedArray.data()); // Base class Engine + // own the Write<T> + // that will call + // overloaded Write + // from Derived + + // Indicate we are done for this step + // N-to-M Aggregation, disk I/O will be performed during this call, + // unless + // time aggregation postpones all of that to some later step + bpWriter->Advance(); + bpWriter->AdvanceAsync(callback_func_to_notify_me); + + // Called once: indicate that we are done with this output for the run + bpWriter->Close(); } - // Writing a local scalar on every process. Will be shown at reading as a 1D - // array - bpWriter->Write<int>(varNparts, Nparts); - - // Writing a global scalar on every process is useless. Information will be - // thrown away - // and only rank 0's data will be in the output - bpWriter->Write<int>(varNproc, nproc); - - // Make a 1D selection to describe the local dimensions of the variable we - // write and - // its offsets in the global spaces - adios::Selection &sel = adios.SelectionBoundingBox( - {Nx}, {rank * Nx}); // local dims and offsets; both as list - varNice.SetSelection(sel); - bpWriter->Write<double>(varNice, NiceArray.data()); // Base class Engine own - // the Write<T> that - // will call overloaded - // Write from Derived - - adios::Selection &lsel = adios.SelectionBoundingBox({1, Nparts}, {rank, 0}); - varRagged.SetSelection(sel); - bpWriter->Write<float>(varRagged, RaggedArray.data()); // Base class Engine - // own the Write<T> - // that will call - // overloaded Write - // from Derived - - // Indicate we are done for this step - // N-to-M Aggregation, disk I/O will be performed during this call, unless - // time aggregation postpones all of that to some later step - bpWriter->Advance(); - bpWriter->AdvanceAsync(callback_func_to_notify_me); - - // Called once: indicate that we are done with this output for the run - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/groupless/compound/reader.cpp b/examples/groupless/compound/reader.cpp index 6dc89ad4bd512c915409c6f1902c76739234d641..58a0e1fd69bb18293f1445ab082d2631683132b1 100644 --- a/examples/groupless/compound/reader.cpp +++ b/examples/groupless/compound/reader.cpp @@ -16,201 +16,207 @@ int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - // GSE === user-defined structure - // - // Like HDF5 example, read with a subset of the structure that was written. - // Easily handled by FFS and HDF5, but ambitious for ADIOS - typedef struct s2_t - { - double c; - int a; - }; - unsigned int Nx; - int Nparts; - int Nwriters; - - try - { - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpReaderSettings = adios.GetMethod("input"); - if (bpReaderSettings.undeclared()) + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + + // Application variable + // GSE === user-defined structure + // + // Like HDF5 example, read with a subset of the structure that was written. + // Easily handled by FFS and HDF5, but ambitious for ADIOS + typedef struct s2_t { - // if not defined by user, we can change the default settings - bpReaderSettings.SetEngine("BP"); // BP is the default engine - } - - // Create engine smart pointer due to polymorphism, - // Default behavior - // auto bpReader = adios.Open( "myNumbers.bp", "r" ); - // this would just open with a default transport, which is "BP" - auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); - - // All the above is same as default use: - // auto bpReader = adios.Open( "myNumbers.bp", "r"); - - if (bpReader == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpReader\n"); - - /* Variable names are available as a vector of strings */ - std::cout << "List of variables in file: " << bpReader->VariableNames - << "\n"; - - /* NX */ - bpReader->Read<unsigned int>( - "NX", Nx); // read a Global scalar which has a single value in a step - - /* nproc */ - bpReader->Read<int>("nproc", Nwriters); // also a global scalar - - /* Nparts */ - // Nparts local scalar is presented as a 1D array of Nwriters elements. - // We need to read a specific value the same way as reading from any 1D - // array. - // Make a single-value selection to describe our rank's position in the - // 1D array of Nwriters values. - if (rank < Nwriters) + double c; + int a; + }; + unsigned int Nx; + int Nparts; + int Nwriters; + + try { - std::shared_ptr<adios::Variable> varNparts = - bpReader.InquiryVariable("Nparts"); - std::unique_ptr<adios::Selection> selNparts = - adios.SelectionBoundingBox({1}, {rank}); - varNparts->SetSelection(selNparts); - bpReader->Read<int>(varNparts, Nparts); - } - // or we could just read the whole array by every process - std::vector<int> partsV(Nwriters); - bpReader->Read<int>( - "Nparts", - partsV - .data()); // read with string name, no selection => read whole array - - std::vector<int> partsV; - bpReader->Read<int>( - "Nparts", - partsV); // read with string name, no selection => read whole array - (Nwriters == partsV.size()) - - /* Nice */ + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpReaderSettings = adios.GetMethod("input"); + if (bpReaderSettings.undeclared()) + { + // if not defined by user, we can change the default settings + bpReaderSettings.SetEngine("BP"); // BP is the default engine + } + + // Create engine smart pointer due to polymorphism, + // Default behavior + // auto bpReader = adios.Open( "myNumbers.bp", "r" ); + // this would just open with a default transport, which is "BP" + auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); + + // All the above is same as default use: + // auto bpReader = adios.Open( "myNumbers.bp", "r"); + + if (bpReader == nullptr) + throw std::ios_base::failure( + "ERROR: failed to open ADIOS bpReader\n"); + + /* Variable names are available as a vector of strings */ + std::cout << "List of variables in file: " << bpReader->VariableNames + << "\n"; + + /* NX */ + bpReader->Read<unsigned int>( + "NX", + Nx); // read a Global scalar which has a single value in a step + + /* nproc */ + bpReader->Read<int>("nproc", Nwriters); // also a global scalar + + /* Nparts */ + // Nparts local scalar is presented as a 1D array of Nwriters elements. + // We need to read a specific value the same way as reading from any 1D + // array. + // Make a single-value selection to describe our rank's position in the + // 1D array of Nwriters values. + if (rank < Nwriters) + { + std::shared_ptr<adios::Variable> varNparts = + bpReader.InquiryVariable("Nparts"); + std::unique_ptr<adios::Selection> selNparts = + adios.SelectionBoundingBox({1}, {rank}); + varNparts->SetSelection(selNparts); + bpReader->Read<int>(varNparts, Nparts); + } + // or we could just read the whole array by every process + std::vector<int> partsV(Nwriters); + bpReader->Read<int>("Nparts", + partsV.data()); // read with string name, no + // selection => read whole array + + std::vector<int> partsV; + bpReader->Read<int>("Nparts", + partsV); // read with string name, no selection => + // read whole array + (Nwriters == partsV.size()) + + /* Nice */ + // inquiry about a variable, whose name we know + /* GSE === compound type declaration borrowed heavily from HDF5 + style */ + adios::CompType mtype(sizeof(s2_t)); + mtype.insertMember("c_name", OFFSET(s2_t, c), PredType::NATIVE_DOUBLE); + mtype.insertMember("a_name", OFFSET(s2_t, a), PredType::NATIVE_INT); + + /* + * GSE === this is a bit conceptually different. There was no real + * check in the prior API that the variable in the file was in any way + * "compatible" with how we planned to read it. This could be done + * here, by providing the details of the structure that we are + * prepared to read in the inquiryVariable, or if we had an API that + * allowed more introspection, we could perhaps support a query on the + * adios::Variable and a later operation that informed it of the data + * type that we were prepared to extract from it. + */ + std::shared_ptr<adios::Variable> varNice = + bpReader.InquiryVariable("Nice", mtype); + + if (varNice == nullptr) + throw std::ios_base::failure("ERROR: failed to find variable " + "'myDoubles' in input file\n"); + + // ? how do we know about the type? std::string varNice->m_Type + uint64_t gdim = + varNice->m_GlobalDimensions[0]; // ?member var or member func? + uint64_t ldim = gdim / nproc; + uint64_t offs = rank * ldim; + if (rank == nproc - 1) + { + ldim = gdim - (ldim * gdim); + } + + NiceArray.reserve(ldim); + + // Make a 1D selection to describe the local dimensions of the variable + // we + // READ and + // its offsets in the global spaces + std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( + {ldim}, {offs}); // local dims and offsets; both as list + varNice->SetSelection(bbsel); + // GSE === Again, templated here? + bpReader->Read<s2_t>(varNice, NiceArray.data()); + + /* Ragged */ // inquiry about a variable, whose name we know - /* GSE === compound type declaration borrowed heavily from HDF5 style */ - adios::CompType mtype(sizeof(s2_t)); - mtype.insertMember("c_name", OFFSET(s2_t, c), PredType::NATIVE_DOUBLE); - mtype.insertMember("a_name", OFFSET(s2_t, a), PredType::NATIVE_INT); - - /* - * GSE === this is a bit conceptually different. There was no real - * check in the prior API that the variable in the file was in any way - * "compatible" with how we planned to read it. This could be done - * here, by providing the details of the structure that we are - * prepared to read in the inquiryVariable, or if we had an API that - * allowed more introspection, we could perhaps support a query on the - * adios::Variable and a later operation that informed it of the data - * type that we were prepared to extract from it. - */ - std::shared_ptr<adios::Variable> varNice = - bpReader.InquiryVariable("Nice", mtype); - - if (varNice == nullptr) - throw std::ios_base::failure( - "ERROR: failed to find variable 'myDoubles' in input file\n"); - - // ? how do we know about the type? std::string varNice->m_Type - uint64_t gdim = - varNice->m_GlobalDimensions[0]; // ?member var or member func? - uint64_t ldim = gdim / nproc; - uint64_t offs = rank * ldim; - if (rank == nproc - 1) - { - ldim = gdim - (ldim * gdim); - } - - NiceArray.reserve(ldim); - - // Make a 1D selection to describe the local dimensions of the variable we - // READ and - // its offsets in the global spaces - std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( - {ldim}, {offs}); // local dims and offsets; both as list - varNice->SetSelection(bbsel); - // GSE === Again, templated here? - bpReader->Read<s2_t>(varNice, NiceArray.data()); - - /* Ragged */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varRagged = - bpReader.InquiryVariable("Ragged"); - if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) - { - throw std::ios_base::failure( - "Unexpected condition: Ragged array's fast dimension " - "is supposed to be VARYING_DIMENSION\n"); - } - // We have here varRagged->sum_nblocks, nsteps, nblocks[], global - if (rank < varRagged->nblocks[0]) // same as rank < Nwriters in this example - { - // get per-writer size information - varRagged->InquiryBlocks(); - // now we have the dimensions per block - - unsigned long long int ldim = varRagged->blockinfo[rank].m_Dimensions[1]; - RaggedArray.resize(ldim); - - std::unique_ptr<adios::Selection> wbsel = adios.SelectionWriteblock(rank); - varRagged->SetSelection(wbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); - - // We can use bounding box selection as well - std::unique_ptr<adios::Selection> rbbsel = - adios.SelectionBoundingBox({1, ldim}, {rank, 0}); - varRagged->SetSelection(rbbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); + std::shared_ptr<adios::Variable<void>> varRagged = + bpReader.InquiryVariable("Ragged"); + if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) + { + throw std::ios_base::failure( + "Unexpected condition: Ragged array's fast dimension " + "is supposed to be VARYING_DIMENSION\n"); + } + // We have here varRagged->sum_nblocks, nsteps, nblocks[], global + if (rank < + varRagged->nblocks[0]) // same as rank < Nwriters in this example + { + // get per-writer size information + varRagged->InquiryBlocks(); + // now we have the dimensions per block + + unsigned long long int ldim = + varRagged->blockinfo[rank].m_Dimensions[1]; + RaggedArray.resize(ldim); + + std::unique_ptr<adios::Selection> wbsel = + adios.SelectionWriteblock(rank); + varRagged->SetSelection(wbsel); + bpReader->Read<float>(varRagged, RaggedArray.data()); + + // We can use bounding box selection as well + std::unique_ptr<adios::Selection> rbbsel = + adios.SelectionBoundingBox({1, ldim}, {rank, 0}); + varRagged->SetSelection(rbbsel); + bpReader->Read<float>(varRagged, RaggedArray.data()); + } + + /* Extra help to process Ragged */ + int maxRaggedDim = + varRagged->GetMaxGlobalDimensions(1); // contains the largest + std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( + 1); // contains all individual sizes in that dimension + + // Close file/stream + bpReader->Close(); } - - /* Extra help to process Ragged */ - int maxRaggedDim = - varRagged->GetMaxGlobalDimensions(1); // contains the largest - std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( - 1); // contains all individual sizes in that dimension - - // Close file/stream - bpReader->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/groupless/compound/writer.cpp b/examples/groupless/compound/writer.cpp index a235ebb4205ec148af8653717fc2407d26c8790c..f8c105e2f0508cccdf3d5322342afe0dc50c4286 100644 --- a/examples/groupless/compound/writer.cpp +++ b/examples/groupless/compound/writer.cpp @@ -21,146 +21,159 @@ typedef enum { VARYING_DIMENSION = -1, LOCAL_VALUE = 0, GLOBAL_VALUE = 1 }; int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - const unsigned int Nx = 10; - // GSE === user-defined structure - typedef struct s1_t - { - int a; - float b; - double c; - }; - const int Nparts = rand() % 6 + 5; // random size per process, 5..10 each - - std::vector<s1_t> NiceArray(Nx); - for (int i = 0; i < Nx; i++) - { - NiceArray.push_back(ss1_t()); - NiceArray[i].a = rank * Nx + (double)i; - NiceArray[i].b = 100.0 * rank * Nx + 100.0 * (double)i; - NiceArray[i].c = 10000.0 * rank * Nx + 10000.0 * (double)i; - } - - try - { - /* GSE === compound type declaration borrowed heavily from HDF5 style */ - adios::CompType mtype(sizeof(s1_t)); - mtype.insertMember("a_name", OFFSET(s1_t, a), PredType::NATIVE_INT); - mtype.insertMember("c_name", OFFSET(s1_t, c), PredType::NATIVE_DOUBLE); - mtype.insertMember("b_name", OFFSET(s1_t, b), PredType::NATIVE_FLOAT); - - // Define group and variables with transforms, variables don't have - // functions, only group can access variables - adios::Variable<unsigned int> &varNX = adios.DefineVariable<unsigned int>( - "NX"); // global single-value across processes - adios::Variable<int> &varNproc = adios.DefineVariable<int>( - "nproc", adios::GLOBAL_VALUE); // same def for global value - adios::Variable<int> &varNparts = adios.DefineVariable<int>( - "Nparts", - adios::LOCAL_VALUE); // a single-value different on every process - - // GSE === template necessary or useful here? Extra argument for - // previously-built compound type information */ - adios::Variable<s1_t> &varNice = adios.DefineVariable<s1_t>( - "Nice", {nproc * Nx}, mtype); // 1D global array - - // add transform to variable in group...not executed (just testing API) - adios::Transform bzip2 = adios::transform::BZIP2(); - varNice->AddTransform(bzip2, 1); - - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpWriterSettings = adios.GetMethod("output"); - if (bpWriterSettings.undeclared()) + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + + // Application variable + const unsigned int Nx = 10; + // GSE === user-defined structure + typedef struct s1_t { - // if not defined by user, we can change the default settings - bpWriterSettings.SetEngine("BP"); // BP is the default engine - bpWriterSettings.AddTransport( - "File", "lucky=yes"); // ISO-POSIX file is the default transport - // Passing parameters to the transport - bpWriterSettings.SetParameters("have_metadata_file", - "yes"); // Passing parameters to the engine - bpWriterSettings.SetParameters("Aggregation", - (nproc + 1) / 2); // number of aggregators + int a; + float b; + double c; + }; + const int Nparts = rand() % 6 + 5; // random size per process, 5..10 each + + std::vector<s1_t> NiceArray(Nx); + for (int i = 0; i < Nx; i++) + { + NiceArray.push_back(ss1_t()); + NiceArray[i].a = rank * Nx + (double)i; + NiceArray[i].b = 100.0 * rank * Nx + 100.0 * (double)i; + NiceArray[i].c = 10000.0 * rank * Nx + 10000.0 * (double)i; } - // Open returns a smart pointer to Engine containing the Derived class - // Writer - // "w" means we overwrite any existing file on disk, but AdvanceStep will - // append steps later. - auto bpWriter = adios.Open("myNumbers.bp", "w", bpWriterSettings); - - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpWriter\n"); - - if (rank == 0) + try { - // Writing a global scalar from only one process - bpWriter->Write<unsigned int>(varNX, Nx); + /* GSE === compound type declaration borrowed heavily from HDF5 style */ + adios::CompType mtype(sizeof(s1_t)); + mtype.insertMember("a_name", OFFSET(s1_t, a), PredType::NATIVE_INT); + mtype.insertMember("c_name", OFFSET(s1_t, c), PredType::NATIVE_DOUBLE); + mtype.insertMember("b_name", OFFSET(s1_t, b), PredType::NATIVE_FLOAT); + + // Define group and variables with transforms, variables don't have + // functions, only group can access variables + adios::Variable<unsigned int> &varNX = + adios.DefineVariable<unsigned int>( + "NX"); // global single-value across processes + adios::Variable<int> &varNproc = adios.DefineVariable<int>( + "nproc", adios::GLOBAL_VALUE); // same def for global value + adios::Variable<int> &varNparts = + adios.DefineVariable<int>("Nparts", + adios::LOCAL_VALUE); // a single-value + // different on + // every process + + // GSE === template necessary or useful here? Extra argument for + // previously-built compound type information */ + adios::Variable<s1_t> &varNice = adios.DefineVariable<s1_t>( + "Nice", {nproc * Nx}, mtype); // 1D global array + + // add transform to variable in group...not executed (just testing API) + adios::Transform bzip2 = adios::transform::BZIP2(); + varNice->AddTransform(bzip2, 1); + + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpWriterSettings = adios.GetMethod("output"); + if (bpWriterSettings.undeclared()) + { + // if not defined by user, we can change the default settings + bpWriterSettings.SetEngine("BP"); // BP is the default engine + bpWriterSettings.AddTransport( + "File", + "lucky=yes"); // ISO-POSIX file is the default transport + // Passing parameters to the transport + bpWriterSettings.SetParameters( + "have_metadata_file", + "yes"); // Passing parameters to the engine + bpWriterSettings.SetParameters("Aggregation", + (nproc + 1) / + 2); // number of aggregators + } + + // Open returns a smart pointer to Engine containing the Derived class + // Writer + // "w" means we overwrite any existing file on disk, but AdvanceStep + // will + // append steps later. + auto bpWriter = adios.Open("myNumbers.bp", "w", bpWriterSettings); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: failed to open ADIOS bpWriter\n"); + + if (rank == 0) + { + // Writing a global scalar from only one process + bpWriter->Write<unsigned int>(varNX, Nx); + } + // Writing a local scalar on every process. Will be shown at reading as + // a 1D + // array + bpWriter->Write<int>(varNparts, Nparts); + + // Writing a global scalar on every process is useless. Information will + // be + // thrown away + // and only rank 0's data will be in the output + bpWriter->Write<int>(varNproc, nproc); + + // Make a 1D selection to describe the local dimensions of the variable + // we + // write and + // its offsets in the global spaces + adios::Selection &sel = adios.SelectionBoundingBox( + {Nx}, {rank * Nx}); // local dims and offsets; both as list + varNice.SetSelection(sel); + + // GSE === Template useful or necessary here? We have to treat this as + // a + // void* inside ADIOS... + bpWriter->Write<sl_t>(varNice, NiceArray.data()); + + // Indicate we are done for this step + // N-to-M Aggregation, disk I/O will be performed during this call, + // unless + // time aggregation postpones all of that to some later step + bpWriter->Advance(); + bpWriter->AdvanceAsync(callback_func_to_notify_me); + + // Called once: indicate that we are done with this output for the run + bpWriter->Close(); } - // Writing a local scalar on every process. Will be shown at reading as a 1D - // array - bpWriter->Write<int>(varNparts, Nparts); - - // Writing a global scalar on every process is useless. Information will be - // thrown away - // and only rank 0's data will be in the output - bpWriter->Write<int>(varNproc, nproc); - - // Make a 1D selection to describe the local dimensions of the variable we - // write and - // its offsets in the global spaces - adios::Selection &sel = adios.SelectionBoundingBox( - {Nx}, {rank * Nx}); // local dims and offsets; both as list - varNice.SetSelection(sel); - - // GSE === Template useful or necessary here? We have to treat this as a - // void* inside ADIOS... - bpWriter->Write<sl_t>(varNice, NiceArray.data()); - - // Indicate we are done for this step - // N-to-M Aggregation, disk I/O will be performed during this call, unless - // time aggregation postpones all of that to some later step - bpWriter->Advance(); - bpWriter->AdvanceAsync(callback_func_to_notify_me); - - // Called once: indicate that we are done with this output for the run - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/groupless/multistep/reader_allsteps.cpp b/examples/groupless/multistep/reader_allsteps.cpp index d71703dda7276d3dfc3c8bd19e495fbcb20ce011..1b28a82c72d71e1438c077f6b00ae88aa837a1f6 100644 --- a/examples/groupless/multistep/reader_allsteps.cpp +++ b/examples/groupless/multistep/reader_allsteps.cpp @@ -16,189 +16,201 @@ int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - std::vector<double> NiceArray; - std::vector<float> RaggedArray; - - int Nparts; - int Nwriters; - int Nsteps; - - try - { - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpReaderSettings = adios.GetMethod("input"); - if (bpReaderSettings.undeclared()) - { - // if not defined by user, we can change the default settings - bpReaderSettings.SetEngine("BP"); // BP is the default engine - // By default we see all steps available in a file, so the next line is - // not needed - bpReaderSettings.SetParameters("Stepping", false); - } + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; - // Create engine smart pointer due to polymorphism, - // Default behavior - // auto bpReader = adios.Open( "myNumbers.bp", "r" ); - // this would just open with a default transport, which is "BP" - auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); - - // All the above is same as default use: - // auto bpReader = adios.Open( "myNumbers.bp", "r"); - - if (bpReader == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpReader\n"); - - /* Note: there is no global number of steps. Each variable has its own - * number of steps */ - - /* NX */ - /* There is a single value for each step. We can read all into a 1D array - * with a step selection. - * We can also just conveniently get the first with a simple read statement. - * Steps are not automatically presented as an array dimension and read does - * not read it as array. - */ - unsigned int Nx; - bpReader->Read<unsigned int>( - "NX", &Nx); // read a Global scalar which has a single value in a step - - std::shared_ptr<adios::Variable<void>> varNx = - bpReader.InquiryVariable("Nx"); - std::vector<int> Nxs(varNx->nsteps()); // number of steps available - // make a StepSelection to select multiple steps. Args: From, #of - // consecutive steps - std::unique_ptr<adios::StepSelection> stepsNx = - adios.StepSelection(0, varNx->nsteps()); - // ? How do we make a selection for an arbitrary list of steps ? - varNX.SetStepSelection(stepsNx); - bpReader->Read<unsigned int>(varNx, Nxs.data()); - - auto itmax = std::max_element(std::begin(Nxs), std::end(Nxs)); - auto itmin = std::min_element(std::begin(Nxs), std::end(Nxs)); - if (*itmin != *itmax) - { - throw std::ios_base::failure("ERROR: NX is not the same at all steps!\n"); - } + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - /* nproc */ - bpReader->Read<int>("nproc", &Nwriters); // also a global scalar - - /* Nparts */ - // Nparts local scalar is presented as a 1D array of Nwriters elements. - // We can read all steps into a 2D array of nproc * Nwriters - std::shared_ptr<adios::Variable<void>> varNparts = - bpReader.InquiryVariable("Nparts"); - std::vector<int> partsV(Nproc * Nwriters); - varNparts->SetStepSelection(adios.StepSelection(0, varNparts->nsteps())); - bpReader->Read<int>( - varNparts, - partsV.data()); // missing spatial selection = whole array at each step - - /* Nice */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varNice = - bpReader.InquiryVariable("Nice"); - - if (varNice == nullptr) - throw std::ios_base::failure( - "ERROR: failed to find variable 'myDoubles' in input file\n"); - - // ? how do we know about the type? std::string varNice->m_Type - unsigned long long int gdim = - varMyDoubles->m_GlobalDimensions[0]; // ?member var or member func? - unsigned long long int ldim = gdim / nproc; - unsigned long long int offs = rank * ldim; - if (rank == nproc - 1) - { - ldim = gdim - (ldim * gdim); - } + // Application variable + std::vector<double> NiceArray; + std::vector<float> RaggedArray; - NiceArray.reserve(ldim); - - // Make a 1D selection to describe the local dimensions of the variable we - // READ and - // its offsets in the global spaces - std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( - {ldim}, {offs}); // local dims and offsets; both as list - bpReader->Read<double>("Nice", bbsel, - NiceArray.data()); // Base class Engine own the - // Read<T> that will call - // overloaded Read from Derived - - /* Ragged */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varRagged = - bpReader.InquiryVariable("Ragged"); - if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) - { - throw std::ios_base::failure( - "Unexpected condition: Ragged array's fast dimension " - "is supposed to be VARYING_DIMENSION\n"); - } - // We have here varRagged->sum_nblocks, nsteps, nblocks[], global - if (rank < varRagged->nblocks[0]) // same as rank < Nwriters in this example - { - // get per-writer size information - varRagged->InquiryBlocks(); - // now we have the dimensions per block - - unsigned long long int ldim = varRagged->blockinfo[rank].m_Dimensions[0]; - RaggedArray.resize(ldim); + int Nparts; + int Nwriters; + int Nsteps; - std::unique_ptr<adios::Selection> wbsel = adios.SelectionWriteblock(rank); - bpReader->Read<float>("Ragged", wbsel, RaggedArray.data()); - - // We can use bounding box selection as well - std::unique_ptr<adios::Selection> rbbsel = - adios.SelectionBoundingBox({1, ldim}, {rank, 0}); - bpReader->Read<float>("Ragged", rbbsel, RaggedArray.data()); + try + { + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpReaderSettings = adios.GetMethod("input"); + if (bpReaderSettings.undeclared()) + { + // if not defined by user, we can change the default settings + bpReaderSettings.SetEngine("BP"); // BP is the default engine + // By default we see all steps available in a file, so the next line + // is + // not needed + bpReaderSettings.SetParameters("Stepping", false); + } + + // Create engine smart pointer due to polymorphism, + // Default behavior + // auto bpReader = adios.Open( "myNumbers.bp", "r" ); + // this would just open with a default transport, which is "BP" + auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); + + // All the above is same as default use: + // auto bpReader = adios.Open( "myNumbers.bp", "r"); + + if (bpReader == nullptr) + throw std::ios_base::failure( + "ERROR: failed to open ADIOS bpReader\n"); + + /* Note: there is no global number of steps. Each variable has its own + * number of steps */ + + /* NX */ + /* There is a single value for each step. We can read all into a 1D + * array + * with a step selection. + * We can also just conveniently get the first with a simple read + * statement. + * Steps are not automatically presented as an array dimension and read + * does + * not read it as array. + */ + unsigned int Nx; + bpReader->Read<unsigned int>( + "NX", + &Nx); // read a Global scalar which has a single value in a step + + std::shared_ptr<adios::Variable<void>> varNx = + bpReader.InquiryVariable("Nx"); + std::vector<int> Nxs(varNx->nsteps()); // number of steps available + // make a StepSelection to select multiple steps. Args: From, #of + // consecutive steps + std::unique_ptr<adios::StepSelection> stepsNx = + adios.StepSelection(0, varNx->nsteps()); + // ? How do we make a selection for an arbitrary list of steps ? + varNX.SetStepSelection(stepsNx); + bpReader->Read<unsigned int>(varNx, Nxs.data()); + + auto itmax = std::max_element(std::begin(Nxs), std::end(Nxs)); + auto itmin = std::min_element(std::begin(Nxs), std::end(Nxs)); + if (*itmin != *itmax) + { + throw std::ios_base::failure( + "ERROR: NX is not the same at all steps!\n"); + } + + /* nproc */ + bpReader->Read<int>("nproc", &Nwriters); // also a global scalar + + /* Nparts */ + // Nparts local scalar is presented as a 1D array of Nwriters elements. + // We can read all steps into a 2D array of nproc * Nwriters + std::shared_ptr<adios::Variable<void>> varNparts = + bpReader.InquiryVariable("Nparts"); + std::vector<int> partsV(Nproc * Nwriters); + varNparts->SetStepSelection( + adios.StepSelection(0, varNparts->nsteps())); + bpReader->Read<int>(varNparts, + partsV.data()); // missing spatial selection = whole + // array at each step + + /* Nice */ + // inquiry about a variable, whose name we know + std::shared_ptr<adios::Variable<void>> varNice = + bpReader.InquiryVariable("Nice"); + + if (varNice == nullptr) + throw std::ios_base::failure("ERROR: failed to find variable " + "'myDoubles' in input file\n"); + + // ? how do we know about the type? std::string varNice->m_Type + unsigned long long int gdim = + varMyDoubles->m_GlobalDimensions[0]; // ?member var or member func? + unsigned long long int ldim = gdim / nproc; + unsigned long long int offs = rank * ldim; + if (rank == nproc - 1) + { + ldim = gdim - (ldim * gdim); + } + + NiceArray.reserve(ldim); + + // Make a 1D selection to describe the local dimensions of the variable + // we + // READ and + // its offsets in the global spaces + std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( + {ldim}, {offs}); // local dims and offsets; both as list + bpReader->Read<double>("Nice", bbsel, + NiceArray.data()); // Base class Engine own the + // Read<T> that will call + // overloaded Read from Derived + + /* Ragged */ + // inquiry about a variable, whose name we know + std::shared_ptr<adios::Variable<void>> varRagged = + bpReader.InquiryVariable("Ragged"); + if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) + { + throw std::ios_base::failure( + "Unexpected condition: Ragged array's fast dimension " + "is supposed to be VARYING_DIMENSION\n"); + } + // We have here varRagged->sum_nblocks, nsteps, nblocks[], global + if (rank < + varRagged->nblocks[0]) // same as rank < Nwriters in this example + { + // get per-writer size information + varRagged->InquiryBlocks(); + // now we have the dimensions per block + + unsigned long long int ldim = + varRagged->blockinfo[rank].m_Dimensions[0]; + RaggedArray.resize(ldim); + + std::unique_ptr<adios::Selection> wbsel = + adios.SelectionWriteblock(rank); + bpReader->Read<float>("Ragged", wbsel, RaggedArray.data()); + + // We can use bounding box selection as well + std::unique_ptr<adios::Selection> rbbsel = + adios.SelectionBoundingBox({1, ldim}, {rank, 0}); + bpReader->Read<float>("Ragged", rbbsel, RaggedArray.data()); + } + + /* Extra help to process Ragged */ + int maxRaggedDim = + varRagged->GetMaxGlobalDimensions(1); // contains the largest + std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( + 1); // contains all individual sizes in that dimension + + // Close file/stream + bpReader->Close(); } - - /* Extra help to process Ragged */ - int maxRaggedDim = - varRagged->GetMaxGlobalDimensions(1); // contains the largest - std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( - 1); // contains all individual sizes in that dimension - - // Close file/stream - bpReader->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/groupless/multistep/reader_stepping.cpp b/examples/groupless/multistep/reader_stepping.cpp index df5adb7d542b9c031c6312bd6db4613b0c40467c..5328408da4249e62be66d2157a3cdb43a57ae703 100644 --- a/examples/groupless/multistep/reader_stepping.cpp +++ b/examples/groupless/multistep/reader_stepping.cpp @@ -16,185 +16,196 @@ int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - std::vector<double> NiceArray; - std::vector<float> RaggedArray; - unsigned int Nx; - int Nparts; - int Nwriters; - int Nsteps; - - try - { - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpReaderSettings = adios.GetMethod("input"); - if (bpReaderSettings.undeclared()) - { - // if not defined by user, we can change the default settings - bpReaderSettings.SetEngine("BP"); // BP is the default engine - bpReaderSettings.SetParameters("Stepping", - true); // see only one step at a time - } + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + + // Application variable + std::vector<double> NiceArray; + std::vector<float> RaggedArray; + unsigned int Nx; + int Nparts; + int Nwriters; + int Nsteps; - // Create engine smart pointer due to polymorphism, - // Default behavior - // auto bpReader = adios.Open( "myNumbers.bp", "r" ); - // this would just open with a default transport, which is "BP" try { - auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); - - while (true) - { - /* NX */ - bpReader->Read<unsigned int>( - "NX", - &Nx); // read a Global scalar which has a single value in a step - - /* nproc */ - bpReader->Read<int>("nproc", &Nwriters); // also a global scalar - - /* Nparts */ - // Nparts local scalar is presented as a 1D array of Nwriters elements. - // We can read all as a 1D array - std::vector<int> partsV(Nwriters); - bpReader->Read<int>( - "Nparts", - &partsV); // read with string name, no selection => read whole array - - /* Nice */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varNice = - bpReader.InquiryVariable("Nice"); - - if (varNice == nullptr) - throw std::ios_base::failure( - "ERROR: failed to find variable 'myDoubles' in input file\n"); - - // ? how do we know about the type? std::string varNice->m_Type - unsigned long long int gdim = - varMyDoubles->m_GlobalDimensions[0]; // ?member var or member func? - unsigned long long int ldim = gdim / nproc; - unsigned long long int offs = rank * ldim; - if (rank == nproc - 1) + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpReaderSettings = adios.GetMethod("input"); + if (bpReaderSettings.undeclared()) { - ldim = gdim - (ldim * gdim); + // if not defined by user, we can change the default settings + bpReaderSettings.SetEngine("BP"); // BP is the default engine + bpReaderSettings.SetParameters("Stepping", + true); // see only one step at a time } - NiceArray.reserve(ldim); - - // Make a 1D selection to describe the local dimensions of the variable - // we READ and - // its offsets in the global spaces - std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( - {ldim}, {offs}); // local dims and offsets; both as list - varNice->SetSelection(bbsel); - bpReader->Read<double>(varNice, NiceArray.data()); - - /* Ragged */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varRagged = - bpReader.InquiryVariable("Ragged"); - if (varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION) + // Create engine smart pointer due to polymorphism, + // Default behavior + // auto bpReader = adios.Open( "myNumbers.bp", "r" ); + // this would just open with a default transport, which is "BP" + try { - throw std::ios_base::failure( - "Unexpected condition: Ragged array's fast dimension " - "is supposed to be VARYING_DIMENSION\n"); + auto bpReader = adios.Open("myNumbers.bp", "r", bpReaderSettings); + + while (true) + { + /* NX */ + bpReader->Read<unsigned int>("NX", + &Nx); // read a Global scalar which + // has a single value in a + // step + + /* nproc */ + bpReader->Read<int>("nproc", &Nwriters); // also a global scalar + + /* Nparts */ + // Nparts local scalar is presented as a 1D array of Nwriters + // elements. + // We can read all as a 1D array + std::vector<int> partsV(Nwriters); + bpReader->Read<int>("Nparts", + &partsV); // read with string name, no + // selection => read whole array + + /* Nice */ + // inquiry about a variable, whose name we know + std::shared_ptr<adios::Variable<void>> varNice = + bpReader.InquiryVariable("Nice"); + + if (varNice == nullptr) + throw std::ios_base::failure("ERROR: failed to find " + "variable 'myDoubles' in " + "input file\n"); + + // ? how do we know about the type? std::string varNice->m_Type + unsigned long long int gdim = + varMyDoubles->m_GlobalDimensions[0]; // ?member var or + // member func? + unsigned long long int ldim = gdim / nproc; + unsigned long long int offs = rank * ldim; + if (rank == nproc - 1) + { + ldim = gdim - (ldim * gdim); + } + + NiceArray.reserve(ldim); + + // Make a 1D selection to describe the local dimensions of the + // variable + // we READ and + // its offsets in the global spaces + std::unique_ptr<adios::Selection> bbsel = + adios.SelectionBoundingBox( + {ldim}, {offs}); // local dims and offsets; both as list + varNice->SetSelection(bbsel); + bpReader->Read<double>(varNice, NiceArray.data()); + + /* Ragged */ + // inquiry about a variable, whose name we know + std::shared_ptr<adios::Variable<void>> varRagged = + bpReader.InquiryVariable("Ragged"); + if (varRagged->m_GlobalDimensions[1] != + adios::VARYING_DIMENSION) + { + throw std::ios_base::failure( + "Unexpected condition: Ragged array's fast " + "dimension " + "is supposed to be VARYING_DIMENSION\n"); + } + // We have here varRagged->sum_nblocks, nsteps, nblocks[], + // global + if (rank < varRagged->nblocks[0]) // same as rank < Nwriters in + // this example + { + // get per-writer size information + varRagged->InquiryBlocks(); + // now we have the dimensions per block + + unsigned long long int ldim = + varRagged->blockinfo[rank].m_Dimensions[0]; + RaggedArray.resize(ldim); + + std::unique_ptr<adios::Selection> wbsel = + adios.SelectionWriteblock(rank); + varRagged->SetSelection(wbsel); + bpReader->Read<float>(varRagged, RaggedArray.data()); + + // We can use bounding box selection as well + std::unique_ptr<adios::Selection> rbbsel = + adios.SelectionBoundingBox({1, ldim}, {rank, 0}); + varRagged->SetSelection(rbbsel); + bpReader->Read<float>(varRagged, RaggedArray.data()); + } + + /* Extra help to process Ragged */ + int maxRaggedDim = varRagged->GetMaxGlobalDimensions( + 1); // contains the largest + std::vector<int> raggedDims = + varRagged->GetVaryingGlobalDimensions( + 1); // contains all individual sizes in that + // dimension + + // promise to not read more from this step + bpReader->Release(); + + // want to move on to the next available step + // bpReader->Advance(adios::NextStep); + // bpReader->Advance(adios::LatestStep); + bpReader->Advance(); // default is adios::NextStep + } + + // Close file/stream + bpReader->Close(); } - // We have here varRagged->sum_nblocks, nsteps, nblocks[], global - if (rank < - varRagged->nblocks[0]) // same as rank < Nwriters in this example + catch (adios::end_of_stream &e) { - // get per-writer size information - varRagged->InquiryBlocks(); - // now we have the dimensions per block - - unsigned long long int ldim = - varRagged->blockinfo[rank].m_Dimensions[0]; - RaggedArray.resize(ldim); - - std::unique_ptr<adios::Selection> wbsel = - adios.SelectionWriteblock(rank); - varRagged->SetSelection(wbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); - - // We can use bounding box selection as well - std::unique_ptr<adios::Selection> rbbsel = - adios.SelectionBoundingBox({1, ldim}, {rank, 0}); - varRagged->SetSelection(rbbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); + if (rank == 0) + { + std::cout << "Reached end of stream, end processing loop.\n"; + } + // Close file/stream + bpReader->Close(); + } + catch (adios::file_not_found &e) + { + if (rank == 0) + { + std::cout << "File/stream does not exist, quit.\n"; + } } - - /* Extra help to process Ragged */ - int maxRaggedDim = - varRagged->GetMaxGlobalDimensions(1); // contains the largest - std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( - 1); // contains all individual sizes in that dimension - - // promise to not read more from this step - bpReader->Release(); - - // want to move on to the next available step - // bpReader->Advance(adios::NextStep); - // bpReader->Advance(adios::LatestStep); - bpReader->Advance(); // default is adios::NextStep - } - - // Close file/stream - bpReader->Close(); - } - catch (adios::end_of_stream &e) - { - if (rank == 0) - { - std::cout << "Reached end of stream, end processing loop.\n"; - } - // Close file/stream - bpReader->Close(); - } - catch (adios::file_not_found &e) - { - if (rank == 0) - { - std::cout << "File/stream does not exist, quit.\n"; - } } - } - catch (std::invalid_argument &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/groupless/multistep/writer_multistep.cpp b/examples/groupless/multistep/writer_multistep.cpp index 946d20f951356e8121dceef8a27f31b38f5b2d29..696d4bdb636ed422d4872ae043505551a84e05a9 100644 --- a/examples/groupless/multistep/writer_multistep.cpp +++ b/examples/groupless/multistep/writer_multistep.cpp @@ -21,152 +21,165 @@ typedef enum { VARYING_DIMENSION = -1, LOCAL_VALUE = 0, GLOBAL_VALUE = 1 }; int main(int argc, char *argv[]) { - int rank, nproc; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - const int NSTEPS = 5; - - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - const unsigned int Nx = 10; - int Nparts; // random size per process, 5..10 each - - std::vector<double> NiceArray(Nx); - for (int i = 0; i < Nx; i++) - { - NiceArray[i] = rank * Nx + (double)i; - } - - std::vector<float> RaggedArray; - - try - { - // Define group and variables with transforms, variables don't have - // functions, only group can access variables - adios::Variable<unsigned int> &varNX = adios.DefineVariable<unsigned int>( - "NX"); // global single-value across processes - adios::Variable<int> &varNproc = adios.DefineVariable<int>( - "nproc", adios::GLOBAL_VALUE); // same def for global value - adios::Variable<int> &varNparts = adios.DefineVariable<int>( - "Nparts", - adios::LOCAL_VALUE); // a single-value different on every process - adios::Variable<double> &varNice = - adios.DefineVariable<double>("Nice", {nproc * Nx}); // 1D global array - adios::Variable<float> &varRagged = adios.DefineVariable<float>( - "Ragged", {nproc, adios::VARYING_DIMENSION}); // ragged array - - // add transform to variable in group...not executed (just testing API) - adios::Transform bzip2 = adios::transform::BZIP2(); - varNice->AddTransform(bzip2, 1); - - // Define method for engine creation - // 1. Get method def from config file or define new one - adios::Method &bpWriterSettings = adios.GetMethod("output"); - if (bpWriterSettings.undeclared()) - { - // if not defined by user, we can change the default settings - bpWriterSettings.SetEngine("BP"); // BP is the default engine - bpWriterSettings.AddTransport( - "File", "lucky=yes"); // ISO-POSIX file is the default transport - // Passing parameters to the transport - bpWriterSettings.SetParameters("have_metadata_file", - "yes"); // Passing parameters to the engine - bpWriterSettings.SetParameters("Aggregation", - (nproc + 1) / 2); // number of aggregators - } + int rank, nproc; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + const int NSTEPS = 5; - // Open returns a smart pointer to Engine containing the Derived class - // Writer - // "w" means we overwrite any existing file on disk, but AdvanceStep will - // append steps later. - auto bpWriter = adios.Open("myNumbers.bp", "w", bpWriterSettings); + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpWriter\n"); + // Application variable + const unsigned int Nx = 10; + int Nparts; // random size per process, 5..10 each - for (int step; step < NSTEPS; step++) + std::vector<double> NiceArray(Nx); + for (int i = 0; i < Nx; i++) { - int Nparts = rand() % 6 + 5; // random size per process, 5..10 each - RaggedArray.reserve(Nparts); - for (int i = 0; i < Nparts; i++) - { - RaggedArray[i] = rank * Nx + (float)i; - } - - if (rank == 0) - { - // Writing a global scalar from only one process - bpWriter->Write<unsigned int>(varNX, &Nx); - } - // Writing a local scalar on every process. Will be shown at reading as a - // 1D array - bpWriter->Write<int>(varNparts, &Nparts); - - // Writing a global scalar on every process is useless. Information will - // be thrown away - // and only rank 0's data will be in the output - bpWriter->Write<int>(varNproc, &nproc); - - // Make a 1D selection to describe the local dimensions of the variable we - // write and - // its offsets in the global spaces - adios::Selection &sel = adios.SelectionBoundingBox( - {Nx}, {rank * Nx}); // local dims and offsets; both as list - NiceArray.SetSelection(sel); - bpWriter->Write<double>(varNice, NiceArray.data()); // Base class Engine - // own the Write<T> - // that will call - // overloaded Write - // from Derived - - adios::Selection &lsel = - adios.SelectionBoundingBox({1, Nparts}, {rank, 0}); - RaggedArray.SetSelection(sel); - bpWriter->Write<float>(varRagged, RaggedArray.data()); // Base class - // Engine own the - // Write<T> that - // will call - // overloaded Write - // from Derived - - // Indicate we are done for this step - // N-to-M Aggregation, disk I/O will be performed during this call, unless - // time aggregation postpones all of that to some later step - bpWriter->Advance(); + NiceArray[i] = rank * Nx + (double)i; } - // Called once: indicate that we are done with this output for the run - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + std::vector<float> RaggedArray; + + try + { + // Define group and variables with transforms, variables don't have + // functions, only group can access variables + adios::Variable<unsigned int> &varNX = + adios.DefineVariable<unsigned int>( + "NX"); // global single-value across processes + adios::Variable<int> &varNproc = adios.DefineVariable<int>( + "nproc", adios::GLOBAL_VALUE); // same def for global value + adios::Variable<int> &varNparts = + adios.DefineVariable<int>("Nparts", + adios::LOCAL_VALUE); // a single-value + // different on + // every process + adios::Variable<double> &varNice = adios.DefineVariable<double>( + "Nice", {nproc * Nx}); // 1D global array + adios::Variable<float> &varRagged = adios.DefineVariable<float>( + "Ragged", {nproc, adios::VARYING_DIMENSION}); // ragged array + + // add transform to variable in group...not executed (just testing API) + adios::Transform bzip2 = adios::transform::BZIP2(); + varNice->AddTransform(bzip2, 1); + + // Define method for engine creation + // 1. Get method def from config file or define new one + adios::Method &bpWriterSettings = adios.GetMethod("output"); + if (bpWriterSettings.undeclared()) + { + // if not defined by user, we can change the default settings + bpWriterSettings.SetEngine("BP"); // BP is the default engine + bpWriterSettings.AddTransport( + "File", + "lucky=yes"); // ISO-POSIX file is the default transport + // Passing parameters to the transport + bpWriterSettings.SetParameters( + "have_metadata_file", + "yes"); // Passing parameters to the engine + bpWriterSettings.SetParameters("Aggregation", + (nproc + 1) / + 2); // number of aggregators + } + + // Open returns a smart pointer to Engine containing the Derived class + // Writer + // "w" means we overwrite any existing file on disk, but AdvanceStep + // will + // append steps later. + auto bpWriter = adios.Open("myNumbers.bp", "w", bpWriterSettings); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: failed to open ADIOS bpWriter\n"); + + for (int step; step < NSTEPS; step++) + { + int Nparts = rand() % 6 + 5; // random size per process, 5..10 each + RaggedArray.reserve(Nparts); + for (int i = 0; i < Nparts; i++) + { + RaggedArray[i] = rank * Nx + (float)i; + } + + if (rank == 0) + { + // Writing a global scalar from only one process + bpWriter->Write<unsigned int>(varNX, &Nx); + } + // Writing a local scalar on every process. Will be shown at reading + // as a + // 1D array + bpWriter->Write<int>(varNparts, &Nparts); + + // Writing a global scalar on every process is useless. Information + // will + // be thrown away + // and only rank 0's data will be in the output + bpWriter->Write<int>(varNproc, &nproc); + + // Make a 1D selection to describe the local dimensions of the + // variable we + // write and + // its offsets in the global spaces + adios::Selection &sel = adios.SelectionBoundingBox( + {Nx}, {rank * Nx}); // local dims and offsets; both as list + NiceArray.SetSelection(sel); + bpWriter->Write<double>(varNice, + NiceArray.data()); // Base class Engine + // own the Write<T> + // that will call + // overloaded Write + // from Derived + + adios::Selection &lsel = + adios.SelectionBoundingBox({1, Nparts}, {rank, 0}); + RaggedArray.SetSelection(sel); + bpWriter->Write<float>(varRagged, RaggedArray.data()); // Base class + // Engine own the + // Write<T> that + // will call + // overloaded Write + // from Derived + + // Indicate we are done for this step + // N-to-M Aggregation, disk I/O will be performed during this call, + // unless + // time aggregation postpones all of that to some later step + bpWriter->Advance(); + } + + // Called once: indicate that we are done with this output for the run + bpWriter->Close(); + } + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/heatTransfer/HeatTransfer.cpp b/examples/heatTransfer/HeatTransfer.cpp index 5cac74fc91b389d6a6167b95e9fc8a58a0737dd7..ac706e4c66d75c5e342faa915ae2edb8aa4519e2 100644 --- a/examples/heatTransfer/HeatTransfer.cpp +++ b/examples/heatTransfer/HeatTransfer.cpp @@ -23,212 +23,213 @@ HeatTransfer::HeatTransfer(const Settings &settings) : m_s{settings} { - m_T1 = new double *[m_s.ndx + 2]; - m_T1[0] = new double[(m_s.ndx + 2) * (m_s.ndy + 2)]; - m_T2 = new double *[m_s.ndx + 2]; - m_T2[0] = new double[(m_s.ndx + 2) * (m_s.ndy + 2)]; - for (unsigned int i = 1; i < m_s.ndx + 2; i++) - { - m_T1[i] = m_T1[i - 1] + m_s.ndy + 2; - m_T2[i] = m_T2[i - 1] + m_s.ndy + 2; - } - m_TCurrent = m_T1; - m_TNext = m_T2; + m_T1 = new double *[m_s.ndx + 2]; + m_T1[0] = new double[(m_s.ndx + 2) * (m_s.ndy + 2)]; + m_T2 = new double *[m_s.ndx + 2]; + m_T2[0] = new double[(m_s.ndx + 2) * (m_s.ndy + 2)]; + for (unsigned int i = 1; i < m_s.ndx + 2; i++) + { + m_T1[i] = m_T1[i - 1] + m_s.ndy + 2; + m_T2[i] = m_T2[i - 1] + m_s.ndy + 2; + } + m_TCurrent = m_T1; + m_TNext = m_T2; } HeatTransfer::~HeatTransfer() { - delete[] m_T1[0]; - delete[] m_T1; - delete[] m_T2[0]; - delete[] m_T2; + delete[] m_T1[0]; + delete[] m_T1; + delete[] m_T2[0]; + delete[] m_T2; } void HeatTransfer::init(bool init_with_rank) { - if (init_with_rank) - { - for (unsigned int i = 0; i < m_s.ndx + 2; i++) - for (unsigned int j = 0; j < m_s.ndy + 2; j++) - m_T1[i][j] = m_s.rank; - } - else - { - const double hx = 2.0 * 4.0 * atan(1.0) / m_s.ndx; - const double hy = 2.0 * 4.0 * atan(1.0) / m_s.ndy; - - double x, y; - for (unsigned int i = 0; i < m_s.ndx + 2; i++) + if (init_with_rank) + { + for (unsigned int i = 0; i < m_s.ndx + 2; i++) + for (unsigned int j = 0; j < m_s.ndy + 2; j++) + m_T1[i][j] = m_s.rank; + } + else { - x = 0.0 + hx * (i - 1); - for (unsigned int j = 0; j < m_s.ndy + 2; j++) - { - y = 0.0 + hy * (j - 1); - m_T1[i][j] = cos(8 * x) + cos(6 * x) - cos(4 * x) + cos(2 * x) - - cos(x) + sin(8 * y) - sin(6 * y) + sin(4 * y) - - sin(2 * y) + sin(y); - } - } - } - m_TCurrent = m_T1; - m_TNext = m_T2; + const double hx = 2.0 * 4.0 * atan(1.0) / m_s.ndx; + const double hy = 2.0 * 4.0 * atan(1.0) / m_s.ndy; + + double x, y; + for (unsigned int i = 0; i < m_s.ndx + 2; i++) + { + x = 0.0 + hx * (i - 1); + for (unsigned int j = 0; j < m_s.ndy + 2; j++) + { + y = 0.0 + hy * (j - 1); + m_T1[i][j] = cos(8 * x) + cos(6 * x) - cos(4 * x) + cos(2 * x) - + cos(x) + sin(8 * y) - sin(6 * y) + sin(4 * y) - + sin(2 * y) + sin(y); + } + } + } + m_TCurrent = m_T1; + m_TNext = m_T2; } void HeatTransfer::printT(std::string message, MPI_Comm comm) const { - int rank, size; - int tag = 1; - int token; - MPI_Status status; - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &size); - if (rank > 0) - { - MPI_Recv(&token, 1, MPI_INT, rank - 1, tag, comm, &status); - } - - std::cout << "Rank " << rank << " " << message << std::endl; - for (unsigned int i = 0; i < m_s.ndx + 2; i++) - { - std::cout << " T[" << i << "][] = "; - for (unsigned int j = 0; j < m_s.ndy + 2; j++) - { - std::cout << std::setw(6) << m_TCurrent[i][j]; - } - std::cout << std::endl; - } - std::cout << std::flush << std::endl; - - if (rank < size - 1) - { - MPI_Send(&token, 1, MPI_INT, rank + 1, tag, comm); - } + int rank, size; + int tag = 1; + int token; + MPI_Status status; + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + if (rank > 0) + { + MPI_Recv(&token, 1, MPI_INT, rank - 1, tag, comm, &status); + } + + std::cout << "Rank " << rank << " " << message << std::endl; + for (unsigned int i = 0; i < m_s.ndx + 2; i++) + { + std::cout << " T[" << i << "][] = "; + for (unsigned int j = 0; j < m_s.ndy + 2; j++) + { + std::cout << std::setw(6) << m_TCurrent[i][j]; + } + std::cout << std::endl; + } + std::cout << std::flush << std::endl; + + if (rank < size - 1) + { + MPI_Send(&token, 1, MPI_INT, rank + 1, tag, comm); + } } void HeatTransfer::switchCurrentNext() { - double **tmp = m_TCurrent; - m_TCurrent = m_TNext; - m_TNext = tmp; + double **tmp = m_TCurrent; + m_TCurrent = m_TNext; + m_TNext = tmp; } void HeatTransfer::iterate() { - for (unsigned int i = 1; i <= m_s.ndx; ++i) - { - for (unsigned int j = 1; j <= m_s.ndy; ++j) + for (unsigned int i = 1; i <= m_s.ndx; ++i) { - m_TNext[i][j] = - omega / 4 * (m_TCurrent[i - 1][j] + m_TCurrent[i + 1][j] + - m_TCurrent[i][j - 1] + m_TCurrent[i][j + 1]) + - (1.0 - omega) * m_TCurrent[i][j]; + for (unsigned int j = 1; j <= m_s.ndy; ++j) + { + m_TNext[i][j] = + omega / 4 * (m_TCurrent[i - 1][j] + m_TCurrent[i + 1][j] + + m_TCurrent[i][j - 1] + m_TCurrent[i][j + 1]) + + (1.0 - omega) * m_TCurrent[i][j]; + } } - } - switchCurrentNext(); + switchCurrentNext(); } void HeatTransfer::heatEdges() { - // Heat the whole global edges - if (m_s.posx == 0) - for (unsigned int j = 0; j < m_s.ndy + 2; ++j) - m_TCurrent[0][j] = edgetemp; - - if (m_s.posx == m_s.npx - 1) - for (unsigned int j = 0; j < m_s.ndy + 2; ++j) - m_TCurrent[m_s.ndx + 1][j] = edgetemp; - - if (m_s.posy == 0) - for (unsigned int i = 0; i < m_s.ndx + 2; ++i) - m_TCurrent[i][0] = edgetemp; - - if (m_s.posy == m_s.npy - 1) - for (unsigned int i = 0; i < m_s.ndx + 2; ++i) - m_TCurrent[i][m_s.ndy + 1] = edgetemp; + // Heat the whole global edges + if (m_s.posx == 0) + for (unsigned int j = 0; j < m_s.ndy + 2; ++j) + m_TCurrent[0][j] = edgetemp; + + if (m_s.posx == m_s.npx - 1) + for (unsigned int j = 0; j < m_s.ndy + 2; ++j) + m_TCurrent[m_s.ndx + 1][j] = edgetemp; + + if (m_s.posy == 0) + for (unsigned int i = 0; i < m_s.ndx + 2; ++i) + m_TCurrent[i][0] = edgetemp; + + if (m_s.posy == m_s.npy - 1) + for (unsigned int i = 0; i < m_s.ndx + 2; ++i) + m_TCurrent[i][m_s.ndy + 1] = edgetemp; } void HeatTransfer::exchange(MPI_Comm comm) { - // Exchange ghost cells, in the order left-right-up-down - - double *send_x = new double[m_s.ndx + 2]; - double *recv_x = new double[m_s.ndx + 2]; - - // send to left + receive from right - int tag = 1; - MPI_Status status; - if (m_s.rank_left >= 0) - { - std::cout << "Rank " << m_s.rank << " send left to rank " << m_s.rank_left - << std::endl; - for (unsigned int i = 0; i < m_s.ndx + 2; ++i) - send_x[i] = m_TCurrent[i][1]; - MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm); - } - if (m_s.rank_right >= 0) - { - std::cout << "Rank " << m_s.rank << " receive from right from rank " - << m_s.rank_right << std::endl; - MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm, - &status); - for (unsigned int i = 0; i < m_s.ndx + 2; ++i) - m_TCurrent[i][m_s.ndy + 1] = recv_x[i]; - } - - // send to right + receive from left - tag = 2; - if (m_s.rank_right >= 0) - { - std::cout << "Rank " << m_s.rank << " send right to rank " << m_s.rank_right - << std::endl; - for (unsigned int i = 0; i < m_s.ndx + 2; ++i) - send_x[i] = m_TCurrent[i][m_s.ndy]; - MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm); - } - if (m_s.rank_left >= 0) - { - std::cout << "Rank " << m_s.rank << " receive from left from rank " - << m_s.rank_left << std::endl; - MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm, &status); - for (unsigned int i = 0; i < m_s.ndx + 2; ++i) - m_TCurrent[i][0] = recv_x[i]; - } - - // send down + receive from above - tag = 3; - if (m_s.rank_down >= 0) - { - std::cout << "Rank " << m_s.rank << " send down to rank " << m_s.rank_down - << std::endl; - MPI_Send(m_TCurrent[m_s.ndx], m_s.ndy + 2, MPI_REAL8, m_s.rank_down, tag, - comm); - } - if (m_s.rank_up >= 0) - { - std::cout << "Rank " << m_s.rank << " receive from above from rank " - << m_s.rank_up << std::endl; - MPI_Recv(m_TCurrent[0], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm, - &status); - } - - // send up + receive from below - tag = 4; - if (m_s.rank_up >= 0) - { - std::cout << "Rank " << m_s.rank << " send up to rank " << m_s.rank_up - << std::endl; - MPI_Send(m_TCurrent[1], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm); - } - if (m_s.rank_down >= 0) - { - std::cout << "Rank " << m_s.rank << " receive from below from rank " - << m_s.rank_down << std::endl; - MPI_Recv(m_TCurrent[m_s.ndx + 1], m_s.ndy + 2, MPI_REAL8, m_s.rank_down, - tag, comm, &status); - } - - delete[] send_x; - delete[] recv_x; + // Exchange ghost cells, in the order left-right-up-down + + double *send_x = new double[m_s.ndx + 2]; + double *recv_x = new double[m_s.ndx + 2]; + + // send to left + receive from right + int tag = 1; + MPI_Status status; + if (m_s.rank_left >= 0) + { + std::cout << "Rank " << m_s.rank << " send left to rank " + << m_s.rank_left << std::endl; + for (unsigned int i = 0; i < m_s.ndx + 2; ++i) + send_x[i] = m_TCurrent[i][1]; + MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm); + } + if (m_s.rank_right >= 0) + { + std::cout << "Rank " << m_s.rank << " receive from right from rank " + << m_s.rank_right << std::endl; + MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm, + &status); + for (unsigned int i = 0; i < m_s.ndx + 2; ++i) + m_TCurrent[i][m_s.ndy + 1] = recv_x[i]; + } + + // send to right + receive from left + tag = 2; + if (m_s.rank_right >= 0) + { + std::cout << "Rank " << m_s.rank << " send right to rank " + << m_s.rank_right << std::endl; + for (unsigned int i = 0; i < m_s.ndx + 2; ++i) + send_x[i] = m_TCurrent[i][m_s.ndy]; + MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm); + } + if (m_s.rank_left >= 0) + { + std::cout << "Rank " << m_s.rank << " receive from left from rank " + << m_s.rank_left << std::endl; + MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm, + &status); + for (unsigned int i = 0; i < m_s.ndx + 2; ++i) + m_TCurrent[i][0] = recv_x[i]; + } + + // send down + receive from above + tag = 3; + if (m_s.rank_down >= 0) + { + std::cout << "Rank " << m_s.rank << " send down to rank " + << m_s.rank_down << std::endl; + MPI_Send(m_TCurrent[m_s.ndx], m_s.ndy + 2, MPI_REAL8, m_s.rank_down, + tag, comm); + } + if (m_s.rank_up >= 0) + { + std::cout << "Rank " << m_s.rank << " receive from above from rank " + << m_s.rank_up << std::endl; + MPI_Recv(m_TCurrent[0], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm, + &status); + } + + // send up + receive from below + tag = 4; + if (m_s.rank_up >= 0) + { + std::cout << "Rank " << m_s.rank << " send up to rank " << m_s.rank_up + << std::endl; + MPI_Send(m_TCurrent[1], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm); + } + if (m_s.rank_down >= 0) + { + std::cout << "Rank " << m_s.rank << " receive from below from rank " + << m_s.rank_down << std::endl; + MPI_Recv(m_TCurrent[m_s.ndx + 1], m_s.ndy + 2, MPI_REAL8, m_s.rank_down, + tag, comm, &status); + } + + delete[] send_x; + delete[] recv_x; } #include <cstring> @@ -238,11 +239,11 @@ void HeatTransfer::exchange(MPI_Comm comm) */ std::vector<double> HeatTransfer::data_noghost() const { - std::vector<double> d(m_s.ndx * m_s.ndy); - for (unsigned int i = 1; i <= m_s.ndx; ++i) - { - std::memcpy(&d[(i - 1) * m_s.ndy], m_TCurrent[i] + 1, - m_s.ndy * sizeof(double)); - } - return d; + std::vector<double> d(m_s.ndx * m_s.ndy); + for (unsigned int i = 1; i <= m_s.ndx; ++i) + { + std::memcpy(&d[(i - 1) * m_s.ndy], m_TCurrent[i] + 1, + m_s.ndy * sizeof(double)); + } + return d; } diff --git a/examples/heatTransfer/HeatTransfer.h b/examples/heatTransfer/HeatTransfer.h index 12334f0664a36eaf54b86aa1b83e2d607a5cd4d8..7d48eb558d2db274218e8b0030ad53cc2aa0f7f3 100644 --- a/examples/heatTransfer/HeatTransfer.h +++ b/examples/heatTransfer/HeatTransfer.h @@ -19,34 +19,36 @@ class HeatTransfer { public: - HeatTransfer(const Settings &settings); // Create two 2D arrays with ghost - // cells to compute - ~HeatTransfer(); - void init(bool init_with_rank); // set up array values with either rank or - // real demo values - void iterate(); // one local calculation step - void heatEdges(); // reset the heat values at the global edge - void exchange(MPI_Comm comm); // send updates to neighbors - - // return a single value at index i,j. 0 <= i <= ndx+2, 0 <= j <= ndy+2 - double T(int i, int j) const { return m_TCurrent[i][j]; }; - // return (1D) pointer to current T data, ndx+2 * ndy+2 elements - double *data() const { return m_TCurrent[0]; }; - // return (1D) pointer to current T data without ghost cells, ndx*ndy elements - std::vector<double> data_noghost() const; - - void printT(std::string message, - MPI_Comm comm) const; // debug: print local TCurrent on stdout + HeatTransfer(const Settings &settings); // Create two 2D arrays with ghost + // cells to compute + ~HeatTransfer(); + void init(bool init_with_rank); // set up array values with either rank or + // real demo values + void iterate(); // one local calculation step + void heatEdges(); // reset the heat values at the global edge + void exchange(MPI_Comm comm); // send updates to neighbors + + // return a single value at index i,j. 0 <= i <= ndx+2, 0 <= j <= ndy+2 + double T(int i, int j) const { return m_TCurrent[i][j]; }; + // return (1D) pointer to current T data, ndx+2 * ndy+2 elements + double *data() const { return m_TCurrent[0]; }; + // return (1D) pointer to current T data without ghost cells, ndx*ndy + // elements + std::vector<double> data_noghost() const; + + void printT(std::string message, + MPI_Comm comm) const; // debug: print local TCurrent on stdout private: - const double edgetemp = 3.0; // temperature at the edges of the global plate - const double omega = 0.8; // weight for current temp is (1-omega) in iteration - double **m_T1; // 2D array (ndx+2) * (ndy+2) size, including ghost cells - double **m_T2; // another 2D array - double **m_TCurrent; // pointer to T1 or T2 - double **m_TNext; // pointer to T2 or T1 - const Settings &m_s; - void switchCurrentNext(); // switch the current array with the next array + const double edgetemp = 3.0; // temperature at the edges of the global plate + const double omega = + 0.8; // weight for current temp is (1-omega) in iteration + double **m_T1; // 2D array (ndx+2) * (ndy+2) size, including ghost cells + double **m_T2; // another 2D array + double **m_TCurrent; // pointer to T1 or T2 + double **m_TNext; // pointer to T2 or T1 + const Settings &m_s; + void switchCurrentNext(); // switch the current array with the next array }; #endif /* HEATTRANSFER_H_ */ diff --git a/examples/heatTransfer/IO.h b/examples/heatTransfer/IO.h index e9c7c6195b24fab12590f009f9c0b024d7009b59..999866112e471e46f2136f804ed2ee5226bb0a0a 100644 --- a/examples/heatTransfer/IO.h +++ b/examples/heatTransfer/IO.h @@ -19,13 +19,13 @@ class IO { public: - IO(const Settings &s, MPI_Comm comm); - ~IO(); - void write(int step, const HeatTransfer &ht, const Settings &s, - MPI_Comm comm); + IO(const Settings &s, MPI_Comm comm); + ~IO(); + void write(int step, const HeatTransfer &ht, const Settings &s, + MPI_Comm comm); private: - std::string m_outputfilename; + std::string m_outputfilename; }; #endif /* IO_H_ */ diff --git a/examples/heatTransfer/IO_adios1.cpp b/examples/heatTransfer/IO_adios1.cpp index 806c654d09ed8e73b6ef0d656953b4fcc5fc48fa..8bc8753c264d3562eb792e7ba39184ed349e957b 100644 --- a/examples/heatTransfer/IO_adios1.cpp +++ b/examples/heatTransfer/IO_adios1.cpp @@ -20,24 +20,24 @@ static int rank_saved; IO::IO(const Settings &s, MPI_Comm comm) { - rank_saved = s.rank; - m_outputfilename = s.outputfile + ".bp"; - adios_init_noxml(comm); - adios_declare_group(&group, "heat", "", adios_stat_default); - adios_select_method(group, "MPI", "", ""); + rank_saved = s.rank; + m_outputfilename = s.outputfile + ".bp"; + adios_init_noxml(comm); + adios_declare_group(&group, "heat", "", adios_stat_default); + adios_select_method(group, "MPI", "", ""); - adios_define_var(group, "gndx", "", adios_integer, "", "", ""); - adios_define_var(group, "gndy", "", adios_integer, "", "", ""); + adios_define_var(group, "gndx", "", adios_integer, "", "", ""); + adios_define_var(group, "gndy", "", adios_integer, "", "", ""); - std::string ldims(std::to_string(s.ndx) + "," + std::to_string(s.ndy)); - std::string gdims(std::to_string(s.gndx) + "," + std::to_string(s.gndy)); - std::string offs(std::to_string(s.offsx) + "," + std::to_string(s.offsy)); - uint64_t T_id; - T_id = adios_define_var(group, "T", "", adios_double, ldims.c_str(), - gdims.c_str(), offs.c_str()); + std::string ldims(std::to_string(s.ndx) + "," + std::to_string(s.ndy)); + std::string gdims(std::to_string(s.gndx) + "," + std::to_string(s.gndy)); + std::string offs(std::to_string(s.offsx) + "," + std::to_string(s.offsy)); + uint64_t T_id; + T_id = adios_define_var(group, "T", "", adios_double, ldims.c_str(), + gdims.c_str(), offs.c_str()); - adios_set_transform(T_id, "none"); - // adios_set_transform( T_id, "zfp:accuracy=0.001"); + adios_set_transform(T_id, "none"); + // adios_set_transform( T_id, "zfp:accuracy=0.001"); } IO::~IO() { adios_finalize(rank_saved); } @@ -45,31 +45,31 @@ IO::~IO() { adios_finalize(rank_saved); } void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) { - char mode[2] = "w"; - if (step > 0) - { - mode[0] = 'a'; - } + char mode[2] = "w"; + if (step > 0) + { + mode[0] = 'a'; + } - // for time measurements, let's synchronize the processes - MPI_Barrier(comm); - double time_start = MPI_Wtime(); + // for time measurements, let's synchronize the processes + MPI_Barrier(comm); + double time_start = MPI_Wtime(); - int64_t f; - adios_open(&f, "heat", m_outputfilename.c_str(), mode, comm); - adios_write(f, "gndx", &s.gndx); - adios_write(f, "gndy", &s.gndy); - adios_write(f, "T", ht.data_noghost().data()); - adios_close(f); + int64_t f; + adios_open(&f, "heat", m_outputfilename.c_str(), mode, comm); + adios_write(f, "gndx", &s.gndx); + adios_write(f, "gndy", &s.gndy); + adios_write(f, "T", ht.data_noghost().data()); + adios_close(f); - MPI_Barrier(comm); - double total_time = MPI_Wtime() - time_start; - uint64_t adios_totalsize = - 2 * sizeof(int) + 2 * s.ndx * s.ndy * sizeof(double); - uint64_t sizeMB = - adios_totalsize * s.nproc / 1024 / 1024 / 1024; // size in MB - uint64_t mbs = sizeMB / total_time; - if (s.rank == 0) - std::cout << "Step " << step << ": " << m_outputfilename << " " << sizeMB - << " " << total_time << "" << mbs << std::endl; + MPI_Barrier(comm); + double total_time = MPI_Wtime() - time_start; + uint64_t adios_totalsize = + 2 * sizeof(int) + 2 * s.ndx * s.ndy * sizeof(double); + uint64_t sizeMB = + adios_totalsize * s.nproc / 1024 / 1024 / 1024; // size in MB + uint64_t mbs = sizeMB / total_time; + if (s.rank == 0) + std::cout << "Step " << step << ": " << m_outputfilename << " " + << sizeMB << " " << total_time << "" << mbs << std::endl; } diff --git a/examples/heatTransfer/IO_adios2.cpp b/examples/heatTransfer/IO_adios2.cpp index 49e9c58602b8dd5bcf05d4c2502746af42b14e54..ac0567820549d3300ca410c9686fe8552fb9578f 100644 --- a/examples/heatTransfer/IO_adios2.cpp +++ b/examples/heatTransfer/IO_adios2.cpp @@ -20,90 +20,95 @@ adios::Variable<double> *varT = nullptr; IO::IO(const Settings &s, MPI_Comm comm) { - rank_saved = s.rank; - m_outputfilename = s.outputfile + ".bp"; - ad = new adios::ADIOS("adios2.xml", comm, adios::Verbose::INFO); + rank_saved = s.rank; + m_outputfilename = s.outputfile + ".bp"; + ad = new adios::ADIOS("adios2.xml", comm, adios::Verbose::INFO); - // Define method for engine creation - // 1. Get method def from config file or define new one + // Define method for engine creation + // 1. Get method def from config file or define new one - adios::Method &bpWriterSettings = ad->DeclareMethod("output"); - if (!bpWriterSettings.isUserDefined()) - { - // if not defined by user, we can change the default settings - bpWriterSettings.SetEngine("BP"); // BP is the default engine - bpWriterSettings.AllowThreads( - 1); // allow 1 extra thread for data processing - bpWriterSettings.AddTransport( - "File", "lucky=yes"); // ISO-POSIX file is the default transport - // Passing parameters to the transport - bpWriterSettings.SetParameters("have_metadata_file", - "yes"); // Passing parameters to the engine - bpWriterSettings.SetParameters( - "Aggregation", - std::to_string((s.nproc + 1) / 2)); // number of aggregators - } + adios::Method &bpWriterSettings = ad->DeclareMethod("output"); + if (!bpWriterSettings.isUserDefined()) + { + // if not defined by user, we can change the default settings + bpWriterSettings.SetEngine("BP"); // BP is the default engine + bpWriterSettings.AllowThreads( + 1); // allow 1 extra thread for data processing + bpWriterSettings.AddTransport( + "File", "lucky=yes"); // ISO-POSIX file is the default transport + // Passing parameters to the transport + bpWriterSettings.SetParameters( + "have_metadata_file", + "yes"); // Passing parameters to the engine + bpWriterSettings.SetParameters( + "Aggregation", + std::to_string((s.nproc + 1) / 2)); // number of aggregators + } - // define T as 2D global array - varT = &ad->DefineVariable<double>( - "T", {s.gndx, s.gndy}, // Global dimensions - {s.ndx, s.ndy}, // local size, could be defined later using SetSelection() - {s.offsx, s.offsy} // offset of the local array in the global space - ); + // define T as 2D global array + varT = &ad->DefineVariable<double>( + "T", {s.gndx, s.gndy}, // Global dimensions + {s.ndx, + s.ndy}, // local size, could be defined later using SetSelection() + {s.offsx, s.offsy} // offset of the local array in the global space + ); - // add transform to variable - // adios::Transform tr = adios::transform::BZIP2( ); - // varT.AddTransform( tr, "" ); - // varT.AddTransform( tr,"accuracy=0.001" ); // for ZFP + // add transform to variable + // adios::Transform tr = adios::transform::BZIP2( ); + // varT.AddTransform( tr, "" ); + // varT.AddTransform( tr,"accuracy=0.001" ); // for ZFP - bpWriter = ad->Open(m_outputfilename, "w", comm, bpWriterSettings, - adios::IOMode::COLLECTIVE); + bpWriter = ad->Open(m_outputfilename, "w", comm, bpWriterSettings, + adios::IOMode::COLLECTIVE); - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: failed to open ADIOS bpWriter\n"); + if (bpWriter == nullptr) + throw std::ios_base::failure("ERROR: failed to open ADIOS bpWriter\n"); } IO::~IO() { - bpWriter->Close(); - delete ad; + bpWriter->Close(); + delete ad; } void /*IO::*/ old_style_write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) { - bpWriter->Write<double>(*varT, ht.data_noghost().data()); - bpWriter->Advance(); + bpWriter->Write<double>(*varT, ht.data_noghost().data()); + bpWriter->Advance(); } void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) { - /* This selection is redundant and not required, since we defined - * the selection already in DefineVariable(). It is here just as an example. - */ - // Make a selection to describe the local dimensions of the variable we write - // and - // its offsets in the global spaces. This could have been done in - // adios.DefineVariable() - adios::Selection sel = adios.SelectionBoundingBox( - {s.ndx, s.ndy}, - {s.offsx, s.offsy}); // local dims and offsets; both as list - var2D.SetSelection(sel); + /* This selection is redundant and not required, since we defined + * the selection already in DefineVariable(). It is here just as an example. + */ + // Make a selection to describe the local dimensions of the variable we + // write + // and + // its offsets in the global spaces. This could have been done in + // adios.DefineVariable() + adios::Selection sel = adios.SelectionBoundingBox( + {s.ndx, s.ndy}, + {s.offsx, s.offsy}); // local dims and offsets; both as list + var2D.SetSelection(sel); - /* Select the area that we want to write from the data pointer we pass to the - writer. - Think HDF5 memspace, just not hyperslabs, only a bounding box selection. - Engine will copy this bounding box from the data pointer into the output - buffer. - Size of the bounding box should match the "space" selection which was given - above. - Default memspace is always the full selection. - */ - adios::Selection memspace = - adios.SelectionBoundingBox({s.ndx, s.ndy}, {1, 1}); - var2D.SetMemorySelection(memspace); + /* Select the area that we want to write from the data pointer we pass to + the + writer. + Think HDF5 memspace, just not hyperslabs, only a bounding box selection. + Engine will copy this bounding box from the data pointer into the output + buffer. + Size of the bounding box should match the "space" selection which was + given + above. + Default memspace is always the full selection. + */ + adios::Selection memspace = + adios.SelectionBoundingBox({s.ndx, s.ndy}, {1, 1}); + var2D.SetMemorySelection(memspace); - bpWriter->Write<double>(*varT, ht.data()); - bpWriter->Advance(); + bpWriter->Write<double>(*varT, ht.data()); + bpWriter->Advance(); } diff --git a/examples/heatTransfer/IO_ascii.cpp b/examples/heatTransfer/IO_ascii.cpp index ccf158dabdf8b373fb47290165556f6bb40e8254..5f16aa05f9ed1ac75892d903ec7af0fe794e64db 100644 --- a/examples/heatTransfer/IO_ascii.cpp +++ b/examples/heatTransfer/IO_ascii.cpp @@ -19,60 +19,61 @@ static std::streambuf *buf; IO::IO(const Settings &s, MPI_Comm comm) { - m_outputfilename = s.outputfile; + m_outputfilename = s.outputfile; - if (m_outputfilename == "cout") - { - buf = std::cout.rdbuf(); - } - else - { - int rank; - MPI_Comm_rank(comm, &rank); - std::string rs = std::to_string(rank); - of.open(m_outputfilename + rs + ".txt"); - buf = of.rdbuf(); - } + if (m_outputfilename == "cout") + { + buf = std::cout.rdbuf(); + } + else + { + int rank; + MPI_Comm_rank(comm, &rank); + std::string rs = std::to_string(rank); + of.open(m_outputfilename + rs + ".txt"); + buf = of.rdbuf(); + } } IO::~IO() { - if (m_outputfilename != "cout") - { - of.close(); - } + if (m_outputfilename != "cout") + { + of.close(); + } } void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) { - std::ostream out(buf); - if (step == 0) - { - out << "rank=" << s.rank << " size=" << s.ndx << "x" << s.ndy - << " offsets=" << s.offsx << ":" << s.offsy << " step=" << step - << std::endl; - out << " time row columns " << s.offsy << "..." << s.offsy + s.ndy - 1 - << std::endl; - out << " "; - for (int j = 1; j <= s.ndy; ++j) + std::ostream out(buf); + if (step == 0) + { + out << "rank=" << s.rank << " size=" << s.ndx << "x" << s.ndy + << " offsets=" << s.offsx << ":" << s.offsy << " step=" << step + << std::endl; + out << " time row columns " << s.offsy << "..." + << s.offsy + s.ndy - 1 << std::endl; + out << " "; + for (int j = 1; j <= s.ndy; ++j) + { + out << std::setw(9) << s.offsy + j - 1; + } + out << "\n-------------------------------------------------------------" + "-\n"; + } + else { - out << std::setw(9) << s.offsy + j - 1; + out << std::endl; } - out << "\n--------------------------------------------------------------\n"; - } - else - { - out << std::endl; - } - for (int i = 1; i <= s.ndx; ++i) - { - out << std::setw(5) << step << std::setw(5) << s.offsx + i - 1; - for (int j = 1; j <= s.ndy; ++j) + for (int i = 1; i <= s.ndx; ++i) { - out << std::setw(9) << ht.T(i, j); + out << std::setw(5) << step << std::setw(5) << s.offsx + i - 1; + for (int j = 1; j <= s.ndy; ++j) + { + out << std::setw(9) << ht.T(i, j); + } + out << std::endl; } - out << std::endl; - } } diff --git a/examples/heatTransfer/IO_hdf5_a.cpp b/examples/heatTransfer/IO_hdf5_a.cpp index 881085f0c59a28aa4a8547fb3a67853d99c35f9a..c0514b803dff617f24d732f8dbcae60a50f6dd7c 100644 --- a/examples/heatTransfer/IO_hdf5_a.cpp +++ b/examples/heatTransfer/IO_hdf5_a.cpp @@ -26,37 +26,38 @@ IO::~IO() {} void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) { - std::string rs = std::to_string(s.rank); - std::string ts = std::to_string(step); - std::string fname = s.outputfile + "." + rs + "." + ts + ".h5"; - - // for time measurements, let's synchronize the processes - MPI_Barrier(comm); - double time_start = MPI_Wtime(); - - hsize_t dims[2] = {static_cast<hsize_t>(s.ndx), static_cast<hsize_t>(s.ndy)}; - - hid_t space = H5Screate_simple(2, dims, NULL); - hid_t file = - H5Fcreate(fname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - hid_t dset = H5Dcreate(file, "T", H5T_NATIVE_DOUBLE, space, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT); - - H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - ht.data_noghost().data()); - - H5Dclose(dset); - H5Sclose(space); - H5Fclose(file); - - MPI_Barrier(comm); - double total_time = MPI_Wtime() - time_start; - uint64_t adios_totalsize = - 2 * sizeof(int) + 2 * s.ndx * s.ndy * sizeof(double); - uint64_t sizeMB = - adios_totalsize * s.nproc / 1024 / 1024 / 1024; // size in MB - uint64_t mbs = sizeMB / total_time; - if (s.rank == 0) - std::cout << "Step " << step << ": " << m_outputfilename << " " << sizeMB - << " " << total_time << "" << mbs << std::endl; + std::string rs = std::to_string(s.rank); + std::string ts = std::to_string(step); + std::string fname = s.outputfile + "." + rs + "." + ts + ".h5"; + + // for time measurements, let's synchronize the processes + MPI_Barrier(comm); + double time_start = MPI_Wtime(); + + hsize_t dims[2] = {static_cast<hsize_t>(s.ndx), + static_cast<hsize_t>(s.ndy)}; + + hid_t space = H5Screate_simple(2, dims, NULL); + hid_t file = + H5Fcreate(fname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + hid_t dset = H5Dcreate(file, "T", H5T_NATIVE_DOUBLE, space, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + + H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + ht.data_noghost().data()); + + H5Dclose(dset); + H5Sclose(space); + H5Fclose(file); + + MPI_Barrier(comm); + double total_time = MPI_Wtime() - time_start; + uint64_t adios_totalsize = + 2 * sizeof(int) + 2 * s.ndx * s.ndy * sizeof(double); + uint64_t sizeMB = + adios_totalsize * s.nproc / 1024 / 1024 / 1024; // size in MB + uint64_t mbs = sizeMB / total_time; + if (s.rank == 0) + std::cout << "Step " << step << ": " << m_outputfilename << " " + << sizeMB << " " << total_time << "" << mbs << std::endl; } diff --git a/examples/heatTransfer/Settings.cpp b/examples/heatTransfer/Settings.cpp index f5e0459ed2f989dcc08cb3a0c466e476369af247..4337a00a33f7b3865bceb1feeb569537f1e6271c 100644 --- a/examples/heatTransfer/Settings.cpp +++ b/examples/heatTransfer/Settings.cpp @@ -15,70 +15,70 @@ static unsigned int convertToUint(std::string varName, char *arg) { - char *end; - int retval = std::strtoll(arg, &end, 10); - if (end[0] || errno == ERANGE) - { - throw std::invalid_argument("Invalid value given for " + varName + ": " + - std::string(arg)); - } - if (retval < 0) - { - throw std::invalid_argument("Negative value given for " + varName + ": " + - std::string(arg)); - } - return (unsigned int)retval; + char *end; + int retval = std::strtoll(arg, &end, 10); + if (end[0] || errno == ERANGE) + { + throw std::invalid_argument("Invalid value given for " + varName + + ": " + std::string(arg)); + } + if (retval < 0) + { + throw std::invalid_argument("Negative value given for " + varName + + ": " + std::string(arg)); + } + return (unsigned int)retval; } Settings::Settings(int argc, char *argv[], int rank, int nproc) : rank{rank} { - if (argc < 8) - { - throw std::invalid_argument("Not enough arguments"); - } - this->nproc = (unsigned int)nproc; + if (argc < 8) + { + throw std::invalid_argument("Not enough arguments"); + } + this->nproc = (unsigned int)nproc; - outputfile = argv[1]; - npx = convertToUint("N", argv[2]); - npy = convertToUint("M", argv[3]); - ndx = convertToUint("nx", argv[4]); - ndy = convertToUint("ny", argv[5]); - steps = convertToUint("steps", argv[6]); - iterations = convertToUint("iterations", argv[7]); + outputfile = argv[1]; + npx = convertToUint("N", argv[2]); + npy = convertToUint("M", argv[3]); + ndx = convertToUint("nx", argv[4]); + ndy = convertToUint("ny", argv[5]); + steps = convertToUint("steps", argv[6]); + iterations = convertToUint("iterations", argv[7]); - if (npx * npy != this->nproc) - { - throw std::invalid_argument("N*M must equal the number of processes"); - } + if (npx * npy != this->nproc) + { + throw std::invalid_argument("N*M must equal the number of processes"); + } - // calculate global array size and the local offsets in that global space - gndx = npx * ndx; - gndy = npy * ndy; - posx = rank % npx; - posy = rank / npx; - offsx = posx * ndx; - offsy = posy * ndy; + // calculate global array size and the local offsets in that global space + gndx = npx * ndx; + gndy = npy * ndy; + posx = rank % npx; + posy = rank / npx; + offsx = posx * ndx; + offsy = posy * ndy; - // determine neighbors - if (posx == 0) - rank_left = -1; - else - rank_left = rank - 1; + // determine neighbors + if (posx == 0) + rank_left = -1; + else + rank_left = rank - 1; - if (posx == npx - 1) - rank_right = -1; - else - rank_right = rank + 1; + if (posx == npx - 1) + rank_right = -1; + else + rank_right = rank + 1; - if (posy == 0) - rank_up = -1; - else - rank_up = rank - npx; + if (posy == 0) + rank_up = -1; + else + rank_up = rank - npx; - if (posy == npy - 1) - rank_down = -1; - else - rank_down = rank + npx; + if (posy == npy - 1) + rank_down = -1; + else + rank_down = rank + npx; } Settings::~Settings() {} diff --git a/examples/heatTransfer/Settings.h b/examples/heatTransfer/Settings.h index 85382656abff49205a77422ec5b880588ff74af6..97e85ea310adcd55a2ccc10ca8333346461b3949 100644 --- a/examples/heatTransfer/Settings.h +++ b/examples/heatTransfer/Settings.h @@ -17,37 +17,38 @@ class Settings { public: - // user arguments - std::string outputfile; - unsigned int npx; // Number of processes in X (slow) dimension - unsigned int npy; // Number of processes in Y (fast) dimension - unsigned int ndx; // Local array size in X dimension per process - unsigned int ndy; // Local array size in y dimension per process - unsigned int steps; // Number of output steps - unsigned int iterations; // Number of computing iterations between steps - - // calculated values from those arguments and number of processes - unsigned int gndx; // Global array size in slow dimension - unsigned int gndy; // Global array size in fast dimension - // X dim positions: rank 0, npx, 2npx... are in the same X position - // Y dim positions: npx number of consecutive processes belong to one row (npx - // columns) - unsigned int posx; // Position of this process in X dimension - unsigned int posy; // Position of this process in Y dimension - unsigned int offsx; // Offset of local array in X dimension on this process - unsigned int offsy; // Offset of local array in Y dimension on this process - - int rank; // MPI rank - unsigned int nproc; // number of processors - - // neighbors by their MPI ranks, -1 if there is no such neighbor - int rank_left; - int rank_right; - int rank_up; - int rank_down; - - Settings(int argc, char *argv[], int rank, int nproc); - ~Settings(); + // user arguments + std::string outputfile; + unsigned int npx; // Number of processes in X (slow) dimension + unsigned int npy; // Number of processes in Y (fast) dimension + unsigned int ndx; // Local array size in X dimension per process + unsigned int ndy; // Local array size in y dimension per process + unsigned int steps; // Number of output steps + unsigned int iterations; // Number of computing iterations between steps + + // calculated values from those arguments and number of processes + unsigned int gndx; // Global array size in slow dimension + unsigned int gndy; // Global array size in fast dimension + // X dim positions: rank 0, npx, 2npx... are in the same X position + // Y dim positions: npx number of consecutive processes belong to one row + // (npx + // columns) + unsigned int posx; // Position of this process in X dimension + unsigned int posy; // Position of this process in Y dimension + unsigned int offsx; // Offset of local array in X dimension on this process + unsigned int offsy; // Offset of local array in Y dimension on this process + + int rank; // MPI rank + unsigned int nproc; // number of processors + + // neighbors by their MPI ranks, -1 if there is no such neighbor + int rank_left; + int rank_right; + int rank_up; + int rank_down; + + Settings(int argc, char *argv[], int rank, int nproc); + ~Settings(); }; #endif /* SETTINGS_H_ */ diff --git a/examples/heatTransfer/main.cpp b/examples/heatTransfer/main.cpp index d15216eb8f775819f037eba802772949dd369bbb..1d1372f401ff641f3dc0da71a1b175b9b5c5b1fb 100644 --- a/examples/heatTransfer/main.cpp +++ b/examples/heatTransfer/main.cpp @@ -23,86 +23,87 @@ void printUsage() { - std::cout << "Usage: heatTransfer output N M nx ny steps iterations\n" - << " output: name of output file\n" - << " N: number of processes in X dimension\n" - << " M: number of processes in Y dimension\n" - << " nx: local array size in X dimension per processor\n" - << " ny: local array size in Y dimension per processor\n" - << " steps: the total number of steps to output\n" - << " iterations: one step consist of this many iterations\n\n"; + std::cout + << "Usage: heatTransfer output N M nx ny steps iterations\n" + << " output: name of output file\n" + << " N: number of processes in X dimension\n" + << " M: number of processes in Y dimension\n" + << " nx: local array size in X dimension per processor\n" + << " ny: local array size in Y dimension per processor\n" + << " steps: the total number of steps to output\n" + << " iterations: one step consist of this many iterations\n\n"; } int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - /* World comm spans all applications started with the same aprun command - on a Cray XK6. So we have to split and create the local - 'world' communicator for heat_transfer only. - In normal start-up, the communicator will just equal the MPI_COMM_WORLD. - */ + MPI_Init(&argc, &argv); + /* World comm spans all applications started with the same aprun command + on a Cray XK6. So we have to split and create the local + 'world' communicator for heat_transfer only. + In normal start-up, the communicator will just equal the MPI_COMM_WORLD. + */ - int wrank, wnproc; - MPI_Comm_rank(MPI_COMM_WORLD, &wrank); - MPI_Comm_size(MPI_COMM_WORLD, &wnproc); - MPI_Barrier(MPI_COMM_WORLD); + int wrank, wnproc; + MPI_Comm_rank(MPI_COMM_WORLD, &wrank); + MPI_Comm_size(MPI_COMM_WORLD, &wnproc); + MPI_Barrier(MPI_COMM_WORLD); - const unsigned int color = 1; - MPI_Comm mpiHeatTransferComm; - MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &mpiHeatTransferComm); + const unsigned int color = 1; + MPI_Comm mpiHeatTransferComm; + MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &mpiHeatTransferComm); - int rank, nproc; - MPI_Comm_rank(mpiHeatTransferComm, &rank); - MPI_Comm_size(mpiHeatTransferComm, &nproc); + int rank, nproc; + MPI_Comm_rank(mpiHeatTransferComm, &rank); + MPI_Comm_size(mpiHeatTransferComm, &nproc); - try - { - double timeStart = MPI_Wtime(); - Settings settings(argc, argv, rank, nproc); - HeatTransfer ht(settings); - IO io(settings, mpiHeatTransferComm); + try + { + double timeStart = MPI_Wtime(); + Settings settings(argc, argv, rank, nproc); + HeatTransfer ht(settings); + IO io(settings, mpiHeatTransferComm); + + ht.init(true); + ht.printT("Initialized T:", mpiHeatTransferComm); + ht.heatEdges(); + // ht.exchange( mpiHeatTransferComm ); + ht.printT("Heated T:", mpiHeatTransferComm); + io.write(0, ht, settings, mpiHeatTransferComm); - ht.init(true); - ht.printT("Initialized T:", mpiHeatTransferComm); - ht.heatEdges(); - // ht.exchange( mpiHeatTransferComm ); - ht.printT("Heated T:", mpiHeatTransferComm); - io.write(0, ht, settings, mpiHeatTransferComm); + for (unsigned int t = 1; t <= settings.steps; ++t) + { + if (rank == 0) + std::cout << "Step " << t << ":\n"; + for (unsigned int iter = 1; iter <= settings.iterations; ++iter) + { + ht.iterate(); + ht.exchange(mpiHeatTransferComm); + ht.heatEdges(); + } + io.write(t, ht, settings, mpiHeatTransferComm); + } + MPI_Barrier(mpiHeatTransferComm); - for (unsigned int t = 1; t <= settings.steps; ++t) + double timeEnd = MPI_Wtime(); + if (rank == 0) + std::cout << "Total runtime = " << timeEnd - timeStart << "s\n"; + } + catch (std::invalid_argument &e) // command-line argument errors { - if (rank == 0) - std::cout << "Step " << t << ":\n"; - for (unsigned int iter = 1; iter <= settings.iterations; ++iter) - { - ht.iterate(); - ht.exchange(mpiHeatTransferComm); - ht.heatEdges(); - } - io.write(t, ht, settings, mpiHeatTransferComm); + std::cout << e.what() << std::endl; + printUsage(); + } + catch (std::ios_base::failure &e) // I/O failure (e.g. file not found) + { + std::cout << "I/O base exception caught\n"; + std::cout << e.what() << std::endl; + } + catch (std::exception &e) // All other exceptions + { + std::cout << "Exception caught\n"; + std::cout << e.what() << std::endl; } - MPI_Barrier(mpiHeatTransferComm); - - double timeEnd = MPI_Wtime(); - if (rank == 0) - std::cout << "Total runtime = " << timeEnd - timeStart << "s\n"; - } - catch (std::invalid_argument &e) // command-line argument errors - { - std::cout << e.what() << std::endl; - printUsage(); - } - catch (std::ios_base::failure &e) // I/O failure (e.g. file not found) - { - std::cout << "I/O base exception caught\n"; - std::cout << e.what() << std::endl; - } - catch (std::exception &e) // All other exceptions - { - std::cout << "Exception caught\n"; - std::cout << e.what() << std::endl; - } - MPI_Finalize(); - return 0; + MPI_Finalize(); + return 0; } diff --git a/examples/hello/adios1Writer/helloADIOS1Writer.cpp b/examples/hello/adios1Writer/helloADIOS1Writer.cpp index 9543ec43b2530c7f64d1435092dee25e8b6719e0..2a7803ab6edac9adc2618699fb3be45c3960b6c7 100644 --- a/examples/hello/adios1Writer/helloADIOS1Writer.cpp +++ b/examples/hello/adios1Writer/helloADIOS1Writer.cpp @@ -17,104 +17,107 @@ int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank, nproc; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug); - - // Application variable - float frank = (float)rank; - std::vector<double> myDoubles = { - frank, frank + 0.1f, frank + 0.2f, frank + 0.3f, frank + 0.4f, - frank + 0.5f, frank + 0.6f, frank + 0.7f, frank + 0.8f, frank + 0.9f}; - const std::size_t Nx = myDoubles.size(); - - const std::size_t rows = 3; - const std::size_t columns = 3; - - std::vector<float> myMatrix; - myMatrix.reserve(rows * columns); - myMatrix.push_back(frank + 0.0); - myMatrix.push_back(frank + 0.1), myMatrix.push_back(frank + 0.2); - myMatrix.push_back(frank + 0.3); - myMatrix.push_back(frank + 0.4), myMatrix.push_back(frank + 0.5); - myMatrix.push_back(frank + 0.6); - myMatrix.push_back(frank + 0.7), myMatrix.push_back(frank + 0.8); - - frank = -(float)rank; - std::vector<float> myMatrix2 = {frank - 0.1f, frank - 0.2f, frank - 0.3f, - frank - 0.4f, frank - 0.5f, frank - 0.6f, - frank - 0.7f, frank - 0.8f, frank - 0.9f}; - - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = adios.DefineVariable<double>( - "myDoubles", {1, Nx}, {nproc, Nx}, {rank, 0}); - adios::Variable<float> &ioMyMatrix = adios.DefineVariable<float>( - "myMatrix", {rows, columns}, {nproc * rows, columns}, {rank * rows, 0}); - adios::Variable<float> &ioMyMatrix2 = adios.DefineVariable<float>( - "myMatrix2", {rows, columns}, {rows, nproc * columns}, - {0, rank * columns}); - - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SingleFile"); // default method type is BPWriter - bpWriterSettings.SetEngine("ADIOS1Writer"); - bpWriterSettings.SetParameters("profile_units=mus"); - bpWriterSettings.AddTransport( - "File", "profile_units=mus", - "have_metadata_file=no"); // uses default POSIX library - - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings, - adios::IOMode::COLLECTIVE); - - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); - - bpWriter->Write<double>(ioMyDoubles, myDoubles.data()); // Base class Engine - // own the Write<T> - // that will call - // overloaded Write - // from Derived - - bpWriter->Write<float>(ioMyMatrix, myMatrix.data()); - bpWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); - - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + MPI_Init(&argc, &argv); + int rank, nproc; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug); + + // Application variable + float frank = (float)rank; + std::vector<double> myDoubles = { + frank, frank + 0.1f, frank + 0.2f, frank + 0.3f, frank + 0.4f, + frank + 0.5f, frank + 0.6f, frank + 0.7f, frank + 0.8f, frank + 0.9f}; + const std::size_t Nx = myDoubles.size(); + + const std::size_t rows = 3; + const std::size_t columns = 3; + + std::vector<float> myMatrix; + myMatrix.reserve(rows * columns); + myMatrix.push_back(frank + 0.0); + myMatrix.push_back(frank + 0.1), myMatrix.push_back(frank + 0.2); + myMatrix.push_back(frank + 0.3); + myMatrix.push_back(frank + 0.4), myMatrix.push_back(frank + 0.5); + myMatrix.push_back(frank + 0.6); + myMatrix.push_back(frank + 0.7), myMatrix.push_back(frank + 0.8); + + frank = -(float)rank; + std::vector<float> myMatrix2 = {frank - 0.1f, frank - 0.2f, frank - 0.3f, + frank - 0.4f, frank - 0.5f, frank - 0.6f, + frank - 0.7f, frank - 0.8f, frank - 0.9f}; + + try { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + // Define variable and local size + adios::Variable<double> &ioMyDoubles = adios.DefineVariable<double>( + "myDoubles", {1, Nx}, {nproc, Nx}, {rank, 0}); + adios::Variable<float> &ioMyMatrix = adios.DefineVariable<float>( + "myMatrix", {rows, columns}, {nproc * rows, columns}, + {rank * rows, 0}); + adios::Variable<float> &ioMyMatrix2 = adios.DefineVariable<float>( + "myMatrix2", {rows, columns}, {rows, nproc * columns}, + {0, rank * columns}); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter + bpWriterSettings.SetEngine("ADIOS1Writer"); + bpWriterSettings.SetParameters("profile_units=mus"); + bpWriterSettings.AddTransport( + "File", "profile_units=mus", + "have_metadata_file=no"); // uses default POSIX library + + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings, + adios::IOMode::COLLECTIVE); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); + + bpWriter->Write<double>(ioMyDoubles, + myDoubles.data()); // Base class Engine + // own the Write<T> + // that will call + // overloaded Write + // from Derived + + bpWriter->Write<float>(ioMyMatrix, myMatrix.data()); + bpWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); + + bpWriter->Close(); } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + } + catch (std::exception &e) + { + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/adios1Writer/helloADIOS1Writer_nompi.cpp b/examples/hello/adios1Writer/helloADIOS1Writer_nompi.cpp index eb282251d2de28fbf726628c99dddfcc6bc62eb2..44d4d5547050e79ef4a3cb3b0222b4d21433438f 100644 --- a/examples/hello/adios1Writer/helloADIOS1Writer_nompi.cpp +++ b/examples/hello/adios1Writer/helloADIOS1Writer_nompi.cpp @@ -15,73 +15,76 @@ int main(int argc, char *argv[]) { - const bool adiosDebug = true; - adios::ADIOS adios(adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adiosDebug); - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); - const std::size_t rows = 3; - const std::size_t columns = 3; - std::vector<float> myMatrix = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t rows = 3; + const std::size_t columns = 3; + std::vector<float> myMatrix = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; + std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); - adios::Variable<float> &ioMyMatrix = - adios.DefineVariable<float>("myMatrix", adios::Dims{rows, columns}); - adios::Variable<float> &ioMyMatrix2 = - adios.DefineVariable<float>("myMatrix2", adios::Dims{rows, columns}); - adios::Variable<float> &ioMyMatrix3 = - adios.DefineVariable<float>("myMatrix3", adios::Dims{rows, columns}); + try + { + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); + adios::Variable<float> &ioMyMatrix = + adios.DefineVariable<float>("myMatrix", adios::Dims{rows, columns}); + adios::Variable<float> &ioMyMatrix2 = adios.DefineVariable<float>( + "myMatrix2", adios::Dims{rows, columns}); + adios::Variable<float> &ioMyMatrix3 = adios.DefineVariable<float>( + "myMatrix3", adios::Dims{rows, columns}); - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SinglePOSIXFile"); // default method type is Writer - bpWriterSettings.SetParameters("profile_units=mus"); - bpWriterSettings.AddTransport("File", "have_metadata_file=yes", - "profile_units=mus"); + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SinglePOSIXFile"); // default method type is Writer + bpWriterSettings.SetParameters("profile_units=mus"); + bpWriterSettings.AddTransport("File", "have_metadata_file=yes", + "profile_units=mus"); - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpFileWriter = adios.Open("myDoubles_nompi.bp", "w", bpWriterSettings, - adios::IOMode::COLLECTIVE); + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpFileWriter = + adios.Open("myDoubles_nompi.bp", "w", bpWriterSettings, + adios::IOMode::COLLECTIVE); - if (bpFileWriter == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); + if (bpFileWriter == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); - bpFileWriter->Write<double>( - ioMyDoubles, myDoubles.data()); // Base class Engine own the Write<T> - // that will call overloaded Write from - // Derived - bpFileWriter->Write<float>(ioMyMatrix, myMatrix.data()); // 2d Example - bpFileWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); // 2d Example - bpFileWriter->Write<float>(ioMyMatrix3, myMatrix2.data()); // 2d Example - bpFileWriter->Close(); - // - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } + bpFileWriter->Write<double>( + ioMyDoubles, + myDoubles.data()); // Base class Engine own the Write<T> + // that will call overloaded Write from + // Derived + bpFileWriter->Write<float>(ioMyMatrix, myMatrix.data()); // 2d Example + bpFileWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); // 2d Example + bpFileWriter->Write<float>(ioMyMatrix3, myMatrix2.data()); // 2d Example + bpFileWriter->Close(); + // + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } - return 0; + return 0; } diff --git a/examples/hello/bpReader/helloBPReader.cpp b/examples/hello/bpReader/helloBPReader.cpp index 5558ee04a5ff9e00ccc772986689c0a348a3d295..934439584aad6c69509e2191e4a5d1ee3e38e0d0 100644 --- a/examples/hello/bpReader/helloBPReader.cpp +++ b/examples/hello/bpReader/helloBPReader.cpp @@ -17,54 +17,55 @@ int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - try - { - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpReaderSettings = - adios.DeclareMethod("SingleFile"); // default method type is BPWriter - bpReaderSettings.AddTransport("File"); // uses default POSIX library + try + { + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpReaderSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter + bpReaderSettings.AddTransport("File"); // uses default POSIX library - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpReader = adios.Open("myDoubles_nompi.bp", "r", bpReaderSettings); + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpReader = adios.Open("myDoubles_nompi.bp", "r", bpReaderSettings); - if (bpReader == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpReader at Open\n"); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + if (bpReader == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpReader at Open\n"); + } + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/bpReader/helloBPReader_nompi.cpp b/examples/hello/bpReader/helloBPReader_nompi.cpp index d5a604fbddb59f33f8f8a38ad09a825ec940d737..79de6af15eb5b0c6892d57a8a2c4b5a92d6f7009 100644 --- a/examples/hello/bpReader/helloBPReader_nompi.cpp +++ b/examples/hello/bpReader/helloBPReader_nompi.cpp @@ -15,40 +15,41 @@ int main(int argc, char *argv[]) { - const bool adiosDebug = true; - adios::ADIOS adios(adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adiosDebug); - try - { - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpReaderSettings = adios.DeclareMethod( - "SingleFile"); // default method type is BPWriter/BPReader - bpReaderSettings.AddTransport("File"); // uses default POSIX library + try + { + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpReaderSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter/BPReader + bpReaderSettings.AddTransport("File"); // uses default POSIX library - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpReader = adios.Open("myDoubles.bp", "r", bpReaderSettings); + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpReader = adios.Open("myDoubles.bp", "r", bpReaderSettings); - if (bpReader == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpReader at Open\n"); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } + if (bpReader == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpReader at Open\n"); + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } - return 0; + return 0; } diff --git a/examples/hello/bpWriter/helloBPWriter.cpp b/examples/hello/bpWriter/helloBPWriter.cpp index abc680ffdcfb93be169f51dc41570122713c2458..29d46647d65a0673ff523d234a56a415df115aaf 100644 --- a/examples/hello/bpWriter/helloBPWriter.cpp +++ b/examples/hello/bpWriter/helloBPWriter.cpp @@ -17,101 +17,103 @@ int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug); - - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); - - const std::size_t rows = 3; - const std::size_t columns = 3; - - std::vector<float> myMatrix; - if (rank % 2 == 0) // even rank - { - myMatrix.reserve(rows * columns); - myMatrix.push_back(1); - myMatrix.push_back(2), myMatrix.push_back(3); - myMatrix.push_back(4); - myMatrix.push_back(5), myMatrix.push_back(6); - myMatrix.push_back(7); - myMatrix.push_back(8), myMatrix.push_back(8); - } - - std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; - - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", {Nx}); - adios::Variable<float> &ioMyMatrix = - adios.DefineVariable<float>("myMatrix", {rows, columns}); - adios::Variable<float> &ioMyMatrix2 = - adios.DefineVariable<float>("myMatrix2", {rows, columns}); - - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SingleFile"); // default method type is BPWriter - bpWriterSettings.SetParameters("profile_units=mus"); - bpWriterSettings.AddTransport( - "File", "profile_units=mus", - "have_metadata_file=no"); // uses default POSIX library - - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings, - adios::IOMode::COLLECTIVE); - - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); - - bpWriter->Write<double>(ioMyDoubles, myDoubles.data()); // Base class Engine - // own the Write<T> - // that will call - // overloaded Write - // from Derived + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug); + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); + + const std::size_t rows = 3; + const std::size_t columns = 3; + + std::vector<float> myMatrix; if (rank % 2 == 0) // even rank { - bpWriter->Write<float>(ioMyMatrix, myMatrix.data()); - bpWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); + myMatrix.reserve(rows * columns); + myMatrix.push_back(1); + myMatrix.push_back(2), myMatrix.push_back(3); + myMatrix.push_back(4); + myMatrix.push_back(5), myMatrix.push_back(6); + myMatrix.push_back(7); + myMatrix.push_back(8), myMatrix.push_back(8); } - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; + + try + { + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", {Nx}); + adios::Variable<float> &ioMyMatrix = + adios.DefineVariable<float>("myMatrix", {rows, columns}); + adios::Variable<float> &ioMyMatrix2 = + adios.DefineVariable<float>("myMatrix2", {rows, columns}); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter + bpWriterSettings.SetParameters("profile_units=mus"); + bpWriterSettings.AddTransport( + "File", "profile_units=mus", + "have_metadata_file=no"); // uses default POSIX library + + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings, + adios::IOMode::COLLECTIVE); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); + + bpWriter->Write<double>(ioMyDoubles, + myDoubles.data()); // Base class Engine + // own the Write<T> + // that will call + // overloaded Write + // from Derived + + if (rank % 2 == 0) // even rank + { + bpWriter->Write<float>(ioMyMatrix, myMatrix.data()); + bpWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); + } + + bpWriter->Close(); + } + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/bpWriter/helloBPWriter_nompi.cpp b/examples/hello/bpWriter/helloBPWriter_nompi.cpp index 3936d3eab4aa6f06db4188809cc7a32e0a6d6263..7c8b7ee24119d01ea4cc32ce4b72af09b789603b 100644 --- a/examples/hello/bpWriter/helloBPWriter_nompi.cpp +++ b/examples/hello/bpWriter/helloBPWriter_nompi.cpp @@ -17,75 +17,78 @@ int main(int /*argc*/, char ** /*argv*/) { - const bool adiosDebug = true; - adios::ADIOS adios(adios::Verbose::WARN, adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adios::Verbose::WARN, adiosDebug); - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); - const std::size_t rows = 3; - const std::size_t columns = 3; - std::vector<float> myMatrix = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t rows = 3; + const std::size_t columns = 3; + std::vector<float> myMatrix = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; + std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); - adios::Variable<float> &ioMyMatrix = - adios.DefineVariable<float>("myMatrix", adios::Dims{rows, columns}); - adios::Variable<float> &ioMyMatrix2 = - adios.DefineVariable<float>("myMatrix2", adios::Dims{rows, columns}); - adios::Variable<float> &ioMyMatrix3 = - adios.DefineVariable<float>("myMatrix3", adios::Dims{rows, columns}); + try + { + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); + adios::Variable<float> &ioMyMatrix = + adios.DefineVariable<float>("myMatrix", adios::Dims{rows, columns}); + adios::Variable<float> &ioMyMatrix2 = adios.DefineVariable<float>( + "myMatrix2", adios::Dims{rows, columns}); + adios::Variable<float> &ioMyMatrix3 = adios.DefineVariable<float>( + "myMatrix3", adios::Dims{rows, columns}); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SinglePOSIXFile"); // default method type is Writer + bpWriterSettings.SetParameters("profile_units=mus"); + bpWriterSettings.AddTransport("File", "have_metadata_file=yes", + "profile_units=mus"); - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SinglePOSIXFile"); // default method type is Writer - bpWriterSettings.SetParameters("profile_units=mus"); - bpWriterSettings.AddTransport("File", "have_metadata_file=yes", - "profile_units=mus"); + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpFileWriter = + adios.Open("myDoubles_nompi.bp", "w", bpWriterSettings, + adios::IOMode::COLLECTIVE); - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpFileWriter = adios.Open("myDoubles_nompi.bp", "w", bpWriterSettings, - adios::IOMode::COLLECTIVE); + if (bpFileWriter == nullptr) + { + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); + } - if (bpFileWriter == nullptr) + bpFileWriter->Write<double>( + ioMyDoubles, + myDoubles.data()); // Base class Engine own the Write<T> + // that will call overloaded Write from + // Derived + bpFileWriter->Write<float>(ioMyMatrix, myMatrix.data()); // 2d Example + bpFileWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); // 2d Example + bpFileWriter->Write<float>(ioMyMatrix3, myMatrix2.data()); // 2d Example + bpFileWriter->Close(); + // + } + catch (std::invalid_argument &e) { - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; } - bpFileWriter->Write<double>( - ioMyDoubles, myDoubles.data()); // Base class Engine own the Write<T> - // that will call overloaded Write from - // Derived - bpFileWriter->Write<float>(ioMyMatrix, myMatrix.data()); // 2d Example - bpFileWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); // 2d Example - bpFileWriter->Write<float>(ioMyMatrix3, myMatrix2.data()); // 2d Example - bpFileWriter->Close(); - // - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - - return 0; + return 0; } diff --git a/examples/hello/compound/helloCompound.cpp b/examples/hello/compound/helloCompound.cpp index fac04ed5936bf0d7fe4c7865435df32f2a84c96f..32ccddd7f70ffd8f0b992f36dda2839118d07c55 100644 --- a/examples/hello/compound/helloCompound.cpp +++ b/examples/hello/compound/helloCompound.cpp @@ -18,94 +18,98 @@ struct Particle { - char Type[10]; ///< alpha, beta, gamma, etc. - double Position[3]; ///< x, y, z - double Velocity[3]; ///< Vx, Vy, Vz + char Type[10]; ///< alpha, beta, gamma, etc. + double Position[3]; ///< x, y, z + double Velocity[3]; ///< Vx, Vy, Vz }; int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); - - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); - - Particle myParticle; - sprintf(myParticle.Type, "%s", "photon"); - myParticle.Position[0] = 0; - myParticle.Position[1] = 1; - myParticle.Position[2] = 2; - - myParticle.Velocity[0] = 10; - myParticle.Velocity[1] = 11; - myParticle.Velocity[2] = 12; - - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); - - adios::VariableCompound &ioMyParticle = - adios.DefineVariableCompound<Particle>("myParticle", adios::Dims{1}); - ioMyParticle.InsertMember<std::string>("Type", offsetof(Particle, Type)); - ioMyParticle.InsertMember<std::vector<double>>( - "Position", offsetof(Particle, Position)); - ioMyParticle.InsertMember<std::vector<double>>( - "Velocity", offsetof(Particle, Velocity)); - - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SingleFile"); // default method type is BPWriter - bpWriterSettings.AddTransport( - "File", "have_metadata_file=yes"); // uses default POSIX library - - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings); - - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); - - bpWriter->Write(ioMyDoubles, myDoubles.data()); // Base class Engine own the - // Write<T> that will call - // overloaded Write from - // Derived - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adiosDebug); + + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); + + Particle myParticle; + sprintf(myParticle.Type, "%s", "photon"); + myParticle.Position[0] = 0; + myParticle.Position[1] = 1; + myParticle.Position[2] = 2; + + myParticle.Velocity[0] = 10; + myParticle.Velocity[1] = 11; + myParticle.Velocity[2] = 12; + + try { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); + + adios::VariableCompound &ioMyParticle = + adios.DefineVariableCompound<Particle>("myParticle", + adios::Dims{1}); + ioMyParticle.InsertMember<std::string>("Type", + offsetof(Particle, Type)); + ioMyParticle.InsertMember<std::vector<double>>( + "Position", offsetof(Particle, Position)); + ioMyParticle.InsertMember<std::vector<double>>( + "Velocity", offsetof(Particle, Velocity)); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter + bpWriterSettings.AddTransport( + "File", "have_metadata_file=yes"); // uses default POSIX library + + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); + + bpWriter->Write(ioMyDoubles, + myDoubles.data()); // Base class Engine own the + // Write<T> that will call + // overloaded Write from + // Derived + bpWriter->Close(); } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::invalid_argument &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + } + catch (std::exception &e) + { + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/compound/helloCompound_nompi.cpp b/examples/hello/compound/helloCompound_nompi.cpp index 08b7debffa9c5f46ed2d2e129bde24f0b8e75778..52d4075ccde051180437ba06a1f7b66b9121c293 100644 --- a/examples/hello/compound/helloCompound_nompi.cpp +++ b/examples/hello/compound/helloCompound_nompi.cpp @@ -17,78 +17,82 @@ struct Particle { - char Type[10]; ///< alpha, beta, gamma, etc. - double Position[3]; ///< x, y, z - double Velocity[3]; ///< Vx, Vy, Vz + char Type[10]; ///< alpha, beta, gamma, etc. + double Position[3]; ///< x, y, z + double Velocity[3]; ///< Vx, Vy, Vz }; int main(int argc, char *argv[]) { - const bool adiosDebug = true; - adios::ADIOS adios(adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adiosDebug); - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); - Particle myParticle; - sprintf(myParticle.Type, "%s", "photon"); - myParticle.Position[0] = 0; - myParticle.Position[1] = 1; - myParticle.Position[2] = 2; + Particle myParticle; + sprintf(myParticle.Type, "%s", "photon"); + myParticle.Position[0] = 0; + myParticle.Position[1] = 1; + myParticle.Position[2] = 2; - myParticle.Velocity[0] = 10; - myParticle.Velocity[1] = 11; - myParticle.Velocity[2] = 12; + myParticle.Velocity[0] = 10; + myParticle.Velocity[1] = 11; + myParticle.Velocity[2] = 12; - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); + try + { + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", adios::Dims{Nx}); - adios::VariableCompound &ioMyParticle = - adios.DefineVariableCompound<Particle>("myParticle"); - ioMyParticle.InsertMember<char>("Type", offsetof(Particle, Type)); - ioMyParticle.InsertMember<double>("Position", offsetof(Particle, Position)); - ioMyParticle.InsertMember<double>("Velocity", offsetof(Particle, Velocity)); + adios::VariableCompound &ioMyParticle = + adios.DefineVariableCompound<Particle>("myParticle"); + ioMyParticle.InsertMember<char>("Type", offsetof(Particle, Type)); + ioMyParticle.InsertMember<double>("Position", + offsetof(Particle, Position)); + ioMyParticle.InsertMember<double>("Velocity", + offsetof(Particle, Velocity)); - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SingleFile"); // default method type is BPWriter - bpWriterSettings.AddTransport( - "File", "have_metadata_file=yes"); // uses default POSIX library + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter + bpWriterSettings.AddTransport( + "File", "have_metadata_file=yes"); // uses default POSIX library - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings); + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpWriter = adios.Open("myDoubles.bp", "w", bpWriterSettings); - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); - bpWriter->Write(ioMyDoubles, myDoubles.data()); // Base class Engine own the - // Write<T> that will call - // overloaded Write from - // Derived - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } + bpWriter->Write(ioMyDoubles, + myDoubles.data()); // Base class Engine own the + // Write<T> that will call + // overloaded Write from + // Derived + bpWriter->Close(); + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } - return 0; + return 0; } diff --git a/examples/hello/datamanReader/helloDataManReader.cpp b/examples/hello/datamanReader/helloDataManReader.cpp index ec1713e73fa3368f0048caeba5abdb59b0efb37d..6c1c87897cd7f8bfef280a045586d5c94131d195 100644 --- a/examples/hello/datamanReader/helloDataManReader.cpp +++ b/examples/hello/datamanReader/helloDataManReader.cpp @@ -21,88 +21,91 @@ void getcb(const void *data, std::string doid, std::string var, std::string dtype, std::vector<std::size_t> varshape) { - std::cout << "data object ID = " << doid << "\n"; // do you need to flush? - std::cout << "variable name = " << var << "\n"; - std::cout << "data type = " << dtype << "\n"; + std::cout << "data object ID = " << doid << "\n"; // do you need to flush? + std::cout << "variable name = " << var << "\n"; + std::cout << "data type = " << dtype << "\n"; - std::size_t varsize = std::accumulate(varshape.begin(), varshape.end(), 1, - std::multiplies<std::size_t>()); + std::size_t varsize = std::accumulate(varshape.begin(), varshape.end(), 1, + std::multiplies<std::size_t>()); - for (unsigned int i = 0; i < varsize; ++i) - std::cout << ((float *)data)[i] << " "; - std::cout << std::endl; + for (unsigned int i = 0; i < varsize; ++i) + std::cout << ((float *)data)[i] << " "; + std::cout << std::endl; } int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN, adiosDebug); + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN, adiosDebug); - try - { - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &datamanSettings = adios.DeclareMethod("WAN"); - if (!datamanSettings.isUserDefined()) + try { - // if not defined by user, we can change the default settings - datamanSettings.SetEngine("DataManReader"); - datamanSettings.SetParameters("peer-to-peer=yes"); - datamanSettings.AddTransport("Mdtm", "localIP=128.0.0.0.1", - "remoteIP=128.0.0.0.2", "tolerances=1,2,3"); - // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", - // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported , - // will throw an exception - } + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &datamanSettings = adios.DeclareMethod("WAN"); + if (!datamanSettings.isUserDefined()) + { + // if not defined by user, we can change the default settings + datamanSettings.SetEngine("DataManReader"); + datamanSettings.SetParameters("peer-to-peer=yes"); + datamanSettings.AddTransport("Mdtm", "localIP=128.0.0.0.1", + "remoteIP=128.0.0.0.2", + "tolerances=1,2,3"); + // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", + // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported + // , + // will throw an exception + } - // Create engine smart pointer to DataManReader Engine due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // DataManReader - auto datamanReader = adios.Open("myDoubles.bp", "r", datamanSettings, - adios::IOMode::INDEPENDENT); + // Create engine smart pointer to DataManReader Engine due to + // polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // DataManReader + auto datamanReader = adios.Open("myDoubles.bp", "r", datamanSettings, + adios::IOMode::INDEPENDENT); - if (datamanReader == nullptr) - throw std::ios_base::failure( - "ERROR: failed to create DataMan I/O engine at Open\n"); + if (datamanReader == nullptr) + throw std::ios_base::failure( + "ERROR: failed to create DataMan I/O engine at Open\n"); - datamanReader->SetCallBack(getcb); + datamanReader->SetCallBack(getcb); - adios::Variable<double> *ioMyDoubles = - datamanReader->InquireVariableDouble("ioMyDoubles"); - if (ioMyDoubles == nullptr) - std::cout << "Variable ioMyDoubles not read...yet\n"; + adios::Variable<double> *ioMyDoubles = + datamanReader->InquireVariableDouble("ioMyDoubles"); + if (ioMyDoubles == nullptr) + std::cout << "Variable ioMyDoubles not read...yet\n"; - datamanReader->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + datamanReader->Close(); + } + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/datamanReader/helloDataManReader_nompi.cpp b/examples/hello/datamanReader/helloDataManReader_nompi.cpp index 28973cbc19a94c8dc6b5b9cd111b85a19c0b30fa..db7a717be43dbfe7809d1dbcc21f3645c03eda5d 100644 --- a/examples/hello/datamanReader/helloDataManReader_nompi.cpp +++ b/examples/hello/datamanReader/helloDataManReader_nompi.cpp @@ -17,81 +17,83 @@ void getcb(const void *data, std::string doid, std::string var, std::string dtype, std::vector<std::size_t> varshape) { - std::cout << "data object ID = " << doid << "\n"; // do you need to flush? - std::cout << "variable name = " << var << "\n"; - std::cout << "data type = " << dtype << "\n"; + std::cout << "data object ID = " << doid << "\n"; // do you need to flush? + std::cout << "variable name = " << var << "\n"; + std::cout << "data type = " << dtype << "\n"; - std::size_t varsize = std::accumulate(varshape.begin(), varshape.end(), 1, - std::multiplies<std::size_t>()); + std::size_t varsize = std::accumulate(varshape.begin(), varshape.end(), 1, + std::multiplies<std::size_t>()); - for (unsigned int i = 0; i < varsize; ++i) - std::cout << ((float *)data)[i] << " "; - std::cout << std::endl; + for (unsigned int i = 0; i < varsize; ++i) + std::cout << ((float *)data)[i] << " "; + std::cout << std::endl; } int main(int argc, char *argv[]) { - const bool adiosDebug = true; - adios::ADIOS adios(adios::Verbose::WARN, adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adios::Verbose::WARN, adiosDebug); - try - { - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &datamanSettings = adios.DeclareMethod("WAN"); - if (!datamanSettings.isUserDefined()) + try { - // if not defined by user, we can change the default settings - datamanSettings.SetEngine("DataManReader"); - datamanSettings.SetParameters("real_time=yes", "method_type=stream", - "method=zmq", "local_ip=127.0.0.1", - "remote_ip=127.0.0.1", "local_port=12307", - "remote_port=12306"); - // datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", - // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", - // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported , - // will throw an exception - } + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &datamanSettings = adios.DeclareMethod("WAN"); + if (!datamanSettings.isUserDefined()) + { + // if not defined by user, we can change the default settings + datamanSettings.SetEngine("DataManReader"); + datamanSettings.SetParameters( + "real_time=yes", "method_type=stream", "method=zmq", + "local_ip=127.0.0.1", "remote_ip=127.0.0.1", "local_port=12307", + "remote_port=12306"); + // datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", + // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported + // , + // will throw an exception + } - // Create engine smart pointer to DataManReader Engine due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // DataManReader - auto datamanReader = adios.Open("myDoubles.bp", "r", datamanSettings, - adios::IOMode::INDEPENDENT); + // Create engine smart pointer to DataManReader Engine due to + // polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // DataManReader + auto datamanReader = adios.Open("myDoubles.bp", "r", datamanSettings, + adios::IOMode::INDEPENDENT); - if (datamanReader == nullptr) - throw std::ios_base::failure( - "ERROR: failed to create DataMan I/O engine at Open\n"); + if (datamanReader == nullptr) + throw std::ios_base::failure( + "ERROR: failed to create DataMan I/O engine at Open\n"); - datamanReader->SetCallBack(getcb); + datamanReader->SetCallBack(getcb); - while (1) - { - } + while (1) + { + } - adios::Variable<double> *ioMyDoubles = - datamanReader->InquireVariableDouble("ioMyDoubles"); - if (ioMyDoubles == nullptr) - std::cout << "Variable ioMyDoubles not read...yet\n"; + adios::Variable<double> *ioMyDoubles = + datamanReader->InquireVariableDouble("ioMyDoubles"); + if (ioMyDoubles == nullptr) + std::cout << "Variable ioMyDoubles not read...yet\n"; - datamanReader->Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } + datamanReader->Close(); + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } - return 0; + return 0; } diff --git a/examples/hello/datamanWriter/helloDataManWriter.cpp b/examples/hello/datamanWriter/helloDataManWriter.cpp index 138abbcec405bed0ac6847667438387bf22b1ca1..b2276254e98cb3075c77518a786b9f05b1840129 100644 --- a/examples/hello/datamanWriter/helloDataManWriter.cpp +++ b/examples/hello/datamanWriter/helloDataManWriter.cpp @@ -17,99 +17,103 @@ int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN, adiosDebug); + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN, adiosDebug); - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); - std::vector<std::complex<float>> myCFloats; - myCFloats.reserve(3); - myCFloats.emplace_back(1, 3); - myCFloats.emplace_back(2, 2); - myCFloats.emplace_back(3, 1); + std::vector<std::complex<float>> myCFloats; + myCFloats.reserve(3); + myCFloats.emplace_back(1, 3); + myCFloats.emplace_back(2, 2); + myCFloats.emplace_back(3, 1); - try - { - // Define variable and local size - auto ioMyDoubles = adios.DefineVariable<double>("myDoubles", {Nx}); - auto ioMyCFloats = - adios.DefineVariable<std::complex<float>>("myCFloats", {3}); - - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &datamanSettings = adios.DeclareMethod("WAN"); - if (!datamanSettings.isUserDefined()) + try { - // if not defined by user, we can change the default settings - datamanSettings.SetEngine("DatamanWriter"); - datamanSettings.SetParameters("peer-to-peer=yes", "real_time=yes", - "compress=no"); - datamanSettings.AddTransport("Mdtm", "localIP=128.0.0.0.1", - "remoteIP=128.0.0.0.2", "tolerances=1,2,3"); - // datamanSettings.AddTransport( "file", "name=myfile.bp", - // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - // datamanSettings.AddTransport( "file", "name=myfile.bp", - // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - // datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", - // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1", - // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", - // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported, will - // throw an exception - } + // Define variable and local size + auto ioMyDoubles = adios.DefineVariable<double>("myDoubles", {Nx}); + auto ioMyCFloats = + adios.DefineVariable<std::complex<float>>("myCFloats", {3}); - // Create engine smart pointer to DataMan Engine due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // DataMan + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &datamanSettings = adios.DeclareMethod("WAN"); + if (!datamanSettings.isUserDefined()) + { + // if not defined by user, we can change the default settings + datamanSettings.SetEngine("DatamanWriter"); + datamanSettings.SetParameters("peer-to-peer=yes", "real_time=yes", + "compress=no"); + datamanSettings.AddTransport("Mdtm", "localIP=128.0.0.0.1", + "remoteIP=128.0.0.0.2", + "tolerances=1,2,3"); + // datamanSettings.AddTransport( "file", "name=myfile.bp", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + // datamanSettings.AddTransport( "file", "name=myfile.bp", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + // datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", + // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet + // supported, will + // throw an exception + } - // adios::DataManWriter datamanWriter; + // Create engine smart pointer to DataMan Engine due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // DataMan - auto datamanWriter = adios.Open("myDoubles.bp", "w", datamanSettings, - adios::IOMode::INDEPENDENT); + // adios::DataManWriter datamanWriter; - if (datamanWriter == nullptr) - throw std::ios_base::failure( - "ERROR: failed to create DataMan I/O engine at Open\n"); + auto datamanWriter = adios.Open("myDoubles.bp", "w", datamanSettings, + adios::IOMode::INDEPENDENT); - datamanWriter->Write<double>( - ioMyDoubles, myDoubles.data()); // Base class Engine own the Write<T> - // that will call overloaded Write from - // Derived - datamanWriter->Write<std::complex<float>>(ioMyCFloats, myCFloats.data()); - datamanWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + if (datamanWriter == nullptr) + throw std::ios_base::failure( + "ERROR: failed to create DataMan I/O engine at Open\n"); + + datamanWriter->Write<double>( + ioMyDoubles, + myDoubles.data()); // Base class Engine own the Write<T> + // that will call overloaded Write from + // Derived + datamanWriter->Write<std::complex<float>>(ioMyCFloats, + myCFloats.data()); + datamanWriter->Close(); + } + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/datamanWriter/helloDataManWriter_nompi.cpp b/examples/hello/datamanWriter/helloDataManWriter_nompi.cpp index 75114e8721323d17809359be69bbd2bfa32e4e03..d6b1e3068f6447cd2985fb16b5983227972230cf 100644 --- a/examples/hello/datamanWriter/helloDataManWriter_nompi.cpp +++ b/examples/hello/datamanWriter/helloDataManWriter_nompi.cpp @@ -15,85 +15,89 @@ int main(int argc, char *argv[]) { - const bool adiosDebug = true; - adios::ADIOS adios(adios::Verbose::WARN, adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adios::Verbose::WARN, adiosDebug); - // Application variable - std::vector<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); + // Application variable + std::vector<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); - std::vector<std::complex<float>> myCFloats; - myCFloats.reserve(3); - myCFloats.emplace_back(1, 3); - myCFloats.emplace_back(2, 2); - myCFloats.emplace_back(3, 1); + std::vector<std::complex<float>> myCFloats; + myCFloats.reserve(3); + myCFloats.emplace_back(1, 3); + myCFloats.emplace_back(2, 2); + myCFloats.emplace_back(3, 1); - try - { - // Define variable and local size - // Define variable and local size - auto ioMyFloats = adios.DefineVariable<float>("myfloats", adios::Dims{Nx}); - auto ioMyFloat = adios.DefineVariable<float>("myfloat", adios::Dims{1}); - // auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", - // adios::Dims{Nx} ); - // auto& ioMyCFloats = adios.DefineVariable<std::complex<float>>( - // "myCFloats", {3} ); - - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &datamanSettings = adios.DeclareMethod("WAN"); - if (!datamanSettings.isUserDefined()) + try { - // if not defined by user, we can change the default settings - datamanSettings.SetEngine("DataManWriter"); - datamanSettings.SetParameters("real_time=yes", "method_type=stream", - "method=dump", "monitoring=yes", - "local_ip=127.0.0.1", "remote_ip=127.0.0.1", - "local_port=12306", "remote_port=12307"); - // datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", - // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", - // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported , - // will throw an exception - } + // Define variable and local size + // Define variable and local size + auto ioMyFloats = + adios.DefineVariable<float>("myfloats", adios::Dims{Nx}); + auto ioMyFloat = adios.DefineVariable<float>("myfloat", adios::Dims{1}); + // auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", + // adios::Dims{Nx} ); + // auto& ioMyCFloats = adios.DefineVariable<std::complex<float>>( + // "myCFloats", {3} ); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &datamanSettings = adios.DeclareMethod("WAN"); + if (!datamanSettings.isUserDefined()) + { + // if not defined by user, we can change the default settings + datamanSettings.SetEngine("DataManWriter"); + datamanSettings.SetParameters( + "real_time=yes", "method_type=stream", "method=dump", + "monitoring=yes", "local_ip=127.0.0.1", "remote_ip=127.0.0.1", + "local_port=12306", "remote_port=12307"); + // datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + // datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", + // "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported + // , + // will throw an exception + } - // Create engine smart pointer to DataMan Engine due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // DataMan - auto datamanWriter = adios.Open("myDoubles.bp", "w", datamanSettings, - adios::IOMode::INDEPENDENT); + // Create engine smart pointer to DataMan Engine due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // DataMan + auto datamanWriter = adios.Open("myDoubles.bp", "w", datamanSettings, + adios::IOMode::INDEPENDENT); - if (datamanWriter == nullptr) - throw std::ios_base::failure( - "ERROR: failed to create DataMan I/O engine at Open\n"); + if (datamanWriter == nullptr) + throw std::ios_base::failure( + "ERROR: failed to create DataMan I/O engine at Open\n"); - datamanWriter->Write<float>( - ioMyFloats, myFloats.data()); // Base class Engine own the Write<T> that - // will call overloaded Write from Derived - const float num = 1.12; - datamanWriter->Write<float>(ioMyFloat, &num); // Base class Engine own the - // Write<T> that will call - // overloaded Write from - // Derived - // datamanWriter->Write( ioMyCFloats, myCFloats.data() ); - datamanWriter->Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } + datamanWriter->Write<float>( + ioMyFloats, + myFloats.data()); // Base class Engine own the Write<T> that + // will call overloaded Write from Derived + const float num = 1.12; + datamanWriter->Write<float>(ioMyFloat, + &num); // Base class Engine own the + // Write<T> that will call + // overloaded Write from + // Derived + // datamanWriter->Write( ioMyCFloats, myCFloats.data() ); + datamanWriter->Close(); + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } - return 0; + return 0; } diff --git a/examples/hello/timeBP/timeBPWriter.cpp b/examples/hello/timeBP/timeBPWriter.cpp index 280e97e1e7eb08761a1b7ce5f0eba11bb4ed66e6..b9ae445debe12905c0614549778632eb32758a6b 100644 --- a/examples/hello/timeBP/timeBPWriter.cpp +++ b/examples/hello/timeBP/timeBPWriter.cpp @@ -17,107 +17,109 @@ int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::ERROR, adiosDebug); - - // Application variable - std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); - - const std::size_t rows = 3; - const std::size_t columns = 3; - - std::vector<float> myMatrix; - if (rank % 2 == 0) // even rank - { - myMatrix.reserve(rows * columns); - myMatrix.push_back(1); - myMatrix.push_back(2), myMatrix.push_back(3); - myMatrix.push_back(4); - myMatrix.push_back(5), myMatrix.push_back(6); - myMatrix.push_back(7); - myMatrix.push_back(8), myMatrix.push_back(8); - } - - std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; - - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", {Nx}); - adios::Variable<float> &ioMyMatrix = - adios.DefineVariable<float>("myMatrix", {rows, columns}); - adios::Variable<float> &ioMyMatrix2 = - adios.DefineVariable<float>("myMatrix2", {rows, columns}); - - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("MyMethod"); // default method type is BPWriter - bpWriterSettings.SetParameters("profile_units=mus"); - bpWriterSettings.AddTransport( - "File", "profile_units=mus", - "have_metadata_file=no"); // uses default POSIX library - - // Create engine smart pointer due to polymorphism, - // Open returns a smart pointer to Engine containing the Derived class - // Writer - auto bpWriter = adios.Open("time.bp", "w", bpWriterSettings); - - if (bpWriter == nullptr) - throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n"); - - for (unsigned int t = 0; t < 10; ++t) + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + const bool adiosDebug = true; + adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::ERROR, adiosDebug); + + // Application variable + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); + + const std::size_t rows = 3; + const std::size_t columns = 3; + + std::vector<float> myMatrix; + if (rank % 2 == 0) // even rank { - myDoubles[0] = t; - bpWriter->Write<double>( - ioMyDoubles, myDoubles.data()); // Base class Engine own the Write<T> - // that will call overloaded Write - // from Derived - - if (rank % 2 == 0) // even rank - { - myMatrix[0] = t; - myMatrix2[0] = t; - - bpWriter->Write<float>(ioMyMatrix, myMatrix.data()); - bpWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); - } - bpWriter->Advance(); + myMatrix.reserve(rows * columns); + myMatrix.push_back(1); + myMatrix.push_back(2), myMatrix.push_back(3); + myMatrix.push_back(4); + myMatrix.push_back(5), myMatrix.push_back(6); + myMatrix.push_back(7); + myMatrix.push_back(8), myMatrix.push_back(8); } - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - if (rank == 0) + std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; + + try + { + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", {Nx}); + adios::Variable<float> &ioMyMatrix = + adios.DefineVariable<float>("myMatrix", {rows, columns}); + adios::Variable<float> &ioMyMatrix2 = + adios.DefineVariable<float>("myMatrix2", {rows, columns}); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = + adios.DeclareMethod("MyMethod"); // default method type is BPWriter + bpWriterSettings.SetParameters("profile_units=mus"); + bpWriterSettings.AddTransport( + "File", "profile_units=mus", + "have_metadata_file=no"); // uses default POSIX library + + // Create engine smart pointer due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // Writer + auto bpWriter = adios.Open("time.bp", "w", bpWriterSettings); + + if (bpWriter == nullptr) + throw std::ios_base::failure( + "ERROR: couldn't create bpWriter at Open\n"); + + for (unsigned int t = 0; t < 10; ++t) + { + myDoubles[0] = t; + bpWriter->Write<double>( + ioMyDoubles, + myDoubles.data()); // Base class Engine own the Write<T> + // that will call overloaded Write + // from Derived + + if (rank % 2 == 0) // even rank + { + myMatrix[0] = t; + myMatrix2[0] = t; + + bpWriter->Write<float>(ioMyMatrix, myMatrix.data()); + bpWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); + } + bpWriter->Advance(); + } + + bpWriter->Close(); + } + catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::ios_base::failure &e) - { - if (rank == 0) + catch (std::ios_base::failure &e) { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) + catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } } - } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/examples/hello/timeBP/timeBPWriter_nompi.cpp b/examples/hello/timeBP/timeBPWriter_nompi.cpp index 48fdd2bbf3111f3c36b550c927d03b475893bf4e..42af66f238ff9e7dad277d0d7c89e4dee30de5d0 100644 --- a/examples/hello/timeBP/timeBPWriter_nompi.cpp +++ b/examples/hello/timeBP/timeBPWriter_nompi.cpp @@ -15,82 +15,83 @@ int main(int /*argc*/, char ** /*argv*/) { - const bool adiosDebug = true; - adios::ADIOS adios(adios::Verbose::ERROR, adiosDebug); + const bool adiosDebug = true; + adios::ADIOS adios(adios::Verbose::ERROR, adiosDebug); - // Application variable - std::vector<double> myDoubles = {10, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myDoubles.size(); + // Application variable + std::vector<double> myDoubles = {10, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myDoubles.size(); - const std::size_t rows = 3; - const std::size_t columns = 3; + const std::size_t rows = 3; + const std::size_t columns = 3; - std::vector<float> myMatrix; - myMatrix.reserve(rows * columns); - myMatrix.push_back(1); - myMatrix.push_back(2), myMatrix.push_back(3); - myMatrix.push_back(4); - myMatrix.push_back(5), myMatrix.push_back(6); - myMatrix.push_back(7); - myMatrix.push_back(8), myMatrix.push_back(8); + std::vector<float> myMatrix; + myMatrix.reserve(rows * columns); + myMatrix.push_back(1); + myMatrix.push_back(2), myMatrix.push_back(3); + myMatrix.push_back(4); + myMatrix.push_back(5), myMatrix.push_back(6); + myMatrix.push_back(7); + myMatrix.push_back(8), myMatrix.push_back(8); - std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; + std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9}; - try - { - // Define variable and local size - adios::Variable<double> &ioMyDoubles = - adios.DefineVariable<double>("myDoubles", {Nx}); - adios::Variable<float> &ioMyMatrix = - adios.DefineVariable<float>("myMatrix", {rows, columns}); - adios::Variable<float> &ioMyMatrix2 = - adios.DefineVariable<float>("myMatrix2", {rows, columns}); + try + { + // Define variable and local size + adios::Variable<double> &ioMyDoubles = + adios.DefineVariable<double>("myDoubles", {Nx}); + adios::Variable<float> &ioMyMatrix = + adios.DefineVariable<float>("myMatrix", {rows, columns}); + adios::Variable<float> &ioMyMatrix2 = + adios.DefineVariable<float>("myMatrix2", {rows, columns}); - // Define method for engine creation, it is basically straight-forward - // parameters - adios::Method &bpWriterSettings = - adios.DeclareMethod("SingleFile"); // default method type is BPWriter - bpWriterSettings.SetParameters("profile_units=mus"); - bpWriterSettings.AddTransport( - "File", "profile_units=mus", - "have_metadata_file=no"); // uses default POSIX library + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &bpWriterSettings = adios.DeclareMethod( + "SingleFile"); // default method type is BPWriter + bpWriterSettings.SetParameters("profile_units=mus"); + bpWriterSettings.AddTransport( + "File", "profile_units=mus", + "have_metadata_file=no"); // uses default POSIX library - // Create object directly rather than using polymorphism with ADIOS.Open - adios::BPFileWriter bpWriter(adios, "time_nompi.bp", "w", adios.m_MPIComm, - bpWriterSettings); + // Create object directly rather than using polymorphism with ADIOS.Open + adios::BPFileWriter bpWriter(adios, "time_nompi.bp", "w", + adios.m_MPIComm, bpWriterSettings); - for (unsigned int t = 0; t < 3; ++t) - { - myDoubles[0] = t; // t * -1; - myMatrix[0] = t; - myMatrix2[0] = t; + for (unsigned int t = 0; t < 3; ++t) + { + myDoubles[0] = t; // t * -1; + myMatrix[0] = t; + myMatrix2[0] = t; - bpWriter.Write(ioMyDoubles, myDoubles.data()); // Base class Engine own - // the Write<T> that will - // call overloaded Write - // from Derived - bpWriter.Write(ioMyMatrix, myMatrix.data()); - bpWriter.Write(ioMyMatrix2, myMatrix2.data()); - bpWriter.Advance(); - } + bpWriter.Write(ioMyDoubles, + myDoubles.data()); // Base class Engine own + // the Write<T> that will + // call overloaded Write + // from Derived + bpWriter.Write(ioMyMatrix, myMatrix.data()); + bpWriter.Write(ioMyMatrix2, myMatrix2.data()); + bpWriter.Advance(); + } - bpWriter.Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } + bpWriter.Close(); + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } - return 0; + return 0; } diff --git a/examples/solidfluid/solidfluid_read.cpp b/examples/solidfluid/solidfluid_read.cpp index 97f7f950563cf91b85747b32b3ba02f69b6ef6a4..028590601b9cdefaae4eeb6ebd37206726d70357 100644 --- a/examples/solidfluid/solidfluid_read.cpp +++ b/examples/solidfluid/solidfluid_read.cpp @@ -19,9 +19,9 @@ struct MYDATA { - int NX; - double *t; - std::vector<double> p; + int NX; + double *t; + std::vector<double> p; }; const int N = 10; @@ -31,276 +31,284 @@ int rank, size; void read_ckpt(adios::ADIOS adios, struct MYDATA &solid, struct MYDATA &fluid) { - try - { - // Open an input which was written with an expected Method - // The write transport is associated with the group in the XML - // ADIOS pairs that with the corresponding read transport - // "r" is required to indicate we are reading - auto ckptfile = adios.Open("checkpoint.bp", "r", comm, "checkpoint"); - // We can also manually set the read transport - // auto ckptfile = adios.Open("checkpoint.bp", adios::READ_METHOD_BP, "r", - // comm); - - // Note: we only see a single step in the input but the checkpoint has - // only one step anyway. This makes this code simple - - // simple immediate read of a scalar - ckptfile->ReadScalar("solid/NX", &solid.NX); - // solid.NX is filled at this point - - // scheduled version of read of another scalar - // //ckptfile->ScheduleRead ("fluid/NX", &fluid.NX); - // //ckptfile->Read(); // perform reading now - ckptfile->Read("fluid/NX", &fluid.NX); - // fluid.NX is filled at this point - - solid.t = new double(solid.NX); - solid.p = std::vector<double>(solid.NX); - - fluid.t = new double(fluid.NX); - fluid.p = std::vector<double>(fluid.NX); - - adios::ADIOS_SELECTION_WRITEBLOCK sel(rank); - adios.Read(ckptfile, sel, "solid/temperature", solid.t); - adios.Read(ckptfile, sel, "solid/pressure", solid.p); - adios.Read(ckptfile, sel, "fluid/temperature", fluid.t); - // force checking if the allocated space equals to the size of the - // selection: - adios.Read(ckptfile, sel, "fluid/pressure", fluid.p, - fluid.NX * sizeof(double)); - adios.Read(ckptfile, true); // true: blocking read, which is also default - adios.Close(ckptfile); // Should this do Read() if user misses or should we - // complain? - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + try + { + // Open an input which was written with an expected Method + // The write transport is associated with the group in the XML + // ADIOS pairs that with the corresponding read transport + // "r" is required to indicate we are reading + auto ckptfile = adios.Open("checkpoint.bp", "r", comm, "checkpoint"); + // We can also manually set the read transport + // auto ckptfile = adios.Open("checkpoint.bp", adios::READ_METHOD_BP, + // "r", + // comm); + + // Note: we only see a single step in the input but the checkpoint has + // only one step anyway. This makes this code simple + + // simple immediate read of a scalar + ckptfile->ReadScalar("solid/NX", &solid.NX); + // solid.NX is filled at this point + + // scheduled version of read of another scalar + // //ckptfile->ScheduleRead ("fluid/NX", &fluid.NX); + // //ckptfile->Read(); // perform reading now + ckptfile->Read("fluid/NX", &fluid.NX); + // fluid.NX is filled at this point + + solid.t = new double(solid.NX); + solid.p = std::vector<double>(solid.NX); + + fluid.t = new double(fluid.NX); + fluid.p = std::vector<double>(fluid.NX); + + adios::ADIOS_SELECTION_WRITEBLOCK sel(rank); + adios.Read(ckptfile, sel, "solid/temperature", solid.t); + adios.Read(ckptfile, sel, "solid/pressure", solid.p); + adios.Read(ckptfile, sel, "fluid/temperature", fluid.t); + // force checking if the allocated space equals to the size of the + // selection: + adios.Read(ckptfile, sel, "fluid/pressure", fluid.p, + fluid.NX * sizeof(double)); + adios.Read(ckptfile, + true); // true: blocking read, which is also default + adios.Close( + ckptfile); // Should this do Read() if user misses or should we + // complain? + } + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking { - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << e.what() << "\n"; + } } - } } void read_solid(adios::ADIOS adios, struct MYDATA &solid) { - float timeout_sec = 1.0; - int retval = 0; - - try - { - // Open a file for input, no group defined - // A reading transport should be defined if not file based - // "r" is required to indicate we are reading - int solidfile = adios.Open("solid.bp", "r", - comm); //, ADIOS_LOCKMODE_NONE, timeout_sec); - // int solidfile = adios.Open("solid.bp", adios::READ_METHOD_BP, "r", comm); - /* process file here... */ - const adios::ADIOS_VARINFO &v = adios.InqVar(solidfile, "temperature"); - v.GetBlockInfo(); - - printf("ndim = %d\n", v.ndim); - // printf ("nsteps = %d\n", v.nsteps); - printf("dims[%" PRIu64 "][%" PRIu64 "]\n", v.dims[0], v.dims[1]); - - uint64_t slice_size = v.dims[0] / size; + float timeout_sec = 1.0; + int retval = 0; - if (rank == size - 1) - slice_size = slice_size + v.dims[0] % size; + try + { + // Open a file for input, no group defined + // A reading transport should be defined if not file based + // "r" is required to indicate we are reading + int solidfile = adios.Open("solid.bp", "r", + comm); //, ADIOS_LOCKMODE_NONE, timeout_sec); + // int solidfile = adios.Open("solid.bp", adios::READ_METHOD_BP, "r", + // comm); + /* process file here... */ + const adios::ADIOS_VARINFO &v = adios.InqVar(solidfile, "temperature"); + v.GetBlockInfo(); - start[0] = rank * slice_size; - count[0] = slice_size; - start[1] = 0; - count[1] = v.dims[1]; + printf("ndim = %d\n", v.ndim); + // printf ("nsteps = %d\n", v.nsteps); + printf("dims[%" PRIu64 "][%" PRIu64 "]\n", v.dims[0], v.dims[1]); - auto data = std::make_unique<double[]>(slice_size * v.dims[1] * 8); + uint64_t slice_size = v.dims[0] / size; - adios::ADIOS_SELECTION_BOUNDINGBOX sel(v.ndim, start, count); + if (rank == size - 1) + slice_size = slice_size + v.dims[0] % size; - /* Processing loop over the steps (we are already in the first one) */ - while (adios_errno != err_end_of_stream) - { - steps++; // steps start counting from 1 + start[0] = rank * slice_size; + count[0] = slice_size; + start[1] = 0; + count[1] = v.dims[1]; - solidfile.ScheduleRead(sel, "temperature", solid.t); - solidfile.Read(true); + auto data = std::make_unique<double[]>(slice_size * v.dims[1] * 8); - if (rank == 0) - printf("--------- Step: %d --------------------------------\n", - solidfile.getCurrentStep()); + adios::ADIOS_SELECTION_BOUNDINGBOX sel(v.ndim, start, count); - printf("rank=%d: [0:%" PRIu64 ",0:%" PRIu64 "] = [", rank, v.dims[0], - v.dims[1]); - for (i = 0; i < slice_size; i++) - { - printf(" ["); - for (j = 0; j < v.dims[1]; j++) + /* Processing loop over the steps (we are already in the first one) */ + while (adios_errno != err_end_of_stream) { - printf("%g ", *((double *)data + i * v.dims[1] + j)); + steps++; // steps start counting from 1 + + solidfile.ScheduleRead(sel, "temperature", solid.t); + solidfile.Read(true); + + if (rank == 0) + printf("--------- Step: %d --------------------------------\n", + solidfile.getCurrentStep()); + + printf("rank=%d: [0:%" PRIu64 ",0:%" PRIu64 "] = [", rank, + v.dims[0], v.dims[1]); + for (i = 0; i < slice_size; i++) + { + printf(" ["); + for (j = 0; j < v.dims[1]; j++) + { + printf("%g ", *((double *)data + i * v.dims[1] + j)); + } + printf("]"); + } + printf(" ]\n\n"); + + // advance to 1) next available step with 2) blocking wait + solidfile.AdvanceStep(false, timeout_sec); + if (adios_errno == err_step_notready) + { + printf("rank %d: No new step arrived within the timeout. Quit. " + "%s\n", + rank, adios_errmsg()); + break; // quit while loop + } } - printf("]"); - } - printf(" ]\n\n"); - - // advance to 1) next available step with 2) blocking wait - solidfile.AdvanceStep(false, timeout_sec); - if (adios_errno == err_step_notready) - { - printf("rank %d: No new step arrived within the timeout. Quit. %s\n", - rank, adios_errmsg()); - break; // quit while loop - } - } - solidfile.Close(); - } - catch (std::exception &e) - { - if (adios_errno == err_file_not_found) - { - printf("rank %d: Stream not found after waiting %f seconds: %s\n", rank, - timeout_sec, adios_errmsg()); - retval = adios_errno; - } - else if (adios_errno == err_end_of_stream) - { - printf("rank %d: Stream terminated before open. %s\n", rank, - adios_errmsg()); - retval = adios_errno; + solidfile.Close(); } - else if (f == NULL) + catch (std::exception &e) { - printf("rank %d: Error at opening stream: %s\n", rank, adios_errmsg()); - retval = adios_errno; + if (adios_errno == err_file_not_found) + { + printf("rank %d: Stream not found after waiting %f seconds: %s\n", + rank, timeout_sec, adios_errmsg()); + retval = adios_errno; + } + else if (adios_errno == err_end_of_stream) + { + printf("rank %d: Stream terminated before open. %s\n", rank, + adios_errmsg()); + retval = adios_errno; + } + else if (f == NULL) + { + printf("rank %d: Error at opening stream: %s\n", rank, + adios_errmsg()); + retval = adios_errno; + } } - } } void read_fluid(adios::ADIOS adios, struct MYDATA &fluid) { - float timeout_sec = 1.0; - int retval = 0; + float timeout_sec = 1.0; + int retval = 0; - // Open a file for input, no group defined - // A reading transport should be defined if not file based - // "r" is required to indicate we are reading - adios::ADIOS_INPUT fluidfile(comm, "r"); - - try - { - fluidfile.Open("fluid.bp"); //, ADIOS_LOCKMODE_NONE, timeout_sec); - - /* process file here... */ - const adios::ADIOS_VARINFO &v = fluidfile.InqVar("temperature"); - v.GetBlockInfo(); - - printf("ndim = %d\n", v.ndim); - // printf ("nsteps = %d\n", v.nsteps); - printf("dims[%" PRIu64 "][%" PRIu64 "]\n", v.dims[0], v.dims[1]); + // Open a file for input, no group defined + // A reading transport should be defined if not file based + // "r" is required to indicate we are reading + adios::ADIOS_INPUT fluidfile(comm, "r"); - uint64_t slice_size = v.dims[0] / size; + try + { + fluidfile.Open("fluid.bp"); //, ADIOS_LOCKMODE_NONE, timeout_sec); - if (rank == size - 1) - slice_size = slice_size + v.dims[0] % size; + /* process file here... */ + const adios::ADIOS_VARINFO &v = fluidfile.InqVar("temperature"); + v.GetBlockInfo(); - start[0] = rank * slice_size; - count[0] = slice_size; - start[1] = 0; - count[1] = v.dims[1]; + printf("ndim = %d\n", v.ndim); + // printf ("nsteps = %d\n", v.nsteps); + printf("dims[%" PRIu64 "][%" PRIu64 "]\n", v.dims[0], v.dims[1]); - data = malloc(slice_size * v.dims[1] * 8); + uint64_t slice_size = v.dims[0] / size; - adios::ADIOS_SELECTION_BOUNDINGBOX sel(v.ndim, start, count); + if (rank == size - 1) + slice_size = slice_size + v.dims[0] % size; - /* Processing loop over the steps (we are already in the first one) */ - while (adios_errno != err_end_of_stream) - { - steps++; // steps start counting from 1 + start[0] = rank * slice_size; + count[0] = slice_size; + start[1] = 0; + count[1] = v.dims[1]; - fluidfile.ScheduleRead(sel, "temperature", fluid.t); - fluidfile.Read(true); + data = malloc(slice_size * v.dims[1] * 8); - if (rank == 0) - printf("--------- Step: %d --------------------------------\n", - fluidfile.getCurrentStep()); + adios::ADIOS_SELECTION_BOUNDINGBOX sel(v.ndim, start, count); - printf("rank=%d: [0:%" PRIu64 ",0:%" PRIu64 "] = [", rank, v.dims[0], - v.dims[1]); - for (i = 0; i < slice_size; i++) - { - printf(" ["); - for (j = 0; j < v.dims[1]; j++) + /* Processing loop over the steps (we are already in the first one) */ + while (adios_errno != err_end_of_stream) { - printf("%g ", *((double *)data + i * v.dims[1] + j)); + steps++; // steps start counting from 1 + + fluidfile.ScheduleRead(sel, "temperature", fluid.t); + fluidfile.Read(true); + + if (rank == 0) + printf("--------- Step: %d --------------------------------\n", + fluidfile.getCurrentStep()); + + printf("rank=%d: [0:%" PRIu64 ",0:%" PRIu64 "] = [", rank, + v.dims[0], v.dims[1]); + for (i = 0; i < slice_size; i++) + { + printf(" ["); + for (j = 0; j < v.dims[1]; j++) + { + printf("%g ", *((double *)data + i * v.dims[1] + j)); + } + printf("]"); + } + printf(" ]\n\n"); + + // advance to 1) next available step with 2) blocking wait + fluidfile.AdvanceStep(false, timeout_sec); + if (adios_errno == err_step_notready) + { + printf("rank %d: No new step arrived within the timeout. Quit. " + "%s\n", + rank, adios_errmsg()); + break; // quit while loop + } } - printf("]"); - } - printf(" ]\n\n"); - - // advance to 1) next available step with 2) blocking wait - fluidfile.AdvanceStep(false, timeout_sec); - if (adios_errno == err_step_notready) - { - printf("rank %d: No new step arrived within the timeout. Quit. %s\n", - rank, adios_errmsg()); - break; // quit while loop - } - } - fluidfile.Close(); - } - catch (std::exception &e) - { - if (adios_errno == err_file_not_found) - { - printf("rank %d: Stream not found after waiting %f seconds: %s\n", rank, - timeout_sec, adios_errmsg()); - retval = adios_errno; - } - else if (adios_errno == err_end_of_stream) - { - printf("rank %d: Stream terminated before open. %s\n", rank, - adios_errmsg()); - retval = adios_errno; + fluidfile.Close(); } - else if (f == NULL) + catch (std::exception &e) { - printf("rank %d: Error at opening stream: %s\n", rank, adios_errmsg()); - retval = adios_errno; + if (adios_errno == err_file_not_found) + { + printf("rank %d: Stream not found after waiting %f seconds: %s\n", + rank, timeout_sec, adios_errmsg()); + retval = adios_errno; + } + else if (adios_errno == err_end_of_stream) + { + printf("rank %d: Stream terminated before open. %s\n", rank, + adios_errmsg()); + retval = adios_errno; + } + else if (f == NULL) + { + printf("rank %d: Error at opening stream: %s\n", rank, + adios_errmsg()); + retval = adios_errno; + } } - } } int main(int argc, char **argv) { - MPI_Init(&argc, &argv); - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &size); + MPI_Init(&argc, &argv); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); - try - { - // ADIOS manager object creation. MPI must be initialized - adios::ADIOS adios("globalArrayXML.xml", comm, true); + try + { + // ADIOS manager object creation. MPI must be initialized + adios::ADIOS adios("globalArrayXML.xml", comm, true); - read_ckpt(adios, solid, fluid); + read_ckpt(adios, solid, fluid); - read_solid(adios, solid); + read_solid(adios, solid); - read_fluid(adios, fluid); - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + read_fluid(adios, fluid); + } + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking { - std::cout << e.what() << "\n"; + if (rank == 0) + { + std::cout << e.what() << "\n"; + } } - } - if (rank == 0) - printf("We have processed %d steps\n", steps); + if (rank == 0) + printf("We have processed %d steps\n", steps); - free(data); - MPI_Finalize(); + free(data); + MPI_Finalize(); - return retval; + return retval; } diff --git a/examples/solidfluid/solidfluid_write.cpp b/examples/solidfluid/solidfluid_write.cpp index fd17df803d8c77336a471649e31c7543e1bec75f..68992800e2c9496ad51caa01b2e3e3a30e4eb66d 100644 --- a/examples/solidfluid/solidfluid_write.cpp +++ b/examples/solidfluid/solidfluid_write.cpp @@ -20,9 +20,9 @@ using adiosFile = std::shared_ptr<adios::Engine>; struct MYDATA { - int NX; - double *t; - std::vector<double> p; + int NX; + double *t; + std::vector<double> p; }; const int N = 10; @@ -32,206 +32,218 @@ int rank, size; void write_data(adiosFile writer, struct MYDATA &data) { - writer->Write("NX", &data.NX); - writer->Write("rank", &rank); - writer->Write("size", &size); - writer->Write("temperature", data.t); - writer->Write("pressure", data.p.data()); - // writer->Flush(); AdvanceStep()??? + writer->Write("NX", &data.NX); + writer->Write("rank", &rank); + writer->Write("size", &size); + writer->Write("temperature", data.t); + writer->Write("pressure", data.p.data()); + // writer->Flush(); AdvanceStep()??? } void write_checkpoint(adiosFile ckptfile, const struct MYDATA &solid, const struct MYDATA &fluid) { - try - { - ckptfile->Write("solid/NX", &solid.NX); - ckptfile->Write("solid/rank", &rank); - ckptfile->Write("solid/size", &size); - ckptfile->Write("solid/temperature", solid.t); - ckptfile->Write("solid/pressure", &solid.p[0]); - - ckptfile->Write("fluid/NX", &fluid.NX); - ckptfile->Write("fluid/rank", &rank); - ckptfile->Write("fluid/size", &size); - ckptfile->Write("fluid/temperature", fluid.t); - ckptfile->Write("fluid/pressure", fluid.p.data()); - // ckptfile->AdvanceStep(); ?? - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + try { - std::cout << "ERROR: caught an exception from write_checkpoint\n"; - std::cout << e.what() << "\n"; + ckptfile->Write("solid/NX", &solid.NX); + ckptfile->Write("solid/rank", &rank); + ckptfile->Write("solid/size", &size); + ckptfile->Write("solid/temperature", solid.t); + ckptfile->Write("solid/pressure", &solid.p[0]); + + ckptfile->Write("fluid/NX", &fluid.NX); + ckptfile->Write("fluid/rank", &rank); + ckptfile->Write("fluid/size", &size); + ckptfile->Write("fluid/temperature", fluid.t); + ckptfile->Write("fluid/pressure", fluid.p.data()); + // ckptfile->AdvanceStep(); ?? + } + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking + { + if (rank == 0) + { + std::cout << "ERROR: caught an exception from write_checkpoint\n"; + std::cout << e.what() << "\n"; + } } - } } void write_viz(std::shared_ptr<adios::Engine> vizstream, struct MYDATA &solid, struct MYDATA &fluid) { - // This stream is not associated with a group, so we must say for each write - // which group to use - // The output variable is re-defined inside as <groupname>/<varname>, unless - // given as third string argument - // An array variable's dimension definitions are also re-defined with - // dimensions <groupname>/<dimensionvar> + // This stream is not associated with a group, so we must say for each write + // which group to use + // The output variable is re-defined inside as <groupname>/<varname>, unless + // given as third string argument + // An array variable's dimension definitions are also re-defined with + // dimensions <groupname>/<dimensionvar> - // vizstream->Write ("solid", "NX", &solid.NX); - // vizstream->Write ("solid", "rank", &rank); - // vizstream->Write ("solid", "size", &size); + // vizstream->Write ("solid", "NX", &solid.NX); + // vizstream->Write ("solid", "rank", &rank); + // vizstream->Write ("solid", "size", &size); - // write solid group's temperature simply as temperature, risking overloading - // the 'temperature' variable when - // reading from a file + // write solid group's temperature simply as temperature, risking + // overloading + // the 'temperature' variable when + // reading from a file - // vizstream->Write ("solid", "temperature", "my/tempvarinfile", solid.t); + // vizstream->Write ("solid", "temperature", "my/tempvarinfile", solid.t); - // vizstream->Write ("fluid", "NX", &fluid.NX); - // vizstream->Write ("fluid", "rank", &rank); - // vizstream->Write ("fluid", "size", &size); + // vizstream->Write ("fluid", "NX", &fluid.NX); + // vizstream->Write ("fluid", "rank", &rank); + // vizstream->Write ("fluid", "size", &size); - // vizstream->Write ("fluid", "temperature", "temperature", fluid.t); + // vizstream->Write ("fluid", "temperature", "temperature", fluid.t); - // vizstream->Flush(); // flushes all data to disk; required operation - // vizstream.AdvanceStep(); + // vizstream->Flush(); // flushes all data to disk; required operation + // vizstream.AdvanceStep(); } void compute(int it, struct MYDATA &solid, struct MYDATA &fluid) { - for (int i = 0; i < solid.NX; i++) - { - solid.t[i] = it * 100.0 + rank * solid.NX + i; - solid.p[i] = it * 1000.0 + rank * solid.NX + i; - } - for (int i = 0; i < fluid.NX; i++) - { - fluid.t[i] = it * 200.0 + rank * fluid.NX + i; - fluid.p[i] = it * 2000.0 + rank * fluid.NX + i; - } + for (int i = 0; i < solid.NX; i++) + { + solid.t[i] = it * 100.0 + rank * solid.NX + i; + solid.p[i] = it * 1000.0 + rank * solid.NX + i; + } + for (int i = 0; i < fluid.NX; i++) + { + fluid.t[i] = it * 200.0 + rank * fluid.NX + i; + fluid.p[i] = it * 2000.0 + rank * fluid.NX + i; + } } int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &size); - - solid.NX = N; - solid.t = new double[N]; - solid.p = std::vector<double>(N); - - fluid.NX = N; - fluid.t = new double[N]; - fluid.p = std::vector<double>(N); - - try - { - // ADIOS manager object creation. MPI must be initialized - adios::ADIOS adios(comm, true); - - adios::Method &fileSettings = - adios.DeclareMethod("Reusable"); // default engine is BP writer - fileSettings.AddTransport("POSIX", "have_metadata_file=no"); - - // Open a file with a Method which has selected a group and a transport in - // the XML. - // "a" will append to an already existing file, "w" would create a new file - // Multiple writes to the same file work as append in this application run - // FIXME: how do we support Update to same step? - - auto solidfile = adios.Open("solid.bp", "w", comm, fileSettings); - - // "solid" is a method but incidentally also a group - // Constructor only creates an object and what is needed there but does not - // open a stream/file - // It can be used to initialize a staging connection if not declared before - // FIXME: which argument can be post-poned into Open() instead of - // constructor? - // solidfile.Open("solid.bp"); - - // Open a file with a Method that has selected a group and an engine in the - // XML - // The transport method(s) are (must be) associated with the engines - // "a" will append to an already existing file, "w" would create a new file - // Multiple writes to the same file work as append in this application run - // FIXME: how do we support Update to same step? - auto fluidfile = adios.Open("fluid.bp", "w", comm, fileSettings); - - auto checkpointFile = adios.Open("checkpoint.bp", "w", comm, fileSettings); - - // int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); - // we do not open this here, but every time when needed in a function - - // Another output not associated with a single group, so that we can mix - // variables to it - // adios:handle vizstream = adios.Open( "stream.bp", comm, "w", "STAGING", - // "options to staging method"); - auto vizstream = adios.Open("stream.bp", "w", comm, fileSettings); - - // This creates an empty group inside, and we can write all kinds of - // variables to it - - // Get Monitor info - std::ofstream logStream("info_" + std::to_string(rank) + ".log"); - adios.MonitorVariables(logStream); - - int checkPointSteps = 10; - - for (int it = 1; it <= 100; it++) - { - compute(it, solid, fluid); + MPI_Init(&argc, &argv); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); - write_data(solidfile, solid); - write_data(fluidfile, fluid); + solid.NX = N; + solid.t = new double[N]; + solid.p = std::vector<double>(N); - if (it % checkPointSteps == 0) - { - write_checkpoint(checkpointFile, solid, fluid); + fluid.NX = N; + fluid.t = new double[N]; + fluid.p = std::vector<double>(N); - MPI_Barrier(comm); - if (rank == 0) + try + { + // ADIOS manager object creation. MPI must be initialized + adios::ADIOS adios(comm, true); + + adios::Method &fileSettings = + adios.DeclareMethod("Reusable"); // default engine is BP writer + fileSettings.AddTransport("POSIX", "have_metadata_file=no"); + + // Open a file with a Method which has selected a group and a transport + // in + // the XML. + // "a" will append to an already existing file, "w" would create a new + // file + // Multiple writes to the same file work as append in this application + // run + // FIXME: how do we support Update to same step? + + auto solidfile = adios.Open("solid.bp", "w", comm, fileSettings); + + // "solid" is a method but incidentally also a group + // Constructor only creates an object and what is needed there but does + // not + // open a stream/file + // It can be used to initialize a staging connection if not declared + // before + // FIXME: which argument can be post-poned into Open() instead of + // constructor? + // solidfile.Open("solid.bp"); + + // Open a file with a Method that has selected a group and an engine in + // the + // XML + // The transport method(s) are (must be) associated with the engines + // "a" will append to an already existing file, "w" would create a new + // file + // Multiple writes to the same file work as append in this application + // run + // FIXME: how do we support Update to same step? + auto fluidfile = adios.Open("fluid.bp", "w", comm, fileSettings); + + auto checkpointFile = + adios.Open("checkpoint.bp", "w", comm, fileSettings); + + // int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); + // we do not open this here, but every time when needed in a function + + // Another output not associated with a single group, so that we can mix + // variables to it + // adios:handle vizstream = adios.Open( "stream.bp", comm, "w", + // "STAGING", + // "options to staging method"); + auto vizstream = adios.Open("stream.bp", "w", comm, fileSettings); + + // This creates an empty group inside, and we can write all kinds of + // variables to it + + // Get Monitor info + std::ofstream logStream("info_" + std::to_string(rank) + ".log"); + adios.MonitorVariables(logStream); + + int checkPointSteps = 10; + + for (int it = 1; it <= 100; it++) { - std::cout << "New checkpoint step, current = " << checkPointSteps - << "\n"; - std::cin >> checkPointSteps; - MPI_Bcast(&checkPointSteps, 1, MPI_INT, 0, comm); + compute(it, solid, fluid); + + write_data(solidfile, solid); + write_data(fluidfile, fluid); + + if (it % checkPointSteps == 0) + { + write_checkpoint(checkpointFile, solid, fluid); + + MPI_Barrier(comm); + if (rank == 0) + { + std::cout + << "New checkpoint step, current = " << checkPointSteps + << "\n"; + std::cin >> checkPointSteps; + MPI_Bcast(&checkPointSteps, 1, MPI_INT, 0, comm); + } + MPI_Barrier(comm); + } + + write_viz(vizstream, solid, fluid); + + MPI_Barrier(comm); + if (rank == 0) + printf("Timestep %d written\n", it); } - MPI_Barrier(comm); - } - write_viz(vizstream, solid, fluid); + solidfile->Close(); + fluidfile->Close(); + vizstream->Close(); - MPI_Barrier(comm); - if (rank == 0) - printf("Timestep %d written\n", it); + // need barrier before we destroy the ADIOS object here automatically + MPI_Barrier(comm); + if (rank == 0) + printf("Finalize adios\n"); } - - solidfile->Close(); - fluidfile->Close(); - vizstream->Close(); - - // need barrier before we destroy the ADIOS object here automatically - MPI_Barrier(comm); - if (rank == 0) - printf("Finalize adios\n"); - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking { - std::cout << "ERROR: " << e.what() << "\n"; + if (rank == 0) + { + std::cout << "ERROR: " << e.what() << "\n"; + } } - } - delete[] solid.t; - delete[] fluid.t; + delete[] solid.t; + delete[] fluid.t; - if (rank == 0) - printf("Finalize MPI\n"); - MPI_Finalize(); - return 0; + if (rank == 0) + printf("Finalize MPI\n"); + MPI_Finalize(); + return 0; } diff --git a/examples/solidfluid/solidfluid_write_nompi.cpp b/examples/solidfluid/solidfluid_write_nompi.cpp index c5342e9a755746b62dbad7c9118e68f4154247c5..37e641fdfcc455f318cbccfabfdf6f459ef362d7 100644 --- a/examples/solidfluid/solidfluid_write_nompi.cpp +++ b/examples/solidfluid/solidfluid_write_nompi.cpp @@ -20,9 +20,9 @@ using adiosFile = std::shared_ptr<adios::Engine>; struct MYDATA { - int NX; - double *t; - std::vector<double> p; + int NX; + double *t; + std::vector<double> p; }; const int N = 10; @@ -31,200 +31,212 @@ int rank = 0, size = 1; void set_io_variables(adios::ADIOS &adios, const std::string process) { - adios.DefineVariable<int>(process + "/NX"); - adios.DefineVariable<int>(process + "/rank"); - adios.DefineVariable<int>(process + "/size"); - adios.DefineVariable<double>(process + "/temperature", adios::Dims{N}); - adios.DefineVariable<double>(process + "/pressure", adios::Dims{N}); + adios.DefineVariable<int>(process + "/NX"); + adios.DefineVariable<int>(process + "/rank"); + adios.DefineVariable<int>(process + "/size"); + adios.DefineVariable<double>(process + "/temperature", adios::Dims{N}); + adios.DefineVariable<double>(process + "/pressure", adios::Dims{N}); } void write_data(adiosFile writer, const std::string process, struct MYDATA &data) { - writer->Write(process + "/NX", &data.NX); - writer->Write(process + "/rank", &rank); - writer->Write(process + "/size", &size); - writer->Write(process + "/temperature", data.t); - writer->Write(process + "/pressure", data.p.data()); - // writer->Flush(); AdvanceStep()??? + writer->Write(process + "/NX", &data.NX); + writer->Write(process + "/rank", &rank); + writer->Write(process + "/size", &size); + writer->Write(process + "/temperature", data.t); + writer->Write(process + "/pressure", data.p.data()); + // writer->Flush(); AdvanceStep()??? } void write_checkpoint(adiosFile ckptfile, const struct MYDATA &solid, const struct MYDATA &fluid) { - try - { - ckptfile->Write("solid/NX", &solid.NX); - ckptfile->Write("solid/rank", &rank); - ckptfile->Write("solid/size", &size); - ckptfile->Write("solid/temperature", solid.t); - ckptfile->Write("solid/pressure", &solid.p[0]); - - ckptfile->Write("fluid/NX", &fluid.NX); - ckptfile->Write("fluid/rank", &rank); - ckptfile->Write("fluid/size", &size); - ckptfile->Write("fluid/temperature", fluid.t); - ckptfile->Write("fluid/pressure", fluid.p.data()); - // ckptfile->AdvanceStep(); ?? - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - if (rank == 0) + try { - std::cout << "ERROR: caught an exception from write_checkpoint\n"; - std::cout << e.what() << "\n"; + ckptfile->Write("solid/NX", &solid.NX); + ckptfile->Write("solid/rank", &rank); + ckptfile->Write("solid/size", &size); + ckptfile->Write("solid/temperature", solid.t); + ckptfile->Write("solid/pressure", &solid.p[0]); + + ckptfile->Write("fluid/NX", &fluid.NX); + ckptfile->Write("fluid/rank", &rank); + ckptfile->Write("fluid/size", &size); + ckptfile->Write("fluid/temperature", fluid.t); + ckptfile->Write("fluid/pressure", fluid.p.data()); + // ckptfile->AdvanceStep(); ?? + } + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking + { + if (rank == 0) + { + std::cout << "ERROR: caught an exception from write_checkpoint\n"; + std::cout << e.what() << "\n"; + } } - } } void write_viz(adiosFile vizstream, struct MYDATA &solid, struct MYDATA &fluid) { - // This stream is not associated with a group, so we must say for each write - // which group to use - // The output variable is re-defined inside as <groupname>/<varname>, unless - // given as third string argument - // An array variable's dimension definitions are also re-defined with - // dimensions <groupname>/<dimensionvar> + // This stream is not associated with a group, so we must say for each write + // which group to use + // The output variable is re-defined inside as <groupname>/<varname>, unless + // given as third string argument + // An array variable's dimension definitions are also re-defined with + // dimensions <groupname>/<dimensionvar> - // vizstream->Write ("solid", "NX", &solid.NX); - // vizstream->Write ("solid", "rank", &rank); - // vizstream->Write ("solid", "size", &size); + // vizstream->Write ("solid", "NX", &solid.NX); + // vizstream->Write ("solid", "rank", &rank); + // vizstream->Write ("solid", "size", &size); - // write solid group's temperature simply as temperature, risking overloading - // the 'temperature' variable when - // reading from a file + // write solid group's temperature simply as temperature, risking + // overloading + // the 'temperature' variable when + // reading from a file - // vizstream->Write ("solid", "temperature", "my/tempvarinfile", solid.t); + // vizstream->Write ("solid", "temperature", "my/tempvarinfile", solid.t); - // vizstream->Write ("fluid", "NX", &fluid.NX); - // vizstream->Write ("fluid", "rank", &rank); - // vizstream->Write ("fluid", "size", &size); + // vizstream->Write ("fluid", "NX", &fluid.NX); + // vizstream->Write ("fluid", "rank", &rank); + // vizstream->Write ("fluid", "size", &size); - // vizstream->Write ("fluid", "temperature", "temperature", fluid.t); + // vizstream->Write ("fluid", "temperature", "temperature", fluid.t); - // vizstream->Flush(); // flushes all data to disk; required operation - // vizstream.AdvanceStep(); + // vizstream->Flush(); // flushes all data to disk; required operation + // vizstream.AdvanceStep(); } void compute(int it, struct MYDATA &solid, struct MYDATA &fluid) { - for (int i = 0; i < solid.NX; i++) - { - solid.t[i] = it * 100.0 + rank * solid.NX + i; - solid.p[i] = it * 1000.0 + rank * solid.NX + i; - } - for (int i = 0; i < fluid.NX; i++) - { - fluid.t[i] = it * 200.0 + rank * fluid.NX + i; - fluid.p[i] = it * 2000.0 + rank * fluid.NX + i; - } + for (int i = 0; i < solid.NX; i++) + { + solid.t[i] = it * 100.0 + rank * solid.NX + i; + solid.p[i] = it * 1000.0 + rank * solid.NX + i; + } + for (int i = 0; i < fluid.NX; i++) + { + fluid.t[i] = it * 200.0 + rank * fluid.NX + i; + fluid.p[i] = it * 2000.0 + rank * fluid.NX + i; + } } int main(int argc, char *argv[]) { - solid.NX = N; - solid.t = new double[N]; - solid.p = std::vector<double>(N); - - fluid.NX = N; - fluid.t = new double[N]; - fluid.p = std::vector<double>(N); - - try - { - // ADIOS manager object creation. MPI must be initialized - adios::ADIOS adios(true); - set_io_variables(adios, "solid"); - set_io_variables(adios, "fluid"); - - adios::Method &fileSettings = - adios.DeclareMethod("Reusable"); // default engine is BP writer - fileSettings.AddTransport("POSIX", "have_metadata_file=no"); - - // Open a file with a Method which has selected a group and a transport in - // the XML. - // "a" will append to an already existing file, "w" would create a new file - // Multiple writes to the same file work as append in this application run - // FIXME: how do we support Update to same step? - - auto solidfile = adios.Open("solid.bp", "w", fileSettings); - - // "solid" is a method but incidentally also a group - // Constructor only creates an object and what is needed there but does not - // open a stream/file - // It can be used to initialize a staging connection if not declared before - // FIXME: which argument can be post-poned into Open() instead of - // constructor? - // solidfile.Open("solid.bp"); - - // Open a file with a Method that has selected a group and an engine in the - // XML - // The transport method(s) are (must be) associated with the engines - // "a" will append to an already existing file, "w" would create a new file - // Multiple writes to the same file work as append in this application run - // FIXME: how do we support Update to same step? - auto fluidfile = adios.Open("fluid.bp", "w", fileSettings); - - auto checkpointFile = adios.Open("checkpoint.bp", "w", fileSettings); - - // int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); - // we do not open this here, but every time when needed in a function - - // Another output not associated with a single group, so that we can mix - // variables to it - // adios:handle vizstream = adios.Open( "stream.bp", comm, "w", "STAGING", - // "options to staging method"); - auto vizstream = adios.Open("stream.bp", "w", fileSettings); - - // This creates an empty group inside, and we can write all kinds of - // variables to it - - // Get Monitor info - std::ofstream logStream("info_nompi.log"); - adios.MonitorVariables(logStream); - - int checkPointSteps = 10; - - for (int it = 1; it <= 100; it++) + solid.NX = N; + solid.t = new double[N]; + solid.p = std::vector<double>(N); + + fluid.NX = N; + fluid.t = new double[N]; + fluid.p = std::vector<double>(N); + + try { - compute(it, solid, fluid); + // ADIOS manager object creation. MPI must be initialized + adios::ADIOS adios(true); + set_io_variables(adios, "solid"); + set_io_variables(adios, "fluid"); + + adios::Method &fileSettings = + adios.DeclareMethod("Reusable"); // default engine is BP writer + fileSettings.AddTransport("POSIX", "have_metadata_file=no"); + + // Open a file with a Method which has selected a group and a transport + // in + // the XML. + // "a" will append to an already existing file, "w" would create a new + // file + // Multiple writes to the same file work as append in this application + // run + // FIXME: how do we support Update to same step? + + auto solidfile = adios.Open("solid.bp", "w", fileSettings); + + // "solid" is a method but incidentally also a group + // Constructor only creates an object and what is needed there but does + // not + // open a stream/file + // It can be used to initialize a staging connection if not declared + // before + // FIXME: which argument can be post-poned into Open() instead of + // constructor? + // solidfile.Open("solid.bp"); + + // Open a file with a Method that has selected a group and an engine in + // the + // XML + // The transport method(s) are (must be) associated with the engines + // "a" will append to an already existing file, "w" would create a new + // file + // Multiple writes to the same file work as append in this application + // run + // FIXME: how do we support Update to same step? + auto fluidfile = adios.Open("fluid.bp", "w", fileSettings); + + auto checkpointFile = adios.Open("checkpoint.bp", "w", fileSettings); + + // int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); + // we do not open this here, but every time when needed in a function + + // Another output not associated with a single group, so that we can mix + // variables to it + // adios:handle vizstream = adios.Open( "stream.bp", comm, "w", + // "STAGING", + // "options to staging method"); + auto vizstream = adios.Open("stream.bp", "w", fileSettings); + + // This creates an empty group inside, and we can write all kinds of + // variables to it + + // Get Monitor info + std::ofstream logStream("info_nompi.log"); + adios.MonitorVariables(logStream); + + int checkPointSteps = 10; + + for (int it = 1; it <= 100; it++) + { + compute(it, solid, fluid); - write_data(solidfile, "solid", solid); - write_data(fluidfile, "fluid", fluid); + write_data(solidfile, "solid", solid); + write_data(fluidfile, "fluid", fluid); - if (it % checkPointSteps == 0) - { - write_checkpoint(checkpointFile, solid, fluid); + if (it % checkPointSteps == 0) + { + write_checkpoint(checkpointFile, solid, fluid); - { - std::cout << "New checkpoint step, current = " << checkPointSteps - << "\n"; - std::cin >> checkPointSteps; - } - } + { + std::cout + << "New checkpoint step, current = " << checkPointSteps + << "\n"; + std::cin >> checkPointSteps; + } + } - write_viz(vizstream, solid, fluid); + write_viz(vizstream, solid, fluid); - std::cout << "Timestep " << it << " written\n"; - } + std::cout << "Timestep " << it << " written\n"; + } - solidfile->Close(); - fluidfile->Close(); - vizstream->Close(); - checkpointFile->Close(); + solidfile->Close(); + fluidfile->Close(); + vizstream->Close(); + checkpointFile->Close(); - // need barrier before we destroy the ADIOS object here automatically ...no! - std::cout << "Finalize adios\n"; - } - catch (std::exception &e) // need to think carefully how to handle C++ - // exceptions with MPI to avoid deadlocking - { - std::cout << e.what() << "\n"; - } + // need barrier before we destroy the ADIOS object here automatically + // ...no! + std::cout << "Finalize adios\n"; + } + catch (std::exception &e) // need to think carefully how to handle C++ + // exceptions with MPI to avoid deadlocking + { + std::cout << e.what() << "\n"; + } - delete[] solid.t; - delete[] fluid.t; + delete[] solid.t; + delete[] fluid.t; - return 0; + return 0; } diff --git a/examples/xmlParser/xmlParser.cpp b/examples/xmlParser/xmlParser.cpp index 358f4467888e4b44e34f3b8290dd1c5fed9f0e4e..98624de22bb771c31a2b9a5de2b9a62fb17ace88 100644 --- a/examples/xmlParser/xmlParser.cpp +++ b/examples/xmlParser/xmlParser.cpp @@ -25,40 +25,40 @@ static void Usage(); int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Init(&argc, &argv); + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); - try - { - if (argc != 2) + try { - Usage(); + if (argc != 2) + { + Usage(); + } + else + { + const std::string xmlConfigFile(argv[1]); + adios::ADIOS adios(xmlConfigFile, MPI_COMM_WORLD, true); + adios.MonitorGroups(std::cout); + } } - else + catch (std::exception &e) { - const std::string xmlConfigFile(argv[1]); - adios::ADIOS adios(xmlConfigFile, MPI_COMM_WORLD, true); - adios.MonitorGroups(std::cout); + if (rank == 0) + { + std::cout << "ERROR: exception caught\n"; + std::cout << e.what() << "\n"; + } } - } - catch (std::exception &e) - { - if (rank == 0) - { - std::cout << "ERROR: exception caught\n"; - std::cout << e.what() << "\n"; - } - } - MPI_Finalize(); - return 0; + MPI_Finalize(); + return 0; } static void Usage() { - std::cout << "Program to test XML Config file parsing\n"; - std::cout << "Usage: \n"; - std::cout << "\t MPI version: ./xmlParser_mpi xmlConfigFile\n"; - std::cout << "\t Non-MPI version: ./xmlParser_nompi xmlConfigFile\n"; + std::cout << "Program to test XML Config file parsing\n"; + std::cout << "Usage: \n"; + std::cout << "\t MPI version: ./xmlParser_mpi xmlConfigFile\n"; + std::cout << "\t Non-MPI version: ./xmlParser_nompi xmlConfigFile\n"; } diff --git a/include/ADIOS.h b/include/ADIOS.h index 85bd4825950c9fceb4865a906c5bdd4cea3d48a5..be624488c96a3fb1c8baf00abf41dcbd2d0eecef 100644 --- a/include/ADIOS.h +++ b/include/ADIOS.h @@ -42,320 +42,333 @@ class Engine; class ADIOS { public: - MPI_Comm m_MPIComm = MPI_COMM_SELF; ///< only used as reference to MPI - /// communicator passed from parallel - /// constructor, MPI_Comm is a pointer - /// itself. Public as called from C - - int m_RankMPI = 0; ///< current MPI rank process - int m_SizeMPI = 1; ///< current MPI processes size - - std::string m_HostLanguage = "C++"; - - /** - * @brief ADIOS empty constructor. Used for non XML config file API calls. - */ - ADIOS(const Verbose verbose = Verbose::WARN, const bool debugMode = false); - - /** - * @brief Serial constructor for config file, only allowed and compiled in - * libadios_nompi.a - * @param config XML config file - * @param debugMode true: on throws exceptions and do additional checks, - * false: off (faster, but unsafe) - */ - ADIOS(std::string config, const Verbose verbose = Verbose::WARN, - const bool debugMode = false); - - /** - * @brief Parallel constructor for XML config file and MPI - * @param config XML config file - * @param mpiComm MPI communicator ...const to be discussed - * @param debugMode true: on, false: off (faster, but unsafe) - */ - - ADIOS(std::string config, MPI_Comm mpiComm, - const Verbose verbose = Verbose::WARN, const bool debugMode = false); - - /** - * @brief Parallel MPI communicator without XML config file - * @param mpiComm MPI communicator passed to m_MPIComm* - * @param debugMode true: on, false: off (faster) - */ - ADIOS(MPI_Comm mpiComm, const Verbose verbose = Verbose::WARN, - const bool debugMode = false); - - ~ADIOS() = default; - - void InitMPI(); ///< sets rank and size in m_rank and m_Size, respectively. - - /** - * Look for template specialization - * @param name - * @param dimensions - * @param globalDimensions - * @param globalOffsets - * @return - */ - template <class T> - inline Variable<T> &DefineVariable(const std::string &name, - const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), - const Dims globalOffsets = Dims()) - { - throw std::invalid_argument("ERROR: type not supported for variable " + - name + " in call to DefineVariable\n"); - } - - template <class T> inline Variable<T> &GetVariable(const std::string &name) - { - throw std::invalid_argument("ERROR: type not supported for variable " + - name + " in call to GetVariable\n"); - } - - template <class T> - VariableCompound &DefineVariableCompound(const std::string &name, - const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), - const Dims globalOffsets = Dims()) - { - CheckVariableInput(name, dimensions); - const unsigned int size = m_Compound.size(); - m_Compound.emplace(size, VariableCompound(name, sizeof(T), dimensions, - globalDimensions, globalOffsets, - m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<T>(), size)); - return m_Compound.at(size); - } - - VariableCompound &GetVariableCompound(const std::string &name); - - /** - * Declares a new method. If the method is defined in the user config file, - * it will be already created during processing the config file, - * the method is set up with the user settings and this function just returns - * that method. - * Otherwise it will create and return a new Method with default settings. - * Use method.isUserDefined() to distinguish between the two cases. - * @param methodName must be unique - */ - Method &DeclareMethod(const std::string &methodName); - - /** - * @brief Open to Write, Read. Creates a new engine from previously defined - * method - * @param streamName unique stream or file name - * @param accessMode "w" or "write", "r" or "read", "a" or "append", "u" or - * "update" - * @param mpiComm option to modify communicator from ADIOS class constructor - * @param method looks for corresponding Method object in ADIOS to initialize - * the engine - * @param iomode Independent or collective open/advance by writers/readers? - * Write() operations are always independent. - * @param timeout_sec Wait some time before reporting on missing stream (i.e. - * wait for it for a while) - * @return Derived class of base Engine depending on Method parameters, - * shared_ptr for potential flexibility - */ - std::shared_ptr<Engine> Open(const std::string &streamName, - const std::string &accessMode, MPI_Comm mpiComm, - const Method &method, - const IOMode iomode = IOMode::INDEPENDENT, - const float timeout_sec = 0.0); - - /** - * @brief Open to Write, Read. Creates a new engine from previously defined - * method. - * Reuses MPI communicator from ADIOS constructor. - * @param streamName unique stream or file name - * @param accessMode "w" or "write", "r" or "read", "a" or "append", "u" or - * "update" - * @param method contains engine parameters - * @param iomode Independent or collective open/advance by writers/readers? - * Write() operations are always independent. - * @param timeout_sec Wait some time before reporting on missing stream (i.e. - * wait for it for a while) - * @return Derived class of base Engine depending on Method parameters, - * shared_ptr for potential flexibility - */ - std::shared_ptr<Engine> Open(const std::string &streamName, - const std::string &accessMode, - const Method &method, - const IOMode iomode = IOMode::INDEPENDENT, - const float timeout_sec = 0.0); - - /** - * Version required by the XML config file implementation, searches method - * inside ADIOS through a unique name - * @param streamName unique stream or file name - * @param accessMode "w" or "write", "r" or "read", "a" or "append" - * @param mpiComm mpi Communicator - * @param methodName used to search method object inside ADIOS object - * @param iomode Independent or collective open/advance by writers/readers? - * Write() operations are always independent. - * @param timeout_sec Wait some time before reporting on missing stream (i.e. - * wait for it for a while) - * @return Derived class of base Engine depending on Method parameters, - * shared_ptr for potential flexibility - */ - std::shared_ptr<Engine> Open(const std::string &streamName, - const std::string &accessMode, MPI_Comm mpiComm, - const std::string &methodName, - const IOMode iomode = IOMode::INDEPENDENT, - const float timeout_sec = 0.0); - - /** - * Version required by the XML config file implementation, searches method - * inside ADIOS through a unique name. - * Reuses ADIOS MPI Communicator from constructor. - * @param streamName unique stream or file name - * @param accessMode "w" or "write", "r" or "read", "a" or "append" - * @param methodName used to search method object inside ADIOS object - * @param iomode Independent or collective open/advance by writers/readers? - * Write() operations are always independent. - * @param timeout_sec Wait some time before reporting on missing stream (i.e. - * wait for it for a while) - * @return Derived class of base Engine depending on Method parameters, - * shared_ptr for potential flexibility - */ - std::shared_ptr<Engine> Open(const std::string &streamName, - const std::string &accessMode, - const std::string &methodName, - const IOMode iomode = IOMode::INDEPENDENT, - const float timeout_sec = 0.0); - - /** - * @brief Open to Read all steps from a file. No streaming, advancing is - * possible here. All steps in the file - * are immediately available for reading. Creates a new engine from previously - * defined method. - * @param fileName file name - * @param mpiComm option to modify communicator from ADIOS class constructor - * @param method looks for corresponding Method object in ADIOS to initialize - * the engine - * @param iomode Independent or collective open/advance by writers/readers? - * Write() operations are always independent. - * @return Derived class of base Engine depending on Method parameters, - * shared_ptr for potential flexibility - */ - std::shared_ptr<Engine> - OpenFileReader(const std::string &fileName, MPI_Comm mpiComm, - const Method &method, - const IOMode iomode = IOMode::INDEPENDENT); - - /** - * @brief Open to Read all steps from a file. No streaming, advancing is - * possible here. All steps in the file - * are immediately available for reading. Creates a new engine from previously - * defined method. - * Version required by the XML config file implementation, searches method - * inside ADIOS through a unique name. - * @param fileName file name - * @param mpiComm option to modify communicator from ADIOS class constructor - * @param methodName used to search method object inside ADIOS object - * @param iomode Independent or collective open/advance by writers/readers? - * Write() operations are always independent. - * @return Derived class of base Engine depending on Method parameters, - * shared_ptr for potential flexibility - */ - std::shared_ptr<Engine> - OpenFileReader(const std::string &fileName, MPI_Comm mpiComm, - const std::string &methodName, - const IOMode iomode = IOMode::INDEPENDENT); - - /** - * @brief Dumps groups information to a file stream or standard output. - * Note that either the user closes this fileStream or it's closed at the end. - * @param logStream either std::cout standard output, or a std::ofstream file - */ - void MonitorVariables(std::ostream &logStream); + MPI_Comm m_MPIComm = MPI_COMM_SELF; ///< only used as reference to MPI + /// communicator passed from parallel + /// constructor, MPI_Comm is a pointer + /// itself. Public as called from C + + int m_RankMPI = 0; ///< current MPI rank process + int m_SizeMPI = 1; ///< current MPI processes size + + std::string m_HostLanguage = "C++"; + + /** + * @brief ADIOS empty constructor. Used for non XML config file API calls. + */ + ADIOS(const Verbose verbose = Verbose::WARN, const bool debugMode = false); + + /** + * @brief Serial constructor for config file, only allowed and compiled in + * libadios_nompi.a + * @param config XML config file + * @param debugMode true: on throws exceptions and do additional checks, + * false: off (faster, but unsafe) + */ + ADIOS(std::string config, const Verbose verbose = Verbose::WARN, + const bool debugMode = false); + + /** + * @brief Parallel constructor for XML config file and MPI + * @param config XML config file + * @param mpiComm MPI communicator ...const to be discussed + * @param debugMode true: on, false: off (faster, but unsafe) + */ + + ADIOS(std::string config, MPI_Comm mpiComm, + const Verbose verbose = Verbose::WARN, const bool debugMode = false); + + /** + * @brief Parallel MPI communicator without XML config file + * @param mpiComm MPI communicator passed to m_MPIComm* + * @param debugMode true: on, false: off (faster) + */ + ADIOS(MPI_Comm mpiComm, const Verbose verbose = Verbose::WARN, + const bool debugMode = false); + + ~ADIOS() = default; + + void InitMPI(); ///< sets rank and size in m_rank and m_Size, respectively. + + /** + * Look for template specialization + * @param name + * @param dimensions + * @param globalDimensions + * @param globalOffsets + * @return + */ + template <class T> + inline Variable<T> &DefineVariable(const std::string &name, + const Dims dimensions = Dims{1}, + const Dims globalDimensions = Dims(), + const Dims globalOffsets = Dims()) + { + throw std::invalid_argument("ERROR: type not supported for variable " + + name + " in call to DefineVariable\n"); + } + + template <class T> inline Variable<T> &GetVariable(const std::string &name) + { + throw std::invalid_argument("ERROR: type not supported for variable " + + name + " in call to GetVariable\n"); + } + + template <class T> + VariableCompound &DefineVariableCompound( + const std::string &name, const Dims dimensions = Dims{1}, + const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims()) + { + CheckVariableInput(name, dimensions); + const unsigned int size = m_Compound.size(); + m_Compound.emplace(size, VariableCompound(name, sizeof(T), dimensions, + globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<T>(), size)); + return m_Compound.at(size); + } + + VariableCompound &GetVariableCompound(const std::string &name); + + /** + * Declares a new method. If the method is defined in the user config file, + * it will be already created during processing the config file, + * the method is set up with the user settings and this function just + * returns + * that method. + * Otherwise it will create and return a new Method with default settings. + * Use method.isUserDefined() to distinguish between the two cases. + * @param methodName must be unique + */ + Method &DeclareMethod(const std::string &methodName); + + /** + * @brief Open to Write, Read. Creates a new engine from previously defined + * method + * @param streamName unique stream or file name + * @param accessMode "w" or "write", "r" or "read", "a" or "append", "u" or + * "update" + * @param mpiComm option to modify communicator from ADIOS class constructor + * @param method looks for corresponding Method object in ADIOS to + * initialize + * the engine + * @param iomode Independent or collective open/advance by writers/readers? + * Write() operations are always independent. + * @param timeout_sec Wait some time before reporting on missing stream + * (i.e. + * wait for it for a while) + * @return Derived class of base Engine depending on Method parameters, + * shared_ptr for potential flexibility + */ + std::shared_ptr<Engine> Open(const std::string &streamName, + const std::string &accessMode, + MPI_Comm mpiComm, const Method &method, + const IOMode iomode = IOMode::INDEPENDENT, + const float timeout_sec = 0.0); + + /** + * @brief Open to Write, Read. Creates a new engine from previously defined + * method. + * Reuses MPI communicator from ADIOS constructor. + * @param streamName unique stream or file name + * @param accessMode "w" or "write", "r" or "read", "a" or "append", "u" or + * "update" + * @param method contains engine parameters + * @param iomode Independent or collective open/advance by writers/readers? + * Write() operations are always independent. + * @param timeout_sec Wait some time before reporting on missing stream + * (i.e. + * wait for it for a while) + * @return Derived class of base Engine depending on Method parameters, + * shared_ptr for potential flexibility + */ + std::shared_ptr<Engine> Open(const std::string &streamName, + const std::string &accessMode, + const Method &method, + const IOMode iomode = IOMode::INDEPENDENT, + const float timeout_sec = 0.0); + + /** + * Version required by the XML config file implementation, searches method + * inside ADIOS through a unique name + * @param streamName unique stream or file name + * @param accessMode "w" or "write", "r" or "read", "a" or "append" + * @param mpiComm mpi Communicator + * @param methodName used to search method object inside ADIOS object + * @param iomode Independent or collective open/advance by writers/readers? + * Write() operations are always independent. + * @param timeout_sec Wait some time before reporting on missing stream + * (i.e. + * wait for it for a while) + * @return Derived class of base Engine depending on Method parameters, + * shared_ptr for potential flexibility + */ + std::shared_ptr<Engine> Open(const std::string &streamName, + const std::string &accessMode, + MPI_Comm mpiComm, + const std::string &methodName, + const IOMode iomode = IOMode::INDEPENDENT, + const float timeout_sec = 0.0); + + /** + * Version required by the XML config file implementation, searches method + * inside ADIOS through a unique name. + * Reuses ADIOS MPI Communicator from constructor. + * @param streamName unique stream or file name + * @param accessMode "w" or "write", "r" or "read", "a" or "append" + * @param methodName used to search method object inside ADIOS object + * @param iomode Independent or collective open/advance by writers/readers? + * Write() operations are always independent. + * @param timeout_sec Wait some time before reporting on missing stream + * (i.e. + * wait for it for a while) + * @return Derived class of base Engine depending on Method parameters, + * shared_ptr for potential flexibility + */ + std::shared_ptr<Engine> Open(const std::string &streamName, + const std::string &accessMode, + const std::string &methodName, + const IOMode iomode = IOMode::INDEPENDENT, + const float timeout_sec = 0.0); + + /** + * @brief Open to Read all steps from a file. No streaming, advancing is + * possible here. All steps in the file + * are immediately available for reading. Creates a new engine from + * previously + * defined method. + * @param fileName file name + * @param mpiComm option to modify communicator from ADIOS class constructor + * @param method looks for corresponding Method object in ADIOS to + * initialize + * the engine + * @param iomode Independent or collective open/advance by writers/readers? + * Write() operations are always independent. + * @return Derived class of base Engine depending on Method parameters, + * shared_ptr for potential flexibility + */ + std::shared_ptr<Engine> + OpenFileReader(const std::string &fileName, MPI_Comm mpiComm, + const Method &method, + const IOMode iomode = IOMode::INDEPENDENT); + + /** + * @brief Open to Read all steps from a file. No streaming, advancing is + * possible here. All steps in the file + * are immediately available for reading. Creates a new engine from + * previously + * defined method. + * Version required by the XML config file implementation, searches method + * inside ADIOS through a unique name. + * @param fileName file name + * @param mpiComm option to modify communicator from ADIOS class constructor + * @param methodName used to search method object inside ADIOS object + * @param iomode Independent or collective open/advance by writers/readers? + * Write() operations are always independent. + * @return Derived class of base Engine depending on Method parameters, + * shared_ptr for potential flexibility + */ + std::shared_ptr<Engine> + OpenFileReader(const std::string &fileName, MPI_Comm mpiComm, + const std::string &methodName, + const IOMode iomode = IOMode::INDEPENDENT); + + /** + * @brief Dumps groups information to a file stream or standard output. + * Note that either the user closes this fileStream or it's closed at the + * end. + * @param logStream either std::cout standard output, or a std::ofstream + * file + */ + void MonitorVariables(std::ostream &logStream); protected: // no const to allow default empty and copy constructors - std::map<unsigned int, Variable<char>> m_Char; - std::map<unsigned int, Variable<unsigned char>> m_UChar; - std::map<unsigned int, Variable<short>> m_Short; - std::map<unsigned int, Variable<unsigned short>> m_UShort; - std::map<unsigned int, Variable<int>> m_Int; - std::map<unsigned int, Variable<unsigned int>> m_UInt; - std::map<unsigned int, Variable<long int>> m_LInt; - std::map<unsigned int, Variable<unsigned long int>> m_ULInt; - std::map<unsigned int, Variable<long long int>> m_LLInt; - std::map<unsigned int, Variable<unsigned long long int>> m_ULLInt; - std::map<unsigned int, Variable<float>> m_Float; - std::map<unsigned int, Variable<double>> m_Double; - std::map<unsigned int, Variable<long double>> m_LDouble; - std::map<unsigned int, Variable<std::complex<float>>> m_CFloat; - std::map<unsigned int, Variable<std::complex<double>>> m_CDouble; - std::map<unsigned int, Variable<std::complex<long double>>> m_CLDouble; - std::map<unsigned int, VariableCompound> m_Compound; - - std::string m_ConfigFile; ///< XML File to be read containing configuration - /// information - bool m_DebugMode = false; ///< if true will do more checks, exceptions, - /// warnings, expect slower code - - // Variables - std::map<std::string, std::pair<std::string, unsigned int>> - m_Variables; ///< Makes variable name unique, key: variable name, value: - /// pair.first = type, pair.second = index in corresponding - /// vector of Variable - - std::vector<std::shared_ptr<Transform>> - m_Transforms; ///< transforms associated with ADIOS run - - /** - * @brief List of Methods (engine metadata) defined from either ADIOS XML - * configuration file or the DeclareMethod function. - * <pre> - * Key: std::string unique method name - * Value: Method class - * </pre> - */ - std::map<std::string, Method> m_Methods; - std::set<std::string> - m_EngineNames; ///< set used to check Engine name uniqueness in debug mode - - /** - * @brief Checks for group existence in m_Groups, if failed throws - * std::invalid_argument exception - * @param itGroup m_Groups iterator, usually from find function - * @param groupName unique name, passed for thrown exception only - * @param hint adds information to thrown exception - */ - void CheckVariableInput(const std::string &name, - const Dims &dimensions) const; - - /** - * Checks for variable name, if not found throws an invalid exception - * @param itVariable iterator pointing to the variable name in m_Variables - * @param name variable name - * @param hint message to be thrown for debugging purporses - */ - void CheckVariableName( - std::map<std::string, - std::pair<std::string, unsigned int>>::const_iterator itVariable, - const std::string &name, const std::string &hint) const; - - /** - * @brief Checks for method existence in m_Methods, if failed throws - * std::invalid_argument exception - * @param itMethod m_Methods iterator, usually from find function - * @param methodName unique name, passed for thrown exception only - * @param hint adds information to thrown exception - */ - void CheckMethod(std::map<std::string, Method>::const_iterator itMethod, - const std::string &methodName, - const std::string &hint) const; - - template <class T> unsigned int GetVariableIndex(const std::string &name) - { - auto itVariable = m_Variables.find(name); - CheckVariableName( - itVariable, name, - "in call to GetVariable<" + GetType<T>() + - ">, or call to GetVariableCompound if <T> = <compound>\n"); - return itVariable->second.second; - } + std::map<unsigned int, Variable<char>> m_Char; + std::map<unsigned int, Variable<unsigned char>> m_UChar; + std::map<unsigned int, Variable<short>> m_Short; + std::map<unsigned int, Variable<unsigned short>> m_UShort; + std::map<unsigned int, Variable<int>> m_Int; + std::map<unsigned int, Variable<unsigned int>> m_UInt; + std::map<unsigned int, Variable<long int>> m_LInt; + std::map<unsigned int, Variable<unsigned long int>> m_ULInt; + std::map<unsigned int, Variable<long long int>> m_LLInt; + std::map<unsigned int, Variable<unsigned long long int>> m_ULLInt; + std::map<unsigned int, Variable<float>> m_Float; + std::map<unsigned int, Variable<double>> m_Double; + std::map<unsigned int, Variable<long double>> m_LDouble; + std::map<unsigned int, Variable<std::complex<float>>> m_CFloat; + std::map<unsigned int, Variable<std::complex<double>>> m_CDouble; + std::map<unsigned int, Variable<std::complex<long double>>> m_CLDouble; + std::map<unsigned int, VariableCompound> m_Compound; + + std::string m_ConfigFile; ///< XML File to be read containing configuration + /// information + bool m_DebugMode = false; ///< if true will do more checks, exceptions, + /// warnings, expect slower code + + // Variables + std::map<std::string, std::pair<std::string, unsigned int>> + m_Variables; ///< Makes variable name unique, key: variable name, + /// value: + /// pair.first = type, pair.second = index in corresponding + /// vector of Variable + + std::vector<std::shared_ptr<Transform>> + m_Transforms; ///< transforms associated with ADIOS run + + /** + * @brief List of Methods (engine metadata) defined from either ADIOS XML + * configuration file or the DeclareMethod function. + * <pre> + * Key: std::string unique method name + * Value: Method class + * </pre> + */ + std::map<std::string, Method> m_Methods; + std::set<std::string> m_EngineNames; ///< set used to check Engine name + /// uniqueness in debug mode + + /** + * @brief Checks for group existence in m_Groups, if failed throws + * std::invalid_argument exception + * @param itGroup m_Groups iterator, usually from find function + * @param groupName unique name, passed for thrown exception only + * @param hint adds information to thrown exception + */ + void CheckVariableInput(const std::string &name, + const Dims &dimensions) const; + + /** + * Checks for variable name, if not found throws an invalid exception + * @param itVariable iterator pointing to the variable name in m_Variables + * @param name variable name + * @param hint message to be thrown for debugging purporses + */ + void CheckVariableName( + std::map<std::string, + std::pair<std::string, unsigned int>>::const_iterator + itVariable, + const std::string &name, const std::string &hint) const; + + /** + * @brief Checks for method existence in m_Methods, if failed throws + * std::invalid_argument exception + * @param itMethod m_Methods iterator, usually from find function + * @param methodName unique name, passed for thrown exception only + * @param hint adds information to thrown exception + */ + void CheckMethod(std::map<std::string, Method>::const_iterator itMethod, + const std::string &methodName, + const std::string &hint) const; + + template <class T> unsigned int GetVariableIndex(const std::string &name) + { + auto itVariable = m_Variables.find(name); + CheckVariableName(itVariable, name, + "in call to GetVariable<" + GetType<T>() + + ">, or call to GetVariableCompound if <T> = " + "<compound>\n"); + return itVariable->second.second; + } }; // template specializations of DefineVariable: @@ -364,12 +377,12 @@ inline Variable<char> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_Char.size(); - m_Char.emplace(size, Variable<char>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<char>(), size)); - return m_Char.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_Char.size(); + m_Char.emplace(size, Variable<char>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<char>(), size)); + return m_Char.at(size); } template <> @@ -377,13 +390,13 @@ inline Variable<unsigned char> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_UChar.size(); - m_UChar.emplace(size, - Variable<unsigned char>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<unsigned char>(), size)); - return m_UChar.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_UChar.size(); + m_UChar.emplace(size, + Variable<unsigned char>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<unsigned char>(), size)); + return m_UChar.at(size); } template <> @@ -391,12 +404,12 @@ inline Variable<short> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_Short.size(); - m_Short.emplace(size, Variable<short>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<unsigned char>(), size)); - return m_Short.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_Short.size(); + m_Short.emplace(size, Variable<short>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<unsigned char>(), size)); + return m_Short.at(size); } template <> @@ -404,13 +417,13 @@ inline Variable<unsigned short> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_UShort.size(); - m_UShort.emplace(size, - Variable<unsigned short>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<unsigned short>(), size)); - return m_UShort.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_UShort.size(); + m_UShort.emplace( + size, Variable<unsigned short>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<unsigned short>(), size)); + return m_UShort.at(size); } template <> @@ -418,12 +431,12 @@ inline Variable<int> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_Int.size(); - m_Int.emplace(size, Variable<int>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<int>(), size)); - return m_Int.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_Int.size(); + m_Int.emplace(size, Variable<int>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<int>(), size)); + return m_Int.at(size); } template <> @@ -431,13 +444,13 @@ inline Variable<unsigned int> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_UInt.size(); - m_UInt.emplace(size, - Variable<unsigned int>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<unsigned int>(), size)); - return m_UInt.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_UInt.size(); + m_UInt.emplace(size, + Variable<unsigned int>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<unsigned int>(), size)); + return m_UInt.at(size); } template <> @@ -445,12 +458,12 @@ inline Variable<long int> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_LInt.size(); - m_LInt.emplace(size, Variable<long int>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<long int>(), size)); - return m_LInt.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_LInt.size(); + m_LInt.emplace(size, Variable<long int>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<long int>(), size)); + return m_LInt.at(size); } template <> @@ -458,13 +471,14 @@ inline Variable<unsigned long int> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_LInt.size(); - m_ULInt.emplace( - size, Variable<unsigned long int>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<unsigned long int>(), size)); - return m_ULInt.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_LInt.size(); + m_ULInt.emplace( + size, Variable<unsigned long int>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, + std::make_pair(GetType<unsigned long int>(), size)); + return m_ULInt.at(size); } template <> @@ -472,13 +486,13 @@ inline Variable<long long int> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_LLInt.size(); - m_LLInt.emplace(size, - Variable<long long int>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<long long int>(), size)); - return m_LLInt.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_LLInt.size(); + m_LLInt.emplace(size, + Variable<long long int>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<long long int>(), size)); + return m_LLInt.at(size); } template <> @@ -486,14 +500,14 @@ inline Variable<unsigned long long int> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_ULLInt.size(); - m_ULLInt.emplace( - size, Variable<unsigned long long int>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, - std::make_pair(GetType<unsigned long long int>(), size)); - return m_ULLInt.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_ULLInt.size(); + m_ULLInt.emplace(size, Variable<unsigned long long int>( + name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace( + name, std::make_pair(GetType<unsigned long long int>(), size)); + return m_ULLInt.at(size); } template <> @@ -501,12 +515,12 @@ inline Variable<float> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_Float.size(); - m_Float.emplace(size, Variable<float>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<float>(), size)); - return m_Float.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_Float.size(); + m_Float.emplace(size, Variable<float>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<float>(), size)); + return m_Float.at(size); } template <> @@ -514,12 +528,12 @@ inline Variable<double> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_Double.size(); - m_Double.emplace(size, Variable<double>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<double>(), size)); - return m_Double.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_Double.size(); + m_Double.emplace(size, Variable<double>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<double>(), size)); + return m_Double.at(size); } template <> @@ -527,13 +541,13 @@ inline Variable<long double> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_LDouble.size(); - m_LDouble.emplace(size, - Variable<long double>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, std::make_pair(GetType<long double>(), size)); - return m_LDouble.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_LDouble.size(); + m_LDouble.emplace(size, + Variable<long double>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, std::make_pair(GetType<long double>(), size)); + return m_LDouble.at(size); } template <> @@ -541,14 +555,14 @@ inline Variable<std::complex<float>> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_CFloat.size(); - m_CFloat.emplace( - size, Variable<std::complex<float>>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, - std::make_pair(GetType<std::complex<float>>(), size)); - return m_CFloat.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_CFloat.size(); + m_CFloat.emplace( + size, Variable<std::complex<float>>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, + std::make_pair(GetType<std::complex<float>>(), size)); + return m_CFloat.at(size); } template <> @@ -556,14 +570,14 @@ inline Variable<std::complex<double>> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_CDouble.size(); - m_CDouble.emplace( - size, Variable<std::complex<double>>(name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace(name, - std::make_pair(GetType<std::complex<double>>(), size)); - return m_CDouble.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_CDouble.size(); + m_CDouble.emplace( + size, Variable<std::complex<double>>(name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace(name, + std::make_pair(GetType<std::complex<double>>(), size)); + return m_CDouble.at(size); } template <> @@ -571,110 +585,110 @@ inline Variable<std::complex<long double>> & ADIOS::DefineVariable(const std::string &name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets) { - CheckVariableInput(name, dimensions); - const unsigned int size = m_CLDouble.size(); - m_CLDouble.emplace(size, Variable<std::complex<long double>>( - name, dimensions, globalDimensions, - globalOffsets, m_DebugMode)); - m_Variables.emplace( - name, std::make_pair(GetType<std::complex<long double>>(), size)); - return m_CLDouble.at(size); + CheckVariableInput(name, dimensions); + const unsigned int size = m_CLDouble.size(); + m_CLDouble.emplace(size, Variable<std::complex<long double>>( + name, dimensions, globalDimensions, + globalOffsets, m_DebugMode)); + m_Variables.emplace( + name, std::make_pair(GetType<std::complex<long double>>(), size)); + return m_CLDouble.at(size); } // Get template specialization template <> inline Variable<char> &ADIOS::GetVariable(const std::string &name) { - return m_Char.at(GetVariableIndex<char>(name)); + return m_Char.at(GetVariableIndex<char>(name)); } template <> inline Variable<unsigned char> &ADIOS::GetVariable(const std::string &name) { - return m_UChar.at(GetVariableIndex<unsigned char>(name)); + return m_UChar.at(GetVariableIndex<unsigned char>(name)); } template <> inline Variable<short> &ADIOS::GetVariable(const std::string &name) { - return m_Short.at(GetVariableIndex<short>(name)); + return m_Short.at(GetVariableIndex<short>(name)); } template <> inline Variable<unsigned short> &ADIOS::GetVariable(const std::string &name) { - return m_UShort.at(GetVariableIndex<unsigned short>(name)); + return m_UShort.at(GetVariableIndex<unsigned short>(name)); } template <> inline Variable<int> &ADIOS::GetVariable(const std::string &name) { - return m_Int.at(GetVariableIndex<int>(name)); + return m_Int.at(GetVariableIndex<int>(name)); } template <> inline Variable<unsigned int> &ADIOS::GetVariable(const std::string &name) { - return m_UInt.at(GetVariableIndex<unsigned int>(name)); + return m_UInt.at(GetVariableIndex<unsigned int>(name)); } template <> inline Variable<long int> &ADIOS::GetVariable(const std::string &name) { - return m_LInt.at(GetVariableIndex<unsigned int>(name)); + return m_LInt.at(GetVariableIndex<unsigned int>(name)); } template <> inline Variable<unsigned long int> &ADIOS::GetVariable(const std::string &name) { - return m_ULInt.at(GetVariableIndex<unsigned long int>(name)); + return m_ULInt.at(GetVariableIndex<unsigned long int>(name)); } template <> inline Variable<long long int> &ADIOS::GetVariable(const std::string &name) { - return m_LLInt.at(GetVariableIndex<long long int>(name)); + return m_LLInt.at(GetVariableIndex<long long int>(name)); } template <> inline Variable<unsigned long long int> & ADIOS::GetVariable(const std::string &name) { - return m_ULLInt.at(GetVariableIndex<unsigned long long int>(name)); + return m_ULLInt.at(GetVariableIndex<unsigned long long int>(name)); } template <> inline Variable<float> &ADIOS::GetVariable(const std::string &name) { - return m_Float.at(GetVariableIndex<float>(name)); + return m_Float.at(GetVariableIndex<float>(name)); } template <> inline Variable<double> &ADIOS::GetVariable(const std::string &name) { - return m_Double.at(GetVariableIndex<double>(name)); + return m_Double.at(GetVariableIndex<double>(name)); } template <> inline Variable<long double> &ADIOS::GetVariable(const std::string &name) { - return m_LDouble.at(GetVariableIndex<long double>(name)); + return m_LDouble.at(GetVariableIndex<long double>(name)); } template <> inline Variable<std::complex<float>> & ADIOS::GetVariable(const std::string &name) { - return m_CFloat.at(GetVariableIndex<std::complex<float>>(name)); + return m_CFloat.at(GetVariableIndex<std::complex<float>>(name)); } template <> inline Variable<std::complex<double>> & ADIOS::GetVariable(const std::string &name) { - return m_CDouble.at(GetVariableIndex<std::complex<double>>(name)); + return m_CDouble.at(GetVariableIndex<std::complex<double>>(name)); } template <> inline Variable<std::complex<long double>> & ADIOS::GetVariable(const std::string &name) { - return m_CLDouble.at(GetVariableIndex<std::complex<long double>>(name)); + return m_CLDouble.at(GetVariableIndex<std::complex<long double>>(name)); } } // end namespace diff --git a/include/ADIOSTypes.h b/include/ADIOSTypes.h index 3949bbc36f98f935a5069b38ea95c567a99d00f5..a3e286d943cff87ecacae3dea7cfb58c636be47f 100644 --- a/include/ADIOSTypes.h +++ b/include/ADIOSTypes.h @@ -18,23 +18,23 @@ namespace adios */ enum { - VARYING_DIMENSION = -1, //!< VARYING_DIMENSION - LOCAL_VALUE = 0, //!< LOCAL_VALUE - GLOBAL_VALUE = 1 //!< GLOBAL_VALUE + VARYING_DIMENSION = -1, //!< VARYING_DIMENSION + LOCAL_VALUE = 0, //!< LOCAL_VALUE + GLOBAL_VALUE = 1 //!< GLOBAL_VALUE }; enum class Verbose { - ERROR = 0, - WARN = 1, - INFO = 2, - DEBUG = 3 + ERROR = 0, + WARN = 1, + INFO = 2, + DEBUG = 3 }; enum class IOMode { - INDEPENDENT = 0, - COLLECTIVE = 1 + INDEPENDENT = 0, + COLLECTIVE = 1 }; } // end namespace diff --git a/include/capsule/heap/STLVector.h b/include/capsule/heap/STLVector.h index b548a64d640a3072d55b9d923174df62fc845eb7..35adb47188b1739a3c0fc114b16a009bbb67f65b 100644 --- a/include/capsule/heap/STLVector.h +++ b/include/capsule/heap/STLVector.h @@ -29,29 +29,30 @@ class STLVector : public Capsule { public: - std::vector<char> m_Data; ///< data buffer allocated using the STL in heap - /// memory, default size = 16 Mb - std::vector<char> m_Metadata; ///< metadata buffer allocated using the STL in - /// heap memory, default size = 100 Kb - - /** - * Unique constructor - * @param accessMode read, write or append - * @param rankMPI MPI rank - * @param debugMode true: extra checks, slower - */ - STLVector(std::string accessMode, int rankMPI, bool debugMode = false); - - ~STLVector() = default; - - char *GetData(); - char *GetMetadata(); - - std::size_t GetDataSize() const; - std::size_t GetMetadataSize() const; - - void ResizeData(const std::size_t size); - void ResizeMetadata(const std::size_t size); + std::vector<char> m_Data; ///< data buffer allocated using the STL in heap + /// memory, default size = 16 Mb + std::vector<char> + m_Metadata; ///< metadata buffer allocated using the STL in + /// heap memory, default size = 100 Kb + + /** + * Unique constructor + * @param accessMode read, write or append + * @param rankMPI MPI rank + * @param debugMode true: extra checks, slower + */ + STLVector(std::string accessMode, int rankMPI, bool debugMode = false); + + ~STLVector() = default; + + char *GetData(); + char *GetMetadata(); + + std::size_t GetDataSize() const; + std::size_t GetMetadataSize() const; + + void ResizeData(const std::size_t size); + void ResizeMetadata(const std::size_t size); }; } // end namespace capsule diff --git a/include/capsule/shmem/ShmSystemV.h b/include/capsule/shmem/ShmSystemV.h index 4c7c5cab4ed15eb9420f0274e6a46daa4f452a2d..2e3a14c5b804736b5c2f8d4d5890bc49efde2eba 100644 --- a/include/capsule/shmem/ShmSystemV.h +++ b/include/capsule/shmem/ShmSystemV.h @@ -18,42 +18,44 @@ class ShmSystemV : public Capsule { public: - /** - * Create a Capsule in shared memory using System V shm API - * @param accessMode - * @param pathName used to create the key as a unique identifier - * @param dataSize size of allocated memory segment for data - * @param metadataSize size of allocated memory segment for metadata - * @param debugMode true: extra checks, slower - */ - ShmSystemV(std::string accessMode, int rankMPI, const std::string &pathName, - size_t dataSize, size_t metadataSize, bool debugMode = false); + /** + * Create a Capsule in shared memory using System V shm API + * @param accessMode + * @param pathName used to create the key as a unique identifier + * @param dataSize size of allocated memory segment for data + * @param metadataSize size of allocated memory segment for metadata + * @param debugMode true: extra checks, slower + */ + ShmSystemV(std::string accessMode, int rankMPI, const std::string &pathName, + size_t dataSize, size_t metadataSize, bool debugMode = false); - ~ShmSystemV() = default; + ~ShmSystemV() = default; - char *GetData(); ///< return the pointer to the raw data buffer - char *GetMetadata(); ///< return the pointer to the raw metadata buffer + char *GetData(); ///< return the pointer to the raw data buffer + char *GetMetadata(); ///< return the pointer to the raw metadata buffer - size_t GetDataSize() const; ///< get current data buffer size - size_t GetMetadataSize() const; ///< get current metadata buffer size + size_t GetDataSize() const; ///< get current data buffer size + size_t GetMetadataSize() const; ///< get current metadata buffer size private: - char *m_Data = - nullptr; ///< reference to a shared memory data buffer created with shmget - const size_t m_DataSize; ///< size of the allocated shared memory segment - key_t m_DataKey; ///< key associated with the data buffer, created with ftok - int m_DataShmID; ///< data shared memory buffer id - - char *m_Metadata = nullptr; ///< reference to a shared memory metadata buffer - /// created with shmget - const size_t m_MetadataSize; ///< size of the allocated shared memory segment - key_t m_MetadataKey; ///< key associated with the metadata buffer, created - /// with ftok - int m_MetadataShmID; ///< metadata shared memory buffer id - - void CheckShm() const; ///< checks if all shared memory allocations are - /// correct, throws std::bad_alloc, called from - /// constructor if debug mode is true + char *m_Data = nullptr; ///< reference to a shared memory data buffer + /// created with shmget + const size_t m_DataSize; ///< size of the allocated shared memory segment + key_t m_DataKey; ///< key associated with the data buffer, created with ftok + int m_DataShmID; ///< data shared memory buffer id + + char *m_Metadata = + nullptr; ///< reference to a shared memory metadata buffer + /// created with shmget + const size_t + m_MetadataSize; ///< size of the allocated shared memory segment + key_t m_MetadataKey; ///< key associated with the metadata buffer, created + /// with ftok + int m_MetadataShmID; ///< metadata shared memory buffer id + + void CheckShm() const; ///< checks if all shared memory allocations are + /// correct, throws std::bad_alloc, called from + /// constructor if debug mode is true }; } // end namespace adios diff --git a/include/core/Attribute.h b/include/core/Attribute.h index dae2644b77d155d16c52c64aff5cf90f6c301f7f..d1384d228ff5019a9ad6fcadf7ee76ff736e3595 100644 --- a/include/core/Attribute.h +++ b/include/core/Attribute.h @@ -23,8 +23,8 @@ namespace adios */ struct Attribute { - const char TypeID; ///< '0': string, '1': numeric - const std::string Value; ///< information about the attribute + const char TypeID; ///< '0': string, '1': numeric + const std::string Value; ///< information about the attribute }; } // end namespace diff --git a/include/core/Capsule.h b/include/core/Capsule.h index 815c8542363f614be1c61e4023b7a9d8ffa779af..8993025f50dd2cc513ba6b868b42cde3ec06f490 100644 --- a/include/core/Capsule.h +++ b/include/core/Capsule.h @@ -27,42 +27,42 @@ class Capsule { public: - const std::string m_Type; ///< buffer type - const std::string m_AccessMode; ///< 'w': write, 'r': read, 'a': append + const std::string m_Type; ///< buffer type + const std::string m_AccessMode; ///< 'w': write, 'r': read, 'a': append - size_t m_DataPosition = 0; ///< position in current data buffer (not - /// included data flushed to transports) - size_t m_DataAbsolutePosition = - 0; ///< includes the data flushed to transports + size_t m_DataPosition = 0; ///< position in current data buffer (not + /// included data flushed to transports) + size_t m_DataAbsolutePosition = + 0; ///< includes the data flushed to transports - size_t m_MetadataPosition = 0; ///< position in metadata buffer + size_t m_MetadataPosition = 0; ///< position in metadata buffer - /** - * Base class constructor providing type from derived class and accessMode - * @param type derived class type - * @param accessMode 'w':write, 'r':read, 'a':append - * @param rankMPI current MPI rank - * @param debugMode - */ - Capsule(std::string type, std::string accessMode, int rankMPI, - bool debugMode); + /** + * Base class constructor providing type from derived class and accessMode + * @param type derived class type + * @param accessMode 'w':write, 'r':read, 'a':append + * @param rankMPI current MPI rank + * @param debugMode + */ + Capsule(std::string type, std::string accessMode, int rankMPI, + bool debugMode); - virtual ~Capsule() = default; + virtual ~Capsule() = default; - virtual char *GetData() = 0; ///< return the pointer to the raw data buffer - virtual char * - GetMetadata() = 0; ///< return the pointer to the raw metadata buffer + virtual char *GetData() = 0; ///< return the pointer to the raw data buffer + virtual char * + GetMetadata() = 0; ///< return the pointer to the raw metadata buffer - virtual size_t GetDataSize() const = 0; ///< get current data buffer size - virtual size_t - GetMetadataSize() const = 0; ///< get current metadata buffer size + virtual size_t GetDataSize() const = 0; ///< get current data buffer size + virtual size_t + GetMetadataSize() const = 0; ///< get current metadata buffer size - virtual void ResizeData(size_t size); ///< resize data buffer - virtual void ResizeMetadata(size_t size); ///< resize metadata buffer + virtual void ResizeData(size_t size); ///< resize data buffer + virtual void ResizeMetadata(size_t size); ///< resize metadata buffer protected: - const int m_RankMPI = 0; ///< current MPI rank - const bool m_DebugMode = false; ///< true: extra checks + const int m_RankMPI = 0; ///< current MPI rank + const bool m_DebugMode = false; ///< true: extra checks }; } // end namespace diff --git a/include/core/Engine.h b/include/core/Engine.h index d536873c72dd08bbcd7e9307713159a73f956d4d..a206682e8f4961af7d4cc663e4efd1f2782bf23e 100644 --- a/include/core/Engine.h +++ b/include/core/Engine.h @@ -38,10 +38,10 @@ namespace adios typedef enum { NONBLOCKINGREAD = 0, BLOCKINGREAD = 1 } PerformReadMode; typedef enum { - APPEND = 0, - UPDATE = 1, // writer advance modes - NEXT_AVAILABLE = 2, - LATEST_AVAILABLE = 3, // reader advance modes + APPEND = 0, + UPDATE = 1, // writer advance modes + NEXT_AVAILABLE = 2, + LATEST_AVAILABLE = 3, // reader advance modes } AdvanceMode; /** @@ -52,450 +52,465 @@ class Engine { public: - MPI_Comm m_MPIComm = MPI_COMM_SELF; - - const std::string m_EngineType; ///< from derived class - const std::string m_Name; ///< name used for this engine - const std::string - m_AccessMode; ///< accessMode for buffers used by this engine - const Method &m_Method; ///< associated method containing engine metadata - - int m_RankMPI = 0; ///< current MPI rank process - int m_SizeMPI = 1; ///< current MPI processes size - - const std::string m_HostLanguage = "C++"; ///< default host language - - /** - * Unique constructor - * @param adios - * @param engineType - * @param name - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - * @param nthreads - * @param endMessage - */ - Engine(ADIOS &adios, std::string engineType, std::string name, - std::string accessMode, MPI_Comm mpiComm, const Method &method, - bool debugMode, unsigned int nthreads, std::string endMessage); - - virtual ~Engine() = default; - - /** @brief Let ADIOS allocate memory for a variable, which can be used by the - * user. - * - * To decrease the cost of copying memory, a user may let ADIOS allocate the - * memory for a user-variable, - * according to the definition of an ADIOS-variable. The memory will be part - * of the ADIOS buffer used - * by the engine and it lives until the engine (file, stream) is closed. - * A variable that has been allocated this way (cannot have its local - * dimensions changed, and AdvanceAsync() should be - * used instead of Advance() and the user-variable must not be modified by the - * application until the notification arrives. - * This is required so that any reader can access the written data before the - * application overwrites it. - * @param var Variable with defined local dimensions and offsets in global - * space - * @param fillValue Fill the allocated array with this value - * @return A constant pointer to the non-constant allocated array. User should - * not deallocate this pointer. - */ - template <class T> - inline T *const AllocateVariable(Variable<T> &var, T fillValue = 0) - { - throw std::invalid_argument("ERROR: type not supported for variable " + - var->name + " in call to GetVariable\n"); - } - - /** - * Needed for DataMan Engine - * @param callback function passed from the user - */ - virtual void SetCallBack(std::function<void(const void *, std::string, - std::string, std::string, Dims)> - callback); - - /** - * Write function that adds static checking on the variable to be passed by - * values - * It then calls its corresponding derived class virtual function - * This version uses m_Group to look for the variableName. - * @param variable name of variable to the written - * @param values pointer passed from the application - */ - template <class T> void Write(Variable<T> &variable, const T *values) - { - Write(variable, values); - } - - /** - * String version - * @param variableName - * @param values - */ - template <class T> - void Write(const std::string &variableName, const T *values) - { - Write(variableName, values); - } - - /** - * Single value version - * @param variable - * @param values - */ - template <class T> void Write(Variable<T> &variable, const T values) - { - const T val = values; - Write(variable, &val); - } - - /** - * Single value version using string as variable handlers, allows rvalues to - * be passed - * @param variableName - * @param values - */ - template <class T> void Write(const std::string &variableName, const T values) - { - const T val = values; - Write(variableName, &val); - } - - virtual void Write(Variable<char> &variable, const char *values); - virtual void Write(Variable<unsigned char> &variable, - const unsigned char *values); - virtual void Write(Variable<short> &variable, const short *values); - virtual void Write(Variable<unsigned short> &variable, - const unsigned short *values); - virtual void Write(Variable<int> &variable, const int *values); - virtual void Write(Variable<unsigned int> &variable, - const unsigned int *values); - virtual void Write(Variable<long int> &variable, const long int *values); - virtual void Write(Variable<unsigned long int> &variable, - const unsigned long int *values); - virtual void Write(Variable<long long int> &variable, - const long long int *values); - virtual void Write(Variable<unsigned long long int> &variable, - const unsigned long long int *values); - virtual void Write(Variable<float> &variable, const float *values); - virtual void Write(Variable<double> &variable, const double *values); - virtual void Write(Variable<long double> &variable, - const long double *values); - virtual void Write(Variable<std::complex<float>> &variable, - const std::complex<float> *values); - virtual void Write(Variable<std::complex<double>> &variable, - const std::complex<double> *values); - virtual void Write(Variable<std::complex<long double>> &variable, - const std::complex<long double> *values); - virtual void Write(VariableCompound &variable, const void *values); - - /** - * @brief Write functions can be overridden by derived classes. Base class - * behavior is to: - * 1) Write to Variable values (m_Values) using the pointer to default group - * *m_Group set with SetDefaultGroup function - * 2) Transform the data - * 3) Write to all capsules -> data and metadata - * @param variableName - * @param values coming from user app - */ - virtual void Write(const std::string &variableName, const char *values); - virtual void Write(const std::string &variableName, - const unsigned char *values); - virtual void Write(const std::string &variableName, const short *values); - virtual void Write(const std::string &variableName, - const unsigned short *values); - virtual void Write(const std::string &variableName, const int *values); - virtual void Write(const std::string &variableName, - const unsigned int *values); - virtual void Write(const std::string &variableName, const long int *values); - virtual void Write(const std::string &variableName, - const unsigned long int *values); - virtual void Write(const std::string &variableName, - const long long int *values); - virtual void Write(const std::string &variableName, - const unsigned long long int *values); - virtual void Write(const std::string &variableName, const float *values); - virtual void Write(const std::string &variableName, const double *values); - virtual void Write(const std::string &variableName, - const long double *values); - virtual void Write(const std::string &variableName, - const std::complex<float> *values); - virtual void Write(const std::string &variableName, - const std::complex<double> *values); - virtual void Write(const std::string &variableName, - const std::complex<long double> *values); - virtual void Write(const std::string &variableName, const void *values); - - /** - * Read function that adds static checking on the variable to be passed by - * values - * It then calls its corresponding derived class virtual function - * This version uses m_Group to look for the variableName. - * @param variable name of variable to the written - * @param values pointer passed from the application, nullptr not allowed, - * must use Read(variable) instead intentionally - */ - template <class T> void Read(Variable<T> &variable, const T *values) - { - Read(variable, values); - } - - /** - * String version - * @param variableName - * @param values - */ - template <class T> void Read(const std::string variableName, const T *values) - { - Read(variableName, values); - } - - /** - * Single value version - * @param variable - * @param values - */ - template <class T> void Read(Variable<T> &variable, const T &values) - { - Read(variable, &values); - } - - /** - * Single value version using string as variable handlers - * @param variableName - * @param values - */ - template <class T> void Read(const std::string variableName, const T &values) - { - Read(variableName, &values); - } - - /** - * Unallocated version, ADIOS will allocate space for incoming data - * @param variable - */ - template <class T> void Read(Variable<T> &variable) - { - Read(variable, nullptr); - } - - /** - * Unallocated version, ADIOS will allocate space for incoming data - * @param variableName - */ - template <class T> void Read(const std::string variableName) - { - Read(variableName, nullptr); - } - - virtual void Read(Variable<double> &variable, const double *values); - - /** - * Read function that adds static checking on the variable to be passed by - * values - * It then calls its corresponding derived class virtual function - * This version uses m_Group to look for the variableName. - * @param variable name of variable to the written - * @param values pointer passed from the application - */ - template <class T> void ScheduleRead(Variable<T> &variable, const T *values) - { - ScheduleRead(variable, values); - } - - /** - * String version - * @param variableName - * @param values - */ - template <class T> - void ScheduleRead(const std::string variableName, const T *values) - { - ScheduleRead(variableName, values); - } - - /** - * Single value version - * @param variable - * @param values - */ - template <class T> void ScheduleRead(Variable<T> &variable, const T &values) - { - ScheduleRead(variable, &values); - } - - /** - * Single value version using string as variable handlers - * @param variableName - * @param values - */ - template <class T> - void ScheduleRead(const std::string variableName, const T &values) - { - ScheduleRead(variableName, &values); - } - - /** - * Unallocated version, ADIOS will allocate space for incoming data - * @param variableName - */ - void ScheduleRead(const std::string variableName) - { - ScheduleRead(variableName, nullptr); - } - - /** - * Unallocated unspecified version, ADIOS will receive any variable and will - * allocate space for incoming data - */ - void ScheduleRead() { ScheduleRead(nullptr, nullptr); } - - virtual void ScheduleRead(Variable<double> &variable, const double *values); - - /** - * Perform all scheduled reads, either blocking until all reads completed, or - * return immediately. - * @param mode Blocking or non-blocking modes - */ - void PerformReads(PerformReadMode mode); - - /** - * Reader application indicates that no more data will be read from the - * current stream before advancing. - * This is necessary to allow writers to advance as soon as possible. - */ - virtual void Release(); - - /** - * Indicates that a new step is going to be written as new variables come in. - */ - virtual void Advance(float timeout_sec = 0.0); - - /** - * Indicates that a new step is going to be written as new variables come in. - * @param mode Advance mode, there are different options for writers and - * readers - */ - virtual void Advance(AdvanceMode mode, float timeout_sec = 0.0); - - /** @brief Advance asynchronously and get a callback when readers release - * access to the buffered step. - * - * User variables that were allocated through AllocateVariable() - * must not be modified until advance is completed. - * @param mode Advance mode, there are different options for writers and - * readers - * @param callback Will be called when advance is completed. - */ - virtual void - AdvanceAsync(AdvanceMode mode, - std::function<void(std::shared_ptr<adios::Engine>)> callback); - - // Read API - /** - * Inquires and (optionally) allocates and copies the contents of a variable - * If success: it returns a pointer to the internal stored variable object in - * ADIOS class. - * If failure: it returns nullptr - * @param name variable name to look for - * @param readIn if true: reads the full variable and payload, allocating - * values in memory, if false: internal payload is nullptr - * @return success: it returns a pointer to the internal stored variable - * object in ADIOS class, failure: nullptr - */ - virtual Variable<void> *InquireVariable(const std::string name, - const bool readIn = true); - virtual Variable<char> *InquireVariableChar(const std::string name, - const bool readIn = true); - virtual Variable<unsigned char> * - InquireVariableUChar(const std::string name, const bool readIn = true); - virtual Variable<short> *InquireVariableShort(const std::string name, - const bool readIn = true); - virtual Variable<unsigned short> * - InquireVariableUShort(const std::string name, const bool readIn = true); - virtual Variable<int> *InquireVariableInt(const std::string name, + MPI_Comm m_MPIComm = MPI_COMM_SELF; + + const std::string m_EngineType; ///< from derived class + const std::string m_Name; ///< name used for this engine + const std::string + m_AccessMode; ///< accessMode for buffers used by this engine + const Method &m_Method; ///< associated method containing engine metadata + + int m_RankMPI = 0; ///< current MPI rank process + int m_SizeMPI = 1; ///< current MPI processes size + + const std::string m_HostLanguage = "C++"; ///< default host language + + /** + * Unique constructor + * @param adios + * @param engineType + * @param name + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + * @param nthreads + * @param endMessage + */ + Engine(ADIOS &adios, std::string engineType, std::string name, + std::string accessMode, MPI_Comm mpiComm, const Method &method, + bool debugMode, unsigned int nthreads, std::string endMessage); + + virtual ~Engine() = default; + + /** @brief Let ADIOS allocate memory for a variable, which can be used by + * the + * user. + * + * To decrease the cost of copying memory, a user may let ADIOS allocate the + * memory for a user-variable, + * according to the definition of an ADIOS-variable. The memory will be part + * of the ADIOS buffer used + * by the engine and it lives until the engine (file, stream) is closed. + * A variable that has been allocated this way (cannot have its local + * dimensions changed, and AdvanceAsync() should be + * used instead of Advance() and the user-variable must not be modified by + * the + * application until the notification arrives. + * This is required so that any reader can access the written data before + * the + * application overwrites it. + * @param var Variable with defined local dimensions and offsets in global + * space + * @param fillValue Fill the allocated array with this value + * @return A constant pointer to the non-constant allocated array. User + * should + * not deallocate this pointer. + */ + template <class T> + inline T *const AllocateVariable(Variable<T> &var, T fillValue = 0) + { + throw std::invalid_argument("ERROR: type not supported for variable " + + var->name + " in call to GetVariable\n"); + } + + /** + * Needed for DataMan Engine + * @param callback function passed from the user + */ + virtual void SetCallBack(std::function<void(const void *, std::string, + std::string, std::string, Dims)> + callback); + + /** + * Write function that adds static checking on the variable to be passed by + * values + * It then calls its corresponding derived class virtual function + * This version uses m_Group to look for the variableName. + * @param variable name of variable to the written + * @param values pointer passed from the application + */ + template <class T> void Write(Variable<T> &variable, const T *values) + { + Write(variable, values); + } + + /** + * String version + * @param variableName + * @param values + */ + template <class T> + void Write(const std::string &variableName, const T *values) + { + Write(variableName, values); + } + + /** + * Single value version + * @param variable + * @param values + */ + template <class T> void Write(Variable<T> &variable, const T values) + { + const T val = values; + Write(variable, &val); + } + + /** + * Single value version using string as variable handlers, allows rvalues to + * be passed + * @param variableName + * @param values + */ + template <class T> + void Write(const std::string &variableName, const T values) + { + const T val = values; + Write(variableName, &val); + } + + virtual void Write(Variable<char> &variable, const char *values); + virtual void Write(Variable<unsigned char> &variable, + const unsigned char *values); + virtual void Write(Variable<short> &variable, const short *values); + virtual void Write(Variable<unsigned short> &variable, + const unsigned short *values); + virtual void Write(Variable<int> &variable, const int *values); + virtual void Write(Variable<unsigned int> &variable, + const unsigned int *values); + virtual void Write(Variable<long int> &variable, const long int *values); + virtual void Write(Variable<unsigned long int> &variable, + const unsigned long int *values); + virtual void Write(Variable<long long int> &variable, + const long long int *values); + virtual void Write(Variable<unsigned long long int> &variable, + const unsigned long long int *values); + virtual void Write(Variable<float> &variable, const float *values); + virtual void Write(Variable<double> &variable, const double *values); + virtual void Write(Variable<long double> &variable, + const long double *values); + virtual void Write(Variable<std::complex<float>> &variable, + const std::complex<float> *values); + virtual void Write(Variable<std::complex<double>> &variable, + const std::complex<double> *values); + virtual void Write(Variable<std::complex<long double>> &variable, + const std::complex<long double> *values); + virtual void Write(VariableCompound &variable, const void *values); + + /** + * @brief Write functions can be overridden by derived classes. Base class + * behavior is to: + * 1) Write to Variable values (m_Values) using the pointer to default group + * *m_Group set with SetDefaultGroup function + * 2) Transform the data + * 3) Write to all capsules -> data and metadata + * @param variableName + * @param values coming from user app + */ + virtual void Write(const std::string &variableName, const char *values); + virtual void Write(const std::string &variableName, + const unsigned char *values); + virtual void Write(const std::string &variableName, const short *values); + virtual void Write(const std::string &variableName, + const unsigned short *values); + virtual void Write(const std::string &variableName, const int *values); + virtual void Write(const std::string &variableName, + const unsigned int *values); + virtual void Write(const std::string &variableName, const long int *values); + virtual void Write(const std::string &variableName, + const unsigned long int *values); + virtual void Write(const std::string &variableName, + const long long int *values); + virtual void Write(const std::string &variableName, + const unsigned long long int *values); + virtual void Write(const std::string &variableName, const float *values); + virtual void Write(const std::string &variableName, const double *values); + virtual void Write(const std::string &variableName, + const long double *values); + virtual void Write(const std::string &variableName, + const std::complex<float> *values); + virtual void Write(const std::string &variableName, + const std::complex<double> *values); + virtual void Write(const std::string &variableName, + const std::complex<long double> *values); + virtual void Write(const std::string &variableName, const void *values); + + /** + * Read function that adds static checking on the variable to be passed by + * values + * It then calls its corresponding derived class virtual function + * This version uses m_Group to look for the variableName. + * @param variable name of variable to the written + * @param values pointer passed from the application, nullptr not allowed, + * must use Read(variable) instead intentionally + */ + template <class T> void Read(Variable<T> &variable, const T *values) + { + Read(variable, values); + } + + /** + * String version + * @param variableName + * @param values + */ + template <class T> + void Read(const std::string variableName, const T *values) + { + Read(variableName, values); + } + + /** + * Single value version + * @param variable + * @param values + */ + template <class T> void Read(Variable<T> &variable, const T &values) + { + Read(variable, &values); + } + + /** + * Single value version using string as variable handlers + * @param variableName + * @param values + */ + template <class T> + void Read(const std::string variableName, const T &values) + { + Read(variableName, &values); + } + + /** + * Unallocated version, ADIOS will allocate space for incoming data + * @param variable + */ + template <class T> void Read(Variable<T> &variable) + { + Read(variable, nullptr); + } + + /** + * Unallocated version, ADIOS will allocate space for incoming data + * @param variableName + */ + template <class T> void Read(const std::string variableName) + { + Read(variableName, nullptr); + } + + virtual void Read(Variable<double> &variable, const double *values); + + /** + * Read function that adds static checking on the variable to be passed by + * values + * It then calls its corresponding derived class virtual function + * This version uses m_Group to look for the variableName. + * @param variable name of variable to the written + * @param values pointer passed from the application + */ + template <class T> void ScheduleRead(Variable<T> &variable, const T *values) + { + ScheduleRead(variable, values); + } + + /** + * String version + * @param variableName + * @param values + */ + template <class T> + void ScheduleRead(const std::string variableName, const T *values) + { + ScheduleRead(variableName, values); + } + + /** + * Single value version + * @param variable + * @param values + */ + template <class T> void ScheduleRead(Variable<T> &variable, const T &values) + { + ScheduleRead(variable, &values); + } + + /** + * Single value version using string as variable handlers + * @param variableName + * @param values + */ + template <class T> + void ScheduleRead(const std::string variableName, const T &values) + { + ScheduleRead(variableName, &values); + } + + /** + * Unallocated version, ADIOS will allocate space for incoming data + * @param variableName + */ + void ScheduleRead(const std::string variableName) + { + ScheduleRead(variableName, nullptr); + } + + /** + * Unallocated unspecified version, ADIOS will receive any variable and will + * allocate space for incoming data + */ + void ScheduleRead() { ScheduleRead(nullptr, nullptr); } + + virtual void ScheduleRead(Variable<double> &variable, const double *values); + + /** + * Perform all scheduled reads, either blocking until all reads completed, + * or + * return immediately. + * @param mode Blocking or non-blocking modes + */ + void PerformReads(PerformReadMode mode); + + /** + * Reader application indicates that no more data will be read from the + * current stream before advancing. + * This is necessary to allow writers to advance as soon as possible. + */ + virtual void Release(); + + /** + * Indicates that a new step is going to be written as new variables come + * in. + */ + virtual void Advance(float timeout_sec = 0.0); + + /** + * Indicates that a new step is going to be written as new variables come + * in. + * @param mode Advance mode, there are different options for writers and + * readers + */ + virtual void Advance(AdvanceMode mode, float timeout_sec = 0.0); + + /** @brief Advance asynchronously and get a callback when readers release + * access to the buffered step. + * + * User variables that were allocated through AllocateVariable() + * must not be modified until advance is completed. + * @param mode Advance mode, there are different options for writers and + * readers + * @param callback Will be called when advance is completed. + */ + virtual void + AdvanceAsync(AdvanceMode mode, + std::function<void(std::shared_ptr<adios::Engine>)> callback); + + // Read API + /** + * Inquires and (optionally) allocates and copies the contents of a variable + * If success: it returns a pointer to the internal stored variable object + * in + * ADIOS class. + * If failure: it returns nullptr + * @param name variable name to look for + * @param readIn if true: reads the full variable and payload, allocating + * values in memory, if false: internal payload is nullptr + * @return success: it returns a pointer to the internal stored variable + * object in ADIOS class, failure: nullptr + */ + virtual Variable<void> *InquireVariable(const std::string name, const bool readIn = true); - virtual Variable<unsigned int> *InquireVariableUInt(const std::string name, - const bool readIn = true); - virtual Variable<long int> *InquireVariableLInt(const std::string name, - const bool readIn = true); - virtual Variable<unsigned long int> * - InquireVariableULInt(const std::string name, const bool readIn = true); - virtual Variable<long long int> * - InquireVariableLLInt(const std::string name, const bool readIn = true); - virtual Variable<unsigned long long int> * - InquireVariableULLInt(const std::string name, const bool readIn = true); - virtual Variable<float> *InquireVariableFloat(const std::string name, + virtual Variable<char> *InquireVariableChar(const std::string name, const bool readIn = true); - virtual Variable<double> *InquireVariableDouble(const std::string name, + virtual Variable<unsigned char> * + InquireVariableUChar(const std::string name, const bool readIn = true); + virtual Variable<short> *InquireVariableShort(const std::string name, const bool readIn = true); - virtual Variable<long double> * - InquireVariableLDouble(const std::string name, const bool readIn = true); - virtual Variable<std::complex<float>> * - InquireVariableCFloat(const std::string name, const bool readIn = true); - virtual Variable<std::complex<double>> * - InquireVariableCDouble(const std::string name, const bool readIn = true); - virtual Variable<std::complex<long double>> * - InquireVariableCLDouble(const std::string name, const bool readIn = true); - virtual VariableCompound *InquireVariableCompound(const std::string name, + virtual Variable<unsigned short> * + InquireVariableUShort(const std::string name, const bool readIn = true); + virtual Variable<int> *InquireVariableInt(const std::string name, + const bool readIn = true); + virtual Variable<unsigned int> * + InquireVariableUInt(const std::string name, const bool readIn = true); + virtual Variable<long int> *InquireVariableLInt(const std::string name, + const bool readIn = true); + virtual Variable<unsigned long int> * + InquireVariableULInt(const std::string name, const bool readIn = true); + virtual Variable<long long int> * + InquireVariableLLInt(const std::string name, const bool readIn = true); + virtual Variable<unsigned long long int> * + InquireVariableULLInt(const std::string name, const bool readIn = true); + virtual Variable<float> *InquireVariableFloat(const std::string name, + const bool readIn = true); + virtual Variable<double> *InquireVariableDouble(const std::string name, const bool readIn = true); + virtual Variable<long double> * + InquireVariableLDouble(const std::string name, const bool readIn = true); + virtual Variable<std::complex<float>> * + InquireVariableCFloat(const std::string name, const bool readIn = true); + virtual Variable<std::complex<double>> * + InquireVariableCDouble(const std::string name, const bool readIn = true); + virtual Variable<std::complex<long double>> * + InquireVariableCLDouble(const std::string name, const bool readIn = true); + virtual VariableCompound *InquireVariableCompound(const std::string name, + const bool readIn = true); - /** Return the names of all variables present in a stream/file opened for - * reading - * - * @return a vector of strings - */ - std::vector<std::string> VariableNames(); + /** Return the names of all variables present in a stream/file opened for + * reading + * + * @return a vector of strings + */ + std::vector<std::string> VariableNames(); - virtual void - Close(const int transportIndex = - -1) = 0; ///< Closes a particular transport, or all if -1 + virtual void + Close(const int transportIndex = + -1) = 0; ///< Closes a particular transport, or all if -1 protected: - ADIOS - &m_ADIOS; ///< reference to ADIOS object that creates this Engine at Open - std::vector<std::shared_ptr<Transport>> m_Transports; ///< transports managed - const bool m_DebugMode = - false; ///< true: additional checks, false: by-pass checks - unsigned int m_nThreads = 0; - const std::string m_EndMessage; ///< added to exceptions to improve debugging - std::set<std::string> m_WrittenVariables; ///< contains the names of the - /// variables that are being written - - virtual void - Init(); ///< Initialize m_Capsules and m_Transports, called from constructor - virtual void InitParameters(); ///< Initialize parameters from Method, called - /// from Initi in constructor - virtual void InitTransports(); ///< Initialize transports from Method, called - /// from Init in constructor - - /** - * Used to verify parameters in m_Method containers - * @param itParam iterator to a certain parameter - * @param parameters map of parameters, from m_Method - * @param parameterName used if exception is thrown to provide debugging - * information - * @param hint used if exception is thrown to provide debugging information - */ - void CheckParameter( - const std::map<std::string, std::string>::const_iterator itParam, - const std::map<std::string, std::string> ¶meters, - const std::string parameterName, const std::string hint) const; - - bool TransportNamesUniqueness() const; ///< checks if transport names are - /// unique among the same types (file - /// I/O) - - /** - * Throws an exception in debug mode if transport index is out of range. - * @param transportIndex must be in the range [ -1 , m_Transports.size()-1 ] - */ - void CheckTransportIndex(const int transportIndex); + ADIOS + &m_ADIOS; ///< reference to ADIOS object that creates this Engine at Open + std::vector<std::shared_ptr<Transport>> + m_Transports; ///< transports managed + const bool m_DebugMode = + false; ///< true: additional checks, false: by-pass checks + unsigned int m_nThreads = 0; + const std::string + m_EndMessage; ///< added to exceptions to improve debugging + std::set<std::string> m_WrittenVariables; ///< contains the names of the + /// variables that are being written + + virtual void + Init(); ///< Initialize m_Capsules and m_Transports, called from constructor + virtual void + InitParameters(); ///< Initialize parameters from Method, called + /// from Initi in constructor + virtual void + InitTransports(); ///< Initialize transports from Method, called + /// from Init in constructor + + /** + * Used to verify parameters in m_Method containers + * @param itParam iterator to a certain parameter + * @param parameters map of parameters, from m_Method + * @param parameterName used if exception is thrown to provide debugging + * information + * @param hint used if exception is thrown to provide debugging information + */ + void CheckParameter( + const std::map<std::string, std::string>::const_iterator itParam, + const std::map<std::string, std::string> ¶meters, + const std::string parameterName, const std::string hint) const; + + bool TransportNamesUniqueness() const; ///< checks if transport names are + /// unique among the same types (file + /// I/O) + + /** + * Throws an exception in debug mode if transport index is out of range. + * @param transportIndex must be in the range [ -1 , m_Transports.size()-1 ] + */ + void CheckTransportIndex(const int transportIndex); }; } // end namespace diff --git a/include/core/Method.h b/include/core/Method.h index f213022eb7ee26dab41c5ac9bad4e548dd77a4f0..0576703b6999fed3eea947642f614297c9d8771c 100644 --- a/include/core/Method.h +++ b/include/core/Method.h @@ -24,15 +24,15 @@ namespace adios { typedef enum { - GLOBAL_READERS = 2, - ROUNDROBIN_READERS = 3, - FIFO_READERS = 4, - OPEN_ALL_STEPS = 5 + GLOBAL_READERS = 2, + ROUNDROBIN_READERS = 3, + FIFO_READERS = 4, + OPEN_ALL_STEPS = 5 } ReadMultiplexPattern; typedef enum { - NOWAITFORSTREAM = 0, - WAITFORSTREAM = 1 + NOWAITFORSTREAM = 0, + WAITFORSTREAM = 1 } StreamOpenMode; // default: wait for stream /** @@ -42,97 +42,99 @@ class Method { public: - const std::string m_Name; ///< Method name (as defined in XML) - const bool m_DebugMode = false; ///< true: on, throws exceptions and do - /// additional checks, false: off, faster, but - /// unsafe - int m_nThreads; - std::string m_Type; ///< Method's engine type - std::map<std::string, std::string> m_Parameters; ///< method parameters - std::vector<std::map<std::string, std::string>> - m_TransportParameters; ///< each is a separate Transport containing their - /// own parameters - - /** - * Constructor - * @param name is a label that can be used in the config file to set up the - * method at runtime - */ - Method(std::string name, bool debugMode = false); - - ~Method() = default; - - /** Check if the method was defined by the user in the config file. - * @return true if the method was user-defined, false otherwise when method is - * set with default parameters - */ - bool isUserDefined(); - - /** - * Define the engine type - * @param type must be a valid engine type - */ - void SetEngine(const std::string type); - - /** - * Set how many threads the engine can use for its operations (e.g. file io, - * compression, staging). - * If 1 is allowed, no extra threads will be created during the ADIOS calls - * for asynchronous operations. - * Note that some transports may require and use extra thread(s). See their - * documentation for their - * requirements. E.g. some staging transports always create an extra thread - * for communication. - * Set this parameter like you set it for OpenMP, i.e. count one thread for - * the main process that calls - * ADIOS functions. - * @param number of threads, minimum 1 is required - */ - void AllowThreads(const int nThreads); - - /** - * Sets parameters for the method in "parameter=value" format - * @param args list of parameters with format "parameter1=value1", ..., - * "parameterN=valueN" - */ - template <class... Args> void SetParameters(Args... args) - { - std::vector<std::string> parameters = {args...}; - m_Parameters = BuildParametersMap(parameters, m_DebugMode); - } - - /** - * Adds a transport and its parameters for the method - * @param type must be a supported transport type under /include/transport - * @param args list of parameters for a transport with format - * "parameter1=value1", ..., "parameterN=valueN" - */ - template <class... Args> - void AddTransport(const std::string type, Args... args) - { - std::vector<std::string> parameters = {args...}; - AddTransportParameters(type, parameters); - } - - void SetReadMultiplexPattern( - const ReadMultiplexPattern - pattern); // How to split stream content among readers - void SetStreamOpenMode(const StreamOpenMode mode); // In Read mode, should - // Open() wait for the - // first step appear - // (default) - - void SetVerbose(const Verbose verbose = Verbose::WARN) - { - m_Verbose = verbose; - }; - Verbose GetVerbose() { return m_Verbose; }; + const std::string m_Name; ///< Method name (as defined in XML) + const bool m_DebugMode = false; ///< true: on, throws exceptions and do + /// additional checks, false: off, faster, but + /// unsafe + int m_nThreads; + std::string m_Type; ///< Method's engine type + std::map<std::string, std::string> m_Parameters; ///< method parameters + std::vector<std::map<std::string, std::string>> + m_TransportParameters; ///< each is a separate Transport containing + /// their + /// own parameters + + /** + * Constructor + * @param name is a label that can be used in the config file to set up the + * method at runtime + */ + Method(std::string name, bool debugMode = false); + + ~Method() = default; + + /** Check if the method was defined by the user in the config file. + * @return true if the method was user-defined, false otherwise when method + * is + * set with default parameters + */ + bool isUserDefined(); + + /** + * Define the engine type + * @param type must be a valid engine type + */ + void SetEngine(const std::string type); + + /** + * Set how many threads the engine can use for its operations (e.g. file io, + * compression, staging). + * If 1 is allowed, no extra threads will be created during the ADIOS calls + * for asynchronous operations. + * Note that some transports may require and use extra thread(s). See their + * documentation for their + * requirements. E.g. some staging transports always create an extra thread + * for communication. + * Set this parameter like you set it for OpenMP, i.e. count one thread for + * the main process that calls + * ADIOS functions. + * @param number of threads, minimum 1 is required + */ + void AllowThreads(const int nThreads); + + /** + * Sets parameters for the method in "parameter=value" format + * @param args list of parameters with format "parameter1=value1", ..., + * "parameterN=valueN" + */ + template <class... Args> void SetParameters(Args... args) + { + std::vector<std::string> parameters = {args...}; + m_Parameters = BuildParametersMap(parameters, m_DebugMode); + } + + /** + * Adds a transport and its parameters for the method + * @param type must be a supported transport type under /include/transport + * @param args list of parameters for a transport with format + * "parameter1=value1", ..., "parameterN=valueN" + */ + template <class... Args> + void AddTransport(const std::string type, Args... args) + { + std::vector<std::string> parameters = {args...}; + AddTransportParameters(type, parameters); + } + + void SetReadMultiplexPattern( + const ReadMultiplexPattern + pattern); // How to split stream content among readers + void SetStreamOpenMode(const StreamOpenMode mode); // In Read mode, should + // Open() wait for the + // first step appear + // (default) + + void SetVerbose(const Verbose verbose = Verbose::WARN) + { + m_Verbose = verbose; + }; + Verbose GetVerbose() { return m_Verbose; }; private: - Verbose m_Verbose = Verbose::WARN; + Verbose m_Verbose = Verbose::WARN; - void AddTransportParameters(const std::string type, - const std::vector<std::string> ¶meters); + void AddTransportParameters(const std::string type, + const std::vector<std::string> ¶meters); }; } // end namespace adios diff --git a/include/core/Profiler.h b/include/core/Profiler.h index eee51ebee869b402a6d2071a8b1a613e9367755c..7d804665bcc121ce355f200e4de0fc35460df5df 100644 --- a/include/core/Profiler.h +++ b/include/core/Profiler.h @@ -22,76 +22,76 @@ class Timer { public: - const std::string Process; - unsigned long long int ProcessTime = 0; - - Timer(const std::string process, const Support::Resolutions resolution) - : Process{process}, Resolution{resolution} - { - } - - void SetInitialTime() - { - InitialTime = std::chrono::high_resolution_clock::now(); - } - - void SetTime() - { - ElapsedTime = std::chrono::high_resolution_clock::now(); - ProcessTime += GetTime(); - } - - long long int GetTime() - { - if (Resolution == Support::Resolutions::mus) - return std::chrono::duration_cast<std::chrono::microseconds>(ElapsedTime - - InitialTime) - .count(); - - else if (Resolution == Support::Resolutions::ms) - return std::chrono::duration_cast<std::chrono::milliseconds>(ElapsedTime - - InitialTime) - .count(); - - else if (Resolution == Support::Resolutions::s) - return std::chrono::duration_cast<std::chrono::seconds>(ElapsedTime - - InitialTime) - .count(); - - else if (Resolution == Support::Resolutions::m) - return std::chrono::duration_cast<std::chrono::minutes>(ElapsedTime - - InitialTime) - .count(); - - else if (Resolution == Support::Resolutions::h) - return std::chrono::duration_cast<std::chrono::hours>(ElapsedTime - - InitialTime) - .count(); - - return -1; // failure - } - - std::string GetUnits() const - { - std::string units; - if (Resolution == Support::Resolutions::mus) - units = "mus"; - else if (Resolution == Support::Resolutions::ms) - units = "ms"; - else if (Resolution == Support::Resolutions::s) - units = "s"; - else if (Resolution == Support::Resolutions::m) - units = "m"; - else if (Resolution == Support::Resolutions::h) - units = "h"; - return units; - } + const std::string Process; + unsigned long long int ProcessTime = 0; + + Timer(const std::string process, const Support::Resolutions resolution) + : Process{process}, Resolution{resolution} + { + } + + void SetInitialTime() + { + InitialTime = std::chrono::high_resolution_clock::now(); + } + + void SetTime() + { + ElapsedTime = std::chrono::high_resolution_clock::now(); + ProcessTime += GetTime(); + } + + long long int GetTime() + { + if (Resolution == Support::Resolutions::mus) + return std::chrono::duration_cast<std::chrono::microseconds>( + ElapsedTime - InitialTime) + .count(); + + else if (Resolution == Support::Resolutions::ms) + return std::chrono::duration_cast<std::chrono::milliseconds>( + ElapsedTime - InitialTime) + .count(); + + else if (Resolution == Support::Resolutions::s) + return std::chrono::duration_cast<std::chrono::seconds>( + ElapsedTime - InitialTime) + .count(); + + else if (Resolution == Support::Resolutions::m) + return std::chrono::duration_cast<std::chrono::minutes>( + ElapsedTime - InitialTime) + .count(); + + else if (Resolution == Support::Resolutions::h) + return std::chrono::duration_cast<std::chrono::hours>(ElapsedTime - + InitialTime) + .count(); + + return -1; // failure + } + + std::string GetUnits() const + { + std::string units; + if (Resolution == Support::Resolutions::mus) + units = "mus"; + else if (Resolution == Support::Resolutions::ms) + units = "ms"; + else if (Resolution == Support::Resolutions::s) + units = "s"; + else if (Resolution == Support::Resolutions::m) + units = "m"; + else if (Resolution == Support::Resolutions::h) + units = "h"; + return units; + } private: - const Support::Resolutions Resolution; - std::chrono::time_point<std::chrono::high_resolution_clock> InitialTime; - std::chrono::time_point<std::chrono::high_resolution_clock> ElapsedTime; - bool InitialTimeSet = false; + const Support::Resolutions Resolution; + std::chrono::time_point<std::chrono::high_resolution_clock> InitialTime; + std::chrono::time_point<std::chrono::high_resolution_clock> ElapsedTime; + bool InitialTimeSet = false; }; /** @@ -99,9 +99,9 @@ private: */ struct Profiler { - std::vector<Timer> m_Timers; - std::vector<unsigned long long int> m_TotalBytes; - bool m_IsActive = false; + std::vector<Timer> m_Timers; + std::vector<unsigned long long int> m_TotalBytes; + bool m_IsActive = false; }; } // end namespace diff --git a/include/core/Support.h b/include/core/Support.h index bb9b451e842f07afbe38d9d3b36da864594e0c65..a36476660fb7bf34603aab6d907957ebdf606e32 100644 --- a/include/core/Support.h +++ b/include/core/Support.h @@ -23,32 +23,34 @@ namespace adios struct Support { - static const std::string Version; ///< current ADIOS version - static const std::set<std::string> - HostLanguages; ///< supported languages: C, C++, Fortran, Python, Java - static const std::set<std::string> Numbers; - static const std::set<std::string> - Transports; ///< supported transport methods - static const std::set<std::string> - Transforms; ///< supported data transform methods - static const std::map<std::string, std::set<std::string>> - Datatypes; ///< supported data types, key: host language, value: all - /// supported types - static const std::map<std::string, std::set<std::string>> - DatatypesAliases; ///< all supported int aliases, key: C++ type (e.g. - /// int), value: aliases to type in key (e.g. int, - /// integer) - - static const std::set<std::string> FileTransports; ///< file I/O transports - - enum class Resolutions - { - mus, - ms, - s, - m, - h - }; + static const std::string Version; ///< current ADIOS version + static const std::set<std::string> HostLanguages; ///< supported languages: + /// C, C++, Fortran, + /// Python, Java + static const std::set<std::string> Numbers; + static const std::set<std::string> + Transports; ///< supported transport methods + static const std::set<std::string> + Transforms; ///< supported data transform methods + static const std::map<std::string, std::set<std::string>> + Datatypes; ///< supported data types, key: host language, value: all + /// supported types + static const std::map<std::string, std::set<std::string>> + DatatypesAliases; ///< all supported int aliases, key: C++ type + ///(e.g. + /// int), value: aliases to type in key (e.g. int, + /// integer) + + static const std::set<std::string> FileTransports; ///< file I/O transports + + enum class Resolutions + { + mus, + ms, + s, + m, + h + }; }; } // end namespace adios diff --git a/include/core/Transform.h b/include/core/Transform.h index a6a6dc75ab80f232f8f08e724837d6b83655b7e2..c133c146d7a9fc6be8fc944f38270bd66c9b393b 100644 --- a/include/core/Transform.h +++ b/include/core/Transform.h @@ -27,21 +27,21 @@ class Transform { public: - const std::string m_Method; + const std::string m_Method; - /** - * Initialize parent method - * @param method zlib, bzip2, szip - */ - Transform(std::string method); + /** + * Initialize parent method + * @param method zlib, bzip2, szip + */ + Transform(std::string method); - virtual ~Transform() = default; + virtual ~Transform() = default; - virtual void Compress(const std::vector<char> &bufferIn, - std::vector<char> &bufferOut); - - virtual void Decompress(const std::vector<char> &bufferIn, + virtual void Compress(const std::vector<char> &bufferIn, std::vector<char> &bufferOut); + + virtual void Decompress(const std::vector<char> &bufferIn, + std::vector<char> &bufferOut); }; } // end namespace adios diff --git a/include/core/Transport.h b/include/core/Transport.h index 0851a9b745462907db42bfd843fa224fd2471c4a..798a0db145aff5aecb9e05f0a4ab8c52149a5963 100644 --- a/include/core/Transport.h +++ b/include/core/Transport.h @@ -27,59 +27,62 @@ class Transport { public: - const std::string m_Type; ///< transport type from derived class - std::string m_Name; ///< from Open - std::string m_AccessMode; ///< from Open - bool m_IsOpen = false; - - MPI_Comm m_MPIComm = MPI_COMM_SELF; - - int m_RankMPI = 0; ///< current MPI rank process - int m_SizeMPI = 1; ///< current MPI processes size - Profiler m_Profiler; ///< collects information about Open and bytes Transport - - /** - * Base constructor that all derived classes pass - * @param - * @param mpiComm passed to m_MPIComm - * @param debugMode passed to m_DebugMode - */ - Transport(std::string type, MPI_Comm mpiComm, bool debugMode); - - virtual ~Transport() = default; - - /** - * Open Output file accesing a mode - * @param name name of stream or file - * @param accessMode r or read, w or write, a or append - */ - virtual void Open(const std::string name, const std::string accessMode) = 0; - - /** - * Set buffer and size for a particular transport - * @param buffer raw data buffer - * @param size raw data buffer size - */ - virtual void SetBuffer(char *buffer, std::size_t size); - - /** - * Write function for a transport - * @param buffer pointer to buffer to be written - * @param size size of buffer to be written - */ - virtual void Write(const char *buffer, std::size_t size) = 0; - - virtual void Flush(); ///< flushes current contents to physical medium without - /// closing the transport - - virtual void Close(); ///< closes current transport and flushes everything, - /// transport becomes unreachable - - virtual void InitProfiler(const std::string accessMode, - const Support::Resolutions resolution); + const std::string m_Type; ///< transport type from derived class + std::string m_Name; ///< from Open + std::string m_AccessMode; ///< from Open + bool m_IsOpen = false; + + MPI_Comm m_MPIComm = MPI_COMM_SELF; + + int m_RankMPI = 0; ///< current MPI rank process + int m_SizeMPI = 1; ///< current MPI processes size + Profiler + m_Profiler; ///< collects information about Open and bytes Transport + + /** + * Base constructor that all derived classes pass + * @param + * @param mpiComm passed to m_MPIComm + * @param debugMode passed to m_DebugMode + */ + Transport(std::string type, MPI_Comm mpiComm, bool debugMode); + + virtual ~Transport() = default; + + /** + * Open Output file accesing a mode + * @param name name of stream or file + * @param accessMode r or read, w or write, a or append + */ + virtual void Open(const std::string name, const std::string accessMode) = 0; + + /** + * Set buffer and size for a particular transport + * @param buffer raw data buffer + * @param size raw data buffer size + */ + virtual void SetBuffer(char *buffer, std::size_t size); + + /** + * Write function for a transport + * @param buffer pointer to buffer to be written + * @param size size of buffer to be written + */ + virtual void Write(const char *buffer, std::size_t size) = 0; + + virtual void + Flush(); ///< flushes current contents to physical medium without + /// closing the transport + + virtual void Close(); ///< closes current transport and flushes everything, + /// transport becomes unreachable + + virtual void InitProfiler(const std::string accessMode, + const Support::Resolutions resolution); protected: - const bool m_DebugMode = false; ///< if true: additional checks and exceptions + const bool m_DebugMode = + false; ///< if true: additional checks and exceptions }; } // end namespace adios diff --git a/include/core/Variable.h b/include/core/Variable.h index 110ae7064cad92d899913204f9677e2781b9afee..93acbfc9fe94a05bef0ecc607efad4272fc50f58 100644 --- a/include/core/Variable.h +++ b/include/core/Variable.h @@ -26,10 +26,10 @@ namespace adios struct TransformData { - Transform &Operation; ///< pointer to transform object - std::map<std::string, std::string> Parameters; ///< transforms parameters - std::vector<std::size_t> - Size; ///< vector that carries the sizes after a transformation is applied + Transform &Operation; ///< pointer to transform object + std::map<std::string, std::string> Parameters; ///< transforms parameters + std::vector<std::size_t> Size; ///< vector that carries the sizes after a + /// transformation is applied }; /** @@ -40,77 +40,79 @@ template <class T> class Variable : public VariableBase { public: - const T *m_AppValues = nullptr; ///< pointer to values passed from user in - /// ADIOS Write, it might change in ADIOS Read - - std::vector<TransformData> m_Transforms; ///< associated transforms, sequence - /// determines application order, e.g. - /// first Transforms[0] then - /// Transforms[1]. Pointer used as - /// reference (no memory management). - - Variable<T>(const std::string name, const Dims dimensions, - const Dims globalDimensions, const Dims globalOffsets, - const bool debugMode) - : VariableBase(name, GetType<T>(), sizeof(T), dimensions, globalDimensions, - globalOffsets, debugMode) - { - if (m_Dimensions == Dims{1}) - m_IsScalar = true; - } - - template <class... Args> void AddTransform(Transform &transform, Args... args) - { - std::vector<std::string> parameters = {args...}; - m_Transforms.emplace_back( - transform, - BuildParametersMap(parameters, m_DebugMode)); // need to check - } - - /** Return the global dimensions of the variable - * @return vector of std::size_t values - */ - std::vector<std::size_t> GetGlobalDimensions(); - - /** Return the number of steps available for the variable - * @return Number of steps - */ - int GetSteps(); - - void Monitor(std::ostream &logInfo) const noexcept - { - logInfo << "Variable: " << m_Name << "\n"; - logInfo << "Type: " << m_Type << "\n"; - logInfo << "Size: " << TotalSize() << " elements\n"; - logInfo << "Payload: " << PayLoadSize() << " bytes\n"; - - if (m_AppValues != nullptr) + const T *m_AppValues = nullptr; ///< pointer to values passed from user in + /// ADIOS Write, it might change in ADIOS Read + + std::vector<TransformData> + m_Transforms; ///< associated transforms, sequence + /// determines application order, e.g. + /// first Transforms[0] then + /// Transforms[1]. Pointer used as + /// reference (no memory management). + + Variable<T>(const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets, + const bool debugMode) + : VariableBase(name, GetType<T>(), sizeof(T), dimensions, globalDimensions, + globalOffsets, debugMode) { - logInfo << "Values (first 10 or max_size): \n"; - std::size_t size = TotalSize(); - if (size > 10) - size = 10; - - if (m_Type.find("complex") != m_Type.npos) // it's complex - { - for (unsigned int i = 0; i < size; ++i) - { - logInfo << "( " << std::real(m_AppValues[i]) << " , " - << std::imag(m_AppValues[i]) << " ) "; - } - } - else - { - for (unsigned int i = 0; i < size; ++i) + if (m_Dimensions == Dims{1}) + m_IsScalar = true; + } + + template <class... Args> + void AddTransform(Transform &transform, Args... args) + { + std::vector<std::string> parameters = {args...}; + m_Transforms.emplace_back( + transform, + BuildParametersMap(parameters, m_DebugMode)); // need to check + } + + /** Return the global dimensions of the variable + * @return vector of std::size_t values + */ + std::vector<std::size_t> GetGlobalDimensions(); + + /** Return the number of steps available for the variable + * @return Number of steps + */ + int GetSteps(); + + void Monitor(std::ostream &logInfo) const noexcept + { + logInfo << "Variable: " << m_Name << "\n"; + logInfo << "Type: " << m_Type << "\n"; + logInfo << "Size: " << TotalSize() << " elements\n"; + logInfo << "Payload: " << PayLoadSize() << " bytes\n"; + + if (m_AppValues != nullptr) { - logInfo << m_AppValues[i] << " "; + logInfo << "Values (first 10 or max_size): \n"; + std::size_t size = TotalSize(); + if (size > 10) + size = 10; + + if (m_Type.find("complex") != m_Type.npos) // it's complex + { + for (unsigned int i = 0; i < size; ++i) + { + logInfo << "( " << std::real(m_AppValues[i]) << " , " + << std::imag(m_AppValues[i]) << " ) "; + } + } + else + { + for (unsigned int i = 0; i < size; ++i) + { + logInfo << m_AppValues[i] << " "; + } + } + + logInfo << " ..."; } - } - - logInfo << " ..."; + logInfo << "\n"; } - logInfo << "\n"; - } }; } // end namespace diff --git a/include/core/VariableBase.h b/include/core/VariableBase.h index cc8c8f79a4806186e47dec2c4d5c5f691ea1039b..eea1d261c67e63b84e1db385117dfcb01781a9ce 100644 --- a/include/core/VariableBase.h +++ b/include/core/VariableBase.h @@ -30,71 +30,75 @@ class VariableBase { public: - const std::string m_Name; ///< variable name - const std::string m_Type; ///< variable type - const std::size_t m_ElementSize; ///< Variable -> sizeof(T), VariableCompound - ///-> from constructor - - bool m_IsScalar = false; - const bool m_IsDimension = false; - - VariableBase(const std::string name, const std::string type, - const std::size_t elementSize, const Dims dimensions, - const Dims globalDimensions, const Dims globalOffsets, - const bool debugMode) - : m_Name{name}, m_Type{type}, m_ElementSize{elementSize}, - m_Dimensions{dimensions}, m_GlobalDimensions{globalDimensions}, - m_GlobalOffsets{globalOffsets}, m_DebugMode{debugMode} - { - } - - virtual ~VariableBase() {} - - std::size_t DimensionsSize() const noexcept { return m_Dimensions.size(); } - - /** - * Returns the payload size in bytes - * @return TotalSize * sizeof(T) - */ - std::size_t PayLoadSize() const noexcept - { - return GetTotalSize(m_Dimensions) * m_ElementSize; - } - - /** - * Returns the total size - * @return number of elements - */ - std::size_t TotalSize() const noexcept { return GetTotalSize(m_Dimensions); } - - // protected: off for now - - Dims m_Dimensions; ///< array of local dimensions - Dims m_GlobalDimensions; ///< array of global dimensions - Dims m_GlobalOffsets; ///< array of global offsets - const bool m_DebugMode = false; - - std::string GetDimensionAsString() { return dimsToString(m_Dimensions); } - std::string GetGlobalDimensionAsString() - { - return dimsToString(m_GlobalDimensions); - } - std::string GetOffsetsAsString() { return dimsToString(m_GlobalOffsets); } + const std::string m_Name; ///< variable name + const std::string m_Type; ///< variable type + const std::size_t + m_ElementSize; ///< Variable -> sizeof(T), VariableCompound + ///-> from constructor + + bool m_IsScalar = false; + const bool m_IsDimension = false; + + VariableBase(const std::string name, const std::string type, + const std::size_t elementSize, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets, + const bool debugMode) + : m_Name{name}, m_Type{type}, m_ElementSize{elementSize}, + m_Dimensions{dimensions}, m_GlobalDimensions{globalDimensions}, + m_GlobalOffsets{globalOffsets}, m_DebugMode{debugMode} + { + } + + virtual ~VariableBase() {} + + std::size_t DimensionsSize() const noexcept { return m_Dimensions.size(); } + + /** + * Returns the payload size in bytes + * @return TotalSize * sizeof(T) + */ + std::size_t PayLoadSize() const noexcept + { + return GetTotalSize(m_Dimensions) * m_ElementSize; + } + + /** + * Returns the total size + * @return number of elements + */ + std::size_t TotalSize() const noexcept + { + return GetTotalSize(m_Dimensions); + } + + // protected: off for now + + Dims m_Dimensions; ///< array of local dimensions + Dims m_GlobalDimensions; ///< array of global dimensions + Dims m_GlobalOffsets; ///< array of global offsets + const bool m_DebugMode = false; + + std::string GetDimensionAsString() { return dimsToString(m_Dimensions); } + std::string GetGlobalDimensionAsString() + { + return dimsToString(m_GlobalDimensions); + } + std::string GetOffsetsAsString() { return dimsToString(m_GlobalOffsets); } private: - std::string dimsToString(Dims dims) - { - std::ostringstream oss; - if (!dims.empty()) + std::string dimsToString(Dims dims) { - // Convert all but the last element to avoid a trailing "," - std::copy(dims.begin(), dims.end() - 1, - std::ostream_iterator<std::size_t>(oss, ",")); - // Now add the last element with no delimiter - oss << dims.back(); + std::ostringstream oss; + if (!dims.empty()) + { + // Convert all but the last element to avoid a trailing "," + std::copy(dims.begin(), dims.end() - 1, + std::ostream_iterator<std::size_t>(oss, ",")); + // Now add the last element with no delimiter + oss << dims.back(); + } + return oss.str(); } - return oss.str(); - } }; } diff --git a/include/core/VariableCompound.h b/include/core/VariableCompound.h index c3bacfccaae20331e45876361388eb035812cd58..322dccd4f08adc8ddc9ffd6cb18a1b2e1b159f9c 100644 --- a/include/core/VariableCompound.h +++ b/include/core/VariableCompound.h @@ -18,9 +18,9 @@ namespace adios struct CompoundElement { - const std::string m_Name; - const std::size_t m_Offset; - const std::string m_Type; + const std::string m_Name; + const std::size_t m_Offset; + const std::string m_Type; }; /** @@ -31,32 +31,32 @@ class VariableCompound : public VariableBase { public: - const void *m_AppValue = nullptr; + const void *m_AppValue = nullptr; - VariableCompound(const std::string name, const std::size_t sizeOfStruct, - const Dims dimensions, const Dims globalDimensions, - const Dims globalOffsets, const bool debugMode) - : VariableBase(name, "compound", sizeOfStruct, dimensions, globalDimensions, - globalOffsets, debugMode) - { - } + VariableCompound(const std::string name, const std::size_t sizeOfStruct, + const Dims dimensions, const Dims globalDimensions, + const Dims globalOffsets, const bool debugMode) + : VariableBase(name, "compound", sizeOfStruct, dimensions, globalDimensions, + globalOffsets, debugMode) + { + } - template <class U> - void InsertMember(const std::string name, const std::size_t offset) - { - m_Elements.push_back(CompoundElement{name, offset, GetType<U>()}); - } + template <class U> + void InsertMember(const std::string name, const std::size_t offset) + { + m_Elements.push_back(CompoundElement{name, offset, GetType<U>()}); + } - void Monitor(std::ostream &logInfo) const noexcept - { - logInfo << "Variable Compound: " << m_Name << "\n"; - logInfo << "Type: " << m_Type << "\n"; - logInfo << "Size: " << TotalSize() << " elements\n"; - logInfo << "Payload: " << PayLoadSize() << " bytes\n"; - } + void Monitor(std::ostream &logInfo) const noexcept + { + logInfo << "Variable Compound: " << m_Name << "\n"; + logInfo << "Type: " << m_Type << "\n"; + logInfo << "Size: " << TotalSize() << " elements\n"; + logInfo << "Payload: " << PayLoadSize() << " bytes\n"; + } private: - std::vector<CompoundElement> m_Elements; ///< vector of element types + std::vector<CompoundElement> m_Elements; ///< vector of element types }; } // end namespace diff --git a/include/engine/adios1/ADIOS1Reader.h b/include/engine/adios1/ADIOS1Reader.h index 70b89700aadabcbd4f2479d48dee4cacba480efc..22e2984765bac022d57ba63ba1b6c4b30906bd56 100644 --- a/include/engine/adios1/ADIOS1Reader.h +++ b/include/engine/adios1/ADIOS1Reader.h @@ -27,96 +27,100 @@ class BPFileReader : public Engine { public: - /** - * Constructor for single BP capsule engine, writes in BP format into a single - * heap capsule - * @param name unique name given to the engine - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - * @param hostLanguage - */ - BPFileReader(ADIOS &adios, const std::string name, - const std::string accessMode, MPI_Comm mpiComm, - const Method &method, const IOMode iomode, - const float timeout_sec, const bool debugMode = false, - const unsigned int nthreads = 1); - - ~BPFileReader(); - - Variable<void> *InquireVariable(const std::string name, - const bool readIn = true); - Variable<char> *InquireVariableChar(const std::string name, - const bool readIn = true); - Variable<unsigned char> *InquireVariableUChar(const std::string name, - const bool readIn = true); - Variable<short> *InquireVariableShort(const std::string name, + /** + * Constructor for single BP capsule engine, writes in BP format into a + * single + * heap capsule + * @param name unique name given to the engine + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + * @param hostLanguage + */ + BPFileReader(ADIOS &adios, const std::string name, + const std::string accessMode, MPI_Comm mpiComm, + const Method &method, const IOMode iomode, + const float timeout_sec, const bool debugMode = false, + const unsigned int nthreads = 1); + + ~BPFileReader(); + + Variable<void> *InquireVariable(const std::string name, + const bool readIn = true); + Variable<char> *InquireVariableChar(const std::string name, const bool readIn = true); - Variable<unsigned short> *InquireVariableUShort(const std::string name, + Variable<unsigned char> *InquireVariableUChar(const std::string name, const bool readIn = true); - Variable<int> *InquireVariableInt(const std::string name, - const bool readIn = true); - Variable<unsigned int> *InquireVariableUInt(const std::string name, - const bool readIn = true); - Variable<long int> *InquireVariableLInt(const std::string name, + Variable<short> *InquireVariableShort(const std::string name, const bool readIn = true); - Variable<unsigned long int> *InquireVariableULInt(const std::string name, + Variable<unsigned short> *InquireVariableUShort(const std::string name, const bool readIn = true); - Variable<long long int> *InquireVariableLLInt(const std::string name, + Variable<int> *InquireVariableInt(const std::string name, + const bool readIn = true); + Variable<unsigned int> *InquireVariableUInt(const std::string name, const bool readIn = true); - Variable<unsigned long long int> * - InquireVariableULLInt(const std::string name, const bool readIn = true); - Variable<float> *InquireVariableFloat(const std::string name, - const bool readIn = true); - Variable<double> *InquireVariableDouble(const std::string name, + Variable<long int> *InquireVariableLInt(const std::string name, + const bool readIn = true); + Variable<unsigned long int> *InquireVariableULInt(const std::string name, + const bool readIn = true); + Variable<long long int> *InquireVariableLLInt(const std::string name, + const bool readIn = true); + Variable<unsigned long long int> * + InquireVariableULLInt(const std::string name, const bool readIn = true); + Variable<float> *InquireVariableFloat(const std::string name, const bool readIn = true); - Variable<long double> *InquireVariableLDouble(const std::string name, - const bool readIn = true); - Variable<std::complex<float>> * - InquireVariableCFloat(const std::string name, const bool readIn = true); - Variable<std::complex<double>> * - InquireVariableCDouble(const std::string name, const bool readIn = true); - Variable<std::complex<long double>> * - InquireVariableCLDouble(const std::string name, const bool readIn = true); - - /** - * Not implemented - * @param name - * @param readIn - * @return - */ - VariableCompound *InquireVariableCompound(const std::string name, + Variable<double> *InquireVariableDouble(const std::string name, const bool readIn = true); + Variable<long double> *InquireVariableLDouble(const std::string name, + const bool readIn = true); + Variable<std::complex<float>> * + InquireVariableCFloat(const std::string name, const bool readIn = true); + Variable<std::complex<double>> * + InquireVariableCDouble(const std::string name, const bool readIn = true); + Variable<std::complex<long double>> * + InquireVariableCLDouble(const std::string name, const bool readIn = true); + + /** + * Not implemented + * @param name + * @param readIn + * @return + */ + VariableCompound *InquireVariableCompound(const std::string name, + const bool readIn = true); - void Close(const int transportIndex = -1); + void Close(const int transportIndex = -1); private: - capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers - // format::BP1Writer m_BP1Writer; ///< format object will provide the required - // BP functionality to be applied on m_Buffer and m_Transports - - void Init(); ///< calls InitCapsules and InitTransports based on Method, - /// called from constructor - void InitCapsules(); - void InitTransports(); ///< from Transports - - std::string - GetMdtmParameter(const std::string parameter, - const std::map<std::string, std::string> &mdtmParameters); - - template <class T> - Variable<T> *InquireVariableCommon(const std::string name, const bool readIn) - { - std::cout << "Hello BPReaderCommon\n"; - - // here read variable metadata (dimensions, type, etc.)...then create a - // Variable like below: - // Variable<T>& variable = m_ADIOS.DefineVariable<T>( m_Name + "/" + name, ) - // return &variable; //return address if success - return nullptr; // on failure - } + capsule::STLVector + m_Buffer; ///< heap capsule, contains data and metadata buffers + // format::BP1Writer m_BP1Writer; ///< format object will provide the + // required + // BP functionality to be applied on m_Buffer and m_Transports + + void Init(); ///< calls InitCapsules and InitTransports based on Method, + /// called from constructor + void InitCapsules(); + void InitTransports(); ///< from Transports + + std::string + GetMdtmParameter(const std::string parameter, + const std::map<std::string, std::string> &mdtmParameters); + + template <class T> + Variable<T> *InquireVariableCommon(const std::string name, + const bool readIn) + { + std::cout << "Hello BPReaderCommon\n"; + + // here read variable metadata (dimensions, type, etc.)...then create a + // Variable like below: + // Variable<T>& variable = m_ADIOS.DefineVariable<T>( m_Name + "/" + + // name, ) + // return &variable; //return address if success + return nullptr; // on failure + } }; } // end namespace adios diff --git a/include/engine/adios1/ADIOS1Writer.h b/include/engine/adios1/ADIOS1Writer.h index 054e7063a05b0f3456575c7e7fcd3bcb54a0a0a7..8f41ed432d566e370110775b13e90c051f51a531 100644 --- a/include/engine/adios1/ADIOS1Writer.h +++ b/include/engine/adios1/ADIOS1Writer.h @@ -27,103 +27,107 @@ class ADIOS1Writer : public Engine { public: - /** - * Constructor for Writer writes in ADIOS 1.x BP format - * @param name unique name given to the engine - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - */ - ADIOS1Writer(ADIOS &adios, const std::string name, - const std::string accessMode, MPI_Comm mpiComm, - const Method &method, const IOMode iomode, - const float timeout_sec, const bool debugMode = false, - const unsigned int nthreads = 1); - - ~ADIOS1Writer(); - - void Write(Variable<char> &variable, const char *values); - void Write(Variable<unsigned char> &variable, const unsigned char *values); - void Write(Variable<short> &variable, const short *values); - void Write(Variable<unsigned short> &variable, const unsigned short *values); - void Write(Variable<int> &variable, const int *values); - void Write(Variable<unsigned int> &variable, const unsigned int *values); - void Write(Variable<long int> &variable, const long int *values); - void Write(Variable<unsigned long int> &variable, - const unsigned long int *values); - void Write(Variable<long long int> &variable, const long long int *values); - void Write(Variable<unsigned long long int> &variable, - const unsigned long long int *values); - void Write(Variable<float> &variable, const float *values); - void Write(Variable<double> &variable, const double *values); - void Write(Variable<long double> &variable, const long double *values); - void Write(Variable<std::complex<float>> &variable, - const std::complex<float> *values); - void Write(Variable<std::complex<double>> &variable, - const std::complex<double> *values); - void Write(Variable<std::complex<long double>> &variable, - const std::complex<long double> *values); - void Write(VariableCompound &variable, const void *values); - - void Write(const std::string variableName, const char *values); - void Write(const std::string variableName, const unsigned char *values); - void Write(const std::string variableName, const short *values); - void Write(const std::string variableName, const unsigned short *values); - void Write(const std::string variableName, const int *values); - void Write(const std::string variableName, const unsigned int *values); - void Write(const std::string variableName, const long int *values); - void Write(const std::string variableName, const unsigned long int *values); - void Write(const std::string variableName, const long long int *values); - void Write(const std::string variableName, - const unsigned long long int *values); - void Write(const std::string variableName, const float *values); - void Write(const std::string variableName, const double *values); - void Write(const std::string variableName, const long double *values); - void Write(const std::string variableName, const std::complex<float> *values); - void Write(const std::string variableName, - const std::complex<double> *values); - void Write(const std::string variableName, - const std::complex<long double> *values); - void Write(const std::string variableName, const void *values); - - void Advance(); - - /** - * Closes a single transport or all transports - * @param transportIndex, if -1 (default) closes all transports, otherwise it - * closes a transport in m_Transport[transportIndex]. In debug mode the latter - * is bounds-checked. - */ - void Close(const int transportIndex = -1); + /** + * Constructor for Writer writes in ADIOS 1.x BP format + * @param name unique name given to the engine + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + */ + ADIOS1Writer(ADIOS &adios, const std::string name, + const std::string accessMode, MPI_Comm mpiComm, + const Method &method, const IOMode iomode, + const float timeout_sec, const bool debugMode = false, + const unsigned int nthreads = 1); + + ~ADIOS1Writer(); + + void Write(Variable<char> &variable, const char *values); + void Write(Variable<unsigned char> &variable, const unsigned char *values); + void Write(Variable<short> &variable, const short *values); + void Write(Variable<unsigned short> &variable, + const unsigned short *values); + void Write(Variable<int> &variable, const int *values); + void Write(Variable<unsigned int> &variable, const unsigned int *values); + void Write(Variable<long int> &variable, const long int *values); + void Write(Variable<unsigned long int> &variable, + const unsigned long int *values); + void Write(Variable<long long int> &variable, const long long int *values); + void Write(Variable<unsigned long long int> &variable, + const unsigned long long int *values); + void Write(Variable<float> &variable, const float *values); + void Write(Variable<double> &variable, const double *values); + void Write(Variable<long double> &variable, const long double *values); + void Write(Variable<std::complex<float>> &variable, + const std::complex<float> *values); + void Write(Variable<std::complex<double>> &variable, + const std::complex<double> *values); + void Write(Variable<std::complex<long double>> &variable, + const std::complex<long double> *values); + void Write(VariableCompound &variable, const void *values); + + void Write(const std::string variableName, const char *values); + void Write(const std::string variableName, const unsigned char *values); + void Write(const std::string variableName, const short *values); + void Write(const std::string variableName, const unsigned short *values); + void Write(const std::string variableName, const int *values); + void Write(const std::string variableName, const unsigned int *values); + void Write(const std::string variableName, const long int *values); + void Write(const std::string variableName, const unsigned long int *values); + void Write(const std::string variableName, const long long int *values); + void Write(const std::string variableName, + const unsigned long long int *values); + void Write(const std::string variableName, const float *values); + void Write(const std::string variableName, const double *values); + void Write(const std::string variableName, const long double *values); + void Write(const std::string variableName, + const std::complex<float> *values); + void Write(const std::string variableName, + const std::complex<double> *values); + void Write(const std::string variableName, + const std::complex<long double> *values); + void Write(const std::string variableName, const void *values); + + void Advance(); + + /** + * Closes a single transport or all transports + * @param transportIndex, if -1 (default) closes all transports, otherwise + * it + * closes a transport in m_Transport[transportIndex]. In debug mode the + * latter + * is bounds-checked. + */ + void Close(const int transportIndex = -1); private: - const char *m_groupname; ///< ADIOS1 group name created from the method's - /// name. Must be a unique group name. - const char *m_filename; ///< Save file name from constructor for Advance() - /// when we re-open in ADIOS1 - MPI_Comm m_comm; ///< Save MPI communicator from constructor for Advance() - /// when we re-open in ADIOS1 - - bool m_initialized = false; ///< set to true after calling adios_init() - int64_t m_adios_file = 0; ///< ADIOS1 file handler returned by adios_open() - int64_t m_adios_group = - 0; ///< ADIOS1 group pointer that holds the ADIOS1 variable definitions - bool m_IsFileOpen = false; - - void Init(); - // these are unused yet, keeping here to see if we need them - void InitParameters(); - void InitTransports(); - void InitProcessGroup(); - - bool ReOpenAsNeeded(); // return true if file is open or reopened - void DefineVariable(std::string name, bool isScalar, - enum ADIOS_DATATYPES vartype, std::string ldims, - std::string gdims, std::string offs); - void WriteVariable(std::string name, bool isScalar, - enum ADIOS_DATATYPES vartype, std::string ldims, - std::string gdims, std::string offs, const void *values); + const char *m_groupname; ///< ADIOS1 group name created from the method's + /// name. Must be a unique group name. + const char *m_filename; ///< Save file name from constructor for Advance() + /// when we re-open in ADIOS1 + MPI_Comm m_comm; ///< Save MPI communicator from constructor for Advance() + /// when we re-open in ADIOS1 + + bool m_initialized = false; ///< set to true after calling adios_init() + int64_t m_adios_file = 0; ///< ADIOS1 file handler returned by adios_open() + int64_t m_adios_group = 0; ///< ADIOS1 group pointer that holds the ADIOS1 + /// variable definitions + bool m_IsFileOpen = false; + + void Init(); + // these are unused yet, keeping here to see if we need them + void InitParameters(); + void InitTransports(); + void InitProcessGroup(); + + bool ReOpenAsNeeded(); // return true if file is open or reopened + void DefineVariable(std::string name, bool isScalar, + enum ADIOS_DATATYPES vartype, std::string ldims, + std::string gdims, std::string offs); + void WriteVariable(std::string name, bool isScalar, + enum ADIOS_DATATYPES vartype, std::string ldims, + std::string gdims, std::string offs, const void *values); }; } // end namespace adios diff --git a/include/engine/bp/BPFileReader.h b/include/engine/bp/BPFileReader.h index 4f4c451532db4769ed6f296e7b342b93cf36c857..74ef5e6a4e8ff91a78b2a08154a1b862eaf5045b 100644 --- a/include/engine/bp/BPFileReader.h +++ b/include/engine/bp/BPFileReader.h @@ -25,95 +25,99 @@ class BPFileReader : public Engine { public: - /** - * Constructor for single BP capsule engine, writes in BP format into a single - * heap capsule - * @param name unique name given to the engine - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - * @param hostLanguage - */ - BPFileReader(ADIOS &adios, std::string name, std::string accessMode, - MPI_Comm mpiComm, const Method &method, IOMode iomode, - float timeout_sec, bool debugMode = false, - unsigned int nthreads = 1); - - virtual ~BPFileReader() = default; - - Variable<void> *InquireVariable(const std::string name, - const bool readIn = true); - Variable<char> *InquireVariableChar(const std::string name, - const bool readIn = true); - Variable<unsigned char> *InquireVariableUChar(const std::string name, - const bool readIn = true); - Variable<short> *InquireVariableShort(const std::string name, + /** + * Constructor for single BP capsule engine, writes in BP format into a + * single + * heap capsule + * @param name unique name given to the engine + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + * @param hostLanguage + */ + BPFileReader(ADIOS &adios, std::string name, std::string accessMode, + MPI_Comm mpiComm, const Method &method, IOMode iomode, + float timeout_sec, bool debugMode = false, + unsigned int nthreads = 1); + + virtual ~BPFileReader() = default; + + Variable<void> *InquireVariable(const std::string name, + const bool readIn = true); + Variable<char> *InquireVariableChar(const std::string name, const bool readIn = true); - Variable<unsigned short> *InquireVariableUShort(const std::string name, + Variable<unsigned char> *InquireVariableUChar(const std::string name, const bool readIn = true); - Variable<int> *InquireVariableInt(const std::string name, - const bool readIn = true); - Variable<unsigned int> *InquireVariableUInt(const std::string name, - const bool readIn = true); - Variable<long int> *InquireVariableLInt(const std::string name, + Variable<short> *InquireVariableShort(const std::string name, const bool readIn = true); - Variable<unsigned long int> *InquireVariableULInt(const std::string name, + Variable<unsigned short> *InquireVariableUShort(const std::string name, const bool readIn = true); - Variable<long long int> *InquireVariableLLInt(const std::string name, + Variable<int> *InquireVariableInt(const std::string name, + const bool readIn = true); + Variable<unsigned int> *InquireVariableUInt(const std::string name, const bool readIn = true); - Variable<unsigned long long int> * - InquireVariableULLInt(const std::string name, const bool readIn = true); - Variable<float> *InquireVariableFloat(const std::string name, - const bool readIn = true); - Variable<double> *InquireVariableDouble(const std::string name, + Variable<long int> *InquireVariableLInt(const std::string name, + const bool readIn = true); + Variable<unsigned long int> *InquireVariableULInt(const std::string name, + const bool readIn = true); + Variable<long long int> *InquireVariableLLInt(const std::string name, + const bool readIn = true); + Variable<unsigned long long int> * + InquireVariableULLInt(const std::string name, const bool readIn = true); + Variable<float> *InquireVariableFloat(const std::string name, const bool readIn = true); - Variable<long double> *InquireVariableLDouble(const std::string name, - const bool readIn = true); - Variable<std::complex<float>> * - InquireVariableCFloat(const std::string name, const bool readIn = true); - Variable<std::complex<double>> * - InquireVariableCDouble(const std::string name, const bool readIn = true); - Variable<std::complex<long double>> * - InquireVariableCLDouble(const std::string name, const bool readIn = true); - - /** - * Not implemented - * @param name - * @param readIn - * @return - */ - VariableCompound *InquireVariableCompound(const std::string name, + Variable<double> *InquireVariableDouble(const std::string name, const bool readIn = true); + Variable<long double> *InquireVariableLDouble(const std::string name, + const bool readIn = true); + Variable<std::complex<float>> * + InquireVariableCFloat(const std::string name, const bool readIn = true); + Variable<std::complex<double>> * + InquireVariableCDouble(const std::string name, const bool readIn = true); + Variable<std::complex<long double>> * + InquireVariableCLDouble(const std::string name, const bool readIn = true); + + /** + * Not implemented + * @param name + * @param readIn + * @return + */ + VariableCompound *InquireVariableCompound(const std::string name, + const bool readIn = true); - void Close(const int transportIndex = -1); + void Close(const int transportIndex = -1); private: - capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers - // format::BP1Writer m_BP1Writer; ///< format object will provide the required - // BP functionality to be applied on m_Buffer and m_Transports - - void Init(); ///< calls InitCapsules and InitTransports based on Method, - /// called from constructor - void InitCapsules(); - void InitTransports(); ///< from Transports - - std::string - GetMdtmParameter(const std::string parameter, - const std::map<std::string, std::string> &mdtmParameters); - - template <class T> - Variable<T> *InquireVariableCommon(const std::string name, const bool readIn) - { - std::cout << "Hello BPReaderCommon\n"; - - // here read variable metadata (dimensions, type, etc.)...then create a - // Variable like below: - // Variable<T>& variable = m_ADIOS.DefineVariable<T>( m_Name + "/" + name, ) - // return &variable; //return address if success - return nullptr; // on failure - } + capsule::STLVector + m_Buffer; ///< heap capsule, contains data and metadata buffers + // format::BP1Writer m_BP1Writer; ///< format object will provide the + // required + // BP functionality to be applied on m_Buffer and m_Transports + + void Init(); ///< calls InitCapsules and InitTransports based on Method, + /// called from constructor + void InitCapsules(); + void InitTransports(); ///< from Transports + + std::string + GetMdtmParameter(const std::string parameter, + const std::map<std::string, std::string> &mdtmParameters); + + template <class T> + Variable<T> *InquireVariableCommon(const std::string name, + const bool readIn) + { + std::cout << "Hello BPReaderCommon\n"; + + // here read variable metadata (dimensions, type, etc.)...then create a + // Variable like below: + // Variable<T>& variable = m_ADIOS.DefineVariable<T>( m_Name + "/" + + // name, ) + // return &variable; //return address if success + return nullptr; // on failure + } }; } // end namespace adios diff --git a/include/engine/bp/BPFileWriter.h b/include/engine/bp/BPFileWriter.h index 558eebbd9572b85a146ebd9fa2c2411a06d3901b..97db293c0defacf50cbced0b0ae84870c8e374c5 100644 --- a/include/engine/bp/BPFileWriter.h +++ b/include/engine/bp/BPFileWriter.h @@ -25,157 +25,165 @@ class BPFileWriter : public Engine { public: - /** - * Constructor for Writer writes in BP format into a single heap capsule, - * manages several transports - * @param name unique name given to the engine - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - */ - BPFileWriter(ADIOS &adios, std::string name, const std::string &accessMode, - MPI_Comm mpiComm, const Method &method, - const IOMode iomode = IOMode::INDEPENDENT, - const float timeout_sec = 0., const bool debugMode = false, - const unsigned int nthreads = 1); - - ~BPFileWriter(); - - void Write(Variable<char> &variable, const char *values); - void Write(Variable<unsigned char> &variable, const unsigned char *values); - void Write(Variable<short> &variable, const short *values); - void Write(Variable<unsigned short> &variable, const unsigned short *values); - void Write(Variable<int> &variable, const int *values); - void Write(Variable<unsigned int> &variable, const unsigned int *values); - void Write(Variable<long int> &variable, const long int *values); - void Write(Variable<unsigned long int> &variable, - const unsigned long int *values); - void Write(Variable<long long int> &variable, const long long int *values); - void Write(Variable<unsigned long long int> &variable, - const unsigned long long int *values); - void Write(Variable<float> &variable, const float *values); - void Write(Variable<double> &variable, const double *values); - void Write(Variable<long double> &variable, const long double *values); - void Write(Variable<std::complex<float>> &variable, - const std::complex<float> *values); - void Write(Variable<std::complex<double>> &variable, - const std::complex<double> *values); - void Write(Variable<std::complex<long double>> &variable, - const std::complex<long double> *values); - void Write(VariableCompound &variable, const void *values); - - void Write(const std::string variableName, const char *values); - void Write(const std::string variableName, const unsigned char *values); - void Write(const std::string variableName, const short *values); - void Write(const std::string variableName, const unsigned short *values); - void Write(const std::string variableName, const int *values); - void Write(const std::string variableName, const unsigned int *values); - void Write(const std::string variableName, const long int *values); - void Write(const std::string variableName, const unsigned long int *values); - void Write(const std::string variableName, const long long int *values); - void Write(const std::string variableName, - const unsigned long long int *values); - void Write(const std::string variableName, const float *values); - void Write(const std::string variableName, const double *values); - void Write(const std::string variableName, const long double *values); - void Write(const std::string variableName, const std::complex<float> *values); - void Write(const std::string variableName, - const std::complex<double> *values); - void Write(const std::string variableName, - const std::complex<long double> *values); - void Write(const std::string variableName, const void *values); - - void Advance(float timeout_sec = 0.0); - - /** - * Closes a single transport or all transports - * @param transportIndex, if -1 (default) closes all transports, otherwise it - * closes a transport in m_Transport[transportIndex]. In debug mode the latter - * is bounds-checked. - */ - void Close(const int transportIndex = -1); + /** + * Constructor for Writer writes in BP format into a single heap capsule, + * manages several transports + * @param name unique name given to the engine + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + */ + BPFileWriter(ADIOS &adios, std::string name, const std::string &accessMode, + MPI_Comm mpiComm, const Method &method, + const IOMode iomode = IOMode::INDEPENDENT, + const float timeout_sec = 0., const bool debugMode = false, + const unsigned int nthreads = 1); + + ~BPFileWriter(); + + void Write(Variable<char> &variable, const char *values); + void Write(Variable<unsigned char> &variable, const unsigned char *values); + void Write(Variable<short> &variable, const short *values); + void Write(Variable<unsigned short> &variable, + const unsigned short *values); + void Write(Variable<int> &variable, const int *values); + void Write(Variable<unsigned int> &variable, const unsigned int *values); + void Write(Variable<long int> &variable, const long int *values); + void Write(Variable<unsigned long int> &variable, + const unsigned long int *values); + void Write(Variable<long long int> &variable, const long long int *values); + void Write(Variable<unsigned long long int> &variable, + const unsigned long long int *values); + void Write(Variable<float> &variable, const float *values); + void Write(Variable<double> &variable, const double *values); + void Write(Variable<long double> &variable, const long double *values); + void Write(Variable<std::complex<float>> &variable, + const std::complex<float> *values); + void Write(Variable<std::complex<double>> &variable, + const std::complex<double> *values); + void Write(Variable<std::complex<long double>> &variable, + const std::complex<long double> *values); + void Write(VariableCompound &variable, const void *values); + + void Write(const std::string variableName, const char *values); + void Write(const std::string variableName, const unsigned char *values); + void Write(const std::string variableName, const short *values); + void Write(const std::string variableName, const unsigned short *values); + void Write(const std::string variableName, const int *values); + void Write(const std::string variableName, const unsigned int *values); + void Write(const std::string variableName, const long int *values); + void Write(const std::string variableName, const unsigned long int *values); + void Write(const std::string variableName, const long long int *values); + void Write(const std::string variableName, + const unsigned long long int *values); + void Write(const std::string variableName, const float *values); + void Write(const std::string variableName, const double *values); + void Write(const std::string variableName, const long double *values); + void Write(const std::string variableName, + const std::complex<float> *values); + void Write(const std::string variableName, + const std::complex<double> *values); + void Write(const std::string variableName, + const std::complex<long double> *values); + void Write(const std::string variableName, const void *values); + + void Advance(float timeout_sec = 0.0); + + /** + * Closes a single transport or all transports + * @param transportIndex, if -1 (default) closes all transports, otherwise + * it + * closes a transport in m_Transport[transportIndex]. In debug mode the + * latter + * is bounds-checked. + */ + void Close(const int transportIndex = -1); private: - capsule::STLVector m_Buffer; ///< heap capsule using STL std::vector<char> - format::BP1Writer m_BP1Writer; ///< format object will provide the required BP - /// functionality to be applied on m_Buffer and - /// m_Transports - format::BP1MetadataSet m_MetadataSet; ///< metadata set accompanying the heap - /// buffer data in bp format. Needed by - /// m_BP1Writer - format::BP1Aggregator m_BP1Aggregator; - - bool m_IsFirstClose = true; ///< set to false after first Close is reached so - /// metadata doesn't have to be accommodated for a - /// subsequent Close - std::size_t m_MaxBufferSize; ///< maximum allowed memory to be allocated - float m_GrowthFactor = 1.5; ///< capsule memory growth factor, new_memory = - /// m_GrowthFactor * current_memory - - bool m_TransportFlush = - false; ///< true: transport flush happened, buffer must be reset - bool m_CloseProcessGroup = false; ///< set to true if advance is called, this - /// prevents flattening the data and metadata - /// in Close - - void Init(); - void InitParameters(); - void InitTransports(); - void InitProcessGroup(); - - void WriteProcessGroupIndex(); - - /** - * Common function for primitive (including std::complex) writes - * @param group - * @param variableName - * @param variable - */ - template <class T> - void WriteVariableCommon(Variable<T> &variable, const T *values) - { - if (m_MetadataSet.Log.m_IsActive == true) - m_MetadataSet.Log.m_Timers[0].SetInitialTime(); - - // set variable - variable.m_AppValues = values; - m_WrittenVariables.insert(variable.m_Name); - - // if first timestep Write - if (m_MetadataSet.DataPGIsOpen == false) // create a new pg index - WriteProcessGroupIndex(); - - // pre-calculate new metadata and payload sizes - // m_TransportFlush = CheckBufferAllocation( - // m_BP1Writer.GetVariableIndexSize( variable ) + - // variable.PayLoadSize(), - // m_GrowthFactor, - // m_MaxBufferSize, - // m_Buffer.m_Data ); - - // WRITE INDEX to data buffer and metadata structure (in memory)// - m_BP1Writer.WriteVariableMetadata(variable, m_Buffer, m_MetadataSet); - - if (m_TransportFlush == true) // in batches + capsule::STLVector m_Buffer; ///< heap capsule using STL std::vector<char> + format::BP1Writer + m_BP1Writer; ///< format object will provide the required BP + /// functionality to be applied on m_Buffer and + /// m_Transports + format::BP1MetadataSet + m_MetadataSet; ///< metadata set accompanying the heap + /// buffer data in bp format. Needed by + /// m_BP1Writer + format::BP1Aggregator m_BP1Aggregator; + + bool m_IsFirstClose = + true; ///< set to false after first Close is reached so + /// metadata doesn't have to be accommodated for a + /// subsequent Close + std::size_t m_MaxBufferSize; ///< maximum allowed memory to be allocated + float m_GrowthFactor = 1.5; ///< capsule memory growth factor, new_memory = + /// m_GrowthFactor * current_memory + + bool m_TransportFlush = + false; ///< true: transport flush happened, buffer must be reset + bool m_CloseProcessGroup = + false; ///< set to true if advance is called, this + /// prevents flattening the data and metadata + /// in Close + + void Init(); + void InitParameters(); + void InitTransports(); + void InitProcessGroup(); + + void WriteProcessGroupIndex(); + + /** + * Common function for primitive (including std::complex) writes + * @param group + * @param variableName + * @param variable + */ + template <class T> + void WriteVariableCommon(Variable<T> &variable, const T *values) { - // write pg index - - // flush to transports - - // reset relative positions to zero, update absolute position - } - else // Write data to buffer - { - m_BP1Writer.WriteVariablePayload(variable, m_Buffer, m_nThreads); + if (m_MetadataSet.Log.m_IsActive == true) + m_MetadataSet.Log.m_Timers[0].SetInitialTime(); + + // set variable + variable.m_AppValues = values; + m_WrittenVariables.insert(variable.m_Name); + + // if first timestep Write + if (m_MetadataSet.DataPGIsOpen == false) // create a new pg index + WriteProcessGroupIndex(); + + // pre-calculate new metadata and payload sizes + // m_TransportFlush = CheckBufferAllocation( + // m_BP1Writer.GetVariableIndexSize( variable ) + + // variable.PayLoadSize(), + // m_GrowthFactor, + // m_MaxBufferSize, + // m_Buffer.m_Data ); + + // WRITE INDEX to data buffer and metadata structure (in memory)// + m_BP1Writer.WriteVariableMetadata(variable, m_Buffer, m_MetadataSet); + + if (m_TransportFlush == true) // in batches + { + // write pg index + + // flush to transports + + // reset relative positions to zero, update absolute position + } + else // Write data to buffer + { + m_BP1Writer.WriteVariablePayload(variable, m_Buffer, m_nThreads); + } + + variable.m_AppValues = + nullptr; // setting pointer to null as not needed after write + + if (m_MetadataSet.Log.m_IsActive == true) + m_MetadataSet.Log.m_Timers[0].SetTime(); } - - variable.m_AppValues = - nullptr; // setting pointer to null as not needed after write - - if (m_MetadataSet.Log.m_IsActive == true) - m_MetadataSet.Log.m_Timers[0].SetTime(); - } }; } // end namespace adios diff --git a/include/engine/dataman/DataManReader.h b/include/engine/dataman/DataManReader.h index 88ba7b65c84664dd906dca772311bd4f93e1fcbb..061d2713c2e70d828a563d96574d6ad91eb19b0d 100644 --- a/include/engine/dataman/DataManReader.h +++ b/include/engine/dataman/DataManReader.h @@ -28,114 +28,118 @@ class DataManReader : public Engine { public: - /** - * Constructor for dataman engine Reader for WAN communications - * @param adios - * @param name - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - * @param nthreads - */ - DataManReader(ADIOS &adios, const std::string name, - const std::string accessMode, MPI_Comm mpiComm, - const Method &method, const IOMode iomode, - const float timeout_sec, const bool debugMode = false, - const unsigned int nthreads = 1); - - ~DataManReader(); - - /** - * Set callback function from user application - * @param callback function (get) provided by the user to be applied in - * DataMan - */ - void SetCallBack(std::function<void(const void *, std::string, std::string, - std::string, Dims)> - callback); - - Variable<void> *InquireVariable(const std::string name, - const bool readIn = true); - Variable<char> *InquireVariableChar(const std::string name, - const bool readIn = true); - Variable<unsigned char> *InquireVariableUChar(const std::string name, - const bool readIn = true); - Variable<short> *InquireVariableShort(const std::string name, + /** + * Constructor for dataman engine Reader for WAN communications + * @param adios + * @param name + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + * @param nthreads + */ + DataManReader(ADIOS &adios, const std::string name, + const std::string accessMode, MPI_Comm mpiComm, + const Method &method, const IOMode iomode, + const float timeout_sec, const bool debugMode = false, + const unsigned int nthreads = 1); + + ~DataManReader(); + + /** + * Set callback function from user application + * @param callback function (get) provided by the user to be applied in + * DataMan + */ + void SetCallBack(std::function<void(const void *, std::string, std::string, + std::string, Dims)> + callback); + + Variable<void> *InquireVariable(const std::string name, + const bool readIn = true); + Variable<char> *InquireVariableChar(const std::string name, const bool readIn = true); - Variable<unsigned short> *InquireVariableUShort(const std::string name, + Variable<unsigned char> *InquireVariableUChar(const std::string name, const bool readIn = true); - Variable<int> *InquireVariableInt(const std::string name, - const bool readIn = true); - Variable<unsigned int> *InquireVariableUInt(const std::string name, - const bool readIn = true); - Variable<long int> *InquireVariableLInt(const std::string name, + Variable<short> *InquireVariableShort(const std::string name, const bool readIn = true); - Variable<unsigned long int> *InquireVariableULInt(const std::string name, + Variable<unsigned short> *InquireVariableUShort(const std::string name, const bool readIn = true); - Variable<long long int> *InquireVariableLLInt(const std::string name, + Variable<int> *InquireVariableInt(const std::string name, + const bool readIn = true); + Variable<unsigned int> *InquireVariableUInt(const std::string name, const bool readIn = true); - Variable<unsigned long long int> * - InquireVariableULLInt(const std::string name, const bool readIn = true); - Variable<float> *InquireVariableFloat(const std::string name, - const bool readIn = true); - Variable<double> *InquireVariableDouble(const std::string name, + Variable<long int> *InquireVariableLInt(const std::string name, + const bool readIn = true); + Variable<unsigned long int> *InquireVariableULInt(const std::string name, + const bool readIn = true); + Variable<long long int> *InquireVariableLLInt(const std::string name, + const bool readIn = true); + Variable<unsigned long long int> * + InquireVariableULLInt(const std::string name, const bool readIn = true); + Variable<float> *InquireVariableFloat(const std::string name, const bool readIn = true); - Variable<long double> *InquireVariableLDouble(const std::string name, - const bool readIn = true); - Variable<std::complex<float>> * - InquireVariableCFloat(const std::string name, const bool readIn = true); - Variable<std::complex<double>> * - InquireVariableCDouble(const std::string name, const bool readIn = true); - Variable<std::complex<long double>> * - InquireVariableCLDouble(const std::string name, const bool readIn = true); - - /** - * Not implemented - * @param name - * @param readIn - * @return - */ - VariableCompound *InquireVariableCompound(const std::string name, + Variable<double> *InquireVariableDouble(const std::string name, const bool readIn = true); + Variable<long double> *InquireVariableLDouble(const std::string name, + const bool readIn = true); + Variable<std::complex<float>> * + InquireVariableCFloat(const std::string name, const bool readIn = true); + Variable<std::complex<double>> * + InquireVariableCDouble(const std::string name, const bool readIn = true); + Variable<std::complex<long double>> * + InquireVariableCLDouble(const std::string name, const bool readIn = true); + + /** + * Not implemented + * @param name + * @param readIn + * @return + */ + VariableCompound *InquireVariableCompound(const std::string name, + const bool readIn = true); - void Close(const int transportIndex = -1); + void Close(const int transportIndex = -1); private: - capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers - format::BP1Writer m_BP1Writer; ///< format object will provide the required BP - /// functionality to be applied on m_Buffer and - /// m_Transports - - bool m_DoRealTime = false; - DataManager m_Man; - std::function<void(const void *, std::string, std::string, std::string, Dims)> - m_CallBack; ///< call back function - - void Init(); ///< calls InitCapsules and InitTransports based on Method, - /// called from constructor - void InitCapsules(); - void InitTransports(); ///< from Transports - - std::string - GetMdtmParameter(const std::string parameter, - const std::map<std::string, std::string> &mdtmParameters); - - template <class T> - Variable<T> *InquireVariableCommon(const std::string name, const bool readIn) - { - std::cout << "I am hooked to the DataMan library\n"; - std::cout << "Hello DatamanReader from rank " << m_RankMPI << "\n"; - std::cout << "Trying to read variable " << name - << " from one of the variables coming from a WAN transport\n"; - - // here read variable metadata (dimensions, type, etc.)...then create a - // Variable like below: - // Variable<T>& variable = m_ADIOS.DefineVariable<T>( m_Name + "/" + name, ) - // return &variable; //return address if success - return nullptr; // on failure - } + capsule::STLVector + m_Buffer; ///< heap capsule, contains data and metadata buffers + format::BP1Writer + m_BP1Writer; ///< format object will provide the required BP + /// functionality to be applied on m_Buffer and + /// m_Transports + + bool m_DoRealTime = false; + DataManager m_Man; + std::function<void(const void *, std::string, std::string, std::string, + Dims)> + m_CallBack; ///< call back function + + void Init(); ///< calls InitCapsules and InitTransports based on Method, + /// called from constructor + void InitCapsules(); + void InitTransports(); ///< from Transports + + std::string + GetMdtmParameter(const std::string parameter, + const std::map<std::string, std::string> &mdtmParameters); + + template <class T> + Variable<T> *InquireVariableCommon(const std::string name, + const bool readIn) + { + std::cout << "I am hooked to the DataMan library\n"; + std::cout << "Hello DatamanReader from rank " << m_RankMPI << "\n"; + std::cout << "Trying to read variable " << name + << " from one of the variables coming from a WAN transport\n"; + + // here read variable metadata (dimensions, type, etc.)...then create a + // Variable like below: + // Variable<T>& variable = m_ADIOS.DefineVariable<T>( m_Name + "/" + + // name, ) + // return &variable; //return address if success + return nullptr; // on failure + } }; } // end namespace diff --git a/include/engine/dataman/DataManWriter.h b/include/engine/dataman/DataManWriter.h index b60399fdcf7bc1f4e767669c862d97e74680d89c..3ca32bb3dad5f8e5b186d717c86a1609c16e0fa2 100644 --- a/include/engine/dataman/DataManWriter.h +++ b/include/engine/dataman/DataManWriter.h @@ -29,149 +29,155 @@ class DataManWriter : public Engine { public: - /** - * Constructor for dataman engine Writer for WAN communications - * @param adios - * @param name unique name given to the engine - * @param accessMode - * @param mpiComm - * @param method - * @param debugMode - * @param nthreads - */ - DataManWriter(ADIOS &adios, const std::string name, - const std::string accessMode, MPI_Comm mpiComm, - const Method &method, const IOMode iomode, - const float timeout_sec, const bool debugMode = false, - const unsigned int nthreads = 1); - - ~DataManWriter(); - - void SetCallBack(std::function<void(const void *, std::string, std::string, - std::string, Dims)> - callback); - - void Write(Variable<char> &variable, const char *values); - void Write(Variable<unsigned char> &variable, const unsigned char *values); - void Write(Variable<short> &variable, const short *values); - void Write(Variable<unsigned short> &variable, const unsigned short *values); - void Write(Variable<int> &variable, const int *values); - void Write(Variable<unsigned int> &variable, const unsigned int *values); - void Write(Variable<long int> &variable, const long int *values); - void Write(Variable<unsigned long int> &variable, - const unsigned long int *values); - void Write(Variable<long long int> &variable, const long long int *values); - void Write(Variable<unsigned long long int> &variable, - const unsigned long long int *values); - void Write(Variable<float> &variable, const float *values); - void Write(Variable<double> &variable, const double *values); - void Write(Variable<long double> &variable, const long double *values); - void Write(Variable<std::complex<float>> &variable, - const std::complex<float> *values); - void Write(Variable<std::complex<double>> &variable, - const std::complex<double> *values); - void Write(Variable<std::complex<long double>> &variable, - const std::complex<long double> *values); - - void Write(const std::string variableName, const char *values); - void Write(const std::string variableName, const unsigned char *values); - void Write(const std::string variableName, const short *values); - void Write(const std::string variableName, const unsigned short *values); - void Write(const std::string variableName, const int *values); - void Write(const std::string variableName, const unsigned int *values); - void Write(const std::string variableName, const long int *values); - void Write(const std::string variableName, const unsigned long int *values); - void Write(const std::string variableName, const long long int *values); - void Write(const std::string variableName, - const unsigned long long int *values); - void Write(const std::string variableName, const float *values); - void Write(const std::string variableName, const double *values); - void Write(const std::string variableName, const long double *values); - void Write(const std::string variableName, const std::complex<float> *values); - void Write(const std::string variableName, - const std::complex<double> *values); - void Write(const std::string variableName, - const std::complex<long double> *values); - - void Close(const int transportIndex = -1); + /** + * Constructor for dataman engine Writer for WAN communications + * @param adios + * @param name unique name given to the engine + * @param accessMode + * @param mpiComm + * @param method + * @param debugMode + * @param nthreads + */ + DataManWriter(ADIOS &adios, const std::string name, + const std::string accessMode, MPI_Comm mpiComm, + const Method &method, const IOMode iomode, + const float timeout_sec, const bool debugMode = false, + const unsigned int nthreads = 1); + + ~DataManWriter(); + + void SetCallBack(std::function<void(const void *, std::string, std::string, + std::string, Dims)> + callback); + + void Write(Variable<char> &variable, const char *values); + void Write(Variable<unsigned char> &variable, const unsigned char *values); + void Write(Variable<short> &variable, const short *values); + void Write(Variable<unsigned short> &variable, + const unsigned short *values); + void Write(Variable<int> &variable, const int *values); + void Write(Variable<unsigned int> &variable, const unsigned int *values); + void Write(Variable<long int> &variable, const long int *values); + void Write(Variable<unsigned long int> &variable, + const unsigned long int *values); + void Write(Variable<long long int> &variable, const long long int *values); + void Write(Variable<unsigned long long int> &variable, + const unsigned long long int *values); + void Write(Variable<float> &variable, const float *values); + void Write(Variable<double> &variable, const double *values); + void Write(Variable<long double> &variable, const long double *values); + void Write(Variable<std::complex<float>> &variable, + const std::complex<float> *values); + void Write(Variable<std::complex<double>> &variable, + const std::complex<double> *values); + void Write(Variable<std::complex<long double>> &variable, + const std::complex<long double> *values); + + void Write(const std::string variableName, const char *values); + void Write(const std::string variableName, const unsigned char *values); + void Write(const std::string variableName, const short *values); + void Write(const std::string variableName, const unsigned short *values); + void Write(const std::string variableName, const int *values); + void Write(const std::string variableName, const unsigned int *values); + void Write(const std::string variableName, const long int *values); + void Write(const std::string variableName, const unsigned long int *values); + void Write(const std::string variableName, const long long int *values); + void Write(const std::string variableName, + const unsigned long long int *values); + void Write(const std::string variableName, const float *values); + void Write(const std::string variableName, const double *values); + void Write(const std::string variableName, const long double *values); + void Write(const std::string variableName, + const std::complex<float> *values); + void Write(const std::string variableName, + const std::complex<double> *values); + void Write(const std::string variableName, + const std::complex<long double> *values); + + void Close(const int transportIndex = -1); private: - capsule::STLVector - m_Buffer; ///< heap capsule, contains data and metadata buffers - format::BP1Writer m_BP1Writer; ///< format object will provide the required BP - /// functionality to be applied on m_Buffer and - /// m_Transports - - bool m_DoRealTime = false; - bool m_DoMonitor = false; - DataManager m_Man; - std::function<void(const void *, std::string, std::string, std::string, Dims)> - m_CallBack; ///< call back function - - void Init(); ///< calls InitCapsules and InitTransports based on Method, - /// called from constructor - void InitCapsules(); - void InitTransports(); ///< from Transports - - /** - * From transport Mdtm in m_Method - * @param parameter must be an accepted parameter - * @param mdtmParameters - * @return value either returns user-defined from "parameter=value" or a - * default - */ - std::string - GetMdtmParameter(const std::string parameter, - const std::map<std::string, std::string> &mdtmParameters); - - template <class T> - void WriteVariableCommon(Variable<T> &variable, const T *values) - { - // here comes your magic at Writing now variable.m_UserValues has the data - // passed by the user - // set variable - variable.m_AppValues = values; - m_WrittenVariables.insert(variable.m_Name); - - // This part will go away, this is just to monitor variables per rank - - json jmsg; - jmsg["doid"] = m_Name; - jmsg["var"] = variable.m_Name; - jmsg["dtype"] = GetType<T>(); - jmsg["putshape"] = variable.m_Dimensions; - if (variable.m_GlobalDimensions.size() == 0) - variable.m_GlobalDimensions = variable.m_Dimensions; - jmsg["varshape"] = variable.m_GlobalDimensions; - if (variable.m_GlobalOffsets.size() == 0) - variable.m_GlobalOffsets.assign(variable.m_Dimensions.size(), 0); - jmsg["offset"] = variable.m_GlobalOffsets; - jmsg["timestep"] = 0; - m_Man.put(values, jmsg); - - if (m_DoMonitor) + capsule::STLVector + m_Buffer; ///< heap capsule, contains data and metadata buffers + format::BP1Writer + m_BP1Writer; ///< format object will provide the required BP + /// functionality to be applied on m_Buffer and + /// m_Transports + + bool m_DoRealTime = false; + bool m_DoMonitor = false; + DataManager m_Man; + std::function<void(const void *, std::string, std::string, std::string, + Dims)> + m_CallBack; ///< call back function + + void Init(); ///< calls InitCapsules and InitTransports based on Method, + /// called from constructor + void InitCapsules(); + void InitTransports(); ///< from Transports + + /** + * From transport Mdtm in m_Method + * @param parameter must be an accepted parameter + * @param mdtmParameters + * @return value either returns user-defined from "parameter=value" or a + * default + */ + std::string + GetMdtmParameter(const std::string parameter, + const std::map<std::string, std::string> &mdtmParameters); + + template <class T> + void WriteVariableCommon(Variable<T> &variable, const T *values) { - MPI_Barrier(m_MPIComm); - std::cout << "I am hooked to the DataMan library\n"; - std::cout << "putshape " << variable.m_Dimensions.size() << endl; - std::cout << "varshape " << variable.m_GlobalDimensions.size() << endl; - std::cout << "offset " << variable.m_GlobalOffsets.size() << endl; - for (int i = 0; i < m_SizeMPI; ++i) - { - if (i == m_RankMPI) + // here comes your magic at Writing now variable.m_UserValues has the + // data + // passed by the user + // set variable + variable.m_AppValues = values; + m_WrittenVariables.insert(variable.m_Name); + + // This part will go away, this is just to monitor variables per rank + + json jmsg; + jmsg["doid"] = m_Name; + jmsg["var"] = variable.m_Name; + jmsg["dtype"] = GetType<T>(); + jmsg["putshape"] = variable.m_Dimensions; + if (variable.m_GlobalDimensions.size() == 0) + variable.m_GlobalDimensions = variable.m_Dimensions; + jmsg["varshape"] = variable.m_GlobalDimensions; + if (variable.m_GlobalOffsets.size() == 0) + variable.m_GlobalOffsets.assign(variable.m_Dimensions.size(), 0); + jmsg["offset"] = variable.m_GlobalOffsets; + jmsg["timestep"] = 0; + m_Man.put(values, jmsg); + + if (m_DoMonitor) { - std::cout << "Rank: " << m_RankMPI << "\n"; - variable.Monitor(std::cout); - std::cout << std::endl; + MPI_Barrier(m_MPIComm); + std::cout << "I am hooked to the DataMan library\n"; + std::cout << "putshape " << variable.m_Dimensions.size() << endl; + std::cout << "varshape " << variable.m_GlobalDimensions.size() + << endl; + std::cout << "offset " << variable.m_GlobalOffsets.size() << endl; + for (int i = 0; i < m_SizeMPI; ++i) + { + if (i == m_RankMPI) + { + std::cout << "Rank: " << m_RankMPI << "\n"; + variable.Monitor(std::cout); + std::cout << std::endl; + } + else + { + sleep(1); + } + } + MPI_Barrier(m_MPIComm); } - else - { - sleep(1); - } - } - MPI_Barrier(m_MPIComm); } - } }; } // end namespace adios diff --git a/include/format/BP1.h b/include/format/BP1.h index fd2e16a4a3bb872631d0053baea7cba40ca7c29f..518325ecdbabfa44403bb3306853a101fccdaa82 100644 --- a/include/format/BP1.h +++ b/include/format/BP1.h @@ -35,15 +35,15 @@ namespace format */ struct BP1Index { - std::vector<char> Buffer; ///< metadata variable index, start with 100Kb - std::uint64_t Count = - 0; ///< number of characteristics sets (time and spatial aggregation) - const std::uint32_t MemberID; - - BP1Index(const std::uint32_t memberID) : MemberID{memberID} - { - Buffer.reserve(500); - } + std::vector<char> Buffer; ///< metadata variable index, start with 100Kb + std::uint64_t Count = 0; ///< number of characteristics sets (time and + /// spatial aggregation) + const std::uint32_t MemberID; + + BP1Index(const std::uint32_t memberID) : MemberID{memberID} + { + Buffer.reserve(500); + } }; /** @@ -51,36 +51,39 @@ struct BP1Index */ struct BP1MetadataSet { - std::uint32_t TimeStep; ///< current time step, updated with advance step, if - /// append it will be updated to last, starts with one - /// in ADIOS1 - - BP1Index PGIndex = BP1Index(0); ///< single buffer for PGIndex - - // no priority for now - std::unordered_map<std::string, BP1Index> - VarsIndices; ///< key: variable name, value: bp metadata variable index - std::unordered_map<std::string, BP1Index> AttributesIndices; ///< key: - /// attribute - /// name, value: - /// bp metadata - /// attribute - /// index - - const unsigned int MiniFooterSize = 28; ///< from bpls reader - - // PG (relative) positions in Data buffer to be updated - std::uint64_t DataPGCount = 0; - std::size_t DataPGLengthPosition = 0; ///< current PG initial ( relative ) - /// position, needs to be updated in - /// every advance step or init - std::uint32_t DataPGVarsCount = 0; ///< variables in current PG - std::size_t DataPGVarsCountPosition = - 0; ///< current PG variable count ( relative ) position, needs to be - /// updated in every advance step or init - bool DataPGIsOpen = false; - - Profiler Log; ///< object that takes buffering profiling info + std::uint32_t + TimeStep; ///< current time step, updated with advance step, if + /// append it will be updated to last, starts with one + /// in ADIOS1 + + BP1Index PGIndex = BP1Index(0); ///< single buffer for PGIndex + + // no priority for now + std::unordered_map<std::string, BP1Index> VarsIndices; ///< key: variable + /// name, value: bp + /// metadata variable + /// index + std::unordered_map<std::string, BP1Index> AttributesIndices; ///< key: + /// attribute + /// name, value: + /// bp metadata + /// attribute + /// index + + const unsigned int MiniFooterSize = 28; ///< from bpls reader + + // PG (relative) positions in Data buffer to be updated + std::uint64_t DataPGCount = 0; + std::size_t DataPGLengthPosition = 0; ///< current PG initial ( relative ) + /// position, needs to be updated in + /// every advance step or init + std::uint32_t DataPGVarsCount = 0; ///< variables in current PG + std::size_t DataPGVarsCountPosition = + 0; ///< current PG variable count ( relative ) position, needs to be + /// updated in every advance step or init + bool DataPGIsOpen = false; + + Profiler Log; ///< object that takes buffering profiling info }; /** @@ -90,228 +93,228 @@ class BP1 { public: - /** - * Checks if input name has .bp extension and returns a .bp directory name - * @param name input (might or not have .bp) - * @return either name.bp (name has no .bp) or name (name has .bp extension) - */ - std::string GetDirectoryName(const std::string name) const noexcept; - - /** - * Opens rank files in the following format: - * if transport.m_MPIComm different from MPI_Comm_SELF --> - * name.bp.dir/name.bp.rank - * @param name might contain .bp or not, if not .bp will be added - * @param accessMode "write" "w", "r" "read", "append" "a" - * @param transport file I/O transport - */ - void OpenRankFiles(const std::string name, const std::string accessMode, - Transport &transport) const; + /** + * Checks if input name has .bp extension and returns a .bp directory name + * @param name input (might or not have .bp) + * @return either name.bp (name has no .bp) or name (name has .bp extension) + */ + std::string GetDirectoryName(const std::string name) const noexcept; + + /** + * Opens rank files in the following format: + * if transport.m_MPIComm different from MPI_Comm_SELF --> + * name.bp.dir/name.bp.rank + * @param name might contain .bp or not, if not .bp will be added + * @param accessMode "write" "w", "r" "read", "append" "a" + * @param transport file I/O transport + */ + void OpenRankFiles(const std::string name, const std::string accessMode, + Transport &transport) const; protected: - /** - * method type for file I/O - */ - enum IO_METHOD - { - METHOD_UNKNOWN = -2 //!< ADIOS_METHOD_UNKNOWN - , - METHOD_NULL = -1 //!< ADIOS_METHOD_NULL - , - METHOD_MPI = 0 //!< METHOD_MPI - , - METHOD_DATATAP = 1 // OBSOLETE - , - METHOD_POSIX = 2 //!< METHOD_POSIX - , - METHOD_DATASPACES = 3 //!< METHOD_DATASPACES - , - METHOD_VTK = 4 // non-existent - , - METHOD_POSIX_ASCII = 5 // non-existent - , - METHOD_MPI_CIO = 6 // OBSOLETE - , - METHOD_PHDF5 = 7 //!< METHOD_PHDF5 - , - METHOD_PROVENANCE = 8 // OBSOLETE - , - METHOD_MPI_STRIPE = 9 // OBSOLETE - , - METHOD_MPI_LUSTRE = 10 //!< METHOD_MPI_LUSTRE - , - METHOD_MPI_STAGGER = 11 // OBSOLETE - , - METHOD_MPI_AGG = 12 // OBSOLETE - , - METHOD_ADAPTIVE = 13 // OBSOLETE - , - METHOD_POSIX1 = 14 // OBSOLETE - , - METHOD_NC4 = 15 //!< METHOD_NC4 - , - METHOD_MPI_AMR = 16 //!< METHOD_MPI_AMR - , - METHOD_MPI_AMR1 = 17 // OBSOLETE - , - METHOD_FLEXPATH = 18 //!< METHOD_FLEXPATH - , - METHOD_NSSI_STAGING = 19 //!< METHOD_NSSI_STAGING - , - METHOD_NSSI_FILTER = 20 //!< METHOD_NSSI_FILTER - , - METHOD_DIMES = 21 //!< METHOD_DIMES - , - METHOD_VAR_MERGE = 22 //!< METHOD_VAR_MERGE - , - METHOD_MPI_BGQ = 23 //!< METHOD_MPI_BGQ - , - METHOD_ICEE = 24 //!< METHOD_ICEE - , - METHOD_COUNT = 25 //!< METHOD_COUNT - , - METHOD_FSTREAM = 26, - METHOD_FILE = 27, - METHOD_ZMQ = 28, - METHOD_MDTM = 29 - }; - - /** - * DataTypes mapping in BP Format - */ - enum DataTypes - { - type_unknown = -1, //!< type_unknown - type_byte = 0, //!< type_byte - type_short = 1, //!< type_short - type_integer = 2, //!< type_integer - type_long = 4, //!< type_long - - type_unsigned_byte = 50, //!< type_unsigned_byte - type_unsigned_short = 51, //!< type_unsigned_short - type_unsigned_integer = 52, //!< type_unsigned_integer - type_unsigned_long = 54, //!< type_unsigned_long - - type_real = 5, //!< type_real or float - type_double = 6, //!< type_double - type_long_double = 7, //!< type_long_double - - type_string = 9, //!< type_string - type_complex = 10, //!< type_complex - type_double_complex = 11, //!< type_double_complex - type_string_array = 12 //!< type_string_array - }; - - /** - * Characteristic ID in variable metadata - */ - enum VariableCharacteristicID - { - characteristic_value = 0, //!< characteristic_value - characteristic_min = 1, //!< Used to read in older bp file format - characteristic_max = 2, //!< Used to read in older bp file format - characteristic_offset = 3, //!< characteristic_offset - characteristic_dimensions = 4, //!< characteristic_dimensions - characteristic_var_id = 5, //!< characteristic_var_id - characteristic_payload_offset = 6, //!< characteristic_payload_offset - characteristic_file_index = 7, //!< characteristic_file_index - characteristic_time_index = 8, //!< characteristic_time_index - characteristic_bitmap = 9, //!< characteristic_bitmap - characteristic_stat = 10, //!< characteristic_stat - characteristic_transform_type = 11 //!< characteristic_transform_type - }; - - /** Define statistics type for characteristic ID = 10 in bp1 format */ - enum VariableStatistics - { - statistic_min = 0, - statistic_max = 1, - statistic_cnt = 2, - statistic_sum = 3, - statistic_sum_square = 4, - statistic_hist = 5, - statistic_finite = 6 - }; - - template <class T> struct Stats - { - T Min; - T Max; - std::uint64_t Offset; - std::uint64_t PayloadOffset; - std::uint32_t TimeIndex; - std::uint32_t MemberID; - - // unsigned long int count; - // long double sum; - // long double sumSquare; - // unsigned long int histogram - // bool finite?? - }; - - /** - * Returns data type index from enum Datatypes - * @param variable input variable - * @return data type - */ - template <class T> inline std::int8_t GetDataType() const noexcept - { - return type_unknown; - } - - std::vector<std::uint8_t> - GetMethodIDs(const std::vector<std::shared_ptr<Transport>> &transports) const - noexcept; + /** + * method type for file I/O + */ + enum IO_METHOD + { + METHOD_UNKNOWN = -2 //!< ADIOS_METHOD_UNKNOWN + , + METHOD_NULL = -1 //!< ADIOS_METHOD_NULL + , + METHOD_MPI = 0 //!< METHOD_MPI + , + METHOD_DATATAP = 1 // OBSOLETE + , + METHOD_POSIX = 2 //!< METHOD_POSIX + , + METHOD_DATASPACES = 3 //!< METHOD_DATASPACES + , + METHOD_VTK = 4 // non-existent + , + METHOD_POSIX_ASCII = 5 // non-existent + , + METHOD_MPI_CIO = 6 // OBSOLETE + , + METHOD_PHDF5 = 7 //!< METHOD_PHDF5 + , + METHOD_PROVENANCE = 8 // OBSOLETE + , + METHOD_MPI_STRIPE = 9 // OBSOLETE + , + METHOD_MPI_LUSTRE = 10 //!< METHOD_MPI_LUSTRE + , + METHOD_MPI_STAGGER = 11 // OBSOLETE + , + METHOD_MPI_AGG = 12 // OBSOLETE + , + METHOD_ADAPTIVE = 13 // OBSOLETE + , + METHOD_POSIX1 = 14 // OBSOLETE + , + METHOD_NC4 = 15 //!< METHOD_NC4 + , + METHOD_MPI_AMR = 16 //!< METHOD_MPI_AMR + , + METHOD_MPI_AMR1 = 17 // OBSOLETE + , + METHOD_FLEXPATH = 18 //!< METHOD_FLEXPATH + , + METHOD_NSSI_STAGING = 19 //!< METHOD_NSSI_STAGING + , + METHOD_NSSI_FILTER = 20 //!< METHOD_NSSI_FILTER + , + METHOD_DIMES = 21 //!< METHOD_DIMES + , + METHOD_VAR_MERGE = 22 //!< METHOD_VAR_MERGE + , + METHOD_MPI_BGQ = 23 //!< METHOD_MPI_BGQ + , + METHOD_ICEE = 24 //!< METHOD_ICEE + , + METHOD_COUNT = 25 //!< METHOD_COUNT + , + METHOD_FSTREAM = 26, + METHOD_FILE = 27, + METHOD_ZMQ = 28, + METHOD_MDTM = 29 + }; + + /** + * DataTypes mapping in BP Format + */ + enum DataTypes + { + type_unknown = -1, //!< type_unknown + type_byte = 0, //!< type_byte + type_short = 1, //!< type_short + type_integer = 2, //!< type_integer + type_long = 4, //!< type_long + + type_unsigned_byte = 50, //!< type_unsigned_byte + type_unsigned_short = 51, //!< type_unsigned_short + type_unsigned_integer = 52, //!< type_unsigned_integer + type_unsigned_long = 54, //!< type_unsigned_long + + type_real = 5, //!< type_real or float + type_double = 6, //!< type_double + type_long_double = 7, //!< type_long_double + + type_string = 9, //!< type_string + type_complex = 10, //!< type_complex + type_double_complex = 11, //!< type_double_complex + type_string_array = 12 //!< type_string_array + }; + + /** + * Characteristic ID in variable metadata + */ + enum VariableCharacteristicID + { + characteristic_value = 0, //!< characteristic_value + characteristic_min = 1, //!< Used to read in older bp file format + characteristic_max = 2, //!< Used to read in older bp file format + characteristic_offset = 3, //!< characteristic_offset + characteristic_dimensions = 4, //!< characteristic_dimensions + characteristic_var_id = 5, //!< characteristic_var_id + characteristic_payload_offset = 6, //!< characteristic_payload_offset + characteristic_file_index = 7, //!< characteristic_file_index + characteristic_time_index = 8, //!< characteristic_time_index + characteristic_bitmap = 9, //!< characteristic_bitmap + characteristic_stat = 10, //!< characteristic_stat + characteristic_transform_type = 11 //!< characteristic_transform_type + }; + + /** Define statistics type for characteristic ID = 10 in bp1 format */ + enum VariableStatistics + { + statistic_min = 0, + statistic_max = 1, + statistic_cnt = 2, + statistic_sum = 3, + statistic_sum_square = 4, + statistic_hist = 5, + statistic_finite = 6 + }; + + template <class T> struct Stats + { + T Min; + T Max; + std::uint64_t Offset; + std::uint64_t PayloadOffset; + std::uint32_t TimeIndex; + std::uint32_t MemberID; + + // unsigned long int count; + // long double sum; + // long double sumSquare; + // unsigned long int histogram + // bool finite?? + }; + + /** + * Returns data type index from enum Datatypes + * @param variable input variable + * @return data type + */ + template <class T> inline std::int8_t GetDataType() const noexcept + { + return type_unknown; + } + + std::vector<std::uint8_t> GetMethodIDs( + const std::vector<std::shared_ptr<Transport>> &transports) const + noexcept; }; // Moving template BP1Writer::GetDataType template specializations outside of // the class template <> inline std::int8_t BP1::GetDataType<char>() const noexcept { - return type_byte; + return type_byte; } template <> inline std::int8_t BP1::GetDataType<short>() const noexcept { - return type_short; + return type_short; } template <> inline std::int8_t BP1::GetDataType<int>() const noexcept { - return type_integer; + return type_integer; } template <> inline std::int8_t BP1::GetDataType<long int>() const noexcept { - return type_long; + return type_long; } template <> inline std::int8_t BP1::GetDataType<unsigned char>() const noexcept { - return type_unsigned_byte; + return type_unsigned_byte; } template <> inline std::int8_t BP1::GetDataType<unsigned short>() const noexcept { - return type_unsigned_short; + return type_unsigned_short; } template <> inline std::int8_t BP1::GetDataType<unsigned int>() const noexcept { - return type_unsigned_integer; + return type_unsigned_integer; } template <> inline std::int8_t BP1::GetDataType<unsigned long int>() const noexcept { - return type_unsigned_long; + return type_unsigned_long; } template <> inline std::int8_t BP1::GetDataType<float>() const noexcept { - return type_real; + return type_real; } template <> inline std::int8_t BP1::GetDataType<double>() const noexcept { - return type_double; + return type_double; } template <> inline std::int8_t BP1::GetDataType<long double>() const noexcept { - return type_long_double; + return type_long_double; } } // end namespace format diff --git a/include/format/BP1Aggregator.h b/include/format/BP1Aggregator.h index a8cf13372fd7b105b0d59967498af1589fd55c18..0522975a19d843c929deeffc3c0c9076ca23779b 100644 --- a/include/format/BP1Aggregator.h +++ b/include/format/BP1Aggregator.h @@ -25,28 +25,29 @@ class BP1Aggregator { public: - MPI_Comm m_MPIComm = MPI_COMM_SELF; ///< MPI communicator from Engine - int m_RankMPI = 0; ///< current MPI rank process - int m_SizeMPI = 1; ///< current MPI processes size - - /** - * Unique constructor - * @param mpiComm coming from engine - */ - BP1Aggregator(MPI_Comm mpiComm, const bool debugMode = false); - - ~BP1Aggregator(); - - /** - * Function that aggregates and writes (from rank = 0) profiling.log in python - * dictionary format - * @param rankLog contain rank profiling info to be aggregated - */ - void WriteProfilingLog(const std::string fileName, - const std::string &rankLog); + MPI_Comm m_MPIComm = MPI_COMM_SELF; ///< MPI communicator from Engine + int m_RankMPI = 0; ///< current MPI rank process + int m_SizeMPI = 1; ///< current MPI processes size + + /** + * Unique constructor + * @param mpiComm coming from engine + */ + BP1Aggregator(MPI_Comm mpiComm, const bool debugMode = false); + + ~BP1Aggregator(); + + /** + * Function that aggregates and writes (from rank = 0) profiling.log in + * python + * dictionary format + * @param rankLog contain rank profiling info to be aggregated + */ + void WriteProfilingLog(const std::string fileName, + const std::string &rankLog); private: - const bool m_DebugMode = false; + const bool m_DebugMode = false; }; } // end namespace format diff --git a/include/format/BP1Writer.h b/include/format/BP1Writer.h index 1a08598a4b2a4fa55c8b2ce86301eeb20354dc38..765961978bcb4c5a15040981e342b87ac865e996 100644 --- a/include/format/BP1Writer.h +++ b/include/format/BP1Writer.h @@ -34,487 +34,502 @@ class BP1Writer : public BP1 { public: - unsigned int m_Threads = - 1; ///< number of threads for thread operations in large array (min,max) - unsigned int m_Verbosity = - 0; ///< statistics verbosity, can change if redefined in Engine method. - float m_GrowthFactor = - 1.5; ///< memory growth factor, can change if redefined in Engine method. - const std::uint8_t m_Version = 3; ///< BP format version - - /** - * Calculates the Process Index size in bytes according to the BP format, - * including list of method with no parameters (for now) - * @param name - * @param timeStepName - * @param numberOfTransports - * @return size of pg index - */ - std::size_t - GetProcessGroupIndexSize(const std::string name, - const std::string timeStepName, - const std::size_t numberOfTransports) const noexcept; - - /** - * Writes a process group index PGIndex and list of methods (from transports), - * done at Open or aggregation of new time step - * Version that operates on a single heap buffer and metadataset. - * @param isFortran - * @param name - * @param processID - * @param transports - * @param buffer - * @param metadataSet - */ - void WriteProcessGroupIndex( - const bool isFortran, const std::string name, - const std::uint32_t processID, - const std::vector<std::shared_ptr<Transport>> &transports, - capsule::STLVector &heap, BP1MetadataSet &metadataSet) const noexcept; - - /** - * Returns the estimated variable index size - * @param group - * @param variableName - * @param variable - * @param verbosity - * @return variable index size - */ - template <class T> - size_t GetVariableIndexSize(const Variable<T> &variable) const noexcept - { - // size_t indexSize = varEntryLength + memberID + lengthGroupName + - // groupName + lengthVariableName + lengthOfPath + path + datatype - size_t indexSize = 23; // without characteristics - indexSize += variable.m_Name.size(); - - // characteristics 3 and 4, check variable number of dimensions - const std::size_t dimensions = - variable.DimensionsSize(); // number of commas in CSV + 1 - indexSize += 28 * dimensions; // 28 bytes per dimension - indexSize += 1; // id - - // characteristics, offset + payload offset in data - indexSize += 2 * (1 + 8); - // characteristic 0, if scalar add value, for now only allowing string - if (dimensions == 1) + unsigned int m_Threads = 1; ///< number of threads for thread operations in + /// large array (min,max) + unsigned int m_Verbosity = 0; ///< statistics verbosity, can change if + /// redefined in Engine method. + float m_GrowthFactor = 1.5; ///< memory growth factor, can change if + /// redefined in Engine method. + const std::uint8_t m_Version = 3; ///< BP format version + + /** + * Calculates the Process Index size in bytes according to the BP format, + * including list of method with no parameters (for now) + * @param name + * @param timeStepName + * @param numberOfTransports + * @return size of pg index + */ + std::size_t GetProcessGroupIndexSize( + const std::string name, const std::string timeStepName, + const std::size_t numberOfTransports) const noexcept; + + /** + * Writes a process group index PGIndex and list of methods (from + * transports), + * done at Open or aggregation of new time step + * Version that operates on a single heap buffer and metadataset. + * @param isFortran + * @param name + * @param processID + * @param transports + * @param buffer + * @param metadataSet + */ + void WriteProcessGroupIndex( + const bool isFortran, const std::string name, + const std::uint32_t processID, + const std::vector<std::shared_ptr<Transport>> &transports, + capsule::STLVector &heap, BP1MetadataSet &metadataSet) const noexcept; + + /** + * Returns the estimated variable index size + * @param group + * @param variableName + * @param variable + * @param verbosity + * @return variable index size + */ + template <class T> + size_t GetVariableIndexSize(const Variable<T> &variable) const noexcept { - indexSize += sizeof(T); - indexSize += 1; // id - // must have an if here - indexSize += 2 + variable.m_Name.size(); - indexSize += 1; // id + // size_t indexSize = varEntryLength + memberID + lengthGroupName + + // groupName + lengthVariableName + lengthOfPath + path + datatype + size_t indexSize = 23; // without characteristics + indexSize += variable.m_Name.size(); + + // characteristics 3 and 4, check variable number of dimensions + const std::size_t dimensions = + variable.DimensionsSize(); // number of commas in CSV + 1 + indexSize += 28 * dimensions; // 28 bytes per dimension + indexSize += 1; // id + + // characteristics, offset + payload offset in data + indexSize += 2 * (1 + 8); + // characteristic 0, if scalar add value, for now only allowing string + if (dimensions == 1) + { + indexSize += sizeof(T); + indexSize += 1; // id + // must have an if here + indexSize += 2 + variable.m_Name.size(); + indexSize += 1; // id + } + + // characteristic statistics + if (m_Verbosity == 0) // default, only min and max + { + indexSize += 2 * (sizeof(T) + 1); + indexSize += 1 + 1; // id + } + + return indexSize + 12; /// extra 12 bytes in case of attributes + // need to add transform characteristics } - // characteristic statistics - if (m_Verbosity == 0) // default, only min and max + /** + * Version for primitive types (except std::complex<T>) + * @param variable + * @param heap + * @param metadataSet + */ + template <class T> + inline void WriteVariableMetadata(const Variable<T> &variable, + capsule::STLVector &heap, + BP1MetadataSet &metadataSet) const + noexcept { - indexSize += 2 * (sizeof(T) + 1); - indexSize += 1 + 1; // id + Stats<T> stats = GetStats(variable); + WriteVariableMetadataCommon(variable, stats, heap, metadataSet); } - return indexSize + 12; /// extra 12 bytes in case of attributes - // need to add transform characteristics - } - - /** - * Version for primitive types (except std::complex<T>) - * @param variable - * @param heap - * @param metadataSet - */ - template <class T> - inline void WriteVariableMetadata(const Variable<T> &variable, - capsule::STLVector &heap, - BP1MetadataSet &metadataSet) const noexcept - { - Stats<T> stats = GetStats(variable); - WriteVariableMetadataCommon(variable, stats, heap, metadataSet); - } - - /** - * Overloaded version for std::complex<T> variables - * @param variable - * @param heap - * @param metadataSet - */ - template <class T> - void WriteVariableMetadata(const Variable<std::complex<T>> &variable, - capsule::STLVector &heap, - BP1MetadataSet &metadataSet) const noexcept - { - Stats<T> stats = GetStats(variable); - WriteVariableMetadataCommon(variable, stats, heap, metadataSet); - } - - /** - * Expensive part this is only for heap buffers need to adapt to vector of - * capsules - * @param variable - * @param buffer - */ - template <class T> - void WriteVariablePayload(const Variable<T> &variable, - capsule::STLVector &heap, - const unsigned int nthreads = 1) const noexcept - { - // EXPENSIVE part, might want to use threads if large, serial for now - CopyToBuffer(heap.m_Data, variable.m_AppValues, variable.TotalSize()); - heap.m_DataAbsolutePosition += variable.PayLoadSize(); - } - - void Advance(BP1MetadataSet &metadataSet, capsule::STLVector &buffer); - - /** - * Function that sets metadata (if first close) and writes to a single - * transport - * @param metadataSet current rank metadata set - * @param heap contains data buffer - * @param transport does a write after data and metadata is setup - * @param isFirstClose true: metadata has been set and aggregated - * @param doAggregation true: for N-to-M, false: for N-to-N - */ - void Close(BP1MetadataSet &metadataSet, capsule::STLVector &heap, - Transport &transport, bool &isFirstClose, - const bool doAggregation) const noexcept; - - /** - * Writes the ADIOS log information (buffering, open, write and close) for a - * rank process - * @param rank current rank - * @param metadataSet contains Profile info for buffering - * @param transports contains Profile info for transport open, writes and - * close - * @return string for this rank that will be aggregated into profiling.log - */ - std::string GetRankProfilingLog( - const int rank, const BP1MetadataSet &metadataSet, - const std::vector<std::shared_ptr<Transport>> &transports) const noexcept; + /** + * Overloaded version for std::complex<T> variables + * @param variable + * @param heap + * @param metadataSet + */ + template <class T> + void WriteVariableMetadata(const Variable<std::complex<T>> &variable, + capsule::STLVector &heap, + BP1MetadataSet &metadataSet) const noexcept + { + Stats<T> stats = GetStats(variable); + WriteVariableMetadataCommon(variable, stats, heap, metadataSet); + } -private: - template <class T, class U> - void WriteVariableMetadataCommon(const Variable<T> &variable, Stats<U> &stats, - capsule::STLVector &heap, - BP1MetadataSet &metadataSet) const noexcept - { - stats.TimeIndex = metadataSet.TimeStep; - - // Get new Index or point to existing index - bool isNew = true; // flag to check if variable is new - BP1Index &varIndex = - GetBP1Index(variable.m_Name, metadataSet.VarsIndices, isNew); - stats.MemberID = varIndex.MemberID; - - // write metadata header in data and extract offsets - stats.Offset = heap.m_DataAbsolutePosition; - WriteVariableMetadataInData(variable, stats, heap); - stats.PayloadOffset = heap.m_DataAbsolutePosition; - - // write to metadata index - WriteVariableMetadataInIndex(variable, stats, isNew, varIndex); - - ++metadataSet.DataPGVarsCount; - } - - template <class T, class U> - void WriteVariableMetadataInData(const Variable<T> &variable, - const Stats<U> &stats, - capsule::STLVector &heap) const noexcept - { - auto &buffer = heap.m_Data; - - const std::size_t varLengthPosition = - buffer.size(); // capture initial position for variable length - buffer.insert(buffer.end(), 8, 0); // skip var length (8) - CopyToBuffer(buffer, &stats.MemberID); // memberID - WriteNameRecord(variable.m_Name, buffer); // variable name - buffer.insert(buffer.end(), 2, 0); // skip path - const std::uint8_t dataType = GetDataType<T>(); // dataType - CopyToBuffer(buffer, &dataType); - constexpr char no = 'n'; // isDimension - CopyToBuffer(buffer, &no); - - // write variable dimensions - const std::uint8_t dimensions = variable.m_Dimensions.size(); - CopyToBuffer(buffer, &dimensions); // count - std::uint16_t dimensionsLength = - 27 * dimensions; // 27 is from 9 bytes for each: var y/n + local, var - // y/n + global dimension, var y/n + global offset, - // changed for characteristic - CopyToBuffer(buffer, &dimensionsLength); // length - WriteDimensionsRecord(buffer, variable.m_Dimensions, - variable.m_GlobalDimensions, variable.m_GlobalOffsets, - 18, true); - - // CHARACTERISTICS - WriteVariableCharacteristics(variable, stats, buffer, true); - - // Back to varLength including payload size - const std::uint64_t varLength = buffer.size() - varLengthPosition + - variable.PayLoadSize() - - 8; // remove its own size - CopyToBuffer(buffer, varLengthPosition, &varLength); // length - - heap.m_DataAbsolutePosition += - buffer.size() - varLengthPosition; // update absolute position to be - // used as payload position - } - - template <class T, class U> - void WriteVariableMetadataInIndex(const Variable<T> &variable, - const Stats<U> &stats, const bool isNew, - BP1Index &index) const noexcept - { - auto &buffer = index.Buffer; - - if (isNew == - true) // write variable header (might be shared with attributes index) + /** + * Expensive part this is only for heap buffers need to adapt to vector of + * capsules + * @param variable + * @param buffer + */ + template <class T> + void WriteVariablePayload(const Variable<T> &variable, + capsule::STLVector &heap, + const unsigned int nthreads = 1) const noexcept { - buffer.insert(buffer.end(), 4, 0); // skip var length (4) - CopyToBuffer(buffer, &stats.MemberID); - buffer.insert(buffer.end(), 2, 0); // skip group name - WriteNameRecord(variable.m_Name, buffer); - buffer.insert(buffer.end(), 2, 0); // skip path - - const std::uint8_t dataType = GetDataType<T>(); - CopyToBuffer(buffer, &dataType); - - // Characteristics Sets Count in Metadata - index.Count = 1; - CopyToBuffer(buffer, &index.Count); + // EXPENSIVE part, might want to use threads if large, serial for now + CopyToBuffer(heap.m_Data, variable.m_AppValues, variable.TotalSize()); + heap.m_DataAbsolutePosition += variable.PayLoadSize(); } - else // update characteristics sets count + + void Advance(BP1MetadataSet &metadataSet, capsule::STLVector &buffer); + + /** + * Function that sets metadata (if first close) and writes to a single + * transport + * @param metadataSet current rank metadata set + * @param heap contains data buffer + * @param transport does a write after data and metadata is setup + * @param isFirstClose true: metadata has been set and aggregated + * @param doAggregation true: for N-to-M, false: for N-to-N + */ + void Close(BP1MetadataSet &metadataSet, capsule::STLVector &heap, + Transport &transport, bool &isFirstClose, + const bool doAggregation) const noexcept; + + /** + * Writes the ADIOS log information (buffering, open, write and close) for a + * rank process + * @param rank current rank + * @param metadataSet contains Profile info for buffering + * @param transports contains Profile info for transport open, writes and + * close + * @return string for this rank that will be aggregated into profiling.log + */ + std::string GetRankProfilingLog( + const int rank, const BP1MetadataSet &metadataSet, + const std::vector<std::shared_ptr<Transport>> &transports) const + noexcept; + +private: + template <class T, class U> + void WriteVariableMetadataCommon(const Variable<T> &variable, + Stats<U> &stats, capsule::STLVector &heap, + BP1MetadataSet &metadataSet) const noexcept { - const std::size_t characteristicsSetsCountPosition = - 15 + variable.m_Name.size(); - ++index.Count; - CopyToBuffer(buffer, characteristicsSetsCountPosition, - &index.Count); // test + stats.TimeIndex = metadataSet.TimeStep; + + // Get new Index or point to existing index + bool isNew = true; // flag to check if variable is new + BP1Index &varIndex = + GetBP1Index(variable.m_Name, metadataSet.VarsIndices, isNew); + stats.MemberID = varIndex.MemberID; + + // write metadata header in data and extract offsets + stats.Offset = heap.m_DataAbsolutePosition; + WriteVariableMetadataInData(variable, stats, heap); + stats.PayloadOffset = heap.m_DataAbsolutePosition; + + // write to metadata index + WriteVariableMetadataInIndex(variable, stats, isNew, varIndex); + + ++metadataSet.DataPGVarsCount; } - WriteVariableCharacteristics(variable, stats, buffer); - } - - template <class T, class U> - void WriteVariableCharacteristics(const Variable<T> &variable, - const Stats<U> &stats, - std::vector<char> &buffer, - const bool addLength = false) const noexcept - { - const std::size_t characteristicsCountPosition = - buffer.size(); // very important to track as writer is going back to - // this position - buffer.insert(buffer.end(), 5, - 0); // skip characteristics count(1) + length (4) - std::uint8_t characteristicsCounter = 0; - - // DIMENSIONS - std::uint8_t characteristicID = characteristic_dimensions; - CopyToBuffer(buffer, &characteristicID); - const std::uint8_t dimensions = variable.m_Dimensions.size(); - - if (addLength == true) + template <class T, class U> + void WriteVariableMetadataInData(const Variable<T> &variable, + const Stats<U> &stats, + capsule::STLVector &heap) const noexcept { - const std::int16_t lengthOfDimensionsCharacteristic = - 24 * dimensions + - 3; // 24 = 3 local, global, global offset x 8 bytes/each - CopyToBuffer(buffer, &lengthOfDimensionsCharacteristic); + auto &buffer = heap.m_Data; + + const std::size_t varLengthPosition = + buffer.size(); // capture initial position for variable length + buffer.insert(buffer.end(), 8, 0); // skip var length (8) + CopyToBuffer(buffer, &stats.MemberID); // memberID + WriteNameRecord(variable.m_Name, buffer); // variable name + buffer.insert(buffer.end(), 2, 0); // skip path + const std::uint8_t dataType = GetDataType<T>(); // dataType + CopyToBuffer(buffer, &dataType); + constexpr char no = 'n'; // isDimension + CopyToBuffer(buffer, &no); + + // write variable dimensions + const std::uint8_t dimensions = variable.m_Dimensions.size(); + CopyToBuffer(buffer, &dimensions); // count + std::uint16_t dimensionsLength = + 27 * + dimensions; // 27 is from 9 bytes for each: var y/n + local, var + // y/n + global dimension, var y/n + global offset, + // changed for characteristic + CopyToBuffer(buffer, &dimensionsLength); // length + WriteDimensionsRecord(buffer, variable.m_Dimensions, + variable.m_GlobalDimensions, + variable.m_GlobalOffsets, 18, true); + + // CHARACTERISTICS + WriteVariableCharacteristics(variable, stats, buffer, true); + + // Back to varLength including payload size + const std::uint64_t varLength = buffer.size() - varLengthPosition + + variable.PayLoadSize() - + 8; // remove its own size + CopyToBuffer(buffer, varLengthPosition, &varLength); // length + + heap.m_DataAbsolutePosition += + buffer.size() - varLengthPosition; // update absolute position to be + // used as payload position } - CopyToBuffer(buffer, &dimensions); // count - const std::uint16_t dimensionsLength = 24 * dimensions; - CopyToBuffer(buffer, &dimensionsLength); // length - WriteDimensionsRecord(buffer, variable.m_Dimensions, - variable.m_GlobalDimensions, variable.m_GlobalOffsets, - 16, addLength); - ++characteristicsCounter; - - // VALUE for SCALAR or STAT min, max for ARRAY - WriteBoundsRecord(variable.m_IsScalar, stats, buffer, - characteristicsCounter, addLength); - // TIME INDEX - WriteCharacteristicRecord(characteristic_time_index, stats.TimeIndex, - buffer, characteristicsCounter, addLength); - - if (addLength == false) // only in metadata offset and payload offset + template <class T, class U> + void WriteVariableMetadataInIndex(const Variable<T> &variable, + const Stats<U> &stats, const bool isNew, + BP1Index &index) const noexcept { - WriteCharacteristicRecord(characteristic_offset, stats.Offset, buffer, - characteristicsCounter); - WriteCharacteristicRecord(characteristic_payload_offset, - stats.PayloadOffset, buffer, - characteristicsCounter); + auto &buffer = index.Buffer; + + if (isNew == true) // write variable header (might be shared with + // attributes index) + { + buffer.insert(buffer.end(), 4, 0); // skip var length (4) + CopyToBuffer(buffer, &stats.MemberID); + buffer.insert(buffer.end(), 2, 0); // skip group name + WriteNameRecord(variable.m_Name, buffer); + buffer.insert(buffer.end(), 2, 0); // skip path + + const std::uint8_t dataType = GetDataType<T>(); + CopyToBuffer(buffer, &dataType); + + // Characteristics Sets Count in Metadata + index.Count = 1; + CopyToBuffer(buffer, &index.Count); + } + else // update characteristics sets count + { + const std::size_t characteristicsSetsCountPosition = + 15 + variable.m_Name.size(); + ++index.Count; + CopyToBuffer(buffer, characteristicsSetsCountPosition, + &index.Count); // test + } + + WriteVariableCharacteristics(variable, stats, buffer); } - // END OF CHARACTERISTICS - - // Back to characteristics count and length - CopyToBuffer(buffer, characteristicsCountPosition, - &characteristicsCounter); // count (1) - const std::uint32_t characteristicsLength = - buffer.size() - characteristicsCountPosition - 4 - - 1; // remove its own length (4 bytes) + characteristic counter ( 1 byte - // ) - CopyToBuffer(buffer, characteristicsCountPosition + 1, - &characteristicsLength); // length - } - - /** - * Writes from &buffer[position]: [2 bytes:string.length()][string.length(): - * string.c_str()] - * @param name - * @param buffer - * @param position - */ - void WriteNameRecord(const std::string name, std::vector<char> &buffer) const - noexcept; - - /** - * Write a dimension record for a global variable used by WriteVariableCommon - * @param buffer - * @param position - * @param localDimensions - * @param globalDimensions - * @param globalOffsets - * @param addType true: for data buffers, false: for metadata buffer and data - * characteristic - */ - void WriteDimensionsRecord(std::vector<char> &buffer, - const std::vector<std::size_t> &localDimensions, - const std::vector<std::size_t> &globalDimensions, - const std::vector<std::size_t> &globalOffsets, - const unsigned int skip, - const bool addType = false) const noexcept; - - /** - * GetStats for primitive types except std::complex<T> types - * @param variable - * @return stats - */ - template <class T> - Stats<T> GetStats(const Variable<T> &variable) const noexcept - { - Stats<T> stats; - const std::size_t valuesSize = variable.TotalSize(); - - if (m_Verbosity == 0) + + template <class T, class U> + void WriteVariableCharacteristics(const Variable<T> &variable, + const Stats<U> &stats, + std::vector<char> &buffer, + const bool addLength = false) const + noexcept { - if (valuesSize >= 10000000) // ten million? this needs actual results - // //here we can make decisions for threads - // based on valuesSize - GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max, - m_Threads); // here we can add cores from constructor - else - GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max); + const std::size_t characteristicsCountPosition = + buffer.size(); // very important to track as writer is going + // back to + // this position + buffer.insert(buffer.end(), 5, + 0); // skip characteristics count(1) + length (4) + std::uint8_t characteristicsCounter = 0; + + // DIMENSIONS + std::uint8_t characteristicID = characteristic_dimensions; + CopyToBuffer(buffer, &characteristicID); + const std::uint8_t dimensions = variable.m_Dimensions.size(); + + if (addLength == true) + { + const std::int16_t lengthOfDimensionsCharacteristic = + 24 * dimensions + + 3; // 24 = 3 local, global, global offset x 8 bytes/each + CopyToBuffer(buffer, &lengthOfDimensionsCharacteristic); + } + + CopyToBuffer(buffer, &dimensions); // count + const std::uint16_t dimensionsLength = 24 * dimensions; + CopyToBuffer(buffer, &dimensionsLength); // length + WriteDimensionsRecord(buffer, variable.m_Dimensions, + variable.m_GlobalDimensions, + variable.m_GlobalOffsets, 16, addLength); + ++characteristicsCounter; + + // VALUE for SCALAR or STAT min, max for ARRAY + WriteBoundsRecord(variable.m_IsScalar, stats, buffer, + characteristicsCounter, addLength); + // TIME INDEX + WriteCharacteristicRecord(characteristic_time_index, stats.TimeIndex, + buffer, characteristicsCounter, addLength); + + if (addLength == false) // only in metadata offset and payload offset + { + WriteCharacteristicRecord(characteristic_offset, stats.Offset, + buffer, characteristicsCounter); + WriteCharacteristicRecord(characteristic_payload_offset, + stats.PayloadOffset, buffer, + characteristicsCounter); + } + // END OF CHARACTERISTICS + + // Back to characteristics count and length + CopyToBuffer(buffer, characteristicsCountPosition, + &characteristicsCounter); // count (1) + const std::uint32_t characteristicsLength = + buffer.size() - characteristicsCountPosition - 4 - + 1; // remove its own length (4 bytes) + characteristic counter ( + // 1 byte + // ) + CopyToBuffer(buffer, characteristicsCountPosition + 1, + &characteristicsLength); // length } - return stats; - } - - /** - * GetStats for std::complex<T> types - * @param variable - * @return stats - */ - template <class T> - Stats<T> GetStats(const Variable<std::complex<T>> &variable) const noexcept - { - Stats<T> stats; - const std::size_t valuesSize = variable.TotalSize(); - - if (m_Verbosity == 0) + + /** + * Writes from &buffer[position]: [2 + * bytes:string.length()][string.length(): + * string.c_str()] + * @param name + * @param buffer + * @param position + */ + void WriteNameRecord(const std::string name, + std::vector<char> &buffer) const noexcept; + + /** + * Write a dimension record for a global variable used by + * WriteVariableCommon + * @param buffer + * @param position + * @param localDimensions + * @param globalDimensions + * @param globalOffsets + * @param addType true: for data buffers, false: for metadata buffer and + * data + * characteristic + */ + void WriteDimensionsRecord(std::vector<char> &buffer, + const std::vector<std::size_t> &localDimensions, + const std::vector<std::size_t> &globalDimensions, + const std::vector<std::size_t> &globalOffsets, + const unsigned int skip, + const bool addType = false) const noexcept; + + /** + * GetStats for primitive types except std::complex<T> types + * @param variable + * @return stats + */ + template <class T> + Stats<T> GetStats(const Variable<T> &variable) const noexcept { - if (valuesSize >= 10000000) // ten million? this needs actual results - // //here we can make decisions for threads - // based on valuesSize - GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max, - m_Threads); // here we can add cores from constructor - else - GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max); + Stats<T> stats; + const std::size_t valuesSize = variable.TotalSize(); + + if (m_Verbosity == 0) + { + if (valuesSize >= + 10000000) // ten million? this needs actual results + // //here we can make decisions for threads + // based on valuesSize + GetMinMax(variable.m_AppValues, valuesSize, stats.Min, + stats.Max, + m_Threads); // here we can add cores from constructor + else + GetMinMax(variable.m_AppValues, valuesSize, stats.Min, + stats.Max); + } + return stats; } - return stats; - } - - template <class T> - void WriteBoundsRecord(const bool isScalar, const Stats<T> &stats, - std::vector<char> &buffer, - std::uint8_t &characteristicsCounter, - const bool addLength) const noexcept - { - if (isScalar == true) + + /** + * GetStats for std::complex<T> types + * @param variable + * @return stats + */ + template <class T> + Stats<T> GetStats(const Variable<std::complex<T>> &variable) const noexcept { - WriteCharacteristicRecord(characteristic_value, stats.Min, buffer, - characteristicsCounter, - addLength); // stats.min = stats.max = value - return; + Stats<T> stats; + const std::size_t valuesSize = variable.TotalSize(); + + if (m_Verbosity == 0) + { + if (valuesSize >= + 10000000) // ten million? this needs actual results + // //here we can make decisions for threads + // based on valuesSize + GetMinMax(variable.m_AppValues, valuesSize, stats.Min, + stats.Max, + m_Threads); // here we can add cores from constructor + else + GetMinMax(variable.m_AppValues, valuesSize, stats.Min, + stats.Max); + } + return stats; } - if (m_Verbosity == 0) // default verbose + template <class T> + void WriteBoundsRecord(const bool isScalar, const Stats<T> &stats, + std::vector<char> &buffer, + std::uint8_t &characteristicsCounter, + const bool addLength) const noexcept { - WriteCharacteristicRecord(characteristic_min, stats.Min, buffer, - characteristicsCounter, addLength); - WriteCharacteristicRecord(characteristic_max, stats.Max, buffer, - characteristicsCounter, addLength); + if (isScalar == true) + { + WriteCharacteristicRecord( + characteristic_value, stats.Min, buffer, characteristicsCounter, + addLength); // stats.min = stats.max = value + return; + } + + if (m_Verbosity == 0) // default verbose + { + WriteCharacteristicRecord(characteristic_min, stats.Min, buffer, + characteristicsCounter, addLength); + WriteCharacteristicRecord(characteristic_max, stats.Max, buffer, + characteristicsCounter, addLength); + } } - } - - /** - * Write a characteristic value record to buffer - * @param id - * @param value - * @param buffers - * @param positions - * @param characvteristicsCounter to be updated by 1 - * @param addLength true for data, false for metadata - */ - template <class T> - void WriteCharacteristicRecord(const std::uint8_t characteristicID, - const T &value, std::vector<char> &buffer, - std::uint8_t &characteristicsCounter, - const bool addLength = false) const noexcept - { - const std::uint8_t id = characteristicID; - CopyToBuffer(buffer, &id); - - if (addLength == true) + + /** + * Write a characteristic value record to buffer + * @param id + * @param value + * @param buffers + * @param positions + * @param characvteristicsCounter to be updated by 1 + * @param addLength true for data, false for metadata + */ + template <class T> + void WriteCharacteristicRecord(const std::uint8_t characteristicID, + const T &value, std::vector<char> &buffer, + std::uint8_t &characteristicsCounter, + const bool addLength = false) const noexcept { - const std::uint16_t lengthOfCharacteristic = sizeof(T); // id - CopyToBuffer(buffer, &lengthOfCharacteristic); + const std::uint8_t id = characteristicID; + CopyToBuffer(buffer, &id); + + if (addLength == true) + { + const std::uint16_t lengthOfCharacteristic = sizeof(T); // id + CopyToBuffer(buffer, &lengthOfCharacteristic); + } + + CopyToBuffer(buffer, &value); + ++characteristicsCounter; } - CopyToBuffer(buffer, &value); - ++characteristicsCounter; - } - - /** - * Returns corresponding index of type BP1Index, if doesn't exists creates a - * new one. - * Used for variables and attributes - * @param name variable or attribute name to look for index - * @param indices look up hash table of indices - * @param isNew true: index is newly created, false: index already exists in - * indices - * @return reference to BP1Index in indices - */ - BP1Index &GetBP1Index(const std::string name, - std::unordered_map<std::string, BP1Index> &indices, - bool &isNew) const noexcept; - - /** - * Flattens the data and fills the pg length, vars count, vars length and - * attributes - * @param metadataSet - * @param buffer - */ - void FlattenData(BP1MetadataSet &metadataSet, - capsule::STLVector &buffer) const noexcept; - - /** - * Flattens the metadata indices into a single metadata buffer in capsule - * @param metadataSet - * @param buffer - */ - void FlattenMetadata(BP1MetadataSet &metadataSet, - capsule::STLVector &buffer) const - noexcept; ///< sets the metadata buffer in capsule with indices and - /// minifooter + /** + * Returns corresponding index of type BP1Index, if doesn't exists creates a + * new one. + * Used for variables and attributes + * @param name variable or attribute name to look for index + * @param indices look up hash table of indices + * @param isNew true: index is newly created, false: index already exists in + * indices + * @return reference to BP1Index in indices + */ + BP1Index &GetBP1Index(const std::string name, + std::unordered_map<std::string, BP1Index> &indices, + bool &isNew) const noexcept; + + /** + * Flattens the data and fills the pg length, vars count, vars length and + * attributes + * @param metadataSet + * @param buffer + */ + void FlattenData(BP1MetadataSet &metadataSet, + capsule::STLVector &buffer) const noexcept; + + /** + * Flattens the metadata indices into a single metadata buffer in capsule + * @param metadataSet + * @param buffer + */ + void FlattenMetadata(BP1MetadataSet &metadataSet, + capsule::STLVector &buffer) const + noexcept; ///< sets the metadata buffer in capsule with indices and + /// minifooter }; } // end namespace format diff --git a/include/functions/adiosTemplates.h b/include/functions/adiosTemplates.h index 249bebf32393497319372466611b0347b6b40839..7266a6b213978bde383267ca8d2ac565ec4d01ee 100644 --- a/include/functions/adiosTemplates.h +++ b/include/functions/adiosTemplates.h @@ -32,51 +32,51 @@ template <> inline std::string GetType<void>() noexcept { return "unknown"; } template <> inline std::string GetType<char>() noexcept { return "char"; } template <> inline std::string GetType<unsigned char>() noexcept { - return "unsigned char"; + return "unsigned char"; } template <> inline std::string GetType<short>() noexcept { return "short"; } template <> inline std::string GetType<unsigned short>() noexcept { - return "unsigned short"; + return "unsigned short"; } template <> inline std::string GetType<int>() noexcept { return "int"; } template <> inline std::string GetType<unsigned int>() noexcept { - return "unsigned int"; + return "unsigned int"; } template <> inline std::string GetType<long int>() noexcept { - return "long int"; + return "long int"; } template <> inline std::string GetType<unsigned long int>() noexcept { - return "unsigned long int"; + return "unsigned long int"; } template <> inline std::string GetType<long long int>() noexcept { - return "long long int"; + return "long long int"; } template <> inline std::string GetType<unsigned long long int>() noexcept { - return "unsigned long long int"; + return "unsigned long long int"; } template <> inline std::string GetType<float>() noexcept { return "float"; } template <> inline std::string GetType<double>() noexcept { return "double"; } template <> inline std::string GetType<long double>() noexcept { - return "long double"; + return "long double"; } template <> inline std::string GetType<std::complex<float>>() noexcept { - return "float complex"; + return "float complex"; } template <> inline std::string GetType<std::complex<double>>() noexcept { - return "double complex"; + return "double complex"; } template <> inline std::string GetType<std::complex<long double>>() noexcept { - return "long double complex"; + return "long double complex"; } /** @@ -92,15 +92,15 @@ bool IsTypeAlias( const std::string type, const std::map<std::string, std::set<std::string>> &aliases) noexcept { - if (type == GetType<T>()) // most of the time we will pass the same type, - // which is a key in aliases - return true; + if (type == GetType<T>()) // most of the time we will pass the same type, + // which is a key in aliases + return true; - bool isAlias = false; - if (aliases.at(GetType<T>()).count(type) == 1) - isAlias = true; + bool isAlias = false; + if (aliases.at(GetType<T>()).count(type) == 1) + isAlias = true; - return isAlias; + return isAlias; } /** @@ -115,20 +115,20 @@ template <class T> inline void GetMinMax(const T *values, const std::size_t size, T &min, T &max, const unsigned int nthreads = 1) noexcept { - min = values[0]; - max = min; + min = values[0]; + max = min; - for (std::size_t i = 1; i < size; ++i) - { - if (values[i] < min) + for (std::size_t i = 1; i < size; ++i) { - min = values[i]; - continue; - } + if (values[i] < min) + { + min = values[i]; + continue; + } - if (values[i] > max) - max = values[i]; - } + if (values[i] > max) + max = values[i]; + } } /** @@ -145,27 +145,27 @@ inline void GetMinMax(const std::complex<T> *values, const std::size_t size, T &min, T &max, const unsigned int nthreads = 1) noexcept { - min = std::norm(values[0]); - max = min; - - for (std::size_t i = 1; i < size; ++i) - { - T norm = std::norm(values[i]); + min = std::norm(values[0]); + max = min; - if (norm < min) + for (std::size_t i = 1; i < size; ++i) { - min = norm; - continue; - } + T norm = std::norm(values[i]); - if (norm > max) - { - max = norm; + if (norm < min) + { + min = norm; + continue; + } + + if (norm > max) + { + max = norm; + } } - } - min = std::sqrt(min); - max = std::sqrt(max); + min = std::sqrt(min); + max = std::sqrt(max); } /** @@ -179,49 +179,49 @@ template <class T, class U> void MemcpyThreads(T *destination, const U *source, std::size_t count, const unsigned int nthreads = 1) { - // do not decompose tasks to less than 4MB pieces - const std::size_t minBlockSize = 4194304; - const std::size_t maxNThreads = - std::max((std::size_t)nthreads, count / minBlockSize); + // do not decompose tasks to less than 4MB pieces + const std::size_t minBlockSize = 4194304; + const std::size_t maxNThreads = + std::max((std::size_t)nthreads, count / minBlockSize); - if (maxNThreads == 1) - { - std::memcpy(destination, source, count); - return; - } + if (maxNThreads == 1) + { + std::memcpy(destination, source, count); + return; + } - const std::size_t stride = count / maxNThreads; - const std::size_t remainder = count % maxNThreads; - const std::size_t last = stride + remainder; + const std::size_t stride = count / maxNThreads; + const std::size_t remainder = count % maxNThreads; + const std::size_t last = stride + remainder; - std::vector<std::thread> memcpyThreads; - memcpyThreads.reserve(maxNThreads); + std::vector<std::thread> memcpyThreads; + memcpyThreads.reserve(maxNThreads); - for (unsigned int t = 0; t < maxNThreads; ++t) - { - const size_t initialDestination = stride * t / sizeof(T); - const size_t initialSource = stride * t / sizeof(U); + for (unsigned int t = 0; t < maxNThreads; ++t) + { + const size_t initialDestination = stride * t / sizeof(T); + const size_t initialSource = stride * t / sizeof(U); - if (t == maxNThreads - 1) - memcpyThreads.push_back(std::thread(std::memcpy, - &destination[initialDestination], - &source[initialSource], last)); - else - memcpyThreads.push_back(std::thread(std::memcpy, - &destination[initialDestination], - &source[initialSource], stride)); - } - // Now join the threads (is this really needed?) - for (auto &thread : memcpyThreads) - thread.join(); + if (t == maxNThreads - 1) + memcpyThreads.push_back( + std::thread(std::memcpy, &destination[initialDestination], + &source[initialSource], last)); + else + memcpyThreads.push_back( + std::thread(std::memcpy, &destination[initialDestination], + &source[initialSource], stride)); + } + // Now join the threads (is this really needed?) + for (auto &thread : memcpyThreads) + thread.join(); } template <class T> void MemcpyToBuffer(std::vector<char> &raw, std::size_t &position, const T *source, std::size_t size) noexcept { - std::memcpy(&raw[position], source, size); - position += size; + std::memcpy(&raw[position], source, size); + position += size; } /** @@ -235,8 +235,8 @@ template <class T> void CopyToBuffer(std::vector<char> &buffer, const T *source, const std::size_t elements = 1) noexcept { - const char *src = reinterpret_cast<const char *>(source); - buffer.insert(buffer.end(), src, src + elements * sizeof(T)); + const char *src = reinterpret_cast<const char *>(source); + buffer.insert(buffer.end(), src, src + elements * sizeof(T)); } /** @@ -251,8 +251,8 @@ template <class T> void CopyToBuffer(std::vector<char> &buffer, const std::size_t position, const T *source, const std::size_t elements = 1) noexcept { - const char *src = reinterpret_cast<const char *>(source); - std::copy(src, src + elements * sizeof(T), buffer.begin() + position); + const char *src = reinterpret_cast<const char *>(source); + std::copy(src, src + elements * sizeof(T), buffer.begin() + position); } template <class T> @@ -260,24 +260,24 @@ void CopyFromBuffer(T *destination, std::size_t elements, const std::vector<char> &raw, std::size_t &position) noexcept { - std::copy(raw.begin() + position, - raw.begin() + position + sizeof(T) * elements, - reinterpret_cast<char *>(destination)); - position += elements * sizeof(T); + std::copy(raw.begin() + position, + raw.begin() + position + sizeof(T) * elements, + reinterpret_cast<char *>(destination)); + position += elements * sizeof(T); } template <class T> void PrintValues(const std::string name, const char *buffer, const std::size_t position, const std::size_t elements) { - std::vector<T> values(elements); - std::memcpy(values.data(), &buffer[position], elements * sizeof(T)); + std::vector<T> values(elements); + std::memcpy(values.data(), &buffer[position], elements * sizeof(T)); - std::cout << "Read " << name << "\n"; - for (const auto value : values) - std::cout << value << " "; + std::cout << "Read " << name << "\n"; + for (const auto value : values) + std::cout << value << " "; - std::cout << "\n"; + std::cout << "\n"; } } // end namespace diff --git a/include/transform/BZip2.h b/include/transform/BZip2.h index 755b6453c2631db0fb5207ce06e3abbd0b3dd477..0735ae2c711eec9d6774da0066192108567728e4 100644 --- a/include/transform/BZip2.h +++ b/include/transform/BZip2.h @@ -22,20 +22,20 @@ class BZIP2 : public Transform { public: - /** - * Initialize parent method - * @param compressionLevel - * @param variable - */ - BZIP2(); + /** + * Initialize parent method + * @param compressionLevel + * @param variable + */ + BZIP2(); - ~BZIP2(); + ~BZIP2(); - void Compress(const std::vector<char> &bufferIn, - std::vector<char> &bufferOut); - - void Decompress(const std::vector<char> &bufferIn, + void Compress(const std::vector<char> &bufferIn, std::vector<char> &bufferOut); + + void Decompress(const std::vector<char> &bufferIn, + std::vector<char> &bufferOut); }; } // end namespace transform diff --git a/include/transport/file/FStream.h b/include/transport/file/FStream.h index 8553c35981ebdb87048631033f293404f3774f88..7a54d040b7fd46b61bcdb890ef281e0bb749e39d 100644 --- a/include/transport/file/FStream.h +++ b/include/transport/file/FStream.h @@ -29,22 +29,22 @@ class FStream : public Transport { public: - FStream(MPI_Comm mpiComm, const bool debugMode); + FStream(MPI_Comm mpiComm, const bool debugMode); - virtual ~FStream() = default; + virtual ~FStream() = default; - void Open(const std::string name, const std::string accessMode); + void Open(const std::string name, const std::string accessMode); - void SetBuffer(char *buffer, std::size_t size); + void SetBuffer(char *buffer, std::size_t size); - void Write(const char *buffer, std::size_t size); + void Write(const char *buffer, std::size_t size); - void Flush(); + void Flush(); - void Close(); + void Close(); private: - std::fstream m_FStream; ///< file stream under name.bp.dir/name.bp.rank + std::fstream m_FStream; ///< file stream under name.bp.dir/name.bp.rank }; } // end namespace transport diff --git a/include/transport/file/FileDescriptor.h b/include/transport/file/FileDescriptor.h index 98d17dfb86d77303588b398a4363fe3c68e2d2ab..63d7a672114aa11e0968ca8a4355ec838fd011d0 100644 --- a/include/transport/file/FileDescriptor.h +++ b/include/transport/file/FileDescriptor.h @@ -25,18 +25,18 @@ class FileDescriptor : public Transport { public: - FileDescriptor(MPI_Comm mpiComm, const bool debugMode); + FileDescriptor(MPI_Comm mpiComm, const bool debugMode); - ~FileDescriptor(); + ~FileDescriptor(); - void Open(const std::string name, const std::string accessMode); + void Open(const std::string name, const std::string accessMode); - void Write(const char *buffer, std::size_t size); + void Write(const char *buffer, std::size_t size); - void Close(); + void Close(); private: - int m_FileDescriptor = -1; ///< file descriptor returned by POSIX open + int m_FileDescriptor = -1; ///< file descriptor returned by POSIX open }; } // end namespace transport diff --git a/include/transport/file/FilePointer.h b/include/transport/file/FilePointer.h index 439bffebebf6ce3bcfb520b05bb4603c2759ee6e..c1de95056ff85e0886d7d7aa0ed7e9f1707e42d7 100644 --- a/include/transport/file/FilePointer.h +++ b/include/transport/file/FilePointer.h @@ -30,22 +30,22 @@ class FilePointer : public Transport { public: - FilePointer(MPI_Comm mpiComm, const bool debugMode); + FilePointer(MPI_Comm mpiComm, const bool debugMode); - ~FilePointer(); + ~FilePointer(); - void Open(const std::string name, const std::string accessMode); + void Open(const std::string name, const std::string accessMode); - void SetBuffer(char *buffer, std::size_t size); + void SetBuffer(char *buffer, std::size_t size); - void Write(const char *buffer, std::size_t size); + void Write(const char *buffer, std::size_t size); - void Flush(); + void Flush(); - void Close(); + void Close(); private: - FILE *m_File = NULL; ///< C file pointer + FILE *m_File = NULL; ///< C file pointer }; } // end namespace transport diff --git a/include/transport/file/MPI_File.h b/include/transport/file/MPI_File.h index 5966cc531da35b6e991cd6fe47189a569fb6e5ec..10685e8cea3d2f9a90f12b9ee1d020a384511725 100644 --- a/include/transport/file/MPI_File.h +++ b/include/transport/file/MPI_File.h @@ -27,22 +27,22 @@ class MPI_File : public Transport { public: - MPI_File(MPI_Comm mpiComm, const bool debugMode); + MPI_File(MPI_Comm mpiComm, const bool debugMode); - ~MPI_File(); + ~MPI_File(); - void Open(const std::string streamName, const std::string accessMode); + void Open(const std::string streamName, const std::string accessMode); - void SetBuffer(char *buffer, std::size_t size); + void SetBuffer(char *buffer, std::size_t size); - void Write(const char *buffer, std::size_t size); + void Write(const char *buffer, std::size_t size); - void Flush(); + void Flush(); - void Close(); + void Close(); private: - MPI_File m_MPIFile; ///< MPI File + MPI_File m_MPIFile; ///< MPI File }; } // end namespace transport diff --git a/include/transport/wan/MdtmMan.h b/include/transport/wan/MdtmMan.h index 84a71156e560909da7b31b7c087337de2bdf1bce..7ddd162acc11beb73abedab6f43aad5c9dd0b7ae 100644 --- a/include/transport/wan/MdtmMan.h +++ b/include/transport/wan/MdtmMan.h @@ -25,112 +25,113 @@ class MdtmMan : public Transport { public: - /** - * - * @param localIP - * @param remoteIP - * @param mode - * @param prefix - * @param numberOfPipes - * @param tolerances - * @param priorities - * @param mpiComm - * @param debugMode - */ - MdtmMan(const std::string localIP, const std::string remoteIP, - const std::string mode, const std::string prefix, - const int numberOfPipes, const std::vector<int> tolerances, - const std::vector<int> priorities, MPI_Comm mpiComm, - const bool debugMode); - - ~MdtmMan(); - - void Open(const std::string name, const std::string accessMode); - - void SetBuffer(char *buffer, std::size_t size); - - /** - * We can always overload this function in the base class and accept other - * types of data pointers, e.g. Write( json* ); - * I'm sticking with char* as it's more general (only C++ libraries, e.g. - * boost understand std::std::vector, MPI, POSIX, Infiniband use pointer*) - * @param buffer - * @param size - */ - void Write(const char *buffer, std::size_t size); - - void Flush(); ///< not sure if this one is needed... - - void Close(); + /** + * + * @param localIP + * @param remoteIP + * @param mode + * @param prefix + * @param numberOfPipes + * @param tolerances + * @param priorities + * @param mpiComm + * @param debugMode + */ + MdtmMan(const std::string localIP, const std::string remoteIP, + const std::string mode, const std::string prefix, + const int numberOfPipes, const std::vector<int> tolerances, + const std::vector<int> priorities, MPI_Comm mpiComm, + const bool debugMode); + + ~MdtmMan(); + + void Open(const std::string name, const std::string accessMode); + + void SetBuffer(char *buffer, std::size_t size); + + /** + * We can always overload this function in the base class and accept other + * types of data pointers, e.g. Write( json* ); + * I'm sticking with char* as it's more general (only C++ libraries, e.g. + * boost understand std::std::vector, MPI, POSIX, Infiniband use pointer*) + * @param buffer + * @param size + */ + void Write(const char *buffer, std::size_t size); + + void Flush(); ///< not sure if this one is needed... + + void Close(); private: - std::string m_LocalIP; ///< local ip address, can change over time - std::string m_RemoteIP; ///< remote ip address, can change over time - std::string m_Mode; ///< send/write, receive/read - std::string m_Prefix; ///< prefix given to message - int m_NumberOfPipes = -1; ///< should it be unsigned int? - std::vector<int> m_Tolerances; - std::vector<int> m_Priorities; - - /** - * Should we change data to char* ? - * @param data - * @param doid - * @param variable - * @param dType - * @param putShape - * @param varShape - * @param offset - * @param timestep - * @param tolerance - * @param priority - * @return - */ - int Put(const void *data, const std::string doid, const std::string variable, - const std::string dType, const std::vector<std::uint64_t> &putShape, - const std::vector<uint64_t> &varShape, - const std::vector<uint64_t> &offset, const std::uint64_t timestep, - const int tolerance, const int priority); - - /** - * - * @param data - * @param doid - * @param variable - * @param dType - * @param putShape - * @param varShape - * @param offset - * @param timestep - * @param tolerance - * @param priority - * @return - */ - int Get(void *data, const std::string doid, const std::string variable, - const std::string dType, const std::vector<std::uint64_t> &putShape, - const std::vector<uint64_t> &varShape, - const std::vector<uint64_t> &offset, const std::uint64_t timestep, - const int tolerance, const int priority); - - /** - * - * @param data - * @param doid - * @param variable - * @param dType - * @param varShape - * @param timestep - * @return - */ - int Get(void *data, const std::string doid, const std::string variable, - const std::string dType, std::vector<std::uint64_t> &varShape, - const std::uint64_t timestep); - - /** - * - * @param jData - */ - void OnReceive(nlohmann::json &jData); + std::string m_LocalIP; ///< local ip address, can change over time + std::string m_RemoteIP; ///< remote ip address, can change over time + std::string m_Mode; ///< send/write, receive/read + std::string m_Prefix; ///< prefix given to message + int m_NumberOfPipes = -1; ///< should it be unsigned int? + std::vector<int> m_Tolerances; + std::vector<int> m_Priorities; + + /** + * Should we change data to char* ? + * @param data + * @param doid + * @param variable + * @param dType + * @param putShape + * @param varShape + * @param offset + * @param timestep + * @param tolerance + * @param priority + * @return + */ + int Put(const void *data, const std::string doid, + const std::string variable, const std::string dType, + const std::vector<std::uint64_t> &putShape, + const std::vector<uint64_t> &varShape, + const std::vector<uint64_t> &offset, const std::uint64_t timestep, + const int tolerance, const int priority); + + /** + * + * @param data + * @param doid + * @param variable + * @param dType + * @param putShape + * @param varShape + * @param offset + * @param timestep + * @param tolerance + * @param priority + * @return + */ + int Get(void *data, const std::string doid, const std::string variable, + const std::string dType, const std::vector<std::uint64_t> &putShape, + const std::vector<uint64_t> &varShape, + const std::vector<uint64_t> &offset, const std::uint64_t timestep, + const int tolerance, const int priority); + + /** + * + * @param data + * @param doid + * @param variable + * @param dType + * @param varShape + * @param timestep + * @return + */ + int Get(void *data, const std::string doid, const std::string variable, + const std::string dType, std::vector<std::uint64_t> &varShape, + const std::uint64_t timestep); + + /** + * + * @param jData + */ + void OnReceive(nlohmann::json &jData); }; } // end namespace transport diff --git a/source/ADIOS.cpp b/source/ADIOS.cpp index d752a127d699ea3726e0db798976356f1eff62e6..0f26439d810c1a641dde3d89cf58d7cc1ea92b91 100644 --- a/source/ADIOS.cpp +++ b/source/ADIOS.cpp @@ -40,62 +40,63 @@ namespace adios ADIOS::ADIOS(const Verbose /*verbose*/, const bool debugMode) : m_DebugMode{debugMode} { - InitMPI(); + InitMPI(); } ADIOS::ADIOS(std::string config, const Verbose /*verbose*/, const bool debugMode) : m_ConfigFile{std::move(config)}, m_DebugMode{debugMode} { - InitMPI(); - // InitXML( m_ConfigFile, m_MPIComm, m_DebugMode, m_Transforms ); + InitMPI(); + // InitXML( m_ConfigFile, m_MPIComm, m_DebugMode, m_Transforms ); } ADIOS::ADIOS(std::string config, MPI_Comm mpiComm, const Verbose /*verbose*/, const bool debugMode) : m_MPIComm{mpiComm}, m_ConfigFile{std::move(config)}, m_DebugMode{debugMode} { - InitMPI(); - // InitXML( m_XMLConfigFile, m_MPIComm, m_DebugMode, m_HostLanguage, - // m_Transforms, m_Groups ); + InitMPI(); + // InitXML( m_XMLConfigFile, m_MPIComm, m_DebugMode, m_HostLanguage, + // m_Transforms, m_Groups ); } ADIOS::ADIOS(MPI_Comm mpiComm, const Verbose /*verbose*/, const bool debugMode) : m_MPIComm{mpiComm}, m_DebugMode{debugMode} { - InitMPI(); + InitMPI(); } // ADIOS::~ADIOS() {} void ADIOS::InitMPI() { - if (m_DebugMode == true) - { - if (m_MPIComm == MPI_COMM_NULL) + if (m_DebugMode == true) { - throw std::ios_base::failure( - "ERROR: engine communicator is MPI_COMM_NULL," - " in call to ADIOS Open or Constructor\n"); + if (m_MPIComm == MPI_COMM_NULL) + { + throw std::ios_base::failure( + "ERROR: engine communicator is MPI_COMM_NULL," + " in call to ADIOS Open or Constructor\n"); + } } - } - MPI_Comm_rank(m_MPIComm, &m_RankMPI); - MPI_Comm_size(m_MPIComm, &m_SizeMPI); + MPI_Comm_rank(m_MPIComm, &m_RankMPI); + MPI_Comm_size(m_MPIComm, &m_SizeMPI); } Method &ADIOS::DeclareMethod(const std::string &methodName) { - if (m_DebugMode == true) - { - if (m_Methods.count(methodName) == 1) + if (m_DebugMode == true) { - throw std::invalid_argument("ERROR: method " + methodName + - " already declared, from DeclareMethod\n"); + if (m_Methods.count(methodName) == 1) + { + throw std::invalid_argument( + "ERROR: method " + methodName + + " already declared, from DeclareMethod\n"); + } } - } - m_Methods.emplace(methodName, Method(methodName, m_DebugMode)); - return m_Methods.at(methodName); + m_Methods.emplace(methodName, Method(methodName, m_DebugMode)); + return m_Methods.at(methodName); } std::shared_ptr<Engine> ADIOS::Open(const std::string &name, @@ -104,97 +105,103 @@ std::shared_ptr<Engine> ADIOS::Open(const std::string &name, const IOMode iomode, const float timeout_sec) { - if (m_DebugMode == true) - { - if (m_EngineNames.count(name) == 1) // Check if Engine already exists + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: engine name " + name + - " already created by Open, in call from Open.\n"); + if (m_EngineNames.count(name) == 1) // Check if Engine already exists + { + throw std::invalid_argument( + "ERROR: engine name " + name + + " already created by Open, in call from Open.\n"); + } } - } - - m_EngineNames.insert(name); - - const std::string type(method.m_Type); - - const bool isDefaultWriter = (accessMode == "w" || accessMode == "write" || - accessMode == "a" || accessMode == "append") && - type.empty() - ? true - : false; - - const bool isDefaultReader = - (accessMode == "r" || accessMode == "read") && type.empty() ? true - : false; - - if (isDefaultWriter || type == "BPFileWriter" || type == "bpfilewriter") - { - return std::make_shared<BPFileWriter>(*this, name, accessMode, mpiComm, - method, iomode, timeout_sec, - m_DebugMode, method.m_nThreads); - } - else if (isDefaultReader || type == "BPReader" || type == "bpreader") - { - return std::make_shared<BPFileReader>(*this, name, accessMode, mpiComm, - method, iomode, timeout_sec, - m_DebugMode, method.m_nThreads); - } - else if (type == "SIRIUS" || type == "sirius" || type == "Sirius") - { - // not yet supported - // return std::make_shared<engine::DataMan>( *this, name, accessMode, - // mpiComm, method, iomode, timeout_sec, m_DebugMode, method.m_nThreads ); - } - else if (type == "DataManWriter") - { + + m_EngineNames.insert(name); + + const std::string type(method.m_Type); + + const bool isDefaultWriter = + (accessMode == "w" || accessMode == "write" || accessMode == "a" || + accessMode == "append") && + type.empty() + ? true + : false; + + const bool isDefaultReader = + (accessMode == "r" || accessMode == "read") && type.empty() ? true + : false; + + if (isDefaultWriter || type == "BPFileWriter" || type == "bpfilewriter") + { + return std::make_shared<BPFileWriter>(*this, name, accessMode, mpiComm, + method, iomode, timeout_sec, + m_DebugMode, method.m_nThreads); + } + else if (isDefaultReader || type == "BPReader" || type == "bpreader") + { + return std::make_shared<BPFileReader>(*this, name, accessMode, mpiComm, + method, iomode, timeout_sec, + m_DebugMode, method.m_nThreads); + } + else if (type == "SIRIUS" || type == "sirius" || type == "Sirius") + { + // not yet supported + // return std::make_shared<engine::DataMan>( *this, name, accessMode, + // mpiComm, method, iomode, timeout_sec, m_DebugMode, method.m_nThreads + // ); + } + else if (type == "DataManWriter") + { #ifdef HAVE_DATAMAN - return std::make_shared<DataManWriter>(*this, name, accessMode, mpiComm, - method, iomode, timeout_sec, - m_DebugMode, method.m_nThreads); + return std::make_shared<DataManWriter>(*this, name, accessMode, mpiComm, + method, iomode, timeout_sec, + m_DebugMode, method.m_nThreads); #else - throw std::invalid_argument("ERROR: this version didn't compile with " - "Dataman library, can't Open DataManWriter\n"); + throw std::invalid_argument( + "ERROR: this version didn't compile with " + "Dataman library, can't Open DataManWriter\n"); #endif - } - else if (type == "DataManReader") - { + } + else if (type == "DataManReader") + { #ifdef HAVE_DATAMAN - return std::make_shared<DataManReader>(*this, name, accessMode, mpiComm, - method, iomode, timeout_sec, - m_DebugMode, method.m_nThreads); + return std::make_shared<DataManReader>(*this, name, accessMode, mpiComm, + method, iomode, timeout_sec, + m_DebugMode, method.m_nThreads); #else - throw std::invalid_argument("ERROR: this version didn't compile with " - "Dataman library, can't Open DataManReader\n"); + throw std::invalid_argument( + "ERROR: this version didn't compile with " + "Dataman library, can't Open DataManReader\n"); #endif - } - else if (type == "ADIOS1Writer") - { + } + else if (type == "ADIOS1Writer") + { #ifdef HAVE_ADIOS1 - return std::make_shared<ADIOS1Writer>(*this, name, accessMode, mpiComm, - method, iomode, timeout_sec, - m_DebugMode, method.m_nThreads); + return std::make_shared<ADIOS1Writer>(*this, name, accessMode, mpiComm, + method, iomode, timeout_sec, + m_DebugMode, method.m_nThreads); #else - throw std::invalid_argument("ERROR: this version didn't compile with ADIOS " - "1.x library, can't Open ADIOS1Writer\n"); + throw std::invalid_argument( + "ERROR: this version didn't compile with ADIOS " + "1.x library, can't Open ADIOS1Writer\n"); #endif - } - else if (type == "Vis") - { - // return std::make_shared<Vis>( *this, name, accessMode, mpiComm, method, - // iomode, timeout_sec, m_DebugMode, method.m_nThreads ); - } - else - { - if (m_DebugMode == true) + } + else if (type == "Vis") { - throw std::invalid_argument("ERROR: method type " + type + - " not supported for " + name + - ", in call to Open\n"); + // return std::make_shared<Vis>( *this, name, accessMode, mpiComm, + // method, + // iomode, timeout_sec, m_DebugMode, method.m_nThreads ); + } + else + { + if (m_DebugMode == true) + { + throw std::invalid_argument("ERROR: method type " + type + + " not supported for " + name + + ", in call to Open\n"); + } } - } - return nullptr; // if debug mode is off + return nullptr; // if debug mode is off } std::shared_ptr<Engine> ADIOS::Open(const std::string &streamName, @@ -202,7 +209,7 @@ std::shared_ptr<Engine> ADIOS::Open(const std::string &streamName, const Method &method, const IOMode iomode, const float timeout_sec) { - return Open(streamName, accessMode, m_MPIComm, method, iomode, timeout_sec); + return Open(streamName, accessMode, m_MPIComm, method, iomode, timeout_sec); } std::shared_ptr<Engine> @@ -210,14 +217,15 @@ ADIOS::Open(const std::string &name, const std::string &accessMode, MPI_Comm mpiComm, const std::string &methodName, const IOMode iomode, const float timeout_sec) { - auto itMethod = m_Methods.find(methodName); + auto itMethod = m_Methods.find(methodName); - if (m_DebugMode == true) - { - CheckMethod(itMethod, methodName, " in call to Open\n"); - } + if (m_DebugMode == true) + { + CheckMethod(itMethod, methodName, " in call to Open\n"); + } - return Open(name, accessMode, mpiComm, itMethod->second, iomode, timeout_sec); + return Open(name, accessMode, mpiComm, itMethod->second, iomode, + timeout_sec); } std::shared_ptr<Engine> ADIOS::Open(const std::string &name, @@ -226,7 +234,7 @@ std::shared_ptr<Engine> ADIOS::Open(const std::string &name, const IOMode iomode, const float timeout_sec) { - return Open(name, accessMode, m_MPIComm, methodName, iomode, timeout_sec); + return Open(name, accessMode, m_MPIComm, methodName, iomode, timeout_sec); } std::shared_ptr<Engine> ADIOS::OpenFileReader(const std::string &name, @@ -234,7 +242,7 @@ std::shared_ptr<Engine> ADIOS::OpenFileReader(const std::string &name, const Method &method, const IOMode iomode) { - return Open(name, "r", m_MPIComm, method, iomode); + return Open(name, "r", m_MPIComm, method, iomode); } std::shared_ptr<Engine> ADIOS::OpenFileReader(const std::string &name, @@ -242,117 +250,117 @@ std::shared_ptr<Engine> ADIOS::OpenFileReader(const std::string &name, const std::string &methodName, const IOMode iomode) { - auto itMethod = m_Methods.find(methodName); + auto itMethod = m_Methods.find(methodName); - if (m_DebugMode == true) - { - CheckMethod(itMethod, methodName, " in call to Open\n"); - } + if (m_DebugMode == true) + { + CheckMethod(itMethod, methodName, " in call to Open\n"); + } - return Open(name, "r", m_MPIComm, itMethod->second, iomode); + return Open(name, "r", m_MPIComm, itMethod->second, iomode); } VariableCompound &ADIOS::GetVariableCompound(const std::string &name) { - return m_Compound.at(GetVariableIndex<void>(name)); + return m_Compound.at(GetVariableIndex<void>(name)); } void ADIOS::MonitorVariables(std::ostream &logStream) { - logStream << "\tVariable \t Type\n"; - - for (auto &variablePair : m_Variables) - { - const std::string name(variablePair.first); - const std::string type(variablePair.second.first); + logStream << "\tVariable \t Type\n"; - if (type == GetType<char>()) - { - GetVariable<char>(name).Monitor(logStream); - } - else if (type == GetType<unsigned char>()) - { - GetVariable<unsigned char>(name).Monitor(logStream); - } - else if (type == GetType<short>()) + for (auto &variablePair : m_Variables) { - GetVariable<short>(name).Monitor(logStream); + const std::string name(variablePair.first); + const std::string type(variablePair.second.first); + + if (type == GetType<char>()) + { + GetVariable<char>(name).Monitor(logStream); + } + else if (type == GetType<unsigned char>()) + { + GetVariable<unsigned char>(name).Monitor(logStream); + } + else if (type == GetType<short>()) + { + GetVariable<short>(name).Monitor(logStream); + } + else if (type == GetType<unsigned short>()) + { + GetVariable<unsigned short>(name).Monitor(logStream); + } + else if (type == GetType<int>()) + { + GetVariable<int>(name).Monitor(logStream); + } + else if (type == GetType<unsigned int>()) + { + GetVariable<unsigned int>(name).Monitor(logStream); + } + else if (type == GetType<long int>()) + { + GetVariable<long int>(name).Monitor(logStream); + } + else if (type == GetType<unsigned long int>()) + { + GetVariable<unsigned long int>(name).Monitor(logStream); + } + else if (type == GetType<long long int>()) + { + GetVariable<long long int>(name).Monitor(logStream); + } + else if (type == GetType<unsigned long long int>()) + { + GetVariable<unsigned long long int>(name).Monitor(logStream); + } + else if (type == GetType<float>()) + { + GetVariable<float>(name).Monitor(logStream); + } + else if (type == GetType<double>()) + { + GetVariable<double>(name).Monitor(logStream); + } + else if (type == GetType<long double>()) + { + GetVariable<long double>(name).Monitor(logStream); + } + else if (type == GetType<std::complex<float>>()) + { + GetVariable<std::complex<float>>(name).Monitor(logStream); + } + else if (type == GetType<std::complex<double>>()) + { + GetVariable<std::complex<double>>(name).Monitor(logStream); + } + else if (type == GetType<std::complex<long double>>()) + { + GetVariable<std::complex<long double>>(name).Monitor(logStream); + } } - else if (type == GetType<unsigned short>()) - { - GetVariable<unsigned short>(name).Monitor(logStream); - } - else if (type == GetType<int>()) - { - GetVariable<int>(name).Monitor(logStream); - } - else if (type == GetType<unsigned int>()) - { - GetVariable<unsigned int>(name).Monitor(logStream); - } - else if (type == GetType<long int>()) - { - GetVariable<long int>(name).Monitor(logStream); - } - else if (type == GetType<unsigned long int>()) - { - GetVariable<unsigned long int>(name).Monitor(logStream); - } - else if (type == GetType<long long int>()) - { - GetVariable<long long int>(name).Monitor(logStream); - } - else if (type == GetType<unsigned long long int>()) - { - GetVariable<unsigned long long int>(name).Monitor(logStream); - } - else if (type == GetType<float>()) - { - GetVariable<float>(name).Monitor(logStream); - } - else if (type == GetType<double>()) - { - GetVariable<double>(name).Monitor(logStream); - } - else if (type == GetType<long double>()) - { - GetVariable<long double>(name).Monitor(logStream); - } - else if (type == GetType<std::complex<float>>()) - { - GetVariable<std::complex<float>>(name).Monitor(logStream); - } - else if (type == GetType<std::complex<double>>()) - { - GetVariable<std::complex<double>>(name).Monitor(logStream); - } - else if (type == GetType<std::complex<long double>>()) - { - GetVariable<std::complex<long double>>(name).Monitor(logStream); - } - } } // PRIVATE FUNCTIONS BELOW void ADIOS::CheckVariableInput(const std::string &name, const Dims &dimensions) const { - if (m_DebugMode == true) - { - if (m_Variables.count(name) == 1) - { - throw std::invalid_argument( - "ERROR: variable " + name + - " already exists, in call to DefineVariable\n"); - } - - if (dimensions.empty() == true) + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: variable " + name + - " dimensions can't be empty, in call to DefineVariable\n"); + if (m_Variables.count(name) == 1) + { + throw std::invalid_argument( + "ERROR: variable " + name + + " already exists, in call to DefineVariable\n"); + } + + if (dimensions.empty() == true) + { + throw std::invalid_argument( + "ERROR: variable " + name + + " dimensions can't be empty, in call to DefineVariable\n"); + } } - } } void ADIOS::CheckVariableName( @@ -360,25 +368,25 @@ void ADIOS::CheckVariableName( itVariable, const std::string &name, const std::string &hint) const { - if (m_DebugMode == true) - { - if (itVariable == m_Variables.end()) + if (m_DebugMode == true) { - throw std::invalid_argument("ERROR: variable " + name + - " does not exist " + hint + "\n"); + if (itVariable == m_Variables.end()) + { + throw std::invalid_argument("ERROR: variable " + name + + " does not exist " + hint + "\n"); + } } - } } void ADIOS::CheckMethod(std::map<std::string, Method>::const_iterator itMethod, const std::string &methodName, const std::string &hint) const { - if (itMethod == m_Methods.end()) - { - throw std::invalid_argument("ERROR: method " + methodName + " not found " + - hint + "\n"); - } + if (itMethod == m_Methods.end()) + { + throw std::invalid_argument("ERROR: method " + methodName + + " not found " + hint + "\n"); + } } } // end namespace adios diff --git a/source/ADIOS_C.cpp b/source/ADIOS_C.cpp index d6f30da48a55cf7fae051d584852fb289c0abbd2..a3306931e5ad22e80525160466606e0013f453bb 100644 --- a/source/ADIOS_C.cpp +++ b/source/ADIOS_C.cpp @@ -25,227 +25,227 @@ extern "C" { void adios_init(const char *xmlConfigFile, const MPI_Comm mpiComm) { - int rank; - MPI_Comm_rank(mpiComm, &rank); - - try - { - adios = new adios::ADIOS(std::string(xmlConfigFile), mpiComm); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } - - // return ( ADIOS* ) ( adios ); + int rank; + MPI_Comm_rank(mpiComm, &rank); + + try + { + adios = new adios::ADIOS(std::string(xmlConfigFile), mpiComm); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } + + // return ( ADIOS* ) ( adios ); } ADIOS *adios_init_debug(const char *xmlConfigFile, const MPI_Comm mpiComm) { - adios::ADIOS *adios; - int rank; - MPI_Comm_rank(mpiComm, &rank); - - try - { - adios = new adios::ADIOS(std::string(xmlConfigFile), mpiComm, true); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } - - return (ADIOS *)(adios); + adios::ADIOS *adios; + int rank; + MPI_Comm_rank(mpiComm, &rank); + + try + { + adios = new adios::ADIOS(std::string(xmlConfigFile), mpiComm, true); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } + + return (ADIOS *)(adios); } void adios_open(const ADIOS *adiosC, const char *groupName, const char *fileName, const char *accessMode) { - adios::ADIOS *adios = (adios::ADIOS *)adiosC; - int rank; - MPI_Comm_rank(adios->m_MPIComm, &rank); - - try - { adios::ADIOS *adios = (adios::ADIOS *)adiosC; - adios->Open(std::string(groupName), std::string(fileName), - std::string(accessMode)); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } + int rank; + MPI_Comm_rank(adios->m_MPIComm, &rank); + + try + { + adios::ADIOS *adios = (adios::ADIOS *)adiosC; + adios->Open(std::string(groupName), std::string(fileName), + std::string(accessMode)); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } } void adios_write(const ADIOS *adiosC, const char *groupName, const char *variableName, const void *values) { - adios::ADIOS *adios = (adios::ADIOS *)adiosC; - int rank; - MPI_Comm_rank(adios->m_MPIComm, &rank); - - try - { - adios->Write(const std::string(groupName), const std::string(variableName), - values); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } + adios::ADIOS *adios = (adios::ADIOS *)adiosC; + int rank; + MPI_Comm_rank(adios->m_MPIComm, &rank); + + try + { + adios->Write(const std::string(groupName), + const std::string(variableName), values); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } } void adios_close(const ADIOS *adiosC, const char *groupName) { - adios::ADIOS *adios = (adios::ADIOS *)adiosC; - int rank; - MPI_Comm_rank(adios->m_MPIComm, &rank); - - try - { - adios->Close(std::string(groupName)); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } + adios::ADIOS *adios = (adios::ADIOS *)adiosC; + int rank; + MPI_Comm_rank(adios->m_MPIComm, &rank); + + try + { + adios->Close(std::string(groupName)); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } } void adios_free(const ADIOS *adiosC) { - adios::ADIOS *adios = (adios::ADIOS *)adiosC; - delete adios; + adios::ADIOS *adios = (adios::ADIOS *)adiosC; + delete adios; } void adios_monitor_groups(const ADIOS *adiosC) { - adios::ADIOS *adios = (adios::ADIOS *)adiosC; - int rank; - MPI_Comm_rank(adios->m_MPIComm, &rank); - - try - { - adios->MonitorGroups(std::cout); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } + adios::ADIOS *adios = (adios::ADIOS *)adiosC; + int rank; + MPI_Comm_rank(adios->m_MPIComm, &rank); + + try + { + adios->MonitorGroups(std::cout); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } } void adios_monitor_groups_file(const ADIOS *adiosC, const char *fileName, const char *mode) { - adios::ADIOS *adios = (adios::ADIOS *)adiosC; - int rank; - MPI_Comm_rank(adios->m_MPIComm, &rank); - - try - { - std::ofstream fileStream; - - if (strcmp(mode, "a") == 0 || strcmp(mode, "append") == 0) - fileStream.open(fileName, std::ostream::app); - else if (strcmp(mode, "w") == 0 || strcmp(mode, "write") == 0) - fileStream.open(fileName); - - adios->MonitorGroups(fileStream); - } - catch (std::bad_alloc &e) - { - if (rank == 0) - std::cout << "Bad allocation exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::invalid_argument &e) - { - if (rank == 0) - std::cout << "Invalid argument exception, STOPPING PROGRAM\n" - << e.what() << "\n"; - } - catch (std::exception &e) - { - if (rank == 0) - std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; - } + adios::ADIOS *adios = (adios::ADIOS *)adiosC; + int rank; + MPI_Comm_rank(adios->m_MPIComm, &rank); + + try + { + std::ofstream fileStream; + + if (strcmp(mode, "a") == 0 || strcmp(mode, "append") == 0) + fileStream.open(fileName, std::ostream::app); + else if (strcmp(mode, "w") == 0 || strcmp(mode, "write") == 0) + fileStream.open(fileName); + + adios->MonitorGroups(fileStream); + } + catch (std::bad_alloc &e) + { + if (rank == 0) + std::cout << "Bad allocation exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::invalid_argument &e) + { + if (rank == 0) + std::cout << "Invalid argument exception, STOPPING PROGRAM\n" + << e.what() << "\n"; + } + catch (std::exception &e) + { + if (rank == 0) + std::cout << "Exception, STOPPING PROGRAM\n" << e.what() << "\n"; + } } #ifdef __cplusplus diff --git a/source/capsule/heap/STLVector.cpp b/source/capsule/heap/STLVector.cpp index 03564095e71fbbcbe560ef293d89d8038c86e699..99d9971e873dd2dedc614525b69b352e9b03101c 100644 --- a/source/capsule/heap/STLVector.cpp +++ b/source/capsule/heap/STLVector.cpp @@ -23,7 +23,7 @@ namespace capsule STLVector::STLVector(std::string accessMode, int rankMPI, bool debugMode) : Capsule{"Heap", std::move(accessMode), rankMPI, debugMode} { - m_Data.reserve(16777216); + m_Data.reserve(16777216); } char *STLVector::GetData() { return m_Data.data(); } @@ -36,44 +36,44 @@ std::size_t STLVector::GetMetadataSize() const { return m_Metadata.size(); } void STLVector::ResizeData(const std::size_t size) { - if (m_DebugMode == true) - { - try + if (m_DebugMode == true) { - m_Data.resize(size); + try + { + m_Data.resize(size); + } + catch (std::bad_alloc &e) + { + throw std::runtime_error("ERROR: bad_alloc detected when resizing " + "data buffer with size " + + std::to_string(size) + "\n"); + } } - catch (std::bad_alloc &e) + else { - throw std::runtime_error( - "ERROR: bad_alloc detected when resizing data buffer with size " + - std::to_string(size) + "\n"); + m_Data.resize(size); } - } - else - { - m_Data.resize(size); - } } void STLVector::ResizeMetadata(const std::size_t size) { - if (m_DebugMode == true) - { - try + if (m_DebugMode == true) { - m_Metadata.resize(size); + try + { + m_Metadata.resize(size); + } + catch (std::bad_alloc &e) + { + throw std::runtime_error("ERROR: bad_alloc detected when resizing " + "metadata buffer with size " + + std::to_string(size) + "\n"); + } } - catch (std::bad_alloc &e) + else { - throw std::runtime_error( - "ERROR: bad_alloc detected when resizing metadata buffer with size " + - std::to_string(size) + "\n"); + m_Metadata.resize(size); } - } - else - { - m_Metadata.resize(size); - } } } // end namespace capsule diff --git a/source/capsule/shmem/ShmSystemV.cpp b/source/capsule/shmem/ShmSystemV.cpp index 8c3e14dd10ef1481d2f160a93c9d984672e37374..b26868c46640c317c9ca77f0b7479379267b0bd9 100644 --- a/source/capsule/shmem/ShmSystemV.cpp +++ b/source/capsule/shmem/ShmSystemV.cpp @@ -25,26 +25,26 @@ ShmSystemV::ShmSystemV(std::string accessMode, int rankMPI, : Capsule{"ShmSystemV", std::move(accessMode), rankMPI, debugMode}, m_DataSize{dataSize}, m_MetadataSize{metadataSize} { - // Data Shared memory sector - const std::string dataPath(pathName + "/adios.shm.data." + - std::to_string(m_RankMPI)); - m_DataKey = ftok(dataPath.c_str(), m_RankMPI + 1); - m_DataShmID = shmget(m_DataKey, m_DataSize, IPC_CREAT | 0666); - m_Data = static_cast<char *>(shmat(m_DataShmID, nullptr, 0)); + // Data Shared memory sector + const std::string dataPath(pathName + "/adios.shm.data." + + std::to_string(m_RankMPI)); + m_DataKey = ftok(dataPath.c_str(), m_RankMPI + 1); + m_DataShmID = shmget(m_DataKey, m_DataSize, IPC_CREAT | 0666); + m_Data = static_cast<char *>(shmat(m_DataShmID, nullptr, 0)); - // Metadata Shared memory sector - const std::string metadataPath(pathName + "/adios.shm.metadata." + - std::to_string(m_RankMPI)); - m_MetadataKey = - ftok(metadataPath.c_str(), - m_RankMPI + 1); // 2nd field must be greater than zero and unique - m_MetadataShmID = shmget(m_MetadataKey, m_MetadataSize, IPC_CREAT | 0666); - m_Metadata = static_cast<char *>(shmat(m_MetadataShmID, nullptr, 0)); + // Metadata Shared memory sector + const std::string metadataPath(pathName + "/adios.shm.metadata." + + std::to_string(m_RankMPI)); + m_MetadataKey = + ftok(metadataPath.c_str(), + m_RankMPI + 1); // 2nd field must be greater than zero and unique + m_MetadataShmID = shmget(m_MetadataKey, m_MetadataSize, IPC_CREAT | 0666); + m_Metadata = static_cast<char *>(shmat(m_MetadataShmID, nullptr, 0)); - if (m_DebugMode == true) - { - CheckShm(); - } + if (m_DebugMode == true) + { + CheckShm(); + } } char *ShmSystemV::GetData() { return m_Data; } @@ -57,37 +57,39 @@ size_t ShmSystemV::GetMetadataSize() const { return m_MetadataSize; } void ShmSystemV::CheckShm() const { - if (m_DataShmID < 0) - { - throw std::ios_base::failure( - "ERROR: Failed to create data shm segment of size " + - std::to_string(m_DataSize) + " from call to ShmSystemV constructor\n"); - } + if (m_DataShmID < 0) + { + throw std::ios_base::failure( + "ERROR: Failed to create data shm segment of size " + + std::to_string(m_DataSize) + + " from call to ShmSystemV constructor\n"); + } - if (m_Data == nullptr) - { - throw std::ios_base::failure( - "ERROR: Failed to attach to data shm segment of size " + - std::to_string(m_DataSize) + " and id " + std::to_string(m_DataShmID) + - ", from call to ShmSystemV constructor\n"); - } + if (m_Data == nullptr) + { + throw std::ios_base::failure( + "ERROR: Failed to attach to data shm segment of size " + + std::to_string(m_DataSize) + " and id " + + std::to_string(m_DataShmID) + + ", from call to ShmSystemV constructor\n"); + } - if (m_DataShmID < 0) - { - throw std::ios_base::failure( - "ERROR: Failed to create metadata shm segment of size " + - std::to_string(m_MetadataSize) + - " from call to ShmSystemV constructor\n"); - } + if (m_DataShmID < 0) + { + throw std::ios_base::failure( + "ERROR: Failed to create metadata shm segment of size " + + std::to_string(m_MetadataSize) + + " from call to ShmSystemV constructor\n"); + } - if (m_Metadata == nullptr) - { - throw std::ios_base::failure( - "ERROR: Failed to attach to metadata shm segment of size " + - std::to_string(m_MetadataSize) + " and id " + - std::to_string(m_MetadataShmID) + - " from call to ShmSystemV constructor\n"); - } + if (m_Metadata == nullptr) + { + throw std::ios_base::failure( + "ERROR: Failed to attach to metadata shm segment of size " + + std::to_string(m_MetadataSize) + " and id " + + std::to_string(m_MetadataShmID) + + " from call to ShmSystemV constructor\n"); + } } } // end namespace adios diff --git a/source/core/Engine.cpp b/source/core/Engine.cpp index 31497911e9f7ad729d17d17a66a87efc8675fd5b..ad23b38f143866f8f97cc1710b22e21e3f4cb59d 100644 --- a/source/core/Engine.cpp +++ b/source/core/Engine.cpp @@ -25,18 +25,18 @@ Engine::Engine(ADIOS &adios, std::string engineType, std::string name, m_Method(method), m_ADIOS(adios), m_DebugMode(debugMode), m_nThreads(nthreads), m_EndMessage(std::move(endMessage)) { - if (m_DebugMode == true) - { - if (m_MPIComm == MPI_COMM_NULL) + if (m_DebugMode == true) { - throw std::ios_base::failure( - "ERROR: engine communicator is MPI_COMM_NULL," - " in call to ADIOS Open or Constructor\n"); + if (m_MPIComm == MPI_COMM_NULL) + { + throw std::ios_base::failure( + "ERROR: engine communicator is MPI_COMM_NULL," + " in call to ADIOS Open or Constructor\n"); + } } - } - MPI_Comm_rank(m_MPIComm, &m_RankMPI); - MPI_Comm_size(m_MPIComm, &m_SizeMPI); + MPI_Comm_rank(m_MPIComm, &m_RankMPI); + MPI_Comm_size(m_MPIComm, &m_SizeMPI); } void Engine::SetCallBack(std::function<void(const void *, std::string, @@ -181,95 +181,95 @@ void Engine::Close(const int /*transportIndex*/) {} Variable<void> *Engine::InquireVariable(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<char> *Engine::InquireVariableChar(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<unsigned char> * Engine::InquireVariableUChar(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<short> *Engine::InquireVariableShort(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<unsigned short> * Engine::InquireVariableUShort(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<int> *Engine::InquireVariableInt(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<unsigned int> *Engine::InquireVariableUInt(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<long int> *Engine::InquireVariableLInt(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<unsigned long int> * Engine::InquireVariableULInt(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<long long int> * Engine::InquireVariableLLInt(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<unsigned long long int> * Engine::InquireVariableULLInt(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<float> *Engine::InquireVariableFloat(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<double> *Engine::InquireVariableDouble(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<long double> * Engine::InquireVariableLDouble(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<std::complex<float>> * Engine::InquireVariableCFloat(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<std::complex<double>> * Engine::InquireVariableCDouble(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } Variable<std::complex<long double>> * Engine::InquireVariableCLDouble(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } VariableCompound *Engine::InquireVariableCompound(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } void Engine::Read(Variable<double> & /*variable*/, const double * /*values*/) {} @@ -291,72 +291,72 @@ void Engine::CheckParameter( const std::map<std::string, std::string> ¶meters, const std::string parameterName, const std::string hint) const { - if (itParam == parameters.end()) - { + if (itParam == parameters.end()) { - throw std::invalid_argument("ERROR: parameter name " + parameterName + - " not found " + hint); + { + throw std::invalid_argument("ERROR: parameter name " + + parameterName + " not found " + hint); + } } - } } bool Engine::TransportNamesUniqueness() const { - auto lf_CheckTransportsType = - [&](const std::set<std::string> &specificType) -> bool { - std::set<std::string> transportNames; + auto lf_CheckTransportsType = + [&](const std::set<std::string> &specificType) -> bool { + std::set<std::string> transportNames; - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itTransport = parameters.find("transport"); - if (m_DebugMode == true) - { - if (itTransport == parameters.end()) + for (const auto ¶meters : m_Method.m_TransportParameters) { - throw std::invalid_argument( - "ERROR: transport not defined in Method input to Engine " + - m_Name); - } - } + auto itTransport = parameters.find("transport"); + if (m_DebugMode == true) + { + if (itTransport == parameters.end()) + { + throw std::invalid_argument("ERROR: transport not defined " + "in Method input to Engine " + + m_Name); + } + } - const std::string type(itTransport->second); - if (specificType.count(type) == 1) // file transports type - { - std::string name(m_Name); - auto itName = parameters.find("name"); - if (itName != parameters.end()) - { - name = itName->second; - } + const std::string type(itTransport->second); + if (specificType.count(type) == 1) // file transports type + { + std::string name(m_Name); + auto itName = parameters.find("name"); + if (itName != parameters.end()) + { + name = itName->second; + } - if (transportNames.count(name) == 0) - { - transportNames.insert(name); - } - else - { - return false; + if (transportNames.count(name) == 0) + { + transportNames.insert(name); + } + else + { + return false; + } + } } - } - } - return true; - }; + return true; + }; - return lf_CheckTransportsType(Support::FileTransports); + return lf_CheckTransportsType(Support::FileTransports); } void Engine::CheckTransportIndex(const int transportIndex) { - if (m_DebugMode == true) - { - if (transportIndex >= static_cast<int>(m_Transports.size()) || - transportIndex < -1) + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: transport index " + std::to_string(transportIndex) + - " is out of range, in call to " + m_Name + "Close \n"); + if (transportIndex >= static_cast<int>(m_Transports.size()) || + transportIndex < -1) + { + throw std::invalid_argument( + "ERROR: transport index " + std::to_string(transportIndex) + + " is out of range, in call to " + m_Name + "Close \n"); + } } - } } } // end namespace adios diff --git a/source/core/Method.cpp b/source/core/Method.cpp index 905b04f9e4c50d6b172c20cfaee909be7309dcb9..02d1750344feb7fa6b2a5154394a7cb08cb396fd 100644 --- a/source/core/Method.cpp +++ b/source/core/Method.cpp @@ -19,56 +19,57 @@ namespace adios Method::Method(std::string name, bool debugMode) : m_Name{std::move(name)}, m_DebugMode{debugMode} { - // m_Type can stay empty (forcing the choice of the default engine) - m_nThreads = 1; + // m_Type can stay empty (forcing the choice of the default engine) + m_nThreads = 1; } bool Method::isUserDefined() { - return false; // TODO(wfg): check if XML has the method defined + return false; // TODO(wfg): check if XML has the method defined } void Method::SetEngine(const std::string type) { m_Type = type; } void Method::AllowThreads(const int nThreads) { - if (nThreads > 1) - { - m_nThreads = nThreads; - } - else - { - m_nThreads = 1; - } + if (nThreads > 1) + { + m_nThreads = nThreads; + } + else + { + m_nThreads = 1; + } } // PRIVATE Functions void Method::AddTransportParameters(const std::string type, const std::vector<std::string> ¶meters) { - if (m_DebugMode == true) - { - if (type.empty() || type.find("=") != type.npos) + if (m_DebugMode == true) { - throw std::invalid_argument("ERROR: first argument in AddTransport must " - "be a single word for transport\n"); + if (type.empty() || type.find("=") != type.npos) + { + throw std::invalid_argument( + "ERROR: first argument in AddTransport must " + "be a single word for transport\n"); + } } - } - std::map<std::string, std::string> mapParameters = - BuildParametersMap(parameters, m_DebugMode); - if (m_DebugMode == true) - { - if (mapParameters.count("transport") == 1) + std::map<std::string, std::string> mapParameters = + BuildParametersMap(parameters, m_DebugMode); + if (m_DebugMode == true) { - std::invalid_argument( - "ERROR: transport can't be redefined with \"transport=type\", " - "type must be the first argument\n"); + if (mapParameters.count("transport") == 1) + { + std::invalid_argument("ERROR: transport can't be redefined with " + "\"transport=type\", " + "type must be the first argument\n"); + } } - } - mapParameters["transport"] = type; - m_TransportParameters.push_back(mapParameters); + mapParameters["transport"] = type; + m_TransportParameters.push_back(mapParameters); } } // end namespace adios diff --git a/source/core/Transport.cpp b/source/core/Transport.cpp index 29fbc773e19e3ecd398f6d4bd79fcae8fe185cda..a3a3e2505be5df43a9345377994ca2446bf175cc 100644 --- a/source/core/Transport.cpp +++ b/source/core/Transport.cpp @@ -18,8 +18,8 @@ namespace adios Transport::Transport(std::string type, MPI_Comm mpiComm, bool debugMode) : m_Type{std::move(type)}, m_MPIComm{mpiComm}, m_DebugMode{debugMode} { - MPI_Comm_rank(m_MPIComm, &m_RankMPI); - MPI_Comm_size(m_MPIComm, &m_SizeMPI); + MPI_Comm_rank(m_MPIComm, &m_RankMPI); + MPI_Comm_size(m_MPIComm, &m_SizeMPI); } void Transport::SetBuffer(char * /*buffer*/, size_t /*size*/) {} @@ -31,27 +31,27 @@ void Transport::Close() {} void Transport::InitProfiler(const std::string accessMode, const Support::Resolutions resolution) { - m_Profiler.m_Timers.emplace_back("open", Support::Resolutions::mus); + m_Profiler.m_Timers.emplace_back("open", Support::Resolutions::mus); - if (accessMode == "w" || accessMode == "write") - { - m_Profiler.m_Timers.emplace_back("write", resolution); - } + if (accessMode == "w" || accessMode == "write") + { + m_Profiler.m_Timers.emplace_back("write", resolution); + } - else if (accessMode == "a" || accessMode == "append") - { - m_Profiler.m_Timers.emplace_back("append", resolution); - } + else if (accessMode == "a" || accessMode == "append") + { + m_Profiler.m_Timers.emplace_back("append", resolution); + } - else if (accessMode == "r" || accessMode == "read") - { - m_Profiler.m_Timers.emplace_back("read", resolution); - } + else if (accessMode == "r" || accessMode == "read") + { + m_Profiler.m_Timers.emplace_back("read", resolution); + } - m_Profiler.m_Timers.emplace_back("close", Support::Resolutions::mus); + m_Profiler.m_Timers.emplace_back("close", Support::Resolutions::mus); - m_Profiler.m_TotalBytes.push_back(0); - m_Profiler.m_IsActive = true; + m_Profiler.m_TotalBytes.push_back(0); + m_Profiler.m_IsActive = true; } } // end namespace adios diff --git a/source/engine/adios1/ADIOS1Reader.cpp b/source/engine/adios1/ADIOS1Reader.cpp index 406c752d39d2e8357c1a0a008c2d2a975cf80425..e3ff93ec01d049bebf8e00c5a03485cc85ef5c2a 100644 --- a/source/engine/adios1/ADIOS1Reader.cpp +++ b/source/engine/adios1/ADIOS1Reader.cpp @@ -30,7 +30,7 @@ BPFileReader::BPFileReader(ADIOS &adios, const std::string name, nthreads, " BPFileReader constructor (or call to ADIOS Open).\n"), m_Buffer(accessMode, m_RankMPI, m_DebugMode) { - Init(); + Init(); } BPFileReader::~BPFileReader() {} @@ -39,109 +39,109 @@ Variable<void> * BPFileReader::InquireVariable(const std::string name, const bool readIn) // not yet implemented { - return nullptr; + return nullptr; } Variable<char> *BPFileReader::InquireVariableChar(const std::string name, const bool readIn) { - return InquireVariableCommon<char>(name, readIn); + return InquireVariableCommon<char>(name, readIn); } Variable<unsigned char> * BPFileReader::InquireVariableUChar(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned char>(name, readIn); + return InquireVariableCommon<unsigned char>(name, readIn); } Variable<short> *BPFileReader::InquireVariableShort(const std::string name, const bool readIn) { - return InquireVariableCommon<short>(name, readIn); + return InquireVariableCommon<short>(name, readIn); } Variable<unsigned short> * BPFileReader::InquireVariableUShort(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned short>(name, readIn); + return InquireVariableCommon<unsigned short>(name, readIn); } Variable<int> *BPFileReader::InquireVariableInt(const std::string name, const bool readIn) { - return InquireVariableCommon<int>(name, readIn); + return InquireVariableCommon<int>(name, readIn); } Variable<unsigned int> * BPFileReader::InquireVariableUInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned int>(name, readIn); + return InquireVariableCommon<unsigned int>(name, readIn); } Variable<long int> *BPFileReader::InquireVariableLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<long int>(name, readIn); + return InquireVariableCommon<long int>(name, readIn); } Variable<unsigned long int> * BPFileReader::InquireVariableULInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned long int>(name, readIn); + return InquireVariableCommon<unsigned long int>(name, readIn); } Variable<long long int> * BPFileReader::InquireVariableLLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<long long int>(name, readIn); + return InquireVariableCommon<long long int>(name, readIn); } Variable<unsigned long long int> * BPFileReader::InquireVariableULLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned long long int>(name, readIn); + return InquireVariableCommon<unsigned long long int>(name, readIn); } Variable<float> *BPFileReader::InquireVariableFloat(const std::string name, const bool readIn) { - return InquireVariableCommon<float>(name, readIn); + return InquireVariableCommon<float>(name, readIn); } Variable<double> *BPFileReader::InquireVariableDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<double>(name, readIn); + return InquireVariableCommon<double>(name, readIn); } Variable<long double> * BPFileReader::InquireVariableLDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<long double>(name, readIn); + return InquireVariableCommon<long double>(name, readIn); } Variable<std::complex<float>> * BPFileReader::InquireVariableCFloat(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<float>>(name, readIn); + return InquireVariableCommon<std::complex<float>>(name, readIn); } Variable<std::complex<double>> * BPFileReader::InquireVariableCDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<double>>(name, readIn); + return InquireVariableCommon<std::complex<double>>(name, readIn); } Variable<std::complex<long double>> * BPFileReader::InquireVariableCLDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<long double>>(name, readIn); + return InquireVariableCommon<std::complex<long double>>(name, readIn); } VariableCompound *BPFileReader::InquireVariableCompound(const std::string name, const bool readIn) { - return nullptr; + return nullptr; } void BPFileReader::Close(const int transportIndex) {} @@ -149,84 +149,87 @@ void BPFileReader::Close(const int transportIndex) {} // PRIVATE void BPFileReader::Init() { - if (m_DebugMode == true) - { - if (m_AccessMode != "r" && m_AccessMode != "read") - throw std::invalid_argument( - "ERROR: BPFileReader doesn't support access mode " + m_AccessMode + - ", in call to ADIOS Open or BPFileReader constructor\n"); - } + if (m_DebugMode == true) + { + if (m_AccessMode != "r" && m_AccessMode != "read") + throw std::invalid_argument( + "ERROR: BPFileReader doesn't support access mode " + + m_AccessMode + + ", in call to ADIOS Open or BPFileReader constructor\n"); + } - InitCapsules(); - InitTransports(); + InitCapsules(); + InitTransports(); } void BPFileReader::InitCapsules() { - // here init memory capsules + // here init memory capsules } void BPFileReader::InitTransports() // maybe move this? { - if (m_DebugMode == true) - { - if (TransportNamesUniqueness() == false) + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: two transports of the same kind (e.g file IO) " - "can't have the same name, modify with name= in Method " - "AddTransport\n"); + if (TransportNamesUniqueness() == false) + { + throw std::invalid_argument( + "ERROR: two transports of the same kind (e.g file IO) " + "can't have the same name, modify with name= in Method " + "AddTransport\n"); + } } - } - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itTransport = parameters.find("transport"); - if (itTransport->second == "file" || itTransport->second == "File") - { - auto itLibrary = parameters.find("library"); - if (itLibrary == parameters.end() || - itLibrary->second == "POSIX") // use default POSIX - { - auto file = - std::make_shared<transport::FileDescriptor>(m_MPIComm, m_DebugMode); - // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "FILE*" || itLibrary->second == "stdio.h") - { - auto file = - std::make_shared<transport::FilePointer>(m_MPIComm, m_DebugMode); - // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "fstream" || - itLibrary->second == "std::fstream") - { - auto file = - std::make_shared<transport::FStream>(m_MPIComm, m_DebugMode); - // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "MPI-IO") - { - } - else - { - if (m_DebugMode == true) - throw std::invalid_argument( - "ERROR: file transport library " + itLibrary->second + - " not supported, in " + m_Name + m_EndMessage); - } - } - else + for (const auto ¶meters : m_Method.m_TransportParameters) { - if (m_DebugMode == true) - throw std::invalid_argument("ERROR: transport " + itTransport->second + - " (you mean File?) not supported, in " + - m_Name + m_EndMessage); + auto itTransport = parameters.find("transport"); + if (itTransport->second == "file" || itTransport->second == "File") + { + auto itLibrary = parameters.find("library"); + if (itLibrary == parameters.end() || + itLibrary->second == "POSIX") // use default POSIX + { + auto file = std::make_shared<transport::FileDescriptor>( + m_MPIComm, m_DebugMode); + // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "FILE*" || + itLibrary->second == "stdio.h") + { + auto file = std::make_shared<transport::FilePointer>( + m_MPIComm, m_DebugMode); + // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "fstream" || + itLibrary->second == "std::fstream") + { + auto file = std::make_shared<transport::FStream>(m_MPIComm, + m_DebugMode); + // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "MPI-IO") + { + } + else + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: file transport library " + itLibrary->second + + " not supported, in " + m_Name + m_EndMessage); + } + } + else + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: transport " + itTransport->second + + " (you mean File?) not supported, in " + m_Name + + m_EndMessage); + } } - } } } // end namespace diff --git a/source/engine/adios1/ADIOS1Writer.cpp b/source/engine/adios1/ADIOS1Writer.cpp index dc45da793801236e09720ba4a5626067a9fe7290..81813dc63f759ec71aeebc70c13e1968f1b57aba 100644 --- a/source/engine/adios1/ADIOS1Writer.cpp +++ b/source/engine/adios1/ADIOS1Writer.cpp @@ -28,49 +28,49 @@ ADIOS1Writer::ADIOS1Writer(ADIOS &adios, const std::string name, nthreads, " ADIOS1Writer constructor (or call to ADIOS Open).\n"), m_groupname{method.m_Name.c_str()}, m_filename{name.c_str()}, m_comm{mpiComm} { - Init(); - adios_open(&m_adios_file, m_groupname, m_filename, accessMode.c_str(), - m_comm); - if (adios_errno == err_no_error) - { - m_IsFileOpen = true; - } + Init(); + adios_open(&m_adios_file, m_groupname, m_filename, accessMode.c_str(), + m_comm); + if (adios_errno == err_no_error) + { + m_IsFileOpen = true; + } } ADIOS1Writer::~ADIOS1Writer() { - if (m_IsFileOpen) - { - adios_close(m_adios_file); - m_IsFileOpen = false; - } + if (m_IsFileOpen) + { + adios_close(m_adios_file); + m_IsFileOpen = false; + } } void ADIOS1Writer::Init() { - if (!m_initialized) - { - adios_init_noxml(m_comm); - m_initialized = true; - } - adios_declare_group(&m_adios_group, m_groupname, "", adios_stat_default); + if (!m_initialized) + { + adios_init_noxml(m_comm); + m_initialized = true; + } + adios_declare_group(&m_adios_group, m_groupname, "", adios_stat_default); - InitParameters(); - InitTransports(); + InitParameters(); + InitTransports(); } bool ADIOS1Writer::ReOpenAsNeeded() { - if (!m_IsFileOpen) - { - adios_open(&m_adios_file, m_groupname, m_filename, "a", m_comm); - if (adios_errno == err_no_error) + if (!m_IsFileOpen) { - m_IsFileOpen = true; - adios_delete_vardefs(m_adios_group); + adios_open(&m_adios_file, m_groupname, m_filename, "a", m_comm); + if (adios_errno == err_no_error) + { + m_IsFileOpen = true; + adios_delete_vardefs(m_adios_group); + } } - } - return m_IsFileOpen; + return m_IsFileOpen; } void ADIOS1Writer::DefineVariable(std::string name, bool isScalar, @@ -78,15 +78,15 @@ void ADIOS1Writer::DefineVariable(std::string name, bool isScalar, std::string ldims, std::string gdims, std::string offs) { - if (isScalar) - { - adios_define_var(m_adios_group, name.c_str(), "", vartype, "", "", ""); - } - else - { - adios_define_var(m_adios_group, name.c_str(), "", vartype, ldims.c_str(), - gdims.c_str(), offs.c_str()); - } + if (isScalar) + { + adios_define_var(m_adios_group, name.c_str(), "", vartype, "", "", ""); + } + else + { + adios_define_var(m_adios_group, name.c_str(), "", vartype, + ldims.c_str(), gdims.c_str(), offs.c_str()); + } } void ADIOS1Writer::WriteVariable(std::string name, bool isScalar, @@ -94,357 +94,362 @@ void ADIOS1Writer::WriteVariable(std::string name, bool isScalar, std::string ldims, std::string gdims, std::string offs, const void *values) { - if (ReOpenAsNeeded()) - { - DefineVariable(name, isScalar, vartype, ldims, gdims, offs); - adios_write(m_adios_file, name.c_str(), values); - } + if (ReOpenAsNeeded()) + { + DefineVariable(name, isScalar, vartype, ldims, gdims, offs); + adios_write(m_adios_file, name.c_str(), values); + } } void ADIOS1Writer::Write(Variable<char> &variable, const char *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_byte, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_byte, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<unsigned char> &variable, const unsigned char *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_byte, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_byte, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<short> &variable, const short *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_short, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_short, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<unsigned short> &variable, const unsigned short *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_short, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_short, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<int> &variable, const int *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_integer, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_integer, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<unsigned int> &variable, const unsigned int *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_integer, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_integer, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<long int> &variable, const long int *values) { - enum ADIOS_DATATYPES type = - adios_integer; // long int is usually 4 bytes which is adios_integer - if (sizeof(long int) == 8) - { - type = adios_long; - } - WriteVariable(variable.m_Name, variable.m_IsScalar, type, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + enum ADIOS_DATATYPES type = + adios_integer; // long int is usually 4 bytes which is adios_integer + if (sizeof(long int) == 8) + { + type = adios_long; + } + WriteVariable(variable.m_Name, variable.m_IsScalar, type, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<unsigned long int> &variable, const unsigned long int *values) { - enum ADIOS_DATATYPES type = - adios_unsigned_integer; // long int is usually 4 bytes - if (sizeof(long int) == 8) - { - type = adios_unsigned_long; - } - WriteVariable(variable.m_Name, variable.m_IsScalar, type, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + enum ADIOS_DATATYPES type = + adios_unsigned_integer; // long int is usually 4 bytes + if (sizeof(long int) == 8) + { + type = adios_unsigned_long; + } + WriteVariable(variable.m_Name, variable.m_IsScalar, type, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<long long int> &variable, const long long int *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_long, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_long, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<unsigned long long int> &variable, const unsigned long long int *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_long, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_unsigned_long, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<float> &variable, const float *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_real, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_real, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<double> &variable, const double *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_double, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_double, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<long double> &variable, const long double *values) { - /* TODO: This is faulty: adios_long_double expects 16 bytes per elements, but - * long double is compiler dependent */ - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_long_double, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + /* TODO: This is faulty: adios_long_double expects 16 bytes per elements, + * but + * long double is compiler dependent */ + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_long_double, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<std::complex<float>> &variable, const std::complex<float> *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_complex, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_complex, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<std::complex<double>> &variable, const std::complex<double> *values) { - WriteVariable(variable.m_Name, variable.m_IsScalar, adios_double_complex, - variable.GetDimensionAsString(), - variable.GetGlobalDimensionAsString(), - variable.GetOffsetsAsString(), values); + WriteVariable(variable.m_Name, variable.m_IsScalar, adios_double_complex, + variable.GetDimensionAsString(), + variable.GetGlobalDimensionAsString(), + variable.GetOffsetsAsString(), values); } void ADIOS1Writer::Write(Variable<std::complex<long double>> &variable, const std::complex<long double> *values) { - throw std::invalid_argument("ERROR: Adios 1.x does not support complex<long " - "double> type, so it cannot write variable " + - variable.m_Name + "\n"); + throw std::invalid_argument( + "ERROR: Adios 1.x does not support complex<long " + "double> type, so it cannot write variable " + + variable.m_Name + "\n"); } void ADIOS1Writer::Write(VariableCompound &variable, const void *values) { - throw std::invalid_argument("ERROR: Adios 1.x does not support compound " - "types, so it cannot write variable " + - variable.m_Name + "\n"); + throw std::invalid_argument("ERROR: Adios 1.x does not support compound " + "types, so it cannot write variable " + + variable.m_Name + "\n"); } // String version void ADIOS1Writer::Write(const std::string variableName, const char *values) { - Write(m_ADIOS.GetVariable<char>(variableName), values); + Write(m_ADIOS.GetVariable<char>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const unsigned char *values) { - Write(m_ADIOS.GetVariable<unsigned char>(variableName), values); + Write(m_ADIOS.GetVariable<unsigned char>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const short *values) { - Write(m_ADIOS.GetVariable<short>(variableName), values); + Write(m_ADIOS.GetVariable<short>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const unsigned short *values) { - Write(m_ADIOS.GetVariable<unsigned short>(variableName), values); + Write(m_ADIOS.GetVariable<unsigned short>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const int *values) { - Write(m_ADIOS.GetVariable<int>(variableName), values); + Write(m_ADIOS.GetVariable<int>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const unsigned int *values) { - Write(m_ADIOS.GetVariable<unsigned int>(variableName), values); + Write(m_ADIOS.GetVariable<unsigned int>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const long int *values) { - Write(m_ADIOS.GetVariable<long int>(variableName), values); + Write(m_ADIOS.GetVariable<long int>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const unsigned long int *values) { - Write(m_ADIOS.GetVariable<unsigned long int>(variableName), values); + Write(m_ADIOS.GetVariable<unsigned long int>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const long long int *values) { - Write(m_ADIOS.GetVariable<long long int>(variableName), values); + Write(m_ADIOS.GetVariable<long long int>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const unsigned long long int *values) { - Write(m_ADIOS.GetVariable<unsigned long long int>(variableName), values); + Write(m_ADIOS.GetVariable<unsigned long long int>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const float *values) { - Write(m_ADIOS.GetVariable<float>(variableName), values); + Write(m_ADIOS.GetVariable<float>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const double *values) { - Write(m_ADIOS.GetVariable<double>(variableName), values); + Write(m_ADIOS.GetVariable<double>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const long double *values) { - Write(m_ADIOS.GetVariable<long double>(variableName), values); + Write(m_ADIOS.GetVariable<long double>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const std::complex<float> *values) { - Write(m_ADIOS.GetVariable<std::complex<float>>(variableName), values); + Write(m_ADIOS.GetVariable<std::complex<float>>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const std::complex<double> *values) { - Write(m_ADIOS.GetVariable<std::complex<double>>(variableName), values); + Write(m_ADIOS.GetVariable<std::complex<double>>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const std::complex<long double> *values) { - Write(m_ADIOS.GetVariable<std::complex<long double>>(variableName), values); + Write(m_ADIOS.GetVariable<std::complex<long double>>(variableName), values); } void ADIOS1Writer::Write(const std::string variableName, const void *values) // Compound type { - throw std::invalid_argument("ERROR: Adios 1.x does not support compound " - "types, so it cannot write variable " + - variableName + "\n"); + throw std::invalid_argument("ERROR: Adios 1.x does not support compound " + "types, so it cannot write variable " + + variableName + "\n"); } void ADIOS1Writer::Advance() { - if (m_IsFileOpen) - { - adios_close(m_adios_file); - m_IsFileOpen = false; - } + if (m_IsFileOpen) + { + adios_close(m_adios_file); + m_IsFileOpen = false; + } } void ADIOS1Writer::Close(const int transportIndex) { - if (m_IsFileOpen) - { - adios_close(m_adios_file); - m_IsFileOpen = false; - } + if (m_IsFileOpen) + { + adios_close(m_adios_file); + m_IsFileOpen = false; + } } // PRIVATE FUNCTIONS void ADIOS1Writer::InitParameters() { - auto itMaxBufferSize = m_Method.m_Parameters.find("max_size_MB"); - if (itMaxBufferSize != m_Method.m_Parameters.end()) - { - adios_set_max_buffer_size(std::stoul(itMaxBufferSize->second)); - } + auto itMaxBufferSize = m_Method.m_Parameters.find("max_size_MB"); + if (itMaxBufferSize != m_Method.m_Parameters.end()) + { + adios_set_max_buffer_size(std::stoul(itMaxBufferSize->second)); + } - auto itVerbosity = m_Method.m_Parameters.find("verbose"); - if (itVerbosity != m_Method.m_Parameters.end()) - { - int verbosity = std::stoi(itVerbosity->second); - if (m_DebugMode == true) + auto itVerbosity = m_Method.m_Parameters.find("verbose"); + if (itVerbosity != m_Method.m_Parameters.end()) { - if (verbosity < 0 || verbosity > 5) - throw std::invalid_argument("ERROR: Method verbose argument must be an " - "integer in the range [0,5], in call to " - "Open or Engine constructor\n"); + int verbosity = std::stoi(itVerbosity->second); + if (m_DebugMode == true) + { + if (verbosity < 0 || verbosity > 5) + throw std::invalid_argument( + "ERROR: Method verbose argument must be an " + "integer in the range [0,5], in call to " + "Open or Engine constructor\n"); + } + adios_verbose_level = verbosity; } - adios_verbose_level = verbosity; - } } void ADIOS1Writer::InitTransports() { - if (m_DebugMode == true) - { - if (TransportNamesUniqueness() == false) + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: two transports of the same kind (e.g file IO) " - "can't have the same name, modify with name= in Method " - "AddTransport\n"); + if (TransportNamesUniqueness() == false) + { + throw std::invalid_argument( + "ERROR: two transports of the same kind (e.g file IO) " + "can't have the same name, modify with name= in Method " + "AddTransport\n"); + } } - } - - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itTransport = parameters.find("transport"); - if (itTransport->second == "file" || itTransport->second == "File") - { - auto itLibrary = parameters.find("library"); - if (itLibrary == parameters.end() || - itLibrary->second == "POSIX") // use default POSIX - { - adios_select_method(m_adios_group, "POSIX", "", ""); - } - else if (itLibrary->second == "MPI_File" || itLibrary->second == "MPI-IO") - { - adios_select_method(m_adios_group, "MPI", "", ""); - } - else - { - if (m_DebugMode == true) - throw std::invalid_argument( - "ERROR: file transport library " + itLibrary->second + - " not supported, in " + m_Name + m_EndMessage); - } - } - else + for (const auto ¶meters : m_Method.m_TransportParameters) { - if (m_DebugMode == true) - throw std::invalid_argument("ERROR: transport " + itTransport->second + - " (you mean File?) not supported, in " + - m_Name + m_EndMessage); + auto itTransport = parameters.find("transport"); + + if (itTransport->second == "file" || itTransport->second == "File") + { + auto itLibrary = parameters.find("library"); + if (itLibrary == parameters.end() || + itLibrary->second == "POSIX") // use default POSIX + { + adios_select_method(m_adios_group, "POSIX", "", ""); + } + else if (itLibrary->second == "MPI_File" || + itLibrary->second == "MPI-IO") + { + adios_select_method(m_adios_group, "MPI", "", ""); + } + else + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: file transport library " + itLibrary->second + + " not supported, in " + m_Name + m_EndMessage); + } + } + else + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: transport " + itTransport->second + + " (you mean File?) not supported, in " + m_Name + + m_EndMessage); + } } - } } } // end namespace adios diff --git a/source/engine/bp/BPFileReader.cpp b/source/engine/bp/BPFileReader.cpp index e658e5580d3046b6cde1847a09c65f2d71d5de4e..b12b655e0f6327c094c9757f3cf255408db3ddfe 100644 --- a/source/engine/bp/BPFileReader.cpp +++ b/source/engine/bp/BPFileReader.cpp @@ -31,117 +31,117 @@ BPFileReader::BPFileReader(ADIOS &adios, std::string name, " BPFileReader constructor (or call to ADIOS Open).\n"), m_Buffer(accessMode, m_RankMPI, m_DebugMode) { - Init(); + Init(); } Variable<void> *BPFileReader::InquireVariable(const std::string /*name*/, const bool /*readIn*/) { - // not yet implemented - return nullptr; + // not yet implemented + return nullptr; } Variable<char> *BPFileReader::InquireVariableChar(const std::string name, const bool readIn) { - return InquireVariableCommon<char>(name, readIn); + return InquireVariableCommon<char>(name, readIn); } Variable<unsigned char> * BPFileReader::InquireVariableUChar(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned char>(name, readIn); + return InquireVariableCommon<unsigned char>(name, readIn); } Variable<short> *BPFileReader::InquireVariableShort(const std::string name, const bool readIn) { - return InquireVariableCommon<short>(name, readIn); + return InquireVariableCommon<short>(name, readIn); } Variable<unsigned short> * BPFileReader::InquireVariableUShort(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned short>(name, readIn); + return InquireVariableCommon<unsigned short>(name, readIn); } Variable<int> *BPFileReader::InquireVariableInt(const std::string name, const bool readIn) { - return InquireVariableCommon<int>(name, readIn); + return InquireVariableCommon<int>(name, readIn); } Variable<unsigned int> * BPFileReader::InquireVariableUInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned int>(name, readIn); + return InquireVariableCommon<unsigned int>(name, readIn); } Variable<long int> *BPFileReader::InquireVariableLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<long int>(name, readIn); + return InquireVariableCommon<long int>(name, readIn); } Variable<unsigned long int> * BPFileReader::InquireVariableULInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned long int>(name, readIn); + return InquireVariableCommon<unsigned long int>(name, readIn); } Variable<long long int> * BPFileReader::InquireVariableLLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<long long int>(name, readIn); + return InquireVariableCommon<long long int>(name, readIn); } Variable<unsigned long long int> * BPFileReader::InquireVariableULLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned long long int>(name, readIn); + return InquireVariableCommon<unsigned long long int>(name, readIn); } Variable<float> *BPFileReader::InquireVariableFloat(const std::string name, const bool readIn) { - return InquireVariableCommon<float>(name, readIn); + return InquireVariableCommon<float>(name, readIn); } Variable<double> *BPFileReader::InquireVariableDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<double>(name, readIn); + return InquireVariableCommon<double>(name, readIn); } Variable<long double> * BPFileReader::InquireVariableLDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<long double>(name, readIn); + return InquireVariableCommon<long double>(name, readIn); } Variable<std::complex<float>> * BPFileReader::InquireVariableCFloat(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<float>>(name, readIn); + return InquireVariableCommon<std::complex<float>>(name, readIn); } Variable<std::complex<double>> * BPFileReader::InquireVariableCDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<double>>(name, readIn); + return InquireVariableCommon<std::complex<double>>(name, readIn); } Variable<std::complex<long double>> * BPFileReader::InquireVariableCLDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<long double>>(name, readIn); + return InquireVariableCommon<std::complex<long double>>(name, readIn); } VariableCompound * BPFileReader::InquireVariableCompound(const std::string /*name*/, const bool /*readIn*/) { - return nullptr; + return nullptr; } void BPFileReader::Close(const int /*transportIndex*/) {} @@ -149,90 +149,93 @@ void BPFileReader::Close(const int /*transportIndex*/) {} // PRIVATE void BPFileReader::Init() { - if (m_DebugMode == true) - { - if (m_AccessMode != "r" && m_AccessMode != "read") + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: BPFileReader doesn't support access mode " + m_AccessMode + - ", in call to ADIOS Open or BPFileReader constructor\n"); + if (m_AccessMode != "r" && m_AccessMode != "read") + { + throw std::invalid_argument( + "ERROR: BPFileReader doesn't support access mode " + + m_AccessMode + + ", in call to ADIOS Open or BPFileReader constructor\n"); + } } - } - InitCapsules(); - InitTransports(); + InitCapsules(); + InitTransports(); } void BPFileReader::InitCapsules() { - // here init memory capsules + // here init memory capsules } void BPFileReader::InitTransports() // maybe move this? { - if (m_DebugMode == true) - { - if (TransportNamesUniqueness() == false) + if (m_DebugMode == true) { - throw std::invalid_argument( - "ERROR: two transports of the same kind (e.g file IO) " - "can't have the same name, modify with name= in Method " - "AddTransport\n"); + if (TransportNamesUniqueness() == false) + { + throw std::invalid_argument( + "ERROR: two transports of the same kind (e.g file IO) " + "can't have the same name, modify with name= in Method " + "AddTransport\n"); + } } - } - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itTransport = parameters.find("transport"); - if (itTransport->second == "file" || itTransport->second == "File") + for (const auto ¶meters : m_Method.m_TransportParameters) { - auto itLibrary = parameters.find("library"); - if (itLibrary == parameters.end() || - itLibrary->second == "POSIX") // use default POSIX - { - auto file = - std::make_shared<transport::FileDescriptor>(m_MPIComm, m_DebugMode); - // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "FILE*" || itLibrary->second == "stdio.h") - { - auto file = - std::make_shared<transport::FilePointer>(m_MPIComm, m_DebugMode); - // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "fstream" || - itLibrary->second == "std::fstream") - { - auto file = - std::make_shared<transport::FStream>(m_MPIComm, m_DebugMode); - // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "MPI-IO") - { - } - else - { - if (m_DebugMode == true) + auto itTransport = parameters.find("transport"); + if (itTransport->second == "file" || itTransport->second == "File") { - throw std::invalid_argument( - "ERROR: file transport library " + itLibrary->second + - " not supported, in " + m_Name + m_EndMessage); + auto itLibrary = parameters.find("library"); + if (itLibrary == parameters.end() || + itLibrary->second == "POSIX") // use default POSIX + { + auto file = std::make_shared<transport::FileDescriptor>( + m_MPIComm, m_DebugMode); + // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "FILE*" || + itLibrary->second == "stdio.h") + { + auto file = std::make_shared<transport::FilePointer>( + m_MPIComm, m_DebugMode); + // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "fstream" || + itLibrary->second == "std::fstream") + { + auto file = std::make_shared<transport::FStream>(m_MPIComm, + m_DebugMode); + // m_BP1Reader.OpenRankFiles( m_Name, m_AccessMode, *file ); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "MPI-IO") + { + } + else + { + if (m_DebugMode == true) + { + throw std::invalid_argument( + "ERROR: file transport library " + itLibrary->second + + " not supported, in " + m_Name + m_EndMessage); + } + } + } + else + { + if (m_DebugMode == true) + { + throw std::invalid_argument( + "ERROR: transport " + itTransport->second + + " (you mean File?) not supported, in " + m_Name + + m_EndMessage); + } } - } - } - else - { - if (m_DebugMode == true) - { - throw std::invalid_argument("ERROR: transport " + itTransport->second + - " (you mean File?) not supported, in " + - m_Name + m_EndMessage); - } } - } } } // end namespace adios diff --git a/source/engine/bp/BPFileWriter.cpp b/source/engine/bp/BPFileWriter.cpp index eb85db8e5b70c4dace2d7e30874b0d715f967fe7..62f6c4d72c34678fcb987787d58b23b8568dadb9 100644 --- a/source/engine/bp/BPFileWriter.cpp +++ b/source/engine/bp/BPFileWriter.cpp @@ -32,107 +32,108 @@ BPFileWriter::BPFileWriter(ADIOS &adios, std::string name, m_BP1Aggregator(m_MPIComm, debugMode), m_MaxBufferSize(m_Buffer.m_Data.max_size()) { - m_MetadataSet.TimeStep = 1; // starting at one to be compatible with ADIOS1.x - Init(); + m_MetadataSet.TimeStep = + 1; // starting at one to be compatible with ADIOS1.x + Init(); } BPFileWriter::~BPFileWriter() = default; void BPFileWriter::Init() { - InitParameters(); - InitTransports(); - InitProcessGroup(); + InitParameters(); + InitTransports(); + InitProcessGroup(); } void BPFileWriter::Write(Variable<char> &variable, const char *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<unsigned char> &variable, const unsigned char *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<short> &variable, const short *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<unsigned short> &variable, const unsigned short *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<int> &variable, const int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<unsigned int> &variable, const unsigned int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<long int> &variable, const long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<unsigned long int> &variable, const unsigned long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<long long int> &variable, const long long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<unsigned long long int> &variable, const unsigned long long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<float> &variable, const float *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<double> &variable, const double *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<long double> &variable, const long double *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<std::complex<float>> &variable, const std::complex<float> *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<std::complex<double>> &variable, const std::complex<double> *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(Variable<std::complex<long double>> &variable, const std::complex<long double> *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void BPFileWriter::Write(VariableCompound & /*variable*/, @@ -143,98 +144,101 @@ void BPFileWriter::Write(VariableCompound & /*variable*/, // String version void BPFileWriter::Write(const std::string variableName, const char *values) { - WriteVariableCommon(m_ADIOS.GetVariable<char>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<char>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const unsigned char *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned char>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned char>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const short *values) { - WriteVariableCommon(m_ADIOS.GetVariable<short>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<short>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const unsigned short *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned short>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned short>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<int>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const unsigned int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned int>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<long int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<long int>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const unsigned long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned long int>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned long int>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const long long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<long long int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<long long int>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const unsigned long long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned long long int>(variableName), - values); + WriteVariableCommon( + m_ADIOS.GetVariable<unsigned long long int>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const float *values) { - WriteVariableCommon(m_ADIOS.GetVariable<float>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<float>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const double *values) { - WriteVariableCommon(m_ADIOS.GetVariable<double>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<double>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const long double *values) { - WriteVariableCommon(m_ADIOS.GetVariable<long double>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<long double>(variableName), values); } void BPFileWriter::Write(const std::string variableName, const std::complex<float> *values) { - WriteVariableCommon(m_ADIOS.GetVariable<std::complex<float>>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<std::complex<float>>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const std::complex<double> *values) { - WriteVariableCommon(m_ADIOS.GetVariable<std::complex<double>>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<std::complex<double>>(variableName), + values); } void BPFileWriter::Write(const std::string variableName, const std::complex<long double> *values) { - WriteVariableCommon( - m_ADIOS.GetVariable<std::complex<long double>>(variableName), values); + WriteVariableCommon( + m_ADIOS.GetVariable<std::complex<long double>>(variableName), values); } void BPFileWriter::Write(const std::string /*variableName*/, @@ -244,308 +248,326 @@ void BPFileWriter::Write(const std::string /*variableName*/, void BPFileWriter::Advance(float /*timeout_sec*/) { - m_BP1Writer.Advance(m_MetadataSet, m_Buffer); + m_BP1Writer.Advance(m_MetadataSet, m_Buffer); } void BPFileWriter::Close(const int transportIndex) { - CheckTransportIndex(transportIndex); - if (transportIndex == -1) - { - for (auto &transport : m_Transports) - { // by reference or value or it doesn't matter? - m_BP1Writer.Close(m_MetadataSet, m_Buffer, *transport, m_IsFirstClose, - false); // false: not using aggregation for now + CheckTransportIndex(transportIndex); + if (transportIndex == -1) + { + for (auto &transport : m_Transports) + { // by reference or value or it doesn't matter? + m_BP1Writer.Close(m_MetadataSet, m_Buffer, *transport, + m_IsFirstClose, + false); // false: not using aggregation for now + } } - } - else - { - m_BP1Writer.Close(m_MetadataSet, m_Buffer, *m_Transports[transportIndex], - m_IsFirstClose, - false); // false: not using aggregation for now - } - - if (m_MetadataSet.Log.m_IsActive == true) - { - bool allClose = true; - for (auto &transport : m_Transports) + else { - if (transport->m_IsOpen == true) - { - allClose = false; - break; - } + m_BP1Writer.Close(m_MetadataSet, m_Buffer, + *m_Transports[transportIndex], m_IsFirstClose, + false); // false: not using aggregation for now } - if (allClose == true) // aggregate and write profiling.log + + if (m_MetadataSet.Log.m_IsActive == true) { - const std::string rankLog = m_BP1Writer.GetRankProfilingLog( - m_RankMPI, m_MetadataSet, m_Transports); + bool allClose = true; + for (auto &transport : m_Transports) + { + if (transport->m_IsOpen == true) + { + allClose = false; + break; + } + } + if (allClose == true) // aggregate and write profiling.log + { + const std::string rankLog = m_BP1Writer.GetRankProfilingLog( + m_RankMPI, m_MetadataSet, m_Transports); - const std::string fileName(m_BP1Writer.GetDirectoryName(m_Name) + - "/profiling.log"); - m_BP1Aggregator.WriteProfilingLog(fileName, rankLog); + const std::string fileName(m_BP1Writer.GetDirectoryName(m_Name) + + "/profiling.log"); + m_BP1Aggregator.WriteProfilingLog(fileName, rankLog); + } } - } } // PRIVATE FUNCTIONS void BPFileWriter::InitParameters() { - auto itGrowthFactor = m_Method.m_Parameters.find("buffer_growth"); - if (itGrowthFactor != m_Method.m_Parameters.end()) - { - const float growthFactor = std::stof(itGrowthFactor->second); - if (m_DebugMode == true) + auto itGrowthFactor = m_Method.m_Parameters.find("buffer_growth"); + if (itGrowthFactor != m_Method.m_Parameters.end()) { - if (growthFactor == 1.f) - { - throw std::invalid_argument( - "ERROR: buffer_growth argument can't be less of equal than 1, in " + - m_EndMessage + "\n"); - } - } - - m_BP1Writer.m_GrowthFactor = growthFactor; - m_GrowthFactor = growthFactor; // float - } + const float growthFactor = std::stof(itGrowthFactor->second); + if (m_DebugMode == true) + { + if (growthFactor == 1.f) + { + throw std::invalid_argument("ERROR: buffer_growth argument " + "can't be less of equal than 1, " + "in " + + m_EndMessage + "\n"); + } + } - auto itMaxBufferSize = m_Method.m_Parameters.find("max_size_MB"); - if (itMaxBufferSize != m_Method.m_Parameters.end()) - { - if (m_DebugMode == true) - { - if (m_GrowthFactor <= 1.f) - { - throw std::invalid_argument("ERROR: Method buffer_growth argument " - "can't be less of equal than 1, in " + - m_EndMessage + "\n"); - } + m_BP1Writer.m_GrowthFactor = growthFactor; + m_GrowthFactor = growthFactor; // float } - m_MaxBufferSize = std::stoul(itMaxBufferSize->second) * - 1048576; // convert from MB to bytes - } - - auto itVerbosity = m_Method.m_Parameters.find("verbose"); - if (itVerbosity != m_Method.m_Parameters.end()) - { - int verbosity = std::stoi(itVerbosity->second); - if (m_DebugMode == true) + auto itMaxBufferSize = m_Method.m_Parameters.find("max_size_MB"); + if (itMaxBufferSize != m_Method.m_Parameters.end()) { - if (verbosity < 0 || verbosity > 5) - { - throw std::invalid_argument("ERROR: Method verbose argument must be an " - "integer in the range [0,5], in call to " - "Open or Engine constructor\n"); - } - } - m_BP1Writer.m_Verbosity = verbosity; - } - - auto itProfile = m_Method.m_Parameters.find("profile_units"); - if (itProfile != m_Method.m_Parameters.end()) - { - auto &profiler = m_MetadataSet.Log; + if (m_DebugMode == true) + { + if (m_GrowthFactor <= 1.f) + { + throw std::invalid_argument( + "ERROR: Method buffer_growth argument " + "can't be less of equal than 1, in " + + m_EndMessage + "\n"); + } + } - if (itProfile->second == "mus" || itProfile->second == "microseconds") - { - profiler.m_Timers.emplace_back("buffering", Support::Resolutions::mus); - } - else if (itProfile->second == "ms" || itProfile->second == "milliseconds") - { - profiler.m_Timers.emplace_back("buffering", Support::Resolutions::ms); + m_MaxBufferSize = std::stoul(itMaxBufferSize->second) * + 1048576; // convert from MB to bytes } - else if (itProfile->second == "s" || itProfile->second == "seconds") - { - profiler.m_Timers.emplace_back("buffering", Support::Resolutions::s); - } - else if (itProfile->second == "min" || itProfile->second == "minutes") - { - profiler.m_Timers.emplace_back("buffering", Support::Resolutions::m); - } - else if (itProfile->second == "h" || itProfile->second == "hours") + + auto itVerbosity = m_Method.m_Parameters.find("verbose"); + if (itVerbosity != m_Method.m_Parameters.end()) { - profiler.m_Timers.emplace_back("buffering", Support::Resolutions::h); + int verbosity = std::stoi(itVerbosity->second); + if (m_DebugMode == true) + { + if (verbosity < 0 || verbosity > 5) + { + throw std::invalid_argument( + "ERROR: Method verbose argument must be an " + "integer in the range [0,5], in call to " + "Open or Engine constructor\n"); + } + } + m_BP1Writer.m_Verbosity = verbosity; } - else + + auto itProfile = m_Method.m_Parameters.find("profile_units"); + if (itProfile != m_Method.m_Parameters.end()) { - if (m_DebugMode == true) - { - throw std::invalid_argument("ERROR: Method profile_buffering_units " - "argument must be mus, ms, s, min or h, in " - "call to Open or Engine constructor\n"); - } - } + auto &profiler = m_MetadataSet.Log; + + if (itProfile->second == "mus" || itProfile->second == "microseconds") + { + profiler.m_Timers.emplace_back("buffering", + Support::Resolutions::mus); + } + else if (itProfile->second == "ms" || + itProfile->second == "milliseconds") + { + profiler.m_Timers.emplace_back("buffering", + Support::Resolutions::ms); + } + else if (itProfile->second == "s" || itProfile->second == "seconds") + { + profiler.m_Timers.emplace_back("buffering", + Support::Resolutions::s); + } + else if (itProfile->second == "min" || itProfile->second == "minutes") + { + profiler.m_Timers.emplace_back("buffering", + Support::Resolutions::m); + } + else if (itProfile->second == "h" || itProfile->second == "hours") + { + profiler.m_Timers.emplace_back("buffering", + Support::Resolutions::h); + } + else + { + if (m_DebugMode == true) + { + throw std::invalid_argument( + "ERROR: Method profile_buffering_units " + "argument must be mus, ms, s, min or h, in " + "call to Open or Engine constructor\n"); + } + } - profiler.m_IsActive = true; - } + profiler.m_IsActive = true; + } } void BPFileWriter::InitTransports() { - if (m_DebugMode == true) - { - if (TransportNamesUniqueness() == false) - { - throw std::invalid_argument( - "ERROR: two transports of the same kind (e.g file IO) " - "can't have the same name, modify with name= in Method " - "AddTransport\n"); - } - } - - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itProfile = parameters.find("profile_units"); - bool doProfiling = false; - Support::Resolutions resolution = - Support::Resolutions::s; // default is seconds - if (itProfile != parameters.end()) + if (m_DebugMode == true) { - if (itProfile->second == "mus" || itProfile->second == "microseconds") - { - resolution = Support::Resolutions::mus; - } - else if (itProfile->second == "ms" || itProfile->second == "milliseconds") - { - resolution = Support::Resolutions::ms; - } - else if (itProfile->second == "s" || itProfile->second == "seconds") - { - resolution = Support::Resolutions::s; - } - else if (itProfile->second == "min" || itProfile->second == "minutes") - { - resolution = Support::Resolutions::m; - } - else if (itProfile->second == "h" || itProfile->second == "hours") - { - resolution = Support::Resolutions::h; - } - else - { - if (m_DebugMode == true) + if (TransportNamesUniqueness() == false) { - throw std::invalid_argument("ERROR: Transport profile_units argument " - "must be mus, ms, s, min or h " + - m_EndMessage); + throw std::invalid_argument( + "ERROR: two transports of the same kind (e.g file IO) " + "can't have the same name, modify with name= in Method " + "AddTransport\n"); } - } - doProfiling = true; } - auto itTransport = parameters.find("transport"); - - if (itTransport->second == "file" || itTransport->second == "File") + for (const auto ¶meters : m_Method.m_TransportParameters) { - auto itLibrary = parameters.find("library"); - if (itLibrary == parameters.end() || - itLibrary->second == "POSIX") // use default POSIX - { - auto file = - std::make_shared<transport::FileDescriptor>(m_MPIComm, m_DebugMode); - if (doProfiling == true) + auto itProfile = parameters.find("profile_units"); + bool doProfiling = false; + Support::Resolutions resolution = + Support::Resolutions::s; // default is seconds + if (itProfile != parameters.end()) { - file->InitProfiler(m_AccessMode, resolution); + if (itProfile->second == "mus" || + itProfile->second == "microseconds") + { + resolution = Support::Resolutions::mus; + } + else if (itProfile->second == "ms" || + itProfile->second == "milliseconds") + { + resolution = Support::Resolutions::ms; + } + else if (itProfile->second == "s" || itProfile->second == "seconds") + { + resolution = Support::Resolutions::s; + } + else if (itProfile->second == "min" || + itProfile->second == "minutes") + { + resolution = Support::Resolutions::m; + } + else if (itProfile->second == "h" || itProfile->second == "hours") + { + resolution = Support::Resolutions::h; + } + else + { + if (m_DebugMode == true) + { + throw std::invalid_argument( + "ERROR: Transport profile_units argument " + "must be mus, ms, s, min or h " + + m_EndMessage); + } + } + doProfiling = true; } - m_BP1Writer.OpenRankFiles(m_Name, m_AccessMode, *file); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "FILE*" || itLibrary->second == "stdio") - { - auto file = - std::make_shared<transport::FilePointer>(m_MPIComm, m_DebugMode); - if (doProfiling == true) - { - file->InitProfiler(m_AccessMode, resolution); - } + auto itTransport = parameters.find("transport"); - m_BP1Writer.OpenRankFiles(m_Name, m_AccessMode, *file); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "fstream" || - itLibrary->second == "std::fstream") - { - auto file = - std::make_shared<transport::FStream>(m_MPIComm, m_DebugMode); - - if (doProfiling == true) + if (itTransport->second == "file" || itTransport->second == "File") { - file->InitProfiler(m_AccessMode, resolution); + auto itLibrary = parameters.find("library"); + if (itLibrary == parameters.end() || + itLibrary->second == "POSIX") // use default POSIX + { + auto file = std::make_shared<transport::FileDescriptor>( + m_MPIComm, m_DebugMode); + if (doProfiling == true) + { + file->InitProfiler(m_AccessMode, resolution); + } + + m_BP1Writer.OpenRankFiles(m_Name, m_AccessMode, *file); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "FILE*" || + itLibrary->second == "stdio") + { + auto file = std::make_shared<transport::FilePointer>( + m_MPIComm, m_DebugMode); + if (doProfiling == true) + { + file->InitProfiler(m_AccessMode, resolution); + } + + m_BP1Writer.OpenRankFiles(m_Name, m_AccessMode, *file); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "fstream" || + itLibrary->second == "std::fstream") + { + auto file = std::make_shared<transport::FStream>(m_MPIComm, + m_DebugMode); + + if (doProfiling == true) + { + file->InitProfiler(m_AccessMode, resolution); + } + + m_BP1Writer.OpenRankFiles(m_Name, m_AccessMode, *file); + m_Transports.push_back(std::move(file)); + } + else if (itLibrary->second == "MPI_File" || + itLibrary->second == "MPI-IO") + { + } + else + { + if (m_DebugMode == true) + { + throw std::invalid_argument( + "ERROR: file transport library " + itLibrary->second + + " not supported, in " + m_Name + m_EndMessage); + } + } } - - m_BP1Writer.OpenRankFiles(m_Name, m_AccessMode, *file); - m_Transports.push_back(std::move(file)); - } - else if (itLibrary->second == "MPI_File" || itLibrary->second == "MPI-IO") - { - } - else - { - if (m_DebugMode == true) + else { - throw std::invalid_argument( - "ERROR: file transport library " + itLibrary->second + - " not supported, in " + m_Name + m_EndMessage); + if (m_DebugMode == true) + { + throw std::invalid_argument( + "ERROR: transport " + itTransport->second + + " (you mean File?) not supported, in " + m_Name + + m_EndMessage); + } } - } } - else - { - if (m_DebugMode == true) - { - throw std::invalid_argument("ERROR: transport " + itTransport->second + - " (you mean File?) not supported, in " + - m_Name + m_EndMessage); - } - } - } } void BPFileWriter::InitProcessGroup() { - if (m_MetadataSet.Log.m_IsActive == true) - { - m_MetadataSet.Log.m_Timers[0].SetInitialTime(); - } + if (m_MetadataSet.Log.m_IsActive == true) + { + m_MetadataSet.Log.m_Timers[0].SetInitialTime(); + } - if (m_AccessMode == "a") - { - // Get last pg timestep and update timestep counter in - // format::BP1MetadataSet - } + if (m_AccessMode == "a") + { + // Get last pg timestep and update timestep counter in + // format::BP1MetadataSet + } - WriteProcessGroupIndex(); + WriteProcessGroupIndex(); - if (m_MetadataSet.Log.m_IsActive == true) - { - m_MetadataSet.Log.m_Timers[0].SetTime(); - } + if (m_MetadataSet.Log.m_IsActive == true) + { + m_MetadataSet.Log.m_Timers[0].SetTime(); + } } void BPFileWriter::WriteProcessGroupIndex() { - // pg = process group - // const std::size_t pgIndexSize = m_BP1Writer.GetProcessGroupIndexSize( - // std::to_string( m_RankMPI ), - // std::to_string( - // m_MetadataSet.TimeStep - // ), - // m_Transports.size() - // ); - // metadata - // GrowBuffer( pgIndexSize, m_GrowthFactor, m_MetadataSet.PGIndex ); - - // data? Need to be careful, maybe add some trailing tolerance in variable - // ???? - // GrowBuffer( pgIndexSize, m_GrowthFactor, m_Buffer.m_Data ); - - const bool isFortran = (m_HostLanguage == "Fortran") ? true : false; - - m_BP1Writer.WriteProcessGroupIndex(isFortran, std::to_string(m_RankMPI), - static_cast<std::uint32_t>(m_RankMPI), - m_Transports, m_Buffer, m_MetadataSet); + // pg = process group + // const std::size_t pgIndexSize = m_BP1Writer.GetProcessGroupIndexSize( + // std::to_string( m_RankMPI ), + // std::to_string( + // m_MetadataSet.TimeStep + // ), + // m_Transports.size() + // ); + // metadata + // GrowBuffer( pgIndexSize, m_GrowthFactor, m_MetadataSet.PGIndex ); + + // data? Need to be careful, maybe add some trailing tolerance in variable + // ???? + // GrowBuffer( pgIndexSize, m_GrowthFactor, m_Buffer.m_Data ); + + const bool isFortran = (m_HostLanguage == "Fortran") ? true : false; + + m_BP1Writer.WriteProcessGroupIndex(isFortran, std::to_string(m_RankMPI), + static_cast<std::uint32_t>(m_RankMPI), + m_Transports, m_Buffer, m_MetadataSet); } } // end namespace adios diff --git a/source/engine/dataman/DataManReader.cpp b/source/engine/dataman/DataManReader.cpp index 941fe8f6065d6e112a26e29c72d2ef626e8b0492..9de0149532e6302aa7ceb7133260d044f7804c8f 100644 --- a/source/engine/dataman/DataManReader.cpp +++ b/source/engine/dataman/DataManReader.cpp @@ -33,7 +33,7 @@ DataManReader::DataManReader(ADIOS &adios, const std::string name, nthreads, " DataManReader constructor (or call to ADIOS Open).\n"), m_Buffer(accessMode, m_RankMPI, m_DebugMode) { - Init(); + Init(); } DataManReader::~DataManReader() {} @@ -43,118 +43,118 @@ void DataManReader::SetCallBack( Dims)> callback) { - m_CallBack = callback; - m_Man.reg_callback(callback); + m_CallBack = callback; + m_Man.reg_callback(callback); } Variable<void> * DataManReader::InquireVariable(const std::string name, const bool readIn) // not yet implemented { - return nullptr; + return nullptr; } Variable<char> *DataManReader::InquireVariableChar(const std::string name, const bool readIn) { - return InquireVariableCommon<char>(name, readIn); + return InquireVariableCommon<char>(name, readIn); } Variable<unsigned char> * DataManReader::InquireVariableUChar(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned char>(name, readIn); + return InquireVariableCommon<unsigned char>(name, readIn); } Variable<short> *DataManReader::InquireVariableShort(const std::string name, const bool readIn) { - return InquireVariableCommon<short>(name, readIn); + return InquireVariableCommon<short>(name, readIn); } Variable<unsigned short> * DataManReader::InquireVariableUShort(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned short>(name, readIn); + return InquireVariableCommon<unsigned short>(name, readIn); } Variable<int> *DataManReader::InquireVariableInt(const std::string name, const bool readIn) { - return InquireVariableCommon<int>(name, readIn); + return InquireVariableCommon<int>(name, readIn); } Variable<unsigned int> * DataManReader::InquireVariableUInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned int>(name, readIn); + return InquireVariableCommon<unsigned int>(name, readIn); } Variable<long int> *DataManReader::InquireVariableLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<long int>(name, readIn); + return InquireVariableCommon<long int>(name, readIn); } Variable<unsigned long int> * DataManReader::InquireVariableULInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned long int>(name, readIn); + return InquireVariableCommon<unsigned long int>(name, readIn); } Variable<long long int> * DataManReader::InquireVariableLLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<long long int>(name, readIn); + return InquireVariableCommon<long long int>(name, readIn); } Variable<unsigned long long int> * DataManReader::InquireVariableULLInt(const std::string name, const bool readIn) { - return InquireVariableCommon<unsigned long long int>(name, readIn); + return InquireVariableCommon<unsigned long long int>(name, readIn); } Variable<float> *DataManReader::InquireVariableFloat(const std::string name, const bool readIn) { - return InquireVariableCommon<float>(name, readIn); + return InquireVariableCommon<float>(name, readIn); } Variable<double> *DataManReader::InquireVariableDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<double>(name, readIn); + return InquireVariableCommon<double>(name, readIn); } Variable<long double> * DataManReader::InquireVariableLDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<long double>(name, readIn); + return InquireVariableCommon<long double>(name, readIn); } Variable<std::complex<float>> * DataManReader::InquireVariableCFloat(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<float>>(name, readIn); + return InquireVariableCommon<std::complex<float>>(name, readIn); } Variable<std::complex<double>> * DataManReader::InquireVariableCDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<double>>(name, readIn); + return InquireVariableCommon<std::complex<double>>(name, readIn); } Variable<std::complex<long double>> * DataManReader::InquireVariableCLDouble(const std::string name, const bool readIn) { - return InquireVariableCommon<std::complex<long double>>(name, readIn); + return InquireVariableCommon<std::complex<long double>>(name, readIn); } VariableCompound *DataManReader::InquireVariableCompound(const std::string name, const bool readIn) { - return nullptr; + return nullptr; } void DataManReader::Close(const int transportIndex) {} @@ -162,159 +162,163 @@ void DataManReader::Close(const int transportIndex) {} // PRIVATE void DataManReader::Init() { - if (m_DebugMode == true) - { - if (m_AccessMode != "r" && m_AccessMode != "read") - throw std::invalid_argument( - "ERROR: DataManReader doesn't support access mode " + m_AccessMode + - ", in call to ADIOS Open or DataManReader constructor\n"); - } - - auto itRealTime = m_Method.m_Parameters.find("real_time"); - if (itRealTime != m_Method.m_Parameters.end()) - { - if (itRealTime->second == "yes" || itRealTime->second == "true") - m_DoRealTime = true; - } - - if (m_DoRealTime) - { - /** - * Lambda function that assigns a parameter in m_Method to a localVariable - * of type std::string - */ - auto lf_AssignString = [this](const std::string parameter, - std::string &localVariable) { - auto it = m_Method.m_Parameters.find(parameter); - if (it != m_Method.m_Parameters.end()) - { - localVariable = it->second; - } - }; - - /** - * Lambda function that assigns a parameter in m_Method to a localVariable - * of type int - */ - auto lf_AssignInt = [this](const std::string parameter, - int &localVariable) { - auto it = m_Method.m_Parameters.find(parameter); - if (it != m_Method.m_Parameters.end()) - { - localVariable = std::stoi(it->second); - } - }; - - auto is_number = [](const std::string &s) { - return !s.empty() && std::find_if(s.begin(), s.end(), [](char c) { - return !std::isdigit(c); - }) == s.end(); - }; - - json jmsg; - for (auto &i : m_Method.m_Parameters) + if (m_DebugMode == true) + { + if (m_AccessMode != "r" && m_AccessMode != "read") + throw std::invalid_argument( + "ERROR: DataManReader doesn't support access mode " + + m_AccessMode + + ", in call to ADIOS Open or DataManReader constructor\n"); + } + + auto itRealTime = m_Method.m_Parameters.find("real_time"); + if (itRealTime != m_Method.m_Parameters.end()) { - if (is_number(i.second)) - { - jmsg[i.first] = std::stoi(i.second); - } - else - { - jmsg[i.first] = i.second; - } + if (itRealTime->second == "yes" || itRealTime->second == "true") + m_DoRealTime = true; + } + + if (m_DoRealTime) + { + /** + * Lambda function that assigns a parameter in m_Method to a + * localVariable + * of type std::string + */ + auto lf_AssignString = [this](const std::string parameter, + std::string &localVariable) { + auto it = m_Method.m_Parameters.find(parameter); + if (it != m_Method.m_Parameters.end()) + { + localVariable = it->second; + } + }; + + /** + * Lambda function that assigns a parameter in m_Method to a + * localVariable + * of type int + */ + auto lf_AssignInt = [this](const std::string parameter, + int &localVariable) { + auto it = m_Method.m_Parameters.find(parameter); + if (it != m_Method.m_Parameters.end()) + { + localVariable = std::stoi(it->second); + } + }; + + auto is_number = [](const std::string &s) { + return !s.empty() && std::find_if(s.begin(), s.end(), [](char c) { + return !std::isdigit(c); + }) == s.end(); + }; + + json jmsg; + for (auto &i : m_Method.m_Parameters) + { + if (is_number(i.second)) + { + jmsg[i.first] = std::stoi(i.second); + } + else + { + jmsg[i.first] = i.second; + } + } + jmsg["stream_mode"] = "receiver"; + m_Man.add_stream(jmsg); + + std::string method_type; + int num_channels = 0; + lf_AssignString("method_type", method_type); + lf_AssignInt("num_channels", num_channels); + } + else + { + InitCapsules(); + InitTransports(); } - jmsg["stream_mode"] = "receiver"; - m_Man.add_stream(jmsg); - - std::string method_type; - int num_channels = 0; - lf_AssignString("method_type", method_type); - lf_AssignInt("num_channels", num_channels); - } - else - { - InitCapsules(); - InitTransports(); - } } void DataManReader::InitCapsules() { - // here init memory capsules + // here init memory capsules } void DataManReader::InitTransports() // maybe move this? { - TransportNamesUniqueness(); + TransportNamesUniqueness(); - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itTransport = parameters.find("transport"); - - if (itTransport->second == "Mdtm" || itTransport->second == "MdtmMan") - { - const std::string localIP( - GetMdtmParameter("localIP", parameters)); // mandatory - const std::string remoteIP( - GetMdtmParameter("remoteIP", parameters)); // mandatory - const std::string prefix(GetMdtmParameter("prefix", parameters)); - const int numberOfPipes = - std::stoi(GetMdtmParameter("pipes", parameters)); - const std::vector<int> tolerances = - CSVToVectorInt(GetMdtmParameter("tolerances", parameters)); - const std::vector<int> priorities = - CSVToVectorInt(GetMdtmParameter("priorities", parameters)); - - m_Transports.push_back(std::make_shared<transport::MdtmMan>( - localIP, remoteIP, m_AccessMode, prefix, numberOfPipes, tolerances, - priorities, m_MPIComm, m_DebugMode)); - } - else if (itTransport->second == "Zmq") - { - } - else + for (const auto ¶meters : m_Method.m_TransportParameters) { - if (m_DebugMode == true) - throw std::invalid_argument( - "ERROR: transport + " + itTransport->second + - " not supported, in " + m_Name + m_EndMessage); + auto itTransport = parameters.find("transport"); + + if (itTransport->second == "Mdtm" || itTransport->second == "MdtmMan") + { + const std::string localIP( + GetMdtmParameter("localIP", parameters)); // mandatory + const std::string remoteIP( + GetMdtmParameter("remoteIP", parameters)); // mandatory + const std::string prefix(GetMdtmParameter("prefix", parameters)); + const int numberOfPipes = + std::stoi(GetMdtmParameter("pipes", parameters)); + const std::vector<int> tolerances = + CSVToVectorInt(GetMdtmParameter("tolerances", parameters)); + const std::vector<int> priorities = + CSVToVectorInt(GetMdtmParameter("priorities", parameters)); + + m_Transports.push_back(std::make_shared<transport::MdtmMan>( + localIP, remoteIP, m_AccessMode, prefix, numberOfPipes, + tolerances, priorities, m_MPIComm, m_DebugMode)); + } + else if (itTransport->second == "Zmq") + { + } + else + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: transport + " + itTransport->second + + " not supported, in " + m_Name + m_EndMessage); + } } - } } std::string DataManReader::GetMdtmParameter( const std::string parameter, const std::map<std::string, std::string> &mdtmParameters) { - auto itParam = mdtmParameters.find(parameter); - if (itParam != mdtmParameters.end()) // found - { - return itParam->second; // return value - } - // if not found - // mandatory ones - if (parameter == "localIP" || parameter == "remoteIP") - { - if (m_DebugMode == true) - throw std::invalid_argument("ERROR: " + parameter + - " parameter not found in Method, in call to " - "DataManWriter constructor\n"); - } - else if (parameter == "prefix") - { - return ""; - } - else if (parameter == "pipes") - { - return "0"; // or 1? - } - else if (parameter == "tolerances") // so far empty string - { - } - else if (parameter == "priority") - { - } - - return ""; // return empty string + auto itParam = mdtmParameters.find(parameter); + if (itParam != mdtmParameters.end()) // found + { + return itParam->second; // return value + } + // if not found + // mandatory ones + if (parameter == "localIP" || parameter == "remoteIP") + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: " + parameter + + " parameter not found in Method, in call to " + "DataManWriter constructor\n"); + } + else if (parameter == "prefix") + { + return ""; + } + else if (parameter == "pipes") + { + return "0"; // or 1? + } + else if (parameter == "tolerances") // so far empty string + { + } + else if (parameter == "priority") + { + } + + return ""; // return empty string } } diff --git a/source/engine/dataman/DataManWriter.cpp b/source/engine/dataman/DataManWriter.cpp index edb5275795a7bf872220c8c8ea49cd4954457a1a..2aa7aaac8bd393d59c6ec923e990ccdc77bccb7c 100644 --- a/source/engine/dataman/DataManWriter.cpp +++ b/source/engine/dataman/DataManWriter.cpp @@ -31,7 +31,7 @@ DataManWriter::DataManWriter(ADIOS &adios, const std::string name, nthreads, " DataManWriter constructor (or call to ADIOS Open).\n"), m_Buffer(accessMode, m_RankMPI, m_DebugMode) { - Init(); + Init(); } DataManWriter::~DataManWriter() {} @@ -41,370 +41,378 @@ void DataManWriter::SetCallBack( Dims)> callback) { - m_CallBack = callback; - m_Man.reg_callback(callback); + m_CallBack = callback; + m_Man.reg_callback(callback); } void DataManWriter::Write(Variable<char> &variable, const char *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<unsigned char> &variable, const unsigned char *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<short> &variable, const short *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<unsigned short> &variable, const unsigned short *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<int> &variable, const int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<unsigned int> &variable, const unsigned int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<long int> &variable, const long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<unsigned long int> &variable, const unsigned long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<long long int> &variable, const long long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<unsigned long long int> &variable, const unsigned long long int *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<float> &variable, const float *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<double> &variable, const double *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<long double> &variable, const long double *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<std::complex<float>> &variable, const std::complex<float> *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<std::complex<double>> &variable, const std::complex<double> *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } void DataManWriter::Write(Variable<std::complex<long double>> &variable, const std::complex<long double> *values) { - WriteVariableCommon(variable, values); + WriteVariableCommon(variable, values); } // String version void DataManWriter::Write(const std::string variableName, const char *values) { - WriteVariableCommon(m_ADIOS.GetVariable<char>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<char>(variableName), values); } void DataManWriter::Write(const std::string variableName, const unsigned char *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned char>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned char>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const short *values) { - WriteVariableCommon(m_ADIOS.GetVariable<short>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<short>(variableName), values); } void DataManWriter::Write(const std::string variableName, const unsigned short *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned short>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned short>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<int>(variableName), values); } void DataManWriter::Write(const std::string variableName, const unsigned int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned int>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<long int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<long int>(variableName), values); } void DataManWriter::Write(const std::string variableName, const unsigned long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned long int>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<unsigned long int>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const long long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<long long int>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<long long int>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const unsigned long long int *values) { - WriteVariableCommon(m_ADIOS.GetVariable<unsigned long long int>(variableName), - values); + WriteVariableCommon( + m_ADIOS.GetVariable<unsigned long long int>(variableName), values); } void DataManWriter::Write(const std::string variableName, const float *values) { - WriteVariableCommon(m_ADIOS.GetVariable<float>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<float>(variableName), values); } void DataManWriter::Write(const std::string variableName, const double *values) { - WriteVariableCommon(m_ADIOS.GetVariable<double>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<double>(variableName), values); } void DataManWriter::Write(const std::string variableName, const long double *values) { - WriteVariableCommon(m_ADIOS.GetVariable<long double>(variableName), values); + WriteVariableCommon(m_ADIOS.GetVariable<long double>(variableName), values); } void DataManWriter::Write(const std::string variableName, const std::complex<float> *values) { - WriteVariableCommon(m_ADIOS.GetVariable<std::complex<float>>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<std::complex<float>>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const std::complex<double> *values) { - WriteVariableCommon(m_ADIOS.GetVariable<std::complex<double>>(variableName), - values); + WriteVariableCommon(m_ADIOS.GetVariable<std::complex<double>>(variableName), + values); } void DataManWriter::Write(const std::string variableName, const std::complex<long double> *values) { - WriteVariableCommon( - m_ADIOS.GetVariable<std::complex<long double>>(variableName), values); + WriteVariableCommon( + m_ADIOS.GetVariable<std::complex<long double>>(variableName), values); } void DataManWriter::Close(const int transportIndex) { - m_Man.flush(); - // here close IPs and deallocate or free/close resources (if using STL no need - // for memory deallocation) + m_Man.flush(); + // here close IPs and deallocate or free/close resources (if using STL no + // need + // for memory deallocation) } // PRIVATE functions below void DataManWriter::Init() { - if (m_DebugMode == true) - { - if (m_AccessMode != "w" && m_AccessMode != "write" && m_AccessMode != "a" && - m_AccessMode != "append") - throw std::invalid_argument( - "ERROR: DataManWriter doesn't support access mode " + m_AccessMode + - ", in call to ADIOS Open or DataManWriter constructor\n"); - } - - auto itRealTime = m_Method.m_Parameters.find("real_time"); - if (itRealTime != m_Method.m_Parameters.end()) - { - if (itRealTime->second == "yes" || itRealTime->second == "true") - m_DoRealTime = true; - } - - itRealTime = m_Method.m_Parameters.find("monitoring"); - if (itRealTime != m_Method.m_Parameters.end()) - { - if (itRealTime->second == "yes" || itRealTime->second == "true") - m_DoMonitor = true; - } - - if (m_DoRealTime) - { - /** - * Lambda function that assigns a parameter in m_Method to a localVariable - * of type std::string - */ - auto lf_AssignString = [this](const std::string parameter, - std::string &localVariable) { - auto it = m_Method.m_Parameters.find(parameter); - if (it != m_Method.m_Parameters.end()) - { - localVariable = it->second; - } - }; - - /** - * Lambda function that assigns a parameter in m_Method to a localVariable - * of type int - */ - auto lf_AssignInt = [this](const std::string parameter, - int &localVariable) { - auto it = m_Method.m_Parameters.find(parameter); - if (it != m_Method.m_Parameters.end()) - { - localVariable = std::stoi(it->second); - } - }; - - auto is_number = [](const std::string &s) { - return !s.empty() && std::find_if(s.begin(), s.end(), [](char c) { - return !std::isdigit(c); - }) == s.end(); - }; - - json jmsg; - for (auto &i : m_Method.m_Parameters) + if (m_DebugMode == true) + { + if (m_AccessMode != "w" && m_AccessMode != "write" && + m_AccessMode != "a" && m_AccessMode != "append") + throw std::invalid_argument( + "ERROR: DataManWriter doesn't support access mode " + + m_AccessMode + + ", in call to ADIOS Open or DataManWriter constructor\n"); + } + + auto itRealTime = m_Method.m_Parameters.find("real_time"); + if (itRealTime != m_Method.m_Parameters.end()) { - if (is_number(i.second)) - { - jmsg[i.first] = std::stoi(i.second); - } - else - { - jmsg[i.first] = i.second; - } + if (itRealTime->second == "yes" || itRealTime->second == "true") + m_DoRealTime = true; } - jmsg["stream_mode"] = "sender"; - m_Man.add_stream(jmsg); - std::string method_type; - int num_channels = 0; - lf_AssignString("method_type", method_type); - lf_AssignInt("num_channels", num_channels); - } - else - { - InitCapsules(); - InitTransports(); - } + itRealTime = m_Method.m_Parameters.find("monitoring"); + if (itRealTime != m_Method.m_Parameters.end()) + { + if (itRealTime->second == "yes" || itRealTime->second == "true") + m_DoMonitor = true; + } + + if (m_DoRealTime) + { + /** + * Lambda function that assigns a parameter in m_Method to a + * localVariable + * of type std::string + */ + auto lf_AssignString = [this](const std::string parameter, + std::string &localVariable) { + auto it = m_Method.m_Parameters.find(parameter); + if (it != m_Method.m_Parameters.end()) + { + localVariable = it->second; + } + }; + + /** + * Lambda function that assigns a parameter in m_Method to a + * localVariable + * of type int + */ + auto lf_AssignInt = [this](const std::string parameter, + int &localVariable) { + auto it = m_Method.m_Parameters.find(parameter); + if (it != m_Method.m_Parameters.end()) + { + localVariable = std::stoi(it->second); + } + }; + + auto is_number = [](const std::string &s) { + return !s.empty() && std::find_if(s.begin(), s.end(), [](char c) { + return !std::isdigit(c); + }) == s.end(); + }; + + json jmsg; + for (auto &i : m_Method.m_Parameters) + { + if (is_number(i.second)) + { + jmsg[i.first] = std::stoi(i.second); + } + else + { + jmsg[i.first] = i.second; + } + } + jmsg["stream_mode"] = "sender"; + m_Man.add_stream(jmsg); + + std::string method_type; + int num_channels = 0; + lf_AssignString("method_type", method_type); + lf_AssignInt("num_channels", num_channels); + } + else + { + InitCapsules(); + InitTransports(); + } } void DataManWriter::InitCapsules() { - // here init memory capsules + // here init memory capsules } void DataManWriter::InitTransports() // maybe move this? { - TransportNamesUniqueness(); + TransportNamesUniqueness(); - for (const auto ¶meters : m_Method.m_TransportParameters) - { - auto itTransport = parameters.find("transport"); - - if (itTransport->second == "Mdtm" || itTransport->second == "MdtmMan") - { - const std::string localIP( - GetMdtmParameter("localIP", parameters)); // mandatory - const std::string remoteIP( - GetMdtmParameter("remoteIP", parameters)); // mandatory - const std::string prefix(GetMdtmParameter("prefix", parameters)); - const int numberOfPipes = - std::stoi(GetMdtmParameter("pipes", parameters)); - const std::vector<int> tolerances = - CSVToVectorInt(GetMdtmParameter("tolerances", parameters)); - const std::vector<int> priorities = - CSVToVectorInt(GetMdtmParameter("priorities", parameters)); - - m_Transports.push_back(std::make_shared<transport::MdtmMan>( - localIP, remoteIP, m_AccessMode, prefix, numberOfPipes, tolerances, - priorities, m_MPIComm, m_DebugMode)); - } - else if (itTransport->second == "Zmq") - { - } - else + for (const auto ¶meters : m_Method.m_TransportParameters) { - if (m_DebugMode == true) - throw std::invalid_argument( - "ERROR: transport + " + itTransport->second + - " not supported, in " + m_Name + m_EndMessage); + auto itTransport = parameters.find("transport"); + + if (itTransport->second == "Mdtm" || itTransport->second == "MdtmMan") + { + const std::string localIP( + GetMdtmParameter("localIP", parameters)); // mandatory + const std::string remoteIP( + GetMdtmParameter("remoteIP", parameters)); // mandatory + const std::string prefix(GetMdtmParameter("prefix", parameters)); + const int numberOfPipes = + std::stoi(GetMdtmParameter("pipes", parameters)); + const std::vector<int> tolerances = + CSVToVectorInt(GetMdtmParameter("tolerances", parameters)); + const std::vector<int> priorities = + CSVToVectorInt(GetMdtmParameter("priorities", parameters)); + + m_Transports.push_back(std::make_shared<transport::MdtmMan>( + localIP, remoteIP, m_AccessMode, prefix, numberOfPipes, + tolerances, priorities, m_MPIComm, m_DebugMode)); + } + else if (itTransport->second == "Zmq") + { + } + else + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: transport + " + itTransport->second + + " not supported, in " + m_Name + m_EndMessage); + } } - } } std::string DataManWriter::GetMdtmParameter( const std::string parameter, const std::map<std::string, std::string> &mdtmParameters) { - auto itParam = mdtmParameters.find(parameter); - if (itParam != mdtmParameters.end()) // found - { - return itParam->second; // return value - } - // if not found - // mandatory ones - if (parameter == "localIP" || parameter == "remoteIP") - { - if (m_DebugMode == true) - throw std::invalid_argument("ERROR: " + parameter + - " parameter not found in Method, in call to " - "DataManWriter constructor\n"); - } - else if (parameter == "prefix") - { - return ""; - } - else if (parameter == "pipes") - { - return "0"; // or 1? - } - else if (parameter == "tolerances") // so far empty string - { - } - else if (parameter == "priority") - { - } - - return ""; // return empty string + auto itParam = mdtmParameters.find(parameter); + if (itParam != mdtmParameters.end()) // found + { + return itParam->second; // return value + } + // if not found + // mandatory ones + if (parameter == "localIP" || parameter == "remoteIP") + { + if (m_DebugMode == true) + throw std::invalid_argument( + "ERROR: " + parameter + + " parameter not found in Method, in call to " + "DataManWriter constructor\n"); + } + else if (parameter == "prefix") + { + return ""; + } + else if (parameter == "pipes") + { + return "0"; // or 1? + } + else if (parameter == "tolerances") // so far empty string + { + } + else if (parameter == "priority") + { + } + + return ""; // return empty string } } // end namespace adios diff --git a/source/format/BP1.cpp b/source/format/BP1.cpp index e9ec112c5753ab5e7905a016cf17815ad7daa1bc..ef69751b1918312def11a2b3005594abf9afd829 100644 --- a/source/format/BP1.cpp +++ b/source/format/BP1.cpp @@ -18,71 +18,71 @@ namespace format std::string BP1::GetDirectoryName(const std::string name) const noexcept { - std::string directory; + std::string directory; - if (name.find(".bp") == name.size() - 3) - { - directory = name; - } - else - { - directory = name + ".bp"; - } - return directory; + if (name.find(".bp") == name.size() - 3) + { + directory = name; + } + else + { + directory = name + ".bp"; + } + return directory; } void BP1::OpenRankFiles(const std::string name, const std::string accessMode, Transport &file) const { - const std::string directory = GetDirectoryName(name); - CreateDirectory( - directory); // creates a directory and sub-directories recursively + const std::string directory = GetDirectoryName(name); + CreateDirectory( + directory); // creates a directory and sub-directories recursively - std::string fileName(directory + "/" + directory + "." + - std::to_string(file.m_RankMPI)); - file.Open(fileName, accessMode); // opens a file transport under - // name.bp.dir/name.bp.rank reserve that - // location fro writing + std::string fileName(directory + "/" + directory + "." + + std::to_string(file.m_RankMPI)); + file.Open(fileName, accessMode); // opens a file transport under + // name.bp.dir/name.bp.rank reserve that + // location fro writing } std::vector<std::uint8_t> BP1::GetMethodIDs( const std::vector<std::shared_ptr<Transport>> &transports) const noexcept { - auto lf_GetMethodID = [](const std::string method) -> std::uint8_t { - int id = METHOD_UNKNOWN; - if (method == "NULL") - { - id = METHOD_NULL; - } - else if (method == "POSIX") - { - id = METHOD_POSIX; - } - else if (method == "FStream") - { - id = METHOD_FSTREAM; - } - else if (method == "File") - { - id = METHOD_FILE; - } - else if (method == "MPI") - { - id = METHOD_MPI; - } + auto lf_GetMethodID = [](const std::string method) -> std::uint8_t { + int id = METHOD_UNKNOWN; + if (method == "NULL") + { + id = METHOD_NULL; + } + else if (method == "POSIX") + { + id = METHOD_POSIX; + } + else if (method == "FStream") + { + id = METHOD_FSTREAM; + } + else if (method == "File") + { + id = METHOD_FILE; + } + else if (method == "MPI") + { + id = METHOD_MPI; + } - return id; - }; + return id; + }; - std::vector<std::uint8_t> methodIDs; - methodIDs.reserve(transports.size()); + std::vector<std::uint8_t> methodIDs; + methodIDs.reserve(transports.size()); - for (const auto &transport : transports) - { - methodIDs.push_back(lf_GetMethodID(transport->m_Type)); - } + for (const auto &transport : transports) + { + methodIDs.push_back(lf_GetMethodID(transport->m_Type)); + } - return methodIDs; + return methodIDs; } } // end namespace format diff --git a/source/format/BP1Aggregator.cpp b/source/format/BP1Aggregator.cpp index f0de393a3ef307ed0b1c4959301ca0b3d0b18677..7b095cb112fa0bb3c54c788e4b731db1f75ba2a7 100644 --- a/source/format/BP1Aggregator.cpp +++ b/source/format/BP1Aggregator.cpp @@ -24,8 +24,8 @@ namespace format BP1Aggregator::BP1Aggregator(MPI_Comm mpiComm, const bool debugMode) : m_MPIComm{mpiComm}, m_DebugMode{debugMode} { - MPI_Comm_rank(m_MPIComm, &m_RankMPI); - MPI_Comm_size(m_MPIComm, &m_SizeMPI); + MPI_Comm_rank(m_MPIComm, &m_RankMPI); + MPI_Comm_size(m_MPIComm, &m_SizeMPI); } BP1Aggregator::~BP1Aggregator() = default; @@ -33,74 +33,75 @@ BP1Aggregator::~BP1Aggregator() = default; void BP1Aggregator::WriteProfilingLog(const std::string fileName, const std::string &rankLog) { - if (m_RankMPI == 0) - { - unsigned int sizeMPI = static_cast<unsigned int>(m_SizeMPI); - std::vector<std::vector<char>> rankLogs(sizeMPI - - 1); // rankLogs from other processes - std::vector<int> rankLogsSizes(sizeMPI - 1, -1); // init with -1 - std::vector<MPI_Request> requests(sizeMPI); - std::vector<MPI_Status> statuses(sizeMPI); - - // first receive sizes - for (unsigned int i = 1; i < sizeMPI; ++i) + if (m_RankMPI == 0) { - MPI_Irecv(&rankLogsSizes[i - 1], 1, MPI_INT, i, 0, m_MPIComm, - &requests[i]); - } + unsigned int sizeMPI = static_cast<unsigned int>(m_SizeMPI); + std::vector<std::vector<char>> rankLogs( + sizeMPI - 1); // rankLogs from other processes + std::vector<int> rankLogsSizes(sizeMPI - 1, -1); // init with -1 + std::vector<MPI_Request> requests(sizeMPI); + std::vector<MPI_Status> statuses(sizeMPI); - for (unsigned int i = 1; i < sizeMPI; ++i) - { - MPI_Wait(&requests[i], &statuses[i]); - if (m_DebugMode == true) - { - if (rankLogsSizes[i - 1] == -1) + // first receive sizes + for (unsigned int i = 1; i < sizeMPI; ++i) { - throw std::runtime_error("ERROR: couldn't get size from rank " + - std::to_string(i) + - ", in ADIOS aggregator for Profiling.log\n"); + MPI_Irecv(&rankLogsSizes[i - 1], 1, MPI_INT, i, 0, m_MPIComm, + &requests[i]); } - } - rankLogs[i - 1].resize(rankLogsSizes[i - 1]); // allocate with zeros - } - // receive rankLog from other ranks - for (unsigned int i = 1; i < sizeMPI; ++i) - { - MPI_Irecv(rankLogs[i - 1].data(), rankLogsSizes[i - 1], MPI_CHAR, i, 1, - m_MPIComm, &requests[i]); - } + for (unsigned int i = 1; i < sizeMPI; ++i) + { + MPI_Wait(&requests[i], &statuses[i]); + if (m_DebugMode == true) + { + if (rankLogsSizes[i - 1] == -1) + { + throw std::runtime_error( + "ERROR: couldn't get size from rank " + + std::to_string(i) + + ", in ADIOS aggregator for Profiling.log\n"); + } + } + rankLogs[i - 1].resize(rankLogsSizes[i - 1]); // allocate with zeros + } - for (unsigned int i = 1; i < sizeMPI; ++i) - { - MPI_Wait(&requests[i], &statuses[i]); - } + // receive rankLog from other ranks + for (unsigned int i = 1; i < sizeMPI; ++i) + { + MPI_Irecv(rankLogs[i - 1].data(), rankLogsSizes[i - 1], MPI_CHAR, i, + 1, m_MPIComm, &requests[i]); + } - // write file - std::string logFile("log = { \n"); - logFile += rankLog + "\n"; - for (unsigned int i = 1; i < sizeMPI; ++i) - { - const std::string rankLogStr(rankLogs[i - 1].data(), - rankLogs[i - 1].size()); - logFile += rankLogStr + "\n"; - } - logFile += " }\n"; + for (unsigned int i = 1; i < sizeMPI; ++i) + { + MPI_Wait(&requests[i], &statuses[i]); + } - std::ofstream logStream(fileName); - logStream.write(logFile.c_str(), logFile.size()); - logStream.close(); - } - else - { - int rankLogSize = static_cast<int>(rankLog.size()); - MPI_Request requestSize; - MPI_Isend(&rankLogSize, 1, MPI_INT, 0, 0, m_MPIComm, &requestSize); + // write file + std::string logFile("log = { \n"); + logFile += rankLog + "\n"; + for (unsigned int i = 1; i < sizeMPI; ++i) + { + const std::string rankLogStr(rankLogs[i - 1].data(), + rankLogs[i - 1].size()); + logFile += rankLogStr + "\n"; + } + logFile += " }\n"; - MPI_Request requestRankLog; - MPI_Isend(rankLog.data(), rankLogSize, MPI_CHAR, 0, 1, m_MPIComm, - &requestRankLog); - } + std::ofstream logStream(fileName); + logStream.write(logFile.c_str(), logFile.size()); + logStream.close(); + } + else + { + int rankLogSize = static_cast<int>(rankLog.size()); + MPI_Request requestSize; + MPI_Isend(&rankLogSize, 1, MPI_INT, 0, 0, m_MPIComm, &requestSize); + + MPI_Request requestRankLog; + MPI_Isend(rankLog.data(), rankLogSize, MPI_CHAR, 0, 1, m_MPIComm, + &requestRankLog); + } } } // end namespace format diff --git a/source/format/BP1Writer.cpp b/source/format/BP1Writer.cpp index 97b717eebf8846f119326761578b14fb988ce6c9..caafd8e86d7c3e111c7caf98daf7ae9d35ca9377 100644 --- a/source/format/BP1Writer.cpp +++ b/source/format/BP1Writer.cpp @@ -25,10 +25,11 @@ std::size_t BP1Writer::GetProcessGroupIndexSize( const std::string name, const std::string timeStepName, const std::size_t numberOfTransports) const noexcept { - // pgIndex + list of methods (transports) - return (name.length() + timeStepName.length() + 23) + - (3 + numberOfTransports); // should be sufficient for data and metadata - // pgindices + // pgIndex + list of methods (transports) + return (name.length() + timeStepName.length() + 23) + + (3 + + numberOfTransports); // should be sufficient for data and metadata + // pgindices } void BP1Writer::WriteProcessGroupIndex( @@ -36,162 +37,163 @@ void BP1Writer::WriteProcessGroupIndex( const std::vector<std::shared_ptr<Transport>> &transports, capsule::STLVector &heap, BP1MetadataSet &metadataSet) const noexcept { - std::vector<char> &metadataBuffer = metadataSet.PGIndex.Buffer; - std::vector<char> &dataBuffer = heap.m_Data; - - metadataSet.DataPGLengthPosition = dataBuffer.size(); - dataBuffer.insert(dataBuffer.end(), 8, 0); // skip pg length (8) - - const std::size_t metadataPGLengthPosition = metadataBuffer.size(); - metadataBuffer.insert(metadataBuffer.end(), 2, 0); // skip pg length (2) - - // write name to metadata - WriteNameRecord(name, metadataBuffer); - // write if host language Fortran in metadata and data - const char hostFortran = - (isFortran) ? 'y' : 'n'; // if host language is fortran - CopyToBuffer(metadataBuffer, &hostFortran); - CopyToBuffer(dataBuffer, &hostFortran); - // write name in data - WriteNameRecord(name, dataBuffer); - - // processID in metadata, - CopyToBuffer(metadataBuffer, &processID); - // skip coordination var in data ....what is coordination var? - dataBuffer.insert(dataBuffer.end(), 4, 0); - - // time step name to metadata and data - const std::string timeStepName(std::to_string(metadataSet.TimeStep)); - WriteNameRecord(timeStepName, metadataBuffer); - WriteNameRecord(timeStepName, dataBuffer); - - // time step to metadata and data - CopyToBuffer(metadataBuffer, &metadataSet.TimeStep); - CopyToBuffer(dataBuffer, &metadataSet.TimeStep); - - // offset to pg in data in metadata which is the current absolute position - CopyToBuffer(metadataBuffer, - static_cast<uint64_t *>(&heap.m_DataAbsolutePosition)); - - // Back to writing metadata pg index length (length of group) - const std::uint16_t metadataPGIndexLength = - metadataBuffer.size() - metadataPGLengthPosition - - 2; // without length of group record - CopyToBuffer(metadataBuffer, metadataPGLengthPosition, - &metadataPGIndexLength); - // DONE With metadataBuffer - - // here write method in data - const std::vector<std::uint8_t> methodIDs = GetMethodIDs(transports); - const std::uint8_t methodsCount = methodIDs.size(); - CopyToBuffer(dataBuffer, &methodsCount); // count - const std::uint16_t methodsLength = - methodIDs.size() * - 3; // methodID (1) + method params length(2), no parameters for now - CopyToBuffer(dataBuffer, &methodsLength); // length - - for (const auto methodID : methodIDs) - { - CopyToBuffer(dataBuffer, &methodID); // method ID, - dataBuffer.insert(dataBuffer.end(), 2, - 0); // skip method params length = 0 (2 bytes) for now - } - - // update absolute position - heap.m_DataAbsolutePosition += - dataBuffer.size() - metadataSet.DataPGLengthPosition; - // pg vars count and position - metadataSet.DataPGVarsCount = 0; - metadataSet.DataPGVarsCountPosition = dataBuffer.size(); - // add vars count and length - dataBuffer.insert(dataBuffer.end(), 12, 0); - heap.m_DataAbsolutePosition += 12; // add vars count and length - - ++metadataSet.DataPGCount; - metadataSet.DataPGIsOpen = true; + std::vector<char> &metadataBuffer = metadataSet.PGIndex.Buffer; + std::vector<char> &dataBuffer = heap.m_Data; + + metadataSet.DataPGLengthPosition = dataBuffer.size(); + dataBuffer.insert(dataBuffer.end(), 8, 0); // skip pg length (8) + + const std::size_t metadataPGLengthPosition = metadataBuffer.size(); + metadataBuffer.insert(metadataBuffer.end(), 2, 0); // skip pg length (2) + + // write name to metadata + WriteNameRecord(name, metadataBuffer); + // write if host language Fortran in metadata and data + const char hostFortran = + (isFortran) ? 'y' : 'n'; // if host language is fortran + CopyToBuffer(metadataBuffer, &hostFortran); + CopyToBuffer(dataBuffer, &hostFortran); + // write name in data + WriteNameRecord(name, dataBuffer); + + // processID in metadata, + CopyToBuffer(metadataBuffer, &processID); + // skip coordination var in data ....what is coordination var? + dataBuffer.insert(dataBuffer.end(), 4, 0); + + // time step name to metadata and data + const std::string timeStepName(std::to_string(metadataSet.TimeStep)); + WriteNameRecord(timeStepName, metadataBuffer); + WriteNameRecord(timeStepName, dataBuffer); + + // time step to metadata and data + CopyToBuffer(metadataBuffer, &metadataSet.TimeStep); + CopyToBuffer(dataBuffer, &metadataSet.TimeStep); + + // offset to pg in data in metadata which is the current absolute position + CopyToBuffer(metadataBuffer, + static_cast<uint64_t *>(&heap.m_DataAbsolutePosition)); + + // Back to writing metadata pg index length (length of group) + const std::uint16_t metadataPGIndexLength = + metadataBuffer.size() - metadataPGLengthPosition - + 2; // without length of group record + CopyToBuffer(metadataBuffer, metadataPGLengthPosition, + &metadataPGIndexLength); + // DONE With metadataBuffer + + // here write method in data + const std::vector<std::uint8_t> methodIDs = GetMethodIDs(transports); + const std::uint8_t methodsCount = methodIDs.size(); + CopyToBuffer(dataBuffer, &methodsCount); // count + const std::uint16_t methodsLength = + methodIDs.size() * + 3; // methodID (1) + method params length(2), no parameters for now + CopyToBuffer(dataBuffer, &methodsLength); // length + + for (const auto methodID : methodIDs) + { + CopyToBuffer(dataBuffer, &methodID); // method ID, + dataBuffer.insert(dataBuffer.end(), 2, + 0); // skip method params length = 0 (2 bytes) for now + } + + // update absolute position + heap.m_DataAbsolutePosition += + dataBuffer.size() - metadataSet.DataPGLengthPosition; + // pg vars count and position + metadataSet.DataPGVarsCount = 0; + metadataSet.DataPGVarsCountPosition = dataBuffer.size(); + // add vars count and length + dataBuffer.insert(dataBuffer.end(), 12, 0); + heap.m_DataAbsolutePosition += 12; // add vars count and length + + ++metadataSet.DataPGCount; + metadataSet.DataPGIsOpen = true; } void BP1Writer::Advance(BP1MetadataSet &metadataSet, capsule::STLVector &buffer) { - FlattenData(metadataSet, buffer); + FlattenData(metadataSet, buffer); } void BP1Writer::Close(BP1MetadataSet &metadataSet, capsule::STLVector &heap, Transport &transport, bool &isFirstClose, const bool doAggregation) const noexcept { - if (metadataSet.Log.m_IsActive == true) - { - metadataSet.Log.m_Timers[0].SetInitialTime(); - } - - if (isFirstClose == true) - { - if (metadataSet.DataPGIsOpen == true) + if (metadataSet.Log.m_IsActive == true) { - FlattenData(metadataSet, heap); + metadataSet.Log.m_Timers[0].SetInitialTime(); } - FlattenMetadata(metadataSet, heap); - - if (metadataSet.Log.m_IsActive == true) + if (isFirstClose == true) { - metadataSet.Log.m_Timers[0].SetInitialTime(); + if (metadataSet.DataPGIsOpen == true) + { + FlattenData(metadataSet, heap); + } + + FlattenMetadata(metadataSet, heap); + + if (metadataSet.Log.m_IsActive == true) + { + metadataSet.Log.m_Timers[0].SetInitialTime(); + } + + if (doAggregation == + true) // N-to-M where 1 <= M <= N-1, might need a new + // Log metadataSet.Log.m_Timers just for + // aggregation + { + // here call aggregator + } + isFirstClose = false; } - if (doAggregation == true) // N-to-M where 1 <= M <= N-1, might need a new - // Log metadataSet.Log.m_Timers just for - // aggregation + if (doAggregation == true) // N-to-M where 1 <= M <= N-1 + { + // here call aggregator to select transports for Write and Close + } + else // N-to-N { - // here call aggregator + transport.Write(heap.m_Data.data(), heap.m_Data.size()); // single write + transport.Close(); } - isFirstClose = false; - } - - if (doAggregation == true) // N-to-M where 1 <= M <= N-1 - { - // here call aggregator to select transports for Write and Close - } - else // N-to-N - { - transport.Write(heap.m_Data.data(), heap.m_Data.size()); // single write - transport.Close(); - } } std::string BP1Writer::GetRankProfilingLog( const int rank, const BP1MetadataSet &metadataSet, const std::vector<std::shared_ptr<Transport>> &transports) const noexcept { - auto lf_WriterTimer = [](std::string &rankLog, const Timer &timer) { - rankLog += "'" + timer.Process + "_" + timer.GetUnits() + "': " + - std::to_string(timer.ProcessTime) + ", "; - }; + auto lf_WriterTimer = [](std::string &rankLog, const Timer &timer) { + rankLog += "'" + timer.Process + "_" + timer.GetUnits() + "': " + + std::to_string(timer.ProcessTime) + ", "; + }; - // prepare string dictionary per rank - std::string rankLog("'rank_" + std::to_string(rank) + "': { "); + // prepare string dictionary per rank + std::string rankLog("'rank_" + std::to_string(rank) + "': { "); - auto &profiler = metadataSet.Log; - rankLog += "'bytes': " + std::to_string(profiler.m_TotalBytes[0]) + ", "; - lf_WriterTimer(rankLog, profiler.m_Timers[0]); + auto &profiler = metadataSet.Log; + rankLog += "'bytes': " + std::to_string(profiler.m_TotalBytes[0]) + ", "; + lf_WriterTimer(rankLog, profiler.m_Timers[0]); - for (unsigned int t = 0; t < transports.size(); ++t) - { - auto &timers = transports[t]->m_Profiler.m_Timers; + for (unsigned int t = 0; t < transports.size(); ++t) + { + auto &timers = transports[t]->m_Profiler.m_Timers; - rankLog += "'transport_" + std::to_string(t) + "': { "; - rankLog += "'lib': " + transports[t]->m_Type + ", "; + rankLog += "'transport_" + std::to_string(t) + "': { "; + rankLog += "'lib': " + transports[t]->m_Type + ", "; - for (unsigned int i = 0; i < 3; ++i) - { - lf_WriterTimer(rankLog, timers[i]); - } + for (unsigned int i = 0; i < 3; ++i) + { + lf_WriterTimer(rankLog, timers[i]); + } + rankLog += "}, "; + } rankLog += "}, "; - } - rankLog += "}, "; - return rankLog; + return rankLog; } // PRIVATE FUNCTIONS @@ -201,66 +203,70 @@ void BP1Writer::WriteDimensionsRecord( const std::vector<std::size_t> &globalOffsets, const unsigned int skip, const bool addType) const noexcept { - auto lf_WriteFlaggedDim = [](std::vector<char> &buffer, const char no, - const std::size_t dimension) { - CopyToBuffer(buffer, &no); - CopyToBuffer(buffer, static_cast<const uint64_t *>(&dimension)); - }; - - // BODY Starts here - if (globalDimensions.empty()) - { - if (addType == true) - { - constexpr char no = 'n'; // dimension format unsigned int value (not using - // memberID for now) - for (const auto &localDimension : localDimensions) - { - lf_WriteFlaggedDim(buffer, no, localDimension); - buffer.insert(buffer.end(), skip, 0); - } - } - else + auto lf_WriteFlaggedDim = [](std::vector<char> &buffer, const char no, + const std::size_t dimension) { + CopyToBuffer(buffer, &no); + CopyToBuffer(buffer, static_cast<const uint64_t *>(&dimension)); + }; + + // BODY Starts here + if (globalDimensions.empty()) { - for (const auto &localDimension : localDimensions) - { - CopyToBuffer(buffer, static_cast<const uint64_t *>(&localDimension)); - buffer.insert(buffer.end(), skip, 0); - } - } - } - else - { - if (addType == true) - { - constexpr char no = 'n'; // dimension format unsigned int value for now - for (unsigned int d = 0; d < localDimensions.size(); ++d) - { - lf_WriteFlaggedDim(buffer, no, localDimensions[d]); - lf_WriteFlaggedDim(buffer, no, globalDimensions[d]); - lf_WriteFlaggedDim(buffer, no, globalOffsets[d]); - } + if (addType == true) + { + constexpr char no = + 'n'; // dimension format unsigned int value (not using + // memberID for now) + for (const auto &localDimension : localDimensions) + { + lf_WriteFlaggedDim(buffer, no, localDimension); + buffer.insert(buffer.end(), skip, 0); + } + } + else + { + for (const auto &localDimension : localDimensions) + { + CopyToBuffer(buffer, + static_cast<const uint64_t *>(&localDimension)); + buffer.insert(buffer.end(), skip, 0); + } + } } else { - for (unsigned int d = 0; d < localDimensions.size(); ++d) - { - CopyToBuffer(buffer, - static_cast<const uint64_t *>(&localDimensions[d])); - CopyToBuffer(buffer, - static_cast<const uint64_t *>(&globalDimensions[d])); - CopyToBuffer(buffer, static_cast<const uint64_t *>(&globalOffsets[d])); - } + if (addType == true) + { + constexpr char no = + 'n'; // dimension format unsigned int value for now + for (unsigned int d = 0; d < localDimensions.size(); ++d) + { + lf_WriteFlaggedDim(buffer, no, localDimensions[d]); + lf_WriteFlaggedDim(buffer, no, globalDimensions[d]); + lf_WriteFlaggedDim(buffer, no, globalOffsets[d]); + } + } + else + { + for (unsigned int d = 0; d < localDimensions.size(); ++d) + { + CopyToBuffer( + buffer, static_cast<const uint64_t *>(&localDimensions[d])); + CopyToBuffer(buffer, static_cast<const uint64_t *>( + &globalDimensions[d])); + CopyToBuffer(buffer, + static_cast<const uint64_t *>(&globalOffsets[d])); + } + } } - } } void BP1Writer::WriteNameRecord(const std::string name, std::vector<char> &buffer) const noexcept { - const std::uint16_t length = name.length(); - CopyToBuffer(buffer, &length); - CopyToBuffer(buffer, name.c_str(), length); + const std::uint16_t length = name.length(); + CopyToBuffer(buffer, &length); + CopyToBuffer(buffer, name.c_str(), length); } BP1Index & @@ -268,138 +274,138 @@ BP1Writer::GetBP1Index(const std::string name, std::unordered_map<std::string, BP1Index> &indices, bool &isNew) const noexcept { - auto itName = indices.find(name); - if (itName == indices.end()) - { - indices.emplace(name, BP1Index(indices.size())); - isNew = true; - return indices.at(name); - } - - isNew = false; - return itName->second; + auto itName = indices.find(name); + if (itName == indices.end()) + { + indices.emplace(name, BP1Index(indices.size())); + isNew = true; + return indices.at(name); + } + + isNew = false; + return itName->second; } void BP1Writer::FlattenData(BP1MetadataSet &metadataSet, capsule::STLVector &heap) const noexcept { - auto &buffer = heap.m_Data; - // vars count and Length (only for PG) - CopyToBuffer(buffer, metadataSet.DataPGVarsCountPosition, - &metadataSet.DataPGVarsCount); - const std::uint64_t varsLength = buffer.size() - - metadataSet.DataPGVarsCountPosition - 8 - - 4; // without record itself and vars count - CopyToBuffer(buffer, metadataSet.DataPGVarsCountPosition + 4, &varsLength); - - // attributes (empty for now) count (4) and length (8) are zero by moving - // positions in time step zero - buffer.insert(buffer.end(), 12, 0); - heap.m_DataAbsolutePosition += 12; - - // Finish writing pg group length - const std::uint64_t dataPGLength = - buffer.size() - metadataSet.DataPGLengthPosition - - 8; // without record itself, 12 due to empty attributes - CopyToBuffer(buffer, metadataSet.DataPGLengthPosition, &dataPGLength); - - ++metadataSet.TimeStep; - metadataSet.DataPGIsOpen = false; + auto &buffer = heap.m_Data; + // vars count and Length (only for PG) + CopyToBuffer(buffer, metadataSet.DataPGVarsCountPosition, + &metadataSet.DataPGVarsCount); + const std::uint64_t varsLength = buffer.size() - + metadataSet.DataPGVarsCountPosition - 8 - + 4; // without record itself and vars count + CopyToBuffer(buffer, metadataSet.DataPGVarsCountPosition + 4, &varsLength); + + // attributes (empty for now) count (4) and length (8) are zero by moving + // positions in time step zero + buffer.insert(buffer.end(), 12, 0); + heap.m_DataAbsolutePosition += 12; + + // Finish writing pg group length + const std::uint64_t dataPGLength = + buffer.size() - metadataSet.DataPGLengthPosition - + 8; // without record itself, 12 due to empty attributes + CopyToBuffer(buffer, metadataSet.DataPGLengthPosition, &dataPGLength); + + ++metadataSet.TimeStep; + metadataSet.DataPGIsOpen = false; } void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, capsule::STLVector &heap) const noexcept { - auto lf_IndexCountLength = - [](std::unordered_map<std::string, BP1Index> &indices, - std::uint32_t &count, std::uint64_t &length) { - count = indices.size(); - length = 0; - for (auto &indexPair : indices) // set each index length - { - auto &indexBuffer = indexPair.second.Buffer; - const std::uint32_t indexLength = indexBuffer.size() - 4; - CopyToBuffer(indexBuffer, 0, &indexLength); - - length += indexBuffer.size(); // overall length - } - }; + auto lf_IndexCountLength = + [](std::unordered_map<std::string, BP1Index> &indices, + std::uint32_t &count, std::uint64_t &length) { + count = indices.size(); + length = 0; + for (auto &indexPair : indices) // set each index length + { + auto &indexBuffer = indexPair.second.Buffer; + const std::uint32_t indexLength = indexBuffer.size() - 4; + CopyToBuffer(indexBuffer, 0, &indexLength); + + length += indexBuffer.size(); // overall length + } + }; + + auto lf_FlattenIndices = + [](const std::uint32_t count, const std::uint64_t length, + const std::unordered_map<std::string, BP1Index> &indices, + std::vector<char> &buffer) { + CopyToBuffer(buffer, &count); + CopyToBuffer(buffer, &length); + + for (const auto &indexPair : indices) // set each index length + { + const auto &indexBuffer = indexPair.second.Buffer; + CopyToBuffer(buffer, indexBuffer.data(), indexBuffer.size()); + } + }; + + // Finish writing metadata counts and lengths + // PG Index + const std::uint64_t pgCount = metadataSet.DataPGCount; + const std::uint64_t pgLength = metadataSet.PGIndex.Buffer.size(); + + // var index count and length (total), and each index length + std::uint32_t varsCount; + std::uint64_t varsLength; + lf_IndexCountLength(metadataSet.VarsIndices, varsCount, varsLength); + // attribute index count and length, and each index length + std::uint32_t attributesCount; + std::uint64_t attributesLength; + lf_IndexCountLength(metadataSet.AttributesIndices, attributesCount, + attributesLength); + + const std::size_t footerSize = (pgLength + 16) + (varsLength + 12) + + (attributesLength + 12) + + metadataSet.MiniFooterSize; + auto &buffer = heap.m_Data; + buffer.reserve(buffer.size() + footerSize); // reserve data to fit metadata, + // must replace with growth buffer + // strategy + + // write pg index + CopyToBuffer(buffer, &pgCount); + CopyToBuffer(buffer, &pgLength); + CopyToBuffer(buffer, metadataSet.PGIndex.Buffer.data(), pgLength); + // Vars indices + lf_FlattenIndices(varsCount, varsLength, metadataSet.VarsIndices, buffer); + // Attribute indices + lf_FlattenIndices(attributesCount, attributesLength, + metadataSet.AttributesIndices, buffer); + + // getting absolute offsets, minifooter is 28 bytes for now + const std::uint64_t offsetPGIndex = heap.m_DataAbsolutePosition; + const std::uint64_t offsetVarsIndex = offsetPGIndex + (pgLength + 16); + const std::uint64_t offsetAttributeIndex = + offsetVarsIndex + (varsLength + 12); + + CopyToBuffer(buffer, &offsetPGIndex); + CopyToBuffer(buffer, &offsetVarsIndex); + CopyToBuffer(buffer, &offsetAttributeIndex); + + // version + if (IsLittleEndian()) + { + const std::uint8_t endian = 0; + CopyToBuffer(buffer, &endian); + buffer.insert(buffer.end(), 2, 0); + CopyToBuffer(buffer, &m_Version); + } + else + { + } - auto lf_FlattenIndices = - [](const std::uint32_t count, const std::uint64_t length, - const std::unordered_map<std::string, BP1Index> &indices, - std::vector<char> &buffer) { - CopyToBuffer(buffer, &count); - CopyToBuffer(buffer, &length); + heap.m_DataAbsolutePosition += footerSize; - for (const auto &indexPair : indices) // set each index length - { - const auto &indexBuffer = indexPair.second.Buffer; - CopyToBuffer(buffer, indexBuffer.data(), indexBuffer.size()); - } - }; - - // Finish writing metadata counts and lengths - // PG Index - const std::uint64_t pgCount = metadataSet.DataPGCount; - const std::uint64_t pgLength = metadataSet.PGIndex.Buffer.size(); - - // var index count and length (total), and each index length - std::uint32_t varsCount; - std::uint64_t varsLength; - lf_IndexCountLength(metadataSet.VarsIndices, varsCount, varsLength); - // attribute index count and length, and each index length - std::uint32_t attributesCount; - std::uint64_t attributesLength; - lf_IndexCountLength(metadataSet.AttributesIndices, attributesCount, - attributesLength); - - const std::size_t footerSize = (pgLength + 16) + (varsLength + 12) + - (attributesLength + 12) + - metadataSet.MiniFooterSize; - auto &buffer = heap.m_Data; - buffer.reserve(buffer.size() + footerSize); // reserve data to fit metadata, - // must replace with growth buffer - // strategy - - // write pg index - CopyToBuffer(buffer, &pgCount); - CopyToBuffer(buffer, &pgLength); - CopyToBuffer(buffer, metadataSet.PGIndex.Buffer.data(), pgLength); - // Vars indices - lf_FlattenIndices(varsCount, varsLength, metadataSet.VarsIndices, buffer); - // Attribute indices - lf_FlattenIndices(attributesCount, attributesLength, - metadataSet.AttributesIndices, buffer); - - // getting absolute offsets, minifooter is 28 bytes for now - const std::uint64_t offsetPGIndex = heap.m_DataAbsolutePosition; - const std::uint64_t offsetVarsIndex = offsetPGIndex + (pgLength + 16); - const std::uint64_t offsetAttributeIndex = - offsetVarsIndex + (varsLength + 12); - - CopyToBuffer(buffer, &offsetPGIndex); - CopyToBuffer(buffer, &offsetVarsIndex); - CopyToBuffer(buffer, &offsetAttributeIndex); - - // version - if (IsLittleEndian()) - { - const std::uint8_t endian = 0; - CopyToBuffer(buffer, &endian); - buffer.insert(buffer.end(), 2, 0); - CopyToBuffer(buffer, &m_Version); - } - else - { - } - - heap.m_DataAbsolutePosition += footerSize; - - if (metadataSet.Log.m_IsActive == true) - { - metadataSet.Log.m_TotalBytes.push_back(heap.m_DataAbsolutePosition); - } + if (metadataSet.Log.m_IsActive == true) + { + metadataSet.Log.m_TotalBytes.push_back(heap.m_DataAbsolutePosition); + } } } // end namespace format diff --git a/source/functions/adiosFunctions.cpp b/source/functions/adiosFunctions.cpp index 78393c641f2c502c35728c46e590252ff8580749..0946dc0d6efa6d79860a595f0ff0be85ad84d8f4 100644 --- a/source/functions/adiosFunctions.cpp +++ b/source/functions/adiosFunctions.cpp @@ -35,197 +35,202 @@ namespace adios void DumpFileToString(const std::string fileName, std::string &fileContent) { - std::ifstream fileStream(fileName); - - if (fileStream.good() == false) - { // check file - throw std::ios_base::failure( - "ERROR: file " + fileName + - " could not be opened. Check permissions or file existence\n"); - } - - std::ostringstream fileSS; - fileSS << fileStream.rdbuf(); - fileStream.close(); - fileContent = fileSS.str(); // convert to string and check - - if (fileContent.empty()) - { - throw std::invalid_argument("ERROR: file " + fileName + " is empty\n"); - } + std::ifstream fileStream(fileName); + + if (fileStream.good() == false) + { // check file + throw std::ios_base::failure( + "ERROR: file " + fileName + + " could not be opened. Check permissions or file existence\n"); + } + + std::ostringstream fileSS; + fileSS << fileStream.rdbuf(); + fileStream.close(); + fileContent = fileSS.str(); // convert to string and check + + if (fileContent.empty()) + { + throw std::invalid_argument("ERROR: file " + fileName + " is empty\n"); + } } void GetSubString(const std::string initialTag, const std::string finalTag, const std::string content, std::string &subString, std::string::size_type ¤tPosition) { - auto lf_Wipe = [](std::string &subString, - std::string::size_type ¤tPosition) { - subString.clear(); - currentPosition = std::string::npos; - }; - - auto lf_SetPositions = - [](const char quote, const std::string::size_type quotePosition, - const std::string &content, std::string::size_type ¤tPosition, - std::string::size_type &closingQuotePosition) { - currentPosition = quotePosition; - closingQuotePosition = content.find(quote, currentPosition + 1); - }; - - // BODY OF FUNCTION STARTS HERE - std::string::size_type start(content.find(initialTag, currentPosition)); - if (start == content.npos) - { - lf_Wipe(subString, currentPosition); - return; - } - currentPosition = start; - - std::string::size_type end(content.find(finalTag, currentPosition)); - if (end == content.npos) - { - lf_Wipe(subString, currentPosition); - return; - } - - // here make sure the finalTag is not a value surrounded by " " or ' ', if so - // find next - bool isValue = true; - - while (isValue == true) - { - std::string::size_type singleQuotePosition = - content.find('\'', currentPosition); - std::string::size_type doubleQuotePosition = - content.find('\"', currentPosition); - - if ((singleQuotePosition == content.npos && - doubleQuotePosition == content.npos) || - (singleQuotePosition == content.npos && end < doubleQuotePosition) || - (doubleQuotePosition == content.npos && end < singleQuotePosition) || - (end < singleQuotePosition && end < doubleQuotePosition)) + auto lf_Wipe = [](std::string &subString, + std::string::size_type ¤tPosition) { + subString.clear(); + currentPosition = std::string::npos; + }; + + auto lf_SetPositions = + [](const char quote, const std::string::size_type quotePosition, + const std::string &content, std::string::size_type ¤tPosition, + std::string::size_type &closingQuotePosition) { + currentPosition = quotePosition; + closingQuotePosition = content.find(quote, currentPosition + 1); + }; + + // BODY OF FUNCTION STARTS HERE + std::string::size_type start(content.find(initialTag, currentPosition)); + if (start == content.npos) { - break; + lf_Wipe(subString, currentPosition); + return; } + currentPosition = start; - // find the closing corresponding quote - std::string::size_type closingQuotePosition; - - if (singleQuotePosition == content.npos) - { // no ' anywhere - lf_SetPositions('\"', doubleQuotePosition, content, currentPosition, - closingQuotePosition); - } - else if (doubleQuotePosition == content.npos) - { // no " anywhere - lf_SetPositions('\'', singleQuotePosition, content, currentPosition, - closingQuotePosition); - } - else + std::string::size_type end(content.find(finalTag, currentPosition)); + if (end == content.npos) { - if (singleQuotePosition < doubleQuotePosition) - { - lf_SetPositions('\'', singleQuotePosition, content, currentPosition, - closingQuotePosition); - } - else - { // find the closing " - lf_SetPositions('\"', doubleQuotePosition, content, currentPosition, - closingQuotePosition); - } + lf_Wipe(subString, currentPosition); + return; } - if (closingQuotePosition == - content.npos) // if can't find closing it's open until the end + // here make sure the finalTag is not a value surrounded by " " or ' ', if + // so + // find next + bool isValue = true; + + while (isValue == true) { - lf_Wipe(subString, currentPosition); - return; - } + std::string::size_type singleQuotePosition = + content.find('\'', currentPosition); + std::string::size_type doubleQuotePosition = + content.find('\"', currentPosition); + + if ((singleQuotePosition == content.npos && + doubleQuotePosition == content.npos) || + (singleQuotePosition == content.npos && + end < doubleQuotePosition) || + (doubleQuotePosition == content.npos && + end < singleQuotePosition) || + (end < singleQuotePosition && end < doubleQuotePosition)) + { + break; + } - currentPosition = closingQuotePosition + 1; + // find the closing corresponding quote + std::string::size_type closingQuotePosition; - if (closingQuotePosition < end) - { - continue; - } + if (singleQuotePosition == content.npos) + { // no ' anywhere + lf_SetPositions('\"', doubleQuotePosition, content, currentPosition, + closingQuotePosition); + } + else if (doubleQuotePosition == content.npos) + { // no " anywhere + lf_SetPositions('\'', singleQuotePosition, content, currentPosition, + closingQuotePosition); + } + else + { + if (singleQuotePosition < doubleQuotePosition) + { + lf_SetPositions('\'', singleQuotePosition, content, + currentPosition, closingQuotePosition); + } + else + { // find the closing " + lf_SetPositions('\"', doubleQuotePosition, content, + currentPosition, closingQuotePosition); + } + } + + if (closingQuotePosition == + content.npos) // if can't find closing it's open until the end + { + lf_Wipe(subString, currentPosition); + return; + } + + currentPosition = closingQuotePosition + 1; + + if (closingQuotePosition < end) + { + continue; + } - // if this point is reached it means it's a value inside " " or ' ', move to - // the next end - end = content.find(finalTag, currentPosition); - } + // if this point is reached it means it's a value inside " " or ' ', + // move to + // the next end + end = content.find(finalTag, currentPosition); + } - subString = content.substr(start, end - start + finalTag.size()); - currentPosition = end; + subString = content.substr(start, end - start + finalTag.size()); + currentPosition = end; } void GetQuotedValue(const char quote, const std::string::size_type "ePosition, std::string ¤tTag, std::string &value) { - currentTag = currentTag.substr(quotePosition + 1); - auto nextQuotePosition = currentTag.find(quote); + currentTag = currentTag.substr(quotePosition + 1); + auto nextQuotePosition = currentTag.find(quote); - if (nextQuotePosition == currentTag.npos) - { - throw std::invalid_argument("ERROR: Invalid attribute in..." + currentTag + - "...check XML file\n"); - } + if (nextQuotePosition == currentTag.npos) + { + throw std::invalid_argument("ERROR: Invalid attribute in..." + + currentTag + "...check XML file\n"); + } - value = currentTag.substr(0, nextQuotePosition); - currentTag = currentTag.substr(nextQuotePosition + 1); + value = currentTag.substr(0, nextQuotePosition); + currentTag = currentTag.substr(nextQuotePosition + 1); } void GetPairs(const std::string tag, std::vector<std::pair<const std::string, const std::string>> &pairs) noexcept { - std::string currentTag( - tag.substr(tag.find_first_of(" \t\n"))); // initialize current tag - - while (currentTag.find('=') != currentTag.npos) // equalPosition - { - currentTag = currentTag.substr(currentTag.find_first_not_of(" \t\n")); - auto equalPosition = currentTag.find('='); - const std::string field(currentTag.substr(0, equalPosition)); // get field - std::string value; - - const char quote = currentTag[equalPosition + 1]; - if (quote == '\'' || quote == '"') // single quotes + std::string currentTag( + tag.substr(tag.find_first_of(" \t\n"))); // initialize current tag + + while (currentTag.find('=') != currentTag.npos) // equalPosition { - GetQuotedValue(quote, equalPosition + 1, currentTag, value); - } + currentTag = currentTag.substr(currentTag.find_first_not_of(" \t\n")); + auto equalPosition = currentTag.find('='); + const std::string field( + currentTag.substr(0, equalPosition)); // get field + std::string value; + + const char quote = currentTag[equalPosition + 1]; + if (quote == '\'' || quote == '"') // single quotes + { + GetQuotedValue(quote, equalPosition + 1, currentTag, value); + } - pairs.push_back( - std::pair<const std::string, const std::string>(field, value)); - } + pairs.push_back( + std::pair<const std::string, const std::string>(field, value)); + } } void GetPairsFromTag( const std::string &fileContent, const std::string tag, std::vector<std::pair<const std::string, const std::string>> &pairs) { - if (tag.back() == '/') // last char is / --> "XML empty tag" - { - GetPairs(tag, pairs); - } - else if (tag[0] == '/') // first char is / ---> closing tag - { - } - else // opening tag - { - const std::string tagName(tag.substr(0, tag.find_first_of(" \t\n\r"))); - const std::string closingTagName("</" + tagName + - ">"); // check for closing tagName - - if (fileContent.find(closingTagName) == fileContent.npos) + if (tag.back() == '/') // last char is / --> "XML empty tag" { - throw std::invalid_argument("ERROR: closing tag " + closingTagName + - " missing, check XML file\n"); + GetPairs(tag, pairs); } + else if (tag[0] == '/') // first char is / ---> closing tag + { + } + else // opening tag + { + const std::string tagName(tag.substr(0, tag.find_first_of(" \t\n\r"))); + const std::string closingTagName("</" + tagName + + ">"); // check for closing tagName - GetPairs(tag, pairs); - } + if (fileContent.find(closingTagName) == fileContent.npos) + { + throw std::invalid_argument("ERROR: closing tag " + closingTagName + + " missing, check XML file\n"); + } + + GetPairs(tag, pairs); + } } // void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, @@ -428,48 +433,48 @@ void GetPairsFromTag( std::size_t GetTotalSize(const std::vector<std::size_t> &dimensions) { - std::size_t product = 1; + std::size_t product = 1; - for (const auto dimension : dimensions) - { - product *= dimension; - } + for (const auto dimension : dimensions) + { + product *= dimension; + } - return product; + return product; } void CreateDirectory(const std::string fullPath) noexcept { - auto lf_Mkdir = [](const std::string directory, struct stat &st) { - if (stat(directory.c_str(), &st) == -1) - { - mkdir(directory.c_str(), 0777); - } - }; - - auto directoryPosition = fullPath.find("/"); + auto lf_Mkdir = [](const std::string directory, struct stat &st) { + if (stat(directory.c_str(), &st) == -1) + { + mkdir(directory.c_str(), 0777); + } + }; - if (fullPath[0] == '/' || fullPath[0] == '.') - { // find the second '/' - directoryPosition = fullPath.find("/", directoryPosition + 1); - } + auto directoryPosition = fullPath.find("/"); - struct stat st = {0}; - if (directoryPosition == fullPath.npos) // no subdirectories - { - lf_Mkdir(fullPath.c_str(), st); - return; - } + if (fullPath[0] == '/' || fullPath[0] == '.') + { // find the second '/' + directoryPosition = fullPath.find("/", directoryPosition + 1); + } - std::string directory(fullPath.substr(0, directoryPosition)); - lf_Mkdir(directory.c_str(), st); + struct stat st = {0}; + if (directoryPosition == fullPath.npos) // no subdirectories + { + lf_Mkdir(fullPath.c_str(), st); + return; + } - while (directoryPosition != fullPath.npos) - { - directoryPosition = fullPath.find("/", directoryPosition + 1); - directory = fullPath.substr(0, directoryPosition); + std::string directory(fullPath.substr(0, directoryPosition)); lf_Mkdir(directory.c_str(), st); - } + + while (directoryPosition != fullPath.npos) + { + directoryPosition = fullPath.find("/", directoryPosition + 1); + directory = fullPath.substr(0, directoryPosition); + lf_Mkdir(directory.c_str(), st); + } } void SetTransformsHelper(const std::vector<std::string> &transformNames, @@ -478,207 +483,209 @@ void SetTransformsHelper(const std::vector<std::string> &transformNames, std::vector<short> &transformIndices, std::vector<short> ¶meters) { - // function to get a parameter from "method:parameter" - auto lf_GetParameter = [](const std::string transformName, - std::string &transformMethod, - const bool debugMode) -> short { - short parameter = -1; - auto colonPosition = transformName.find(":"); - - if (colonPosition != transformName.npos) - { - if (debugMode == true) - { - if (colonPosition == transformName.size() - 1) + // function to get a parameter from "method:parameter" + auto lf_GetParameter = [](const std::string transformName, + std::string &transformMethod, + const bool debugMode) -> short { + short parameter = -1; + auto colonPosition = transformName.find(":"); + + if (colonPosition != transformName.npos) { - throw std::invalid_argument("ERROR: wrong format for transform " + - transformName + - ", in call to SetTransform\n"); + if (debugMode == true) + { + if (colonPosition == transformName.size() - 1) + { + throw std::invalid_argument( + "ERROR: wrong format for transform " + transformName + + ", in call to SetTransform\n"); + } + } + + transformMethod = transformName.substr(0, colonPosition); + parameter = std::stoi( + transformName.substr(colonPosition + 1)); // need to test } - } + return parameter; + }; + + // Get transform index from transforms, if not found return -1 + auto lf_GetTransformIndex = + [](const std::string transformMethod, + const std::vector<std::shared_ptr<Transform>> &transforms) -> short { + short transformIndex = -1; + for (unsigned int i = 0; i < transforms.size(); ++i) + { + if (transforms[i]->m_Method == transformMethod) + { + transformIndex = i; + break; + } + } + return transformIndex; + }; - transformMethod = transformName.substr(0, colonPosition); - parameter = - std::stoi(transformName.substr(colonPosition + 1)); // need to test - } - return parameter; - }; - - // Get transform index from transforms, if not found return -1 - auto lf_GetTransformIndex = - [](const std::string transformMethod, - const std::vector<std::shared_ptr<Transform>> &transforms) -> short { - short transformIndex = -1; - for (unsigned int i = 0; i < transforms.size(); ++i) - { - if (transforms[i]->m_Method == transformMethod) - { - transformIndex = i; - break; - } - } - return transformIndex; - }; - - // BODY of FUNCTION STARTS HERE - for (const std::string transformName : transformNames) - { - std::string transformMethod(transformName); - short parameter = - lf_GetParameter(transformName, transformMethod, - debugMode); // from transform = "method:parameter" - short transformIndex = lf_GetTransformIndex(transformMethod, transforms); - - if (transformIndex == -1) // not found, then create a new transform + // BODY of FUNCTION STARTS HERE + for (const std::string transformName : transformNames) { - if (transformMethod == "bzip2") - { + std::string transformMethod(transformName); + short parameter = + lf_GetParameter(transformName, transformMethod, + debugMode); // from transform = "method:parameter" + short transformIndex = + lf_GetTransformIndex(transformMethod, transforms); + + if (transformIndex == -1) // not found, then create a new transform + { + if (transformMethod == "bzip2") + { #ifdef HAVE_BZIP2 - transforms.push_back(std::make_shared<CBZIP2>()); + transforms.push_back(std::make_shared<CBZIP2>()); #endif - } + } - transformIndex = static_cast<short>(transforms.size() - 1); + transformIndex = static_cast<short>(transforms.size() - 1); + } + transformIndices.push_back(transformIndex); + parameters.push_back(parameter); } - transformIndices.push_back(transformIndex); - parameters.push_back(parameter); - } } std::map<std::string, std::string> BuildParametersMap(const std::vector<std::string> ¶meters, const bool debugMode) { - auto lf_GetFieldValue = [](const std::string parameter, std::string &field, - std::string &value, const bool debugMode) { - auto equalPosition = parameter.find("="); + auto lf_GetFieldValue = [](const std::string parameter, std::string &field, + std::string &value, const bool debugMode) { + auto equalPosition = parameter.find("="); - if (debugMode == true) - { - if (equalPosition == parameter.npos) - { - throw std::invalid_argument("ERROR: wrong format for parameter " + - parameter + - ", format must be field=value \n"); - } - - if (equalPosition == parameter.size() - 1) - { - throw std::invalid_argument("ERROR: empty value in parameter " + - parameter + - ", format must be field=value \n"); - } - } - - field = parameter.substr(0, equalPosition); - value = parameter.substr(equalPosition + 1); // need to test - }; + if (debugMode == true) + { + if (equalPosition == parameter.npos) + { + throw std::invalid_argument( + "ERROR: wrong format for parameter " + parameter + + ", format must be field=value \n"); + } + + if (equalPosition == parameter.size() - 1) + { + throw std::invalid_argument("ERROR: empty value in parameter " + + parameter + + ", format must be field=value \n"); + } + } - // BODY OF FUNCTION STARTS HERE - std::map<std::string, std::string> parametersOutput; + field = parameter.substr(0, equalPosition); + value = parameter.substr(equalPosition + 1); // need to test + }; - for (const auto parameter : parameters) - { - std::string field, value; - lf_GetFieldValue(parameter, field, value, debugMode); + // BODY OF FUNCTION STARTS HERE + std::map<std::string, std::string> parametersOutput; - if (debugMode == true) + for (const auto parameter : parameters) { - if (parametersOutput.count(field) == 1) - { - throw std::invalid_argument("ERROR: parameter " + field + - " already exists, must be unique\n"); - } - } + std::string field, value; + lf_GetFieldValue(parameter, field, value, debugMode); - parametersOutput[field] = value; - } + if (debugMode == true) + { + if (parametersOutput.count(field) == 1) + { + throw std::invalid_argument( + "ERROR: parameter " + field + + " already exists, must be unique\n"); + } + } + + parametersOutput[field] = value; + } - return parametersOutput; + return parametersOutput; } std::vector<int> CSVToVectorInt(const std::string csv) { - std::vector<int> numbers; - if (csv.empty()) - { - return numbers; - } - - if (csv.find(",") == csv.npos) // check if no commas, one int - { - numbers.push_back(std::stoi(csv)); // might need to be checked - } - else - { - int count = std::count(csv.begin(), csv.end(), ','); - numbers.reserve(count); - - std::istringstream csvSS(csv); - std::string value; - while (std::getline(csvSS, value, ',')) // need to test + std::vector<int> numbers; + if (csv.empty()) { - numbers.push_back(std::stoi(csv)); + return numbers; } - } - return numbers; + if (csv.find(",") == csv.npos) // check if no commas, one int + { + numbers.push_back(std::stoi(csv)); // might need to be checked + } + else + { + int count = std::count(csv.begin(), csv.end(), ','); + numbers.reserve(count); + + std::istringstream csvSS(csv); + std::string value; + while (std::getline(csvSS, value, ',')) // need to test + { + numbers.push_back(std::stoi(csv)); + } + } + + return numbers; } bool CheckBufferAllocation(const std::size_t newSize, const float growthFactor, const std::size_t maxBufferSize, std::vector<char> &buffer) { - // Check if data in buffer needs to be reallocated - const std::size_t requiredDataSize = - buffer.size() + newSize + 100; // adding some bytes for tolerance - // might need to write payload in batches - bool doTransportsFlush = (requiredDataSize > maxBufferSize) ? true : false; - - if (GrowBuffer(requiredDataSize, growthFactor, buffer) == -1) - { - doTransportsFlush = true; - } - - return doTransportsFlush; + // Check if data in buffer needs to be reallocated + const std::size_t requiredDataSize = + buffer.size() + newSize + 100; // adding some bytes for tolerance + // might need to write payload in batches + bool doTransportsFlush = (requiredDataSize > maxBufferSize) ? true : false; + + if (GrowBuffer(requiredDataSize, growthFactor, buffer) == -1) + { + doTransportsFlush = true; + } + + return doTransportsFlush; } int GrowBuffer(const std::size_t incomingDataSize, const float growthFactor, std::vector<char> &buffer) { - const std::size_t currentCapacity = buffer.capacity(); - const std::size_t availableSpace = currentCapacity - buffer.size(); - const double gf = static_cast<double>(growthFactor); - - if (incomingDataSize > availableSpace) - { - const std::size_t neededCapacity = incomingDataSize + buffer.size(); - const double numerator = std::log(static_cast<double>(neededCapacity) / - static_cast<double>(currentCapacity)); - const double denominator = std::log(gf); - - double n = std::ceil(numerator / denominator); - const std::size_t newSize = - static_cast<std::size_t>(std::ceil(std::pow(gf, n) * currentCapacity)); - - try - { - buffer.reserve(newSize); - } - catch (std::bad_alloc &e) + const std::size_t currentCapacity = buffer.capacity(); + const std::size_t availableSpace = currentCapacity - buffer.size(); + const double gf = static_cast<double>(growthFactor); + + if (incomingDataSize > availableSpace) { - return -1; - } + const std::size_t neededCapacity = incomingDataSize + buffer.size(); + const double numerator = std::log(static_cast<double>(neededCapacity) / + static_cast<double>(currentCapacity)); + const double denominator = std::log(gf); + + double n = std::ceil(numerator / denominator); + const std::size_t newSize = static_cast<std::size_t>( + std::ceil(std::pow(gf, n) * currentCapacity)); - return 1; - } - return 0; + try + { + buffer.reserve(newSize); + } + catch (std::bad_alloc &e) + { + return -1; + } + + return 1; + } + return 0; } bool IsLittleEndian() noexcept { - uint16_t hexa = 0x1234; - return *reinterpret_cast<uint8_t *>(&hexa) != 0x12; // NOLINT + uint16_t hexa = 0x1234; + return *reinterpret_cast<uint8_t *>(&hexa) != 0x12; // NOLINT } } // namespace adios diff --git a/source/mpidummy.cpp b/source/mpidummy.cpp index f85e40a44a64c84718691452db59a420e1b8f369..c70ae74e0d74dd3a1215427e8d82e1ab36d55b5e 100644 --- a/source/mpidummy.cpp +++ b/source/mpidummy.cpp @@ -40,26 +40,26 @@ static char mpierrmsg[MPI_MAX_ERROR_STRING]; int MPI_Init(int * /*argc*/, char *** /*argv*/) { - mpierrmsg[0] = '\0'; - return MPI_SUCCESS; + mpierrmsg[0] = '\0'; + return MPI_SUCCESS; } int MPI_Finalize() { - mpierrmsg[0] = '\0'; - return MPI_SUCCESS; + mpierrmsg[0] = '\0'; + return MPI_SUCCESS; } int MPI_Initialized(int *flag) { - *flag = 1; - return MPI_SUCCESS; + *flag = 1; + return MPI_SUCCESS; } int MPI_Comm_split(MPI_Comm /*comm*/, int /*color*/, int /*key*/, MPI_Comm * /*comm_out*/) { - return MPI_SUCCESS; + return MPI_SUCCESS; } int MPI_Barrier(MPI_Comm /*comm*/) { return MPI_SUCCESS; } @@ -67,31 +67,31 @@ int MPI_Barrier(MPI_Comm /*comm*/) { return MPI_SUCCESS; } int MPI_Bcast(void * /*buffer*/, int /*count*/, MPI_Datatype /*datatype*/, int /*root*/, MPI_Comm /*comm*/) { - return MPI_SUCCESS; + return MPI_SUCCESS; } int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) { - *newcomm = comm; - return MPI_SUCCESS; + *newcomm = comm; + return MPI_SUCCESS; } int MPI_Comm_rank(MPI_Comm /*comm*/, int *rank) { - *rank = 0; - return MPI_SUCCESS; + *rank = 0; + return MPI_SUCCESS; } int MPI_Comm_size(MPI_Comm /*comm*/, int *size) { - *size = 1; - return MPI_SUCCESS; + *size = 1; + return MPI_SUCCESS; } int MPI_Comm_free(MPI_Comm *comm) { - *comm = 0; - return MPI_SUCCESS; + *comm = 0; + return MPI_SUCCESS; } MPI_Comm MPI_Comm_f2c(MPI_Fint comm) { return comm; } @@ -100,158 +100,158 @@ 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) - { - ier = MPI_ERR_BUFFER; - } - if (comm == MPI_COMM_NULL || root) - { - ier = MPI_ERR_COMM; - } - - switch (sendtype) - { + int ier = MPI_SUCCESS; + size_t n = 0, nsent = 0, nrecv = 0; + if (!sendbuf || !recvbuf) + { + ier = MPI_ERR_BUFFER; + } + if (comm == MPI_COMM_NULL || root) + { + ier = MPI_ERR_COMM; + } + + switch (sendtype) + { case MPI_INT: - n = sizeof(int); - break; + n = sizeof(int); + break; default: - return MPI_ERR_TYPE; - } - nsent = n * sendcnt; + return MPI_ERR_TYPE; + } + nsent = n * sendcnt; - switch (recvtype) - { + switch (recvtype) + { case MPI_INT: - nrecv = sizeof(int); - break; + nrecv = sizeof(int); + break; default: - return MPI_ERR_TYPE; - } - nrecv = n * recvcnt; - - if (nrecv != nsent) - { - ier = MPI_ERR_COUNT; - } - - if (ier == MPI_SUCCESS) - { - memcpy(recvbuf, sendbuf, nsent); - } - else - { - snprintf(mpierrmsg, ier, "could not gather data\n"); - } - - return ier; + return MPI_ERR_TYPE; + } + nrecv = n * recvcnt; + + if (nrecv != nsent) + { + ier = MPI_ERR_COUNT; + } + + if (ier == MPI_SUCCESS) + { + memcpy(recvbuf, sendbuf, nsent); + } + else + { + snprintf(mpierrmsg, ier, "could not gather data\n"); + } + + return ier; } int MPI_Gatherv(const void *sendbuf, int sendcnt, MPI_Datatype sendtype, void *recvbuf, const int *recvcnts, const int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm) { - int ier = MPI_SUCCESS; - if (!recvcnts || !displs) - { - ier = MPI_ERR_BUFFER; - } - - if (ier == MPI_SUCCESS) - { - ier = MPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, *recvcnts, recvtype, - root, comm); - } - - return ier; + int ier = MPI_SUCCESS; + if (!recvcnts || !displs) + { + ier = MPI_ERR_BUFFER; + } + + if (ier == MPI_SUCCESS) + { + ier = MPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, *recvcnts, + recvtype, root, comm); + } + + return ier; } 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 MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, + recvtype, 0, comm); } int MPI_Scatter(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) - { - ier = MPI_ERR_BUFFER; - } - - if (comm == MPI_COMM_NULL || root) - { - ier = MPI_ERR_COMM; - } - - switch (sendtype) - { + int ier = MPI_SUCCESS; + size_t n = 0, nsent = 0, nrecv = 0; + if (!sendbuf || !recvbuf) + { + ier = MPI_ERR_BUFFER; + } + + if (comm == MPI_COMM_NULL || root) + { + ier = MPI_ERR_COMM; + } + + switch (sendtype) + { case MPI_INT: - n = sizeof(int); - break; + n = sizeof(int); + break; default: - return MPI_ERR_TYPE; - } - nsent = n * sendcnt; + return MPI_ERR_TYPE; + } + nsent = n * sendcnt; - switch (recvtype) - { + switch (recvtype) + { case MPI_INT: - nrecv = sizeof(int); - break; + nrecv = sizeof(int); + break; default: - return MPI_ERR_TYPE; - } - nrecv = n * recvcnt; - - if (nrecv != nsent) - { - ier = MPI_ERR_COUNT; - } - - if (ier == MPI_SUCCESS) - { - memcpy(recvbuf, sendbuf, nsent); - } - else - { - snprintf(mpierrmsg, ier, "could not scatter data\n"); - } - - return ier; + return MPI_ERR_TYPE; + } + nrecv = n * recvcnt; + + if (nrecv != nsent) + { + ier = MPI_ERR_COUNT; + } + + if (ier == MPI_SUCCESS) + { + memcpy(recvbuf, sendbuf, nsent); + } + else + { + snprintf(mpierrmsg, ier, "could not scatter data\n"); + } + + return ier; } int MPI_Scatterv(const void *sendbuf, const int *sendcnts, const int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm) { - int ier = MPI_SUCCESS; - if (!sendcnts || !displs) - { - ier = MPI_ERR_BUFFER; - } - - if (ier == MPI_SUCCESS) - { - ier = MPI_Scatter(sendbuf, *sendcnts, sendtype, recvbuf, recvcnt, recvtype, - root, comm); - } - - return ier; + int ier = MPI_SUCCESS; + if (!sendcnts || !displs) + { + ier = MPI_ERR_BUFFER; + } + + if (ier == MPI_SUCCESS) + { + ier = MPI_Scatter(sendbuf, *sendcnts, sendtype, recvbuf, recvcnt, + recvtype, root, comm); + } + + return ier; } int MPI_Recv(void * /*recvbuffer*/, int /*count*/, MPI_Datatype /*type*/, int /*source*/, int /*tag*/, MPI_Comm /*comm*/, MPI_Status * /*status*/) { - return 0; + return 0; } int MPI_Irecv(void * /*recvbuffer*/, int /*count*/, MPI_Datatype /*type*/, @@ -259,20 +259,20 @@ int MPI_Irecv(void * /*recvbuffer*/, int /*count*/, MPI_Datatype /*type*/, MPI_Request * /*request*/) { - return 0; + return 0; } int MPI_Send(const void * /*sendbuffer*/, int /*count*/, MPI_Datatype /*type*/, int /*destination*/, int /*tag*/, MPI_Comm /*comm*/) { - return 0; + return 0; } int MPI_Isend(const void * /*recvbuffer*/, int /*count*/, MPI_Datatype /*type*/, int /*source*/, int /*tag*/, MPI_Comm /*comm*/, MPI_Request * /*request*/) { - return 0; + return 0; } int MPI_Wait(MPI_Request * /*request*/, MPI_Status * /*status*/) { return 0; } @@ -280,83 +280,85 @@ int MPI_Wait(MPI_Request * /*request*/, MPI_Status * /*status*/) { return 0; } int MPI_File_open(MPI_Comm /*comm*/, const char *filename, int amode, MPI_Info /*info*/, MPI_File *fh) { - *fh = open64(filename, amode); - if (*fh == -1) - { - snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, "File not found: %s", filename); - return -1; - } - return MPI_SUCCESS; + *fh = open64(filename, amode); + if (*fh == -1) + { + snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, "File not found: %s", + filename); + return -1; + } + return MPI_SUCCESS; } int MPI_File_close(MPI_File *fh) { return close(*fh); } int MPI_File_get_size(MPI_File fh, MPI_Offset *size) { - uint64_t curpos = lseek64(fh, 0, SEEK_CUR); // get the current seek pos - uint64_t endpos = - lseek64(fh, 0, SEEK_END); // go to end, returned is the size in bytes - lseek64(fh, curpos, SEEK_SET); // go back where we were - *size = static_cast<MPI_Offset>(endpos); - // printf("MPI_File_get_size: fh=%d, size=%lld\n", fh, *size); - return MPI_SUCCESS; + uint64_t curpos = lseek64(fh, 0, SEEK_CUR); // get the current seek pos + uint64_t endpos = + lseek64(fh, 0, SEEK_END); // go to end, returned is the size in bytes + lseek64(fh, curpos, SEEK_SET); // go back where we were + *size = static_cast<MPI_Offset>(endpos); + // printf("MPI_File_get_size: fh=%d, size=%lld\n", fh, *size); + return MPI_SUCCESS; } int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status) { - // FIXME: int count can read only 2GB (*datatype size) array at max - uint64_t bytes_to_read = static_cast<uint64_t>(count) * datatype; - uint64_t bytes_read; - bytes_read = read(fh, buf, bytes_to_read); - if (bytes_read != bytes_to_read) - { - snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, - "could not read %" PRId64 " bytes. read only: %" PRId64 "\n", - bytes_to_read, bytes_read); - return -2; - } - *status = bytes_read; - // printf("MPI_File_read: fh=%d, count=%d, typesize=%d, bytes read=%lld\n", - // fh, count, datatype, *status); - return MPI_SUCCESS; + // FIXME: int count can read only 2GB (*datatype size) array at max + uint64_t bytes_to_read = static_cast<uint64_t>(count) * datatype; + uint64_t bytes_read; + bytes_read = read(fh, buf, bytes_to_read); + if (bytes_read != bytes_to_read) + { + snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, + "could not read %" PRId64 " bytes. read only: %" PRId64 "\n", + bytes_to_read, bytes_read); + return -2; + } + *status = bytes_read; + // printf("MPI_File_read: fh=%d, count=%d, typesize=%d, bytes read=%lld\n", + // fh, count, datatype, *status); + return MPI_SUCCESS; } int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence) { - lseek64(fh, offset, whence); - // printf("MPI_File_seek: fh=%d, offset=%lld, whence=%d\n", fh, off, whence); - return MPI_SUCCESS; + lseek64(fh, offset, whence); + // printf("MPI_File_seek: fh=%d, offset=%lld, whence=%d\n", fh, off, + // whence); + return MPI_SUCCESS; } int MPI_Get_count(const MPI_Status *status, MPI_Datatype, int *count) { - *count = static_cast<int>(*status); - return MPI_SUCCESS; + *count = static_cast<int>(*status); + return MPI_SUCCESS; } int MPI_Error_string(int /*errorcode*/, char *string, int *resultlen) { - // sprintf(string, "Dummy lib does not know error strings. - // Code=%d\n",errorcode); - strcpy(string, mpierrmsg); - *resultlen = strlen(string); - return MPI_SUCCESS; + // sprintf(string, "Dummy lib does not know error strings. + // Code=%d\n",errorcode); + strcpy(string, mpierrmsg); + *resultlen = strlen(string); + return MPI_SUCCESS; } double MPI_Wtime() { - // Implementation not tested - timeval tv = {0, 0}; - gettimeofday(&tv, nullptr); - return tv.tv_sec + tv.tv_usec * 1e-6; + // Implementation not tested + timeval tv = {0, 0}; + gettimeofday(&tv, nullptr); + return tv.tv_sec + tv.tv_usec * 1e-6; } int MPI_Get_processor_name(char *name, int *resultlen) { - sprintf(name, "0"); - *resultlen = 1; - return 0; + sprintf(name, "0"); + *resultlen = 1; + return 0; } } // end namespace adios diff --git a/source/transport/file/FStream.cpp b/source/transport/file/FStream.cpp index 2a404ae6a96a10471e5ccd97acd547617a73fdb0..b516de8b067f6b6d373ba237965999e3c72b62d6 100644 --- a/source/transport/file/FStream.cpp +++ b/source/transport/file/FStream.cpp @@ -27,50 +27,51 @@ FStream::FStream(MPI_Comm mpiComm, bool debugMode) void FStream::Open(const std::string name, const std::string accessMode) { - m_Name = name; - m_AccessMode = accessMode; + m_Name = name; + m_AccessMode = accessMode; - if (accessMode == "w" || accessMode == "write") - { - m_FStream.open(name, std::fstream::out); - } - else if (accessMode == "a" || accessMode == "append") - { - m_FStream.open(name, std::fstream::out | std::fstream::app); - } - else if (accessMode == "r" || accessMode == "read") - { - m_FStream.open(name, std::fstream::in); - } + if (accessMode == "w" || accessMode == "write") + { + m_FStream.open(name, std::fstream::out); + } + else if (accessMode == "a" || accessMode == "append") + { + m_FStream.open(name, std::fstream::out | std::fstream::app); + } + else if (accessMode == "r" || accessMode == "read") + { + m_FStream.open(name, std::fstream::in); + } - if (m_DebugMode == true) - { - if (!m_FStream) + if (m_DebugMode == true) { - throw std::ios_base::failure( - "ERROR: couldn't open file " + name + - ", in call to Open from FStream transport\n"); + if (!m_FStream) + { + throw std::ios_base::failure( + "ERROR: couldn't open file " + name + + ", in call to Open from FStream transport\n"); + } } - } } void FStream::SetBuffer(char *buffer, std::size_t size) { - m_FStream.rdbuf()->pubsetbuf(buffer, size); + m_FStream.rdbuf()->pubsetbuf(buffer, size); } void FStream::Write(const char *buffer, std::size_t size) { - m_FStream.write(buffer, size); + m_FStream.write(buffer, size); - if (m_DebugMode == true) - { - if (!m_FStream) + if (m_DebugMode == true) { - throw std::ios_base::failure("ERROR: couldn't write to file " + m_Name + - ", in call to FStream write\n"); + if (!m_FStream) + { + throw std::ios_base::failure("ERROR: couldn't write to file " + + m_Name + + ", in call to FStream write\n"); + } } - } } void FStream::Flush() { m_FStream.flush(); } diff --git a/source/transport/file/FileDescriptor.cpp b/source/transport/file/FileDescriptor.cpp index 0d6a87c96826042d79581ec356b9c96d796a85cf..e1c3df9ab69d0ecd027a9ea3af072674e084e5ec 100644 --- a/source/transport/file/FileDescriptor.cpp +++ b/source/transport/file/FileDescriptor.cpp @@ -31,128 +31,129 @@ FileDescriptor::FileDescriptor(MPI_Comm mpiComm, const bool debugMode) FileDescriptor::~FileDescriptor() { - if (m_FileDescriptor != -1) - { - close(m_FileDescriptor); - } + if (m_FileDescriptor != -1) + { + close(m_FileDescriptor); + } } void FileDescriptor::Open(const std::string name, const std::string accessMode) { - m_Name = name; - m_AccessMode = accessMode; + m_Name = name; + m_AccessMode = accessMode; - if (accessMode == "w" || accessMode == "write") - { - if (m_Profiler.m_IsActive == true) + if (accessMode == "w" || accessMode == "write") { - m_Profiler.m_Timers[0].SetInitialTime(); - } + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[0].SetInitialTime(); + } - m_FileDescriptor = open(m_Name.c_str(), O_WRONLY | O_CREAT, 0777); + m_FileDescriptor = open(m_Name.c_str(), O_WRONLY | O_CREAT, 0777); - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[0].SetTime(); - } - } - else if (accessMode == "a" || accessMode == "append") - { - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[0].SetInitialTime(); + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[0].SetTime(); + } } - - m_FileDescriptor = - open(m_Name.c_str(), O_WRONLY | O_APPEND); // we need to change this - - if (m_Profiler.m_IsActive == true) + else if (accessMode == "a" || accessMode == "append") { - m_Profiler.m_Timers[0].SetTime(); + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[0].SetInitialTime(); + } + + m_FileDescriptor = open(m_Name.c_str(), + O_WRONLY | O_APPEND); // we need to change this + + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[0].SetTime(); + } } - } - else if (accessMode == "r" || accessMode == "read") - { - if (m_Profiler.m_IsActive == true) + else if (accessMode == "r" || accessMode == "read") { - m_Profiler.m_Timers[0].SetInitialTime(); - } + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[0].SetInitialTime(); + } - m_FileDescriptor = open(m_Name.c_str(), O_RDONLY); + m_FileDescriptor = open(m_Name.c_str(), O_RDONLY); - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[0].SetTime(); + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[0].SetTime(); + } } - } - if (m_DebugMode == true) - { - if (m_FileDescriptor == -1) + if (m_DebugMode == true) { - throw std::ios_base::failure("ERROR: couldn't open file " + m_Name + - ", from call to Open in FD transport using " - "POSIX open. Does file exists?\n"); + if (m_FileDescriptor == -1) + { + throw std::ios_base::failure( + "ERROR: couldn't open file " + m_Name + + ", from call to Open in FD transport using " + "POSIX open. Does file exists?\n"); + } } - } } void FileDescriptor::Write(const char *buffer, std::size_t size) { - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[1].SetInitialTime(); - } - - auto writtenSize = write(m_FileDescriptor, buffer, size); + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[1].SetInitialTime(); + } - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[1].SetTime(); - } + auto writtenSize = write(m_FileDescriptor, buffer, size); - if (m_DebugMode == true) - { - if (writtenSize == -1) + if (m_Profiler.m_IsActive == true) { - throw std::ios_base::failure("ERROR: couldn't write to file " + m_Name + - ", in call to POSIX write\n"); + m_Profiler.m_Timers[1].SetTime(); } - if (static_cast<std::size_t>(writtenSize) != size) + if (m_DebugMode == true) { - throw std::ios_base::failure( - "ERROR: written size + " + std::to_string(writtenSize) + - " is not equal to intended size " + std::to_string(size) + - " in file " + m_Name + ", in call to POSIX write\n"); + if (writtenSize == -1) + { + throw std::ios_base::failure("ERROR: couldn't write to file " + + m_Name + ", in call to POSIX write\n"); + } + + if (static_cast<std::size_t>(writtenSize) != size) + { + throw std::ios_base::failure( + "ERROR: written size + " + std::to_string(writtenSize) + + " is not equal to intended size " + std::to_string(size) + + " in file " + m_Name + ", in call to POSIX write\n"); + } } - } } void FileDescriptor::Close() { - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[2].SetInitialTime(); - } + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[2].SetInitialTime(); + } - int status = close(m_FileDescriptor); + int status = close(m_FileDescriptor); - if (m_Profiler.m_IsActive == true) - { - m_Profiler.m_Timers[2].SetTime(); - } + if (m_Profiler.m_IsActive == true) + { + m_Profiler.m_Timers[2].SetTime(); + } - if (m_DebugMode == true) - { - if (status == -1) + if (m_DebugMode == true) { - throw std::ios_base::failure("ERROR: couldn't close file " + m_Name + - ", in call to POSIX write\n"); + if (status == -1) + { + throw std::ios_base::failure("ERROR: couldn't close file " + + m_Name + ", in call to POSIX write\n"); + } } - } - m_IsOpen = false; + m_IsOpen = false; } } // end namespace transport diff --git a/source/transport/file/FilePointer.cpp b/source/transport/file/FilePointer.cpp index 1ba57204e6a6827c7454c688b37b8e2f1d62e2c9..4cbe9a8918f4c8a2fcae03543460292e2a22648b 100644 --- a/source/transport/file/FilePointer.cpp +++ b/source/transport/file/FilePointer.cpp @@ -26,76 +26,78 @@ FilePointer::FilePointer(MPI_Comm mpiComm, const bool debugMode) FilePointer::~FilePointer() { - if (m_File != nullptr) - { - fclose(m_File); - } + if (m_File != nullptr) + { + fclose(m_File); + } } void FilePointer::Open(const std::string name, const std::string accessMode) { - m_Name = name; - m_AccessMode = accessMode; - - if (accessMode == "w" || accessMode == "write") - { - m_File = fopen(name.c_str(), "w"); - } - else if (accessMode == "a" || accessMode == "append") - { - m_File = fopen(name.c_str(), "a"); - } - else if (accessMode == "r" || accessMode == "read") - { - m_File = fopen(name.c_str(), "r"); - } - - if (m_DebugMode == true) - { - if (m_File == nullptr) + m_Name = name; + m_AccessMode = accessMode; + + if (accessMode == "w" || accessMode == "write") + { + m_File = fopen(name.c_str(), "w"); + } + else if (accessMode == "a" || accessMode == "append") { - throw std::ios_base::failure("ERROR: couldn't open file " + name + - ", " - "in call to Open from File* transport\n"); + m_File = fopen(name.c_str(), "a"); + } + else if (accessMode == "r" || accessMode == "read") + { + m_File = fopen(name.c_str(), "r"); + } + + if (m_DebugMode == true) + { + if (m_File == nullptr) + { + throw std::ios_base::failure( + "ERROR: couldn't open file " + name + + ", " + "in call to Open from File* transport\n"); + } } - } } void FilePointer::SetBuffer(char *buffer, std::size_t size) { - int status = setvbuf(m_File, buffer, _IOFBF, size); + int status = setvbuf(m_File, buffer, _IOFBF, size); - if (m_DebugMode == true) - { - if (status == 1) + if (m_DebugMode == true) { - throw std::ios_base::failure("ERROR: could not set buffer in rank " + - std::to_string(m_RankMPI) + "\n"); + if (status == 1) + { + throw std::ios_base::failure( + "ERROR: could not set buffer in rank " + + std::to_string(m_RankMPI) + "\n"); + } } - } } void FilePointer::Write(const char *buffer, std::size_t size) { - fwrite(buffer, sizeof(char), size, m_File); + fwrite(buffer, sizeof(char), size, m_File); - if (m_DebugMode == true) - { - if (ferror(m_File)) + if (m_DebugMode == true) { - throw std::ios_base::failure("ERROR: couldn't write to file " + m_Name + - ", in call to File* write\n"); + if (ferror(m_File)) + { + throw std::ios_base::failure("ERROR: couldn't write to file " + + m_Name + ", in call to File* write\n"); + } } - } } void FilePointer::Flush() { fflush(m_File); } void FilePointer::Close() { - fclose(m_File); + fclose(m_File); - m_IsOpen = false; + m_IsOpen = false; } } // end namespace transport diff --git a/source/transport/wan/MdtmMan.cpp b/source/transport/wan/MdtmMan.cpp index 55324e0c2f23d9f2ba33f5b1a43584becda3bac8..cdece2ecbfa5270b2e36eedb07af430319056cb1 100644 --- a/source/transport/wan/MdtmMan.cpp +++ b/source/transport/wan/MdtmMan.cpp @@ -49,7 +49,7 @@ int MdtmMan::Put(const void *data, const std::string doid, const int priority) { - return 0; + return 0; } int MdtmMan::Get(void *data, const std::string doid, const std::string variable, @@ -61,7 +61,7 @@ int MdtmMan::Get(void *data, const std::string doid, const std::string variable, const int priority) { - return 0; + return 0; } int MdtmMan::Get(void *data, const std::string doid, const std::string variable, @@ -69,7 +69,7 @@ int MdtmMan::Get(void *data, const std::string doid, const std::string variable, const std::uint64_t timestep) { - return 0; + return 0; } void MdtmMan::OnReceive(nlohmann::json &jData) {}