From f332881227a74a8d8d4d4708b6fbb4a08c546789 Mon Sep 17 00:00:00 2001 From: Junmin Gu Date: Fri, 22 Sep 2023 18:08:09 -0700 Subject: [PATCH 01/41] 1) removed unused code sections 2) added support for Local Arrays 3) added test for local arrays in python 4) result can be returned as vector of start/count (global array only), or vector of block ids --- bindings/CXX11/adios2/cxx11/Query.cpp | 8 +- bindings/CXX11/adios2/cxx11/Query.h | 1 + bindings/Python/py11Query.cpp | 7 + bindings/Python/py11Query.h | 1 + bindings/Python/py11glue.cpp | 42 ++--- examples/query/test.cpp | 83 ++++----- source/adios2/toolkit/query/BlockIndex.h | 134 ++++++++------ source/adios2/toolkit/query/Query.cpp | 165 ++++++++++-------- source/adios2/toolkit/query/Query.h | 59 ++++++- source/adios2/toolkit/query/Worker.cpp | 20 ++- source/adios2/toolkit/query/Worker.h | 1 + testing/adios2/bindings/python/CMakeLists.txt | 3 +- .../bindings/python/TestQueryLocalArray.py | 140 +++++++++++++++ 13 files changed, 461 insertions(+), 203 deletions(-) create mode 100644 testing/adios2/bindings/python/TestQueryLocalArray.py diff --git a/bindings/CXX11/adios2/cxx11/Query.cpp b/bindings/CXX11/adios2/cxx11/Query.cpp index 140d1485c6..099b68a818 100644 --- a/bindings/CXX11/adios2/cxx11/Query.cpp +++ b/bindings/CXX11/adios2/cxx11/Query.cpp @@ -14,6 +14,11 @@ QueryWorker::QueryWorker(const std::string &configFile, adios2::Engine &reader) delete m; } +void QueryWorker::GetResultCoverage(std::vector &touched_blockIDs) +{ + m_Worker->GetResultCoverage(touched_blockIDs); +} + void QueryWorker::GetResultCoverage(std::vector> &touched_blocks) { adios2::Box empty; @@ -26,4 +31,5 @@ void QueryWorker::GetResultCoverage(const adios2::Box &outputSelec if (m_Worker) return m_Worker->GetResultCoverage(outputSelection, touched_blocks); } -} + +} // namespace diff --git a/bindings/CXX11/adios2/cxx11/Query.h b/bindings/CXX11/adios2/cxx11/Query.h index 1b26ab62d6..0cd5750bbf 100644 --- a/bindings/CXX11/adios2/cxx11/Query.h +++ b/bindings/CXX11/adios2/cxx11/Query.h @@ -29,6 +29,7 @@ class QueryWorker // configFile has query, can be either xml or json QueryWorker(const std::string &configFile, adios2::Engine &engine); + void GetResultCoverage(std::vector &touched_block_ids); // touched_blocks is a list of regions specified by (start, count), // that contains data that satisfies the query file void GetResultCoverage(std::vector> &touched_blocks); diff --git a/bindings/Python/py11Query.cpp b/bindings/Python/py11Query.cpp index 0e82cae6bb..01c8cdb050 100644 --- a/bindings/Python/py11Query.cpp +++ b/bindings/Python/py11Query.cpp @@ -36,5 +36,12 @@ std::vector> Query::GetResult() return touched_blocks; } +std::vector Query::GetBlockIDs() +{ + std::vector touched_block_ids; + m_QueryWorker->GetResultCoverage(touched_block_ids); + return touched_block_ids; +} + } // py11 } // adios2 diff --git a/bindings/Python/py11Query.h b/bindings/Python/py11Query.h index b8cd29018b..64768f0b7d 100644 --- a/bindings/Python/py11Query.h +++ b/bindings/Python/py11Query.h @@ -34,6 +34,7 @@ class Query explicit operator bool() const noexcept; std::vector> GetResult(); + std::vector GetBlockIDs(); private: Query(adios2::query::Worker *qw); diff --git a/bindings/Python/py11glue.cpp b/bindings/Python/py11glue.cpp index b9f239b603..5e420bebff 100644 --- a/bindings/Python/py11glue.cpp +++ b/bindings/Python/py11glue.cpp @@ -357,7 +357,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) "adios2 query construction, a xml query File and a read engine", pybind11::arg("queryFile"), pybind11::arg("reader") = true) - .def("GetResult", &adios2::py11::Query::GetResult); + .def("GetResult", &adios2::py11::Query::GetResult) + + .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); pybind11::class_(m, "Variable") // Python 2 @@ -433,13 +435,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) pybind11::return_value_policy::move) .def("Put", - (void(adios2::py11::Engine::*)(adios2::py11::Variable, const pybind11::array &, - const adios2::Mode launch)) & + (void (adios2::py11::Engine::*)(adios2::py11::Variable, const pybind11::array &, + const adios2::Mode launch)) & adios2::py11::Engine::Put, pybind11::arg("variable"), pybind11::arg("array"), pybind11::arg("launch") = adios2::Mode::Deferred) - .def("Put", (void(adios2::py11::Engine::*)(adios2::py11::Variable, const std::string &)) & + .def("Put", (void (adios2::py11::Engine::*)(adios2::py11::Variable, const std::string &)) & adios2::py11::Engine::Put) .def("PerformPuts", &adios2::py11::Engine::PerformPuts) @@ -447,8 +449,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .def("PerformDataWrite", &adios2::py11::Engine::PerformDataWrite) .def("Get", - (void(adios2::py11::Engine::*)(adios2::py11::Variable, pybind11::array &, - const adios2::Mode launch)) & + (void (adios2::py11::Engine::*)(adios2::py11::Variable, pybind11::array &, + const adios2::Mode launch)) & adios2::py11::Engine::Get, pybind11::arg("variable"), pybind11::arg("array"), pybind11::arg("launch") = adios2::Mode::Deferred) @@ -599,9 +601,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, - const adios2::Dims &, const bool)) & + (void (adios2::py11::File::*)(const std::string &, const pybind11::array &, + const adios2::Dims &, const adios2::Dims &, + const adios2::Dims &, const bool)) & adios2::py11::File::Write, pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), @@ -633,7 +635,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void(adios2::py11::File::*)( + (void (adios2::py11::File::*)( const std::string &, const pybind11::array &, const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, const adios2::vParams &, const bool)) & adios2::py11::File::Write, @@ -668,8 +670,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, const bool, - const bool)) & + (void (adios2::py11::File::*)(const std::string &, const pybind11::array &, const bool, + const bool)) & adios2::py11::File::Write, pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("local_value") = false, pybind11::arg("end_step") = false, R"md( @@ -691,8 +693,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void(adios2::py11::File::*)(const std::string &, const std::string &, const bool, - const bool)) & + (void (adios2::py11::File::*)(const std::string &, const std::string &, const bool, + const bool)) & adios2::py11::File::Write, pybind11::arg("name"), pybind11::arg("string"), pybind11::arg("local_value") = false, pybind11::arg("end_step") = false, R"md( @@ -714,8 +716,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write_attribute", - (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, - const std::string &, const std::string, const bool)) & + (void (adios2::py11::File::*)(const std::string &, const pybind11::array &, + const std::string &, const std::string, const bool)) & adios2::py11::File::WriteAttribute, pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, R"md( @@ -742,8 +744,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write_attribute", - (void(adios2::py11::File::*)(const std::string &, const std::string &, - const std::string &, const std::string, const bool)) & + (void (adios2::py11::File::*)(const std::string &, const std::string &, + const std::string &, const std::string, const bool)) & adios2::py11::File::WriteAttribute, pybind11::arg("name"), pybind11::arg("string_value"), pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", @@ -771,8 +773,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write_attribute", - (void(adios2::py11::File::*)(const std::string &, const std::vector &, - const std::string &, const std::string, const bool)) & + (void (adios2::py11::File::*)(const std::string &, const std::vector &, + const std::string &, const std::string, const bool)) & adios2::py11::File::WriteAttribute, pybind11::arg("name"), pybind11::arg("string_array"), pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", diff --git a/examples/query/test.cpp b/examples/query/test.cpp index b97a2d7714..441cc4718e 100644 --- a/examples/query/test.cpp +++ b/examples/query/test.cpp @@ -10,7 +10,29 @@ #include #include -// #include "adios2/toolkit/query/Worker.h" +// returns block ids +void queryIDs(adios2::IO &queryIO, std::string &dataFileName, std::string &queryFile) +{ + adios2::Engine reader = queryIO.Open(dataFileName, adios2::Mode::Read, MPI_COMM_WORLD); + // adios2::QueryWorker* worker = NULL; + queryIO.SetParameter("StreamReader", "true"); + std::vector touched_blockIDs; + + while (reader.BeginStep() == adios2::StepStatus::OK) + { + adios2::QueryWorker w = adios2::QueryWorker(queryFile, reader); + w.GetResultCoverage(touched_blockIDs); + + std::cout << " Num touched blocks =" << touched_blockIDs.size() << std::endl; + for (auto n : touched_blockIDs) + { + std::cout << "\t[" << n << "] " << std::endl; + } + + reader.EndStep(); + } + reader.Close(); +} void queryWithStreaming(adios2::IO &queryIO, std::string &dataFileName, std::string &queryFile) { @@ -24,7 +46,10 @@ void queryWithStreaming(adios2::IO &queryIO, std::string &dataFileName, std::str adios2::QueryWorker w = adios2::QueryWorker(queryFile, reader); w.GetResultCoverage(touched_blocks); - std::cout << " ... now can read out touched blocks ... size=" << touched_blocks.size() + std::cout << " Num touched regions =" + << touched_blocks.size() + // std::cout << " ... now can read out touched blocks ... size=" << + // touched_blocks.size() << std::endl; for (auto n : touched_blocks) { @@ -68,12 +93,6 @@ int main(int argc, char *argv[]) configFileName = argv[1]; dataFileName = argv[2]; - if (rank == 0) - { - std::cout << " using config file = " << configFileName << std::endl; - std::cout << " data file = " << dataFileName << std::endl; - } - adios2::ADIOS ad = adios2::ADIOS(configFileName, MPI_COMM_WORLD); adios2::IO queryIO = ad.DeclareIO("query"); @@ -83,8 +102,16 @@ int main(int argc, char *argv[]) { queryFile = argv[3]; } - std::cout << "Testing query file ..." << queryFile << std::endl; + if (rank == 0) + { + std::cout << " using config file = " << configFileName << std::endl; + std::cout << " data file = " << dataFileName << std::endl; + std::cout << " queryfile = " << queryFile << std::endl; + } + queryIDs(queryIO, dataFileName, queryFile); + + std::cout << "\n" << std::endl; queryWithStreaming(queryIO, dataFileName, queryFile); return 0; @@ -99,41 +126,3 @@ int main(int argc, char *argv[]) return 0; } - -bool testMe(std::string &queryConfigFile, std::string const &doubleVarName, MPI_Comm comm) -{ - adios2::ADIOS ad(queryConfigFile, comm); - std::string dataFileName = "test.file"; - - // adios2::query::Worker w(queryConfigFile, comm); - - // w.SetSource(inIO, reader); - - { - // the config file should have info on idx method to use - - /* - // if wanting to build customized minmax idx - // instead of using the existing block stats or bp4 minmax arrays - bool overwrite = false; - size_t recommendedSize = 20000; - - if (!w.PrepareIdx(overwrite, recommendedSize, doubleVarName)) - return false; - */ - } - - adios2::IO inIO = ad.DeclareIO("query"); - adios2::Engine reader = inIO.Open(dataFileName, adios2::Mode::Read, comm); - - // to be continued - if (!reader) - return false; - // std::vector dataOutput; - // std::vector coordinateOutput; - - return true; -} - -/* - */ diff --git a/source/adios2/toolkit/query/BlockIndex.h b/source/adios2/toolkit/query/BlockIndex.h index 94890de269..b3a52afcb0 100644 --- a/source/adios2/toolkit/query/BlockIndex.h +++ b/source/adios2/toolkit/query/BlockIndex.h @@ -12,15 +12,6 @@ namespace query template class BlockIndex { - struct Tree - { - // - // ** no need to keep the original block. might be smaller than - // blockIndex typename Variable::BPInfo& m_BlockInfo; - // - std::vector::BPInfo> m_SubBlockInfo; - }; - public: BlockIndex(adios2::core::Variable *var, adios2::core::IO &io, adios2::core::Engine &reader) @@ -30,15 +21,20 @@ class BlockIndex void Generate(std::string &fromBPFile, const adios2::Params &inputs) {} - void Evaluate(const QueryVar &query, std::vector> &resultSubBlocks) + void Evaluate(const QueryVar &query, std::vector &resultBlockIDs) { + if (nullptr == m_VarPtr) + { + throw std::runtime_error("Unable to evaluate query! Invalid Variable detected"); + } + if (m_IdxReader.m_EngineType.find("5") != std::string::npos) // a bp5 reader - RunBP5Stat(query, resultSubBlocks); + RunBP5Stat(query, resultBlockIDs); else - RunBP4Stat(query, resultSubBlocks); + RunBP4Stat(query, resultBlockIDs); } - void RunBP5Stat(const QueryVar &query, std::vector> &hitBlocks) + void RunBP5Stat(const QueryVar &query, std::vector &hitBlocks) { size_t currStep = m_IdxReader.CurrentStep(); adios2::Dims currShape = m_VarPtr->Shape(); @@ -52,29 +48,40 @@ class BlockIndex } for (auto &blockInfo : MinBlocksInfo->BlocksInfo) { - Dims ss(MinBlocksInfo->Dims); - Dims cc(MinBlocksInfo->Dims); - for (std::vector::size_type i = 0; i < ss.size(); i++) - { - ss[i] = blockInfo.Start[i]; - cc[i] = blockInfo.Count[i]; - } - if (!query.TouchSelection(ss, cc)) - continue; - T bmin = *(T *)&blockInfo.MinMax.MinUnion; T bmax = *(T *)&blockInfo.MinMax.MaxUnion; bool isHit = query.m_RangeTree.CheckInterval(bmin, bmax); - if (isHit) + + if (!isHit) + continue; + + if (m_VarPtr->m_ShapeID != adios2::ShapeID::LocalArray) { - adios2::Box box = {ss, cc}; - hitBlocks.push_back(box); + Dims ss(MinBlocksInfo->Dims); + Dims cc(MinBlocksInfo->Dims); + for (std::vector::size_type i = 0; i < ss.size(); i++) + { + ss[i] = blockInfo.Start[i]; + cc[i] = blockInfo.Count[i]; + } + if (!query.TouchSelection(ss, cc)) + continue; + + if (isHit) + { + adios2::Box box = {ss, cc}; + hitBlocks.push_back(BlockHit(blockInfo.BlockID, box)); + } + } + else + { // local array + hitBlocks.push_back(BlockHit(blockInfo.BlockID)); } } delete MinBlocksInfo; } - void RunBP4Stat(const QueryVar &query, std::vector> &hitBlocks) + void RunBP4Stat(const QueryVar &query, std::vector &hitBlocks) { size_t currStep = m_IdxReader.CurrentStep(); adios2::Dims currShape = m_VarPtr->Shape(); @@ -86,45 +93,66 @@ class BlockIndex for (auto &blockInfo : varBlocksInfo) { - if (!query.TouchSelection(blockInfo.Start, blockInfo.Count)) + bool isHit = query.m_RangeTree.CheckInterval(blockInfo.Min, blockInfo.Max); + if (!isHit) continue; - if (blockInfo.MinMaxs.size() > 0) + if (m_VarPtr->m_ShapeID == adios2::ShapeID::LocalArray) { - adios2::helper::CalculateSubblockInfo(blockInfo.Count, blockInfo.SubBlockInfo); - unsigned int numSubBlocks = static_cast(blockInfo.MinMaxs.size() / 2); - for (unsigned int i = 0; i < numSubBlocks; i++) + if (isHit) + hitBlocks.push_back(BlockHit(blockInfo.BlockID)); + } + else + { + // global array + if (!query.TouchSelection(blockInfo.Start, blockInfo.Count)) + continue; + + BlockHit tmp(blockInfo.BlockID); + if (blockInfo.MinMaxs.size() > 0) { - bool isHit = query.m_RangeTree.CheckInterval(blockInfo.MinMaxs[2 * i], - blockInfo.MinMaxs[2 * i + 1]); - if (isHit) + // Consolidate to whole block If all subblocks are hits, then return the whole + // block + bool allCovered = true; + + adios2::helper::CalculateSubblockInfo(blockInfo.Count, blockInfo.SubBlockInfo); + unsigned int numSubBlocks = + static_cast(blockInfo.MinMaxs.size() / 2); + for (unsigned int i = 0; i < numSubBlocks; i++) { - adios2::Box currSubBlock = - adios2::helper::GetSubBlock(blockInfo.Count, blockInfo.SubBlockInfo, i); - for (size_t d = 0; d < blockInfo.Count.size(); ++d) + bool isSubblockHit = query.m_RangeTree.CheckInterval( + blockInfo.MinMaxs[2 * i], blockInfo.MinMaxs[2 * i + 1]); + if (isSubblockHit) + { + adios2::Box currSubBlock = adios2::helper::GetSubBlock( + blockInfo.Count, blockInfo.SubBlockInfo, i); + for (size_t d = 0; d < blockInfo.Count.size(); ++d) + currSubBlock.first[d] += blockInfo.Start[d]; + + if (!query.TouchSelection(currSubBlock.first, currSubBlock.second)) + continue; + tmp.m_Regions.push_back(currSubBlock); + } + else { - currSubBlock.first[d] += blockInfo.Start[d]; + allCovered = false; } - if (!query.TouchSelection(currSubBlock.first, currSubBlock.second)) - continue; - hitBlocks.push_back(currSubBlock); + } // for num subblocks + + if (!allCovered) + { + hitBlocks.push_back(tmp); + continue; } } - } - else - { // default - bool isHit = query.m_RangeTree.CheckInterval(blockInfo.Min, blockInfo.Max); - if (isHit) - { - adios2::Box box = {blockInfo.Start, blockInfo.Count}; - hitBlocks.push_back(box); - } + + // no subblock info or (allCovered = true) + adios2::Box box = {blockInfo.Start, blockInfo.Count}; + hitBlocks.push_back(BlockHit(blockInfo.BlockID, box)); } } } - Tree m_Content; - // can not be unique_ptr as it changes with bp5 through steps // as BP5Deserializer::SetupForStep calls io.RemoveVariables() // must use ptr as bp5 associates ptrs with blockinfo, see MinBlocksInfo() in bp5 diff --git a/source/adios2/toolkit/query/Query.cpp b/source/adios2/toolkit/query/Query.cpp index 6dc85b94c5..cca5c68481 100644 --- a/source/adios2/toolkit/query/Query.cpp +++ b/source/adios2/toolkit/query/Query.cpp @@ -53,6 +53,77 @@ adios2::Dims split(const std::string &s, char delim) return dim; } +BlockHit::BlockHit(size_t id) : m_ID(id) {} + +BlockHit::BlockHit(size_t id, Box &box) : m_ID(id) { m_Regions.push_back(box); } + +BlockHit::BlockHit(const BlockHit &cpy) +{ + m_ID = cpy.m_ID; + m_Regions = cpy.m_Regions; +} + +// +// return false if no intersection to apply +// e.g. different blockID, no overlapped subblocks +// return true if has intersection +// +// note that BlockHit comparison should match +// e.g. both are local/global arrays blocks +// +bool BlockHit::applyIntersection(const BlockHit &tmp) +{ + if (m_ID != tmp.m_ID) + return false; + + // local array, no subblock info + if (isLocalArrayBlock() || tmp.isLocalArrayBlock()) + return true; + + // check subblocks: + bool overlapped = false; + for (auto b : tmp.m_Regions) + { + for (auto it = m_Regions.begin(); it != m_Regions.end(); it++) + { + adios2::Box curr = QueryBase::GetIntersection(*it, b); + if (curr.first.size() != 0) // has intersection + { + overlapped = true; + *it = curr; + } + } + } + + return overlapped; +} + +// return true if can extended with tmp +// e.g. at least same blockID with tmp +bool BlockHit::applyExtension(const BlockHit &tmp) +{ + if (m_ID != tmp.m_ID) + return false; + + // check subblocks: + for (auto b : tmp.m_Regions) + { + bool duplicated = false; + for (auto box : m_Regions) + { + if (adios2::helper::IdenticalBoxes(box, b)) + { + duplicated = true; + continue; + } + } + if (!duplicated) + m_Regions.push_back(b); + } + + return true; +} + void QueryBase::ApplyOutputRegion(std::vector> &touchedBlocks, const adios2::Box &referenceRegion) { @@ -97,10 +168,11 @@ bool QueryComposite::AddNode(QueryBase *var) } void QueryComposite::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engine &reader, - std::vector> &touchedBlocks) + // std::vector> &touchedBlocks) + std::vector &touchedBlocks) { - auto lf_ApplyAND = [&](std::vector> &touched, - const std::vector> &curr) -> void { + auto lf_ApplyAND = [&](std::vector &touched, + const std::vector &curr) -> void { if (curr.size() == 0) { touched.clear(); @@ -112,35 +184,19 @@ void QueryComposite::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engi bool intersects = false; for (auto b : curr) { - adios2::Box curr = GetIntersection(touched[i - 1], b); - if (curr.first.size() != 0) // has intersection + if (touched[i].applyIntersection(b)) { intersects = true; break; } } if (!intersects) - // it = touched.erase(it); touched.erase(touched.begin() + i - 1); - // if (touched.end() == it) - // break; - } - - for (auto b : curr) - { - for (auto it = touched.begin(); it != touched.end(); it++) - { - adios2::Box curr = GetIntersection(*it, b); - if (curr.first.size() != 0) // has intersection - { - *it = curr; - } - } } }; // lf_ApplyAND - auto lf_ApplyOR = [&](std::vector> &touched, - const std::vector> &curr) -> void { + auto lf_ApplyOR = [&](std::vector &touched, + const std::vector &curr) -> void { if (curr.size() == 0) return; @@ -149,7 +205,7 @@ void QueryComposite::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engi bool duplicated = false; for (auto box : touched) { - if (adios2::helper::IdenticalBoxes(box, b)) + if (box.applyExtension(b)) { duplicated = true; continue; @@ -160,42 +216,6 @@ void QueryComposite::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engi } }; // lf_ApplyOR - /* - auto lf_ApplyRelation = [&](std::vector> &collection, - const Box &block) -> void { - if (adios2::query::Relation::AND == m_Relation) - { - for (auto it = touchedBlocks.begin(); it != touchedBlocks.end(); - it++) - { - adios2::Box curr = GetIntersection(*it, block); - // adios2::helper::IntersectionBox(*it, block); - if (curr.first.size() == 0) // no intersection - { - it = touchedBlocks.erase(it); - if (touchedBlocks.end() == it) - return; - } - else - *it = curr; - } - - return; - } - - if (adios2::query::Relation::OR == m_Relation) - { - for (auto box : touchedBlocks) - { - if (adios2::helper::IdenticalBoxes(box, block)) - return; - } - touchedBlocks.push_back(block); - return; - } - }; // local - */ - if (m_Nodes.size() == 0) return; @@ -203,7 +223,7 @@ void QueryComposite::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engi for (auto node : m_Nodes) { counter++; - std::vector> currBlocks; + std::vector currBlocks; node->BlockIndexEvaluate(io, reader, currBlocks); if (counter == 1) { @@ -227,9 +247,6 @@ void QueryComposite::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engi else if (adios2::query::Relation::OR == m_Relation) lf_ApplyOR(touchedBlocks, currBlocks); } - // plan to shift all var results to regions start at 0, and find out the - // overlapped regions boxes can be different size especially if they are - // from BP3 } bool QueryVar::IsSelectionValid(adios2::Dims &shape) const @@ -245,14 +262,6 @@ bool QueryVar::IsSelectionValid(adios2::Dims &shape) const return false; // different dimension } - /* - for (size_t i = 0; i < shape.size(); i++) - { - if ((m_Selection.first[i] > shape[i]) || - (m_Selection.second[i] > shape[i])) - return false; - } - */ return true; } @@ -298,13 +307,10 @@ bool QueryVar::TouchSelection(adios2::Dims &start, adios2::Dims &count) const } void QueryVar::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engine &reader, - std::vector> &touchedBlocks) + std::vector &touchedBlocks) { const DataType varType = io.InquireVariableType(m_VarName); - // Variable var = io.InquireVariable(m_VarName); - // BlockIndex idx(io, reader); - // var already exists when loading query. skipping validity checking #define declare_type(T) \ if (varType == adios2::helper::GetDataType()) \ @@ -320,7 +326,14 @@ void QueryVar::BlockIndexEvaluate(adios2::core::IO &io, adios2::core::Engine &re if (touchedBlocks.size() > 0) { LimitToSelection(touchedBlocks); - ApplyOutputRegion(touchedBlocks, m_Selection); + + for (auto blk : touchedBlocks) + { + if (!blk.isLocalArrayBlock()) + { + ApplyOutputRegion(blk.m_Regions, m_Selection); + } + } } } } // namespace query diff --git a/source/adios2/toolkit/query/Query.h b/source/adios2/toolkit/query/Query.h index f3bef1c34b..52bcca5983 100644 --- a/source/adios2/toolkit/query/Query.h +++ b/source/adios2/toolkit/query/Query.h @@ -93,6 +93,27 @@ class RangeTree std::vector m_SubNodes; }; // class RangeTree +struct BlockHit +{ + BlockHit(size_t id); + BlockHit(size_t id, Box &box); + BlockHit(const BlockHit &cpy); + + size_t m_ID; + + // if no sublocks, m_Regions is start/count of block (if global array). size=1 + // with subblocks, + // if global array, m_Regions has all the touched sub blocks with (abs) start count + // if local array, because client needs to read whole block, subblocks is ignored + // size=0 + // items in this vector are assumed to have no intersection. + std::vector> m_Regions; + + bool isLocalArrayBlock() const { return (0 == m_Regions.size()); } + bool applyIntersection(const BlockHit &tmp); + bool applyExtension(const BlockHit &tmp); +}; + class QueryBase { public: @@ -100,9 +121,10 @@ class QueryBase virtual bool IsCompatible(const adios2::Box &box) = 0; virtual void Print() = 0; virtual void BlockIndexEvaluate(adios2::core::IO &, adios2::core::Engine &, - std::vector> &touchedBlocks) = 0; + // std::vector> &touchedBlocks) = 0; + std::vector &touchedBlocks) = 0; - Box GetIntersection(const Box &box1, const Box &box2) noexcept + static Box GetIntersection(const Box &box1, const Box &box2) noexcept { Box b1 = adios2::helper::StartEndBox(box1.first, box1.second); Box b2 = adios2::helper::StartEndBox(box2.first, box2.second); @@ -140,7 +162,9 @@ class QueryVar : public QueryBase std::string &GetVarName() { return m_VarName; } void BlockIndexEvaluate(adios2::core::IO &, adios2::core::Engine &, - std::vector> &touchedBlocks); + std::vector &touchedBlocks); + // std::vector> &touchedBlocks); + void BroadcastOutputRegion(const adios2::Box ®ion) { m_OutputRegion = region; } void Print() { m_RangeTree.Print(); } @@ -183,6 +207,32 @@ class QueryVar : public QueryBase } } + // only applies to global arrays + void LimitToSelection(std::vector &blockHits) + { + for (auto i = blockHits.size(); i >= 1; i--) + { + if (blockHits[i - 1].isLocalArrayBlock()) + return; + + bool keepBlk = false; + for (auto it = blockHits[i - 1].m_Regions.begin(); + it != blockHits[i - 1].m_Regions.end(); it++) + { + Box overlap = GetIntersection(m_Selection, *it); + if (overlap.first.size() != 0) + { + keepBlk = true; + it->first = overlap.first; + it->second = overlap.second; + } + } + + if (!keepBlk) + blockHits.erase(blockHits.begin() + i - 1); + } + } + RangeTree m_RangeTree; adios2::Box m_Selection; @@ -212,7 +262,8 @@ class QueryComposite : public QueryBase } void BlockIndexEvaluate(adios2::core::IO &, adios2::core::Engine &, - std::vector> &touchedBlocks); + std::vector &touchedBlocks); + // std::vector> &touchedBlocks); bool AddNode(QueryBase *v); diff --git a/source/adios2/toolkit/query/Worker.cpp b/source/adios2/toolkit/query/Worker.cpp index 9609e8277a..e1a8ab02c2 100644 --- a/source/adios2/toolkit/query/Worker.cpp +++ b/source/adios2/toolkit/query/Worker.cpp @@ -82,6 +82,20 @@ QueryVar *Worker::GetBasicVarQuery(adios2::core::IO ¤tIO, const std::strin return nullptr; } +void Worker::GetResultCoverage(std::vector &touchedBlockIDs) +{ + touchedBlockIDs.clear(); + + std::vector blockHits; + if (m_Query && m_SourceReader) + { + m_Query->BlockIndexEvaluate(m_SourceReader->m_IO, *m_SourceReader, blockHits); + } + + for (auto blk : blockHits) + touchedBlockIDs.push_back(blk.m_ID); +} + void Worker::GetResultCoverage(const adios2::Box &outputRegion, std::vector> &touchedBlocks) { @@ -95,7 +109,11 @@ void Worker::GetResultCoverage(const adios2::Box &outputRegion, if (m_Query && m_SourceReader) { - m_Query->BlockIndexEvaluate(m_SourceReader->m_IO, *m_SourceReader, touchedBlocks); + std::vector blockHits; + m_Query->BlockIndexEvaluate(m_SourceReader->m_IO, *m_SourceReader, blockHits); + + for (auto blk : blockHits) + touchedBlocks.insert(touchedBlocks.end(), blk.m_Regions.begin(), blk.m_Regions.end()); } } } // namespace query diff --git a/source/adios2/toolkit/query/Worker.h b/source/adios2/toolkit/query/Worker.h index d95042a356..09cee08f7b 100644 --- a/source/adios2/toolkit/query/Worker.h +++ b/source/adios2/toolkit/query/Worker.h @@ -42,6 +42,7 @@ class Worker adios2::core::Engine *GetSourceReader() { return m_SourceReader; } + void GetResultCoverage(std::vector &); void GetResultCoverage(const adios2::Box &, std::vector> &); protected: diff --git a/testing/adios2/bindings/python/CMakeLists.txt b/testing/adios2/bindings/python/CMakeLists.txt index dd3c292a75..7d4b8d4104 100644 --- a/testing/adios2/bindings/python/CMakeLists.txt +++ b/testing/adios2/bindings/python/CMakeLists.txt @@ -25,7 +25,8 @@ if(ADIOS2_HAVE_MPI) add_python_mpi_test(BPBlocksInfo) add_python_mpi_test(BPChangingShapeHighLevelAPI) add_python_mpi_test(NullEngine) - add_python_mpi_test(Query) + add_python_mpi_test(Query) + add_python_mpi_test(QueryLocalArray) # Currently hangs in H5Fclose for unknown reasons #if(ADIOS2_HAVE_HDF5) # add_python_mpi_test(BPWriteTypesHighLevelAPI_HDF5) diff --git a/testing/adios2/bindings/python/TestQueryLocalArray.py b/testing/adios2/bindings/python/TestQueryLocalArray.py new file mode 100644 index 0000000000..8025d540d7 --- /dev/null +++ b/testing/adios2/bindings/python/TestQueryLocalArray.py @@ -0,0 +1,140 @@ +# +from mpi4py import MPI +import numpy as np +import adios2 +import sys + +# MPI +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + +# ####################################### +# # usage: [bp4 | bp5=default] ## +# ####################################### +numSteps = 5 +queryFile = 'query.xml' +targetVarName = 'var0' + +# User data +myArray = np.array([0, 1., 2., 3., 4., 5., 6., 7., 8., 9.]) +Nx = myArray.size + +# ADIOS MPI Communicator +adios = adios2.ADIOS(comm) + +supportedEngines = ['bp5', 'bp4'] +engineType = 'bp5' +if (len(sys.argv) > 1): + engineType = sys.argv[1].lower() + +if (engineType in supportedEngines): + if (rank == 0): + print('Using engine type:', engineType) +else: + sys.exit('specified engine does not exist') + + +dataFileName = 'test_' + engineType + '.bp' + + +def writeDataFile(): + bpIO = adios.DeclareIO("Writer") + bpIO.SetEngine(engineType) + + ioArray = bpIO.DefineVariable(targetVarName, myArray, [], [], [Nx], False) + + bpIO.SetParameter("statsblocksize", "3") + + bpFileWriter = bpIO.Open(dataFileName, adios2.Mode.Write) + + for i in range(numSteps): + bpFileWriter.BeginStep() + bpFileWriter.Put(ioArray, i * 10.0 + myArray / (rank + 1), + adios2.Mode.Sync) + bpFileWriter.EndStep() + + bpFileWriter.Close() + + +def createQueryFile(): + print(".. Writing query file to: ", queryFile) + + file1 = open(queryFile, 'w') + queryContent = [ + "\n", "\n", + " \n" + " \n", + " \n", + " \n", + " \n", " \n", + " \n", " \n", "\n" + ] + file1.writelines(queryContent) + file1.close() + + +def doAnalysis(reader, touched_blocks, varList): + print(" Step: ", reader.CurrentStep(), + " num touched blocks: ", len(touched_blocks)) + + values = [] + data = {} + + for var in varList: + data[var] = [] + + if (len(touched_blocks) > 0): + for n in touched_blocks: + for var in varList: + values = np.zeros(10, dtype=np.double) + var.SetBlockSelection(n) + reader.Get(var, values, adios2.Mode.Sync) + data[var].extend(values) + + +def queryDataFile(): + # # use no mpi + adios_nompi = adios2.ADIOS() + queryIO = adios_nompi.DeclareIO("query") + + reader = queryIO.Open(dataFileName, adios2.Mode.Read) + print("dataFile=", dataFileName, "queryFile=", queryFile) + touched_blocks = [] + + print("Num steps: ", reader.Steps()) + + while (reader.BeginStep() == adios2.StepStatus.OK): + # bp5 loads metadata after beginstep(), + # therefore query has to be called per step + w = adios2.Query(queryFile, reader) + # assume only rank 0 wants to process result + var = [queryIO.InquireVariable(targetVarName)] + + if (rank == 0): + touched_blocks = w.GetBlockIDs() + doAnalysis(reader, touched_blocks, var) + + reader.EndStep() + reader.Close() + + +def cleanUp(): + import os + import shutil + os.remove(queryFile) + shutil.rmtree(dataFileName) + print(" Cleanup generated files: ", queryFile, dataFileName) + +# +# actual setup: +# + + +writeDataFile() + + +if (0 == rank): + createQueryFile() + queryDataFile() + cleanUp() From 1e96b21700108028ed07e33a213c234f725844dc Mon Sep 17 00:00:00 2001 From: Junmin Gu Date: Sat, 23 Sep 2023 10:02:03 -0700 Subject: [PATCH 02/41] clang-format v16 --- bindings/Python/py11glue.cpp | 1095 ++++++++++++++++++---------------- 1 file changed, 567 insertions(+), 528 deletions(-) diff --git a/bindings/Python/py11glue.cpp b/bindings/Python/py11glue.cpp index 5e420bebff..44e28f1a98 100644 --- a/bindings/Python/py11glue.cpp +++ b/bindings/Python/py11glue.cpp @@ -31,47 +31,40 @@ #if ADIOS2_USE_MPI -namespace pybind11 -{ -namespace detail -{ -template <> -struct type_caster -{ +namespace pybind11 { +namespace detail { +template <> struct type_caster { public: - /** - * This macro establishes the name 'MPI4PY_Comm' in - * function signatures and declares a local variable - * 'value' of type MPI4PY_Comm - */ - PYBIND11_TYPE_CASTER(adios2::py11::MPI4PY_Comm, _("MPI4PY_Comm")); - - /** - * Conversion part 1 (Python->C++): convert a PyObject into a MPI4PY_Comm - * instance or return false upon failure. The second argument - * indicates whether implicit conversions should be applied. - */ - bool load(handle src, bool) - { - // Import mpi4py if it does not exist. - if (!PyMPIComm_Get) - { - if (import_mpi4py() < 0) - { - throw std::runtime_error("ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ - } - } - // If src is not actually a MPI4PY communicator, the next - // call returns nullptr, and we return false to indicate the conversion - // failed. - MPI_Comm *mpiCommPtr = PyMPIComm_Get(src.ptr()); - if (mpiCommPtr == nullptr) - { - return false; - } - value.comm = *mpiCommPtr; - return true; + /** + * This macro establishes the name 'MPI4PY_Comm' in + * function signatures and declares a local variable + * 'value' of type MPI4PY_Comm + */ + PYBIND11_TYPE_CASTER(adios2::py11::MPI4PY_Comm, _("MPI4PY_Comm")); + + /** + * Conversion part 1 (Python->C++): convert a PyObject into a MPI4PY_Comm + * instance or return false upon failure. The second argument + * indicates whether implicit conversions should be applied. + */ + bool load(handle src, bool) { + // Import mpi4py if it does not exist. + if (!PyMPIComm_Get) { + if (import_mpi4py() < 0) { + throw std::runtime_error( + "ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ + } } + // If src is not actually a MPI4PY communicator, the next + // call returns nullptr, and we return false to indicate the conversion + // failed. + MPI_Comm *mpiCommPtr = PyMPIComm_Get(src.ptr()); + if (mpiCommPtr == nullptr) { + return false; + } + value.comm = *mpiCommPtr; + return true; + } }; } // namespace detail } // namespace pybind11 @@ -81,75 +74,74 @@ struct type_caster #if ADIOS2_USE_MPI adios2::py11::File OpenMPI(const std::string &name, const std::string mode, - adios2::py11::MPI4PY_Comm comm, const std::string enginetype) -{ - return adios2::py11::File(name, mode, comm, enginetype); + adios2::py11::MPI4PY_Comm comm, + const std::string enginetype) { + return adios2::py11::File(name, mode, comm, enginetype); } -adios2::py11::File OpenConfigMPI(const std::string &name, const std::string mode, - adios2::py11::MPI4PY_Comm comm, const std::string &configfile, - const std::string ioinconfigfile) -{ - return adios2::py11::File(name, mode, comm, configfile, ioinconfigfile); +adios2::py11::File OpenConfigMPI(const std::string &name, + const std::string mode, + adios2::py11::MPI4PY_Comm comm, + const std::string &configfile, + const std::string ioinconfigfile) { + return adios2::py11::File(name, mode, comm, configfile, ioinconfigfile); } #endif adios2::py11::File Open(const std::string &name, const std::string mode, - const std::string enginetype) -{ - return adios2::py11::File(name, mode, enginetype); + const std::string enginetype) { + return adios2::py11::File(name, mode, enginetype); } adios2::py11::File OpenConfig(const std::string &name, const std::string mode, - const std::string configfile, const std::string ioinconfigfile) -{ - return adios2::py11::File(name, mode, configfile, ioinconfigfile); + const std::string configfile, + const std::string ioinconfigfile) { + return adios2::py11::File(name, mode, configfile, ioinconfigfile); } -PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) -{ - m.attr("ConstantDims") = true; - m.attr("VariableDims") = false; - m.attr("LocalValueDim") = adios2::LocalValueDim; - m.attr("GlobalValue") = false; - m.attr("LocalValue") = true; - - m.attr("__version__") = ADIOS2_VERSION_STR; - - // enum classes - pybind11::enum_(m, "Mode") - .value("Write", adios2::Mode::Write) - .value("Read", adios2::Mode::Read) - .value("ReadRandomAccess", adios2::Mode::ReadRandomAccess) - .value("Append", adios2::Mode::Append) - .value("Deferred", adios2::Mode::Deferred) - .value("Sync", adios2::Mode::Sync) - .export_values(); - - pybind11::enum_(m, "ShapeID") - .value("Unknown", adios2::ShapeID::Unknown) - .value("GlobalValue", adios2::ShapeID::GlobalValue) - .value("GlobalArray", adios2::ShapeID::GlobalArray) - .value("LocalValue", adios2::ShapeID::LocalValue) - .value("LocalArray", adios2::ShapeID::LocalArray) - .export_values(); - - pybind11::enum_(m, "StepMode") - .value("Append", adios2::StepMode::Append) - .value("Update", adios2::StepMode::Update) - .value("Read", adios2::StepMode::Read) - .export_values(); - - pybind11::enum_(m, "StepStatus") - .value("OK", adios2::StepStatus::OK) - .value("NotReady", adios2::StepStatus::NotReady) - .value("EndOfStream", adios2::StepStatus::EndOfStream) - .value("OtherError", adios2::StepStatus::OtherError) - .export_values(); +PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { + m.attr("ConstantDims") = true; + m.attr("VariableDims") = false; + m.attr("LocalValueDim") = adios2::LocalValueDim; + m.attr("GlobalValue") = false; + m.attr("LocalValue") = true; + + m.attr("__version__") = ADIOS2_VERSION_STR; + + // enum classes + pybind11::enum_(m, "Mode") + .value("Write", adios2::Mode::Write) + .value("Read", adios2::Mode::Read) + .value("ReadRandomAccess", adios2::Mode::ReadRandomAccess) + .value("Append", adios2::Mode::Append) + .value("Deferred", adios2::Mode::Deferred) + .value("Sync", adios2::Mode::Sync) + .export_values(); + + pybind11::enum_(m, "ShapeID") + .value("Unknown", adios2::ShapeID::Unknown) + .value("GlobalValue", adios2::ShapeID::GlobalValue) + .value("GlobalArray", adios2::ShapeID::GlobalArray) + .value("LocalValue", adios2::ShapeID::LocalValue) + .value("LocalArray", adios2::ShapeID::LocalArray) + .export_values(); + + pybind11::enum_(m, "StepMode") + .value("Append", adios2::StepMode::Append) + .value("Update", adios2::StepMode::Update) + .value("Read", adios2::StepMode::Read) + .export_values(); + + pybind11::enum_(m, "StepStatus") + .value("OK", adios2::StepStatus::OK) + .value("NotReady", adios2::StepStatus::NotReady) + .value("EndOfStream", adios2::StepStatus::EndOfStream) + .value("OtherError", adios2::StepStatus::OtherError) + .export_values(); #if ADIOS2_USE_MPI - m.def("open", &OpenMPI, pybind11::arg("name"), pybind11::arg("mode"), pybind11::arg("comm"), - pybind11::arg("engine_type") = "BPFile", R"md( + m.def("open", &OpenMPI, pybind11::arg("name"), pybind11::arg("mode"), + pybind11::arg("comm"), pybind11::arg("engine_type") = "BPFile", R"md( Simple API MPI open, based on python IO. Allows for passing parameters in source code. @@ -172,9 +164,10 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) handler to adios File for the simple Python API )md"); - m.def("open", &OpenConfigMPI, pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("comm"), pybind11::arg("config_file"), pybind11::arg("io_in_config_file"), - R"md( + m.def("open", &OpenConfigMPI, pybind11::arg("name"), pybind11::arg("mode"), + pybind11::arg("comm"), pybind11::arg("config_file"), + pybind11::arg("io_in_config_file"), + R"md( Simple API MPI open, based on python IO. Allows for passing a runtime configuration file in xml format and the name of the io element related to the returning File. @@ -202,328 +195,350 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md"); #endif - m.def("open", &Open, "High-level API, file object open", pybind11::arg("name"), - pybind11::arg("mode"), pybind11::arg("engine_type") = "BPFile"); - - m.def("open", &OpenConfig, "High-level API, file object open with a runtime config file", - pybind11::arg("name"), pybind11::arg("mode"), pybind11::arg("config_file"), - pybind11::arg("io_in_config_file")); - - pybind11::class_(m, "ADIOS") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::ADIOS &adios) { - const bool opBool = adios ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::ADIOS &adios) { - const bool opBool = adios ? true : false; - return opBool; - }) - .def(pybind11::init(), "adios2 module starting point " - "non-MPI, constructs an ADIOS class " - "object") - .def(pybind11::init(), - "adios2 module starting point non-MPI, constructs an ADIOS class " - "object", - pybind11::arg("configFile")) + m.def("open", &Open, "High-level API, file object open", + pybind11::arg("name"), pybind11::arg("mode"), + pybind11::arg("engine_type") = "BPFile"); + + m.def("open", &OpenConfig, + "High-level API, file object open with a runtime config file", + pybind11::arg("name"), pybind11::arg("mode"), + pybind11::arg("config_file"), pybind11::arg("io_in_config_file")); + + pybind11::class_(m, "ADIOS") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::ADIOS &adios) { + const bool opBool = adios ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::ADIOS &adios) { + const bool opBool = adios ? true : false; + return opBool; + }) + .def(pybind11::init(), "adios2 module starting point " + "non-MPI, constructs an ADIOS class " + "object") + .def(pybind11::init(), + "adios2 module starting point non-MPI, constructs an ADIOS class " + "object", + pybind11::arg("configFile")) #if ADIOS2_USE_MPI - .def(pybind11::init(), - "adios2 module starting point, constructs an ADIOS class object", - pybind11::arg("comm")) - .def(pybind11::init(), - "adios2 module starting point, constructs an ADIOS class object", - pybind11::arg("configFile"), pybind11::arg("comm")) + .def(pybind11::init(), + "adios2 module starting point, constructs an ADIOS class object", + pybind11::arg("comm")) + .def(pybind11::init(), + "adios2 module starting point, constructs an ADIOS class object", + pybind11::arg("configFile"), pybind11::arg("comm")) #endif - .def("DeclareIO", &adios2::py11::ADIOS::DeclareIO, - "spawn IO object component returning a IO object with a unique " - "name, throws an exception if IO with the same name is declared " - "twice") - .def("AtIO", &adios2::py11::ADIOS::AtIO, - "returns an IO object " - "previously defined IO object " - "with DeclareIO, throws " - "an exception if not found") - .def("DefineOperator", &adios2::py11::ADIOS::DefineOperator) - .def("InquireOperator", &adios2::py11::ADIOS::InquireOperator) - .def("FlushAll", &adios2::py11::ADIOS::FlushAll, - "flushes all engines in all spawned IO objects") - .def("RemoveIO", &adios2::py11::ADIOS::RemoveIO, - "DANGER ZONE: remove a particular IO by name, creates dangling " - "objects to parameters, variable, attributes, engines created " - "with removed IO") - .def("RemoveAllIOs", &adios2::py11::ADIOS::RemoveAllIOs, - "DANGER ZONE: remove all IOs in current ADIOS object, creates " - "dangling objects to parameters, variable, attributes, engines " - "created with removed IO"); - - pybind11::class_(m, "IO") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::IO &io) { - const bool opBool = io ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::IO &io) { - const bool opBool = io ? true : false; - return opBool; - }) - .def("SetEngine", &adios2::py11::IO::SetEngine) - .def("SetParameters", &adios2::py11::IO::SetParameters, - pybind11::arg("parameters") = adios2::Params()) - .def("SetParameter", &adios2::py11::IO::SetParameter) - .def("Parameters", &adios2::py11::IO::Parameters) - .def("AddTransport", &adios2::py11::IO::AddTransport, pybind11::arg("type"), - pybind11::arg("parameters") = adios2::Params()) - - .def("DefineVariable", - (adios2::py11::Variable(adios2::py11::IO::*)( - const std::string &, const pybind11::array &, const adios2::Dims &, - const adios2::Dims &, const adios2::Dims &, const bool)) & - adios2::py11::IO::DefineVariable, - pybind11::return_value_policy::move, pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("shape") = adios2::Dims(), pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), pybind11::arg("isConstantDims") = false) - - .def("DefineVariable", - (adios2::py11::Variable(adios2::py11::IO::*)(const std::string &)) & - adios2::py11::IO::DefineVariable, - pybind11::return_value_policy::move, pybind11::arg("name")) - - .def("InquireVariable", &adios2::py11::IO::InquireVariable, - pybind11::return_value_policy::move) - - .def("InquireAttribute", &adios2::py11::IO::InquireAttribute, - pybind11::return_value_policy::move) - - .def("DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const pybind11::array &, const std::string &, - const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", pybind11::return_value_policy::move) - - .def( - "DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)(const std::string &, const std::string &, - const std::string &, const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("stringValue"), - pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) - - .def("DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const std::vector &, const std::string &, - const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("strings"), pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", pybind11::return_value_policy::move) - - .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)(const std::string &, const int)) & - adios2::py11::IO::Open) + .def("DeclareIO", &adios2::py11::ADIOS::DeclareIO, + "spawn IO object component returning a IO object with a unique " + "name, throws an exception if IO with the same name is declared " + "twice") + .def("AtIO", &adios2::py11::ADIOS::AtIO, + "returns an IO object " + "previously defined IO object " + "with DeclareIO, throws " + "an exception if not found") + .def("DefineOperator", &adios2::py11::ADIOS::DefineOperator) + .def("InquireOperator", &adios2::py11::ADIOS::InquireOperator) + .def("FlushAll", &adios2::py11::ADIOS::FlushAll, + "flushes all engines in all spawned IO objects") + .def("RemoveIO", &adios2::py11::ADIOS::RemoveIO, + "DANGER ZONE: remove a particular IO by name, creates dangling " + "objects to parameters, variable, attributes, engines created " + "with removed IO") + .def("RemoveAllIOs", &adios2::py11::ADIOS::RemoveAllIOs, + "DANGER ZONE: remove all IOs in current ADIOS object, creates " + "dangling objects to parameters, variable, attributes, engines " + "created with removed IO"); + + pybind11::class_(m, "IO") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::IO &io) { + const bool opBool = io ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::IO &io) { + const bool opBool = io ? true : false; + return opBool; + }) + .def("SetEngine", &adios2::py11::IO::SetEngine) + .def("SetParameters", &adios2::py11::IO::SetParameters, + pybind11::arg("parameters") = adios2::Params()) + .def("SetParameter", &adios2::py11::IO::SetParameter) + .def("Parameters", &adios2::py11::IO::Parameters) + .def("AddTransport", &adios2::py11::IO::AddTransport, + pybind11::arg("type"), + pybind11::arg("parameters") = adios2::Params()) + + .def("DefineVariable", + (adios2::py11::Variable(adios2::py11::IO::*)( + const std::string &, const pybind11::array &, + const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, + const bool)) & + adios2::py11::IO::DefineVariable, + pybind11::return_value_policy::move, pybind11::arg("name"), + pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), + pybind11::arg("start") = adios2::Dims(), + pybind11::arg("count") = adios2::Dims(), + pybind11::arg("isConstantDims") = false) + + .def("DefineVariable", + (adios2::py11::Variable(adios2::py11::IO::*)(const std::string &)) & + adios2::py11::IO::DefineVariable, + pybind11::return_value_policy::move, pybind11::arg("name")) + + .def("InquireVariable", &adios2::py11::IO::InquireVariable, + pybind11::return_value_policy::move) + + .def("InquireAttribute", &adios2::py11::IO::InquireAttribute, + pybind11::return_value_policy::move) + + .def("DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)( + const std::string &, const pybind11::array &, + const std::string &, const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", + pybind11::return_value_policy::move) + + .def("DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)( + const std::string &, const std::string &, const std::string &, + const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("stringValue"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", + pybind11::return_value_policy::move) + + .def("DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)( + const std::string &, const std::vector &, + const std::string &, const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("strings"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", + pybind11::return_value_policy::move) + + .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)( + const std::string &, const int)) & + adios2::py11::IO::Open) #if ADIOS2_USE_MPI - .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)(const std::string &, const int, - adios2::py11::MPI4PY_Comm comm)) & - adios2::py11::IO::Open) + .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)( + const std::string &, const int, + adios2::py11::MPI4PY_Comm comm)) & + adios2::py11::IO::Open) #endif - .def("AvailableVariables", &adios2::py11::IO::AvailableVariables) - .def("AvailableAttributes", &adios2::py11::IO::AvailableAttributes) - .def("FlushAll", &adios2::py11::IO::FlushAll) - .def("EngineType", &adios2::py11::IO::EngineType) - .def("RemoveVariable", &adios2::py11::IO::RemoveVariable) - .def("RemoveAllVariables", &adios2::py11::IO::RemoveAllVariables) - .def("RemoveAttribute", &adios2::py11::IO::RemoveAttribute) - .def("RemoveAllAttributes", &adios2::py11::IO::RemoveAllAttributes); - - pybind11::class_(m, "Query") - .def("__nonzero__", - [](const adios2::py11::Query &query) { - const bool opBool = query ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Query &query) { - const bool opBool = query ? true : false; - return opBool; - }) - .def(pybind11::init(), - "adios2 query construction, a xml query File and a read engine", - pybind11::arg("queryFile"), pybind11::arg("reader") = true) - - .def("GetResult", &adios2::py11::Query::GetResult) - - .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); - - pybind11::class_(m, "Variable") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Variable &variable) { - const bool opBool = variable ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Variable &variable) { - const bool opBool = variable ? true : false; - return opBool; - }) - .def("SetShape", &adios2::py11::Variable::SetShape) - .def("SetBlockSelection", &adios2::py11::Variable::SetBlockSelection) - .def("SetSelection", &adios2::py11::Variable::SetSelection) - .def("SetStepSelection", &adios2::py11::Variable::SetStepSelection) - .def("SelectionSize", &adios2::py11::Variable::SelectionSize) - .def("Name", &adios2::py11::Variable::Name) - .def("Type", &adios2::py11::Variable::Type) - .def("Sizeof", &adios2::py11::Variable::Sizeof) - .def("ShapeID", &adios2::py11::Variable::ShapeID) - .def("Shape", &adios2::py11::Variable::Shape, - pybind11::arg("step") = adios2::EngineCurrentStep) - .def("Start", &adios2::py11::Variable::Start) - .def("Count", &adios2::py11::Variable::Count) - .def("Steps", &adios2::py11::Variable::Steps) - .def("StepsStart", &adios2::py11::Variable::StepsStart) - .def("BlockID", &adios2::py11::Variable::BlockID) - .def("AddOperation", &adios2::py11::Variable::AddOperation) - .def("Operations", &adios2::py11::Variable::Operations); - - pybind11::class_(m, "Attribute") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Attribute &attribute) { - const bool opBool = attribute ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Attribute &attribute) { - const bool opBool = attribute ? true : false; - return opBool; - }) - .def("Name", &adios2::py11::Attribute::Name) - .def("Type", &adios2::py11::Attribute::Type) - .def("DataString", &adios2::py11::Attribute::DataString) - .def("Data", &adios2::py11::Attribute::Data); - - pybind11::class_(m, "Engine") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Engine &engine) { - const bool opBool = engine ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Engine &engine) { - const bool opBool = engine ? true : false; - return opBool; - }) - .def("BeginStep", - (adios2::StepStatus(adios2::py11::Engine::*)(const adios2::StepMode, const float)) & - adios2::py11::Engine::BeginStep, - pybind11::arg("mode"), pybind11::arg("timeoutSeconds") = -1.f, - pybind11::return_value_policy::move) - - .def("BeginStep", - (adios2::StepStatus(adios2::py11::Engine::*)()) & adios2::py11::Engine::BeginStep, - pybind11::return_value_policy::move) - - .def("Put", - (void (adios2::py11::Engine::*)(adios2::py11::Variable, const pybind11::array &, - const adios2::Mode launch)) & - adios2::py11::Engine::Put, - pybind11::arg("variable"), pybind11::arg("array"), - pybind11::arg("launch") = adios2::Mode::Deferred) - - .def("Put", (void (adios2::py11::Engine::*)(adios2::py11::Variable, const std::string &)) & - adios2::py11::Engine::Put) - - .def("PerformPuts", &adios2::py11::Engine::PerformPuts) - - .def("PerformDataWrite", &adios2::py11::Engine::PerformDataWrite) - - .def("Get", - (void (adios2::py11::Engine::*)(adios2::py11::Variable, pybind11::array &, - const adios2::Mode launch)) & - adios2::py11::Engine::Get, - pybind11::arg("variable"), pybind11::arg("array"), - pybind11::arg("launch") = adios2::Mode::Deferred) - - .def("Get", - (std::string(adios2::py11::Engine::*)(adios2::py11::Variable, - const adios2::Mode launch)) & - adios2::py11::Engine::Get, - pybind11::arg("variable"), pybind11::arg("launch") = adios2::Mode::Deferred) - - .def("PerformGets", &adios2::py11::Engine::PerformGets) - - .def("EndStep", &adios2::py11::Engine::EndStep) - - .def("Flush", &adios2::py11::Engine::Flush) - - .def("Close", &adios2::py11::Engine::Close, pybind11::arg("transportIndex") = -1) - - .def("CurrentStep", &adios2::py11::Engine::CurrentStep) - - .def("Name", &adios2::py11::Engine::Name) - - .def("Type", &adios2::py11::Engine::Type) - - .def("Steps", &adios2::py11::Engine::Steps) - - .def("LockWriterDefinitions", &adios2::py11::Engine::LockWriterDefinitions) - - .def("LockReaderSelections", &adios2::py11::Engine::LockReaderSelections) - - .def("BlocksInfo", &adios2::py11::Engine::BlocksInfo); - - pybind11::class_(m, "Operator") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Operator &op) { - const bool opBool = op ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Operator &op) { - const bool opBool = op ? true : false; - return opBool; - }) - .def("Type", &adios2::py11::Operator::Type) - .def("SetParameter", &adios2::py11::Operator::SetParameter) - .def("Parameters", &adios2::py11::Operator::Parameters); - - pybind11::class_(m, "File") - .def("__repr__", - [](const adios2::py11::File &stream) { - return ""; - }) - - // enter and exit are defined for the with-as operator in Python - .def("__enter__", [](const adios2::py11::File &stream) { return stream; }) - .def("__exit__", [](adios2::py11::File &stream, pybind11::args) { stream.Close(); }) - .def( - "__iter__", [](adios2::py11::File &stream) { return stream; }, - pybind11::keep_alive<0, 1>()) - .def("__next__", - [](adios2::py11::File &stream) { - if (!stream.GetStep()) - { - throw pybind11::stop_iteration(); - } - return stream; - }) - - .def("set_parameter", &adios2::py11::File::SetParameter, pybind11::arg("key"), - pybind11::arg("value"), R"md( + .def("AvailableVariables", &adios2::py11::IO::AvailableVariables) + .def("AvailableAttributes", &adios2::py11::IO::AvailableAttributes) + .def("FlushAll", &adios2::py11::IO::FlushAll) + .def("EngineType", &adios2::py11::IO::EngineType) + .def("RemoveVariable", &adios2::py11::IO::RemoveVariable) + .def("RemoveAllVariables", &adios2::py11::IO::RemoveAllVariables) + .def("RemoveAttribute", &adios2::py11::IO::RemoveAttribute) + .def("RemoveAllAttributes", &adios2::py11::IO::RemoveAllAttributes); + + pybind11::class_(m, "Query") + .def("__nonzero__", + [](const adios2::py11::Query &query) { + const bool opBool = query ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Query &query) { + const bool opBool = query ? true : false; + return opBool; + }) + .def(pybind11::init(), + "adios2 query construction, a xml query File and a read engine", + pybind11::arg("queryFile"), pybind11::arg("reader") = true) + + .def("GetResult", &adios2::py11::Query::GetResult) + + .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); + + pybind11::class_(m, "Variable") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Variable &variable) { + const bool opBool = variable ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Variable &variable) { + const bool opBool = variable ? true : false; + return opBool; + }) + .def("SetShape", &adios2::py11::Variable::SetShape) + .def("SetBlockSelection", &adios2::py11::Variable::SetBlockSelection) + .def("SetSelection", &adios2::py11::Variable::SetSelection) + .def("SetStepSelection", &adios2::py11::Variable::SetStepSelection) + .def("SelectionSize", &adios2::py11::Variable::SelectionSize) + .def("Name", &adios2::py11::Variable::Name) + .def("Type", &adios2::py11::Variable::Type) + .def("Sizeof", &adios2::py11::Variable::Sizeof) + .def("ShapeID", &adios2::py11::Variable::ShapeID) + .def("Shape", &adios2::py11::Variable::Shape, + pybind11::arg("step") = adios2::EngineCurrentStep) + .def("Start", &adios2::py11::Variable::Start) + .def("Count", &adios2::py11::Variable::Count) + .def("Steps", &adios2::py11::Variable::Steps) + .def("StepsStart", &adios2::py11::Variable::StepsStart) + .def("BlockID", &adios2::py11::Variable::BlockID) + .def("AddOperation", &adios2::py11::Variable::AddOperation) + .def("Operations", &adios2::py11::Variable::Operations); + + pybind11::class_(m, "Attribute") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Attribute &attribute) { + const bool opBool = attribute ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Attribute &attribute) { + const bool opBool = attribute ? true : false; + return opBool; + }) + .def("Name", &adios2::py11::Attribute::Name) + .def("Type", &adios2::py11::Attribute::Type) + .def("DataString", &adios2::py11::Attribute::DataString) + .def("Data", &adios2::py11::Attribute::Data); + + pybind11::class_(m, "Engine") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Engine &engine) { + const bool opBool = engine ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Engine &engine) { + const bool opBool = engine ? true : false; + return opBool; + }) + .def("BeginStep", + (adios2::StepStatus(adios2::py11::Engine::*)(const adios2::StepMode, + const float)) & + adios2::py11::Engine::BeginStep, + pybind11::arg("mode"), pybind11::arg("timeoutSeconds") = -1.f, + pybind11::return_value_policy::move) + + .def("BeginStep", + (adios2::StepStatus(adios2::py11::Engine::*)()) & + adios2::py11::Engine::BeginStep, + pybind11::return_value_policy::move) + + .def("Put", + (void(adios2::py11::Engine::*)(adios2::py11::Variable, + const pybind11::array &, + const adios2::Mode launch)) & + adios2::py11::Engine::Put, + pybind11::arg("variable"), pybind11::arg("array"), + pybind11::arg("launch") = adios2::Mode::Deferred) + + .def("Put", (void(adios2::py11::Engine::*)(adios2::py11::Variable, + const std::string &)) & + adios2::py11::Engine::Put) + + .def("PerformPuts", &adios2::py11::Engine::PerformPuts) + + .def("PerformDataWrite", &adios2::py11::Engine::PerformDataWrite) + + .def("Get", + (void(adios2::py11::Engine::*)(adios2::py11::Variable, + pybind11::array &, + const adios2::Mode launch)) & + adios2::py11::Engine::Get, + pybind11::arg("variable"), pybind11::arg("array"), + pybind11::arg("launch") = adios2::Mode::Deferred) + + .def("Get", + (std::string(adios2::py11::Engine::*)(adios2::py11::Variable, + const adios2::Mode launch)) & + adios2::py11::Engine::Get, + pybind11::arg("variable"), + pybind11::arg("launch") = adios2::Mode::Deferred) + + .def("PerformGets", &adios2::py11::Engine::PerformGets) + + .def("EndStep", &adios2::py11::Engine::EndStep) + + .def("Flush", &adios2::py11::Engine::Flush) + + .def("Close", &adios2::py11::Engine::Close, + pybind11::arg("transportIndex") = -1) + + .def("CurrentStep", &adios2::py11::Engine::CurrentStep) + + .def("Name", &adios2::py11::Engine::Name) + + .def("Type", &adios2::py11::Engine::Type) + + .def("Steps", &adios2::py11::Engine::Steps) + + .def("LockWriterDefinitions", + &adios2::py11::Engine::LockWriterDefinitions) + + .def("LockReaderSelections", &adios2::py11::Engine::LockReaderSelections) + + .def("BlocksInfo", &adios2::py11::Engine::BlocksInfo); + + pybind11::class_(m, "Operator") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Operator &op) { + const bool opBool = op ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Operator &op) { + const bool opBool = op ? true : false; + return opBool; + }) + .def("Type", &adios2::py11::Operator::Type) + .def("SetParameter", &adios2::py11::Operator::SetParameter) + .def("Parameters", &adios2::py11::Operator::Parameters); + + pybind11::class_(m, "File") + .def("__repr__", + [](const adios2::py11::File &stream) { + return ""; + }) + + // enter and exit are defined for the with-as operator in Python + .def("__enter__", [](const adios2::py11::File &stream) { return stream; }) + .def("__exit__", + [](adios2::py11::File &stream, pybind11::args) { stream.Close(); }) + .def( + "__iter__", [](adios2::py11::File &stream) { return stream; }, + pybind11::keep_alive<0, 1>()) + .def("__next__", + [](adios2::py11::File &stream) { + if (!stream.GetStep()) { + throw pybind11::stop_iteration(); + } + return stream; + }) + + .def("set_parameter", &adios2::py11::File::SetParameter, + pybind11::arg("key"), pybind11::arg("value"), R"md( Sets a single parameter. Overwrites value if key exists. Parameters @@ -534,8 +549,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) parameter value )md") - .def("set_parameters", &adios2::py11::File::SetParameters, pybind11::arg("parameters"), - R"md( + .def("set_parameters", &adios2::py11::File::SetParameters, + pybind11::arg("parameters"), + R"md( Sets parameters using a dictionary. Removes any previous parameter. @@ -547,9 +563,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) parameter value )md") - .def("add_transport", &adios2::py11::File::AddTransport, - pybind11::return_value_policy::move, pybind11::arg("type"), - pybind11::arg("parameters") = adios2::Params(), R"md( + .def("add_transport", &adios2::py11::File::AddTransport, + pybind11::return_value_policy::move, pybind11::arg("type"), + pybind11::arg("parameters") = adios2::Params(), R"md( Adds a transport and its parameters to current IO. Must be supported by current engine type. @@ -566,9 +582,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) handler to added transport )md") - .def("available_variables", &adios2::py11::File::AvailableVariables, - pybind11::return_value_policy::move, - pybind11::arg("keys") = std::vector(), R"md( + .def("available_variables", &adios2::py11::File::AvailableVariables, + pybind11::return_value_policy::move, + pybind11::arg("keys") = std::vector(), R"md( Returns a 2-level dictionary with variable information. Read mode only. @@ -587,8 +603,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) variable information dictionary )md") - .def("available_attributes", &adios2::py11::File::AvailableAttributes, - pybind11::return_value_policy::move, R"md( + .def("available_attributes", &adios2::py11::File::AvailableAttributes, + pybind11::return_value_policy::move, R"md( Returns a 2-level dictionary with attribute information. Read mode only. @@ -600,15 +616,18 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) attribute information dictionary )md") - .def("write", - (void (adios2::py11::File::*)(const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, - const adios2::Dims &, const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), - pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), - pybind11::arg("end_step") = false, - R"md( + .def("write", + (void(adios2::py11::File::*)( + const std::string &, const pybind11::array &, + const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, + const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("shape") = adios2::Dims(), + pybind11::arg("start") = adios2::Dims(), + pybind11::arg("count") = adios2::Dims(), + pybind11::arg("end_step") = false, + R"md( writes a self-describing array (numpy) variable Parameters @@ -634,15 +653,17 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) end current step, begin next step and flush (default = false). )md") - .def("write", - (void (adios2::py11::File::*)( - const std::string &, const pybind11::array &, const adios2::Dims &, - const adios2::Dims &, const adios2::Dims &, const adios2::vParams &, const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape"), - pybind11::arg("start"), pybind11::arg("count"), pybind11::arg("operations"), - pybind11::arg("end_step") = false, - R"md( + .def("write", + (void(adios2::py11::File::*)( + const std::string &, const pybind11::array &, + const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, + const adios2::vParams &, const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("shape"), pybind11::arg("start"), + pybind11::arg("count"), pybind11::arg("operations"), + pybind11::arg("end_step") = false, + R"md( writes a self-describing array (numpy) variable with operations e.g. compression: 'zfp', 'mgard', 'sz' @@ -669,12 +690,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) end current step, begin next step and flush (default = false). )md") - .def("write", - (void (adios2::py11::File::*)(const std::string &, const pybind11::array &, const bool, - const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("local_value") = false, - pybind11::arg("end_step") = false, R"md( + .def("write", + (void(adios2::py11::File::*)(const std::string &, + const pybind11::array &, const bool, + const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("local_value") = false, + pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable Parameters @@ -692,12 +715,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (default = false). )md") - .def("write", - (void (adios2::py11::File::*)(const std::string &, const std::string &, const bool, - const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("string"), pybind11::arg("local_value") = false, - pybind11::arg("end_step") = false, R"md( + .def( + "write", + (void(adios2::py11::File::*)(const std::string &, const std::string &, + const bool, const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("string"), + pybind11::arg("local_value") = false, + pybind11::arg("end_step") = false, R"md( writes a self-describing single value string variable Parameters @@ -715,12 +740,15 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (default = false). )md") - .def("write_attribute", - (void (adios2::py11::File::*)(const std::string &, const pybind11::array &, - const std::string &, const std::string, const bool)) & - adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, R"md( + .def("write_attribute", + (void(adios2::py11::File::*)( + const std::string &, const pybind11::array &, + const std::string &, const std::string, const bool)) & + adios2::py11::File::WriteAttribute, + pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, + R"md( writes a self-describing single value array (numpy) variable Parameters @@ -743,13 +771,15 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (default = false). )md") - .def("write_attribute", - (void (adios2::py11::File::*)(const std::string &, const std::string &, - const std::string &, const std::string, const bool)) & - adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("string_value"), - pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", - pybind11::arg("end_step") = false, R"md( + .def("write_attribute", + (void(adios2::py11::File::*)( + const std::string &, const std::string &, const std::string &, + const std::string, const bool)) & + adios2::py11::File::WriteAttribute, + pybind11::arg("name"), pybind11::arg("string_value"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, + R"md( writes a self-describing single value array (numpy) variable Parameters @@ -772,13 +802,15 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (default = false). )md") - .def("write_attribute", - (void (adios2::py11::File::*)(const std::string &, const std::vector &, - const std::string &, const std::string, const bool)) & - adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("string_array"), - pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", - pybind11::arg("end_step") = false, R"md( + .def("write_attribute", + (void(adios2::py11::File::*)( + const std::string &, const std::vector &, + const std::string &, const std::string, const bool)) & + adios2::py11::File::WriteAttribute, + pybind11::arg("name"), pybind11::arg("string_array"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, + R"md( writes a self-describing single value array (numpy) variable Parameters @@ -801,12 +833,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (default = false). )md") - .def("read_string", - (std::vector(adios2::py11::File::*)(const std::string &, const size_t)) & - adios2::py11::File::ReadString, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("block_id") = 0, - R"md( + .def("read_string", + (std::vector(adios2::py11::File::*)(const std::string &, + const size_t)) & + adios2::py11::File::ReadString, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("block_id") = 0, + R"md( Reads string value for current step (use for streaming mode step by step) @@ -826,14 +859,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") - .def("read_string", - (std::vector(adios2::py11::File::*)(const std::string &, const size_t, - const size_t, const size_t)) & - adios2::py11::File::ReadString, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("step_start"), pybind11::arg("step_count"), - pybind11::arg("block_id") = 0, - R"md( + .def("read_string", + (std::vector(adios2::py11::File::*)( + const std::string &, const size_t, const size_t, const size_t)) & + adios2::py11::File::ReadString, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("step_start"), pybind11::arg("step_count"), + pybind11::arg("block_id") = 0, + R"md( Reads string value for a certain step (random access mode) @@ -855,12 +888,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) data string values for a certain step range. )md") - .def("read", - (pybind11::array(adios2::py11::File::*)(const std::string &, const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("block_id") = 0, - R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)(const std::string &, + const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("block_id") = 0, + R"md( Reads entire variable for current step (streaming mode step by step) @@ -877,14 +911,16 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) Single values will have a shape={1} numpy array )md") - .def("read", - (pybind11::array(adios2::py11::File::*)(const std::string &, const adios2::Dims &, - const adios2::Dims &, const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), - pybind11::arg("block_id") = 0, - R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)( + const std::string &, const adios2::Dims &, const adios2::Dims &, + const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("start") = adios2::Dims(), + pybind11::arg("count") = adios2::Dims(), + pybind11::arg("block_id") = 0, + R"md( Reads a selection piece in dimension for current step (streaming mode step by step) @@ -909,14 +945,15 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) empty if exception is thrown )md") - .def("read", - (pybind11::array(adios2::py11::File::*)(const std::string &, const adios2::Dims &, - const adios2::Dims &, const size_t, - const size_t, const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("start"), pybind11::arg("count"), pybind11::arg("step_start"), - pybind11::arg("step_count"), pybind11::arg("block_id") = 0, R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)( + const std::string &, const adios2::Dims &, const adios2::Dims &, + const size_t, const size_t, const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("start"), pybind11::arg("count"), + pybind11::arg("step_start"), pybind11::arg("step_count"), + pybind11::arg("block_id") = 0, R"md( Random access read allowed to select steps, only valid with File Engines @@ -944,12 +981,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) resulting array from selection )md") - .def("read_attribute", - (pybind11::array(adios2::py11::File::*)(const std::string &, const std::string &, - const std::string)) & - adios2::py11::File::ReadAttribute, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", R"md( + .def("read_attribute", + (pybind11::array(adios2::py11::File::*)( + const std::string &, const std::string &, const std::string)) & + adios2::py11::File::ReadAttribute, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", R"md( Reads a numpy based attribute Parameters @@ -969,12 +1007,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) resulting array attribute data )md") - .def("read_attribute_string", - (std::vector(adios2::py11::File::*)( - const std::string &, const std::string &, const std::string)) & - adios2::py11::File::ReadAttributeString, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", R"md( + .def("read_attribute_string", + (std::vector(adios2::py11::File::*)( + const std::string &, const std::string &, const std::string)) & + adios2::py11::File::ReadAttributeString, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", R"md( Read a string attribute Parameters @@ -993,7 +1032,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) list resulting string list attribute data)md") - .def("end_step", &adios2::py11::File::EndStep, R"md( + .def("end_step", &adios2::py11::File::EndStep, R"md( Write mode: advances to the next step. Convenient when declaring variable attributes as advancing to the next step is not attached to any variable. @@ -1002,20 +1041,20 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) in file based engines) )md") - .def("close", &adios2::py11::File::Close, R"md( + .def("close", &adios2::py11::File::Close, R"md( Closes file, thus becoming unreachable. Not required if using open in a with-as statement. Required in all other cases per-open to avoid resource leaks. )md") - .def("current_step", &adios2::py11::File::CurrentStep, R"md( + .def("current_step", &adios2::py11::File::CurrentStep, R"md( Inspect current step when using for-in loops, read mode only Returns current step )md") - .def("steps", &adios2::py11::File::Steps, R"md( + .def("steps", &adios2::py11::File::Steps, R"md( Inspect available number of steps, for file engines, read mode only Returns From 70669028dce97b5b92380abfee7e0d5f1ea7fe59 Mon Sep 17 00:00:00 2001 From: Junmin Gu Date: Sat, 23 Sep 2023 10:20:48 -0700 Subject: [PATCH 03/41] older clang-format --- bindings/Python/py11glue.cpp | 1094 ++++++++++++++++------------------ 1 file changed, 527 insertions(+), 567 deletions(-) diff --git a/bindings/Python/py11glue.cpp b/bindings/Python/py11glue.cpp index 44e28f1a98..7118b9f896 100644 --- a/bindings/Python/py11glue.cpp +++ b/bindings/Python/py11glue.cpp @@ -31,40 +31,47 @@ #if ADIOS2_USE_MPI -namespace pybind11 { -namespace detail { -template <> struct type_caster { +namespace pybind11 +{ +namespace detail +{ +template <> +struct type_caster +{ public: - /** - * This macro establishes the name 'MPI4PY_Comm' in - * function signatures and declares a local variable - * 'value' of type MPI4PY_Comm - */ - PYBIND11_TYPE_CASTER(adios2::py11::MPI4PY_Comm, _("MPI4PY_Comm")); - - /** - * Conversion part 1 (Python->C++): convert a PyObject into a MPI4PY_Comm - * instance or return false upon failure. The second argument - * indicates whether implicit conversions should be applied. - */ - bool load(handle src, bool) { - // Import mpi4py if it does not exist. - if (!PyMPIComm_Get) { - if (import_mpi4py() < 0) { - throw std::runtime_error( - "ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ - } + /** + * This macro establishes the name 'MPI4PY_Comm' in + * function signatures and declares a local variable + * 'value' of type MPI4PY_Comm + */ + PYBIND11_TYPE_CASTER(adios2::py11::MPI4PY_Comm, _("MPI4PY_Comm")); + + /** + * Conversion part 1 (Python->C++): convert a PyObject into a MPI4PY_Comm + * instance or return false upon failure. The second argument + * indicates whether implicit conversions should be applied. + */ + bool load(handle src, bool) + { + // Import mpi4py if it does not exist. + if (!PyMPIComm_Get) + { + if (import_mpi4py() < 0) + { + throw std::runtime_error("ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ + } + } + // If src is not actually a MPI4PY communicator, the next + // call returns nullptr, and we return false to indicate the conversion + // failed. + MPI_Comm *mpiCommPtr = PyMPIComm_Get(src.ptr()); + if (mpiCommPtr == nullptr) + { + return false; + } + value.comm = *mpiCommPtr; + return true; } - // If src is not actually a MPI4PY communicator, the next - // call returns nullptr, and we return false to indicate the conversion - // failed. - MPI_Comm *mpiCommPtr = PyMPIComm_Get(src.ptr()); - if (mpiCommPtr == nullptr) { - return false; - } - value.comm = *mpiCommPtr; - return true; - } }; } // namespace detail } // namespace pybind11 @@ -74,74 +81,75 @@ template <> struct type_caster { #if ADIOS2_USE_MPI adios2::py11::File OpenMPI(const std::string &name, const std::string mode, - adios2::py11::MPI4PY_Comm comm, - const std::string enginetype) { - return adios2::py11::File(name, mode, comm, enginetype); + adios2::py11::MPI4PY_Comm comm, const std::string enginetype) +{ + return adios2::py11::File(name, mode, comm, enginetype); } -adios2::py11::File OpenConfigMPI(const std::string &name, - const std::string mode, - adios2::py11::MPI4PY_Comm comm, - const std::string &configfile, - const std::string ioinconfigfile) { - return adios2::py11::File(name, mode, comm, configfile, ioinconfigfile); +adios2::py11::File OpenConfigMPI(const std::string &name, const std::string mode, + adios2::py11::MPI4PY_Comm comm, const std::string &configfile, + const std::string ioinconfigfile) +{ + return adios2::py11::File(name, mode, comm, configfile, ioinconfigfile); } #endif adios2::py11::File Open(const std::string &name, const std::string mode, - const std::string enginetype) { - return adios2::py11::File(name, mode, enginetype); + const std::string enginetype) +{ + return adios2::py11::File(name, mode, enginetype); } adios2::py11::File OpenConfig(const std::string &name, const std::string mode, - const std::string configfile, - const std::string ioinconfigfile) { - return adios2::py11::File(name, mode, configfile, ioinconfigfile); + const std::string configfile, const std::string ioinconfigfile) +{ + return adios2::py11::File(name, mode, configfile, ioinconfigfile); } -PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { - m.attr("ConstantDims") = true; - m.attr("VariableDims") = false; - m.attr("LocalValueDim") = adios2::LocalValueDim; - m.attr("GlobalValue") = false; - m.attr("LocalValue") = true; - - m.attr("__version__") = ADIOS2_VERSION_STR; - - // enum classes - pybind11::enum_(m, "Mode") - .value("Write", adios2::Mode::Write) - .value("Read", adios2::Mode::Read) - .value("ReadRandomAccess", adios2::Mode::ReadRandomAccess) - .value("Append", adios2::Mode::Append) - .value("Deferred", adios2::Mode::Deferred) - .value("Sync", adios2::Mode::Sync) - .export_values(); - - pybind11::enum_(m, "ShapeID") - .value("Unknown", adios2::ShapeID::Unknown) - .value("GlobalValue", adios2::ShapeID::GlobalValue) - .value("GlobalArray", adios2::ShapeID::GlobalArray) - .value("LocalValue", adios2::ShapeID::LocalValue) - .value("LocalArray", adios2::ShapeID::LocalArray) - .export_values(); - - pybind11::enum_(m, "StepMode") - .value("Append", adios2::StepMode::Append) - .value("Update", adios2::StepMode::Update) - .value("Read", adios2::StepMode::Read) - .export_values(); - - pybind11::enum_(m, "StepStatus") - .value("OK", adios2::StepStatus::OK) - .value("NotReady", adios2::StepStatus::NotReady) - .value("EndOfStream", adios2::StepStatus::EndOfStream) - .value("OtherError", adios2::StepStatus::OtherError) - .export_values(); +PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) +{ + m.attr("ConstantDims") = true; + m.attr("VariableDims") = false; + m.attr("LocalValueDim") = adios2::LocalValueDim; + m.attr("GlobalValue") = false; + m.attr("LocalValue") = true; + + m.attr("__version__") = ADIOS2_VERSION_STR; + + // enum classes + pybind11::enum_(m, "Mode") + .value("Write", adios2::Mode::Write) + .value("Read", adios2::Mode::Read) + .value("ReadRandomAccess", adios2::Mode::ReadRandomAccess) + .value("Append", adios2::Mode::Append) + .value("Deferred", adios2::Mode::Deferred) + .value("Sync", adios2::Mode::Sync) + .export_values(); + + pybind11::enum_(m, "ShapeID") + .value("Unknown", adios2::ShapeID::Unknown) + .value("GlobalValue", adios2::ShapeID::GlobalValue) + .value("GlobalArray", adios2::ShapeID::GlobalArray) + .value("LocalValue", adios2::ShapeID::LocalValue) + .value("LocalArray", adios2::ShapeID::LocalArray) + .export_values(); + + pybind11::enum_(m, "StepMode") + .value("Append", adios2::StepMode::Append) + .value("Update", adios2::StepMode::Update) + .value("Read", adios2::StepMode::Read) + .export_values(); + + pybind11::enum_(m, "StepStatus") + .value("OK", adios2::StepStatus::OK) + .value("NotReady", adios2::StepStatus::NotReady) + .value("EndOfStream", adios2::StepStatus::EndOfStream) + .value("OtherError", adios2::StepStatus::OtherError) + .export_values(); #if ADIOS2_USE_MPI - m.def("open", &OpenMPI, pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("comm"), pybind11::arg("engine_type") = "BPFile", R"md( + m.def("open", &OpenMPI, pybind11::arg("name"), pybind11::arg("mode"), pybind11::arg("comm"), + pybind11::arg("engine_type") = "BPFile", R"md( Simple API MPI open, based on python IO. Allows for passing parameters in source code. @@ -164,10 +172,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { handler to adios File for the simple Python API )md"); - m.def("open", &OpenConfigMPI, pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("comm"), pybind11::arg("config_file"), - pybind11::arg("io_in_config_file"), - R"md( + m.def("open", &OpenConfigMPI, pybind11::arg("name"), pybind11::arg("mode"), + pybind11::arg("comm"), pybind11::arg("config_file"), pybind11::arg("io_in_config_file"), + R"md( Simple API MPI open, based on python IO. Allows for passing a runtime configuration file in xml format and the name of the io element related to the returning File. @@ -195,350 +202,327 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { )md"); #endif - m.def("open", &Open, "High-level API, file object open", - pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("engine_type") = "BPFile"); - - m.def("open", &OpenConfig, - "High-level API, file object open with a runtime config file", - pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("config_file"), pybind11::arg("io_in_config_file")); - - pybind11::class_(m, "ADIOS") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::ADIOS &adios) { - const bool opBool = adios ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::ADIOS &adios) { - const bool opBool = adios ? true : false; - return opBool; - }) - .def(pybind11::init(), "adios2 module starting point " - "non-MPI, constructs an ADIOS class " - "object") - .def(pybind11::init(), - "adios2 module starting point non-MPI, constructs an ADIOS class " - "object", - pybind11::arg("configFile")) + m.def("open", &Open, "High-level API, file object open", pybind11::arg("name"), + pybind11::arg("mode"), pybind11::arg("engine_type") = "BPFile"); + + m.def("open", &OpenConfig, "High-level API, file object open with a runtime config file", + pybind11::arg("name"), pybind11::arg("mode"), pybind11::arg("config_file"), + pybind11::arg("io_in_config_file")); + + pybind11::class_(m, "ADIOS") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::ADIOS &adios) { + const bool opBool = adios ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::ADIOS &adios) { + const bool opBool = adios ? true : false; + return opBool; + }) + .def(pybind11::init(), "adios2 module starting point " + "non-MPI, constructs an ADIOS class " + "object") + .def(pybind11::init(), + "adios2 module starting point non-MPI, constructs an ADIOS class " + "object", + pybind11::arg("configFile")) #if ADIOS2_USE_MPI - .def(pybind11::init(), - "adios2 module starting point, constructs an ADIOS class object", - pybind11::arg("comm")) - .def(pybind11::init(), - "adios2 module starting point, constructs an ADIOS class object", - pybind11::arg("configFile"), pybind11::arg("comm")) + .def(pybind11::init(), + "adios2 module starting point, constructs an ADIOS class object", + pybind11::arg("comm")) + .def(pybind11::init(), + "adios2 module starting point, constructs an ADIOS class object", + pybind11::arg("configFile"), pybind11::arg("comm")) #endif - .def("DeclareIO", &adios2::py11::ADIOS::DeclareIO, - "spawn IO object component returning a IO object with a unique " - "name, throws an exception if IO with the same name is declared " - "twice") - .def("AtIO", &adios2::py11::ADIOS::AtIO, - "returns an IO object " - "previously defined IO object " - "with DeclareIO, throws " - "an exception if not found") - .def("DefineOperator", &adios2::py11::ADIOS::DefineOperator) - .def("InquireOperator", &adios2::py11::ADIOS::InquireOperator) - .def("FlushAll", &adios2::py11::ADIOS::FlushAll, - "flushes all engines in all spawned IO objects") - .def("RemoveIO", &adios2::py11::ADIOS::RemoveIO, - "DANGER ZONE: remove a particular IO by name, creates dangling " - "objects to parameters, variable, attributes, engines created " - "with removed IO") - .def("RemoveAllIOs", &adios2::py11::ADIOS::RemoveAllIOs, - "DANGER ZONE: remove all IOs in current ADIOS object, creates " - "dangling objects to parameters, variable, attributes, engines " - "created with removed IO"); - - pybind11::class_(m, "IO") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::IO &io) { - const bool opBool = io ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::IO &io) { - const bool opBool = io ? true : false; - return opBool; - }) - .def("SetEngine", &adios2::py11::IO::SetEngine) - .def("SetParameters", &adios2::py11::IO::SetParameters, - pybind11::arg("parameters") = adios2::Params()) - .def("SetParameter", &adios2::py11::IO::SetParameter) - .def("Parameters", &adios2::py11::IO::Parameters) - .def("AddTransport", &adios2::py11::IO::AddTransport, - pybind11::arg("type"), - pybind11::arg("parameters") = adios2::Params()) - - .def("DefineVariable", - (adios2::py11::Variable(adios2::py11::IO::*)( - const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, - const bool)) & - adios2::py11::IO::DefineVariable, - pybind11::return_value_policy::move, pybind11::arg("name"), - pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), - pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), - pybind11::arg("isConstantDims") = false) - - .def("DefineVariable", - (adios2::py11::Variable(adios2::py11::IO::*)(const std::string &)) & - adios2::py11::IO::DefineVariable, - pybind11::return_value_policy::move, pybind11::arg("name")) - - .def("InquireVariable", &adios2::py11::IO::InquireVariable, - pybind11::return_value_policy::move) - - .def("InquireAttribute", &adios2::py11::IO::InquireAttribute, - pybind11::return_value_policy::move) - - .def("DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const pybind11::array &, - const std::string &, const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) - - .def("DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const std::string &, const std::string &, - const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("stringValue"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) - - .def("DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const std::vector &, - const std::string &, const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("strings"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) - - .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)( - const std::string &, const int)) & - adios2::py11::IO::Open) + .def("DeclareIO", &adios2::py11::ADIOS::DeclareIO, + "spawn IO object component returning a IO object with a unique " + "name, throws an exception if IO with the same name is declared " + "twice") + .def("AtIO", &adios2::py11::ADIOS::AtIO, + "returns an IO object " + "previously defined IO object " + "with DeclareIO, throws " + "an exception if not found") + .def("DefineOperator", &adios2::py11::ADIOS::DefineOperator) + .def("InquireOperator", &adios2::py11::ADIOS::InquireOperator) + .def("FlushAll", &adios2::py11::ADIOS::FlushAll, + "flushes all engines in all spawned IO objects") + .def("RemoveIO", &adios2::py11::ADIOS::RemoveIO, + "DANGER ZONE: remove a particular IO by name, creates dangling " + "objects to parameters, variable, attributes, engines created " + "with removed IO") + .def("RemoveAllIOs", &adios2::py11::ADIOS::RemoveAllIOs, + "DANGER ZONE: remove all IOs in current ADIOS object, creates " + "dangling objects to parameters, variable, attributes, engines " + "created with removed IO"); + + pybind11::class_(m, "IO") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::IO &io) { + const bool opBool = io ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::IO &io) { + const bool opBool = io ? true : false; + return opBool; + }) + .def("SetEngine", &adios2::py11::IO::SetEngine) + .def("SetParameters", &adios2::py11::IO::SetParameters, + pybind11::arg("parameters") = adios2::Params()) + .def("SetParameter", &adios2::py11::IO::SetParameter) + .def("Parameters", &adios2::py11::IO::Parameters) + .def("AddTransport", &adios2::py11::IO::AddTransport, pybind11::arg("type"), + pybind11::arg("parameters") = adios2::Params()) + + .def("DefineVariable", + (adios2::py11::Variable(adios2::py11::IO::*)( + const std::string &, const pybind11::array &, const adios2::Dims &, + const adios2::Dims &, const adios2::Dims &, const bool)) & + adios2::py11::IO::DefineVariable, + pybind11::return_value_policy::move, pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("shape") = adios2::Dims(), pybind11::arg("start") = adios2::Dims(), + pybind11::arg("count") = adios2::Dims(), pybind11::arg("isConstantDims") = false) + + .def("DefineVariable", + (adios2::py11::Variable(adios2::py11::IO::*)(const std::string &)) & + adios2::py11::IO::DefineVariable, + pybind11::return_value_policy::move, pybind11::arg("name")) + + .def("InquireVariable", &adios2::py11::IO::InquireVariable, + pybind11::return_value_policy::move) + + .def("InquireAttribute", &adios2::py11::IO::InquireAttribute, + pybind11::return_value_policy::move) + + .def("DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)( + const std::string &, const pybind11::array &, const std::string &, + const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::return_value_policy::move) + + .def( + "DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)(const std::string &, const std::string &, + const std::string &, const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("stringValue"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", + pybind11::return_value_policy::move) + + .def("DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)( + const std::string &, const std::vector &, const std::string &, + const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("strings"), pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::return_value_policy::move) + + .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)(const std::string &, const int)) & + adios2::py11::IO::Open) #if ADIOS2_USE_MPI - .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)( - const std::string &, const int, - adios2::py11::MPI4PY_Comm comm)) & - adios2::py11::IO::Open) + .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)(const std::string &, const int, + adios2::py11::MPI4PY_Comm comm)) & + adios2::py11::IO::Open) #endif - .def("AvailableVariables", &adios2::py11::IO::AvailableVariables) - .def("AvailableAttributes", &adios2::py11::IO::AvailableAttributes) - .def("FlushAll", &adios2::py11::IO::FlushAll) - .def("EngineType", &adios2::py11::IO::EngineType) - .def("RemoveVariable", &adios2::py11::IO::RemoveVariable) - .def("RemoveAllVariables", &adios2::py11::IO::RemoveAllVariables) - .def("RemoveAttribute", &adios2::py11::IO::RemoveAttribute) - .def("RemoveAllAttributes", &adios2::py11::IO::RemoveAllAttributes); - - pybind11::class_(m, "Query") - .def("__nonzero__", - [](const adios2::py11::Query &query) { - const bool opBool = query ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Query &query) { - const bool opBool = query ? true : false; - return opBool; - }) - .def(pybind11::init(), - "adios2 query construction, a xml query File and a read engine", - pybind11::arg("queryFile"), pybind11::arg("reader") = true) - - .def("GetResult", &adios2::py11::Query::GetResult) - - .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); - - pybind11::class_(m, "Variable") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Variable &variable) { - const bool opBool = variable ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Variable &variable) { - const bool opBool = variable ? true : false; - return opBool; - }) - .def("SetShape", &adios2::py11::Variable::SetShape) - .def("SetBlockSelection", &adios2::py11::Variable::SetBlockSelection) - .def("SetSelection", &adios2::py11::Variable::SetSelection) - .def("SetStepSelection", &adios2::py11::Variable::SetStepSelection) - .def("SelectionSize", &adios2::py11::Variable::SelectionSize) - .def("Name", &adios2::py11::Variable::Name) - .def("Type", &adios2::py11::Variable::Type) - .def("Sizeof", &adios2::py11::Variable::Sizeof) - .def("ShapeID", &adios2::py11::Variable::ShapeID) - .def("Shape", &adios2::py11::Variable::Shape, - pybind11::arg("step") = adios2::EngineCurrentStep) - .def("Start", &adios2::py11::Variable::Start) - .def("Count", &adios2::py11::Variable::Count) - .def("Steps", &adios2::py11::Variable::Steps) - .def("StepsStart", &adios2::py11::Variable::StepsStart) - .def("BlockID", &adios2::py11::Variable::BlockID) - .def("AddOperation", &adios2::py11::Variable::AddOperation) - .def("Operations", &adios2::py11::Variable::Operations); - - pybind11::class_(m, "Attribute") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Attribute &attribute) { - const bool opBool = attribute ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Attribute &attribute) { - const bool opBool = attribute ? true : false; - return opBool; - }) - .def("Name", &adios2::py11::Attribute::Name) - .def("Type", &adios2::py11::Attribute::Type) - .def("DataString", &adios2::py11::Attribute::DataString) - .def("Data", &adios2::py11::Attribute::Data); - - pybind11::class_(m, "Engine") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Engine &engine) { - const bool opBool = engine ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Engine &engine) { - const bool opBool = engine ? true : false; - return opBool; - }) - .def("BeginStep", - (adios2::StepStatus(adios2::py11::Engine::*)(const adios2::StepMode, - const float)) & - adios2::py11::Engine::BeginStep, - pybind11::arg("mode"), pybind11::arg("timeoutSeconds") = -1.f, - pybind11::return_value_policy::move) - - .def("BeginStep", - (adios2::StepStatus(adios2::py11::Engine::*)()) & - adios2::py11::Engine::BeginStep, - pybind11::return_value_policy::move) - - .def("Put", - (void(adios2::py11::Engine::*)(adios2::py11::Variable, - const pybind11::array &, - const adios2::Mode launch)) & - adios2::py11::Engine::Put, - pybind11::arg("variable"), pybind11::arg("array"), - pybind11::arg("launch") = adios2::Mode::Deferred) - - .def("Put", (void(adios2::py11::Engine::*)(adios2::py11::Variable, - const std::string &)) & - adios2::py11::Engine::Put) - - .def("PerformPuts", &adios2::py11::Engine::PerformPuts) - - .def("PerformDataWrite", &adios2::py11::Engine::PerformDataWrite) - - .def("Get", - (void(adios2::py11::Engine::*)(adios2::py11::Variable, - pybind11::array &, - const adios2::Mode launch)) & - adios2::py11::Engine::Get, - pybind11::arg("variable"), pybind11::arg("array"), - pybind11::arg("launch") = adios2::Mode::Deferred) - - .def("Get", - (std::string(adios2::py11::Engine::*)(adios2::py11::Variable, - const adios2::Mode launch)) & - adios2::py11::Engine::Get, - pybind11::arg("variable"), - pybind11::arg("launch") = adios2::Mode::Deferred) - - .def("PerformGets", &adios2::py11::Engine::PerformGets) - - .def("EndStep", &adios2::py11::Engine::EndStep) - - .def("Flush", &adios2::py11::Engine::Flush) - - .def("Close", &adios2::py11::Engine::Close, - pybind11::arg("transportIndex") = -1) - - .def("CurrentStep", &adios2::py11::Engine::CurrentStep) - - .def("Name", &adios2::py11::Engine::Name) - - .def("Type", &adios2::py11::Engine::Type) - - .def("Steps", &adios2::py11::Engine::Steps) - - .def("LockWriterDefinitions", - &adios2::py11::Engine::LockWriterDefinitions) - - .def("LockReaderSelections", &adios2::py11::Engine::LockReaderSelections) - - .def("BlocksInfo", &adios2::py11::Engine::BlocksInfo); - - pybind11::class_(m, "Operator") - // Python 2 - .def("__nonzero__", - [](const adios2::py11::Operator &op) { - const bool opBool = op ? true : false; - return opBool; - }) - // Python 3 - .def("__bool__", - [](const adios2::py11::Operator &op) { - const bool opBool = op ? true : false; - return opBool; - }) - .def("Type", &adios2::py11::Operator::Type) - .def("SetParameter", &adios2::py11::Operator::SetParameter) - .def("Parameters", &adios2::py11::Operator::Parameters); - - pybind11::class_(m, "File") - .def("__repr__", - [](const adios2::py11::File &stream) { - return ""; - }) - - // enter and exit are defined for the with-as operator in Python - .def("__enter__", [](const adios2::py11::File &stream) { return stream; }) - .def("__exit__", - [](adios2::py11::File &stream, pybind11::args) { stream.Close(); }) - .def( - "__iter__", [](adios2::py11::File &stream) { return stream; }, - pybind11::keep_alive<0, 1>()) - .def("__next__", - [](adios2::py11::File &stream) { - if (!stream.GetStep()) { - throw pybind11::stop_iteration(); - } - return stream; - }) - - .def("set_parameter", &adios2::py11::File::SetParameter, - pybind11::arg("key"), pybind11::arg("value"), R"md( + .def("AvailableVariables", &adios2::py11::IO::AvailableVariables) + .def("AvailableAttributes", &adios2::py11::IO::AvailableAttributes) + .def("FlushAll", &adios2::py11::IO::FlushAll) + .def("EngineType", &adios2::py11::IO::EngineType) + .def("RemoveVariable", &adios2::py11::IO::RemoveVariable) + .def("RemoveAllVariables", &adios2::py11::IO::RemoveAllVariables) + .def("RemoveAttribute", &adios2::py11::IO::RemoveAttribute) + .def("RemoveAllAttributes", &adios2::py11::IO::RemoveAllAttributes); + + pybind11::class_(m, "Query") + .def("__nonzero__", + [](const adios2::py11::Query &query) { + const bool opBool = query ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Query &query) { + const bool opBool = query ? true : false; + return opBool; + }) + .def(pybind11::init(), + "adios2 query construction, a xml query File and a read engine", + pybind11::arg("queryFile"), pybind11::arg("reader") = true) + + .def("GetResult", &adios2::py11::Query::GetResult); + .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); + + pybind11::class_(m, "Variable") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Variable &variable) { + const bool opBool = variable ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Variable &variable) { + const bool opBool = variable ? true : false; + return opBool; + }) + .def("SetShape", &adios2::py11::Variable::SetShape) + .def("SetBlockSelection", &adios2::py11::Variable::SetBlockSelection) + .def("SetSelection", &adios2::py11::Variable::SetSelection) + .def("SetStepSelection", &adios2::py11::Variable::SetStepSelection) + .def("SelectionSize", &adios2::py11::Variable::SelectionSize) + .def("Name", &adios2::py11::Variable::Name) + .def("Type", &adios2::py11::Variable::Type) + .def("Sizeof", &adios2::py11::Variable::Sizeof) + .def("ShapeID", &adios2::py11::Variable::ShapeID) + .def("Shape", &adios2::py11::Variable::Shape, + pybind11::arg("step") = adios2::EngineCurrentStep) + .def("Start", &adios2::py11::Variable::Start) + .def("Count", &adios2::py11::Variable::Count) + .def("Steps", &adios2::py11::Variable::Steps) + .def("StepsStart", &adios2::py11::Variable::StepsStart) + .def("BlockID", &adios2::py11::Variable::BlockID) + .def("AddOperation", &adios2::py11::Variable::AddOperation) + .def("Operations", &adios2::py11::Variable::Operations); + + pybind11::class_(m, "Attribute") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Attribute &attribute) { + const bool opBool = attribute ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Attribute &attribute) { + const bool opBool = attribute ? true : false; + return opBool; + }) + .def("Name", &adios2::py11::Attribute::Name) + .def("Type", &adios2::py11::Attribute::Type) + .def("DataString", &adios2::py11::Attribute::DataString) + .def("Data", &adios2::py11::Attribute::Data); + + pybind11::class_(m, "Engine") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Engine &engine) { + const bool opBool = engine ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Engine &engine) { + const bool opBool = engine ? true : false; + return opBool; + }) + .def("BeginStep", + (adios2::StepStatus(adios2::py11::Engine::*)(const adios2::StepMode, const float)) & + adios2::py11::Engine::BeginStep, + pybind11::arg("mode"), pybind11::arg("timeoutSeconds") = -1.f, + pybind11::return_value_policy::move) + + .def("BeginStep", + (adios2::StepStatus(adios2::py11::Engine::*)()) & adios2::py11::Engine::BeginStep, + pybind11::return_value_policy::move) + + .def("Put", + (void(adios2::py11::Engine::*)(adios2::py11::Variable, const pybind11::array &, + const adios2::Mode launch)) & + adios2::py11::Engine::Put, + pybind11::arg("variable"), pybind11::arg("array"), + pybind11::arg("launch") = adios2::Mode::Deferred) + + .def("Put", (void(adios2::py11::Engine::*)(adios2::py11::Variable, const std::string &)) & + adios2::py11::Engine::Put) + + .def("PerformPuts", &adios2::py11::Engine::PerformPuts) + + .def("PerformDataWrite", &adios2::py11::Engine::PerformDataWrite) + + .def("Get", + (void(adios2::py11::Engine::*)(adios2::py11::Variable, pybind11::array &, + const adios2::Mode launch)) & + adios2::py11::Engine::Get, + pybind11::arg("variable"), pybind11::arg("array"), + pybind11::arg("launch") = adios2::Mode::Deferred) + + .def("Get", + (std::string(adios2::py11::Engine::*)(adios2::py11::Variable, + const adios2::Mode launch)) & + adios2::py11::Engine::Get, + pybind11::arg("variable"), pybind11::arg("launch") = adios2::Mode::Deferred) + + .def("PerformGets", &adios2::py11::Engine::PerformGets) + + .def("EndStep", &adios2::py11::Engine::EndStep) + + .def("Flush", &adios2::py11::Engine::Flush) + + .def("Close", &adios2::py11::Engine::Close, pybind11::arg("transportIndex") = -1) + + .def("CurrentStep", &adios2::py11::Engine::CurrentStep) + + .def("Name", &adios2::py11::Engine::Name) + + .def("Type", &adios2::py11::Engine::Type) + + .def("Steps", &adios2::py11::Engine::Steps) + + .def("LockWriterDefinitions", &adios2::py11::Engine::LockWriterDefinitions) + + .def("LockReaderSelections", &adios2::py11::Engine::LockReaderSelections) + + .def("BlocksInfo", &adios2::py11::Engine::BlocksInfo); + + pybind11::class_(m, "Operator") + // Python 2 + .def("__nonzero__", + [](const adios2::py11::Operator &op) { + const bool opBool = op ? true : false; + return opBool; + }) + // Python 3 + .def("__bool__", + [](const adios2::py11::Operator &op) { + const bool opBool = op ? true : false; + return opBool; + }) + .def("Type", &adios2::py11::Operator::Type) + .def("SetParameter", &adios2::py11::Operator::SetParameter) + .def("Parameters", &adios2::py11::Operator::Parameters); + + pybind11::class_(m, "File") + .def("__repr__", + [](const adios2::py11::File &stream) { + return ""; + }) + + // enter and exit are defined for the with-as operator in Python + .def("__enter__", [](const adios2::py11::File &stream) { return stream; }) + .def("__exit__", [](adios2::py11::File &stream, pybind11::args) { stream.Close(); }) + .def( + "__iter__", [](adios2::py11::File &stream) { return stream; }, + pybind11::keep_alive<0, 1>()) + .def("__next__", + [](adios2::py11::File &stream) { + if (!stream.GetStep()) + { + throw pybind11::stop_iteration(); + } + return stream; + }) + + .def("set_parameter", &adios2::py11::File::SetParameter, pybind11::arg("key"), + pybind11::arg("value"), R"md( Sets a single parameter. Overwrites value if key exists. Parameters @@ -549,9 +533,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { parameter value )md") - .def("set_parameters", &adios2::py11::File::SetParameters, - pybind11::arg("parameters"), - R"md( + .def("set_parameters", &adios2::py11::File::SetParameters, pybind11::arg("parameters"), + R"md( Sets parameters using a dictionary. Removes any previous parameter. @@ -563,9 +546,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { parameter value )md") - .def("add_transport", &adios2::py11::File::AddTransport, - pybind11::return_value_policy::move, pybind11::arg("type"), - pybind11::arg("parameters") = adios2::Params(), R"md( + .def("add_transport", &adios2::py11::File::AddTransport, + pybind11::return_value_policy::move, pybind11::arg("type"), + pybind11::arg("parameters") = adios2::Params(), R"md( Adds a transport and its parameters to current IO. Must be supported by current engine type. @@ -582,9 +565,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { handler to added transport )md") - .def("available_variables", &adios2::py11::File::AvailableVariables, - pybind11::return_value_policy::move, - pybind11::arg("keys") = std::vector(), R"md( + .def("available_variables", &adios2::py11::File::AvailableVariables, + pybind11::return_value_policy::move, + pybind11::arg("keys") = std::vector(), R"md( Returns a 2-level dictionary with variable information. Read mode only. @@ -603,8 +586,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { variable information dictionary )md") - .def("available_attributes", &adios2::py11::File::AvailableAttributes, - pybind11::return_value_policy::move, R"md( + .def("available_attributes", &adios2::py11::File::AvailableAttributes, + pybind11::return_value_policy::move, R"md( Returns a 2-level dictionary with attribute information. Read mode only. @@ -616,18 +599,15 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { attribute information dictionary )md") - .def("write", - (void(adios2::py11::File::*)( - const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, - const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("shape") = adios2::Dims(), - pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), - pybind11::arg("end_step") = false, - R"md( + .def("write", + (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, + const adios2::Dims &, const adios2::Dims &, + const adios2::Dims &, const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), + pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), + pybind11::arg("end_step") = false, + R"md( writes a self-describing array (numpy) variable Parameters @@ -653,17 +633,15 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { end current step, begin next step and flush (default = false). )md") - .def("write", - (void(adios2::py11::File::*)( - const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, const adios2::Dims &, - const adios2::vParams &, const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("shape"), pybind11::arg("start"), - pybind11::arg("count"), pybind11::arg("operations"), - pybind11::arg("end_step") = false, - R"md( + .def("write", + (void(adios2::py11::File::*)( + const std::string &, const pybind11::array &, const adios2::Dims &, + const adios2::Dims &, const adios2::Dims &, const adios2::vParams &, const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape"), + pybind11::arg("start"), pybind11::arg("count"), pybind11::arg("operations"), + pybind11::arg("end_step") = false, + R"md( writes a self-describing array (numpy) variable with operations e.g. compression: 'zfp', 'mgard', 'sz' @@ -690,14 +668,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { end current step, begin next step and flush (default = false). )md") - .def("write", - (void(adios2::py11::File::*)(const std::string &, - const pybind11::array &, const bool, - const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("local_value") = false, - pybind11::arg("end_step") = false, R"md( + .def("write", + (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, const bool, + const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("local_value") = false, + pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable Parameters @@ -715,14 +691,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { (default = false). )md") - .def( - "write", - (void(adios2::py11::File::*)(const std::string &, const std::string &, - const bool, const bool)) & - adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("string"), - pybind11::arg("local_value") = false, - pybind11::arg("end_step") = false, R"md( + .def("write", + (void(adios2::py11::File::*)(const std::string &, const std::string &, const bool, + const bool)) & + adios2::py11::File::Write, + pybind11::arg("name"), pybind11::arg("string"), pybind11::arg("local_value") = false, + pybind11::arg("end_step") = false, R"md( writes a self-describing single value string variable Parameters @@ -740,15 +714,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { (default = false). )md") - .def("write_attribute", - (void(adios2::py11::File::*)( - const std::string &, const pybind11::array &, - const std::string &, const std::string, const bool)) & - adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, - R"md( + .def("write_attribute", + (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, + const std::string &, const std::string, const bool)) & + adios2::py11::File::WriteAttribute, + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable Parameters @@ -771,15 +742,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { (default = false). )md") - .def("write_attribute", - (void(adios2::py11::File::*)( - const std::string &, const std::string &, const std::string &, - const std::string, const bool)) & - adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("string_value"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, - R"md( + .def("write_attribute", + (void(adios2::py11::File::*)(const std::string &, const std::string &, + const std::string &, const std::string, const bool)) & + adios2::py11::File::WriteAttribute, + pybind11::arg("name"), pybind11::arg("string_value"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", + pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable Parameters @@ -802,15 +771,13 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { (default = false). )md") - .def("write_attribute", - (void(adios2::py11::File::*)( - const std::string &, const std::vector &, - const std::string &, const std::string, const bool)) & - adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("string_array"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, - R"md( + .def("write_attribute", + (void(adios2::py11::File::*)(const std::string &, const std::vector &, + const std::string &, const std::string, const bool)) & + adios2::py11::File::WriteAttribute, + pybind11::arg("name"), pybind11::arg("string_array"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", + pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable Parameters @@ -833,13 +800,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { (default = false). )md") - .def("read_string", - (std::vector(adios2::py11::File::*)(const std::string &, - const size_t)) & - adios2::py11::File::ReadString, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("block_id") = 0, - R"md( + .def("read_string", + (std::vector(adios2::py11::File::*)(const std::string &, const size_t)) & + adios2::py11::File::ReadString, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("block_id") = 0, + R"md( Reads string value for current step (use for streaming mode step by step) @@ -859,14 +825,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { )md") - .def("read_string", - (std::vector(adios2::py11::File::*)( - const std::string &, const size_t, const size_t, const size_t)) & - adios2::py11::File::ReadString, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("step_start"), pybind11::arg("step_count"), - pybind11::arg("block_id") = 0, - R"md( + .def("read_string", + (std::vector(adios2::py11::File::*)(const std::string &, const size_t, + const size_t, const size_t)) & + adios2::py11::File::ReadString, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("step_start"), pybind11::arg("step_count"), + pybind11::arg("block_id") = 0, + R"md( Reads string value for a certain step (random access mode) @@ -888,13 +854,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { data string values for a certain step range. )md") - .def("read", - (pybind11::array(adios2::py11::File::*)(const std::string &, - const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("block_id") = 0, - R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)(const std::string &, const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("block_id") = 0, + R"md( Reads entire variable for current step (streaming mode step by step) @@ -911,16 +876,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { Single values will have a shape={1} numpy array )md") - .def("read", - (pybind11::array(adios2::py11::File::*)( - const std::string &, const adios2::Dims &, const adios2::Dims &, - const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), - pybind11::arg("block_id") = 0, - R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)(const std::string &, const adios2::Dims &, + const adios2::Dims &, const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), + pybind11::arg("block_id") = 0, + R"md( Reads a selection piece in dimension for current step (streaming mode step by step) @@ -945,15 +908,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { empty if exception is thrown )md") - .def("read", - (pybind11::array(adios2::py11::File::*)( - const std::string &, const adios2::Dims &, const adios2::Dims &, - const size_t, const size_t, const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("start"), pybind11::arg("count"), - pybind11::arg("step_start"), pybind11::arg("step_count"), - pybind11::arg("block_id") = 0, R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)(const std::string &, const adios2::Dims &, + const adios2::Dims &, const size_t, + const size_t, const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("start"), pybind11::arg("count"), pybind11::arg("step_start"), + pybind11::arg("step_count"), pybind11::arg("block_id") = 0, R"md( Random access read allowed to select steps, only valid with File Engines @@ -981,13 +943,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { resulting array from selection )md") - .def("read_attribute", - (pybind11::array(adios2::py11::File::*)( - const std::string &, const std::string &, const std::string)) & - adios2::py11::File::ReadAttribute, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", R"md( + .def("read_attribute", + (pybind11::array(adios2::py11::File::*)(const std::string &, const std::string &, + const std::string)) & + adios2::py11::File::ReadAttribute, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", R"md( Reads a numpy based attribute Parameters @@ -1007,13 +968,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { resulting array attribute data )md") - .def("read_attribute_string", - (std::vector(adios2::py11::File::*)( - const std::string &, const std::string &, const std::string)) & - adios2::py11::File::ReadAttributeString, - pybind11::return_value_policy::take_ownership, pybind11::arg("name"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", R"md( + .def("read_attribute_string", + (std::vector(adios2::py11::File::*)( + const std::string &, const std::string &, const std::string)) & + adios2::py11::File::ReadAttributeString, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", R"md( Read a string attribute Parameters @@ -1032,7 +992,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { list resulting string list attribute data)md") - .def("end_step", &adios2::py11::File::EndStep, R"md( + .def("end_step", &adios2::py11::File::EndStep, R"md( Write mode: advances to the next step. Convenient when declaring variable attributes as advancing to the next step is not attached to any variable. @@ -1041,20 +1001,20 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) { in file based engines) )md") - .def("close", &adios2::py11::File::Close, R"md( + .def("close", &adios2::py11::File::Close, R"md( Closes file, thus becoming unreachable. Not required if using open in a with-as statement. Required in all other cases per-open to avoid resource leaks. )md") - .def("current_step", &adios2::py11::File::CurrentStep, R"md( + .def("current_step", &adios2::py11::File::CurrentStep, R"md( Inspect current step when using for-in loops, read mode only Returns current step )md") - .def("steps", &adios2::py11::File::Steps, R"md( + .def("steps", &adios2::py11::File::Steps, R"md( Inspect available number of steps, for file engines, read mode only Returns From 79528bd072ffda7149842ef8a46cfc5f7c1bcb75 Mon Sep 17 00:00:00 2001 From: Junmin Gu Date: Sat, 23 Sep 2023 10:24:16 -0700 Subject: [PATCH 04/41] removed extra ; --- bindings/Python/py11glue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/Python/py11glue.cpp b/bindings/Python/py11glue.cpp index 7118b9f896..128c52d941 100644 --- a/bindings/Python/py11glue.cpp +++ b/bindings/Python/py11glue.cpp @@ -357,7 +357,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) "adios2 query construction, a xml query File and a read engine", pybind11::arg("queryFile"), pybind11::arg("reader") = true) - .def("GetResult", &adios2::py11::Query::GetResult); + .def("GetResult", &adios2::py11::Query::GetResult) .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); pybind11::class_(m, "Variable") From 2149fe7d23743acadb7524cd8704a0735ca4503a Mon Sep 17 00:00:00 2001 From: Junmin Gu Date: Sat, 23 Sep 2023 17:13:52 -0700 Subject: [PATCH 05/41] modified test. it failed because I consolidate block when all subblocks are touched --- testing/adios2/performance/query/TestBPQuery.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/adios2/performance/query/TestBPQuery.cpp b/testing/adios2/performance/query/TestBPQuery.cpp index a3ff5ae4a2..6e0e918a10 100644 --- a/testing/adios2/performance/query/TestBPQuery.cpp +++ b/testing/adios2/performance/query/TestBPQuery.cpp @@ -31,10 +31,10 @@ void WriteXmlQuery1D(const std::string &queryFile, const std::string &ioName, file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; - file << " " << std::endl; + file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; - file << " " << std::endl; + file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; @@ -99,7 +99,7 @@ void BPQueryTest::QueryIntVar(const std::string &fname, adios2::ADIOS &adios, std::vector rr; if (engineName.compare("BP4") == 0) - rr = {9, 9, 9}; + rr = {2, 1, 1}; else rr = {1, 1, 1}; @@ -135,7 +135,7 @@ void BPQueryTest::QueryDoubleVar(const std::string &fname, adios2::ADIOS &adios, std::vector rr; //= {0,9,9}; if (engineName.compare("BP4") == 0) - rr = {0, 9, 9}; + rr = {0, 3, 1}; else rr = {0, 1, 1}; while (bpReader.BeginStep() == adios2::StepStatus::OK) From 2884f713d1376f6b1ee65584c8edb730c6229776 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Fri, 22 Sep 2023 14:52:26 -0400 Subject: [PATCH 06/41] Import tests from bp to staging common, implement memory selection in SST --- source/adios2/engine/sst/SstWriter.tcc | 56 +++++++-- .../bp/TestBPWriteMemorySelectionRead.cpp | 114 ++++++++++++++---- .../engine/staging-common/CMakeLists.txt | 5 + .../engine/staging-common/TestSupp.cmake | 12 ++ 4 files changed, 157 insertions(+), 30 deletions(-) diff --git a/source/adios2/engine/sst/SstWriter.tcc b/source/adios2/engine/sst/SstWriter.tcc index b2e850500f..237c902d8e 100644 --- a/source/adios2/engine/sst/SstWriter.tcc +++ b/source/adios2/engine/sst/SstWriter.tcc @@ -70,19 +70,61 @@ void SstWriter::PutSyncCommon(Variable &variable, const T *values) } else { - if (variable.m_Type == DataType::String) + if (!variable.m_MemoryCount.empty()) { - std::string &source = *(std::string *)values; - void *p = &(source[0]); + size_t ObjSize; + if (variable.m_Type == DataType::Struct) + { + ObjSize = variable.m_ElementSize; + } + else + { + ObjSize = helper::GetDataTypeSize(variable.m_Type); + } + + const bool sourceRowMajor = helper::IsRowMajor(m_IO.m_HostLanguage); + helper::DimsArray MemoryStart(variable.m_MemoryStart); + helper::DimsArray MemoryCount(variable.m_MemoryCount); + helper::DimsArray varCount(variable.m_Count); + + int DimCount = (int)variable.m_Count.size(); + helper::DimsArray ZeroDims(DimCount, (size_t)0); + // get a temporary span then fill with memselection now + format::BufferV::BufferPos bp5span(0, 0, 0); + m_BP5Serializer->Marshal((void *)&variable, variable.m_Name.c_str(), variable.m_Type, variable.m_ElementSize, DimCount, Shape, - Count, Start, &p, true, nullptr); + Count, Start, nullptr, false, &bp5span); + void *ptr = m_BP5Serializer->GetPtr(bp5span.bufferIdx, bp5span.posInBuffer); + + if (!sourceRowMajor) + { + std::reverse(MemoryStart.begin(), MemoryStart.end()); + std::reverse(MemoryCount.begin(), MemoryCount.end()); + std::reverse(varCount.begin(), varCount.end()); + } + helper::NdCopy((const char *)values, helper::CoreDims(ZeroDims), MemoryCount, + sourceRowMajor, false, (char *)ptr, MemoryStart, varCount, + sourceRowMajor, false, (int)ObjSize, helper::CoreDims(), + helper::CoreDims(), helper::CoreDims(), helper::CoreDims(), + false /* safemode */, variable.m_MemSpace); } else { - m_BP5Serializer->Marshal((void *)&variable, variable.m_Name.c_str(), - variable.m_Type, variable.m_ElementSize, DimCount, Shape, - Count, Start, values, true, nullptr); + if (variable.m_Type == DataType::String) + { + std::string &source = *(std::string *)values; + void *p = &(source[0]); + m_BP5Serializer->Marshal((void *)&variable, variable.m_Name.c_str(), + variable.m_Type, variable.m_ElementSize, DimCount, + Shape, Count, Start, &p, true, nullptr); + } + else + { + m_BP5Serializer->Marshal((void *)&variable, variable.m_Name.c_str(), + variable.m_Type, variable.m_ElementSize, DimCount, + Shape, Count, Start, values, true, nullptr); + } } } } diff --git a/testing/adios2/engine/bp/TestBPWriteMemorySelectionRead.cpp b/testing/adios2/engine/bp/TestBPWriteMemorySelectionRead.cpp index ea52b5753d..aa8d516b21 100644 --- a/testing/adios2/engine/bp/TestBPWriteMemorySelectionRead.cpp +++ b/testing/adios2/engine/bp/TestBPWriteMemorySelectionRead.cpp @@ -15,6 +15,8 @@ #include "../SmallTestData.h" std::string engineName; // comes from command line +bool DoWrite = true; +bool DoRead = true; namespace { @@ -166,9 +168,13 @@ void AssignStep3D(const size_t step, std::vector> &vector, } // end anonymous namespace +#if ADIOS2_USE_MPI +MPI_Comm testComm; +#endif + void BPSteps1D(const size_t ghostCells) { - const std::string fname("BPSteps1D_" + std::to_string(ghostCells) + ".bp"); + const std::string fname("BPSteps1D_" + std::to_string(ghostCells)); int mpiRank = 0, mpiSize = 1; // Number of rows @@ -178,15 +184,16 @@ void BPSteps1D(const size_t ghostCells) const size_t NSteps = 3; #if ADIOS2_USE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank); - MPI_Comm_size(MPI_COMM_WORLD, &mpiSize); + MPI_Comm_rank(testComm, &mpiRank); + MPI_Comm_size(testComm, &mpiSize); #endif #if ADIOS2_USE_MPI - adios2::ADIOS adios(MPI_COMM_WORLD); + adios2::ADIOS adios(testComm); #else adios2::ADIOS adios; #endif + if (DoWrite) { adios2::IO io = adios.DeclareIO("WriteIO"); @@ -195,6 +202,7 @@ void BPSteps1D(const size_t ghostCells) io.SetEngine(engineName); } + io.SetParameters("StatsLevel=1"); const adios2::Dims shape{static_cast(Nx * mpiSize)}; const adios2::Dims start{static_cast(Nx * mpiRank)}; const adios2::Dims count{Nx}; @@ -256,9 +264,10 @@ void BPSteps1D(const size_t ghostCells) bpWriter.Close(); } #if ADIOS2_USE_MPI - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(testComm); #endif // Reader + if (DoRead) { adios2::IO io = adios.DeclareIO("ReadIO"); @@ -377,7 +386,7 @@ void BPSteps1D(const size_t ghostCells) void BPSteps2D4x2(const size_t ghostCells) { - const std::string fname("BPSteps2D4x2_" + std::to_string(ghostCells) + ".bp"); + const std::string fname("BPSteps2D4x2_" + std::to_string(ghostCells)); int mpiRank = 0, mpiSize = 1; // Number of rows @@ -391,15 +400,16 @@ void BPSteps2D4x2(const size_t ghostCells) const size_t NSteps = 3; #if ADIOS2_USE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank); - MPI_Comm_size(MPI_COMM_WORLD, &mpiSize); + MPI_Comm_rank(testComm, &mpiRank); + MPI_Comm_size(testComm, &mpiSize); #endif #if ADIOS2_USE_MPI - adios2::ADIOS adios(MPI_COMM_WORLD); + adios2::ADIOS adios(testComm); #else adios2::ADIOS adios; #endif + if (DoWrite) { adios2::IO io = adios.DeclareIO("WriteIO"); @@ -470,9 +480,10 @@ void BPSteps2D4x2(const size_t ghostCells) bpWriter.Close(); } #if ADIOS2_USE_MPI - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(testComm); #endif // Reader + if (DoRead) { adios2::IO io = adios.DeclareIO("ReadIO"); @@ -601,7 +612,7 @@ void BPSteps2D4x2(const size_t ghostCells) void BPSteps3D8x2x4(const size_t ghostCells) { - const std::string fname("BPSteps3D8x2x4_" + std::to_string(ghostCells) + ".bp"); + const std::string fname("BPSteps3D8x2x4_" + std::to_string(ghostCells)); int mpiRank = 0, mpiSize = 1; // Number of rows @@ -617,15 +628,16 @@ void BPSteps3D8x2x4(const size_t ghostCells) const size_t NSteps = 3; #if ADIOS2_USE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank); - MPI_Comm_size(MPI_COMM_WORLD, &mpiSize); + MPI_Comm_rank(testComm, &mpiRank); + MPI_Comm_size(testComm, &mpiSize); #endif #if ADIOS2_USE_MPI - adios2::ADIOS adios(MPI_COMM_WORLD); + adios2::ADIOS adios(testComm); #else adios2::ADIOS adios; #endif + if (DoWrite) { adios2::IO io = adios.DeclareIO("WriteIO"); @@ -698,9 +710,10 @@ void BPSteps3D8x2x4(const size_t ghostCells) bpWriter.Close(); } #if ADIOS2_USE_MPI - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(testComm); #endif // Reader + if (DoRead) { adios2::IO io = adios.DeclareIO("ReadIO"); @@ -878,25 +891,80 @@ INSTANTIATE_TEST_SUITE_P(ghostCells, BPWriteMemSelReadVector, ::testing::Values( int main(int argc, char **argv) { + int result; + ::testing::InitGoogleTest(&argc, argv); + int bare_arg = 0; + + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-do_write") == 0) + { + DoWrite = true; + DoRead = false; + } + else if (strcmp(argv[i], "-do_read") == 0) + { + DoWrite = false; + DoRead = true; + } + else if (argv[i][0] == '-') + { + std::cerr << "Unknown argument: " << argv[i] << std::endl; + exit(1); + } + else + { + std::string fname; + std::string engineParams; + if (bare_arg == 0) + { + /* first arg without -- is engine */ + engineName = std::string(argv[1]); + bare_arg++; + } + else if (bare_arg == 1) + { + /* second arg without -- is filename */ + // fname = std::string(argv[1]); + bare_arg++; + } + else if (bare_arg == 2) + { + // engineParams = ParseEngineParams(argv[1]); + bare_arg++; + } + else + { + + throw std::invalid_argument("Unknown argument \"" + std::string(argv[1]) + "\""); + } + } + } + #if ADIOS2_USE_MPI int provided; + int thread_support_level = + (engineName == "SST" || engineName == "sst") ? MPI_THREAD_MULTIPLE : MPI_THREAD_SINGLE; // MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP - MPI_Init_thread(nullptr, nullptr, MPI_THREAD_MULTIPLE, &provided); -#endif + MPI_Init_thread(nullptr, nullptr, thread_support_level, &provided); - int result; - ::testing::InitGoogleTest(&argc, argv); + int key; + MPI_Comm_rank(MPI_COMM_WORLD, &key); - if (argc > 1) - { - engineName = std::string(argv[1]); - } + const unsigned int color = (DoRead & !DoWrite) ? 1 : 0; + + MPI_Comm_split(MPI_COMM_WORLD, color, key, &testComm); +#endif result = RUN_ALL_TESTS(); #if ADIOS2_USE_MPI +#ifdef CRAY_MPICH_VERSION + MPI_Barrier(MPI_COMM_WORLD); +#else MPI_Finalize(); +#endif #endif return result; diff --git a/testing/adios2/engine/staging-common/CMakeLists.txt b/testing/adios2/engine/staging-common/CMakeLists.txt index a5a3f09056..ee20d68b8c 100644 --- a/testing/adios2/engine/staging-common/CMakeLists.txt +++ b/testing/adios2/engine/staging-common/CMakeLists.txt @@ -149,8 +149,13 @@ set (ALL_SIMPLE_TESTS "") list (APPEND ALL_SIMPLE_TESTS ${SIMPLE_TESTS} ${SIMPLE_FORTRAN_TESTS} ${SIMPLE_MPI_TESTS} ${SIMPLE_ZFP_TESTS}) set (SST_SPECIFIC_TESTS "") +import_bp_test(WriteMemorySelectionRead 1 1) +list (APPEND SST_SPECIFIC_TESTS "WriteMemorySelectionRead.1x1") list (APPEND SST_SPECIFIC_TESTS "1x1.SstRUDP;1x1.LocalMultiblock;RoundRobinDistribution.1x1x3;AllToAllDistribution.1x1x3;OnDemandSingle.1x1") + if (ADIOS2_HAVE_MPI) + import_bp_test(WriteMemorySelectionRead 3 3) + list (APPEND SST_SPECIFIC_TESTS "WriteMemorySelectionRead.3x3") list (APPEND SST_SPECIFIC_TESTS "2x3.SstRUDP;2x1.LocalMultiblock;5x3.LocalMultiblock;") endif() diff --git a/testing/adios2/engine/staging-common/TestSupp.cmake b/testing/adios2/engine/staging-common/TestSupp.cmake index 13ce1765a4..ca63109a77 100644 --- a/testing/adios2/engine/staging-common/TestSupp.cmake +++ b/testing/adios2/engine/staging-common/TestSupp.cmake @@ -323,3 +323,15 @@ function(from_hex HEX DEC) set(${DEC} ${_res} PARENT_SCOPE) endfunction() +function(import_bp_test BASENAME WRITE_SCALE READ_SCALE) + set (WRITER_POSTFIX "Serial") + set (READER_POSTFIX "Serial") + if (${WRITE_SCALE} GREATER 1) + set (WRITER_POSTFIX "MPI") + endif() + if (${READ_SCALE} GREATER 1) + set (READER_POSTFIX "MPI") + endif() + set (${BASENAME}.${WRITE_SCALE}x${READ_SCALE}_CMD "run_test.py.$ -nw ${WRITE_SCALE} -nr ${READ_SCALE} --warg=-do_write --rarg=-do_read -w $ -r $" PARENT_SCOPE) + +endfunction() From 51f7b6f2f390d8044b8d4383344198e313fd1f53 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Tue, 26 Sep 2023 16:22:32 -0400 Subject: [PATCH 07/41] Try always using the MPI version --- testing/adios2/engine/staging-common/TestSupp.cmake | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/testing/adios2/engine/staging-common/TestSupp.cmake b/testing/adios2/engine/staging-common/TestSupp.cmake index ca63109a77..7106ae5184 100644 --- a/testing/adios2/engine/staging-common/TestSupp.cmake +++ b/testing/adios2/engine/staging-common/TestSupp.cmake @@ -326,12 +326,6 @@ endfunction() function(import_bp_test BASENAME WRITE_SCALE READ_SCALE) set (WRITER_POSTFIX "Serial") set (READER_POSTFIX "Serial") - if (${WRITE_SCALE} GREATER 1) - set (WRITER_POSTFIX "MPI") - endif() - if (${READ_SCALE} GREATER 1) - set (READER_POSTFIX "MPI") - endif() - set (${BASENAME}.${WRITE_SCALE}x${READ_SCALE}_CMD "run_test.py.$ -nw ${WRITE_SCALE} -nr ${READ_SCALE} --warg=-do_write --rarg=-do_read -w $ -r $" PARENT_SCOPE) + set (${BASENAME}.${WRITE_SCALE}x${READ_SCALE}_CMD "run_test.py.$ -nw ${WRITE_SCALE} -nr ${READ_SCALE} --warg=-do_write --rarg=-do_read -w $ -r $" PARENT_SCOPE) endfunction() From 5bde4908ff3009b02bfe54a404c5f88aed2b24d0 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Tue, 26 Sep 2023 20:25:32 -0400 Subject: [PATCH 08/41] Try always using the MPI version --- testing/adios2/engine/staging-common/TestSupp.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/testing/adios2/engine/staging-common/TestSupp.cmake b/testing/adios2/engine/staging-common/TestSupp.cmake index 7106ae5184..dcc9305093 100644 --- a/testing/adios2/engine/staging-common/TestSupp.cmake +++ b/testing/adios2/engine/staging-common/TestSupp.cmake @@ -326,6 +326,12 @@ endfunction() function(import_bp_test BASENAME WRITE_SCALE READ_SCALE) set (WRITER_POSTFIX "Serial") set (READER_POSTFIX "Serial") - set (${BASENAME}.${WRITE_SCALE}x${READ_SCALE}_CMD "run_test.py.$ -nw ${WRITE_SCALE} -nr ${READ_SCALE} --warg=-do_write --rarg=-do_read -w $ -r $" PARENT_SCOPE) + if(ADIOS2_HAVE_MPI) + set (WRITER_POSTFIX "MPI") + endif() + if(ADIOS2_HAVE_MPI) + set (READER_POSTFIX "MPI") + endif() + set (${BASENAME}.${WRITE_SCALE}x${READ_SCALE}_CMD "run_test.py.$ -nw ${WRITE_SCALE} -nr ${READ_SCALE} --warg=-do_write --rarg=-do_read -w $ -r $" PARENT_SCOPE) endfunction() From 700839ddea71270ce05408110872cc340d3606d9 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Sat, 30 Sep 2023 15:22:35 -0400 Subject: [PATCH 09/41] Add prototype testing of remote functionality (#3830) --- source/adios2/toolkit/remote/Remote.cpp | 4 +- source/adios2/toolkit/remote/Remote.h | 20 +-- .../adios2/toolkit/remote/remote_common.cpp | 19 +++ source/adios2/toolkit/remote/remote_common.h | 13 ++ .../adios2/toolkit/remote/remote_server.cpp | 158 +++++++++++++++--- testing/adios2/engine/bp/CMakeLists.txt | 19 +++ 6 files changed, 191 insertions(+), 42 deletions(-) diff --git a/source/adios2/toolkit/remote/Remote.cpp b/source/adios2/toolkit/remote/Remote.cpp index 13f46dbdc7..0fe3199420 100644 --- a/source/adios2/toolkit/remote/Remote.cpp +++ b/source/adios2/toolkit/remote/Remote.cpp @@ -54,8 +54,8 @@ void Remote::InitCMData() { std::lock_guard lockGuard(m_CMInitMutex); bool first = true; - auto &CM = CManagerSingleton::Instance(first); - ev_state.cm = CM.m_cm; + auto CM = CManagerSingleton::Instance(first); + ev_state.cm = CM->m_cm; RegisterFormats(ev_state); if (first) { diff --git a/source/adios2/toolkit/remote/Remote.h b/source/adios2/toolkit/remote/Remote.h index f6b16bd304..75824cdc31 100644 --- a/source/adios2/toolkit/remote/Remote.h +++ b/source/adios2/toolkit/remote/Remote.h @@ -69,28 +69,15 @@ class CManagerSingleton #ifdef ADIOS2_HAVE_SST CManager m_cm = NULL; #endif - static CManagerSingleton &Instance(bool &first) + static CManagerSingleton *Instance(bool &first) { - // Since it's a static variable, if the class has already been created, - // it won't be created again. - // And it **is** thread-safe in C++11. - static CManagerSingleton myInstance; + static CManagerSingleton *ptr = new CManagerSingleton(); static bool internal_first = true; - // Return a reference to our instance. - first = internal_first; internal_first = false; - return myInstance; + return ptr; } - // delete copy and move constructors and assign operators - CManagerSingleton(CManagerSingleton const &) = delete; // Copy construct - CManagerSingleton(CManagerSingleton &&) = delete; // Move construct - CManagerSingleton &operator=(CManagerSingleton const &) = delete; // Copy assign - CManagerSingleton &operator=(CManagerSingleton &&) = delete; // Move assign - - // Any other public methods. - protected: #ifdef ADIOS2_HAVE_SST CManagerSingleton() { m_cm = CManager_create(); } @@ -101,7 +88,6 @@ class CManagerSingleton ~CManagerSingleton() {} #endif - // And any other protected methods. }; } // end namespace adios2 diff --git a/source/adios2/toolkit/remote/remote_common.cpp b/source/adios2/toolkit/remote/remote_common.cpp index 20870815d5..28be359240 100644 --- a/source/adios2/toolkit/remote/remote_common.cpp +++ b/source/adios2/toolkit/remote/remote_common.cpp @@ -96,6 +96,23 @@ FMField CloseFileList[] = { FMStructDescRec CloseFileStructs[] = {{"Close", CloseFileList, sizeof(struct _CloseFileMsg), NULL}, {NULL, NULL, 0, NULL}}; +FMField KillServerList[] = {{"KillResponseCondition", "integer", sizeof(long), + FMOffset(KillServerMsg, KillResponseCondition)}, + {NULL, NULL, 0, 0}}; + +FMStructDescRec KillServerStructs[] = { + {"KillServer", KillServerList, sizeof(struct _KillServerMsg), NULL}, {NULL, NULL, 0, NULL}}; + +FMField KillResponseList[] = { + {"KillResponseCondition", "integer", sizeof(long), + FMOffset(KillResponseMsg, KillResponseCondition)}, + {"Status", "string", sizeof(char *), FMOffset(KillResponseMsg, Status)}, + {NULL, NULL, 0, 0}}; + +FMStructDescRec KillResponseStructs[] = { + {"KillResponse", KillResponseList, sizeof(struct _KillResponseMsg), NULL}, + {NULL, NULL, 0, NULL}}; + void RegisterFormats(RemoteCommon::Remote_evpath_state &ev_state) { ev_state.OpenFileFormat = CMregister_format(ev_state.cm, RemoteCommon::OpenFileStructs); @@ -108,6 +125,8 @@ void RegisterFormats(RemoteCommon::Remote_evpath_state &ev_state) ev_state.ReadRequestFormat = CMregister_format(ev_state.cm, RemoteCommon::ReadRequestStructs); ev_state.ReadResponseFormat = CMregister_format(ev_state.cm, RemoteCommon::ReadResponseStructs); ev_state.CloseFileFormat = CMregister_format(ev_state.cm, RemoteCommon::CloseFileStructs); + ev_state.KillServerFormat = CMregister_format(ev_state.cm, RemoteCommon::KillServerStructs); + ev_state.KillResponseFormat = CMregister_format(ev_state.cm, RemoteCommon::KillResponseStructs); } } } diff --git a/source/adios2/toolkit/remote/remote_common.h b/source/adios2/toolkit/remote/remote_common.h index 48102e7b2d..a8c5aee5db 100644 --- a/source/adios2/toolkit/remote/remote_common.h +++ b/source/adios2/toolkit/remote/remote_common.h @@ -87,6 +87,17 @@ typedef struct _CloseFileMsg void *FileHandle; } *CloseFileMsg; +typedef struct _KillServerMsg +{ + int KillResponseCondition; +} *KillServerMsg; + +typedef struct _KillResponseMsg +{ + int KillResponseCondition; + char *Status; +} *KillResponseMsg; + enum VerbosityLevel { NoVerbose = 0, // Generally no output (but not absolutely quiet?) @@ -111,6 +122,8 @@ struct Remote_evpath_state CMFormat ReadRequestFormat; CMFormat ReadResponseFormat; CMFormat CloseFileFormat; + CMFormat KillServerFormat; + CMFormat KillResponseFormat; }; void RegisterFormats(struct Remote_evpath_state &ev_state); diff --git a/source/adios2/toolkit/remote/remote_server.cpp b/source/adios2/toolkit/remote/remote_server.cpp index 523ab70c55..9ae911322d 100644 --- a/source/adios2/toolkit/remote/remote_server.cpp +++ b/source/adios2/toolkit/remote/remote_server.cpp @@ -30,6 +30,13 @@ using namespace adios2; int verbose = 1; ADIOS adios("C++"); +size_t TotalSimpleBytesSent = 0; +size_t TotalGetBytesSent = 0; +size_t TotalSimpleReads = 0; +size_t TotalGets = 0; +size_t SimpleFilesOpened = 0; +size_t ADIOSFilesOpened = 0; + std::string readable_size(uint64_t size) { constexpr const char FILE_SIZE_UNITS[8][3]{"B ", "KB", "MB", "GB", "TB", "PB", "EB", "ZB"}; @@ -178,6 +185,7 @@ static void OpenHandler(CManager cm, CMConnection conn, void *vevent, void *clie CMconn_register_close_handler(conn, ConnCloseHandler, NULL); ADIOSFileMap[f->m_ID] = f; ConnToFileMap.emplace(conn, f->m_ID); + ADIOSFilesOpened++; } static void OpenSimpleHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, @@ -198,6 +206,7 @@ static void OpenSimpleHandler(CManager cm, CMConnection conn, void *vevent, void CMconn_register_close_handler(conn, ConnCloseHandler, NULL); SimpleFileMap[f->m_ID] = f; ConnToFileMap.emplace(conn, f->m_ID); + SimpleFilesOpened++; } static void GetRequestHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, @@ -263,6 +272,8 @@ static void GetRequestHandler(CManager cm, CMConnection conn, void *vevent, void << " for Get<" << TypeOfVar << ">(" << VarName << ")" << b << std::endl; \ f->m_BytesSent += Response.Size; \ f->m_OperationCount++; \ + TotalGetBytesSent += Response.Size; \ + TotalGets++; \ CMwrite(conn, ev_state->ReadResponseFormat, &Response); \ } ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(GET) @@ -300,16 +311,78 @@ static void ReadRequestHandler(CManager cm, CMConnection conn, void *vevent, voi std::cout << "Returning " << readable_size(Response.Size) << " for Read " << std::endl; f->m_BytesSent += Response.Size; f->m_OperationCount++; + TotalSimpleBytesSent += Response.Size; + TotalSimpleReads++; CMwrite(conn, ev_state->ReadResponseFormat, &Response); free(tmp); } -void REVPServerRegisterHandlers(struct Remote_evpath_state &ev_state) +static void KillServerHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, + attr_list attrs) +{ + KillServerMsg kill_msg = static_cast(vevent); + struct Remote_evpath_state *ev_state = static_cast(client_data); + _KillResponseMsg kill_response_msg; + memset(&kill_response_msg, 0, sizeof(kill_response_msg)); + kill_response_msg.KillResponseCondition = kill_msg->KillResponseCondition; + std::stringstream Status; + Status << "ADIOS files Opened: " << ADIOSFilesOpened << " (" << TotalGets << " gets for " + << readable_size(TotalGetBytesSent) << ") Simple files opened: " << SimpleFilesOpened + << " (" << TotalSimpleReads << " reads for " << readable_size(TotalSimpleBytesSent) + << ")"; + kill_response_msg.Status = strdup(Status.str().c_str()); + CMwrite(conn, ev_state->KillResponseFormat, &kill_response_msg); + free(kill_response_msg.Status); + exit(0); +} + +static void KillResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, + attr_list attrs) +{ + KillResponseMsg kill_response_msg = static_cast(vevent); + std::cout << "Server final status: " << kill_response_msg->Status << std::endl; + exit(0); +} + +void ServerRegisterHandlers(struct Remote_evpath_state &ev_state) { CMregister_handler(ev_state.OpenFileFormat, OpenHandler, &ev_state); CMregister_handler(ev_state.OpenSimpleFileFormat, OpenSimpleHandler, &ev_state); CMregister_handler(ev_state.GetRequestFormat, GetRequestHandler, &ev_state); CMregister_handler(ev_state.ReadRequestFormat, ReadRequestHandler, &ev_state); + CMregister_handler(ev_state.KillServerFormat, KillServerHandler, &ev_state); + CMregister_handler(ev_state.KillResponseFormat, KillResponseHandler, &ev_state); +} + +static const char *hostname = "localhost"; + +void connect_and_kill(int ServerPort) +{ + CManager cm = CManager_create(); + _KillServerMsg kill_msg; + struct Remote_evpath_state ev_state; + attr_list contact_list = create_attr_list(); + atom_t CM_IP_PORT = -1; + atom_t CM_IP_HOSTNAME = -1; + CM_IP_HOSTNAME = attr_atom_from_string("IP_HOST"); + CM_IP_PORT = attr_atom_from_string("IP_PORT"); + add_attr(contact_list, CM_IP_HOSTNAME, Attr_String, (attr_value)hostname); + add_attr(contact_list, CM_IP_PORT, Attr_Int4, (attr_value)ServerPort); + CMConnection conn = CMinitiate_conn(cm, contact_list); + if (!conn) + return; + + ev_state.cm = cm; + + RegisterFormats(ev_state); + + ServerRegisterHandlers(ev_state); + + memset(&kill_msg, 0, sizeof(kill_msg)); + kill_msg.KillResponseCondition = CMCondition_get(ev_state.cm, conn); + CMwrite(conn, ev_state.KillServerFormat, &kill_msg); + CMCondition_wait(ev_state.cm, kill_msg.KillResponseCondition); + exit(0); } static atom_t CM_IP_PORT = -1; @@ -318,9 +391,67 @@ int main(int argc, char **argv) { CManager cm; struct Remote_evpath_state ev_state; + int background = 0; + int kill_server = 0; + + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-background") == 0) + { + background++; + } + else if (strcmp(argv[i], "-kill_server") == 0) + { + kill_server++; + } + if (argv[i][0] == '-') + { + size_t j = 1; + while (argv[i][j] != 0) + { + if (argv[i][j] == 'v') + { + verbose++; + } + else if (argv[i][j] == 'q') + { + verbose--; + } + j++; + } + } + else + { + fprintf(stderr, "Unknown argument \"%s\"\n", argv[i]); + fprintf(stderr, "Usage: remote_server [-background] [-kill_server] [-v] [-q]\n"); + exit(1); + } + } + + if (kill_server) + { + connect_and_kill(ServerPort); + exit(0); + } + if (background) + { + if (verbose) + { + printf("Forking server to background\n"); + } + if (fork() != 0) + { + /* I'm the parent, wait a sec to let the child start, then exit */ + sleep(1); + exit(0); + } + /* I'm the child, close IO FDs so that ctest continues. No verbosity here */ + verbose = 0; + close(0); + close(1); + close(2); + } - (void)argc; - (void)argv; cm = CManager_create(); CM_IP_PORT = attr_atom_from_string("IP_PORT"); attr_list listen_list = NULL; @@ -339,28 +470,9 @@ int main(int argc, char **argv) } ev_state.cm = cm; - while (argv[1] && (argv[1][0] == '-')) - { - size_t i = 1; - while (argv[1][i] != 0) - { - if (argv[1][i] == 'v') - { - verbose++; - } - else if (argv[1][i] == 'q') - { - verbose--; - } - i++; - } - argv++; - argc--; - } - RegisterFormats(ev_state); - REVPServerRegisterHandlers(ev_state); + ServerRegisterHandlers(ev_state); std::cout << "doing Run Network" << std::endl; CMrun_network(cm); diff --git a/testing/adios2/engine/bp/CMakeLists.txt b/testing/adios2/engine/bp/CMakeLists.txt index a57f950a23..10f724cc1b 100644 --- a/testing/adios2/engine/bp/CMakeLists.txt +++ b/testing/adios2/engine/bp/CMakeLists.txt @@ -106,6 +106,25 @@ bp_gtest_add_tests_helper(LargeMetadata MPI_ALLOW) set(BP5LargeMeta "Engine.BP.BPLargeMetadata.BPWrite1D_LargeMetadata.BP5.Serial") +if ((NOT WIN32) AND ADIOS2_HAVE_SST) +# prototype for remote server testing +# (we don't really use SST here, just EVPath, but ADIOS2_HAVE_SST is the most relevant conditional) + macro(add_remote_tests_helper testname) + add_test(NAME "Remote.BP${testname}.GetRemote" COMMAND Test.Engine.BP.${testname}.Serial bp5) + set_tests_properties(Remote.BP${testname}.GetRemote PROPERTIES FIXTURES_REQUIRED Server ENVIRONMENT "DoRemote=1") + endmacro() + + add_test(NAME remoteServerSetup COMMAND remote_server -background) + set_tests_properties(remoteServerSetup PROPERTIES FIXTURES_SETUP Server) + + add_test(NAME remoteServerCleanup COMMAND remote_server -kill_server) + set_tests_properties(remoteServerCleanup PROPERTIES FIXTURES_CLEANUP Server) + + #add remote tests below this line + add_remote_tests_helper(WriteReadADIOS2stdio) + add_remote_tests_helper(WriteMemorySelectionRead) +endif() + if(ADIOS2_HAVE_MPI) list(APPEND BP5LargeMeta "Engine.BP.BPLargeMetadata.BPWrite1D_LargeMetadata.BP5.MPI" "Engine.BP.BPLargeMetadata.ManyLongStrings.BP5.MPI") endif() From 107164d6fba5db462e739247380d6154448ca295 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Fri, 13 Oct 2023 23:13:05 -0400 Subject: [PATCH 10/41] Tweak Remote class and test multi-threaded file remote access (#3834) * Tweak Remote class and test multi-threaded file remote access * rework * Bad clang-format * New formulation --- source/adios2/toolkit/remote/Remote.cpp | 22 +++++++++++-------- source/adios2/toolkit/remote/Remote.h | 28 ++++++++++--------------- testing/adios2/engine/bp/CMakeLists.txt | 19 +++++++++++------ 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/source/adios2/toolkit/remote/Remote.cpp b/source/adios2/toolkit/remote/Remote.cpp index 0fe3199420..3a397b05a9 100644 --- a/source/adios2/toolkit/remote/Remote.cpp +++ b/source/adios2/toolkit/remote/Remote.cpp @@ -50,16 +50,20 @@ void ReadResponseHandler(CManager cm, CMConnection conn, void *vevent, void *cli return; }; +CManagerSingleton &CManagerSingleton::Instance(RemoteCommon::Remote_evpath_state &ev_state) +{ + std::mutex mtx; + const std::lock_guard lock(mtx); + static CManagerSingleton instance; + ev_state = instance.internalEvState; + return instance; +} + void Remote::InitCMData() { - std::lock_guard lockGuard(m_CMInitMutex); - bool first = true; - auto CM = CManagerSingleton::Instance(first); - ev_state.cm = CM->m_cm; - RegisterFormats(ev_state); - if (first) - { - CMfork_comm_thread(ev_state.cm); + (void)CManagerSingleton::Instance(ev_state); + static std::once_flag flag; + std::call_once(flag, [&]() { CMregister_handler(ev_state.OpenResponseFormat, (CMHandlerFunc)OpenResponseHandler, &ev_state); CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler, @@ -68,7 +72,7 @@ void Remote::InitCMData() (CMHandlerFunc)OpenSimpleResponseHandler, &ev_state); CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler, &ev_state); - } + }); } void Remote::Open(const std::string hostname, const int32_t port, const std::string filename, diff --git a/source/adios2/toolkit/remote/Remote.h b/source/adios2/toolkit/remote/Remote.h index 75824cdc31..608d35f637 100644 --- a/source/adios2/toolkit/remote/Remote.h +++ b/source/adios2/toolkit/remote/Remote.h @@ -63,32 +63,26 @@ class Remote bool m_Active = false; }; +#ifdef ADIOS2_HAVE_SST class CManagerSingleton { public: -#ifdef ADIOS2_HAVE_SST + static CManagerSingleton &Instance(RemoteCommon::Remote_evpath_state &ev_state); + +private: CManager m_cm = NULL; -#endif - static CManagerSingleton *Instance(bool &first) + RemoteCommon::Remote_evpath_state internalEvState; + CManagerSingleton() { - static CManagerSingleton *ptr = new CManagerSingleton(); - static bool internal_first = true; - first = internal_first; - internal_first = false; - return ptr; + m_cm = CManager_create(); + internalEvState.cm = m_cm; + RegisterFormats(internalEvState); + CMfork_comm_thread(internalEvState.cm); } -protected: -#ifdef ADIOS2_HAVE_SST - CManagerSingleton() { m_cm = CManager_create(); } - ~CManagerSingleton() { CManager_close(m_cm); } -#else - CManagerSingleton() {} - - ~CManagerSingleton() {} -#endif }; +#endif } // end namespace adios2 diff --git a/testing/adios2/engine/bp/CMakeLists.txt b/testing/adios2/engine/bp/CMakeLists.txt index 10f724cc1b..03479c7edc 100644 --- a/testing/adios2/engine/bp/CMakeLists.txt +++ b/testing/adios2/engine/bp/CMakeLists.txt @@ -107,22 +107,29 @@ bp_gtest_add_tests_helper(LargeMetadata MPI_ALLOW) set(BP5LargeMeta "Engine.BP.BPLargeMetadata.BPWrite1D_LargeMetadata.BP5.Serial") if ((NOT WIN32) AND ADIOS2_HAVE_SST) -# prototype for remote server testing -# (we don't really use SST here, just EVPath, but ADIOS2_HAVE_SST is the most relevant conditional) - macro(add_remote_tests_helper testname) + # prototype for remote server testing + # (we don't really use SST here, just EVPath, but ADIOS2_HAVE_SST is the most relevant conditional) + + macro(add_get_remote_tests_helper testname) add_test(NAME "Remote.BP${testname}.GetRemote" COMMAND Test.Engine.BP.${testname}.Serial bp5) set_tests_properties(Remote.BP${testname}.GetRemote PROPERTIES FIXTURES_REQUIRED Server ENVIRONMENT "DoRemote=1") endmacro() + macro(add_file_remote_tests_helper testname) + add_test(NAME "Remote.BP${testname}.FileRemote" COMMAND Test.Engine.BP.${testname}.Serial bp5) + set_tests_properties(Remote.BP${testname}.FileRemote PROPERTIES FIXTURES_REQUIRED Server ENVIRONMENT "DoFileRemote=1") + endmacro() + add_test(NAME remoteServerSetup COMMAND remote_server -background) set_tests_properties(remoteServerSetup PROPERTIES FIXTURES_SETUP Server) add_test(NAME remoteServerCleanup COMMAND remote_server -kill_server) set_tests_properties(remoteServerCleanup PROPERTIES FIXTURES_CLEANUP Server) - #add remote tests below this line - add_remote_tests_helper(WriteReadADIOS2stdio) - add_remote_tests_helper(WriteMemorySelectionRead) + ##### add remote tests below this line + add_get_remote_tests_helper(WriteReadADIOS2stdio) + add_get_remote_tests_helper(WriteMemorySelectionRead) + add_file_remote_tests_helper(WriteMemorySelectionRead) endif() if(ADIOS2_HAVE_MPI) From ac071858422b1e848dab6c8dc5f3cd4e1fa1fab8 Mon Sep 17 00:00:00 2001 From: Vicente Bolea Date: Tue, 17 Oct 2023 13:56:40 -0400 Subject: [PATCH 11/41] MPI: add timeout for conf test for MPI_DP (#3848) --- cmake/DetectOptions.cmake | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmake/DetectOptions.cmake b/cmake/DetectOptions.cmake index c8f277567c..409db1b552 100644 --- a/cmake/DetectOptions.cmake +++ b/cmake/DetectOptions.cmake @@ -445,9 +445,11 @@ if(ADIOS2_USE_SST AND NOT WIN32) endif() endif() if(ADIOS2_HAVE_MPI) - set(CMAKE_REQUIRED_LIBRARIES MPI::MPI_C) - include(CheckCSourceRuns) - check_c_source_runs([=[ + set(CMAKE_REQUIRED_LIBRARIES "MPI::MPI_C;Threads::Threads") + include(CheckCXXSourceRuns) + check_cxx_source_runs([=[ + #include + #include #include #include @@ -457,9 +459,18 @@ if(ADIOS2_USE_SST AND NOT WIN32) int main() { + // Timeout after 5 second + auto task = std::async(std::launch::async, []() { + std::this_thread::sleep_for(std::chrono::seconds(5)); + exit(EXIT_FAILURE); + }); + + char* port_name = new char[MPI_MAX_PORT_NAME]; MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, NULL); - MPI_Open_port(MPI_INFO_NULL, malloc(sizeof(char) * MPI_MAX_PORT_NAME)); + MPI_Open_port(MPI_INFO_NULL, port_name); + MPI_Close_port(port_name); MPI_Finalize(); + exit(EXIT_SUCCESS); }]=] ADIOS2_HAVE_MPI_CLIENT_SERVER) unset(CMAKE_REQUIRED_LIBRARIES) From 8707f2b857097ebc0ce696ae9c3ab2ad88b1f8e4 Mon Sep 17 00:00:00 2001 From: Junmin Gu Date: Tue, 17 Oct 2023 12:14:47 -0700 Subject: [PATCH 12/41] Update test.cpp --- examples/query/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/query/test.cpp b/examples/query/test.cpp index 441cc4718e..c6cd4e32b9 100644 --- a/examples/query/test.cpp +++ b/examples/query/test.cpp @@ -10,7 +10,7 @@ #include #include -// returns block ids +// touched block ids are printed. void queryIDs(adios2::IO &queryIO, std::string &dataFileName, std::string &queryFile) { adios2::Engine reader = queryIO.Open(dataFileName, adios2::Mode::Read, MPI_COMM_WORLD); From d0fcf101823c9693dcfc3c5b665693b8acf1013e Mon Sep 17 00:00:00 2001 From: Vicente Bolea Date: Tue, 17 Oct 2023 15:38:56 -0400 Subject: [PATCH 13/41] cmake: update minimum cmake to 3.12 (#3849) --- cmake/adios2-config-install.cmake.in | 2 +- cmake/install/post/adios2-config-dummy/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/adios2-config-install.cmake.in b/cmake/adios2-config-install.cmake.in index 86d3ef64ef..a0d6cf1def 100644 --- a/cmake/adios2-config-install.cmake.in +++ b/cmake/adios2-config-install.cmake.in @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.12) set(_ADIOS2_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}") diff --git a/cmake/install/post/adios2-config-dummy/CMakeLists.txt b/cmake/install/post/adios2-config-dummy/CMakeLists.txt index 7b31c5c911..83db648edd 100644 --- a/cmake/install/post/adios2-config-dummy/CMakeLists.txt +++ b/cmake/install/post/adios2-config-dummy/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.12) project(adios2-config-dummy C CXX) From 975e8deba0f5b53f0dc6d8e37d0d1aa36bd1a858 Mon Sep 17 00:00:00 2001 From: Vicente Bolea Date: Tue, 17 Oct 2023 15:53:52 -0400 Subject: [PATCH 14/41] MPI_DP: do not call MPI_Init (#3847) --- source/adios2/toolkit/sst/dp/mpi_dp.c | 66 ++++++++------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/source/adios2/toolkit/sst/dp/mpi_dp.c b/source/adios2/toolkit/sst/dp/mpi_dp.c index 612985c146..d82fc189b4 100644 --- a/source/adios2/toolkit/sst/dp/mpi_dp.c +++ b/source/adios2/toolkit/sst/dp/mpi_dp.c @@ -42,8 +42,6 @@ #define QUOTE(name) #name #define MACRO_TO_STR(name) QUOTE(name) -static pthread_once_t OnceMpiInitializer = PTHREAD_ONCE_INIT; - /*****Stream Basic Structures ***********************************************/ typedef struct _MpiReaderContactInfo @@ -235,40 +233,6 @@ static void MpiReadReplyHandler(CManager cm, CMConnection conn, void *msg_v, voi static void MpiReadRequestHandler(CManager cm, CMConnection conn, void *msg_v, void *client_Data, attr_list attrs); -/** - * Initialize MPI in the mode that it is required for MPI_DP to work. - * - * It can be called multiple times. - */ -static void MpiInitialize() -{ - int IsInitialized = 0; - int provided; - - MPI_Initialized(&IsInitialized); - if (!IsInitialized) - { - MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &provided); - } - else - { - MPI_Query_thread(&provided); - } - - if (provided != MPI_THREAD_MULTIPLE) - { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (!rank) - { - fprintf(stderr, - "MPI init without MPI_THREAD_MULTIPLE (Externally " - "initialized:%s)\n", - IsInitialized ? "true" : "false"); - } - } -} - /*****Public accessible functions********************************************/ /** @@ -286,8 +250,6 @@ static DP_RS_Stream MpiInitReader(CP_Services Svcs, void *CP_Stream, void **Read struct _SstParams *Params, attr_list WriterContact, SstStats Stats) { - pthread_once(&OnceMpiInitializer, MpiInitialize); - MpiStreamRD Stream = calloc(sizeof(struct _MpiStreamRD), 1); CManager cm = Svcs->getCManager(CP_Stream); SMPI_Comm comm = Svcs->getMPIComm(CP_Stream); @@ -327,8 +289,6 @@ static DP_RS_Stream MpiInitReader(CP_Services Svcs, void *CP_Stream, void **Read static DP_WS_Stream MpiInitWriter(CP_Services Svcs, void *CP_Stream, struct _SstParams *Params, attr_list DPAttrs, SstStats Stats) { - pthread_once(&OnceMpiInitializer, MpiInitialize); - MpiStreamWR Stream = calloc(sizeof(struct _MpiStreamWR), 1); CManager cm = Svcs->getCManager(CP_Stream); SMPI_Comm comm = Svcs->getMPIComm(CP_Stream); @@ -798,16 +758,30 @@ static void MpiReleaseTimeStep(CP_Services Svcs, DP_WS_Stream Stream_v, long Tim */ static int MpiGetPriority(CP_Services Svcs, void *CP_Stream, struct _SstParams *Params) { -#if defined(MPICH) - // Only enabled when MPI_THREAD_MULTIPLE and using MPICH + int IsInitialized = 0; int provided = 0; - pthread_once(&OnceMpiInitializer, MpiInitialize); - MPI_Query_thread(&provided); - if (provided == MPI_THREAD_MULTIPLE) + int IsMPICH = 0; +#if defined(MPICH) + IsMPICH = 1; + + MPI_Initialized(&IsInitialized); + if (IsInitialized) { - return 100; + MPI_Query_thread(&provided); + // Only enabled when MPI_THREAD_MULTIPLE and using MPICH + if (provided == MPI_THREAD_MULTIPLE) + { + return 100; + } } #endif + + Svcs->verbose(CP_Stream, DPTraceVerbose, + "MPI DP disabled since the following predicate is false: " + "(MPICH=%s AND MPI_initialized=%s AND MPI_THREAD_MULTIPLE=%s)", + IsMPICH ? "true" : "false", IsInitialized ? "true" : "false", + provided == MPI_THREAD_MULTIPLE ? "true" : "false"); + return -100; } From 897ca42ccbe0cd21718b5f9f046d21326d4d7ed5 Mon Sep 17 00:00:00 2001 From: Spiros Tsalikis Date: Thu, 14 Sep 2023 14:52:33 -0400 Subject: [PATCH 15/41] Improve existing examples 1) Make all examples individually compilable 2) Make examples' executable names be consistent 3) Move certain examples in the right folders 4) Rename certain examples for clarity 5) Make all examples installable 6) Fix Python formatting using black 7) Add licence documentation wherever it's missing --- CMakeLists.txt | 2 +- examples/CMakeLists.txt | 22 +--- examples/basics/CMakeLists.txt | 5 +- examples/basics/globalArray/CMakeLists.txt | 12 --- examples/basics/globalArrayND/CMakeLists.txt | 31 ++++++ .../globalArrayNDWrite.cpp} | 0 examples/basics/joinedArray/CMakeLists.txt | 27 ++++- ...edArray_write.cpp => joinedArrayWrite.cpp} | 0 examples/basics/localArray/CMakeLists.txt | 32 ++++-- ...localArray_read.cpp => localArrayRead.cpp} | 0 ...calArray_write.cpp => localArrayWrite.cpp} | 0 examples/basics/queryWorker/CMakeLists.txt | 30 ++++++ .../READ.ME => basics/queryWorker/README.md} | 0 .../queryWorker}/configs/bp4io.xml | 2 +- .../queryWorker}/configs/bp4io_composite.xml | 4 +- .../queryWorker}/configs/q1.json | 0 .../queryWorker}/configs/q2.json | 0 .../queryWorker/queryWorker.cpp} | 38 ------- examples/basics/values/CMakeLists.txt | 28 ++++- .../{values_write.cpp => valuesWrite.cpp} | 0 examples/cuda/CMakeLists.txt | 8 -- examples/fides/01_onecell/CMakeLists.txt | 7 -- examples/fides/01_onecell/README.md | 28 ----- examples/fides/CMakeLists.txt | 6 -- examples/h5subfile/CMakeLists.txt | 10 -- examples/heatTransfer/inline/CMakeLists.txt | 14 --- examples/heatTransfer/read/CMakeLists.txt | 11 -- .../heatTransfer/read_fileonly/CMakeLists.txt | 12 --- .../read_fileonly/heatRead_adios1.cpp | 101 ------------------ examples/heatTransfer/write/CMakeLists.txt | 66 ------------ examples/hello/CMakeLists.txt | 34 +++--- .../hello/bpAttributeWriter/CMakeLists.txt | 28 ++++- ...ributeWriter.cpp => bpAttributeWriter.cpp} | 2 +- ..._nompi.cpp => bpAttributeWriter_nompi.cpp} | 2 +- examples/hello/bpFWriteCRead/CMakeLists.txt | 59 +++++++--- examples/hello/bpFlushWriter/CMakeLists.txt | 27 ++++- ...lloBPFlushWriter.cpp => bpFlushWriter.cpp} | 2 +- ...iter_nompi.cpp => bpFlushWriter_nompi.cpp} | 2 +- examples/hello/bpReader/CMakeLists.txt | 69 ++++++++---- .../{helloBPReader.cpp => bpReader.cpp} | 4 +- ...derHeatMap2D.cpp => bpReaderHeatMap2D.cpp} | 2 +- ...eaderHeatMap2D.py => bpReaderHeatMap2D.py} | 17 +-- ...derHeatMap3D.F90 => bpReaderHeatMap3D.F90} | 4 +- ...derHeatMap3D.cpp => bpReaderHeatMap3D.cpp} | 0 ...oBPReader_nompi.cpp => bpReader_nompi.cpp} | 2 +- examples/hello/bpTimeWriter/CMakeLists.txt | 27 ++++- ...helloBPTimeWriter.cpp => bpTimeWriter.cpp} | 2 +- .../{helloBPTimeWriter.py => bpTimeWriter.py} | 7 +- ...riter_nompi.cpp => bpTimeWriter_nompi.cpp} | 2 +- examples/hello/bpWriteReadCuda/CMakeLists.txt | 25 +++++ .../bpWriteReadCuda/bpWriteReadCuda.cu} | 3 + examples/hello/bpWriter/CMakeLists.txt | 91 +++++++++++----- ...lloBPPutDeferred.cpp => bpPutDeferred.cpp} | 12 +-- .../bpWriter/{helloBPSZ.cpp => bpSZ.cpp} | 2 +- ...helloBPSubStreams.cpp => bpSubStreams.cpp} | 2 +- .../{helloBPWriter.F90 => bpWriter.F90} | 4 +- .../bpWriter/{helloBPWriter.c => bpWriter.c} | 2 +- .../{helloBPWriter.cpp => bpWriter.cpp} | 2 +- .../{helloBPWriter.py => bpWriter.py} | 17 +-- ...lloBPWriter_nompi.py => bpWriter_nompi.py} | 7 +- examples/hello/datamanReader/CMakeLists.txt | 26 ++++- ...lloDataManReader.cpp => dataManReader.cpp} | 2 +- ...helloDataManReader.py => dataManReader.py} | 4 +- examples/hello/datamanWriter/CMakeLists.txt | 26 ++++- ...lloDataManWriter.cpp => dataManWriter.cpp} | 2 +- ...helloDataManWriter.py => dataManWriter.py} | 7 +- .../hello/dataspacesReader/CMakeLists.txt | 33 +++++- ...aSpacesReader.cpp => dataSpacesReader.cpp} | 2 +- .../hello/dataspacesWriter/CMakeLists.txt | 33 +++++- ...aSpacesWriter.cpp => dataSpacesWriter.cpp} | 2 +- examples/hello/hdf5Reader/CMakeLists.txt | 33 +++++- .../{helloHDF5Reader.cpp => hdf5Reader.cpp} | 2 +- ...5Reader_nompi.cpp => hdf5Reader_nompi.cpp} | 2 +- examples/hello/hdf5SubFile/CMakeLists.txt | 30 ++++++ .../hdf5SubFile/hdf5SubFile.cpp} | 2 +- examples/hello/hdf5Writer/CMakeLists.txt | 33 +++++- .../{helloHDF5Writer.cpp => hdf5Writer.cpp} | 2 +- ...5Writer_nompi.cpp => hdf5Writer_nompi.cpp} | 2 +- .../hello/inlineFWriteCppRead/CMakeLists.txt | 43 +++++--- examples/hello/inlineMWE/CMakeLists.txt | 17 +++ examples/{ => hello}/inlineMWE/inlineMWE.cpp | 5 + .../hello/inlineReaderWriter/CMakeLists.txt | 27 ++++- ...eaderWriter.cpp => inlineReaderWriter.cpp} | 2 +- examples/hello/skeleton/CMakeLists.txt | 37 +++++-- ...HelloSkeletonArgs.cpp => SkeletonArgs.cpp} | 9 +- .../{HelloSkeletonArgs.h => SkeletonArgs.h} | 4 +- .../{HelloSkeletonPrint.h => SkeletonPrint.h} | 0 .../skeleton/{hello_bpfile.xml => bpfile.xml} | 2 +- .../{hello_skeleton.xml => skeleton.xml} | 2 +- ...oSkeletonReader.cpp => skeletonReader.cpp} | 11 +- ...oSkeletonWriter.cpp => skeletonWriter.cpp} | 6 +- examples/hello/sstReader/CMakeLists.txt | 35 +++++- .../{helloSstReader.cpp => sstReader.cpp} | 4 +- examples/hello/sstWriter/CMakeLists.txt | 35 +++++- .../{helloSstWriter.cpp => sstWriter.cpp} | 13 +-- .../{helloSstWriter.py => sstWriter.py} | 10 +- examples/inlineMWE/CMakeLists.txt | 7 -- examples/plugins/CMakeLists.txt | 4 +- examples/plugins/engine/CMakeLists.txt | 46 ++++---- ...e_read.cpp => examplePluginEngineRead.cpp} | 2 +- ...write.cpp => examplePluginEngineWrite.cpp} | 2 +- examples/plugins/engine/example_engine.xml | 4 +- examples/plugins/operator/CMakeLists.txt | 30 ++++-- ...read.cpp => examplePluginOperatorRead.cpp} | 2 +- ...ite.cpp => examplePluginOperatorWrite.cpp} | 0 examples/query/CMakeLists.txt | 10 -- examples/simulations/CMakeLists.txt | 3 + .../heatTransfer/CMakeLists.txt | 9 +- .../{ => simulations}/heatTransfer/ReadMe.md | 14 +-- .../heatTransfer/heat_bp3.xml | 4 +- .../heatTransfer/heat_bp3_zfp.xml | 4 +- .../heatTransfer/heat_bp4.xml | 4 +- .../heatTransfer/heat_bp4_zfp.xml | 4 +- .../heatTransfer/heat_dataman.xml | 4 +- .../heatTransfer/heat_dataspaces.xml | 4 +- .../heatTransfer/heat_file.xml | 4 +- .../heatTransfer/heat_hdf5.xml | 4 +- .../heatTransfer/heat_inline.xml | 2 +- .../heatTransfer/heat_nullcore.xml | 4 +- .../heatTransfer/heat_ssc.xml | 4 +- .../heatTransfer/heat_sst_bp.xml | 4 +- .../heatTransfer/heat_sst_bp_rdma.xml | 4 +- .../heatTransfer/heat_sst_ffs.xml | 4 +- .../heatTransfer/heat_sst_ffs_rdma.xml | 4 +- .../heatTransfer/inline/CMakeLists.txt | 34 ++++++ .../heatTransfer/inline/InlineIO.cpp | 0 .../heatTransfer/inline/InlineIO.h | 0 .../heatTransfer/inline/main.cpp | 0 .../heatTransfer/read/CMakeLists.txt | 31 ++++++ .../heatTransfer/read/PrintDataStep.h | 0 .../heatTransfer/read/ReadSettings.cpp | 0 .../heatTransfer/read/ReadSettings.h | 0 .../heatTransfer/read/heatRead.cpp | 0 .../heatTransfer/readFileOnly/CMakeLists.txt | 27 +++++ .../heatTransfer/readFileOnly}/PrintData.h | 0 .../readFileOnly/heatReadFileOnly.cpp} | 9 +- .../heatTransfer/write/CMakeLists.txt | 81 ++++++++++++++ .../heatTransfer/write/HeatTransfer.cpp | 0 .../heatTransfer/write/HeatTransfer.h | 0 .../{ => simulations}/heatTransfer/write/IO.h | 0 .../heatTransfer/write/IO_adios2.cpp | 2 +- .../heatTransfer/write/IO_ascii.cpp | 0 .../heatTransfer/write/IO_h5mixer.cpp | 0 .../heatTransfer/write/IO_hdf5_a.cpp | 2 +- .../heatTransfer/write/IO_ph5.cpp | 0 .../heatTransfer/write/Settings.cpp | 0 .../heatTransfer/write/Settings.h | 0 .../heatTransfer/write/main.cpp | 0 examples/useCases/CMakeLists.txt | 2 +- examples/useCases/fidesOneCell/CMakeLists.txt | 17 +++ examples/useCases/fidesOneCell/ReadMe.md | 37 +++++++ .../fidesOneCell/fidesOneCell.cpp} | 2 +- .../fidesOneCell/fidesOneCell.json} | 0 .../fidesOneCell}/paraview-onecell-step0.png | Bin .../fidesOneCell}/paraview-onecell-step9.png | Bin .../insituGlobalArrays/CMakeLists.txt | 38 +++++-- .../examples/heatTransfer/TestBPFileMx1.cmake | 16 +-- .../heatTransfer/TestBPFileMx1_zfp.cmake | 16 +-- .../examples/heatTransfer/TestBPFileMxM.cmake | 16 +-- .../examples/heatTransfer/TestBPFileMxN.cmake | 16 +-- .../examples/heatTransfer/TestInlineMxM.cmake | 4 +- .../examples/heatTransfer/TestSSCMx1.cmake | 8 +- .../examples/heatTransfer/TestSSCMxM.cmake | 8 +- .../examples/heatTransfer/TestSSCMxN.cmake | 8 +- .../examples/heatTransfer/TestSSTBPMx1.cmake | 8 +- .../examples/heatTransfer/TestSSTBPMxM.cmake | 8 +- .../examples/heatTransfer/TestSSTBPMxN.cmake | 8 +- .../heatTransfer/TestSSTBPRDMAMxN.cmake | 8 +- .../examples/heatTransfer/TestSSTFFSMx1.cmake | 8 +- .../examples/heatTransfer/TestSSTFFSMxM.cmake | 8 +- .../examples/heatTransfer/TestSSTFFSMxN.cmake | 8 +- .../heatTransfer/TestSSTFFSRDMAMxN.cmake | 8 +- .../install/EncryptionOperator/CMakeLists.txt | 4 +- testing/install/EnginePlugin/CMakeLists.txt | 4 +- 174 files changed, 1314 insertions(+), 783 deletions(-) delete mode 100644 examples/basics/globalArray/CMakeLists.txt create mode 100644 examples/basics/globalArrayND/CMakeLists.txt rename examples/basics/{globalArray/globalArray_write.cpp => globalArrayND/globalArrayNDWrite.cpp} (100%) rename examples/basics/joinedArray/{joinedArray_write.cpp => joinedArrayWrite.cpp} (100%) rename examples/basics/localArray/{localArray_read.cpp => localArrayRead.cpp} (100%) rename examples/basics/localArray/{localArray_write.cpp => localArrayWrite.cpp} (100%) create mode 100644 examples/basics/queryWorker/CMakeLists.txt rename examples/{query/READ.ME => basics/queryWorker/README.md} (100%) rename examples/{query => basics/queryWorker}/configs/bp4io.xml (99%) rename examples/{query => basics/queryWorker}/configs/bp4io_composite.xml (98%) rename examples/{query => basics/queryWorker}/configs/q1.json (100%) rename examples/{query => basics/queryWorker}/configs/q2.json (100%) rename examples/{query/test.cpp => basics/queryWorker/queryWorker.cpp} (75%) rename examples/basics/values/{values_write.cpp => valuesWrite.cpp} (100%) delete mode 100644 examples/cuda/CMakeLists.txt delete mode 100644 examples/fides/01_onecell/CMakeLists.txt delete mode 100644 examples/fides/01_onecell/README.md delete mode 100644 examples/fides/CMakeLists.txt delete mode 100644 examples/h5subfile/CMakeLists.txt delete mode 100644 examples/heatTransfer/inline/CMakeLists.txt delete mode 100644 examples/heatTransfer/read/CMakeLists.txt delete mode 100644 examples/heatTransfer/read_fileonly/CMakeLists.txt delete mode 100644 examples/heatTransfer/read_fileonly/heatRead_adios1.cpp delete mode 100644 examples/heatTransfer/write/CMakeLists.txt rename examples/hello/bpAttributeWriter/{helloBPAttributeWriter.cpp => bpAttributeWriter.cpp} (97%) rename examples/hello/bpAttributeWriter/{helloBPAttributeWriter_nompi.cpp => bpAttributeWriter_nompi.cpp} (96%) rename examples/hello/bpFlushWriter/{helloBPFlushWriter.cpp => bpFlushWriter.cpp} (97%) rename examples/hello/bpFlushWriter/{helloBPFlushWriter_nompi.cpp => bpFlushWriter_nompi.cpp} (96%) rename examples/hello/bpReader/{helloBPReader.cpp => bpReader.cpp} (97%) rename examples/hello/bpReader/{helloBPReaderHeatMap2D.cpp => bpReaderHeatMap2D.cpp} (98%) rename examples/hello/bpReader/{helloBPReaderHeatMap2D.py => bpReaderHeatMap2D.py} (75%) rename examples/hello/bpReader/{helloBPReaderHeatMap3D.F90 => bpReaderHeatMap3D.F90} (98%) rename examples/hello/bpReader/{helloBPReaderHeatMap3D.cpp => bpReaderHeatMap3D.cpp} (100%) rename examples/hello/bpReader/{helloBPReader_nompi.cpp => bpReader_nompi.cpp} (97%) rename examples/hello/bpTimeWriter/{helloBPTimeWriter.cpp => bpTimeWriter.cpp} (98%) rename examples/hello/bpTimeWriter/{helloBPTimeWriter.py => bpTimeWriter.py} (87%) rename examples/hello/bpTimeWriter/{helloBPTimeWriter_nompi.cpp => bpTimeWriter_nompi.cpp} (96%) create mode 100644 examples/hello/bpWriteReadCuda/CMakeLists.txt rename examples/{cuda/cudaBPWriteRead.cu => hello/bpWriteReadCuda/bpWriteReadCuda.cu} (96%) rename examples/hello/bpWriter/{helloBPPutDeferred.cpp => bpPutDeferred.cpp} (91%) rename examples/hello/bpWriter/{helloBPSZ.cpp => bpSZ.cpp} (98%) rename examples/hello/bpWriter/{helloBPSubStreams.cpp => bpSubStreams.cpp} (99%) rename examples/hello/bpWriter/{helloBPWriter.F90 => bpWriter.F90} (97%) rename examples/hello/bpWriter/{helloBPWriter.c => bpWriter.c} (97%) rename examples/hello/bpWriter/{helloBPWriter.cpp => bpWriter.cpp} (97%) rename examples/hello/bpWriter/{helloBPWriter.py => bpWriter.py} (73%) rename examples/hello/bpWriter/{helloBPWriter_nompi.py => bpWriter_nompi.py} (72%) rename examples/hello/datamanReader/{helloDataManReader.cpp => dataManReader.cpp} (98%) rename examples/hello/datamanReader/{helloDataManReader.py => dataManReader.py} (92%) rename examples/hello/datamanWriter/{helloDataManWriter.cpp => dataManWriter.cpp} (98%) rename examples/hello/datamanWriter/{helloDataManWriter.py => dataManWriter.py} (92%) rename examples/hello/dataspacesReader/{helloDataSpacesReader.cpp => dataSpacesReader.cpp} (98%) rename examples/hello/dataspacesWriter/{helloDataSpacesWriter.cpp => dataSpacesWriter.cpp} (98%) rename examples/hello/hdf5Reader/{helloHDF5Reader.cpp => hdf5Reader.cpp} (99%) rename examples/hello/hdf5Reader/{helloHDF5Reader_nompi.cpp => hdf5Reader_nompi.cpp} (99%) create mode 100644 examples/hello/hdf5SubFile/CMakeLists.txt rename examples/{h5subfile/h5_subfile.cpp => hello/hdf5SubFile/hdf5SubFile.cpp} (99%) rename examples/hello/hdf5Writer/{helloHDF5Writer.cpp => hdf5Writer.cpp} (98%) rename examples/hello/hdf5Writer/{helloHDF5Writer_nompi.cpp => hdf5Writer_nompi.cpp} (96%) create mode 100644 examples/hello/inlineMWE/CMakeLists.txt rename examples/{ => hello}/inlineMWE/inlineMWE.cpp (88%) rename examples/hello/inlineReaderWriter/{helloInlineReaderWriter.cpp => inlineReaderWriter.cpp} (98%) rename examples/hello/skeleton/{HelloSkeletonArgs.cpp => SkeletonArgs.cpp} (92%) rename examples/hello/skeleton/{HelloSkeletonArgs.h => SkeletonArgs.h} (93%) rename examples/hello/skeleton/{HelloSkeletonPrint.h => SkeletonPrint.h} (100%) rename examples/hello/skeleton/{hello_bpfile.xml => bpfile.xml} (97%) rename examples/hello/skeleton/{hello_skeleton.xml => skeleton.xml} (96%) rename examples/hello/skeleton/{helloSkeletonReader.cpp => skeletonReader.cpp} (93%) rename examples/hello/skeleton/{helloSkeletonWriter.cpp => skeletonWriter.cpp} (93%) rename examples/hello/sstReader/{helloSstReader.cpp => sstReader.cpp} (97%) rename examples/hello/sstWriter/{helloSstWriter.cpp => sstWriter.cpp} (81%) rename examples/hello/sstWriter/{helloSstWriter.py => sstWriter.py} (72%) delete mode 100644 examples/inlineMWE/CMakeLists.txt rename examples/plugins/engine/{examplePluginEngine_read.cpp => examplePluginEngineRead.cpp} (97%) rename examples/plugins/engine/{examplePluginEngine_write.cpp => examplePluginEngineWrite.cpp} (97%) rename examples/plugins/operator/{examplePluginOperator_read.cpp => examplePluginOperatorRead.cpp} (97%) rename examples/plugins/operator/{examplePluginOperator_write.cpp => examplePluginOperatorWrite.cpp} (100%) delete mode 100644 examples/query/CMakeLists.txt create mode 100644 examples/simulations/CMakeLists.txt rename examples/{ => simulations}/heatTransfer/CMakeLists.txt (75%) rename examples/{ => simulations}/heatTransfer/ReadMe.md (75%) rename examples/{ => simulations}/heatTransfer/heat_bp3.xml (97%) rename examples/{ => simulations}/heatTransfer/heat_bp3_zfp.xml (98%) rename examples/{ => simulations}/heatTransfer/heat_bp4.xml (97%) rename examples/{ => simulations}/heatTransfer/heat_bp4_zfp.xml (98%) rename examples/{ => simulations}/heatTransfer/heat_dataman.xml (97%) rename examples/{ => simulations}/heatTransfer/heat_dataspaces.xml (91%) rename examples/{ => simulations}/heatTransfer/heat_file.xml (97%) rename examples/{ => simulations}/heatTransfer/heat_hdf5.xml (97%) rename examples/{ => simulations}/heatTransfer/heat_inline.xml (96%) rename examples/{ => simulations}/heatTransfer/heat_nullcore.xml (78%) rename examples/{ => simulations}/heatTransfer/heat_ssc.xml (94%) rename examples/{ => simulations}/heatTransfer/heat_sst_bp.xml (91%) rename examples/{ => simulations}/heatTransfer/heat_sst_bp_rdma.xml (92%) rename examples/{ => simulations}/heatTransfer/heat_sst_ffs.xml (91%) rename examples/{ => simulations}/heatTransfer/heat_sst_ffs_rdma.xml (92%) create mode 100644 examples/simulations/heatTransfer/inline/CMakeLists.txt rename examples/{ => simulations}/heatTransfer/inline/InlineIO.cpp (100%) rename examples/{ => simulations}/heatTransfer/inline/InlineIO.h (100%) rename examples/{ => simulations}/heatTransfer/inline/main.cpp (100%) create mode 100644 examples/simulations/heatTransfer/read/CMakeLists.txt rename examples/{ => simulations}/heatTransfer/read/PrintDataStep.h (100%) rename examples/{ => simulations}/heatTransfer/read/ReadSettings.cpp (100%) rename examples/{ => simulations}/heatTransfer/read/ReadSettings.h (100%) rename examples/{ => simulations}/heatTransfer/read/heatRead.cpp (100%) create mode 100644 examples/simulations/heatTransfer/readFileOnly/CMakeLists.txt rename examples/{heatTransfer/read_fileonly => simulations/heatTransfer/readFileOnly}/PrintData.h (100%) rename examples/{heatTransfer/read_fileonly/heatRead_adios2.cpp => simulations/heatTransfer/readFileOnly/heatReadFileOnly.cpp} (96%) create mode 100644 examples/simulations/heatTransfer/write/CMakeLists.txt rename examples/{ => simulations}/heatTransfer/write/HeatTransfer.cpp (100%) rename examples/{ => simulations}/heatTransfer/write/HeatTransfer.h (100%) rename examples/{ => simulations}/heatTransfer/write/IO.h (100%) rename examples/{ => simulations}/heatTransfer/write/IO_adios2.cpp (99%) rename examples/{ => simulations}/heatTransfer/write/IO_ascii.cpp (100%) rename examples/{ => simulations}/heatTransfer/write/IO_h5mixer.cpp (100%) rename examples/{ => simulations}/heatTransfer/write/IO_hdf5_a.cpp (96%) rename examples/{ => simulations}/heatTransfer/write/IO_ph5.cpp (100%) rename examples/{ => simulations}/heatTransfer/write/Settings.cpp (100%) rename examples/{ => simulations}/heatTransfer/write/Settings.h (100%) rename examples/{ => simulations}/heatTransfer/write/main.cpp (100%) create mode 100644 examples/useCases/fidesOneCell/CMakeLists.txt create mode 100644 examples/useCases/fidesOneCell/ReadMe.md rename examples/{fides/01_onecell/fides_onecell.cpp => useCases/fidesOneCell/fidesOneCell.cpp} (97%) rename examples/{fides/01_onecell/fides_onecell.json => useCases/fidesOneCell/fidesOneCell.json} (100%) rename examples/{fides/01_onecell => useCases/fidesOneCell}/paraview-onecell-step0.png (100%) rename examples/{fides/01_onecell => useCases/fidesOneCell}/paraview-onecell-step9.png (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3f223ed14..90122c6507 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,7 +176,7 @@ if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) if(DEFINED Kokkos_CUDA_ARCHITECTURES) set(CMAKE_CUDA_ARCHITECTURES ${Kokkos_CUDA_ARCHITECTURES}) else() - # Mininum common non-deprecated architecture + # Minimum common non-deprecated architecture set(CMAKE_CUDA_ARCHITECTURES 52) endif() endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3187dc3f49..316e77723e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,24 +5,6 @@ add_subdirectory(basics) add_subdirectory(hello) -add_subdirectory(query) -add_subdirectory(useCases) -add_subdirectory(inlineMWE) add_subdirectory(plugins) -add_subdirectory(fides) - -if(ADIOS2_HAVE_MPI) - add_subdirectory(heatTransfer) -endif() - - -if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) - add_subdirectory(cuda) -endif() - - -if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_HDF5) - if(HDF5_VERSION VERSION_GREATER_EQUAL 1.14) - add_subdirectory(h5subfile) - endif() -endif() +add_subdirectory(simulations) +add_subdirectory(useCases) diff --git a/examples/basics/CMakeLists.txt b/examples/basics/CMakeLists.txt index 94fa54cd4c..7e470c02d1 100644 --- a/examples/basics/CMakeLists.txt +++ b/examples/basics/CMakeLists.txt @@ -3,7 +3,10 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_subdirectory(globalArray) +add_subdirectory(globalArrayND) add_subdirectory(joinedArray) add_subdirectory(localArray) +if(ADIOS2_HAVE_DATAMAN) + add_subdirectory(queryWorker) +endif() add_subdirectory(values) diff --git a/examples/basics/globalArray/CMakeLists.txt b/examples/basics/globalArray/CMakeLists.txt deleted file mode 100644 index a145a8939b..0000000000 --- a/examples/basics/globalArray/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(globalArray_write globalArray_write.cpp) -target_link_libraries(globalArray_write adios2::cxx11) - -if(ADIOS2_HAVE_MPI) - add_executable(globalArray_write_mpi globalArray_write.cpp) - target_link_libraries(globalArray_write_mpi adios2::cxx11_mpi MPI::MPI_C) -endif() diff --git a/examples/basics/globalArrayND/CMakeLists.txt b/examples/basics/globalArrayND/CMakeLists.txt new file mode 100644 index 0000000000..f1d131c5fa --- /dev/null +++ b/examples/basics/globalArrayND/CMakeLists.txt @@ -0,0 +1,31 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsGlobalArrayNDExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_globalArrayNDWrite globalArrayNDWrite.cpp) +target_link_libraries(adios2_basics_globalArrayNDWrite adios2::cxx11) +install(TARGETS adios2_basics_globalArrayNDWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_basics_globalArrayNDWrite_mpi globalArrayNDWrite.cpp) + target_link_libraries(adios2_basics_globalArrayNDWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_globalArrayNDWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/basics/globalArray/globalArray_write.cpp b/examples/basics/globalArrayND/globalArrayNDWrite.cpp similarity index 100% rename from examples/basics/globalArray/globalArray_write.cpp rename to examples/basics/globalArrayND/globalArrayNDWrite.cpp diff --git a/examples/basics/joinedArray/CMakeLists.txt b/examples/basics/joinedArray/CMakeLists.txt index 0ac015c3a1..a342d75293 100644 --- a/examples/basics/joinedArray/CMakeLists.txt +++ b/examples/basics/joinedArray/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(joinedArray_write joinedArray_write.cpp) -target_link_libraries(joinedArray_write adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsJoinedArrayExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_joinedArrayWrite joinedArrayWrite.cpp) +target_link_libraries(adios2_basics_joinedArrayWrite adios2::cxx11) +install(TARGETS adios2_basics_joinedArrayWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(joinedArray_write_mpi joinedArray_write.cpp) - target_link_libraries(joinedArray_write_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_basics_joinedArrayWrite_mpi joinedArrayWrite.cpp) + target_link_libraries(adios2_basics_joinedArrayWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_joinedArrayWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/basics/joinedArray/joinedArray_write.cpp b/examples/basics/joinedArray/joinedArrayWrite.cpp similarity index 100% rename from examples/basics/joinedArray/joinedArray_write.cpp rename to examples/basics/joinedArray/joinedArrayWrite.cpp diff --git a/examples/basics/localArray/CMakeLists.txt b/examples/basics/localArray/CMakeLists.txt index 1d304a647e..a43a61550f 100644 --- a/examples/basics/localArray/CMakeLists.txt +++ b/examples/basics/localArray/CMakeLists.txt @@ -3,13 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(localArray_write localArray_write.cpp) -target_link_libraries(localArray_write adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsLocalArrayExample) -add_executable(localArray_read localArray_read.cpp) -target_link_libraries(localArray_read adios2::cxx11) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_localArrayWrite localArrayWrite.cpp) +target_link_libraries(adios2_basics_localArrayWrite adios2::cxx11) +install(TARGETS adios2_basics_localArrayWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_basics_localArrayRead localArrayRead.cpp) +target_link_libraries(adios2_basics_localArrayRead adios2::cxx11) +install(TARGETS adios2_basics_localArrayRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(localArray_write_mpi localArray_write.cpp) - target_link_libraries(localArray_write_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_basics_localArrayWrite_mpi localArrayWrite.cpp) + target_link_libraries(adios2_basics_localArrayWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_localArrayWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/basics/localArray/localArray_read.cpp b/examples/basics/localArray/localArrayRead.cpp similarity index 100% rename from examples/basics/localArray/localArray_read.cpp rename to examples/basics/localArray/localArrayRead.cpp diff --git a/examples/basics/localArray/localArray_write.cpp b/examples/basics/localArray/localArrayWrite.cpp similarity index 100% rename from examples/basics/localArray/localArray_write.cpp rename to examples/basics/localArray/localArrayWrite.cpp diff --git a/examples/basics/queryWorker/CMakeLists.txt b/examples/basics/queryWorker/CMakeLists.txt new file mode 100644 index 0000000000..839dd19bf2 --- /dev/null +++ b/examples/basics/queryWorker/CMakeLists.txt @@ -0,0 +1,30 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsQueryWorkerExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ZeroMQ 4.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_DataMan) + add_executable(adios2_basics_queryWorker queryWorker.cpp) + target_link_libraries(adios2_basics_queryWorker adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_queryWorker RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + diff --git a/examples/query/READ.ME b/examples/basics/queryWorker/README.md similarity index 100% rename from examples/query/READ.ME rename to examples/basics/queryWorker/README.md diff --git a/examples/query/configs/bp4io.xml b/examples/basics/queryWorker/configs/bp4io.xml similarity index 99% rename from examples/query/configs/bp4io.xml rename to examples/basics/queryWorker/configs/bp4io.xml index 65245c97e6..d921181b65 100644 --- a/examples/query/configs/bp4io.xml +++ b/examples/basics/queryWorker/configs/bp4io.xml @@ -1,6 +1,6 @@ diff --git a/examples/query/configs/bp4io_composite.xml b/examples/basics/queryWorker/configs/bp4io_composite.xml similarity index 98% rename from examples/query/configs/bp4io_composite.xml rename to examples/basics/queryWorker/configs/bp4io_composite.xml index 4e6136b4e4..412f883bcd 100644 --- a/examples/query/configs/bp4io_composite.xml +++ b/examples/basics/queryWorker/configs/bp4io_composite.xml @@ -1,7 +1,7 @@ diff --git a/examples/query/configs/q1.json b/examples/basics/queryWorker/configs/q1.json similarity index 100% rename from examples/query/configs/q1.json rename to examples/basics/queryWorker/configs/q1.json diff --git a/examples/query/configs/q2.json b/examples/basics/queryWorker/configs/q2.json similarity index 100% rename from examples/query/configs/q2.json rename to examples/basics/queryWorker/configs/q2.json diff --git a/examples/query/test.cpp b/examples/basics/queryWorker/queryWorker.cpp similarity index 75% rename from examples/query/test.cpp rename to examples/basics/queryWorker/queryWorker.cpp index b97a2d7714..2f172a18f0 100644 --- a/examples/query/test.cpp +++ b/examples/basics/queryWorker/queryWorker.cpp @@ -99,41 +99,3 @@ int main(int argc, char *argv[]) return 0; } - -bool testMe(std::string &queryConfigFile, std::string const &doubleVarName, MPI_Comm comm) -{ - adios2::ADIOS ad(queryConfigFile, comm); - std::string dataFileName = "test.file"; - - // adios2::query::Worker w(queryConfigFile, comm); - - // w.SetSource(inIO, reader); - - { - // the config file should have info on idx method to use - - /* - // if wanting to build customized minmax idx - // instead of using the existing block stats or bp4 minmax arrays - bool overwrite = false; - size_t recommendedSize = 20000; - - if (!w.PrepareIdx(overwrite, recommendedSize, doubleVarName)) - return false; - */ - } - - adios2::IO inIO = ad.DeclareIO("query"); - adios2::Engine reader = inIO.Open(dataFileName, adios2::Mode::Read, comm); - - // to be continued - if (!reader) - return false; - // std::vector dataOutput; - // std::vector coordinateOutput; - - return true; -} - -/* - */ diff --git a/examples/basics/values/CMakeLists.txt b/examples/basics/values/CMakeLists.txt index f36b4c745a..799c72cc54 100644 --- a/examples/basics/values/CMakeLists.txt +++ b/examples/basics/values/CMakeLists.txt @@ -3,10 +3,30 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(values_write values_write.cpp) -target_link_libraries(values_write adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsValuesExample) + +if(NOT TARGET adios2_core) + set(_components C) + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_valuesWrite valuesWrite.cpp) +target_link_libraries(adios2_basics_valuesWrite adios2::cxx11) +install(TARGETS adios2_basics_valuesWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(values_write_mpi values_write.cpp) - target_link_libraries(values_write_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_basics_valuesWrite_mpi valuesWrite.cpp) + target_link_libraries(adios2_basics_valuesWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_valuesWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/basics/values/values_write.cpp b/examples/basics/values/valuesWrite.cpp similarity index 100% rename from examples/basics/values/values_write.cpp rename to examples/basics/values/valuesWrite.cpp diff --git a/examples/cuda/CMakeLists.txt b/examples/cuda/CMakeLists.txt deleted file mode 100644 index 6a613392f4..0000000000 --- a/examples/cuda/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(CudaBPWriteRead_cuda cudaBPWriteRead.cu) -target_link_libraries(CudaBPWriteRead_cuda PUBLIC adios2::cxx11 CUDA::cudart) -set_target_properties(CudaBPWriteRead_cuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) diff --git a/examples/fides/01_onecell/CMakeLists.txt b/examples/fides/01_onecell/CMakeLists.txt deleted file mode 100644 index e553b37ccc..0000000000 --- a/examples/fides/01_onecell/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(fides_onecell fides_onecell.cpp) -target_link_libraries(fides_onecell adios2::cxx11) diff --git a/examples/fides/01_onecell/README.md b/examples/fides/01_onecell/README.md deleted file mode 100644 index d55174b571..0000000000 --- a/examples/fides/01_onecell/README.md +++ /dev/null @@ -1,28 +0,0 @@ -Single cell example for visualization with Fides schema in ParaView -------------------------------------------------------------------- - -This example writes 8 points in 3D space, the corners of a box, and then defines a single hexagon cell of those eight points. -The coordinates of the points are stored in three 1D arrays, separating the X-Y-Z coordinates. - -The cell is the enumeration of the points connected in the order of a hexagon prescribed by VTK, see -Figure 19-20 in the VTK User Guide, type VTK_HEXAHEDRON in page 480 (page 494 in the PDF). -https://vtk.org/wp-content/uploads/2021/08/VTKUsersGuide.pdf - -The visualization schema is described in the fides-onecell.json file, according to https://fides.readthedocs.io/en/latest/schema/schema.html - -We compose the coordinate system as a composite of the three 1D arrays for X, Y and Z coordinates. This is just an enumeration of the N points in space (N = size of X = size of Y = size of Z) , in contrast to other examples where X, Y, Z is combined to specify a structured grid (number of points = size of X * size of Y * size of Z). - -In ParaView, one opens the fides-onecell.json file and adds an property "source" with the value of the full path of the onecell.bp. See left-middle Properties box in the ParaView window in the image paraview-onecell-step0.png. Then hit Apply button and a gray box should appear (the single cell visualized). which can be rotated on screen. Then one must color the box with the data ("pointdata") to get the pictures shown in the included images. - -Note that the dataset over the points is called "DataOnPoints" in the onecell.bp file, but it is called "pointdata" in the Fides schema to demonstrate which name is which (ParaView presents pointdata to the user while reading the DataOnPoints array from the file). - -First step of onecell.bp in ParaView: - -paraview-onecell-step0.png - -Last step of onecell.bp in ParaView: - -paraview-onecell-step9.png - diff --git a/examples/fides/CMakeLists.txt b/examples/fides/CMakeLists.txt deleted file mode 100644 index 98d3e0e647..0000000000 --- a/examples/fides/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_subdirectory(01_onecell) diff --git a/examples/h5subfile/CMakeLists.txt b/examples/h5subfile/CMakeLists.txt deleted file mode 100644 index 0d94ae241b..0000000000 --- a/examples/h5subfile/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -if(ADIOS2_HAVE_MPI) - add_executable(H5EngineSubfileTest h5_subfile.cpp) - target_link_libraries(H5EngineSubfileTest adios2::cxx11_mpi MPI::MPI_C) -endif() - diff --git a/examples/heatTransfer/inline/CMakeLists.txt b/examples/heatTransfer/inline/CMakeLists.txt deleted file mode 100644 index 54fd8de038..0000000000 --- a/examples/heatTransfer/inline/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_inline_adios2 - main.cpp - InlineIO.cpp - ../write/HeatTransfer.cpp - ../write/Settings.cpp -) -target_link_libraries(heatTransfer_inline_adios2 - adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} -) diff --git a/examples/heatTransfer/read/CMakeLists.txt b/examples/heatTransfer/read/CMakeLists.txt deleted file mode 100644 index dd1adbe0cb..0000000000 --- a/examples/heatTransfer/read/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_read - heatRead.cpp - PrintDataStep.h - ReadSettings.cpp -) -target_link_libraries(heatTransfer_read adios2::cxx11_mpi MPI::MPI_C) diff --git a/examples/heatTransfer/read_fileonly/CMakeLists.txt b/examples/heatTransfer/read_fileonly/CMakeLists.txt deleted file mode 100644 index d0ab4b830b..0000000000 --- a/examples/heatTransfer/read_fileonly/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_read_fileonly_adios2 heatRead_adios2.cpp PrintData.h) -target_link_libraries(heatTransfer_read_fileonly_adios2 adios2::cxx11_mpi MPI::MPI_C) - -#if(ADIOS2_HAVE_HDF5) - #add_executable(heatTransfer_read_fileonly_h5_mpi heatRead_h5.cpp PrintData.h) - #target_link_libraries(heatTransfer_read_fileonly_h5_mpi adios2::cxx11_mpi MPI::MPI_C) -#endif() diff --git a/examples/heatTransfer/read_fileonly/heatRead_adios1.cpp b/examples/heatTransfer/read_fileonly/heatRead_adios1.cpp deleted file mode 100644 index c727a9e825..0000000000 --- a/examples/heatTransfer/read_fileonly/heatRead_adios1.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "PrintData.h" - -int main(int argc, char *argv[]) -{ - MPI_Init(&argc, &argv); - - if (argc < 2) - { - std::cout << "Not enough arguments: need an input file\n"; - return 1; - } - const char *inputfile = argv[1]; - - /* 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 the reader 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); - - const unsigned int color = 2; - MPI_Comm mpiReaderComm; - MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &mpiReaderComm); - - int rank, nproc; - MPI_Comm_rank(mpiReaderComm, &rank); - MPI_Comm_size(mpiReaderComm, &nproc); - - adios_read_init_method(ADIOS_READ_METHOD_BP, mpiReaderComm, "verbose=3"); - - ADIOS_FILE *f; - f = adios_read_open_file(inputfile, ADIOS_READ_METHOD_BP, mpiReaderComm); - if (f == NULL) - { - std::cout << adios_errmsg() << std::endl; - return -1; - } - - ADIOS_VARINFO *vgndx = adios_inq_var(f, "gndx"); - ADIOS_VARINFO *vgndy = adios_inq_var(f, "gndy"); - - unsigned int gndx = *(unsigned int *)vgndx->value; - unsigned int gndy = *(unsigned int *)vgndy->value; - - if (rank == 0) - { - std::cout << "gndx = " << gndx << std::endl; - std::cout << "gndy = " << gndy << std::endl; - } - adios_free_varinfo(vgndx); - adios_free_varinfo(vgndy); - - // 1D decomposition of the columns, which is inefficient for reading! - uint64_t readsize[2] = {gndx, gndy / nproc}; - uint64_t offset[2] = {0LL, rank * readsize[1]}; - if (rank == nproc - 1) - { - // last process should read all the rest of columns - readsize[1] = gndy - readsize[1] * (nproc - 1); - } - - std::cout << "rank " << rank << " reads " << readsize[1] << " columns from offset " << offset[1] - << std::endl; - - ADIOS_VARINFO *vT = adios_inq_var(f, "T"); - - double *T = new double[vT->nsteps * readsize[0] * readsize[1]]; - - // Create a 2D selection for the subset - ADIOS_SELECTION *sel = adios_selection_boundingbox(2, offset, readsize); - - // Arrays are read by scheduling one or more of them - // and performing the reads at once - adios_schedule_read(f, sel, "T", 0, vT->nsteps, T); - adios_perform_reads(f, 1); - - printData(T, readsize, offset, rank, vT->nsteps); - adios_read_close(f); - adios_free_varinfo(vT); - delete[] T; - // Terminate - adios_selection_delete(sel); - adios_read_finalize_method(ADIOS_READ_METHOD_BP); - MPI_Finalize(); - return 0; -} diff --git a/examples/heatTransfer/write/CMakeLists.txt b/examples/heatTransfer/write/CMakeLists.txt deleted file mode 100644 index 268b05fe28..0000000000 --- a/examples/heatTransfer/write/CMakeLists.txt +++ /dev/null @@ -1,66 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_write_adios2 - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_adios2.cpp -) -target_link_libraries(heatTransfer_write_adios2 - adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} -) - -add_executable(heatTransfer_write_ascii - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_ascii.cpp -) -target_link_libraries(heatTransfer_write_ascii - MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} -) - -if(ADIOS2_HAVE_HDF5) - add_executable(heatTransfer_write_hdf5 - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_hdf5_a.cpp - ) - target_include_directories(heatTransfer_write_hdf5 - PRIVATE ${HDF5_C_INCLUDE_DIRS} - ) - target_link_libraries(heatTransfer_write_hdf5 - ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} - ) - - if(HDF5_IS_PARALLEL) - add_executable(heatTransfer_write_ph5 - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_ph5.cpp - ) - target_include_directories(heatTransfer_write_ph5 - PRIVATE ${HDF5_C_INCLUDE_DIRS} - ) - target_link_libraries(heatTransfer_write_ph5 - ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} - ) - endif() - - if(NOT (HDF5_VERSION VERSION_LESS 1.11)) - add_executable(heatTransfer_write_h5mixer - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_h5mixer.cpp - ) - target_link_libraries(heatTransfer_write_h5mixer - adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} - ) - endif() -endif() diff --git a/examples/hello/CMakeLists.txt b/examples/hello/CMakeLists.txt index 1de325635a..dd90609718 100644 --- a/examples/hello/CMakeLists.txt +++ b/examples/hello/CMakeLists.txt @@ -3,13 +3,16 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_subdirectory(bpWriter) +add_subdirectory(bpAttributeWriter) +add_subdirectory(bpFlushWriter) + +if(ADIOS2_HAVE_MPI) + add_subdirectory(bpFWriteCRead) +endif() + add_subdirectory(bpReader) add_subdirectory(bpTimeWriter) -add_subdirectory(bpFlushWriter) -add_subdirectory(bpAttributeWriter) -add_subdirectory(inlineReaderWriter) -add_subdirectory(skeleton) +add_subdirectory(bpWriter) if(ADIOS2_HAVE_DataMan) add_subdirectory(datamanReader) @@ -21,20 +24,23 @@ if(ADIOS2_HAVE_DataSpaces) add_subdirectory(dataspacesWriter) endif() -if(ADIOS2_HAVE_SST) - add_subdirectory(sstReader) - add_subdirectory(sstWriter) -endif() - if(ADIOS2_HAVE_HDF5) add_subdirectory(hdf5Writer) add_subdirectory(hdf5Reader) + if(HDF5_VERSION VERSION_GREATER_EQUAL 1.14) + add_subdirectory(hdf5SubFile) + endif() endif() -if(ADIOS2_HAVE_MPI) - add_subdirectory(bpFWriteCRead) +if(ADIOS2_HAVE_Fortran) + add_subdirectory(inlineFWriteCppRead) endif() -if(ADIOS2_HAVE_Fortran) - add_subdirectory(inlineFWriteCppRead) +add_subdirectory(inlineMWE) +add_subdirectory(inlineReaderWriter) +add_subdirectory(skeleton) + +if(ADIOS2_HAVE_SST) + add_subdirectory(sstReader) + add_subdirectory(sstWriter) endif() diff --git a/examples/hello/bpAttributeWriter/CMakeLists.txt b/examples/hello/bpAttributeWriter/CMakeLists.txt index 6222de2122..c5eaf598e3 100644 --- a/examples/hello/bpAttributeWriter/CMakeLists.txt +++ b/examples/hello/bpAttributeWriter/CMakeLists.txt @@ -3,12 +3,30 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpAttributeWriter helloBPAttributeWriter_nompi.cpp) -target_link_libraries(hello_bpAttributeWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPAttributeWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpAttributeWriter bpAttributeWriter_nompi.cpp) +target_link_libraries(adios2_hello_bpAttributeWriter adios2::cxx11) +install(TARGETS adios2_hello_bpAttributeWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - find_package(MPI COMPONENTS C REQUIRED) - add_executable(hello_bpAttributeWriter_mpi helloBPAttributeWriter.cpp) - target_link_libraries(hello_bpAttributeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpAttributeWriter_mpi bpAttributeWriter.cpp) + target_link_libraries(adios2_hello_bpAttributeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpAttributeWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/bpAttributeWriter/helloBPAttributeWriter.cpp b/examples/hello/bpAttributeWriter/bpAttributeWriter.cpp similarity index 97% rename from examples/hello/bpAttributeWriter/helloBPAttributeWriter.cpp rename to examples/hello/bpAttributeWriter/bpAttributeWriter.cpp index dce3946fa1..beb376d434 100644 --- a/examples/hello/bpAttributeWriter/helloBPAttributeWriter.cpp +++ b/examples/hello/bpAttributeWriter/bpAttributeWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter.cpp: Simple self-descriptive example of how to write a variable + * bpAttributeWriter.cpp: Simple self-descriptive example of how to write a variable * to a BP File that lives in several MPI processes. * * Created on: Feb 16, 2017 diff --git a/examples/hello/bpAttributeWriter/helloBPAttributeWriter_nompi.cpp b/examples/hello/bpAttributeWriter/bpAttributeWriter_nompi.cpp similarity index 96% rename from examples/hello/bpAttributeWriter/helloBPAttributeWriter_nompi.cpp rename to examples/hello/bpAttributeWriter/bpAttributeWriter_nompi.cpp index 9b9fedd9ab..0a01f808fc 100644 --- a/examples/hello/bpAttributeWriter/helloBPAttributeWriter_nompi.cpp +++ b/examples/hello/bpAttributeWriter/bpAttributeWriter_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter_nompi.cpp sequential non-mpi version of helloBPWriter + * bpAttributeWriter_nompi.cpp sequential non-mpi version of bpAttributeWriter * * Created on: Jan 9, 2017 * Author: William F Godoy godoywf@ornl.gov diff --git a/examples/hello/bpFWriteCRead/CMakeLists.txt b/examples/hello/bpFWriteCRead/CMakeLists.txt index ff5dcc1b2b..759d6919c6 100644 --- a/examples/hello/bpFWriteCRead/CMakeLists.txt +++ b/examples/hello/bpFWriteCRead/CMakeLists.txt @@ -3,18 +3,49 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(CppWriter CppWriter.cpp) -target_link_libraries(CppWriter adios2::cxx11_mpi MPI::MPI_C) - -add_executable(CppReader CppReader.cpp) -target_link_libraries(CppReader adios2::cxx11_mpi MPI::MPI_C) - -if(ADIOS2_HAVE_Fortran) - add_executable(FWriter FWriter.f90) - add_executable(FReader FReader.f90) - target_link_libraries(FWriter adios2::fortran_mpi MPI::MPI_Fortran) - target_link_libraries(FReader adios2::fortran_mpi MPI::MPI_Fortran) - set_target_properties(FWriter FReader PROPERTIES - LINKER_LANGUAGE Fortran - ) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPFWriteCReadExample) + +if(NOT TARGET adios2_core) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if (ADIOS2_HAVE_MPI) + add_executable(adios2_hello_CppWriter CppWriter.cpp) + target_link_libraries(adios2_hello_CppWriter adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_CppWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_CppReader CppReader.cpp) + target_link_libraries(adios2_hello_CppReader adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_CppReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_Fortran) + add_executable(adios2_hello_FWriter FWriter.f90) + target_link_libraries(adios2_hello_FWriter adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_FWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_FReader FReader.f90) + target_link_libraries(adios2_hello_FReader adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_FReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/bpFlushWriter/CMakeLists.txt b/examples/hello/bpFlushWriter/CMakeLists.txt index 351282fa3c..61c78ebc7b 100644 --- a/examples/hello/bpFlushWriter/CMakeLists.txt +++ b/examples/hello/bpFlushWriter/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpFlushWriter helloBPFlushWriter_nompi.cpp) -target_link_libraries(hello_bpFlushWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPFlushWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpFlushWriter bpFlushWriter_nompi.cpp) +target_link_libraries(adios2_hello_bpFlushWriter adios2::cxx11) +install(TARGETS adios2_hello_bpFlushWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_bpFlushWriter_mpi helloBPFlushWriter.cpp) - target_link_libraries(hello_bpFlushWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpFlushWriter_mpi bpFlushWriter.cpp) + target_link_libraries(adios2_hello_bpFlushWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpFlushWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/bpFlushWriter/helloBPFlushWriter.cpp b/examples/hello/bpFlushWriter/bpFlushWriter.cpp similarity index 97% rename from examples/hello/bpFlushWriter/helloBPFlushWriter.cpp rename to examples/hello/bpFlushWriter/bpFlushWriter.cpp index bcdfc441f9..785ec43369 100644 --- a/examples/hello/bpFlushWriter/helloBPFlushWriter.cpp +++ b/examples/hello/bpFlushWriter/bpFlushWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPFlushWriter.cpp: Example that tests buffer overflow forcing a flush to + * bpFlushWriter.cpp: Example that tests buffer overflow forcing a flush to * transports when writing a large variable in independent N-to-N mode. This * will have performance penalties, but it's safer. * diff --git a/examples/hello/bpFlushWriter/helloBPFlushWriter_nompi.cpp b/examples/hello/bpFlushWriter/bpFlushWriter_nompi.cpp similarity index 96% rename from examples/hello/bpFlushWriter/helloBPFlushWriter_nompi.cpp rename to examples/hello/bpFlushWriter/bpFlushWriter_nompi.cpp index edd92663ac..f8480c4464 100644 --- a/examples/hello/bpFlushWriter/helloBPFlushWriter_nompi.cpp +++ b/examples/hello/bpFlushWriter/bpFlushWriter_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter_nompi.cpp sequential non-mpi version of helloBPWriter + * bpFlushWriter_nompi.cpp sequential non-mpi version of bpFlushWriter * * Created on: Jan 9, 2017 * Author: William F Godoy godoywf@ornl.gov diff --git a/examples/hello/bpReader/CMakeLists.txt b/examples/hello/bpReader/CMakeLists.txt index 462227301f..95be573537 100644 --- a/examples/hello/bpReader/CMakeLists.txt +++ b/examples/hello/bpReader/CMakeLists.txt @@ -3,28 +3,59 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpReader helloBPReader_nompi.cpp) -target_link_libraries(hello_bpReader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPReaderExample) -if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpReaderHeatMap3D_f helloBPReaderHeatMap3D.F90) - set_property(TARGET hello_bpReaderHeatMap3D_f PROPERTY LINKER_LANGUAGE Fortran) - target_link_libraries(hello_bpReaderHeatMap3D_f adios2::fortran) +if(NOT TARGET adios2::cxx11) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) endif() +add_executable(adios2_hello_bpReader bpReader_nompi.cpp) +target_link_libraries(adios2_hello_bpReader adios2::cxx11) +install(TARGETS adios2_hello_bpReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + if(ADIOS2_HAVE_MPI) - add_executable(hello_bpReader_mpi helloBPReader.cpp) - target_link_libraries(hello_bpReader_mpi adios2::cxx11_mpi MPI::MPI_C) - - add_executable(hello_bpReaderHeatMap2D helloBPReaderHeatMap2D.cpp) - target_link_libraries(hello_bpReaderHeatMap2D adios2::cxx11_mpi MPI::MPI_C) - - add_executable(hello_bpReaderHeatMap3D helloBPReaderHeatMap3D.cpp) - target_link_libraries(hello_bpReaderHeatMap3D adios2::cxx11_mpi MPI::MPI_C) - - if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpReaderHeatMap3D_f_mpi helloBPReaderHeatMap3D.F90) - target_link_libraries(hello_bpReaderHeatMap3D_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) - set_property(TARGET hello_bpReaderHeatMap3D_f_mpi PROPERTY LINKER_LANGUAGE Fortran) + add_executable(adios2_hello_bpReader_mpi bpReader.cpp) + target_link_libraries(adios2_hello_bpReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_bpReaderHeatMap2D bpReaderHeatMap2D.cpp) + target_link_libraries(adios2_hello_bpReaderHeatMap2D adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpReaderHeatMap2D RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_bpReaderHeatMap3D bpReaderHeatMap3D.cpp) + target_link_libraries(adios2_hello_bpReaderHeatMap3D adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpReaderHeatMap3D RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + +if(ADIOS2_HAVE_Fortran) + add_executable(adios2_hello_bpReaderHeatMap3D_f bpReaderHeatMap3D.F90) + target_link_libraries(adios2_hello_bpReaderHeatMap3D_f adios2::fortran) + install(TARGETS adios2_hello_bpReaderHeatMap3D_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_bpReaderHeatMap3D_f_mpi bpReaderHeatMap3D.F90) + target_link_libraries(adios2_hello_bpReaderHeatMap3D_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_bpReaderHeatMap3D_f_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endif() diff --git a/examples/hello/bpReader/helloBPReader.cpp b/examples/hello/bpReader/bpReader.cpp similarity index 97% rename from examples/hello/bpReader/helloBPReader.cpp rename to examples/hello/bpReader/bpReader.cpp index 9da7f3c83e..d873b76c3a 100644 --- a/examples/hello/bpReader/helloBPReader.cpp +++ b/examples/hello/bpReader/bpReader.cpp @@ -2,8 +2,8 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPReader.cpp: Simple self-descriptive example of how to read a variable - * to a BP File. + * bpReader.cpp: Simple self-descriptive example of how to read a variable + * from a BP File. * * Try running like this from the build directory: * mpirun -np 3 ./bin/hello_bpReader diff --git a/examples/hello/bpReader/helloBPReaderHeatMap2D.cpp b/examples/hello/bpReader/bpReaderHeatMap2D.cpp similarity index 98% rename from examples/hello/bpReader/helloBPReaderHeatMap2D.cpp rename to examples/hello/bpReader/bpReaderHeatMap2D.cpp index 184d5730c2..46df44ce90 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap2D.cpp +++ b/examples/hello/bpReader/bpReaderHeatMap2D.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPReaderHeatMap.cpp : Writes a heat map in a regular 2D mesh, + * bpReaderHeatMap2D.cpp : Writes a heat map in a regular 2D mesh, * values grow from 0 in increments of 1 * * temperature[gNx, Ny] diff --git a/examples/hello/bpReader/helloBPReaderHeatMap2D.py b/examples/hello/bpReader/bpReaderHeatMap2D.py similarity index 75% rename from examples/hello/bpReader/helloBPReaderHeatMap2D.py rename to examples/hello/bpReader/bpReaderHeatMap2D.py index 9aa8925a39..ea63fee022 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap2D.py +++ b/examples/hello/bpReader/bpReaderHeatMap2D.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloBPReaderHeatMap2D.py +# bpReaderHeatMap2D.py # # # Created on: Dec 5th, 2017 @@ -41,10 +41,11 @@ adios = adios2.ADIOS(comm) ioWrite = adios.DeclareIO("ioWriter") -varTemperature = ioWrite.DefineVariable("temperature2D", temperatures, shape, - start, count, adios2.ConstantDims) +varTemperature = ioWrite.DefineVariable( + "temperature2D", temperatures, shape, start, count, adios2.ConstantDims +) -obpStream = ioWrite.Open('HeatMap2D_py.bp', adios2.Mode.Write) +obpStream = ioWrite.Open("HeatMap2D_py.bp", adios2.Mode.Write) obpStream.Put(varTemperature, temperatures) obpStream.Close() @@ -52,7 +53,7 @@ if rank == 0: ioRead = adios.DeclareIO("ioReader") - ibpStream = ioRead.Open('HeatMap2D_py.bp', adios2.Mode.Read, MPI.COMM_SELF) + ibpStream = ioRead.Open("HeatMap2D_py.bp", adios2.Mode.Read, MPI.COMM_SELF) var_inTemperature = ioRead.InquireVariable("temperature2D") @@ -60,15 +61,15 @@ var_inTemperature.SetSelection([[2, 2], [4, 4]]) inSize = var_inTemperature.SelectionSize() - print('Incoming size ' + str(inSize)) + print("Incoming size " + str(inSize)) inTemperatures = numpy.zeros(inSize, dtype=numpy.int) ibpStream.Get(var_inTemperature, inTemperatures, adios2.Mode.Sync) - print('Incoming temperature map') + print("Incoming temperature map") for i in range(0, inTemperatures.size): - print(str(inTemperatures[i]) + ' ') + print(str(inTemperatures[i]) + " ") if (i + 1) % 4 == 0: print() diff --git a/examples/hello/bpReader/helloBPReaderHeatMap3D.F90 b/examples/hello/bpReader/bpReaderHeatMap3D.F90 similarity index 98% rename from examples/hello/bpReader/helloBPReaderHeatMap3D.F90 rename to examples/hello/bpReader/bpReaderHeatMap3D.F90 index e44d9c53bf..3bd7251e89 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap3D.F90 +++ b/examples/hello/bpReader/bpReaderHeatMap3D.F90 @@ -1,4 +1,4 @@ -program helloBPReaderHeatMap3D +program bpReaderHeatMap3D #if ADIOS2_USE_MPI use mpi #endif @@ -130,4 +130,4 @@ program helloBPReaderHeatMap3D call MPI_Finalize(ierr) #endif -end program helloBPReaderHeatMap3D +end program bpReaderHeatMap3D diff --git a/examples/hello/bpReader/helloBPReaderHeatMap3D.cpp b/examples/hello/bpReader/bpReaderHeatMap3D.cpp similarity index 100% rename from examples/hello/bpReader/helloBPReaderHeatMap3D.cpp rename to examples/hello/bpReader/bpReaderHeatMap3D.cpp diff --git a/examples/hello/bpReader/helloBPReader_nompi.cpp b/examples/hello/bpReader/bpReader_nompi.cpp similarity index 97% rename from examples/hello/bpReader/helloBPReader_nompi.cpp rename to examples/hello/bpReader/bpReader_nompi.cpp index 629fa2e1f9..b2651d17fa 100644 --- a/examples/hello/bpReader/helloBPReader_nompi.cpp +++ b/examples/hello/bpReader/bpReader_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPReader.cpp: Simple self-descriptive example of how to read a variable + * bpReader_nompi.cpp: Simple self-descriptive example of how to read a variable * from a BP File. * * Created on: Feb 16, 2017 diff --git a/examples/hello/bpTimeWriter/CMakeLists.txt b/examples/hello/bpTimeWriter/CMakeLists.txt index 5306bbd375..30a9f1d361 100644 --- a/examples/hello/bpTimeWriter/CMakeLists.txt +++ b/examples/hello/bpTimeWriter/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpTimeWriter helloBPTimeWriter_nompi.cpp) -target_link_libraries(hello_bpTimeWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPTimeWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpTimeWriter bpTimeWriter_nompi.cpp) +target_link_libraries(adios2_hello_bpTimeWriter adios2::cxx11) +install(TARGETS adios2_hello_bpTimeWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_bpTimeWriter_mpi helloBPTimeWriter.cpp) - target_link_libraries(hello_bpTimeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpTimeWriter_mpi bpTimeWriter.cpp) + target_link_libraries(adios2_hello_bpTimeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpTimeWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/bpTimeWriter/helloBPTimeWriter.cpp b/examples/hello/bpTimeWriter/bpTimeWriter.cpp similarity index 98% rename from examples/hello/bpTimeWriter/helloBPTimeWriter.cpp rename to examples/hello/bpTimeWriter/bpTimeWriter.cpp index eab24b40e9..77e37389cc 100644 --- a/examples/hello/bpTimeWriter/helloBPTimeWriter.cpp +++ b/examples/hello/bpTimeWriter/bpTimeWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPTimeWriter.cpp example for writing a variable using the Advance + * bpTimeWriter.cpp example for writing a variable using the Advance * function for time aggregation. Time step is saved as an additional (global) * single value variable, just for tracking purposes. * diff --git a/examples/hello/bpTimeWriter/helloBPTimeWriter.py b/examples/hello/bpTimeWriter/bpTimeWriter.py similarity index 87% rename from examples/hello/bpTimeWriter/helloBPTimeWriter.py rename to examples/hello/bpTimeWriter/bpTimeWriter.py index 4ddff5a1aa..87afc7f1c1 100644 --- a/examples/hello/bpTimeWriter/helloBPTimeWriter.py +++ b/examples/hello/bpTimeWriter/bpTimeWriter.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# test_hello.py +# bpTimeWriter.py # Created on: Feb 2, 2017 # Author: William F Godoy godoywf@ornl.gov @@ -28,8 +28,9 @@ bpIO = adios.DeclareIO("BPN2N") # Variables -bpArray = bpIO.DefineVariable("bpArray", myArray, [size * nx], [rank * nx], - [nx], adios2.ConstantDims) +bpArray = bpIO.DefineVariable( + "bpArray", myArray, [size * nx], [rank * nx], [nx], adios2.ConstantDims +) bpTimeStep = bpIO.DefineVariable("bpTimeStep", time) # Engine diff --git a/examples/hello/bpTimeWriter/helloBPTimeWriter_nompi.cpp b/examples/hello/bpTimeWriter/bpTimeWriter_nompi.cpp similarity index 96% rename from examples/hello/bpTimeWriter/helloBPTimeWriter_nompi.cpp rename to examples/hello/bpTimeWriter/bpTimeWriter_nompi.cpp index 9165189504..ddfd113fa4 100644 --- a/examples/hello/bpTimeWriter/helloBPTimeWriter_nompi.cpp +++ b/examples/hello/bpTimeWriter/bpTimeWriter_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPTimeWriter_nompi.cpp no mpi version of helloBPTimeWriter.cpp + * bpTimeWriter_nompi.cpp no mpi version of bpTimeWriter.cpp * * Created on: Feb 16, 2017 * Author: William F Godoy godoywf@ornl.gov diff --git a/examples/hello/bpWriteReadCuda/CMakeLists.txt b/examples/hello/bpWriteReadCuda/CMakeLists.txt new file mode 100644 index 0000000000..453867f0b4 --- /dev/null +++ b/examples/hello/bpWriteReadCuda/CMakeLists.txt @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriteReadCudaExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(CUDAToolkit REQUIRED) + if(CUDAToolkit_FOUND) + enable_language(CUDA) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) + add_executable(adios2_hello_bpWriteReadCuda bpWriteReadCuda.cu) + target_link_libraries(adios2_hello_bpWriteReadCuda PUBLIC adios2::cxx11 CUDA::cudart) + set_target_properties(adios2_hello_bpWriteReadCuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + install(TARGETS adios2_hello_bpWriteReadCuda RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/cuda/cudaBPWriteRead.cu b/examples/hello/bpWriteReadCuda/bpWriteReadCuda.cu similarity index 96% rename from examples/cuda/cudaBPWriteRead.cu rename to examples/hello/bpWriteReadCuda/bpWriteReadCuda.cu index 1d2dcd4eda..953ae92924 100644 --- a/examples/cuda/cudaBPWriteRead.cu +++ b/examples/hello/bpWriteReadCuda/bpWriteReadCuda.cu @@ -1,4 +1,7 @@ /* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * * Simple example of writing and reading data * through ADIOS2 BP engine with multiple simulations steps * for every IO step. diff --git a/examples/hello/bpWriter/CMakeLists.txt b/examples/hello/bpWriter/CMakeLists.txt index aad594f556..0e48312f8c 100644 --- a/examples/hello/bpWriter/CMakeLists.txt +++ b/examples/hello/bpWriter/CMakeLists.txt @@ -3,50 +3,89 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpWriter helloBPWriter.cpp) -target_link_libraries(hello_bpWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriterExample) -add_executable(hello_bpWriter_c helloBPWriter.c) -target_link_libraries(hello_bpWriter_c adios2::c) +if(NOT TARGET adios2_core) + set(_components C) -add_executable(hello_bpPutDeferred helloBPPutDeferred.cpp) -target_link_libraries(hello_bpPutDeferred adios2::cxx11) + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(SZ QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpWriter bpWriter.cpp) +target_link_libraries(adios2_hello_bpWriter adios2::cxx11) +install(TARGETS adios2_hello_bpWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_bpWriter_c bpWriter.c) +target_link_libraries(adios2_hello_bpWriter_c adios2::c) +install(TARGETS adios2_hello_bpWriter_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_bpPutDeferred bpPutDeferred.cpp) +target_link_libraries(adios2_hello_bpPutDeferred adios2::cxx11) +install(TARGETS adios2_hello_bpPutDeferred RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_executable(hello_bpSubStreams helloBPSubStreams.cpp) -target_link_libraries(hello_bpSubStreams adios2::cxx11) +add_executable(adios2_hello_bpSubStreams bpSubStreams.cpp) +target_link_libraries(adios2_hello_bpSubStreams adios2::cxx11) +install(TARGETS adios2_hello_bpSubStreams RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_SZ) - add_executable(hello_bpSZ helloBPSZ.cpp) - target_link_libraries(hello_bpSZ adios2::cxx11) + add_executable(adios2_hello_bpSZ bpSZ.cpp) + target_link_libraries(adios2_hello_bpSZ adios2::cxx11) + install(TARGETS adios2_hello_bpSZ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpWriter_f helloBPWriter.F90) - set_property(TARGET hello_bpWriter_f PROPERTY LINKER_LANGUAGE Fortran) - target_link_libraries(hello_bpWriter_f adios2::fortran) + add_executable(adios2_hello_bpWriter_f bpWriter.F90) + target_link_libraries(adios2_hello_bpWriter_f adios2::fortran) + install(TARGETS adios2_hello_bpWriter_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(ADIOS2_HAVE_MPI) - add_executable(hello_bpWriter_mpi helloBPWriter.cpp) - target_link_libraries(hello_bpWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpWriter_mpi bpWriter.cpp) + target_link_libraries(adios2_hello_bpWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_bpWriter_c_mpi helloBPWriter.c) - target_link_libraries(hello_bpWriter_c_mpi adios2::c_mpi MPI::MPI_C) + add_executable(adios2_hello_bpWriter_c_mpi bpWriter.c) + target_link_libraries(adios2_hello_bpWriter_c_mpi adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpWriter_c_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_bpPutDeferred_mpi helloBPPutDeferred.cpp) - target_link_libraries(hello_bpPutDeferred_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpPutDeferred_mpi bpPutDeferred.cpp) + target_link_libraries(adios2_hello_bpPutDeferred_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpPutDeferred_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_bpSubStreams_mpi helloBPSubStreams.cpp) - target_link_libraries(hello_bpSubStreams_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpSubStreams_mpi bpSubStreams.cpp) + target_link_libraries(adios2_hello_bpSubStreams_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpSubStreams_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_SZ) - add_executable(hello_bpSZ_mpi helloBPSZ.cpp) - target_link_libraries(hello_bpSZ_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpSZ_mpi bpSZ.cpp) + target_link_libraries(adios2_hello_bpSZ_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpSZ_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpWriter_f_mpi helloBPWriter.F90) - set_property(TARGET hello_bpWriter_f_mpi PROPERTY LINKER_LANGUAGE Fortran) - target_link_libraries(hello_bpWriter_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) + add_executable(adios2_hello_bpWriter_f_mpi bpWriter.F90) + target_link_libraries(adios2_hello_bpWriter_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_bpWriter_f_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endif() diff --git a/examples/hello/bpWriter/helloBPPutDeferred.cpp b/examples/hello/bpWriter/bpPutDeferred.cpp similarity index 91% rename from examples/hello/bpWriter/helloBPPutDeferred.cpp rename to examples/hello/bpWriter/bpPutDeferred.cpp index 209486496d..bec6d3e289 100644 --- a/examples/hello/bpWriter/helloBPPutDeferred.cpp +++ b/examples/hello/bpWriter/bpPutDeferred.cpp @@ -2,17 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPPutDeferred.cpp - * - * Created on: Oct 23, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -/* - * Distributed under the OSI-approved Apache License, Version 2.0. See - * accompanying file Copyright.txt for details. - * - * helloBPPutDeferred.cpp: Simple self-descriptive example of how to write a + * bpPutDeferred.cpp: Simple self-descriptive example of how to write a * variable * to a BP File that lives in several MPI processes. * diff --git a/examples/hello/bpWriter/helloBPSZ.cpp b/examples/hello/bpWriter/bpSZ.cpp similarity index 98% rename from examples/hello/bpWriter/helloBPSZ.cpp rename to examples/hello/bpWriter/bpSZ.cpp index 5678ecb12c..357f42f829 100644 --- a/examples/hello/bpWriter/helloBPSZ.cpp +++ b/examples/hello/bpWriter/bpSZ.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPSZ.cpp : example passing runtime compression arguments + * bpSZ.cpp : example passing runtime compression arguments * * Created on: Aug 3, 2018 * Author: William F Godoy godoywf@ornl.gov diff --git a/examples/hello/bpWriter/helloBPSubStreams.cpp b/examples/hello/bpWriter/bpSubStreams.cpp similarity index 99% rename from examples/hello/bpWriter/helloBPSubStreams.cpp rename to examples/hello/bpWriter/bpSubStreams.cpp index 54db43007d..dad04e82b7 100644 --- a/examples/hello/bpWriter/helloBPSubStreams.cpp +++ b/examples/hello/bpWriter/bpSubStreams.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPSubStreams.cpp + * bpSubStreams.cpp * * Created on: Feb 21, 2018 * Author: William F Godoy godoywf@ornl.gov diff --git a/examples/hello/bpWriter/helloBPWriter.F90 b/examples/hello/bpWriter/bpWriter.F90 similarity index 97% rename from examples/hello/bpWriter/helloBPWriter.F90 rename to examples/hello/bpWriter/bpWriter.F90 index d1cea302ae..296cb290a1 100644 --- a/examples/hello/bpWriter/helloBPWriter.F90 +++ b/examples/hello/bpWriter/bpWriter.F90 @@ -1,4 +1,4 @@ -program helloBPWriter +program bpWriter #if ADIOS2_USE_MPI use mpi #endif @@ -72,4 +72,4 @@ program helloBPWriter call MPI_Finalize(ierr) #endif -end program helloBPWriter +end program bpWriter diff --git a/examples/hello/bpWriter/helloBPWriter.c b/examples/hello/bpWriter/bpWriter.c similarity index 97% rename from examples/hello/bpWriter/helloBPWriter.c rename to examples/hello/bpWriter/bpWriter.c index b88271347b..a4e17ce3ae 100644 --- a/examples/hello/bpWriter/helloBPWriter.c +++ b/examples/hello/bpWriter/bpWriter.c @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter.c : C bindings version of helloBPWriter.cpp + * bpWriter.c : C bindings version of bpWriter.cpp * * Created on: Aug 8, 2017 * Author: William F Godoy godoywf@ornl.gov diff --git a/examples/hello/bpWriter/helloBPWriter.cpp b/examples/hello/bpWriter/bpWriter.cpp similarity index 97% rename from examples/hello/bpWriter/helloBPWriter.cpp rename to examples/hello/bpWriter/bpWriter.cpp index 5a80cdbeb4..878a02a60a 100644 --- a/examples/hello/bpWriter/helloBPWriter.cpp +++ b/examples/hello/bpWriter/bpWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter.cpp: Simple self-descriptive example of how to write a variable + * bpWriter.cpp: Simple self-descriptive example of how to write a variable * to a BP File that lives in several MPI processes. * * Created on: Feb 16, 2017 diff --git a/examples/hello/bpWriter/helloBPWriter.py b/examples/hello/bpWriter/bpWriter.py similarity index 73% rename from examples/hello/bpWriter/helloBPWriter.py rename to examples/hello/bpWriter/bpWriter.py index ce29de2f0e..5218e79933 100644 --- a/examples/hello/bpWriter/helloBPWriter.py +++ b/examples/hello/bpWriter/bpWriter.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloBPWriter_nompi.py : only works with non MPI version +# bpWriter.py : only works with MPI version # Created on: Feb 2, 2017 # Author: William F Godoy godoywf@ornl.gov from mpi4py import MPI @@ -15,7 +15,7 @@ size = comm.Get_size() # User data -myArray = numpy.array([0, 1., 2., 3., 4., 5., 6., 7., 8., 9.]) +myArray = numpy.array([0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) Nx = myArray.size # ADIOS MPI Communicator @@ -23,20 +23,21 @@ # ADIOS IO bpIO = adios.DeclareIO("BPFile_N2N") -bpIO.SetEngine('bp3') +bpIO.SetEngine("bp3") # bpIO.SetParameters( {"Threads" : "2", "ProfileUnits" : "Microseconds", # "InitialBufferSize" : "17Kb"} ) bpIOParams = {} -bpIOParams['Threads'] = '2' -bpIOParams['ProfileUnits'] = 'Microseconds' -bpIOParams['InitialBufferSize'] = '17Kb' +bpIOParams["Threads"] = "2" +bpIOParams["ProfileUnits"] = "Microseconds" +bpIOParams["InitialBufferSize"] = "17Kb" bpIO.SetParameters(bpIOParams) -fileID = bpIO.AddTransport('File', {'Library': 'fstream'}) +fileID = bpIO.AddTransport("File", {"Library": "fstream"}) # ADIOS Variable name, shape, start, offset, constant dims ioArray = bpIO.DefineVariable( - "bpArray", myArray, [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims) + "bpArray", myArray, [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims +) # ADIOS Engine bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write) diff --git a/examples/hello/bpWriter/helloBPWriter_nompi.py b/examples/hello/bpWriter/bpWriter_nompi.py similarity index 72% rename from examples/hello/bpWriter/helloBPWriter_nompi.py rename to examples/hello/bpWriter/bpWriter_nompi.py index 9428808fa0..5155104df1 100644 --- a/examples/hello/bpWriter/helloBPWriter_nompi.py +++ b/examples/hello/bpWriter/bpWriter_nompi.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloBPWriter.py : only works with MPI version +# bpWriter_nonmpi.py : only works with non MPI version # Created on: Feb 2, 2017 # Author: William F Godoy godoywf@ornl.gov @@ -10,7 +10,7 @@ import adios2 # User data -myArray = numpy.array([0, 1., 2., 3., 4., 5., 6., 7., 8., 9.]) +myArray = numpy.array([0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) Nx = myArray.size # adios @@ -20,8 +20,7 @@ bpIO = adios.DeclareIO("BPFile_N2N") # ADIOS Variable name, shape, start, offset, constant dims -ioArray = bpIO.DefineVariable( - "bpArray", myArray, [], [], [Nx], adios2.ConstantDims) +ioArray = bpIO.DefineVariable("bpArray", myArray, [], [], [Nx], adios2.ConstantDims) # ADIOS Engine bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write) diff --git a/examples/hello/datamanReader/CMakeLists.txt b/examples/hello/datamanReader/CMakeLists.txt index 56a6139009..656bacefac 100644 --- a/examples/hello/datamanReader/CMakeLists.txt +++ b/examples/hello/datamanReader/CMakeLists.txt @@ -3,8 +3,28 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -if(ADIOS2_HAVE_MPI) - add_executable(hello_datamanReader helloDataManReader.cpp) - target_link_libraries(hello_datamanReader adios2::cxx11_mpi MPI::MPI_C) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataManReaderExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ZeroMQ 4.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_DataMan) + add_executable(adios2_hello_datamanReader dataManReader.cpp) + target_link_libraries(adios2_hello_datamanReader adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_datamanReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/datamanReader/helloDataManReader.cpp b/examples/hello/datamanReader/dataManReader.cpp similarity index 98% rename from examples/hello/datamanReader/helloDataManReader.cpp rename to examples/hello/datamanReader/dataManReader.cpp index 8313a9a56d..2bc58495b2 100644 --- a/examples/hello/datamanReader/helloDataManReader.cpp +++ b/examples/hello/datamanReader/dataManReader.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataManReader.cpp + * dataManReader.cpp * * Created on: Jan 9, 2017 * Author: Jason Wang diff --git a/examples/hello/datamanReader/helloDataManReader.py b/examples/hello/datamanReader/dataManReader.py similarity index 92% rename from examples/hello/datamanReader/helloDataManReader.py rename to examples/hello/datamanReader/dataManReader.py index 87248b6a64..c773e84fb8 100644 --- a/examples/hello/datamanReader/helloDataManReader.py +++ b/examples/hello/datamanReader/dataManReader.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloDataManReader.py +# dataManReader.py # # Created on: Sept 5, 2019 # Author: Jason Wang @@ -21,7 +21,7 @@ io.SetEngine("DataMan") io.SetParameters({"IPAddress": "127.0.0.1", "Port": "12306", "Timeout": "5"}) -engine = io.Open('HelloDataMan', adios2.Mode.Read, comm) +engine = io.Open("HelloDataMan", adios2.Mode.Read, comm) while True: stepStatus = engine.BeginStep() diff --git a/examples/hello/datamanWriter/CMakeLists.txt b/examples/hello/datamanWriter/CMakeLists.txt index 7c500d6e12..0bc0789ac6 100644 --- a/examples/hello/datamanWriter/CMakeLists.txt +++ b/examples/hello/datamanWriter/CMakeLists.txt @@ -3,7 +3,27 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -if(ADIOS2_HAVE_MPI) - add_executable(hello_datamanWriter helloDataManWriter.cpp) - target_link_libraries(hello_datamanWriter adios2::cxx11_mpi MPI::MPI_C) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataManWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ZeroMQ 4.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_DataMan) + add_executable(adios2_hello_datamanWriter dataManWriter.cpp) + target_link_libraries(adios2_hello_datamanWriter adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_datamanWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/datamanWriter/helloDataManWriter.cpp b/examples/hello/datamanWriter/dataManWriter.cpp similarity index 98% rename from examples/hello/datamanWriter/helloDataManWriter.cpp rename to examples/hello/datamanWriter/dataManWriter.cpp index bd29cb9c2b..fc106c2bb3 100644 --- a/examples/hello/datamanWriter/helloDataManWriter.cpp +++ b/examples/hello/datamanWriter/dataManWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataManWriter.cpp + * dataManWriter.cpp * * Created on: Feb 16, 2017 * Author: Jason Wang diff --git a/examples/hello/datamanWriter/helloDataManWriter.py b/examples/hello/datamanWriter/dataManWriter.py similarity index 92% rename from examples/hello/datamanWriter/helloDataManWriter.py rename to examples/hello/datamanWriter/dataManWriter.py index e23774cb38..9035d0f42a 100644 --- a/examples/hello/datamanWriter/helloDataManWriter.py +++ b/examples/hello/datamanWriter/dataManWriter.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloDataManWriter.py +# dataManWriter.py # # Created on: Sept 5, 2019 # Author: Jason Wang @@ -36,9 +36,10 @@ io.SetParameters({"IPAddress": "127.0.0.1", "Port": "12306", "Timeout": "5"}) var = io.DefineVariable( - "FloatArray", floatArray, shape, start, count, adios2.ConstantDims) + "FloatArray", floatArray, shape, start, count, adios2.ConstantDims +) -engine = io.Open('HelloDataMan', adios2.Mode.Write) +engine = io.Open("HelloDataMan", adios2.Mode.Write) for i in range(steps): floatArray = floatArray + 1 diff --git a/examples/hello/dataspacesReader/CMakeLists.txt b/examples/hello/dataspacesReader/CMakeLists.txt index 7136868362..11e8e3ff13 100644 --- a/examples/hello/dataspacesReader/CMakeLists.txt +++ b/examples/hello/dataspacesReader/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_dataSpacesReader helloDataSpacesReader.cpp) -target_link_libraries(hello_dataSpacesReader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataSpacesReaderExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_dataSpacesReader_mpi helloDataSpacesReader.cpp) - target_link_libraries(hello_dataSpacesReader_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(DataSpaces 2.1.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_DataSpaces) + add_executable(adios2_hello_dataSpacesReader dataSpacesReader.cpp) + target_link_libraries(adios2_hello_dataSpacesReader adios2::cxx11) + install(TARGETS adios2_hello_dataSpacesReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_dataSpacesReader_mpi dataSpacesReader.cpp) + target_link_libraries(adios2_hello_dataSpacesReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_dataSpacesReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/dataspacesReader/helloDataSpacesReader.cpp b/examples/hello/dataspacesReader/dataSpacesReader.cpp similarity index 98% rename from examples/hello/dataspacesReader/helloDataSpacesReader.cpp rename to examples/hello/dataspacesReader/dataSpacesReader.cpp index c2efd7ee1b..c6f6731432 100644 --- a/examples/hello/dataspacesReader/helloDataSpacesReader.cpp +++ b/examples/hello/dataspacesReader/dataSpacesReader.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataSpacesReader.cpp + * dataSpacesReader.cpp * * Created on: Feb 06, 2019 * Author: Pradeep Subedi diff --git a/examples/hello/dataspacesWriter/CMakeLists.txt b/examples/hello/dataspacesWriter/CMakeLists.txt index 6518c8c24b..32a1bb4673 100644 --- a/examples/hello/dataspacesWriter/CMakeLists.txt +++ b/examples/hello/dataspacesWriter/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_dataSpacesWriter helloDataSpacesWriter.cpp) -target_link_libraries(hello_dataSpacesWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataSpacesWriterExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_dataSpacesWriter_mpi helloDataSpacesWriter.cpp) - target_link_libraries(hello_dataSpacesWriter_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(DataSpaces 2.1.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_DataSpaces) + add_executable(adios2_hello_dataSpacesWriter dataSpacesWriter.cpp) + target_link_libraries(adios2_hello_dataSpacesWriter adios2::cxx11) + install(TARGETS adios2_hello_dataSpacesWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_dataSpacesWriter_mpi dataSpacesWriter.cpp) + target_link_libraries(adios2_hello_dataSpacesWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_dataSpacesWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/dataspacesWriter/helloDataSpacesWriter.cpp b/examples/hello/dataspacesWriter/dataSpacesWriter.cpp similarity index 98% rename from examples/hello/dataspacesWriter/helloDataSpacesWriter.cpp rename to examples/hello/dataspacesWriter/dataSpacesWriter.cpp index 103578c716..9c9e23b466 100644 --- a/examples/hello/dataspacesWriter/helloDataSpacesWriter.cpp +++ b/examples/hello/dataspacesWriter/dataSpacesWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataSpacesWriter.cpp + * dataSpacesWriter.cpp * * Created on: Feb 06, 2019 * Author: Pradeep Subedi diff --git a/examples/hello/hdf5Reader/CMakeLists.txt b/examples/hello/hdf5Reader/CMakeLists.txt index 2dd4227cf9..ebfcb9ad7b 100644 --- a/examples/hello/hdf5Reader/CMakeLists.txt +++ b/examples/hello/hdf5Reader/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_hdf5Reader helloHDF5Reader_nompi.cpp) -target_link_libraries(hello_hdf5Reader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloHDF5ReaderExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_hdf5Reader_mpi helloHDF5Reader.cpp) - target_link_libraries(hello_hdf5Reader_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(HDF5 QUIET COMPONENTS C) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_HDF5) + add_executable(adios2_hello_hdf5Reader hdf5Reader_nompi.cpp) + target_link_libraries(adios2_hello_hdf5Reader adios2::cxx11) + install(TARGETS adios2_hello_hdf5Reader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_hdf5Reader_mpi hdf5Reader.cpp) + target_link_libraries(adios2_hello_hdf5Reader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_hdf5Reader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/hdf5Reader/helloHDF5Reader.cpp b/examples/hello/hdf5Reader/hdf5Reader.cpp similarity index 99% rename from examples/hello/hdf5Reader/helloHDF5Reader.cpp rename to examples/hello/hdf5Reader/hdf5Reader.cpp index 33a2b7fb01..c1db98dde9 100644 --- a/examples/hello/hdf5Reader/helloHDF5Reader.cpp +++ b/examples/hello/hdf5Reader/hdf5Reader.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Reader.cpp + * hdf5Reader.cpp * * Created on: Jan 24, 2018 * Author: Junmin Gu diff --git a/examples/hello/hdf5Reader/helloHDF5Reader_nompi.cpp b/examples/hello/hdf5Reader/hdf5Reader_nompi.cpp similarity index 99% rename from examples/hello/hdf5Reader/helloHDF5Reader_nompi.cpp rename to examples/hello/hdf5Reader/hdf5Reader_nompi.cpp index c52d7515e0..45826a8979 100644 --- a/examples/hello/hdf5Reader/helloHDF5Reader_nompi.cpp +++ b/examples/hello/hdf5Reader/hdf5Reader_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Reader.cpp + * hdf5Reader.cpp * * Created on: Jan 24, 2018 * Author: Junmin Gu diff --git a/examples/hello/hdf5SubFile/CMakeLists.txt b/examples/hello/hdf5SubFile/CMakeLists.txt new file mode 100644 index 0000000000..81e494fa1b --- /dev/null +++ b/examples/hello/hdf5SubFile/CMakeLists.txt @@ -0,0 +1,30 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(HelloHDF5SubFileExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(HDF5 QUIET COMPONENTS C) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_HDF5 AND HDF5_VERSION VERSION_GREATER_EQUAL 1.14) + add_executable(adios2_hello_hdf5Subfile hdf5SubFile.cpp) + target_link_libraries(adios2_hello_hdf5Subfile adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_hdf5Subfile RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + diff --git a/examples/h5subfile/h5_subfile.cpp b/examples/hello/hdf5SubFile/hdf5SubFile.cpp similarity index 99% rename from examples/h5subfile/h5_subfile.cpp rename to examples/hello/hdf5SubFile/hdf5SubFile.cpp index 09e3111ecf..a018267b1a 100644 --- a/examples/h5subfile/h5_subfile.cpp +++ b/examples/hello/hdf5SubFile/hdf5SubFile.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Writer.cpp: Simple self-descriptive example of how to write a + * hdf5SubFile.cpp: Simple self-descriptive example of how to write a * variable to a parallel HDF5 File using MPI processes. * * Created on: March 6, 2023 diff --git a/examples/hello/hdf5Writer/CMakeLists.txt b/examples/hello/hdf5Writer/CMakeLists.txt index 934fbb4cfb..b1fd2bcdcf 100644 --- a/examples/hello/hdf5Writer/CMakeLists.txt +++ b/examples/hello/hdf5Writer/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_hdf5Writer helloHDF5Writer_nompi.cpp) -target_link_libraries(hello_hdf5Writer adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloHDF5WriterExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_hdf5Writer_mpi helloHDF5Writer.cpp) - target_link_libraries(hello_hdf5Writer_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(HDF5 QUIET COMPONENTS C) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_HDF5) + add_executable(adios2_hello_hdf5Writer hdf5Writer_nompi.cpp) + target_link_libraries(adios2_hello_hdf5Writer adios2::cxx11) + install(TARGETS adios2_hello_hdf5Writer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_hdf5Writer_mpi hdf5Writer.cpp) + target_link_libraries(adios2_hello_hdf5Writer_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_hdf5Writer_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/hdf5Writer/helloHDF5Writer.cpp b/examples/hello/hdf5Writer/hdf5Writer.cpp similarity index 98% rename from examples/hello/hdf5Writer/helloHDF5Writer.cpp rename to examples/hello/hdf5Writer/hdf5Writer.cpp index 7b5e001533..3e09334593 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer.cpp +++ b/examples/hello/hdf5Writer/hdf5Writer.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Writer.cpp: Simple self-descriptive example of how to write a + * hdf5Writer.cpp: Simple self-descriptive example of how to write a * variable to a parallel HDF5 File using MPI processes. * * Created on: March 20, 2017 diff --git a/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp b/examples/hello/hdf5Writer/hdf5Writer_nompi.cpp similarity index 96% rename from examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp rename to examples/hello/hdf5Writer/hdf5Writer_nompi.cpp index 436cde2194..c781519f82 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp +++ b/examples/hello/hdf5Writer/hdf5Writer_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Writer_nompi.cpp no mpi version of helloHDF5Writer.cpp + * hdf5Writer_nompi.cpp no mpi version of helloHDF5Writer.cpp * * Created on: March 20, 2017 * Author: Junmin diff --git a/examples/hello/inlineFWriteCppRead/CMakeLists.txt b/examples/hello/inlineFWriteCppRead/CMakeLists.txt index 64b99b539d..ad5cfbd537 100644 --- a/examples/hello/inlineFWriteCppRead/CMakeLists.txt +++ b/examples/hello/inlineFWriteCppRead/CMakeLists.txt @@ -3,17 +3,36 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -include(FortranCInterface) -FortranCInterface_HEADER(InlineExampleFC.h MACRO_NAMESPACE "FC_") -FortranCInterface_VERIFY(CXX QUIET) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloFWriteCppReadExample) -add_library(InlineMixedLangCPP inlineMixedLang.cpp) -target_link_libraries(InlineMixedLangCPP adios2::cxx11) -target_include_directories(InlineMixedLangCPP - PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} - ) +if(NOT TARGET adios2_core) + set(_components CXX) -add_executable(InlineMixedLangF inlineMixedLang.f90) -target_link_libraries(InlineMixedLangF adios2::fortran InlineMixedLangCPP) -set_target_properties(InlineMixedLangF PROPERTIES LINKER_LANGUAGE Fortran) + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_Fortran) + include(FortranCInterface) + FortranCInterface_HEADER(InlineExampleFC.h MACRO_NAMESPACE "FC_") + FortranCInterface_VERIFY(CXX QUIET) + + add_library(adios2_hello_inlineMixedLang inlineMixedLang.cpp) + target_link_libraries(adios2_hello_inlineMixedLang adios2::cxx11) + target_include_directories(adios2_hello_inlineMixedLang PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + install(TARGETS adios2_hello_inlineMixedLang RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_inlineMixedLang_f inlineMixedLang.f90) + target_link_libraries(adios2_hello_inlineMixedLang_f adios2_hello_inlineMixedLang adios2::fortran) + set_target_properties(adios2_hello_inlineMixedLang_f PROPERTIES LINKER_LANGUAGE Fortran) + install(TARGETS adios2_hello_inlineMixedLang_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/inlineMWE/CMakeLists.txt b/examples/hello/inlineMWE/CMakeLists.txt new file mode 100644 index 0000000000..98ac7fcc70 --- /dev/null +++ b/examples/hello/inlineMWE/CMakeLists.txt @@ -0,0 +1,17 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloInlineMWEExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_inlineMWE inlineMWE.cpp) +target_link_libraries(adios2_hello_inlineMWE adios2::cxx11) +install(TARGETS adios2_hello_inlineMWE RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/inlineMWE/inlineMWE.cpp b/examples/hello/inlineMWE/inlineMWE.cpp similarity index 88% rename from examples/inlineMWE/inlineMWE.cpp rename to examples/hello/inlineMWE/inlineMWE.cpp index 41d4ba37a6..5dc5ed6f04 100644 --- a/examples/inlineMWE/inlineMWE.cpp +++ b/examples/hello/inlineMWE/inlineMWE.cpp @@ -1,3 +1,8 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + #include #include diff --git a/examples/hello/inlineReaderWriter/CMakeLists.txt b/examples/hello/inlineReaderWriter/CMakeLists.txt index 25a8334140..cf76d4d0e6 100644 --- a/examples/hello/inlineReaderWriter/CMakeLists.txt +++ b/examples/hello/inlineReaderWriter/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_inlineReaderWriter helloInlineReaderWriter.cpp) -target_link_libraries(hello_inlineReaderWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloInlineReaderWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_inlineReaderWriter inlineReaderWriter.cpp) +target_link_libraries(adios2_hello_inlineReaderWriter adios2::cxx11) +install(TARGETS adios2_hello_inlineReaderWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_inlineReaderWriter_mpi helloInlineReaderWriter.cpp) - target_link_libraries(hello_inlineReaderWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_inlineReaderWriter_mpi inlineReaderWriter.cpp) + target_link_libraries(adios2_hello_inlineReaderWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_inlineReaderWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/inlineReaderWriter/helloInlineReaderWriter.cpp b/examples/hello/inlineReaderWriter/inlineReaderWriter.cpp similarity index 98% rename from examples/hello/inlineReaderWriter/helloInlineReaderWriter.cpp rename to examples/hello/inlineReaderWriter/inlineReaderWriter.cpp index 3fe9674924..f7ca536bfc 100644 --- a/examples/hello/inlineReaderWriter/helloInlineReaderWriter.cpp +++ b/examples/hello/inlineReaderWriter/inlineReaderWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloInlineReaderWriter.cpp example borrowed from helloBPTimeWriter, using + * inlineReaderWriter.cpp example borrowed from bpTimeWriter, using * the inline engine. Writes a variable using the Advance function for time * aggregation. Time step is saved as an additional (global) single value * variable, just for tracking purposes. diff --git a/examples/hello/skeleton/CMakeLists.txt b/examples/hello/skeleton/CMakeLists.txt index 5e5a35007c..4c6ead50ab 100644 --- a/examples/hello/skeleton/CMakeLists.txt +++ b/examples/hello/skeleton/CMakeLists.txt @@ -3,16 +3,37 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_skeletonWriter helloSkeletonWriter.cpp HelloSkeletonArgs.cpp) -target_link_libraries(hello_skeletonWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloSkeletonExample) -add_executable(hello_skeletonReader helloSkeletonReader.cpp HelloSkeletonArgs.cpp) -target_link_libraries(hello_skeletonReader adios2::cxx11) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_skeletonWriter skeletonWriter.cpp SkeletonArgs.cpp) +target_link_libraries(adios2_hello_skeletonWriter adios2::cxx11) +install(TARGETS adios2_hello_skeletonWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_skeletonReader skeletonReader.cpp SkeletonArgs.cpp) +target_link_libraries(adios2_hello_skeletonReader adios2::cxx11) +install(TARGETS adios2_hello_skeletonReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_skeletonWriter_mpi helloSkeletonWriter.cpp HelloSkeletonArgs.cpp) - target_link_libraries(hello_skeletonWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_skeletonWriter_mpi skeletonWriter.cpp SkeletonArgs.cpp) + target_link_libraries(adios2_hello_skeletonWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_skeletonWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_skeletonReader_mpi helloSkeletonReader.cpp HelloSkeletonArgs.cpp) - target_link_libraries(hello_skeletonReader_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_skeletonReader_mpi skeletonReader.cpp SkeletonArgs.cpp) + target_link_libraries(adios2_hello_skeletonReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_skeletonReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/skeleton/HelloSkeletonArgs.cpp b/examples/hello/skeleton/SkeletonArgs.cpp similarity index 92% rename from examples/hello/skeleton/HelloSkeletonArgs.cpp rename to examples/hello/skeleton/SkeletonArgs.cpp index 2ee3b8ff64..109ca5388d 100644 --- a/examples/hello/skeleton/HelloSkeletonArgs.cpp +++ b/examples/hello/skeleton/SkeletonArgs.cpp @@ -6,7 +6,7 @@ * Author: Norbert Podhorszki */ -#include "HelloSkeletonArgs.h" +#include "SkeletonArgs.h" #include @@ -42,7 +42,7 @@ static void printUsage(bool isWriter) static unsigned int convertToUint(std::string varName, char *arg) { char *end; - unsigned int retval = std::strtoul(arg, &end, 10); + const auto retval = static_cast(std::strtoul(arg, &end, 10)); if (end[0] || errno == ERANGE) { throw std::invalid_argument("Invalid value given for " + varName + ": " + std::string(arg)); @@ -50,8 +50,7 @@ static unsigned int convertToUint(std::string varName, char *arg) return retval; } -HelloSkeletonArgs::HelloSkeletonArgs(bool isWriter, int argc, char *argv[], int rank, int nproc) -: rank{rank} +SkeletonArgs::SkeletonArgs(bool isWriter, int argc, char *argv[], int rank, int nproc) : rank{rank} { npx = npy = ndx = ndy = steps = sleeptime = 0; gndx = gndy = posx = posy = offsx = offsy = 0; @@ -98,7 +97,7 @@ HelloSkeletonArgs::HelloSkeletonArgs(bool isWriter, int argc, char *argv[], int } } -void HelloSkeletonArgs::DecomposeArray(size_t NX, size_t NY) +void SkeletonArgs::DecomposeArray(size_t NX, size_t NY) { gndx = static_cast(NX); gndy = static_cast(NY); diff --git a/examples/hello/skeleton/HelloSkeletonArgs.h b/examples/hello/skeleton/SkeletonArgs.h similarity index 93% rename from examples/hello/skeleton/HelloSkeletonArgs.h rename to examples/hello/skeleton/SkeletonArgs.h index 7ae34366f0..0433e83950 100644 --- a/examples/hello/skeleton/HelloSkeletonArgs.h +++ b/examples/hello/skeleton/SkeletonArgs.h @@ -11,7 +11,7 @@ #include -class HelloSkeletonArgs +class SkeletonArgs { public: @@ -41,7 +41,7 @@ class HelloSkeletonArgs int rank; // MPI rank unsigned int nproc; // number of processors - HelloSkeletonArgs(bool isWriter, int argc, char *argv[], int rank, int nproc); + SkeletonArgs(bool isWriter, int argc, char *argv[], int rank, int nproc); void DecomposeArray(size_t NX, size_t NY); }; diff --git a/examples/hello/skeleton/HelloSkeletonPrint.h b/examples/hello/skeleton/SkeletonPrint.h similarity index 100% rename from examples/hello/skeleton/HelloSkeletonPrint.h rename to examples/hello/skeleton/SkeletonPrint.h diff --git a/examples/hello/skeleton/hello_bpfile.xml b/examples/hello/skeleton/bpfile.xml similarity index 97% rename from examples/hello/skeleton/hello_bpfile.xml rename to examples/hello/skeleton/bpfile.xml index aeb255fd93..f46b17d38b 100644 --- a/examples/hello/skeleton/hello_bpfile.xml +++ b/examples/hello/skeleton/bpfile.xml @@ -1,6 +1,6 @@ diff --git a/examples/hello/skeleton/hello_skeleton.xml b/examples/hello/skeleton/skeleton.xml similarity index 96% rename from examples/hello/skeleton/hello_skeleton.xml rename to examples/hello/skeleton/skeleton.xml index bbca561454..ed9ad58b9c 100644 --- a/examples/hello/skeleton/hello_skeleton.xml +++ b/examples/hello/skeleton/skeleton.xml @@ -1,6 +1,6 @@ diff --git a/examples/hello/skeleton/helloSkeletonReader.cpp b/examples/hello/skeleton/skeletonReader.cpp similarity index 93% rename from examples/hello/skeleton/helloSkeletonReader.cpp rename to examples/hello/skeleton/skeletonReader.cpp index 5744647b2a..87a070f004 100644 --- a/examples/hello/skeleton/helloSkeletonReader.cpp +++ b/examples/hello/skeleton/skeletonReader.cpp @@ -1,3 +1,8 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + #include #include //std::ios_base::failure #include //std::cout @@ -6,8 +11,8 @@ #include -#include "HelloSkeletonArgs.h" -#include "HelloSkeletonPrint.h" +#include "SkeletonArgs.h" +#include "SkeletonPrint.h" int main(int argc, char *argv[]) { @@ -32,7 +37,7 @@ int main(int argc, char *argv[]) try { - HelloSkeletonArgs settings(false, argc, argv, rank, nproc); + SkeletonArgs settings(false, argc, argv, rank, nproc); /** ADIOS class factory of IO class objects, Debug is ON by default */ #if ADIOS2_USE_MPI diff --git a/examples/hello/skeleton/helloSkeletonWriter.cpp b/examples/hello/skeleton/skeletonWriter.cpp similarity index 93% rename from examples/hello/skeleton/helloSkeletonWriter.cpp rename to examples/hello/skeleton/skeletonWriter.cpp index 407fe967dc..0eb1d43638 100644 --- a/examples/hello/skeleton/helloSkeletonWriter.cpp +++ b/examples/hello/skeleton/skeletonWriter.cpp @@ -13,7 +13,7 @@ #include #include -#include "HelloSkeletonArgs.h" +#include "SkeletonArgs.h" #include @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) try { - HelloSkeletonArgs settings(true, argc, argv, rank, nproc); + SkeletonArgs settings(true, argc, argv, rank, nproc); std::vector myArray(settings.ndx * settings.ndy); @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) { for (size_t i = 0; i < settings.ndx; ++i) { - myArray[idx] = rank + (step / 100.0f); + myArray[idx] = static_cast(rank) + (static_cast(step) / 100.0f); ++idx; } } diff --git a/examples/hello/sstReader/CMakeLists.txt b/examples/hello/sstReader/CMakeLists.txt index eff30267d5..39a0b615c0 100644 --- a/examples/hello/sstReader/CMakeLists.txt +++ b/examples/hello/sstReader/CMakeLists.txt @@ -3,10 +3,35 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_sstReader helloSstReader.cpp) -target_link_libraries(hello_sstReader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloSstReaderExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_sstReader_mpi helloSstReader.cpp) - target_link_libraries(hello_sstReader_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + if(NOT WIN32) + find_package(LIBFABRIC 1.6 QUIET) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_SST) + add_executable(adios2_hello_sstReader sstReader.cpp) + target_link_libraries(adios2_hello_sstReader adios2::cxx11) + install(TARGETS adios2_hello_sstReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_sstReader_mpi sstReader.cpp) + target_link_libraries(adios2_hello_sstReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_sstReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/sstReader/helloSstReader.cpp b/examples/hello/sstReader/sstReader.cpp similarity index 97% rename from examples/hello/sstReader/helloSstReader.cpp rename to examples/hello/sstReader/sstReader.cpp index 8dfcb1ba0c..56630b3eea 100644 --- a/examples/hello/sstReader/helloSstReader.cpp +++ b/examples/hello/sstReader/sstReader.cpp @@ -2,10 +2,10 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloSstReader.cpp + * sstReader.cpp * * Created on: Aug 17, 2017 -v * Author: Greg Eisenhauer + * Author: Greg Eisenhauer */ #include diff --git a/examples/hello/sstWriter/CMakeLists.txt b/examples/hello/sstWriter/CMakeLists.txt index 637e00bfd4..f5adca3e58 100644 --- a/examples/hello/sstWriter/CMakeLists.txt +++ b/examples/hello/sstWriter/CMakeLists.txt @@ -3,10 +3,35 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_sstWriter helloSstWriter.cpp) -target_link_libraries(hello_sstWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloSstWriterExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_sstWriter_mpi helloSstWriter.cpp) - target_link_libraries(hello_sstWriter_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + if (NOT WIN32) + find_package(LIBFABRIC 1.6 QUIET) + endif () + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_SST) + add_executable(adios2_hello_sstWriter sstWriter.cpp) + target_link_libraries(adios2_hello_sstWriter adios2::cxx11) + install(TARGETS adios2_hello_sstWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_sstWriter_mpi sstWriter.cpp) + target_link_libraries(adios2_hello_sstWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_sstWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/sstWriter/helloSstWriter.cpp b/examples/hello/sstWriter/sstWriter.cpp similarity index 81% rename from examples/hello/sstWriter/helloSstWriter.cpp rename to examples/hello/sstWriter/sstWriter.cpp index e4c58b1b17..02d4981171 100644 --- a/examples/hello/sstWriter/helloSstWriter.cpp +++ b/examples/hello/sstWriter/sstWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloSstWriter.cpp + * sstWriter.cpp * * Created on: Aug 17, 2017 * Author: Greg Eisenhauer @@ -35,11 +35,12 @@ int main(int argc, char *argv[]) size = 1; #endif - std::vector myFloats = {(float)10.0 * rank + 0, (float)10.0 * rank + 1, - (float)10.0 * rank + 2, (float)10.0 * rank + 3, - (float)10.0 * rank + 4, (float)10.0 * rank + 5, - (float)10.0 * rank + 6, (float)10.0 * rank + 7, - (float)10.0 * rank + 8, (float)10.0 * rank + 9}; + std::vector myFloats = { + static_cast(10.0 * rank + 0), static_cast(10.0 * rank + 1), + static_cast(10.0 * rank + 2), static_cast(10.0 * rank + 3), + static_cast(10.0 * rank + 4), static_cast(10.0 * rank + 5), + static_cast(10.0 * rank + 6), static_cast(10.0 * rank + 7), + static_cast(10.0 * rank + 8), static_cast(10.0 * rank + 9)}; const std::size_t Nx = myFloats.size(); try diff --git a/examples/hello/sstWriter/helloSstWriter.py b/examples/hello/sstWriter/sstWriter.py similarity index 72% rename from examples/hello/sstWriter/helloSstWriter.py rename to examples/hello/sstWriter/sstWriter.py index 99508627ad..08a7a8270a 100644 --- a/examples/hello/sstWriter/helloSstWriter.py +++ b/examples/hello/sstWriter/sstWriter.py @@ -12,13 +12,13 @@ # ADIOS IO sstIO = adios.DeclareIO("myIO") -sstIO.SetEngine('Sst') -myArray = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], - dtype='f') +sstIO.SetEngine("Sst") +myArray = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype="f") myArray = 10.0 * rank + myArray nx = len(myArray) -ioArray = sstIO.DefineVariable("bpFloats", myArray, [size * nx], - [rank * nx], [nx], adios2.ConstantDims) +ioArray = sstIO.DefineVariable( + "bpFloats", myArray, [size * nx], [rank * nx], [nx], adios2.ConstantDims +) sstFileWriter = sstIO.Open("helloSst", adios2.Mode.Write) sstFileWriter.BeginStep() sstFileWriter.Put(ioArray, myArray, adios2.Mode.Sync) diff --git a/examples/inlineMWE/CMakeLists.txt b/examples/inlineMWE/CMakeLists.txt deleted file mode 100644 index 3773d2d3f7..0000000000 --- a/examples/inlineMWE/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(inlineMWE inlineMWE.cpp) -target_link_libraries(inlineMWE adios2::cxx11) diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 5fed9662d6..013d696b17 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -4,4 +4,6 @@ #------------------------------------------------------------------------------# add_subdirectory(engine) -add_subdirectory(operator) +if(ADIOS2_HAVE_Sodium) + add_subdirectory(operator) +endif() diff --git a/examples/plugins/engine/CMakeLists.txt b/examples/plugins/engine/CMakeLists.txt index a611c0b8b7..d902043a83 100644 --- a/examples/plugins/engine/CMakeLists.txt +++ b/examples/plugins/engine/CMakeLists.txt @@ -3,33 +3,39 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# +cmake_minimum_required(VERSION 3.12) +project(ADIOS2PluginsEngineExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + include(GenerateExportHeader) -add_library(PluginEngineWrite - ExampleWritePlugin.cpp -) -target_link_libraries(PluginEngineWrite adios2::cxx11 adios2_core) -generate_export_header(PluginEngineWrite BASE_NAME plugin_engine_write) -target_include_directories(PluginEngineWrite PUBLIC + +add_library(adios2_plugins_exampleWritePlugin ExampleWritePlugin.cpp) +target_link_libraries(adios2_plugins_exampleWritePlugin adios2::cxx11 adios2_core) +generate_export_header(adios2_plugins_exampleWritePlugin BASE_NAME plugin_engine_write) +target_include_directories(adios2_plugins_exampleWritePlugin PUBLIC $ $ ) +install(TARGETS adios2_plugins_exampleWritePlugin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_library(PluginEngineRead - ExampleReadPlugin.cpp -) -target_link_libraries(PluginEngineRead adios2::cxx11 adios2_core) -generate_export_header(PluginEngineRead BASE_NAME plugin_engine_read) -target_include_directories(PluginEngineRead PUBLIC +add_library(adios2_plugins_exampleReadPlugin ExampleReadPlugin.cpp) +target_link_libraries(adios2_plugins_exampleReadPlugin adios2::cxx11 adios2_core) +generate_export_header(adios2_plugins_exampleReadPlugin BASE_NAME plugin_engine_read) +target_include_directories(adios2_plugins_exampleReadPlugin PUBLIC $ $ ) +install(TARGETS adios2_plugins_exampleReadPlugin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_executable(examplePluginEngine_write - examplePluginEngine_write.cpp -) -target_link_libraries(examplePluginEngine_write adios2::cxx11) +add_executable(adios2_plugins_examplePluginEngineWrite examplePluginEngineWrite.cpp) +target_link_libraries(adios2_plugins_examplePluginEngineWrite adios2::cxx11) +install(TARGETS adios2_plugins_examplePluginEngineWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_executable(examplePluginEngine_read - examplePluginEngine_read.cpp -) -target_link_libraries(examplePluginEngine_read adios2::cxx11) +add_executable(adios2_plugins_examplePluginEngineRead examplePluginEngineRead.cpp) +target_link_libraries(adios2_plugins_examplePluginEngineRead adios2::cxx11) +install(TARGETS adios2_plugins_examplePluginEngineRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/plugins/engine/examplePluginEngine_read.cpp b/examples/plugins/engine/examplePluginEngineRead.cpp similarity index 97% rename from examples/plugins/engine/examplePluginEngine_read.cpp rename to examples/plugins/engine/examplePluginEngineRead.cpp index 17042868dc..684ea561c1 100644 --- a/examples/plugins/engine/examplePluginEngine_read.cpp +++ b/examples/plugins/engine/examplePluginEngineRead.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * examplePluginEngine_read.cpp example showing how to use ExampleReadPlugin + * examplePluginEngineRead.cpp example showing how to use ExampleReadPlugin * engine * * Created on: July 5, 2021 diff --git a/examples/plugins/engine/examplePluginEngine_write.cpp b/examples/plugins/engine/examplePluginEngineWrite.cpp similarity index 97% rename from examples/plugins/engine/examplePluginEngine_write.cpp rename to examples/plugins/engine/examplePluginEngineWrite.cpp index bb6f6f51b9..3d142d36c6 100644 --- a/examples/plugins/engine/examplePluginEngine_write.cpp +++ b/examples/plugins/engine/examplePluginEngineWrite.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * examplePluginEngine_write.cpp example showing how to use ExampleWritePlugin + * examplePluginEngineWrite.cpp example showing how to use ExampleWritePlugin * engine * * Created on: July 5, 2021 diff --git a/examples/plugins/engine/example_engine.xml b/examples/plugins/engine/example_engine.xml index 412c1a9684..46393a70d7 100644 --- a/examples/plugins/engine/example_engine.xml +++ b/examples/plugins/engine/example_engine.xml @@ -10,7 +10,7 @@ - + @@ -22,7 +22,7 @@ - + diff --git a/examples/plugins/operator/CMakeLists.txt b/examples/plugins/operator/CMakeLists.txt index 8881bb8f16..f71e6dca20 100644 --- a/examples/plugins/operator/CMakeLists.txt +++ b/examples/plugins/operator/CMakeLists.txt @@ -2,12 +2,24 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(exampleOperatorPlugin_write - examplePluginOperator_write.cpp -) -target_link_libraries(exampleOperatorPlugin_write adios2::cxx11) - -add_executable(exampleOperatorPlugin_read - examplePluginOperator_read.cpp -) -target_link_libraries(exampleOperatorPlugin_read adios2::cxx11) + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2PluginsOperatorExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(Sodium QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_Sodium) + add_executable(adios2_plugins_exampleOperatorPluginWrite examplePluginOperatorWrite.cpp) + target_link_libraries(adios2_plugins_exampleOperatorPluginWrite adios2::cxx11) + install(TARGETS adios2_plugins_exampleOperatorPluginWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_plugins_exampleOperatorPluginRead examplePluginOperatorRead.cpp) + target_link_libraries(adios2_plugins_exampleOperatorPluginRead adios2::cxx11) + install(TARGETS adios2_plugins_exampleOperatorPluginRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() \ No newline at end of file diff --git a/examples/plugins/operator/examplePluginOperator_read.cpp b/examples/plugins/operator/examplePluginOperatorRead.cpp similarity index 97% rename from examples/plugins/operator/examplePluginOperator_read.cpp rename to examples/plugins/operator/examplePluginOperatorRead.cpp index 01e47e92a5..e48fff3b74 100644 --- a/examples/plugins/operator/examplePluginOperator_read.cpp +++ b/examples/plugins/operator/examplePluginOperatorRead.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * examplePluginOperator_read.cpp example showing how to use EncryptionOperator + * examplePluginOperatorRead.cpp example showing how to use EncryptionOperator * plugin * * Created on: July 5, 2021 diff --git a/examples/plugins/operator/examplePluginOperator_write.cpp b/examples/plugins/operator/examplePluginOperatorWrite.cpp similarity index 100% rename from examples/plugins/operator/examplePluginOperator_write.cpp rename to examples/plugins/operator/examplePluginOperatorWrite.cpp diff --git a/examples/query/CMakeLists.txt b/examples/query/CMakeLists.txt deleted file mode 100644 index 444dda6fef..0000000000 --- a/examples/query/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -if(ADIOS2_HAVE_MPI) - add_executable(queryTest test.cpp) - target_link_libraries(queryTest adios2::cxx11_mpi MPI::MPI_C) -endif() - diff --git a/examples/simulations/CMakeLists.txt b/examples/simulations/CMakeLists.txt new file mode 100644 index 0000000000..93f7e8c70c --- /dev/null +++ b/examples/simulations/CMakeLists.txt @@ -0,0 +1,3 @@ +if(ADIOS2_HAVE_MPI) + add_subdirectory(heatTransfer) +endif() diff --git a/examples/heatTransfer/CMakeLists.txt b/examples/simulations/heatTransfer/CMakeLists.txt similarity index 75% rename from examples/heatTransfer/CMakeLists.txt rename to examples/simulations/heatTransfer/CMakeLists.txt index 48a07f6fd2..7b00974587 100644 --- a/examples/heatTransfer/CMakeLists.txt +++ b/examples/simulations/heatTransfer/CMakeLists.txt @@ -3,7 +3,10 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_subdirectory(write) -add_subdirectory(read) -add_subdirectory(read_fileonly) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsHeatTransferExample) + add_subdirectory(inline) +add_subdirectory(read) +add_subdirectory(readFileOnly) +add_subdirectory(write) diff --git a/examples/heatTransfer/ReadMe.md b/examples/simulations/heatTransfer/ReadMe.md similarity index 75% rename from examples/heatTransfer/ReadMe.md rename to examples/simulations/heatTransfer/ReadMe.md index 9ad00c1681..a378c72f96 100644 --- a/examples/heatTransfer/ReadMe.md +++ b/examples/simulations/heatTransfer/ReadMe.md @@ -1,4 +1,4 @@ -examples/heatTransfer +### heatTransfer example This example solves a 2D Poisson equation for temperature in homogeneous media using finite differences. This examples shows a straight-forward way to hook @@ -7,7 +7,7 @@ an application to the ADIOS2 library for its IO. 1. write: illustrates the Write API as well as has implementations of other IO libraries - * adios 1.x + * adios 2 * hdf5 sequential, separate file per process per step * phdf5 parallel, steps appended to the same one file @@ -17,7 +17,7 @@ an application to the ADIOS2 library for its IO. * in situ to read step by step as the writer outputs them (need to run with a suitable engine) -3. read_fileonly: illustrates reading all output steps at once (a single read +3. readFileOnly: illustrates reading all output steps at once (a single read statement) into a single contiguous memory block. This approach only works for post-mortem processing. @@ -38,12 +38,12 @@ Writer usage: heatTransfer config output N M nx ny steps iterations steps: the total number of steps to output iterations: one step consist of this many iterations -The ADIOS2 executable needs an XML config file to select the Engine used for the output. The engines are: File, BP4 and HDF5, the corresponding XML config files are in the examples/heatTransfer/ directory. The "File" engine will be BP4 or HDF5 depending on the extension of the file name. +The ADIOS2 executable needs an XML config file to select the Engine used for the output. The engines are: File, BP4 and HDF5, the corresponding XML config files are in the examples/simulations/heatTransfer/ directory. The "File" engine will be BP4 or HDF5 depending on the extension of the file name. The adios1, ph5 and hdf5 versions of the example do not use XML config files, so just type "none" for the config argument. -$ mpirun -np 12 ./bin/heatTransfer_write_adios2 ../examples/heatTransfer/heat_file.xml heat.bp 4 3 5 10 10 10 -$ mpirun -np 12 ./bin/heatTransfer_write_adios2 ../examples/heatTransfer/heat_file.xml heat.h5 4 3 5 10 10 10 +$ mpirun -np 12 ./bin/adios2_simulations_heatTransferWrite ../examples/simulations/heatTransfer/heat_file.xml heat.bp 4 3 5 10 10 10 +$ mpirun -np 12 ./bin/adios2_simulations_heatTransferWrite ../examples/simulations/heatTransfer/heat_file.xml heat.h5 4 3 5 10 10 10 2. Read the output step-by-step and print data into text files (data. per reader process) @@ -55,7 +55,7 @@ Reader Usage: heatRead config input N M M: number of processes in Y dimension -$ mpirun -np 2 ./bin/heatTransfer_read ../examples/heatTransfer/heat_file.xml heat 2 1 +$ mpirun -np 2 ./bin/heatTransfer_read ../examples/simulations/heatTransfer/heat_file.xml heat 2 1 Notes: diff --git a/examples/heatTransfer/heat_bp3.xml b/examples/simulations/heatTransfer/heat_bp3.xml similarity index 97% rename from examples/heatTransfer/heat_bp3.xml rename to examples/simulations/heatTransfer/heat_bp3.xml index 6b004a3c6d..bc5e91fc53 100644 --- a/examples/heatTransfer/heat_bp3.xml +++ b/examples/simulations/heatTransfer/heat_bp3.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_bp3_zfp.xml b/examples/simulations/heatTransfer/heat_bp3_zfp.xml similarity index 98% rename from examples/heatTransfer/heat_bp3_zfp.xml rename to examples/simulations/heatTransfer/heat_bp3_zfp.xml index b2220e480a..ab7fc71756 100644 --- a/examples/heatTransfer/heat_bp3_zfp.xml +++ b/examples/simulations/heatTransfer/heat_bp3_zfp.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_bp4.xml b/examples/simulations/heatTransfer/heat_bp4.xml similarity index 97% rename from examples/heatTransfer/heat_bp4.xml rename to examples/simulations/heatTransfer/heat_bp4.xml index 5373aa9fca..dd7ba50541 100644 --- a/examples/heatTransfer/heat_bp4.xml +++ b/examples/simulations/heatTransfer/heat_bp4.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_bp4_zfp.xml b/examples/simulations/heatTransfer/heat_bp4_zfp.xml similarity index 98% rename from examples/heatTransfer/heat_bp4_zfp.xml rename to examples/simulations/heatTransfer/heat_bp4_zfp.xml index f7401bc5de..b6af72c1ce 100644 --- a/examples/heatTransfer/heat_bp4_zfp.xml +++ b/examples/simulations/heatTransfer/heat_bp4_zfp.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_dataman.xml b/examples/simulations/heatTransfer/heat_dataman.xml similarity index 97% rename from examples/heatTransfer/heat_dataman.xml rename to examples/simulations/heatTransfer/heat_dataman.xml index e7cbddb66a..dc5164e8d5 100644 --- a/examples/heatTransfer/heat_dataman.xml +++ b/examples/simulations/heatTransfer/heat_dataman.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_dataspaces.xml b/examples/simulations/heatTransfer/heat_dataspaces.xml similarity index 91% rename from examples/heatTransfer/heat_dataspaces.xml rename to examples/simulations/heatTransfer/heat_dataspaces.xml index 3d8fabe929..690436b548 100644 --- a/examples/heatTransfer/heat_dataspaces.xml +++ b/examples/simulations/heatTransfer/heat_dataspaces.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_file.xml b/examples/simulations/heatTransfer/heat_file.xml similarity index 97% rename from examples/heatTransfer/heat_file.xml rename to examples/simulations/heatTransfer/heat_file.xml index b5bd9a970e..1a2392301e 100644 --- a/examples/heatTransfer/heat_file.xml +++ b/examples/simulations/heatTransfer/heat_file.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_hdf5.xml b/examples/simulations/heatTransfer/heat_hdf5.xml similarity index 97% rename from examples/heatTransfer/heat_hdf5.xml rename to examples/simulations/heatTransfer/heat_hdf5.xml index a4abcf1290..334b9841f4 100644 --- a/examples/heatTransfer/heat_hdf5.xml +++ b/examples/simulations/heatTransfer/heat_hdf5.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_inline.xml b/examples/simulations/heatTransfer/heat_inline.xml similarity index 96% rename from examples/heatTransfer/heat_inline.xml rename to examples/simulations/heatTransfer/heat_inline.xml index 7de2cb351b..e01923f265 100644 --- a/examples/heatTransfer/heat_inline.xml +++ b/examples/simulations/heatTransfer/heat_inline.xml @@ -1,6 +1,6 @@ diff --git a/examples/heatTransfer/heat_ssc.xml b/examples/simulations/heatTransfer/heat_ssc.xml similarity index 94% rename from examples/heatTransfer/heat_ssc.xml rename to examples/simulations/heatTransfer/heat_ssc.xml index 5f37add34b..435b12df9f 100644 --- a/examples/heatTransfer/heat_ssc.xml +++ b/examples/simulations/heatTransfer/heat_ssc.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_sst_bp_rdma.xml b/examples/simulations/heatTransfer/heat_sst_bp_rdma.xml similarity index 92% rename from examples/heatTransfer/heat_sst_bp_rdma.xml rename to examples/simulations/heatTransfer/heat_sst_bp_rdma.xml index a324215006..9c321e76b5 100644 --- a/examples/heatTransfer/heat_sst_bp_rdma.xml +++ b/examples/simulations/heatTransfer/heat_sst_bp_rdma.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_sst_ffs.xml b/examples/simulations/heatTransfer/heat_sst_ffs.xml similarity index 91% rename from examples/heatTransfer/heat_sst_ffs.xml rename to examples/simulations/heatTransfer/heat_sst_ffs.xml index 1e8712cf93..6332d8e46e 100644 --- a/examples/heatTransfer/heat_sst_ffs.xml +++ b/examples/simulations/heatTransfer/heat_sst_ffs.xml @@ -1,7 +1,7 @@ diff --git a/examples/heatTransfer/heat_sst_ffs_rdma.xml b/examples/simulations/heatTransfer/heat_sst_ffs_rdma.xml similarity index 92% rename from examples/heatTransfer/heat_sst_ffs_rdma.xml rename to examples/simulations/heatTransfer/heat_sst_ffs_rdma.xml index ed2b0be094..08a0844b54 100644 --- a/examples/heatTransfer/heat_sst_ffs_rdma.xml +++ b/examples/simulations/heatTransfer/heat_sst_ffs_rdma.xml @@ -1,7 +1,7 @@ diff --git a/examples/simulations/heatTransfer/inline/CMakeLists.txt b/examples/simulations/heatTransfer/inline/CMakeLists.txt new file mode 100644 index 0000000000..4e41311ce9 --- /dev/null +++ b/examples/simulations/heatTransfer/inline/CMakeLists.txt @@ -0,0 +1,34 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsHeatTransferInlineExample) + +if(NOT TARGET adios2_core) + set(_components C CXX) + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(Threads QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND Threads_FOUND) + add_executable(adios2_simulations_heatTransferInline + main.cpp + InlineIO.cpp + ../write/HeatTransfer.cpp + ../write/Settings.cpp + ) + target_link_libraries(adios2_simulations_heatTransferInline adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_simulations_heatTransferInline RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/heatTransfer/inline/InlineIO.cpp b/examples/simulations/heatTransfer/inline/InlineIO.cpp similarity index 100% rename from examples/heatTransfer/inline/InlineIO.cpp rename to examples/simulations/heatTransfer/inline/InlineIO.cpp diff --git a/examples/heatTransfer/inline/InlineIO.h b/examples/simulations/heatTransfer/inline/InlineIO.h similarity index 100% rename from examples/heatTransfer/inline/InlineIO.h rename to examples/simulations/heatTransfer/inline/InlineIO.h diff --git a/examples/heatTransfer/inline/main.cpp b/examples/simulations/heatTransfer/inline/main.cpp similarity index 100% rename from examples/heatTransfer/inline/main.cpp rename to examples/simulations/heatTransfer/inline/main.cpp diff --git a/examples/simulations/heatTransfer/read/CMakeLists.txt b/examples/simulations/heatTransfer/read/CMakeLists.txt new file mode 100644 index 0000000000..fcc241a2fe --- /dev/null +++ b/examples/simulations/heatTransfer/read/CMakeLists.txt @@ -0,0 +1,31 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsHeatTransferReadExample) + +if(NOT TARGET adios2_core) + set(_components C CXX) + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_simulations_heatTransferRead + heatRead.cpp + PrintDataStep.h + ReadSettings.cpp + ) + target_link_libraries(adios2_simulations_heatTransferRead adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_simulations_heatTransferRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/heatTransfer/read/PrintDataStep.h b/examples/simulations/heatTransfer/read/PrintDataStep.h similarity index 100% rename from examples/heatTransfer/read/PrintDataStep.h rename to examples/simulations/heatTransfer/read/PrintDataStep.h diff --git a/examples/heatTransfer/read/ReadSettings.cpp b/examples/simulations/heatTransfer/read/ReadSettings.cpp similarity index 100% rename from examples/heatTransfer/read/ReadSettings.cpp rename to examples/simulations/heatTransfer/read/ReadSettings.cpp diff --git a/examples/heatTransfer/read/ReadSettings.h b/examples/simulations/heatTransfer/read/ReadSettings.h similarity index 100% rename from examples/heatTransfer/read/ReadSettings.h rename to examples/simulations/heatTransfer/read/ReadSettings.h diff --git a/examples/heatTransfer/read/heatRead.cpp b/examples/simulations/heatTransfer/read/heatRead.cpp similarity index 100% rename from examples/heatTransfer/read/heatRead.cpp rename to examples/simulations/heatTransfer/read/heatRead.cpp diff --git a/examples/simulations/heatTransfer/readFileOnly/CMakeLists.txt b/examples/simulations/heatTransfer/readFileOnly/CMakeLists.txt new file mode 100644 index 0000000000..5cb5dd3c4d --- /dev/null +++ b/examples/simulations/heatTransfer/readFileOnly/CMakeLists.txt @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsHeatTransferReadFileOnlyExample) + +if(NOT TARGET adios2_core) + set(_components C CXX) + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_simulations_heatTransferReadFileOnly heatReadFileOnly.cpp PrintData.h) + target_link_libraries(adios2_simulations_heatTransferReadFileOnly adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_simulations_heatTransferReadFileOnly RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif () diff --git a/examples/heatTransfer/read_fileonly/PrintData.h b/examples/simulations/heatTransfer/readFileOnly/PrintData.h similarity index 100% rename from examples/heatTransfer/read_fileonly/PrintData.h rename to examples/simulations/heatTransfer/readFileOnly/PrintData.h diff --git a/examples/heatTransfer/read_fileonly/heatRead_adios2.cpp b/examples/simulations/heatTransfer/readFileOnly/heatReadFileOnly.cpp similarity index 96% rename from examples/heatTransfer/read_fileonly/heatRead_adios2.cpp rename to examples/simulations/heatTransfer/readFileOnly/heatReadFileOnly.cpp index af7d6dfb5e..28ba45d18e 100644 --- a/examples/heatTransfer/read_fileonly/heatRead_adios2.cpp +++ b/examples/simulations/heatTransfer/readFileOnly/heatReadFileOnly.cpp @@ -1,15 +1,14 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ #include #include "adios2.h" #include -#include #include -#include -#include -#include -#include #include #include "PrintData.h" diff --git a/examples/simulations/heatTransfer/write/CMakeLists.txt b/examples/simulations/heatTransfer/write/CMakeLists.txt new file mode 100644 index 0000000000..7f1378c982 --- /dev/null +++ b/examples/simulations/heatTransfer/write/CMakeLists.txt @@ -0,0 +1,81 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsHeatTransferWriteExample) + +if(NOT TARGET adios2_core) + set(_components C CXX) + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(Threads QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if (ADIOS2_HAVE_MPI AND Threads_FOUND) + add_executable(adios2_simulations_heatTransferWrite + main.cpp + HeatTransfer.cpp + Settings.cpp + IO_adios2.cpp + ) + target_link_libraries(adios2_simulations_heatTransferWrite adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_simulations_heatTransferWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_simulations_heatTransferWrite_ascii + main.cpp + HeatTransfer.cpp + Settings.cpp + IO_ascii.cpp + ) + target_link_libraries(adios2_simulations_heatTransferWrite_ascii MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_simulations_heatTransferWrite_ascii RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_HDF5) + add_executable(adios2_simulations_heatTransferWrite_hdf5 + main.cpp + HeatTransfer.cpp + Settings.cpp + IO_hdf5_a.cpp + ) + target_include_directories(adios2_simulations_heatTransferWrite_hdf5 PRIVATE ${HDF5_C_INCLUDE_DIRS}) + target_link_libraries(adios2_simulations_heatTransferWrite_hdf5 + ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_simulations_heatTransferWrite_hdf5 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(HDF5_IS_PARALLEL) + add_executable(adios2_simulations_heatTransferWrite_ph5 + main.cpp + HeatTransfer.cpp + Settings.cpp + IO_ph5.cpp + ) + target_include_directories(adios2_simulations_heatTransferWrite_ph5 PRIVATE ${HDF5_C_INCLUDE_DIRS}) + target_link_libraries(adios2_simulations_heatTransferWrite_ph5 + ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_simulations_heatTransferWrite_ph5 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + if(NOT (HDF5_VERSION VERSION_LESS 1.11)) + add_executable(adios2_simulations_heatTransferWrite_h5mixer + main.cpp + HeatTransfer.cpp + Settings.cpp + IO_h5mixer.cpp + ) + target_link_libraries(adios2_simulations_heatTransferWrite_h5mixer + adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_simulations_heatTransferWrite_h5mixer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + endif() +endif() diff --git a/examples/heatTransfer/write/HeatTransfer.cpp b/examples/simulations/heatTransfer/write/HeatTransfer.cpp similarity index 100% rename from examples/heatTransfer/write/HeatTransfer.cpp rename to examples/simulations/heatTransfer/write/HeatTransfer.cpp diff --git a/examples/heatTransfer/write/HeatTransfer.h b/examples/simulations/heatTransfer/write/HeatTransfer.h similarity index 100% rename from examples/heatTransfer/write/HeatTransfer.h rename to examples/simulations/heatTransfer/write/HeatTransfer.h diff --git a/examples/heatTransfer/write/IO.h b/examples/simulations/heatTransfer/write/IO.h similarity index 100% rename from examples/heatTransfer/write/IO.h rename to examples/simulations/heatTransfer/write/IO.h diff --git a/examples/heatTransfer/write/IO_adios2.cpp b/examples/simulations/heatTransfer/write/IO_adios2.cpp similarity index 99% rename from examples/heatTransfer/write/IO_adios2.cpp rename to examples/simulations/heatTransfer/write/IO_adios2.cpp index b983f3a0bc..b33c2b55ff 100644 --- a/examples/heatTransfer/write/IO_adios2.cpp +++ b/examples/simulations/heatTransfer/write/IO_adios2.cpp @@ -12,7 +12,7 @@ #include -#include +#include "adios2.h" adios2::ADIOS ad; adios2::Engine bpWriter; diff --git a/examples/heatTransfer/write/IO_ascii.cpp b/examples/simulations/heatTransfer/write/IO_ascii.cpp similarity index 100% rename from examples/heatTransfer/write/IO_ascii.cpp rename to examples/simulations/heatTransfer/write/IO_ascii.cpp diff --git a/examples/heatTransfer/write/IO_h5mixer.cpp b/examples/simulations/heatTransfer/write/IO_h5mixer.cpp similarity index 100% rename from examples/heatTransfer/write/IO_h5mixer.cpp rename to examples/simulations/heatTransfer/write/IO_h5mixer.cpp diff --git a/examples/heatTransfer/write/IO_hdf5_a.cpp b/examples/simulations/heatTransfer/write/IO_hdf5_a.cpp similarity index 96% rename from examples/heatTransfer/write/IO_hdf5_a.cpp rename to examples/simulations/heatTransfer/write/IO_hdf5_a.cpp index 2546e03e23..4f2e54c693 100644 --- a/examples/heatTransfer/write/IO_hdf5_a.cpp +++ b/examples/simulations/heatTransfer/write/IO_hdf5_a.cpp @@ -49,7 +49,7 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm com 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 - double mbs = sizeMB / total_time; + double mbs = static_cast(sizeMB) / total_time; if (s.rank == 0) std::cout << "Step " << step << ": " << m_outputfilename << " " << sizeMB << " " << total_time << "" << mbs << std::endl; diff --git a/examples/heatTransfer/write/IO_ph5.cpp b/examples/simulations/heatTransfer/write/IO_ph5.cpp similarity index 100% rename from examples/heatTransfer/write/IO_ph5.cpp rename to examples/simulations/heatTransfer/write/IO_ph5.cpp diff --git a/examples/heatTransfer/write/Settings.cpp b/examples/simulations/heatTransfer/write/Settings.cpp similarity index 100% rename from examples/heatTransfer/write/Settings.cpp rename to examples/simulations/heatTransfer/write/Settings.cpp diff --git a/examples/heatTransfer/write/Settings.h b/examples/simulations/heatTransfer/write/Settings.h similarity index 100% rename from examples/heatTransfer/write/Settings.h rename to examples/simulations/heatTransfer/write/Settings.h diff --git a/examples/heatTransfer/write/main.cpp b/examples/simulations/heatTransfer/write/main.cpp similarity index 100% rename from examples/heatTransfer/write/main.cpp rename to examples/simulations/heatTransfer/write/main.cpp diff --git a/examples/useCases/CMakeLists.txt b/examples/useCases/CMakeLists.txt index f5de8aeacf..e53d930f80 100644 --- a/examples/useCases/CMakeLists.txt +++ b/examples/useCases/CMakeLists.txt @@ -3,5 +3,5 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# +add_subdirectory(fidesOneCell) add_subdirectory(insituGlobalArrays) - diff --git a/examples/useCases/fidesOneCell/CMakeLists.txt b/examples/useCases/fidesOneCell/CMakeLists.txt new file mode 100644 index 0000000000..d64277fc57 --- /dev/null +++ b/examples/useCases/fidesOneCell/CMakeLists.txt @@ -0,0 +1,17 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2UseCasesFidesOneCellExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_useCases_fidesOneCell fidesOneCell.cpp) +target_link_libraries(adios2_useCases_fidesOneCell adios2::cxx11) +install(TARGETS adios2_useCases_fidesOneCell RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/useCases/fidesOneCell/ReadMe.md b/examples/useCases/fidesOneCell/ReadMe.md new file mode 100644 index 0000000000..ef39aa28e0 --- /dev/null +++ b/examples/useCases/fidesOneCell/ReadMe.md @@ -0,0 +1,37 @@ +Single cell example for visualization with Fides schema in ParaView +------------------------------------------------------------------- + +This example writes 8 points in 3D space, the corners of a box, and then defines a single hexagon cell of those eight +points. +The coordinates of the points are stored in three 1D arrays, separating the X-Y-Z coordinates. + +The cell is the enumeration of the points connected in the order of a hexagon prescribed by VTK, see +Figure 19-20 in the VTK User Guide, type VTK_HEXAHEDRON in page 480 (page 494 in the PDF). +https://vtk.org/wp-content/uploads/2021/08/VTKUsersGuide.pdf + +The visualization schema is described in the fidesOneCell.json file, according +to https://fides.readthedocs.io/en/latest/schema/schema.html + +We compose the coordinate system as a composite of the three 1D arrays for X, Y and Z coordinates. This is just an +enumeration of the N points in space (N = size of X = size of Y = size of Z) , in contrast to other examples where X, Y, +Z is combined to specify a structured grid (number of points = size of X * size of Y * size of Z). + +In ParaView, one opens the fidesOneCell.json file and adds an property "source" with the value of the full path of the +onecell.bp. See left-middle Properties box in the ParaView window in the image paraview-onecell-step0.png. Then hit +Apply button and a gray box should appear (the single cell visualized). which can be rotated on screen. Then one must +color the box with the data ("pointdata") to get the pictures shown in the included images. + +Note that the dataset over the points is called "DataOnPoints" in the onecell.bp file, but it is called "pointdata" in +the Fides schema to demonstrate which name is which (ParaView presents pointdata to the user while reading the +DataOnPoints array from the file). + +First step of onecell.bp in ParaView: + +paraview-onecell-step0.png + +Last step of onecell.bp in ParaView: + +paraview-onecell-step9.png + diff --git a/examples/fides/01_onecell/fides_onecell.cpp b/examples/useCases/fidesOneCell/fidesOneCell.cpp similarity index 97% rename from examples/fides/01_onecell/fides_onecell.cpp rename to examples/useCases/fidesOneCell/fidesOneCell.cpp index d02c82750d..e012965fcc 100644 --- a/examples/fides/01_onecell/fides_onecell.cpp +++ b/examples/useCases/fidesOneCell/fidesOneCell.cpp @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) writer.Put(varPointData, pointdata); writer.Put(varCellData, celldata); writer.Put(varStep, step); - writer.Put(varTime, step * 1.0); + writer.Put(varTime, static_cast(step)); writer.EndStep(); } diff --git a/examples/fides/01_onecell/fides_onecell.json b/examples/useCases/fidesOneCell/fidesOneCell.json similarity index 100% rename from examples/fides/01_onecell/fides_onecell.json rename to examples/useCases/fidesOneCell/fidesOneCell.json diff --git a/examples/fides/01_onecell/paraview-onecell-step0.png b/examples/useCases/fidesOneCell/paraview-onecell-step0.png similarity index 100% rename from examples/fides/01_onecell/paraview-onecell-step0.png rename to examples/useCases/fidesOneCell/paraview-onecell-step0.png diff --git a/examples/fides/01_onecell/paraview-onecell-step9.png b/examples/useCases/fidesOneCell/paraview-onecell-step9.png similarity index 100% rename from examples/fides/01_onecell/paraview-onecell-step9.png rename to examples/useCases/fidesOneCell/paraview-onecell-step9.png diff --git a/examples/useCases/insituGlobalArrays/CMakeLists.txt b/examples/useCases/insituGlobalArrays/CMakeLists.txt index 8ef3a1c205..281c687b7e 100644 --- a/examples/useCases/insituGlobalArrays/CMakeLists.txt +++ b/examples/useCases/insituGlobalArrays/CMakeLists.txt @@ -3,16 +3,38 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(insituGlobalArraysWriter insituGlobalArraysWriter.cpp) -target_link_libraries(insituGlobalArraysWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2UseCasesInSituGlobalArraysExample) -add_executable(insituGlobalArraysReaderNxN insituGlobalArraysReaderNxN.cpp) -target_link_libraries(insituGlobalArraysReaderNxN adios2::cxx11) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + + +add_executable(adios2_useCases_insituGlobalArraysWriter insituGlobalArraysWriter.cpp) +target_link_libraries(adios2_useCases_insituGlobalArraysWriter adios2::cxx11) +install(TARGETS adios2_useCases_insituGlobalArraysWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_useCases_insituGlobalArraysReaderNxN insituGlobalArraysReaderNxN.cpp) +target_link_libraries(adios2_useCases_insituGlobalArraysReaderNxN adios2::cxx11) +install(TARGETS adios2_useCases_insituGlobalArraysReaderNxN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(insituGlobalArraysWriter_mpi insituGlobalArraysWriter.cpp) - target_link_libraries(insituGlobalArraysWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_useCases_insituGlobalArraysWriter_mpi insituGlobalArraysWriter.cpp) + target_link_libraries(adios2_useCases_insituGlobalArraysWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_useCases_insituGlobalArraysWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(insituGlobalArraysReaderNxN_mpi insituGlobalArraysReaderNxN.cpp) - target_link_libraries(insituGlobalArraysReaderNxN_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_useCases_insituGlobalArraysReaderNxN_mpi insituGlobalArraysReaderNxN.cpp) + target_link_libraries(adios2_useCases_insituGlobalArraysReaderNxN_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_useCases_insituGlobalArraysReaderNxN_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/testing/examples/heatTransfer/TestBPFileMx1.cmake b/testing/examples/heatTransfer/TestBPFileMx1.cmake index 354856868f..f2855476bb 100644 --- a/testing/examples/heatTransfer/TestBPFileMx1.cmake +++ b/testing/examples/heatTransfer/TestBPFileMx1.cmake @@ -8,8 +8,8 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.BP3.Mx1.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP3.Mx1.Write PROPERTIES PROCESSORS 4) @@ -17,8 +17,8 @@ set_tests_properties(HeatTransfer.BP3.Mx1.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP3.Mx1.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp Read.bp 1 1 ) @@ -43,8 +43,8 @@ SetupTestPipeline(HeatTransfer.BP3.Mx1 "Write;Read;Dump;Validate" TRUE) add_test(NAME HeatTransfer.BP4.Mx1.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP4.Mx1.Write PROPERTIES PROCESSORS 4) @@ -52,8 +52,8 @@ set_tests_properties(HeatTransfer.BP4.Mx1.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP4.Mx1.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp Read.bp 1 1 ) diff --git a/testing/examples/heatTransfer/TestBPFileMx1_zfp.cmake b/testing/examples/heatTransfer/TestBPFileMx1_zfp.cmake index 4f5651a06a..ed75a60b9f 100644 --- a/testing/examples/heatTransfer/TestBPFileMx1_zfp.cmake +++ b/testing/examples/heatTransfer/TestBPFileMx1_zfp.cmake @@ -8,8 +8,8 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.BP3.zfp.Mx1.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3_zfp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3_zfp.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP3.zfp.Mx1.Write PROPERTIES PROCESSORS 4) @@ -17,8 +17,8 @@ set_tests_properties(HeatTransfer.BP3.zfp.Mx1.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP3.zfp.Mx1.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp Read.bp 1 1 ) @@ -36,8 +36,8 @@ SetupTestPipeline(HeatTransfer.BP3.zfp.Mx1 "Write;Read;Dump" TRUE) add_test(NAME HeatTransfer.BP4.zfp.Mx1.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4_zfp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4_zfp.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP3.zfp.Mx1.Write PROPERTIES PROCESSORS 4) @@ -45,8 +45,8 @@ set_tests_properties(HeatTransfer.BP3.zfp.Mx1.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP4.zfp.Mx1.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp Read.bp 1 1 ) diff --git a/testing/examples/heatTransfer/TestBPFileMxM.cmake b/testing/examples/heatTransfer/TestBPFileMxM.cmake index ac3e02bd85..64d5cbe1e2 100644 --- a/testing/examples/heatTransfer/TestBPFileMxM.cmake +++ b/testing/examples/heatTransfer/TestBPFileMxM.cmake @@ -9,8 +9,8 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.BP3.MxM.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP3.MxM.Write PROPERTIES PROCESSORS 4) @@ -18,8 +18,8 @@ set_tests_properties(HeatTransfer.BP3.MxM.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP3.MxM.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp Read.bp 2 2 ) set_tests_properties(HeatTransfer.BP3.MxM.Read PROPERTIES PROCESSORS 4) @@ -44,8 +44,8 @@ SetupTestPipeline(HeatTransfer.BP3.MxM "Write;Read;Dump;Validate" True) add_test(NAME HeatTransfer.BP4.MxM.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP4.MxM.Write PROPERTIES PROCESSORS 4) @@ -53,8 +53,8 @@ set_tests_properties(HeatTransfer.BP4.MxM.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP4.MxM.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp Read.bp 2 2 ) set_tests_properties(HeatTransfer.BP4.MxM.Read PROPERTIES PROCESSORS 4) diff --git a/testing/examples/heatTransfer/TestBPFileMxN.cmake b/testing/examples/heatTransfer/TestBPFileMxN.cmake index 9c89a4977e..b94bd843a3 100644 --- a/testing/examples/heatTransfer/TestBPFileMxN.cmake +++ b/testing/examples/heatTransfer/TestBPFileMxN.cmake @@ -9,8 +9,8 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.BP3.MxN.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP3.MxN.Write PROPERTIES PROCESSORS 4) @@ -18,8 +18,8 @@ set_tests_properties(HeatTransfer.BP3.MxN.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP3.MxN.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp3.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp3.xml Write.bp Read.bp 1 3 ) set_tests_properties(HeatTransfer.BP3.MxN.Read PROPERTIES PROCESSORS 3) @@ -44,8 +44,8 @@ SetupTestPipeline(HeatTransfer.BP3.MxN "Write;Read;Dump;Validate" True) add_test(NAME HeatTransfer.BP4.MxN.Write COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.BP4.MxN.Write PROPERTIES PROCESSORS 4) @@ -53,8 +53,8 @@ set_tests_properties(HeatTransfer.BP4.MxN.Write PROPERTIES PROCESSORS 4) add_test(NAME HeatTransfer.BP4.MxN.Read COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_bp4.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_bp4.xml Write.bp Read.bp 1 3 ) set_tests_properties(HeatTransfer.BP4.MxN.Read PROPERTIES PROCESSORS 3) diff --git a/testing/examples/heatTransfer/TestInlineMxM.cmake b/testing/examples/heatTransfer/TestInlineMxM.cmake index b14102f196..ecdf64abaf 100644 --- a/testing/examples/heatTransfer/TestInlineMxM.cmake +++ b/testing/examples/heatTransfer/TestInlineMxM.cmake @@ -8,8 +8,8 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.Inline.MxM COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_inline.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_inline.xml Read.bp 2 2 10 10 10 10 ) set_tests_properties(HeatTransfer.Inline.MxM PROPERTIES PROCESSORS 8) diff --git a/testing/examples/heatTransfer/TestSSCMx1.cmake b/testing/examples/heatTransfer/TestSSCMx1.cmake index 7183b35657..eb599d00e4 100644 --- a/testing/examples/heatTransfer/TestSSCMx1.cmake +++ b/testing/examples/heatTransfer/TestSSCMx1.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.InsituMPI.Mx1 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_ssc.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_ssc.xml Write.bp 2 2 10 10 10 10 : ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_ssc.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_ssc.xml Write.bp Read.bp 1 1 ) set_tests_properties(HeatTransfer.InsituMPI.Mx1 PROPERTIES PROCESSORS 5) diff --git a/testing/examples/heatTransfer/TestSSCMxM.cmake b/testing/examples/heatTransfer/TestSSCMxM.cmake index 9af79873de..94c326786a 100644 --- a/testing/examples/heatTransfer/TestSSCMxM.cmake +++ b/testing/examples/heatTransfer/TestSSCMxM.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SSC.MxM COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_ssc.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_ssc.xml Write.bp 2 2 10 10 10 10 : ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_ssc.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_ssc.xml Write.bp Read.bp 2 2 ) set_tests_properties(HeatTransfer.SSC.MxM PROPERTIES PROCESSORS 8) diff --git a/testing/examples/heatTransfer/TestSSCMxN.cmake b/testing/examples/heatTransfer/TestSSCMxN.cmake index 46818db55d..ebbbc7e8bf 100644 --- a/testing/examples/heatTransfer/TestSSCMxN.cmake +++ b/testing/examples/heatTransfer/TestSSCMxN.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.InsituMPI.MxN COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_ssc.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_ssc.xml Write.bp 2 2 10 10 10 10 : ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_ssc.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_ssc.xml Write.bp Read.bp 1 3 ) set_tests_properties(HeatTransfer.InsituMPI.MxN PROPERTIES PROCESSORS 7) diff --git a/testing/examples/heatTransfer/TestSSTBPMx1.cmake b/testing/examples/heatTransfer/TestSSTBPMx1.cmake index 7da75f9cb4..6566541d62 100644 --- a/testing/examples/heatTransfer/TestSSTBPMx1.cmake +++ b/testing/examples/heatTransfer/TestSSTBPMx1.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.BP.Mx1 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp.xml Write.bp Read.bp 1 1 SST ) set_tests_properties(HeatTransfer.SST.BP.Mx1 PROPERTIES PROCESSORS 5) diff --git a/testing/examples/heatTransfer/TestSSTBPMxM.cmake b/testing/examples/heatTransfer/TestSSTBPMxM.cmake index 286b707eb7..d4fe9f52ae 100644 --- a/testing/examples/heatTransfer/TestSSTBPMxM.cmake +++ b/testing/examples/heatTransfer/TestSSTBPMxM.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.BP.MxM COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp.xml Write.bp Read.bp 2 2 SST ) set_tests_properties(HeatTransfer.SST.BP.MxM PROPERTIES PROCESSORS 8) diff --git a/testing/examples/heatTransfer/TestSSTBPMxN.cmake b/testing/examples/heatTransfer/TestSSTBPMxN.cmake index 1860244786..c7c26b2f51 100644 --- a/testing/examples/heatTransfer/TestSSTBPMxN.cmake +++ b/testing/examples/heatTransfer/TestSSTBPMxN.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.BP.MxN COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp.xml Write.bp Read.bp 1 3 SST ) set_tests_properties(HeatTransfer.SST.BP.MxN PROPERTIES PROCESSORS 7) diff --git a/testing/examples/heatTransfer/TestSSTBPRDMAMxN.cmake b/testing/examples/heatTransfer/TestSSTBPRDMAMxN.cmake index 70dbb99a7e..487194089d 100644 --- a/testing/examples/heatTransfer/TestSSTBPRDMAMxN.cmake +++ b/testing/examples/heatTransfer/TestSSTBPRDMAMxN.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.BP.RDMA.MxN COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp_rdma.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp_rdma.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_bp_rdma.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_bp_rdma.xml Write.bp Read.bp 1 3 SST ) set_tests_properties(HeatTransfer.SST.BP.RDMA.MxN PROPERTIES PROCESSORS 7) diff --git a/testing/examples/heatTransfer/TestSSTFFSMx1.cmake b/testing/examples/heatTransfer/TestSSTFFSMx1.cmake index 1c261b0f0f..b0dfb92210 100644 --- a/testing/examples/heatTransfer/TestSSTFFSMx1.cmake +++ b/testing/examples/heatTransfer/TestSSTFFSMx1.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.FFS.Mx1 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 1 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs.xml Write.bp Read.bp 1 1 SST ) set_tests_properties(HeatTransfer.SST.FFS.Mx1 PROPERTIES PROCESSORS 5) diff --git a/testing/examples/heatTransfer/TestSSTFFSMxM.cmake b/testing/examples/heatTransfer/TestSSTFFSMxM.cmake index 500869e30c..fd9ff096c9 100644 --- a/testing/examples/heatTransfer/TestSSTFFSMxM.cmake +++ b/testing/examples/heatTransfer/TestSSTFFSMxM.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.FFS.MxM COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs.xml Write.bp Read.bp 2 2 SST ) set_tests_properties(HeatTransfer.SST.FFS.MxM PROPERTIES PROCESSORS 8) diff --git a/testing/examples/heatTransfer/TestSSTFFSMxN.cmake b/testing/examples/heatTransfer/TestSSTFFSMxN.cmake index 774a1ce7ff..0e973c1f5c 100644 --- a/testing/examples/heatTransfer/TestSSTFFSMxN.cmake +++ b/testing/examples/heatTransfer/TestSSTFFSMxN.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.FFS.MxN COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs.xml Write.bp Read.bp 1 3 SST ) set_tests_properties(HeatTransfer.SST.FFS.MxN PROPERTIES PROCESSORS 7) diff --git a/testing/examples/heatTransfer/TestSSTFFSRDMAMxN.cmake b/testing/examples/heatTransfer/TestSSTFFSRDMAMxN.cmake index 70c933e375..08f1cad1a7 100644 --- a/testing/examples/heatTransfer/TestSSTFFSRDMAMxN.cmake +++ b/testing/examples/heatTransfer/TestSSTFFSRDMAMxN.cmake @@ -8,13 +8,13 @@ include(ADIOSFunctions) add_test(NAME HeatTransfer.SST.FFS.MxN COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_EXTRA_FLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs_rdma.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs_rdma.xml Write.bp 2 2 10 10 10 10 SST : ${MPIEXEC_NUMPROC_FLAG} 3 - $ - ${PROJECT_SOURCE_DIR}/examples/heatTransfer/heat_sst_ffs_rdma.xml + $ + ${PROJECT_SOURCE_DIR}/examples/simulations/heatTransfer/heat_sst_ffs_rdma.xml Write.bp Read.bp 1 3 SST ) set_tests_properties(HeatTransfer.SST.FFS.MxN PROPERTIES PROCESSORS 7) diff --git a/testing/install/EncryptionOperator/CMakeLists.txt b/testing/install/EncryptionOperator/CMakeLists.txt index ed4fae524b..aca5c62e68 100644 --- a/testing/install/EncryptionOperator/CMakeLists.txt +++ b/testing/install/EncryptionOperator/CMakeLists.txt @@ -17,14 +17,14 @@ set(ENV{ADIOS2_PLUGIN_PATH} "${adios2_DIR}/../../") # add write test add_executable(adios_plugin_operator_write_test - ../../../examples/plugins/operator/examplePluginOperator_write.cpp + ../../../examples/plugins/operator/examplePluginOperatorWrite.cpp ) target_link_libraries(adios_plugin_operator_write_test adios2::cxx11) add_test(NAME adios_plugin_operator_write_test COMMAND adios_plugin_operator_write_test) # add read test add_executable(adios_plugin_operator_read_test - ../../../examples/plugins/operator/examplePluginOperator_read.cpp + ../../../examples/plugins/operator/examplePluginOperatorRead.cpp ) target_link_libraries(adios_plugin_operator_read_test adios2::cxx11) add_test(NAME adios_plugin_operator_read_test COMMAND adios_plugin_operator_read_test) diff --git a/testing/install/EnginePlugin/CMakeLists.txt b/testing/install/EnginePlugin/CMakeLists.txt index 7a7425f8d6..2949290c2b 100644 --- a/testing/install/EnginePlugin/CMakeLists.txt +++ b/testing/install/EnginePlugin/CMakeLists.txt @@ -43,7 +43,7 @@ endif() # add write test add_executable(adios_plugin_engine_write_test - ../../../examples/plugins/engine/examplePluginEngine_write.cpp + ../../../examples/plugins/engine/examplePluginEngineWrite.cpp ) target_link_libraries(adios_plugin_engine_write_test adios2::cxx11) add_test(NAME adios_plugin_engine_write_test COMMAND adios_plugin_engine_write_test) @@ -53,7 +53,7 @@ set_tests_properties(adios_plugin_engine_write_test PROPERTIES # add read test add_executable(adios_plugin_engine_read_test - ../../../examples/plugins/engine/examplePluginEngine_read.cpp + ../../../examples/plugins/engine/examplePluginEngineRead.cpp ) target_link_libraries(adios_plugin_engine_read_test adios2::cxx11) add_test(NAME adios_plugin_engine_read_test COMMAND adios_plugin_engine_read_test) From 3bdc1aa2b33c53c2f4764e8162e1f8088d788cdb Mon Sep 17 00:00:00 2001 From: Spiros Tsalikis Date: Mon, 18 Sep 2023 14:16:55 -0400 Subject: [PATCH 16/41] Add examples from ADIOS2-Examples 1) Make all examples individually compilable 2) Make examples' executable names be consistent 3) Rename certain examples for clarity 4) Make all examples installable 5) Fix Python formatting using black 6) Add licence documentation wherever it's missing --- examples/basics/CMakeLists.txt | 8 +- examples/basics/globalArray1D/CMakeLists.txt | 80 + examples/basics/globalArray1D/decomp.F90 | 53 + examples/basics/globalArray1D/decomp.c | 67 + examples/basics/globalArray1D/decomp.h | 14 + .../globalArray1D/globalArray1DRead.F90 | 104 + .../basics/globalArray1D/globalArray1DRead.c | 86 + .../globalArray1D/globalArray1DWrite.F90 | 93 + .../basics/globalArray1D/globalArray1DWrite.c | 99 + examples/basics/globalArray1D/mpivars.F90 | 30 + examples/basics/globalArray1D/mpivars.c | 29 + examples/basics/globalArray1D/mpivars.h | 14 + .../globalArrayND/globalArrayNDWrite.cpp | 3 +- examples/basics/queryWorker/CMakeLists.txt | 4 +- examples/basics/queryWorker/README.md | 8 - examples/basics/queryWorker/queryWorker.cpp | 11 +- examples/basics/values/CMakeLists.txt | 21 + examples/basics/values/mpivars.F90 | 30 + examples/basics/values/values.F90 | 169 + .../basics/variablesShapes/CMakeLists.txt | 39 + .../variablesShapes/variablesShapes.cpp | 269 + .../variablesShapes/variablesShapes_hl.cpp | 194 + examples/hello/CMakeLists.txt | 16 + examples/hello/bpThreadWrite/CMakeLists.txt | 21 + .../hello/bpThreadWrite/bpThreadWrite.cpp | 122 + examples/hello/bpWriteReadHip/CMakeLists.txt | 25 + .../hello/bpWriteReadHip/bpWriteReadHip.cpp | 135 + .../hello/bpWriteReadKokkos/CMakeLists.txt | 33 + .../bpWriteReadKokkos/bpWriteReadKokkos.cpp | 117 + examples/hello/helloWorld/CMakeLists.txt | 47 + examples/hello/helloWorld/hello-world-hl.cpp | 75 + examples/hello/helloWorld/hello-world-hl.py | 47 + examples/hello/helloWorld/hello-world.c | 71 + examples/hello/helloWorld/hello-world.cpp | 76 + examples/hello/helloWorld/hello-world.py | 54 + examples/simulations/CMakeLists.txt | 10 + .../GrayScott.jl/.JuliaFormatter.toml | 4 + .../simulations/GrayScott.jl/Project.toml | 19 + examples/simulations/GrayScott.jl/ReadMe.md | 139 + .../GrayScott.jl/examples/settings-files.json | 23 + .../simulations/GrayScott.jl/gray-scott.jl | 15 + .../GrayScott.jl/scripts/config_crusher.sh | 43 + .../GrayScott.jl/scripts/config_summit.sh | 43 + .../GrayScott.jl/scripts/job_crusher.sh | 17 + .../GrayScott.jl/scripts/job_summit.sh | 18 + .../simulations/GrayScott.jl/src/GrayScott.jl | 91 + .../GrayScott.jl/src/analysis/pdfcalc.jl | 160 + .../GrayScott.jl/src/helper/Helper.jl | 7 + .../GrayScott.jl/src/helper/helperMPI.jl | 15 + .../GrayScott.jl/src/helper/helperString.jl | 14 + .../GrayScott.jl/src/simulation/IO.jl | 106 + .../GrayScott.jl/src/simulation/Inputs.jl | 78 + .../GrayScott.jl/src/simulation/Simulation.jl | 281 + .../src/simulation/Simulation_AMDGPU.jl | 168 + .../src/simulation/Simulation_CUDA.jl | 160 + .../GrayScott.jl/src/simulation/Structs.jl | 102 + .../GrayScott.jl/test/Project.toml | 3 + .../test/functional/functional-GrayScott.jl | 12 + .../simulations/GrayScott.jl/test/runtests.jl | 26 + .../test/unit/analysis/unit-pdfcalc.jl | 19 + .../test/unit/helper/unit-helperMPI.jl | 12 + .../test/unit/simulation/unit-IO.jl | 36 + .../test/unit/simulation/unit-Inputs.jl | 15 + .../test/unit/simulation/unit-Simulation.jl | 34 + .../unit/simulation/unit-Simulation_CUDA.jl | 28 + .../gray-scott-kokkos/CMakeLists.txt | 47 + .../simulations/gray-scott-kokkos/README.md | 2 + .../gray-scott-kokkos/gray-scott.cpp | 330 + .../gray-scott-kokkos/gray-scott.h | 102 + .../simulations/gray-scott-kokkos/json.hpp | 20274 ++++++++++++++++ .../simulations/gray-scott-kokkos/main.cpp | 183 + .../simulations/gray-scott-kokkos/restart.cpp | 96 + .../simulations/gray-scott-kokkos/restart.h | 18 + .../gray-scott-kokkos/settings.cpp | 89 + .../simulations/gray-scott-kokkos/settings.h | 37 + .../simulations/gray-scott-kokkos/timer.hpp | 55 + .../simulations/gray-scott-kokkos/writer.cpp | 140 + .../simulations/gray-scott-kokkos/writer.h | 32 + .../gray-scott-struct/CMakeLists.txt | 70 + .../simulations/gray-scott-struct/README.md | 197 + .../adios2-inline-plugin.xml | 135 + .../simulations/gray-scott-struct/adios2.xml | 142 + .../gray-scott-struct/analysis/curvature.cpp | 202 + .../gray-scott-struct/analysis/find_blobs.cpp | 245 + .../gray-scott-struct/analysis/isosurface.cpp | 346 + .../gray-scott-struct/analysis/pdf-calc.cpp | 354 + .../gray-scott-struct/catalyst/gs-fides.json | 60 + .../gray-scott-struct/catalyst/gs-pipeline.py | 65 + .../gray-scott-struct/catalyst/setup.sh | 6 + .../simulations/gray-scott-struct/cleanup.sh | 28 + .../gray-scott-struct/common/timer.hpp | 59 + .../gray-scott-struct/img/example1.jpg | Bin 0 -> 23365 bytes .../gray-scott-struct/img/example2.jpg | Bin 0 -> 24700 bytes .../gray-scott-struct/img/example3.jpg | Bin 0 -> 22000 bytes .../gray-scott-struct/img/example4.jpg | Bin 0 -> 19246 bytes .../gray-scott-struct/img/example5.jpg | Bin 0 -> 17746 bytes .../gray-scott-struct/plot/decomp.py | 121 + .../gray-scott-struct/plot/gsplot.py | 187 + .../gray-scott-struct/plot/pdfplot.py | 135 + .../plot/render_isosurface.cpp | 204 + .../gray-scott-struct/simulation/LICENSE | 20 + .../simulation/gray-scott.cpp | 290 + .../gray-scott-struct/simulation/gray-scott.h | 131 + .../gray-scott-struct/simulation/json.hpp | 20274 ++++++++++++++++ .../gray-scott-struct/simulation/main.cpp | 176 + .../gray-scott-struct/simulation/restart.cpp | 92 + .../gray-scott-struct/simulation/restart.h | 19 + .../simulation/settings-files.json | 21 + .../simulation/settings-inline.json | 21 + .../simulation/settings-staging.json | 21 + .../gray-scott-struct/simulation/settings.cpp | 89 + .../gray-scott-struct/simulation/settings.h | 37 + .../gray-scott-struct/simulation/writer.cpp | 146 + .../gray-scott-struct/simulation/writer.h | 33 + .../gray-scott-struct/test-firstrun.json | 21 + .../gray-scott-struct/test-restart.json | 21 + .../gray-scott-struct/visit-bp4.session | 5456 +++++ .../gray-scott-struct/visit-bp4.session.gui | 54 + .../gray-scott-struct/visit-sst.session | 5600 +++++ .../gray-scott-struct/visit-sst.session.gui | 54 + .../simulations/gray-scott/CMakeLists.txt | 69 + examples/simulations/gray-scott/README.md | 211 + .../gray-scott/adios2-fides-staging.xml | 142 + .../gray-scott/adios2-inline-plugin.xml | 135 + examples/simulations/gray-scott/adios2.xml | 142 + .../gray-scott/analysis/curvature.cpp | 202 + .../gray-scott/analysis/find_blobs.cpp | 245 + .../gray-scott/analysis/isosurface.cpp | 346 + .../gray-scott/analysis/pdf-calc.cpp | 354 + .../gray-scott/catalyst/gs-fides.json | 60 + .../gray-scott/catalyst/gs-pipeline.py | 193 + .../simulations/gray-scott/catalyst/setup.sh | 6 + examples/simulations/gray-scott/cleanup.sh | 28 + .../simulations/gray-scott/common/timer.hpp | 55 + .../simulations/gray-scott/img/example1.jpg | Bin 0 -> 23365 bytes .../simulations/gray-scott/img/example2.jpg | Bin 0 -> 24700 bytes .../simulations/gray-scott/img/example3.jpg | Bin 0 -> 22000 bytes .../simulations/gray-scott/img/example4.jpg | Bin 0 -> 19246 bytes .../simulations/gray-scott/img/example5.jpg | Bin 0 -> 17746 bytes .../simulations/gray-scott/plot/decomp.py | 121 + .../simulations/gray-scott/plot/gsplot.py | 187 + .../simulations/gray-scott/plot/pdfplot.py | 135 + .../gray-scott/plot/render_isosurface.cpp | 204 + .../simulations/gray-scott/simulation/LICENSE | 20 + .../gray-scott/simulation/gray-scott.cpp | 277 + .../gray-scott/simulation/gray-scott.h | 130 + .../gray-scott/simulation/json.hpp | 20274 ++++++++++++++++ .../gray-scott/simulation/main.cpp | 177 + .../gray-scott/simulation/restart.cpp | 96 + .../gray-scott/simulation/restart.h | 19 + .../gray-scott/simulation/settings-files.json | 21 + .../simulation/settings-inline.json | 21 + .../simulation/settings-staging.json | 21 + .../gray-scott/simulation/settings.cpp | 89 + .../gray-scott/simulation/settings.h | 37 + .../gray-scott/simulation/writer.cpp | 152 + .../gray-scott/simulation/writer.h | 33 + .../simulations/gray-scott/visit-bp4.session | 5456 +++++ .../gray-scott/visit-bp4.session.gui | 54 + .../simulations/gray-scott/visit-sst.session | 5600 +++++ .../gray-scott/visit-sst.session.gui | 54 + .../korteweg-de-vries/CMakeLists.txt | 17 + .../simulations/korteweg-de-vries/KdV.cpp | 198 + .../simulations/korteweg-de-vries/README.md | 15 + .../korteweg-de-vries/graph_solution.py | 34 + .../simulations/lorenz_ode/CMakeLists.txt | 23 + examples/simulations/lorenz_ode/README.md | 38 + examples/simulations/lorenz_ode/lorenz.hpp | 221 + .../simulations/lorenz_ode/lorenzReader.cpp | 123 + .../simulations/lorenz_ode/lorenzWriter.cpp | 88 + .../simulations/lorenz_ode/lorenz_ode.svg | 2 + .../lorenz_ode/ode_phase_space.svg | 2 + .../simulations/lorenz_ode/ode_tuples.svg | 2 + .../lorenz_ode/second_derivative.svg | 2 + .../simulations/lorenz_ode/taylor_series.svg | 2 + 175 files changed, 96611 insertions(+), 21 deletions(-) create mode 100644 examples/basics/globalArray1D/CMakeLists.txt create mode 100644 examples/basics/globalArray1D/decomp.F90 create mode 100644 examples/basics/globalArray1D/decomp.c create mode 100644 examples/basics/globalArray1D/decomp.h create mode 100644 examples/basics/globalArray1D/globalArray1DRead.F90 create mode 100644 examples/basics/globalArray1D/globalArray1DRead.c create mode 100644 examples/basics/globalArray1D/globalArray1DWrite.F90 create mode 100644 examples/basics/globalArray1D/globalArray1DWrite.c create mode 100644 examples/basics/globalArray1D/mpivars.F90 create mode 100644 examples/basics/globalArray1D/mpivars.c create mode 100644 examples/basics/globalArray1D/mpivars.h delete mode 100644 examples/basics/queryWorker/README.md create mode 100644 examples/basics/values/mpivars.F90 create mode 100644 examples/basics/values/values.F90 create mode 100644 examples/basics/variablesShapes/CMakeLists.txt create mode 100644 examples/basics/variablesShapes/variablesShapes.cpp create mode 100644 examples/basics/variablesShapes/variablesShapes_hl.cpp create mode 100644 examples/hello/bpThreadWrite/CMakeLists.txt create mode 100644 examples/hello/bpThreadWrite/bpThreadWrite.cpp create mode 100644 examples/hello/bpWriteReadHip/CMakeLists.txt create mode 100644 examples/hello/bpWriteReadHip/bpWriteReadHip.cpp create mode 100644 examples/hello/bpWriteReadKokkos/CMakeLists.txt create mode 100644 examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp create mode 100644 examples/hello/helloWorld/CMakeLists.txt create mode 100644 examples/hello/helloWorld/hello-world-hl.cpp create mode 100644 examples/hello/helloWorld/hello-world-hl.py create mode 100644 examples/hello/helloWorld/hello-world.c create mode 100644 examples/hello/helloWorld/hello-world.cpp create mode 100644 examples/hello/helloWorld/hello-world.py create mode 100644 examples/simulations/GrayScott.jl/.JuliaFormatter.toml create mode 100644 examples/simulations/GrayScott.jl/Project.toml create mode 100644 examples/simulations/GrayScott.jl/ReadMe.md create mode 100644 examples/simulations/GrayScott.jl/examples/settings-files.json create mode 100644 examples/simulations/GrayScott.jl/gray-scott.jl create mode 100644 examples/simulations/GrayScott.jl/scripts/config_crusher.sh create mode 100644 examples/simulations/GrayScott.jl/scripts/config_summit.sh create mode 100644 examples/simulations/GrayScott.jl/scripts/job_crusher.sh create mode 100644 examples/simulations/GrayScott.jl/scripts/job_summit.sh create mode 100644 examples/simulations/GrayScott.jl/src/GrayScott.jl create mode 100644 examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl create mode 100644 examples/simulations/GrayScott.jl/src/helper/Helper.jl create mode 100644 examples/simulations/GrayScott.jl/src/helper/helperMPI.jl create mode 100644 examples/simulations/GrayScott.jl/src/helper/helperString.jl create mode 100644 examples/simulations/GrayScott.jl/src/simulation/IO.jl create mode 100644 examples/simulations/GrayScott.jl/src/simulation/Inputs.jl create mode 100644 examples/simulations/GrayScott.jl/src/simulation/Simulation.jl create mode 100644 examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl create mode 100644 examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl create mode 100644 examples/simulations/GrayScott.jl/src/simulation/Structs.jl create mode 100644 examples/simulations/GrayScott.jl/test/Project.toml create mode 100644 examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl create mode 100644 examples/simulations/GrayScott.jl/test/runtests.jl create mode 100644 examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl create mode 100644 examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl create mode 100644 examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl create mode 100644 examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl create mode 100644 examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl create mode 100644 examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl create mode 100644 examples/simulations/gray-scott-kokkos/CMakeLists.txt create mode 100644 examples/simulations/gray-scott-kokkos/README.md create mode 100644 examples/simulations/gray-scott-kokkos/gray-scott.cpp create mode 100644 examples/simulations/gray-scott-kokkos/gray-scott.h create mode 100644 examples/simulations/gray-scott-kokkos/json.hpp create mode 100644 examples/simulations/gray-scott-kokkos/main.cpp create mode 100644 examples/simulations/gray-scott-kokkos/restart.cpp create mode 100644 examples/simulations/gray-scott-kokkos/restart.h create mode 100644 examples/simulations/gray-scott-kokkos/settings.cpp create mode 100644 examples/simulations/gray-scott-kokkos/settings.h create mode 100644 examples/simulations/gray-scott-kokkos/timer.hpp create mode 100644 examples/simulations/gray-scott-kokkos/writer.cpp create mode 100644 examples/simulations/gray-scott-kokkos/writer.h create mode 100644 examples/simulations/gray-scott-struct/CMakeLists.txt create mode 100644 examples/simulations/gray-scott-struct/README.md create mode 100644 examples/simulations/gray-scott-struct/adios2-inline-plugin.xml create mode 100644 examples/simulations/gray-scott-struct/adios2.xml create mode 100644 examples/simulations/gray-scott-struct/analysis/curvature.cpp create mode 100644 examples/simulations/gray-scott-struct/analysis/find_blobs.cpp create mode 100644 examples/simulations/gray-scott-struct/analysis/isosurface.cpp create mode 100644 examples/simulations/gray-scott-struct/analysis/pdf-calc.cpp create mode 100644 examples/simulations/gray-scott-struct/catalyst/gs-fides.json create mode 100644 examples/simulations/gray-scott-struct/catalyst/gs-pipeline.py create mode 100644 examples/simulations/gray-scott-struct/catalyst/setup.sh create mode 100755 examples/simulations/gray-scott-struct/cleanup.sh create mode 100644 examples/simulations/gray-scott-struct/common/timer.hpp create mode 100644 examples/simulations/gray-scott-struct/img/example1.jpg create mode 100644 examples/simulations/gray-scott-struct/img/example2.jpg create mode 100644 examples/simulations/gray-scott-struct/img/example3.jpg create mode 100644 examples/simulations/gray-scott-struct/img/example4.jpg create mode 100644 examples/simulations/gray-scott-struct/img/example5.jpg create mode 100644 examples/simulations/gray-scott-struct/plot/decomp.py create mode 100644 examples/simulations/gray-scott-struct/plot/gsplot.py create mode 100644 examples/simulations/gray-scott-struct/plot/pdfplot.py create mode 100644 examples/simulations/gray-scott-struct/plot/render_isosurface.cpp create mode 100644 examples/simulations/gray-scott-struct/simulation/LICENSE create mode 100644 examples/simulations/gray-scott-struct/simulation/gray-scott.cpp create mode 100644 examples/simulations/gray-scott-struct/simulation/gray-scott.h create mode 100644 examples/simulations/gray-scott-struct/simulation/json.hpp create mode 100644 examples/simulations/gray-scott-struct/simulation/main.cpp create mode 100644 examples/simulations/gray-scott-struct/simulation/restart.cpp create mode 100644 examples/simulations/gray-scott-struct/simulation/restart.h create mode 100644 examples/simulations/gray-scott-struct/simulation/settings-files.json create mode 100644 examples/simulations/gray-scott-struct/simulation/settings-inline.json create mode 100644 examples/simulations/gray-scott-struct/simulation/settings-staging.json create mode 100644 examples/simulations/gray-scott-struct/simulation/settings.cpp create mode 100644 examples/simulations/gray-scott-struct/simulation/settings.h create mode 100644 examples/simulations/gray-scott-struct/simulation/writer.cpp create mode 100644 examples/simulations/gray-scott-struct/simulation/writer.h create mode 100644 examples/simulations/gray-scott-struct/test-firstrun.json create mode 100644 examples/simulations/gray-scott-struct/test-restart.json create mode 100644 examples/simulations/gray-scott-struct/visit-bp4.session create mode 100644 examples/simulations/gray-scott-struct/visit-bp4.session.gui create mode 100644 examples/simulations/gray-scott-struct/visit-sst.session create mode 100644 examples/simulations/gray-scott-struct/visit-sst.session.gui create mode 100644 examples/simulations/gray-scott/CMakeLists.txt create mode 100644 examples/simulations/gray-scott/README.md create mode 100644 examples/simulations/gray-scott/adios2-fides-staging.xml create mode 100644 examples/simulations/gray-scott/adios2-inline-plugin.xml create mode 100644 examples/simulations/gray-scott/adios2.xml create mode 100644 examples/simulations/gray-scott/analysis/curvature.cpp create mode 100644 examples/simulations/gray-scott/analysis/find_blobs.cpp create mode 100644 examples/simulations/gray-scott/analysis/isosurface.cpp create mode 100644 examples/simulations/gray-scott/analysis/pdf-calc.cpp create mode 100644 examples/simulations/gray-scott/catalyst/gs-fides.json create mode 100644 examples/simulations/gray-scott/catalyst/gs-pipeline.py create mode 100644 examples/simulations/gray-scott/catalyst/setup.sh create mode 100755 examples/simulations/gray-scott/cleanup.sh create mode 100644 examples/simulations/gray-scott/common/timer.hpp create mode 100644 examples/simulations/gray-scott/img/example1.jpg create mode 100644 examples/simulations/gray-scott/img/example2.jpg create mode 100644 examples/simulations/gray-scott/img/example3.jpg create mode 100644 examples/simulations/gray-scott/img/example4.jpg create mode 100644 examples/simulations/gray-scott/img/example5.jpg create mode 100644 examples/simulations/gray-scott/plot/decomp.py create mode 100644 examples/simulations/gray-scott/plot/gsplot.py create mode 100644 examples/simulations/gray-scott/plot/pdfplot.py create mode 100644 examples/simulations/gray-scott/plot/render_isosurface.cpp create mode 100644 examples/simulations/gray-scott/simulation/LICENSE create mode 100644 examples/simulations/gray-scott/simulation/gray-scott.cpp create mode 100644 examples/simulations/gray-scott/simulation/gray-scott.h create mode 100644 examples/simulations/gray-scott/simulation/json.hpp create mode 100644 examples/simulations/gray-scott/simulation/main.cpp create mode 100644 examples/simulations/gray-scott/simulation/restart.cpp create mode 100644 examples/simulations/gray-scott/simulation/restart.h create mode 100644 examples/simulations/gray-scott/simulation/settings-files.json create mode 100644 examples/simulations/gray-scott/simulation/settings-inline.json create mode 100644 examples/simulations/gray-scott/simulation/settings-staging.json create mode 100644 examples/simulations/gray-scott/simulation/settings.cpp create mode 100644 examples/simulations/gray-scott/simulation/settings.h create mode 100644 examples/simulations/gray-scott/simulation/writer.cpp create mode 100644 examples/simulations/gray-scott/simulation/writer.h create mode 100644 examples/simulations/gray-scott/visit-bp4.session create mode 100644 examples/simulations/gray-scott/visit-bp4.session.gui create mode 100644 examples/simulations/gray-scott/visit-sst.session create mode 100644 examples/simulations/gray-scott/visit-sst.session.gui create mode 100644 examples/simulations/korteweg-de-vries/CMakeLists.txt create mode 100644 examples/simulations/korteweg-de-vries/KdV.cpp create mode 100644 examples/simulations/korteweg-de-vries/README.md create mode 100644 examples/simulations/korteweg-de-vries/graph_solution.py create mode 100644 examples/simulations/lorenz_ode/CMakeLists.txt create mode 100644 examples/simulations/lorenz_ode/README.md create mode 100644 examples/simulations/lorenz_ode/lorenz.hpp create mode 100644 examples/simulations/lorenz_ode/lorenzReader.cpp create mode 100644 examples/simulations/lorenz_ode/lorenzWriter.cpp create mode 100644 examples/simulations/lorenz_ode/lorenz_ode.svg create mode 100644 examples/simulations/lorenz_ode/ode_phase_space.svg create mode 100644 examples/simulations/lorenz_ode/ode_tuples.svg create mode 100644 examples/simulations/lorenz_ode/second_derivative.svg create mode 100644 examples/simulations/lorenz_ode/taylor_series.svg diff --git a/examples/basics/CMakeLists.txt b/examples/basics/CMakeLists.txt index 7e470c02d1..972125c4df 100644 --- a/examples/basics/CMakeLists.txt +++ b/examples/basics/CMakeLists.txt @@ -3,10 +3,12 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# +if(ADIOS2_HAVE_MPI) + add_subdirectory(globalArray1D) +endif() add_subdirectory(globalArrayND) add_subdirectory(joinedArray) add_subdirectory(localArray) -if(ADIOS2_HAVE_DATAMAN) - add_subdirectory(queryWorker) -endif() +add_subdirectory(queryWorker) add_subdirectory(values) +add_subdirectory(variablesShapes) diff --git a/examples/basics/globalArray1D/CMakeLists.txt b/examples/basics/globalArray1D/CMakeLists.txt new file mode 100644 index 0000000000..1173b5fab5 --- /dev/null +++ b/examples/basics/globalArray1D/CMakeLists.txt @@ -0,0 +1,80 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsGlobalArray1DExample) + +if(NOT TARGET adios2_core) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI) + add_library(adios2_basics_globalArray1D_mpivars_c OBJECT mpivars.c) + target_link_libraries(adios2_basics_globalArray1D_mpivars_c MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1D_mpivars_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_library(adios2_basics_globalArray1D_decomp_c OBJECT decomp.c) + target_link_libraries(adios2_basics_globalArray1D_decomp_c + adios2_basics_globalArray1D_mpivars_c MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1D_decomp_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DWrite_c globalArray1DWrite.c) + target_link_libraries(adios2_basics_globalArray1DWrite_c + adios2_basics_globalArray1D_mpivars_c + adios2_basics_globalArray1D_decomp_c + adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1DWrite_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DRead_c globalArray1DRead.c) + target_link_libraries(adios2_basics_globalArray1DRead_c + adios2_basics_globalArray1D_mpivars_c + adios2_basics_globalArray1D_decomp_c + adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1DRead_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_Fortran) + add_library(adios2_basics_globalArray1D_mpivars_f OBJECT mpivars.F90) + target_link_libraries(adios2_basics_globalArray1D_mpivars_f MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1D_mpivars_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_library(adios2_basics_globalArray1D_decomp_f OBJECT decomp.F90) + target_link_libraries(adios2_basics_globalArray1D_decomp_f + adios2_basics_globalArray1D_mpivars_f MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1D_decomp_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DWrite_f globalArray1DWrite.F90) + target_link_libraries(adios2_basics_globalArray1DWrite_f + adios2_basics_globalArray1D_mpivars_f + adios2_basics_globalArray1D_decomp_f + adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1DWrite_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DRead_f globalArray1DRead.F90) + target_link_libraries(adios2_basics_globalArray1DRead_f + adios2_basics_globalArray1D_mpivars_f + adios2_basics_globalArray1D_decomp_f + adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1DRead_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() +endif() diff --git a/examples/basics/globalArray1D/decomp.F90 b/examples/basics/globalArray1D/decomp.F90 new file mode 100644 index 0000000000..b39d93d92c --- /dev/null +++ b/examples/basics/globalArray1D/decomp.F90 @@ -0,0 +1,53 @@ +! Helper functions for all examples +module decomp +contains + +! random integer from {minv, minv+1, ..., maxv} +! including minv and maxv +function get_random(minv, maxv) result(n) + implicit none + integer, intent(in) :: minv, maxv + real :: r + integer :: n + call random_number(r) + n = minv + FLOOR((maxv+1-minv)*r) +end function get_random + +! gather the local sizes of arrays and sum them up +! so that each process knows the global shape +! and its own offset in the global space +subroutine gather_decomp_1d(mysize, myshape, myoffset) + use mpivars + implicit none + integer*8, intent(in) :: mysize + integer*8, intent(out) :: myshape, myoffset + integer*8, dimension(:), allocatable :: sizes + + allocate(sizes(nproc)) + call MPI_Allgather( mysize, 1, MPI_LONG_LONG, & + sizes, 1, MPI_LONG_LONG, & + app_comm, ierr) + myshape = sum(sizes) + myoffset = sum(sizes(1:rank)) + deallocate(sizes) +end subroutine gather_decomp_1d + +subroutine decompose_1d(globalsize, myoffset, mysize) + use mpivars + implicit none + integer*8, intent(in) :: globalsize + integer*8, intent(out) :: myoffset, mysize + integer*8 :: rem + + mysize = globalsize/nproc + rem = globalsize-(nproc*mysize) + if (rank < rem) then + mysize = mysize + 1 + myoffset = rank*mysize + else + myoffset = rank*mysize + rem + endif +end subroutine decompose_1d + +end module decomp + diff --git a/examples/basics/globalArray1D/decomp.c b/examples/basics/globalArray1D/decomp.c new file mode 100644 index 0000000000..bb7d3300a5 --- /dev/null +++ b/examples/basics/globalArray1D/decomp.c @@ -0,0 +1,67 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + * + * Helper functions for all examples + */ +#include "decomp.h" +#include "mpivars.h" +#include +#include +#include +#include + +/* random integer from {minv, minv+1, ..., maxv} + including minv and maxv */ +long long int get_random(int minv, int maxv) +{ + long long int n; + time_t t; + /* Intializes random number generator */ + srand((unsigned)time(&t)); + n = (rand() % (maxv - minv + 1)) + minv; + return n; +} +/* gather the local sizes of arrays and sum them up + so that each process knows the global shape + and its own offset in the global space */ +void gather_decomp_1d(long long int *mysize, long long int *myshape, long long int *myoffset) +{ + long long int *sizes; + int i; + sizes = malloc(sizeof(long long int) * (size_t)nproc); + MPI_Allgather(mysize, 1, MPI_LONG_LONG, sizes, 1, MPI_LONG_LONG, app_comm); + + *myshape = 0; + for (i = 0; i < nproc; i++) + { + *myshape += sizes[i]; + } + *myoffset = 0; + for (i = 0; i < rank; i++) + { + *myoffset += sizes[i]; + } + + free(sizes); + return; +} + +void decomp_1d(long long int globalsize, long long int *myoffset, long long int *mysize) +{ + long long int rem; + *mysize = globalsize / nproc; + rem = globalsize - (nproc * *mysize); + if (rank < rem) + { + mysize = mysize + 1; + *myoffset = rank * *mysize; + } + else + { + *myoffset = rank * *mysize + rem; + } + return; +} diff --git a/examples/basics/globalArray1D/decomp.h b/examples/basics/globalArray1D/decomp.h new file mode 100644 index 0000000000..e972714844 --- /dev/null +++ b/examples/basics/globalArray1D/decomp.h @@ -0,0 +1,14 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ + +#ifndef ADIOS2EXAMPLES_DECOMP_H +#define ADIOS2EXAMPLES_DECOMP_H + +extern long long int get_random(int, int); +extern void gather_decomp_1d(long long int *, long long int *, long long int *); +extern void decomp_1d(long long int, long long int *, long long int *); +#endif // ADIOS2EXAMPLES_DECOMP_H diff --git a/examples/basics/globalArray1D/globalArray1DRead.F90 b/examples/basics/globalArray1D/globalArray1DRead.F90 new file mode 100644 index 0000000000..725f1992cd --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DRead.F90 @@ -0,0 +1,104 @@ +program adios2_global_array_1d_read + use mpivars + use adios2 + implicit none + + ! ADIOS2 variables + type(adios2_adios) :: adios + + ! MPI then ADIOS2 initialization + call init_mpi(234) + call adios2_init(adios, app_comm, ierr) + + call reader() + + ! ADIOS2 then MPI finalization + call adios2_finalize(adios, ierr) + call finalize_mpi() + +contains + +subroutine reader + use mpivars + use decomp + use adios2 + implicit none + + character(len=256), parameter :: streamname = "adios2-global-array-1d-f.bp" + + type(adios2_io) :: io + type(adios2_engine) :: engine + type(adios2_variable) :: var_g + integer :: step, istatus + + ! Application variables + ! g = 1D distributed array, global shape and per-process size is fixed + + real*4, dimension(:), allocatable :: g + integer :: ndims + integer*8, dimension(:), allocatable :: fixed_shape + integer*8, dimension(1) :: fixed_start, fixed_count + + call adios2_declare_io (io, adios, 'input', ierr) + call adios2_open(engine, io, streamname, adios2_mode_read, ierr) + if (ierr .ne. 0) then + print '(" Failed to open stream: ",a)', streamname + print '(" open stream ierr=: ",i0)', ierr + return + endif + + ! Reading steps + step = 0 + do + call adios2_begin_step(engine, adios2_step_mode_read, 0.0, istatus, ierr) + if (ierr /= 0) then + print '(" Failure when trying to get next step: ",a)', streamname + exit + endif + if (istatus == adios2_step_status_end_of_stream) then + ! Stream has terminated, no more steps are available + !print '(" Input stream has terminated: ",a)', streamname + exit + endif + + ! Variable pointer MUST be retrieved every step, the reference + ! will go invalid after adios2_end_step + call adios2_inquire_variable(var_g, io, "GlobalArray", ierr ) + + ! Get variable dimensions and do decomposition in the first step + ! These don't change for the stream in this example + if (step == 0) then + ! fixed_shape is allocated in the next call + call adios2_variable_shape(fixed_shape, ndims, var_g, ierr) + + call decompose_1d(fixed_shape(1), fixed_start(1), fixed_count(1)) + allocate(g(fixed_count(1))) + + write (*,100) "Read plan rank=", rank, & + " global shape = ", fixed_shape(1), & + " local count = ", fixed_count(1), & + " offset = ", fixed_start(1) +100 format (a,i2,a,i4,a,i1,a,i4) + endif + + call adios2_set_selection(var_g, 1, fixed_start, fixed_count, ierr) + call adios2_get(engine, var_g, g, ierr) + call adios2_end_step(engine, ierr) + + ! g[] is now filled with data AFTER adios2_end_step/adios2_perform_gets + ! or should call adios2_get(engine, var_g, g, adios2_mode_sync, ierr) + ! to get it immediately in the get() call + + step = step + 1 + enddo + + ! Close the output + call adios2_close(engine, ierr) + + deallocate(g) + deallocate(fixed_shape) + +end subroutine reader + + +end program adios2_global_array_1d_read diff --git a/examples/basics/globalArray1D/globalArray1DRead.c b/examples/basics/globalArray1D/globalArray1DRead.c new file mode 100644 index 0000000000..288ce9f11b --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DRead.c @@ -0,0 +1,86 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#include "decomp.h" +#include "mpivars.h" +#include +#include +#include + +void reader(adios2_adios *adios) +{ + int step; + float *g; + const char *streamname = "adios2-global-array-1d-c.bp"; + adios2_step_status err; + + long long int fixed_shape = 0, fixed_start = 0, fixed_count = 0; + + adios2_io *io = adios2_declare_io(adios, "input"); + size_t shape[1]; + shape[0] = (size_t)fixed_shape; + + adios2_engine *engine = adios2_open(io, streamname, adios2_mode_read); + step = 0; + do + { + adios2_begin_step(engine, adios2_step_mode_read, 10.0, &err); + adios2_variable *var_g = adios2_inquire_variable(io, "GlobalArray"); + if (step == 0) + { + /* fixed_shape is allocated in the next call*/ + adios2_variable_shape(shape, var_g); + fixed_shape = (long long int)shape[0]; + decomp_1d(fixed_shape, &fixed_start, &fixed_count); + g = malloc((size_t)fixed_count * sizeof(float)); + + printf("Read plan rank = %d global shape = %lld local count = %lld " + "offset = %lld\n", + rank, fixed_shape, fixed_count, fixed_start); + } + adios2_end_step(engine); + step++; + } while (err != adios2_step_status_end_of_stream); + // Close the output + adios2_close(engine); + free(g); + + if (rank == 0) + { + printf("Try the following: \n"); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n " + "%lld \n", + fixed_shape); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n " + "%lld \n ", + fixed_shape); + printf(" mpirun -n 2 ./adios2-global-array-1d-read-c \n"); + } +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + init_mpi(123, argc, argv); +#endif + + { +#if ADIOS2_USE_MPI + + adios2_adios *adios = adios2_init_mpi(MPI_COMM_WORLD); +#else + adios2_adios *adios = adios2_init(); +#endif + reader(adios); + adios2_finalize(adios); + } + +#if ADIOS2_USE_MPI + finalize_mpi(); +#endif + + return 0; +} diff --git a/examples/basics/globalArray1D/globalArray1DWrite.F90 b/examples/basics/globalArray1D/globalArray1DWrite.F90 new file mode 100644 index 0000000000..90d0778909 --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DWrite.F90 @@ -0,0 +1,93 @@ +program adios2_global_array_1d_write + use mpivars + use adios2 + implicit none + integer, parameter :: numsteps = 5 + + ! ADIOS2 variables + type(adios2_adios) :: adios + + ! MPI then ADIOS2 initialization + call init_mpi(123) + call adios2_init(adios, app_comm, ierr) + + call writer() + + ! ADIOS2 then MPI finalization + call adios2_finalize(adios, ierr) + call finalize_mpi() + +contains + +subroutine writer + use mpivars + use decomp + use adios2 + implicit none + + type(adios2_io) :: io + type(adios2_engine) :: engine + type(adios2_variable) :: var_g + type(adios2_attribute) :: attr + integer :: step + + ! Application variables + ! g = 1D distributed array, + ! global shape and per-process size is fixed + + real*4, dimension(:), allocatable :: g + character(80), parameter :: ga = "Global Array with fixed shape and decomposition" + + integer, parameter :: mincount = 2, maxcount = 5 + integer*8, dimension(1) :: fixed_shape, fixed_start, fixed_count + + fixed_count(1) = get_random(mincount, maxcount) + allocate(g(fixed_count(1))) + call gather_decomp_1d(fixed_count(1), fixed_shape(1), fixed_start(1)) + + call adios2_declare_io (io, adios, 'output', ierr) + + call adios2_define_variable(var_g, io, "GlobalArray", & + adios2_type_real4, 1, & + fixed_shape, fixed_start, fixed_count, & + adios2_constant_dims, ierr) + + call adios2_define_attribute(attr, io, "GlobalArray/info", ga, ierr) + + call adios2_open(engine, io, "adios2-global-array-1d-f.bp", adios2_mode_write, ierr) + + write (*,100) "Decomp rank=", rank, & + " global shape = ", fixed_shape(1), & + " local count = ", fixed_count(1), & + " offset = ", fixed_start(1) +100 format (a,i2,a,i4,a,i1,a,i4) + + ! Computation/output loop + do step=0,numsteps-1 + g = rank + (step+1)/100.0 + ! Output all data + call adios2_begin_step(engine, adios2_step_mode_append, ierr) + call adios2_put(engine, var_g, g, ierr); + call adios2_end_step(engine, ierr) + enddo + + ! Close the output + call adios2_close(engine, ierr) + + deallocate(g) + + if (rank == 0) then + write (*,*) "Try the following: " + write (*,'(a,a,i4)') & + " bpls -la adios2-global-array-1d-f.bp ", & + "GlobalArray -d -n ", fixed_shape(1) + write (*,'(a,a,i4)') & + " bpls -la adios2-global-array-1d-f.bp ", & + "GlobalArray -d -t -n ", fixed_shape(1) + write (*,'(a)') & + " mpirun -n 2 ./adios2-global-array-1d-read-f " + endif +end subroutine writer + + +end program adios2_global_array_1d_write diff --git a/examples/basics/globalArray1D/globalArray1DWrite.c b/examples/basics/globalArray1D/globalArray1DWrite.c new file mode 100644 index 0000000000..4ae38ed3da --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DWrite.c @@ -0,0 +1,99 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#include "decomp.h" +#include "mpivars.h" +#include +#include +#include + +void writer(adios2_adios *adios) +{ + int step, i; + float *g; + const int mincount = 2; + const int maxcount = 5; + const int numsteps = 5; + adios2_step_status err; + + long long int fixed_shape = 0, fixed_start = 0, fixed_count = 0; + + /* Application variables + g = 1D distributed array, + global shape and per-process size is fixed */ + fixed_count = get_random(mincount, maxcount); + g = malloc((size_t)fixed_count * sizeof(float)); + gather_decomp_1d(&fixed_count, &fixed_shape, &fixed_start); + + adios2_io *io = adios2_declare_io(adios, "output"); + size_t shape[1]; + shape[0] = (size_t)fixed_shape; + + size_t start[1]; + start[0] = (size_t)fixed_start; + + size_t count[1]; + count[0] = (size_t)fixed_count; + + adios2_variable *var_g = adios2_define_variable(io, "GlobalArray", adios2_type_float, 1, shape, + start, count, adios2_constant_dims_true); + + adios2_engine *engine = adios2_open(io, "adios2-global-array-1d-c.bp", adios2_mode_write); + printf("Decmp rank = %d global shape = %lld local count = %lld offset = " + "%lld\n", + rank, fixed_shape, fixed_count, fixed_start); + for (step = 0; step < numsteps; step++) + { + for (i = 0; i < fixed_count; i++) + { + g[i] = (float)(rank + (step + 1) / 100.0); + } + + adios2_begin_step(engine, adios2_step_mode_append, 10.0f, &err); + adios2_put(engine, var_g, g, adios2_mode_deferred); + adios2_end_step(engine); + } + // Close the output + adios2_close(engine); + free(g); + + if (rank == 0) + { + printf("Try the following: \n"); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n " + "%lld \n", + fixed_shape); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n " + "%lld \n ", + fixed_shape); + printf(" mpirun -n 2 ./adios2-global-array-1d-read-c \n"); + } +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + init_mpi(123, argc, argv); +#endif + + { +#if ADIOS2_USE_MPI + + adios2_adios *adios = adios2_init_mpi(MPI_COMM_WORLD); +#else + adios2_adios *adios = adios2_init(); +#endif + + writer(adios); + adios2_finalize(adios); + } + +#if ADIOS2_USE_MPI + finalize_mpi(); +#endif + + return 0; +} diff --git a/examples/basics/globalArray1D/mpivars.F90 b/examples/basics/globalArray1D/mpivars.F90 new file mode 100644 index 0000000000..323e4b0c15 --- /dev/null +++ b/examples/basics/globalArray1D/mpivars.F90 @@ -0,0 +1,30 @@ +module mpivars + implicit none + include 'mpif.h' + + integer:: app_comm, rank, nproc + integer:: wrank, wnproc + integer:: ierr + +contains + +subroutine init_mpi(color) + integer, intent(in):: color + call MPI_Init(ierr) + ! World comm spans all applications started with the same mpirun command + call MPI_Comm_rank(MPI_COMM_WORLD, wrank, ierr) + call MPI_Comm_size(MPI_COMM_WORLD, wnproc, ierr) + + ! Have to split and create a 'world' communicator for this app only + ! color must be unique for each application + call MPI_Comm_split (MPI_COMM_WORLD, color, wrank, app_comm, ierr) + call MPI_Comm_rank (app_comm, rank, ierr) + call MPI_Comm_size (app_comm, nproc , ierr) +end subroutine init_mpi + +subroutine finalize_mpi() + call MPI_Finalize(ierr) +end subroutine finalize_mpi + +end module mpivars + diff --git a/examples/basics/globalArray1D/mpivars.c b/examples/basics/globalArray1D/mpivars.c new file mode 100644 index 0000000000..5c4aa5634b --- /dev/null +++ b/examples/basics/globalArray1D/mpivars.c @@ -0,0 +1,29 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#include "mpivars.h" +#include + +int rank, nproc; +int wrank, wnproc; +MPI_Comm app_comm; + +void init_mpi(int color, int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + /* World comm spans all applications started with the same mpirun command */ + MPI_Comm_rank(MPI_COMM_WORLD, &wrank); + MPI_Comm_size(MPI_COMM_WORLD, &wnproc); + + /* Have to split and create a 'world' communicator for this app only + color must be unique for each application*/ + MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &app_comm); + MPI_Comm_rank(app_comm, &rank); + MPI_Comm_size(app_comm, &nproc); + return; +} + +void finalize_mpi() { MPI_Finalize(); } diff --git a/examples/basics/globalArray1D/mpivars.h b/examples/basics/globalArray1D/mpivars.h new file mode 100644 index 0000000000..98c00586d3 --- /dev/null +++ b/examples/basics/globalArray1D/mpivars.h @@ -0,0 +1,14 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#ifndef ADIOS2EXAMPLES_MPIVARS_H +#define ADIOS2EXAMPLES_MPIVARS_H +#include +extern int rank, nproc; +extern MPI_Comm app_comm; +void init_mpi(int, int, char *argv[]); +void finalize_mpi(); +#endif // ADIOS2EXAMPLES_MPIVARS_H diff --git a/examples/basics/globalArrayND/globalArrayNDWrite.cpp b/examples/basics/globalArrayND/globalArrayNDWrite.cpp index 45c63c5c25..9832cc47ab 100644 --- a/examples/basics/globalArrayND/globalArrayNDWrite.cpp +++ b/examples/basics/globalArrayND/globalArrayNDWrite.cpp @@ -94,7 +94,8 @@ int main(int argc, char *argv[]) for (size_t i = 0; i < Nx; i++) { - row[i] = step * Nx * nproc * 1.0 + rank * Nx * 1.0 + (double)i; + row[i] = static_cast(step) * Nx * nproc * 1.0 + rank * Nx * 1.0 + + static_cast(i); } // Make a 2D selection to describe the local dimensions of the diff --git a/examples/basics/queryWorker/CMakeLists.txt b/examples/basics/queryWorker/CMakeLists.txt index 839dd19bf2..7cce9e5c4c 100644 --- a/examples/basics/queryWorker/CMakeLists.txt +++ b/examples/basics/queryWorker/CMakeLists.txt @@ -17,12 +17,10 @@ if(NOT TARGET adios2_core) list(APPEND _components MPI) endif() - find_package(ZeroMQ 4.1 QUIET) - find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) endif() -if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_DataMan) +if(ADIOS2_HAVE_MPI) add_executable(adios2_basics_queryWorker queryWorker.cpp) target_link_libraries(adios2_basics_queryWorker adios2::cxx11_mpi MPI::MPI_C) install(TARGETS adios2_basics_queryWorker RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/basics/queryWorker/README.md b/examples/basics/queryWorker/README.md deleted file mode 100644 index 65b8042d3e..0000000000 --- a/examples/basics/queryWorker/README.md +++ /dev/null @@ -1,8 +0,0 @@ -q1.json is a json query file for one var - -q2.json is a composite query - -The bp*xml are the from heat transfer example with bp4 engine. -and tag is added at the end for xml query spec - -JSON query file option should be used with ADIOS2_HAVE_DATAMAN \ No newline at end of file diff --git a/examples/basics/queryWorker/queryWorker.cpp b/examples/basics/queryWorker/queryWorker.cpp index 2f172a18f0..9d878714b7 100644 --- a/examples/basics/queryWorker/queryWorker.cpp +++ b/examples/basics/queryWorker/queryWorker.cpp @@ -1,17 +1,16 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + #include "adios2.h" #include #include -#include #include -#include -#include -#include #include #include -// #include "adios2/toolkit/query/Worker.h" - void queryWithStreaming(adios2::IO &queryIO, std::string &dataFileName, std::string &queryFile) { adios2::Engine reader = queryIO.Open(dataFileName, adios2::Mode::Read, MPI_COMM_WORLD); diff --git a/examples/basics/values/CMakeLists.txt b/examples/basics/values/CMakeLists.txt index 799c72cc54..f37b7da6ab 100644 --- a/examples/basics/values/CMakeLists.txt +++ b/examples/basics/values/CMakeLists.txt @@ -9,6 +9,15 @@ project(ADIOS2BasicsValuesExample) if(NOT TARGET adios2_core) set(_components C) + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + find_package(MPI COMPONENTS ${_components}) if(MPI_FOUND) # Workaround for various MPI implementations forcing the link of C++ bindings @@ -29,4 +38,16 @@ if(ADIOS2_HAVE_MPI) add_executable(adios2_basics_valuesWrite_mpi valuesWrite.cpp) target_link_libraries(adios2_basics_valuesWrite_mpi adios2::cxx11_mpi MPI::MPI_C) install(TARGETS adios2_basics_valuesWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_Fortran) + add_library(adios2_basics_values_mpivars_f OBJECT mpivars.F90) + target_link_libraries(adios2_basics_values_mpivars_f MPI::MPI_Fortran) + install(TARGETS adios2_basics_values_mpivars_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_values_f values.F90) + target_link_libraries(adios2_basics_values_f + adios2_basics_values_mpivars_f + adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_basics_values_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/basics/values/mpivars.F90 b/examples/basics/values/mpivars.F90 new file mode 100644 index 0000000000..323e4b0c15 --- /dev/null +++ b/examples/basics/values/mpivars.F90 @@ -0,0 +1,30 @@ +module mpivars + implicit none + include 'mpif.h' + + integer:: app_comm, rank, nproc + integer:: wrank, wnproc + integer:: ierr + +contains + +subroutine init_mpi(color) + integer, intent(in):: color + call MPI_Init(ierr) + ! World comm spans all applications started with the same mpirun command + call MPI_Comm_rank(MPI_COMM_WORLD, wrank, ierr) + call MPI_Comm_size(MPI_COMM_WORLD, wnproc, ierr) + + ! Have to split and create a 'world' communicator for this app only + ! color must be unique for each application + call MPI_Comm_split (MPI_COMM_WORLD, color, wrank, app_comm, ierr) + call MPI_Comm_rank (app_comm, rank, ierr) + call MPI_Comm_size (app_comm, nproc , ierr) +end subroutine init_mpi + +subroutine finalize_mpi() + call MPI_Finalize(ierr) +end subroutine finalize_mpi + +end module mpivars + diff --git a/examples/basics/values/values.F90 b/examples/basics/values/values.F90 new file mode 100644 index 0000000000..608ecf37b6 --- /dev/null +++ b/examples/basics/values/values.F90 @@ -0,0 +1,169 @@ +program adios2_values + use mpivars + use adios2 + implicit none + integer, parameter :: numsteps = 5 + ! ADIOS2 variables + type(adios2_adios) :: adios + + ! MPI then ADIOS2 initialization + call init_mpi(12345) + call adios2_init(adios, app_comm, ierr) + + call writer() + call reader() + + ! ADIOS2 then MPI finalization + call adios2_finalize(adios, ierr) + call finalize_mpi() + +contains + +subroutine writer + use mpivars + use adios2 + implicit none + + type(adios2_variable) :: var_gc, var_gv, var_lc, var_lv, var_gs + type(adios2_io) :: io + type(adios2_engine) :: engine + integer :: step + + ! Application variables + ! gc = Global Constant (a single value from the entire application, once per run (e.g. NPROC)) + ! gv = Global Value (a single value from the entire application, changes over time) + ! lc = Local Constant (one value per process, once per run (e.g. RANK)) + ! lv = Local Value (one value per process, changes over time) + ! gs = a string, same as a global value + integer :: gc, gv, lc, lv + character(len=80) :: gs + + call adios2_declare_io (io, adios, 'Values', ierr) + + call adios2_define_variable(var_gc, io, "GlobalConstant", adios2_type_integer4, ierr) + call adios2_define_variable(var_gv, io, "GlobalValue", adios2_type_integer4, ierr) + ! Local values will show up in reading as a 1D array of nproc elements + ! the write side definition is quite cumbersome in Fortran :-( + ! We have to define it almost like a distributed global array with a special + ! dimension value to indicate its type + call adios2_define_variable(var_lc, io, "LocalConstant", adios2_type_integer4, & + 1, (/ adios2_local_value_dim /), & + adios2_null_dims, & + adios2_null_dims, & + adios2_constant_dims, ierr) + + call adios2_define_variable(var_lv, io, "LocalValue", adios2_type_integer4, & + 1, (/ adios2_local_value_dim /), & + adios2_null_dims, & + adios2_null_dims, & + adios2_constant_dims, ierr) + + call adios2_define_variable(var_gs, io, "GlobalString", adios2_type_string, ierr) + + call adios2_open(engine, io, "adios2-values-f.bp", adios2_mode_write, ierr) + + ! Computation/output loop + gc = nproc + lc = rank + do step=0,numsteps-1 + gv = step + lv = nproc*(step)+rank + write (gs,'(a,i3)') "This is step ", step + + call adios2_begin_step(engine, adios2_step_mode_append, ierr) + if (step == 0) then + call adios2_put(engine, var_lc, lc, ierr); + if (rank == 0) then + ! could be written from every process but it is useless + call adios2_put(engine, var_gc, gc, ierr); + endif + endif + if (rank == 0) then + ! could be written from every process but it is useless + call adios2_put(engine, var_gv, gv, ierr); + call adios2_put(engine, var_gs, gs, ierr); + endif + call adios2_put(engine, var_lv, lv, ierr); + call adios2_end_step(engine, ierr) + enddo + + ! Close the output + call adios2_close(engine, ierr) + +end subroutine writer + + +subroutine reader + use mpivars + implicit none + + type(adios2_variable) :: var_gc, var_gv, var_lc, var_lv + type(adios2_io) :: io + type(adios2_engine) :: engine + integer*8 :: numsteps, i + integer*4 :: gc + integer*4, dimension(:), allocatable :: gvs, lcs + integer*4, dimension(:,:), allocatable :: lvs + character(len=80)::fmt + integer*8, dimension(:), allocatable :: shape_lv, shape_lc + integer :: ndims_lv, ndims_lc + + ! Note, every process reads everything in this example + + call adios2_declare_io(io, adios, "ValuesInput", ierr) + call adios2_open(engine, io, "adios2-values-f.bp", adios2_mode_read, MPI_COMM_SELF, ierr) + + call adios2_inquire_variable(var_gc, io, "GlobalConstant", ierr) + call adios2_get(engine, var_gc, gc , ierr) + + call adios2_inquire_variable(var_gv, io, "GlobalValue", ierr) + call adios2_variable_steps(numsteps, var_gv, ierr) + call adios2_set_step_selection(var_gv, 0_8, numsteps, ierr) + allocate(gvs(numsteps)) + call adios2_get(engine, var_gv, gvs , ierr) + + ! Read Local Values and Local Constants as a 1D array + ! shape array is allocated inside adios2_variable_shape() + + call adios2_inquire_variable(var_lc, io, "LocalConstant", ierr) + call adios2_variable_shape(shape_lc, ndims_lc, var_lc, ierr) + allocate(lcs(shape_lc(1))) + call adios2_get(engine, var_lc, lcs , ierr) + + call adios2_inquire_variable(var_lv, io, "LocalValue", ierr) + call adios2_variable_shape(shape_lv, ndims_lv, var_lv, ierr) + call adios2_set_step_selection(var_lv, 0_8, numsteps, ierr) + allocate(lvs(shape_lv(1),numsteps)) + call adios2_get(engine, var_lv, lvs , ierr) + + call adios2_close(engine, ierr) + + ! By default, get()s are deferred and content is available AFTER + ! adios2_close() or adios2_perform_gets() + ! Use adios2_mode_sync option in adios2_get() to get the content immediately + + if (rank == 0) then + write(*,'("Number of steps in file = ",i5)') numsteps + write(*,'("GlobalConstant = ", i5)') gc + + write(fmt,'(a,i5,a)') '(a18,',numsteps,'i4,a2)' + !write(*,'(a)') fmt + write(*,fmt) "GlobalValue(s) = [", gvs, " ]" + + write(fmt,'(a,i5,a)') '(a20,',shape_lc(1),'i4,a2)' + !write(*,'(a)') fmt + write(*,fmt) "LocalConstant(s) = [", lcs, " ]" + + write(fmt,'(a,i5,a)') '(a6,i3,a4,',shape_lv(1),'i4)' + !write(*,'(a)') fmt + write(*,'(a)') "LocalValues = [" + do i = 1, numsteps + write(*,fmt) " step", i-1, ":", lvs(:,i) + enddo + write(*,*) " ]" + endif + + deallocate(gvs, lcs, lvs) +end subroutine reader + +end program adios2_values diff --git a/examples/basics/variablesShapes/CMakeLists.txt b/examples/basics/variablesShapes/CMakeLists.txt new file mode 100644 index 0000000000..2dbd92f4fd --- /dev/null +++ b/examples/basics/variablesShapes/CMakeLists.txt @@ -0,0 +1,39 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsVariablesShapesExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_variablesShapes variablesShapes.cpp) +target_link_libraries(adios2_basics_variablesShapes adios2::cxx11) +install(TARGETS adios2_basics_variablesShapes RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_basics_variablesShapes_hl variablesShapes_hl.cpp) +target_link_libraries(adios2_basics_variablesShapes_hl adios2::cxx11) +install(TARGETS adios2_basics_variablesShapes_hl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_basics_variablesShapes_mpi variablesShapes.cpp) + target_link_libraries(adios2_basics_variablesShapes_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_variablesShapes_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_variablesShapes_hl_mpi variablesShapes_hl.cpp) + target_link_libraries(adios2_basics_variablesShapes_hl_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_variablesShapes_hl_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/basics/variablesShapes/variablesShapes.cpp b/examples/basics/variablesShapes/variablesShapes.cpp new file mode 100644 index 0000000000..6dce0f8fae --- /dev/null +++ b/examples/basics/variablesShapes/variablesShapes.cpp @@ -0,0 +1,269 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * * variablesShapes.cpp : adios2 low-level API example to write and read + * supported Variables shapes using stepping + * (streaming) mode + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //std::size_t +#include // std::cout +#include // std::numeric_limits +#include //std::iota +#include //std::exception + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(adios2::ADIOS &adios, const std::size_t nx, const std::size_t nsteps, const int rank, + const int size) +{ + auto lf_compute = [](const std::size_t step, const std::size_t nx, + const int rank) -> std::vector { + const float value = static_cast(step + rank * nx); + std::vector array(nx); + std::iota(array.begin(), array.end(), value); + return array; + }; + + adios2::IO io = adios.DeclareIO("variables-shapes_writer"); + + // You can define variables according to: + // type : string, uint8_t, int8_t8, ... , float, double + // shape: global : value or array + // local : value (return a global array), array + + /********** GLOBAL VALUE *************/ + // string variables are always of value type, can't pass dimensions + adios2::Variable varGlobalValueString = + io.DefineVariable("GlobalValueString"); + + // global value can change on each step. Example: Step + adios2::Variable varStep = io.DefineVariable("Step"); + + /********** GLOBAL ARRAYS *************/ + // For a regular 1D decomposition: + + // 0*nx 1*nx 2*nx 3*nx shape (4*nx) + //--------//-------//--------//---------// + // nx nx nx nx + + // global shape -> this is the physical dimension across MPI processes + const adios2::Dims shape = {static_cast(size * nx)}; + + // local start for rank offset -> this is the local origin for the rank + // domain + const adios2::Dims start = {static_cast(rank * nx)}; + + // local count -> this is the local size from the local start for the rank + // domain + const adios2::Dims count = {nx}; + + // adios2::Dims is an alias to std::vector + // helps remember the inputs to adios2 functions DefineVariable (write) and + // SetSelection (read) make sure you always pass std::size_t types + + // global array with dimensions (shape, start, count) + // last argument indicates to adios2 that dimensions won't change + adios2::Variable varGlobalArray = + io.DefineVariable("GlobalArray", shape, start, count, adios2::ConstantDims); + + /********** LOCAL VALUE **************/ + // Independent values per rank at write, but presented as a global array at + // read Example: store current rank, but presented as an array of ranks + adios2::Variable varLocalValueInt32 = + io.DefineVariable("Rank", {adios2::LocalValueDim}); + + /********** LOCAL ARRAY **************/ + // Independent values and dimensions per rank, there is no notion of + // "continuity", each start from 0-origin to count. Example: mesh + // nodes-per-rank + adios2::Variable varLocalArray = + io.DefineVariable("LocalArray", {}, {}, count, adios2::ConstantDims); + + adios2::Engine writer = io.Open("variables-shapes.bp", adios2::Mode::Write); + + for (size_t step = 0; step < nsteps; ++step) + { + // this part mimics the compute portion in an application + const std::vector array = lf_compute(step, nx, rank); + + // ADIOS2 I/O portion + + // BeginStep/EndStep is the streaming API -> supported by all engines + writer.BeginStep(); + + // minimize global and local values footprint, by only one rank putting + // the variables + if (rank == 0) + { + // Global value changing over steps + writer.Put(varStep, static_cast(step)); + + if (step == 0) + { + // Global absolute value + writer.Put(varGlobalValueString, std::string("ADIOS2 Basics Variable Example")); + // Local absolute value + writer.Put(varLocalValueInt32, static_cast(rank)); + } + } + + // for this example all ranks put a global and a local array + writer.Put(varGlobalArray, array.data()); + writer.Put(varLocalArray, array.data()); + writer.EndStep(); + } + writer.Close(); +} + +void reader(adios2::ADIOS &adios, const int rank, const int size) +{ + adios2::IO io = adios.DeclareIO("variables-shapes_reader"); + // all ranks opening the bp file have access to the entire metadata + adios2::Engine reader = io.Open("variables-shapes.bp", adios2::Mode::Read); + + // reading in streaming mode + while (reader.BeginStep() != adios2::StepStatus::EndOfStream) + { + // scope between BeginStep and EndStep is only for the current step + const size_t currentStep = reader.CurrentStep(); + + // Typical flow: InquireVariable + adios2::Variable varStep = io.InquireVariable("Step"); + uint64_t step = std::numeric_limits::max(); + // check Variable existence + if (varStep) + { + if (rank == 0) + { + // variable objects are "printable" reporting Name and Type + std::cout << "Found Global Value " << varStep << " in step " << currentStep << "\n"; + // output: Found Global Value Variable(Name: "Step") + // in step 0 + } + reader.Get(varStep, step); + } + + // GlobalValueString + adios2::Variable varGlobalValueString = + io.InquireVariable("GlobalValueString"); + std::string globalValueString; + // check Variable existence and Get + if (varGlobalValueString) + { + if (rank == 0) + { + std::cout << "Found Global Value " << varGlobalValueString << " in step " + << currentStep << "\n"; + } + reader.Get(varGlobalValueString, globalValueString); + } + + // Global Arrays at read from local values at write + adios2::Variable varRanks = io.InquireVariable("Ranks"); + std::vector ranks; + if (varRanks) + { + if (rank == 0) + { + std::cout << "Found Global Array " << varRanks << " in step " << currentStep + << "\n"; + } + // passing a vector convenience: adios2 would resize it + // automatically + reader.Get(varRanks, ranks); + } + + // Global Array + adios2::Variable varGlobalArray = io.InquireVariable("GlobalArray"); + std::vector globalArray; + if (varGlobalArray) + { + if (rank == 0) + { + std::cout << "Found GlobalArray " << varGlobalArray << " in step " << currentStep + << "\n"; + } + reader.Get(varGlobalArray, globalArray); + } + + // Local Array + adios2::Variable varLocalArray = io.InquireVariable("LocalArray"); + std::vector localArray; + if (varLocalArray) + { + // local arrays require an extra step to select the block of + // interest (0 is default) we only select block 0 in this example + varLocalArray.SetBlockSelection(0); + if (rank == 0) + { + std::cout << "Found LocalArray " << varLocalArray << " in step " << currentStep + << "\n"; + } + reader.Get(varLocalArray, localArray); + } + + // since all Get calls are "deferred" all the data would be populated at + // EndStep + reader.EndStep(); + + // data is available + + if (rank == 0) + { + std::cout << "\n"; + } + } + + reader.Close(); +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + int rank = 0; + int size = 1; + +#if ADIOS2_USE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); +#endif + + try + { +#if ADIOS2_USE_MPI + adios2::ADIOS adios(MPI_COMM_WORLD); +#else + adios2::ADIOS adios; +#endif + + constexpr std::size_t nx = 10; + constexpr std::size_t nsteps = 3; + + writer(adios, nx, nsteps, rank, size); + reader(adios, rank, size); + } + catch (const std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/basics/variablesShapes/variablesShapes_hl.cpp b/examples/basics/variablesShapes/variablesShapes_hl.cpp new file mode 100644 index 0000000000..5977b2c311 --- /dev/null +++ b/examples/basics/variablesShapes/variablesShapes_hl.cpp @@ -0,0 +1,194 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * variablesShapes_hl.cpp : adios2 high-level API example to write and read + * supported Variables shapes using stepping (streaming) mode + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //std::size_t +#include // std::cout +#include // std::numeric_limits +#include //std::iota +#include //std::exception + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(const std::size_t nx, const std::size_t nsteps, const int rank, const int size) +{ + auto lf_compute = [](const std::size_t step, const std::size_t nx, + const int rank) -> std::vector { + const float value = static_cast(step + rank * nx); + std::vector array(nx); + std::iota(array.begin(), array.end(), value); + return array; + }; + + // You can define variables according to: + // type : string, uint8_t, int8_t8, ... , float, double + // shape: global : value or array + // local : value (return a global array), array + + // global shape -> this is the physical dimension across MPI processes + const adios2::Dims shape = {static_cast(size * nx)}; + + // local start for rank offset -> this is the local origin for the rank + // domain + const adios2::Dims start = {static_cast(rank * nx)}; + + // local count -> this is the local size from the local start for the rank + // domain + const adios2::Dims count = {nx}; + + // adios2::Dims is an alias to std::vector + // helps remember the inputs to adios2 functions DefineVariable (write) and + // SetSelection (read) make sure you always pass std::size_t types + +#if ADIOS2_USE_MPI + adios2::fstream out("variables-shapes_hl.bp", adios2::fstream::out, MPI_COMM_WORLD); +#else + adios2::fstream out("variables-shapes_hl.bp", adios2::fstream::out); +#endif + + for (size_t step = 0; step < nsteps; ++step) + { + // this part mimics the compute portion in an application + const std::vector array = lf_compute(step, nx, rank); + + // ADIOS2 I/O portion + + // minimize global and local values footprint, by only one rank writing + // the variables + if (rank == 0) + { + // Global value changing over steps + out.write("Step", static_cast(step)); + + if (step == 0) + { + // Constant Global value + out.write("GlobalValueString", std::string("ADIOS2 Basics Variable Example")); + + // Constant Local value + out.write("LocalValueInt32", static_cast(rank), adios2::LocalValue); + } + } + + // for this example all ranks write a global and a local array + out.write("GlobalArray", array.data(), shape, start, count); + out.write("LocalArray", array.data(), {}, {}, count); + + out.end_step(); + } + out.close(); +} + +void reader(const int rank, const int size) +{ + auto lf_ArrayToString = [](const std::vector &array) -> std::string { + std::string contents = "{ "; + for (const float value : array) + { + contents += std::to_string(static_cast(value)) + " "; + } + contents += "}"; + return contents; + }; + +// all ranks opening the bp file have access to the entire metadata +#if ADIOS2_USE_MPI + adios2::fstream in("variables-shapes_hl.bp", adios2::fstream::in, MPI_COMM_WORLD); +#else + adios2::fstream in("variables-shapes_hl.bp", adios2::fstream::in); +#endif + + // reading in streaming mode, supported by all engines + // similar to std::getline in std::fstream + adios2::fstep inStep; + while (adios2::getstep(in, inStep)) + { + const std::size_t currentStep = inStep.current_step(); + + const std::vector steps = inStep.read("Step"); + if (!steps.empty() && rank == 0) + { + std::cout << "Found Step " << steps.front() << " in currentStep " << currentStep + << "\n"; + } + + const std::vector globalValueString = + inStep.read("GlobalValueString"); + if (!globalValueString.empty() && rank == 0) + { + std::cout << "Found GlobalValueString " << globalValueString.front() + << " in currentStep " << currentStep << "\n"; + } + + const std::vector ranks = inStep.read("Ranks"); + if (!ranks.empty() && rank == 0) + { + std::cout << "Found rank " << ranks.front() << " in currentStep " << currentStep + << "\n"; + } + + const std::vector globalArray = inStep.read("GlobalArray"); + if (!globalArray.empty() && rank == 0) + { + std::cout << "Found globalArray " << lf_ArrayToString(globalArray) + " in currentStep " + << currentStep << "\n"; + } + + // default reads block 0 + const std::vector localArray = inStep.read("LocalArray"); + if (!localArray.empty() && rank == 0) + { + std::cout << "Found localArray " << lf_ArrayToString(localArray) + " in currentStep " + << currentStep << "\n"; + } + // indicate end of adios2 operations for this step + in.end_step(); + } + in.close(); +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + int rank = 0; + int size = 1; + +#if ADIOS2_USE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); +#endif + + try + { + constexpr std::size_t nx = 10; + constexpr std::size_t nsteps = 3; + + writer(nx, nsteps, rank, size); + reader(rank, size); + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/CMakeLists.txt b/examples/hello/CMakeLists.txt index dd90609718..297ed51882 100644 --- a/examples/hello/CMakeLists.txt +++ b/examples/hello/CMakeLists.txt @@ -11,9 +11,23 @@ if(ADIOS2_HAVE_MPI) endif() add_subdirectory(bpReader) +add_subdirectory(bpThreadWrite) add_subdirectory(bpTimeWriter) add_subdirectory(bpWriter) +if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) + add_subdirectory(bpWriteReadCuda) +endif() + +find_package(hip QUIET) +if(ADIOS2_HAVE_Kokkos_HIP OR hip_FOUND) + add_subdirectory(bpWriteReadHip) +endif() + +if(ADIOS2_HAVE_Kokkos) + add_subdirectory(bpWriteReadKokkos) +endif() + if(ADIOS2_HAVE_DataMan) add_subdirectory(datamanReader) add_subdirectory(datamanWriter) @@ -32,6 +46,8 @@ if(ADIOS2_HAVE_HDF5) endif() endif() +add_subdirectory(helloWorld) + if(ADIOS2_HAVE_Fortran) add_subdirectory(inlineFWriteCppRead) endif() diff --git a/examples/hello/bpThreadWrite/CMakeLists.txt b/examples/hello/bpThreadWrite/CMakeLists.txt new file mode 100644 index 0000000000..bc7fd8fb1b --- /dev/null +++ b/examples/hello/bpThreadWrite/CMakeLists.txt @@ -0,0 +1,21 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloThreadWriteExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(Threads QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(Threads_FOUND) + add_executable(adios2_hello_bpThreadWrite bpThreadWrite.cpp) + target_link_libraries(adios2_hello_bpThreadWrite adios2::cxx11 ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_hello_bpThreadWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/bpThreadWrite/bpThreadWrite.cpp b/examples/hello/bpThreadWrite/bpThreadWrite.cpp new file mode 100644 index 0000000000..f29c288879 --- /dev/null +++ b/examples/hello/bpThreadWrite/bpThreadWrite.cpp @@ -0,0 +1,122 @@ + +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * bpThreadWrite.cpp : adios2 low-level API example to write in a threaded + * application using C++11 thread and having adios2 calls + * inside mutex regions adios2 API are not thread-safe: + * 1. launching MPI from a thread is not possible on many + * supercomputers + * 2. I/O is highly serialized (buffering and low-level I/O + * calls), therefore users must be aware that adios2 might introduce + * bottlenecks. To run: Do not use MPI, just run the executable + * ./adios2_hello_bpThreadWrite + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include + +#include //std::size_t +#include +#include +#include +#include +#include + +namespace +{ + +std::mutex mutex; + +// tasks that runs on thread, each section of the vector is covered +template +void ThreadTask(const std::size_t threadID, std::vector &data, const std::size_t startIndex, + const std::size_t localSize, const std::string &variableName, adios2::IO io, + adios2::Engine engine) +{ + (void)threadID; // unused variable + // populate vector data, but simply adding step to index + for (std::size_t i = 0; i < localSize; ++i) + { + const std::size_t index = startIndex + i; + data[index] = static_cast(index); + } + + // I/O write region in a locked mutex + { + mutex.lock(); + + adios2::Variable variable = io.InquireVariable(variableName); + variable.SetSelection({{startIndex}, {localSize}}); + + engine.Put(variable, &data[startIndex]); + // PerformPuts must be called to collect memory per buffer + engine.PerformPuts(); + + mutex.unlock(); + } +} + +} // end namespace + +int main(int argc, char *argv[]) +{ + try + { + constexpr std::size_t nx = 100; + // data to be populated and written per thread + std::vector data(nx); + + // initialize adios2 objects serially + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("thread-write"); + // populate shape, leave start and count empty as + // they will come from each thread SetSelection + const std::string variableName = "data"; + io.DefineVariable(variableName, adios2::Dims{nx}, adios2::Dims(), adios2::Dims()); + + adios2::Engine engine = io.Open("thread-writes.bp", adios2::Mode::Write); + + // set up thread tasks + // just grab maximum number of threads to simplify things + const auto nthreads = static_cast(std::thread::hardware_concurrency()); + std::vector threadTasks; + threadTasks.reserve(nthreads); + + // launch threaded tasks (this is what OpenMP would simplify) + // elements per thread + const std::size_t stride = nx / nthreads; + // elements for last thread, add remainder + const std::size_t last = stride + nx % nthreads; + + // launch threads + for (std::size_t t = 0; t < nthreads; ++t) + { + const std::size_t startIndex = stride * t; + // non-inclusive endIndex + const std::size_t localSize = (t == nthreads - 1) ? last : stride; + + // use std::ref to pass things by reference + // adios2 objects can be passed by value + + threadTasks.emplace_back(ThreadTask, t, std::ref(data), startIndex, localSize, + std::ref(variableName), io, engine); + } + + for (auto &threadTask : threadTasks) + { + threadTask.join(); + } + + engine.Close(); + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; + } + + return 0; +} diff --git a/examples/hello/bpWriteReadHip/CMakeLists.txt b/examples/hello/bpWriteReadHip/CMakeLists.txt new file mode 100644 index 0000000000..431f1586e1 --- /dev/null +++ b/examples/hello/bpWriteReadHip/CMakeLists.txt @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriteReadHipExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(hip QUIET) + if(hip_FOUND) + enable_language(HIP) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_Kokkos_HIP OR hip_FOUND) + add_executable(adios2_hello_bpWriteReadHip bpWriteReadHip.cpp) + target_link_libraries(adios2_hello_bpWriteReadHip adios2::cxx11 hip::runtime) + set_target_properties(adios2_hello_bpWriteReadHip PROPERTIES LANGUAGE "HIP") + install(TARGETS adios2_hello_bpWriteReadHip RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/bpWriteReadHip/bpWriteReadHip.cpp b/examples/hello/bpWriteReadHip/bpWriteReadHip.cpp new file mode 100644 index 0000000000..99e3e94bf3 --- /dev/null +++ b/examples/hello/bpWriteReadHip/bpWriteReadHip.cpp @@ -0,0 +1,135 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ +#include +#include +#include +#include + +#include + +#include + +__global__ void hip_initialize(float *vec) { vec[hipBlockIdx_x] = hipBlockIdx_x; } + +__global__ void hip_increment(float *vec, float val) { vec[hipBlockIdx_x] += val; } + +int BPWrite(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + hipError_t hipExit; + float *gpuSimData; + hipExit = hipMalloc((void **)&gpuSimData, N * sizeof(float)); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + hipLaunchKernelGGL(hip_initialize, dim3(N), dim3(1), 0, 0, gpuSimData); + hipExit = hipDeviceSynchronize(); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("WriteIO"); + io.SetEngine(engine); + + const adios2::Dims shape{static_cast(N)}; + const adios2::Dims start{static_cast(0)}; + const adios2::Dims count{N}; + auto data = io.DefineVariable("data", shape, start, count); + + adios2::Engine bpWriter = io.Open(fname, adios2::Mode::Write); + + for (size_t step = 0; step < nSteps; ++step) + { + adios2::Box sel({0}, {N}); + data.SetSelection(sel); + + bpWriter.BeginStep(); + bpWriter.Put(data, gpuSimData); + bpWriter.EndStep(); + + hipLaunchKernelGGL(hip_increment, dim3(N), dim3(1), 0, 0, gpuSimData, 10); + hipExit = hipDeviceSynchronize(); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + } + + bpWriter.Close(); + return 0; +} + +int BPRead(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + hipError_t hipExit; + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("ReadIO"); + io.SetEngine(engine); + + adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read); + + unsigned int step = 0; + float *gpuSimData; + hipExit = hipMalloc((void **)&gpuSimData, N * sizeof(float)); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + for (; bpReader.BeginStep() == adios2::StepStatus::OK; ++step) + { + auto data = io.InquireVariable("data"); + const adios2::Dims start{0}; + const adios2::Dims count{N}; + const adios2::Box sel(start, count); + data.SetSelection(sel); + + bpReader.Get(data, gpuSimData); + bpReader.EndStep(); + + std::vector cpuData(N); + hipExit = hipMemcpy(cpuData.data(), gpuSimData, N * sizeof(float), hipMemcpyDeviceToHost); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + std::cout << "Simualation step " << step << " : "; + std::cout << cpuData.size() << " elements: " << cpuData[0]; + std::cout << " " << cpuData[1] << " ... "; + std::cout << cpuData[cpuData.size() - 1] << std::endl; + } + bpReader.Close(); + return 0; +} + +int main(int argc, char **argv) +{ + hipError_t hipExit; + const int device_id = 0; + hipExit = hipSetDevice(device_id); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + const std::vector list_of_engines = {"BP4", "BP5"}; + const size_t N = 6000; + int nSteps = 2, ret = 0; + + for (auto engine : list_of_engines) + { + std::cout << "Using engine " << engine << std::endl; + const std::string fname(engine + "_HIP_WR.bp"); + ret += BPWrite(fname, N, nSteps, engine); + ret += BPRead(fname, N, nSteps, engine); + } + return ret; +} diff --git a/examples/hello/bpWriteReadKokkos/CMakeLists.txt b/examples/hello/bpWriteReadKokkos/CMakeLists.txt new file mode 100644 index 0000000000..a8e810b734 --- /dev/null +++ b/examples/hello/bpWriteReadKokkos/CMakeLists.txt @@ -0,0 +1,33 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriteReadKokkosExample) + +# CXX Compiler settings only in for this example +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(Kokkos 3.7 QUIET) + if(Kokkos_FOUND AND DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +else() + if(DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() +endif() + +if(ADIOS2_HAVE_Kokkos) + add_executable(adios2_hello_bpWriteReadKokkos bpWriteReadKokkos.cpp) + kokkos_compilation(SOURCE bpWriteReadKokkos.cpp) + target_link_libraries(adios2_hello_bpWriteReadKokkos adios2::cxx11 Kokkos::kokkos) + install(TARGETS adios2_hello_bpWriteReadKokkos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp b/examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp new file mode 100644 index 0000000000..7f837d6538 --- /dev/null +++ b/examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp @@ -0,0 +1,117 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ +#include +#include +#include + +#include + +#include + +int BPWrite(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + // Initialize the simulation data with the default memory space + using mem_space = Kokkos::DefaultExecutionSpace::memory_space; + Kokkos::View gpuSimData("simBuffer", N); + Kokkos::parallel_for( + "initBuffer", Kokkos::RangePolicy(0, N), + KOKKOS_LAMBDA(int i) { gpuSimData(i) = static_cast(i); }); + Kokkos::fence(); + + // Set up the ADIOS structures + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("WriteIO"); + io.SetEngine(engine); + + const adios2::Dims shape{static_cast(N)}; + const adios2::Dims start{static_cast(0)}; + const adios2::Dims count{N}; + auto data = io.DefineVariable("data", shape, start, count); + + adios2::Engine bpWriter = io.Open(fname, adios2::Mode::Write); + + // Simulation steps + for (int step = 0; step < nSteps; ++step) + { + // Make a 1D selection to describe the local dimensions of the + // variable we write and its offsets in the global spaces + adios2::Box sel({0}, {N}); + data.SetSelection(sel); + + // Start IO step every write step + bpWriter.BeginStep(); + bpWriter.Put(data, gpuSimData.data()); + bpWriter.EndStep(); + + // Update values in the simulation data using the default + // execution space + Kokkos::parallel_for( + "updateBuffer", Kokkos::RangePolicy(0, N), + KOKKOS_LAMBDA(int i) { gpuSimData(i) += 10; }); + Kokkos::fence(); + } + + bpWriter.Close(); + Kokkos::DefaultExecutionSpace exe_space; + std::cout << "Done writing on memory space: " << exe_space.name() << std::endl; + return 0; +} + +int BPRead(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + // Create ADIOS structures + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("ReadIO"); + io.SetEngine(engine); + + Kokkos::DefaultExecutionSpace exe_space; + std::cout << "Read on memory space: " << exe_space.name() << std::endl; + + adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read); + + unsigned int step = 0; + using mem_space = Kokkos::DefaultExecutionSpace::memory_space; + Kokkos::View gpuSimData("simBuffer", N); + for (; bpReader.BeginStep() == adios2::StepStatus::OK; ++step) + { + auto data = io.InquireVariable("data"); + const adios2::Dims start{0}; + const adios2::Dims count{N}; + const adios2::Box sel(start, count); + data.SetSelection(sel); + + bpReader.Get(data, gpuSimData.data()); + bpReader.EndStep(); + + auto cpuData = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, gpuSimData); + std::cout << "Simualation step " << step << " : "; + std::cout << cpuData.size() << " elements: " << cpuData[0]; + std::cout << " " << cpuData[1] << " ... "; + std::cout << cpuData[cpuData.size() - 1] << std::endl; + } + + bpReader.Close(); + return 0; +} + +int main(int argc, char **argv) +{ + const std::vector list_of_engines = {"BP4", "BP5"}; + const size_t N = 6000; + int nSteps = 2, ret = 0; + + Kokkos::initialize(argc, argv); + { + for (auto engine : list_of_engines) + { + std::cout << "Using engine " << engine << std::endl; + const std::string fname(engine + "_Kokkos_WR.bp"); + ret += BPWrite(fname, N, nSteps, engine); + ret += BPRead(fname, N, nSteps, engine); + } + } + Kokkos::finalize(); + return ret; +} diff --git a/examples/hello/helloWorld/CMakeLists.txt b/examples/hello/helloWorld/CMakeLists.txt new file mode 100644 index 0000000000..416d0d5b26 --- /dev/null +++ b/examples/hello/helloWorld/CMakeLists.txt @@ -0,0 +1,47 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloHelloWorldExample) + +if(NOT TARGET adios2_core) + set(_components C CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_helloWorld_c hello-world.c) +target_link_libraries(adios2_hello_helloWorld_c adios2::c) +install(TARGETS adios2_hello_helloWorld_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_helloWorld hello-world.cpp) +target_link_libraries(adios2_hello_helloWorld adios2::cxx11) +install(TARGETS adios2_hello_helloWorld RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_helloWorld_hl hello-world-hl.cpp) +target_link_libraries(adios2_hello_helloWorld_hl adios2::cxx11) +install(TARGETS adios2_hello_helloWorld_hl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_helloWorld_c_mpi hello-world.c) + target_link_libraries(adios2_hello_helloWorld_c_mpi adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_hello_helloWorld_c_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_helloWorld_mpi hello-world.cpp) + target_link_libraries(adios2_hello_helloWorld_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_helloWorld_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_helloWorld_hl_mpi hello-world-hl.cpp) + target_link_libraries(adios2_hello_helloWorld_hl_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_helloWorld_hl_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/helloWorld/hello-world-hl.cpp b/examples/hello/helloWorld/hello-world-hl.cpp new file mode 100644 index 0000000000..d1a4f2c05f --- /dev/null +++ b/examples/hello/helloWorld/hello-world-hl.cpp @@ -0,0 +1,75 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * hello-world-hl.cpp : adios2 high-level API example to write and read a + * std::string Variable with a greeting + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include +#include + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(const std::string &greeting) +{ +#if ADIOS2_USE_MPI + adios2::fstream out("hello-world-hl-cpp.bp", adios2::fstream::out, MPI_COMM_WORLD); +#else + adios2::fstream out("hello-world-hl-cpp.bp", adios2::fstream::out); +#endif + + out.write("Greeting", greeting); + out.close(); +} + +std::string reader() +{ +#if ADIOS2_USE_MPI + adios2::fstream in("hello-world-hl-cpp.bp", adios2::fstream::in, MPI_COMM_WORLD); +#else + adios2::fstream in("hello-world-hl-cpp.bp", adios2::fstream::in); +#endif + + for (adios2::fstep iStep; adios2::getstep(in, iStep);) + { + const std::vector greetings = in.read("Greeting"); + return greetings.front(); + } + return ""; +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + try + { + const std::string greeting = "Hello World from ADIOS2"; + writer(greeting); + + const std::string message = reader(); + std::cout << message << "\n"; + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/helloWorld/hello-world-hl.py b/examples/hello/helloWorld/hello-world-hl.py new file mode 100644 index 0000000000..825fb5282e --- /dev/null +++ b/examples/hello/helloWorld/hello-world-hl.py @@ -0,0 +1,47 @@ +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# hello-world.py : adios2 high-level API example to write and read a +# string Variable with a greeting +# +# Created on: 2/2/2021 +# Author: Dmitry Ganyushin ganyushindi@ornl.gov +# +import sys +from mpi4py import MPI +import adios2 + +DATA_FILENAME = "hello-world-hl-py.bp" +# MPI +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + + +def writer(greeting): + """write a string to a bp file""" + with adios2.open(DATA_FILENAME, "w", comm) as fh: + fh.write("Greeting", greeting, end_step=True) + return 0 + + +def reader(): + """read a string from to a bp file""" + with adios2.open(DATA_FILENAME, "r", comm) as fh: + for fstep in fh: + message = fstep.read_string("Greeting") + return message + + +def main(): + """driver function""" + greeting = "Hello World from ADIOS2" + writer(greeting) + message = reader() + print("{}".format(message)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/examples/hello/helloWorld/hello-world.c b/examples/hello/helloWorld/hello-world.c new file mode 100644 index 0000000000..6c14ea65ad --- /dev/null +++ b/examples/hello/helloWorld/hello-world.c @@ -0,0 +1,71 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * hello-world.c : adios2 C API example to write and read a + * char* Variable with a greeting + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //printf +#include //malloc, free + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(adios2_adios *adios, const char *greeting) +{ + adios2_io *io = adios2_declare_io(adios, "hello-world-writer"); + adios2_variable *var_greeting = adios2_define_variable( + io, "Greeting", adios2_type_string, 0, NULL, NULL, NULL, adios2_constant_dims_true); + + adios2_engine *engine = adios2_open(io, "hello-world-c.bp", adios2_mode_write); + adios2_put(engine, var_greeting, greeting, adios2_mode_deferred); + adios2_close(engine); +} + +void reader(adios2_adios *adios, char *greeting) +{ + adios2_step_status status; + adios2_io *io = adios2_declare_io(adios, "hello-world-reader"); + adios2_engine *engine = adios2_open(io, "hello-world-c.bp", adios2_mode_read); + adios2_variable *var_greeting = adios2_inquire_variable(io, "Greeting"); + adios2_begin_step(engine, adios2_step_mode_read, -1., &status); + adios2_get(engine, var_greeting, greeting, adios2_mode_deferred); + adios2_end_step(engine); + adios2_close(engine); +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + { +#if ADIOS2_USE_MPI + adios2_adios *adios = adios2_init_mpi(MPI_COMM_WORLD); +#else + adios2_adios *adios = adios2_init(); +#endif + + const char greeting[] = "Hello World from ADIOS2"; + writer(adios, greeting); + + char *message = (char *)malloc(24); + reader(adios, message); + printf("%s\n", message); + + free(message); + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/helloWorld/hello-world.cpp b/examples/hello/helloWorld/hello-world.cpp new file mode 100644 index 0000000000..9f30c14fa3 --- /dev/null +++ b/examples/hello/helloWorld/hello-world.cpp @@ -0,0 +1,76 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * hello-world.cpp : adios2 low-level API example to write and read a + * std::string Variable with a greeting + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include +#include + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(adios2::ADIOS &adios, const std::string &greeting) +{ + adios2::IO io = adios.DeclareIO("hello-world-writer"); + adios2::Variable varGreeting = io.DefineVariable("Greeting"); + + adios2::Engine writer = io.Open("hello-world-cpp.bp", adios2::Mode::Write); + writer.Put(varGreeting, greeting); + writer.Close(); +} + +std::string reader(adios2::ADIOS &adios) +{ + adios2::IO io = adios.DeclareIO("hello-world-reader"); + adios2::Engine reader = io.Open("hello-world-cpp.bp", adios2::Mode::Read); + reader.BeginStep(); + adios2::Variable varGreeting = io.InquireVariable("Greeting"); + std::string greeting; + reader.Get(varGreeting, greeting); + reader.EndStep(); + reader.Close(); + return greeting; +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + try + { +#if ADIOS2_USE_MPI + adios2::ADIOS adios(MPI_COMM_WORLD); +#else + adios2::ADIOS adios; +#endif + + const std::string greeting = "Hello World from ADIOS2"; + writer(adios, greeting); + + const std::string message = reader(adios); + std::cout << message << "\n"; + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/helloWorld/hello-world.py b/examples/hello/helloWorld/hello-world.py new file mode 100644 index 0000000000..f73e5c4d31 --- /dev/null +++ b/examples/hello/helloWorld/hello-world.py @@ -0,0 +1,54 @@ +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# hello-world.py : adios2 low-level API example to write and read a +# string Variable with a greeting +# +# Created on: 2/2/2021 +# Author: Dmitry Ganyushin ganyushindi@ornl.gov +# +import sys +from mpi4py import MPI +import adios2 + +DATA_FILENAME = "hello-world-py.bp" +# MPI +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + + +def writer(ad, greeting): + """write a string to a bp file""" + io = ad.DeclareIO("hello-world-writer") + var_greeting = io.DefineVariable("Greeting") + w = io.Open(DATA_FILENAME, adios2.Mode.Write) + w.Put(var_greeting, greeting) + w.Close() + return 0 + + +def reader(ad): + """read a string from to a bp file""" + io = ad.DeclareIO("hello-world-reader") + r = io.Open(DATA_FILENAME, adios2.Mode.Read) + r.BeginStep() + var_greeting = io.InquireVariable("Greeting") + message = r.Get(var_greeting) + r.EndStep() + return message + + +def main(): + """driver function""" + ad = adios2.ADIOS(comm) + greeting = "Hello World from ADIOS2" + writer(ad, greeting) + message = reader(ad) + print("{}".format(message)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/examples/simulations/CMakeLists.txt b/examples/simulations/CMakeLists.txt index 93f7e8c70c..d6b6434beb 100644 --- a/examples/simulations/CMakeLists.txt +++ b/examples/simulations/CMakeLists.txt @@ -1,3 +1,13 @@ if(ADIOS2_HAVE_MPI) + add_subdirectory(gray-scott) + add_subdirectory(gray-scott-struct) + + if(ADIOS2_HAVE_Kokkos) + add_subdirectory(gray-scott-kokkos) + endif() + add_subdirectory(heatTransfer) endif() + +add_subdirectory(korteweg-de-vries) +add_subdirectory(lorenz_ode) diff --git a/examples/simulations/GrayScott.jl/.JuliaFormatter.toml b/examples/simulations/GrayScott.jl/.JuliaFormatter.toml new file mode 100644 index 0000000000..00db94693b --- /dev/null +++ b/examples/simulations/GrayScott.jl/.JuliaFormatter.toml @@ -0,0 +1,4 @@ +margin = 80 +join_lines_based_on_source = true +style = "sciml" +format_doctrings = true diff --git a/examples/simulations/GrayScott.jl/Project.toml b/examples/simulations/GrayScott.jl/Project.toml new file mode 100644 index 0000000000..a295ba3546 --- /dev/null +++ b/examples/simulations/GrayScott.jl/Project.toml @@ -0,0 +1,19 @@ +name = "GrayScott" +uuid = "089a57ea-382b-4fd7-9f05-24902db6ec52" +authors = ["William F Godoy "] +version = "0.1.0" + +[deps] +ADIOS2 = "e0ce9d3b-0dbd-416f-8264-ccca772f60ec" +AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" +ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" +MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267" +PProf = "e4faabce-9ead-11e9-39d9-4379958e3056" +Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[compat] +julia = "1.8" diff --git a/examples/simulations/GrayScott.jl/ReadMe.md b/examples/simulations/GrayScott.jl/ReadMe.md new file mode 100644 index 0000000000..fe4f08631d --- /dev/null +++ b/examples/simulations/GrayScott.jl/ReadMe.md @@ -0,0 +1,139 @@ +# ADIOS2 GrayScott.jl example + +Julia version of [the gray-scott C++ and Python](https://github.com/ornladios/ADIOS2/blob/master/examples/simulations/gray-scott/) +example. + +This is a 3D 7-point stencil code to simulate the following [Gray-Scott +reaction diffusion model](https://doi.org/10.1126/science.261.5118.189): + +``` +u_t = Du * (u_xx + u_yy + u_zz) - u * v^2 + F * (1 - u) + noise * randn(-1,1) +v_t = Dv * (v_xx + v_yy + v_zz) + u * v^2 - (F + k) * v +``` + +This version contains: + +- CPU threaded solver using Julia's [multithreading]](https://docs.julialang.org/en/v1/manual/multi-threading/) +- GPU solvers using [CUDA.jl](https://github.com/JuliaGPU/CUDA.jl), [AMDGPU.jl](https://github.com/JuliaGPU/AMDGPU.jl) +- Parallel I/O using the [ADIOS2.jl](https://github.com/eschnett/ADIOS2.jl) Julia bindings to [ADIOS2](https://github.com/ornladios/ADIOS2) +- Message passing interface (MPI) using [MPI.jl](https://github.com/JuliaParallel/MPI.jl) Julia bindings to MPI +- Easily switch between float- (Float32) and double- (Float64) precision in the configuration file + +## How to run + +Currently only the simulation part is ported from C++, the data analysis is work-in-progress. + +Pre-requisites: + +- A recent Julia version: v1.8.5 or v1.9.0-beta3 as of January 2023 from [julialang.org/downloads](https://julialang.org/downloads/) + +### Run locally + +1. **Set up dependencies** + +From the `GrayScott.jl` directory instantiate and use MPI artifact jll (preferred method). +To use a system provided MPI, see [here](https://juliaparallel.org/MPI.jl/latest/configuration/#using_system_mpi) + +```julia + +$ julia --project + +Julia REPL + +julia> ] + +(GrayScott.jl)> instantiate +... +(GrayScott.jl)> <- +julia> using MPIPreferences +julia> MPIPreferences.use_jll_binary() +julia> exit() +``` + +Julia manages its own packages using [Pkg.jl](https://pkgdocs.julialang.org/v1/), the above would create platform-specific `LocalPreferences.toml` and `Manifest.toml` files. + +2. **Set up the examples/settings-files.json configuration file** + +``` +{ + "L": 64, + "Du": 0.2, + "Dv": 0.1, + "F": 0.02, + "k": 0.048, + "dt": 1.0, + "plotgap": 10, + "steps": 10000, + "noise": 0.1, + "output": "gs-julia-1MPI-64L-F32.bp", + "checkpoint": false, + "checkpoint_freq": 700, + "checkpoint_output": "ckpt.bp", + "restart": false, + "restart_input": "ckpt.bp", + "adios_config": "adios2.xml", + "adios_span": false, + "adios_memory_selection": false, + "mesh_type": "image", + "precision": "Float32", + "backend": "CPU" +} + +``` + +The file is nearly identical to the C++ original example. +Not all options are currently supported, but two Julia-only options are added: + + - "precision": either Float32 or Float64 in the array simulation (including GPUs) + - "backend": "CPU", "CUDA" or "AMDGPU" + +3. **Running the simulation** + +- `CPU threads`: launch julia assigning a number of threads (e.g. -t 8): + + ``` + $ julia --project -t 8 gray-scott.jl examples/settings-files.json + ``` + +- `CUDA/AMDGPU`: set the "backend" option in examples/settings-files.json to either "CUDA" or "AMDGPU" + + ``` + $ julia --project gray-scott.jl examples/settings-files.json + ``` + +This would generate an adios2 file from the output entry in the configuration file (e.g. `gs-julia-1MPI-64L-F32.bp`) +that can be visualized with ParaView with either the VTX or the FIDES readers. +**Important**: the AMDGPU.jl implementation of `randn` is currently work in progress. +See related issue [here](https://github.com/JuliaGPU/AMDGPU.jl/issues/378) + + +4. **Running on OLCF Summit and Crusher systems** +The code was tested on the Oak Ridge National Laboratory Leadership Computing Facilities (OLCF): [Summit](https://docs.olcf.ornl.gov/systems/summit_user_guide.html) and [Crusher](https://docs.olcf.ornl.gov/systems/crusher_quick_start_guide.html). Both are used testing a recent version of Julia [v1.9.0-beta3](https://julialang.org/downloads/#upcoming_release) and a `JULIA_DEPOT_PATH` is required to install packages and artifacts. **DO NOT USE your home directory**. We are providing configuration scripts in `scripts/config_XXX.sh` showing the plumming required for these systems. They need to be executed only once per session from the login nodes. + +To reuse these file the first 3 entries must be modified and run on login-nodes and the PATH poiting at a downloaded Julia binary for the corresponding PowerPC (Summit) and x86-64 (Crusher) architectures. Only "CPU" and "CUDA" backends are supported on Summit, while "CPU" and "AMDGPU" backends are supported on Crusher. + + ``` + # Replace these 3 entries + PROJ_DIR=/gpfs/alpine/proj-shared/csc383 + export JULIA_DEPOT_PATH=$PROJ_DIR/etc/summit/julia_depot + GS_DIR=$PROJ_DIR/wgodoy/ADIOS2/examples/simulations/GrayScott.jl + ... + # and the path + export PATH=$PROJ_DIR/opt/summit/julia-1.9.0-beta3/bin:$PATH + ``` + +## To-do list + + 1. Add support including random number on device kernel code on `AMDGPU.jl` + 2. Set the domain size `L` in the configuration file as a multiple of 6 for Summit, and a multiple of 4 on Crusher + 3. Add data analysis: PDF for u and v and Julia 2D plotting capabilities: Plots.jl, Makie.jl + 4. Add interactive computing with Pluto.jl notebooks + + +## Acknowledgements +This research was supported by the Exascale Computing Project (17-SC-20-SC), a joint project of the U.S. Department of Energy’s Office of Science and National Nuclear Security Administration, responsible for delivering a capable exascale ecosystem, including software, applications, and hardware technology, to support the nation’s exascale computing imperative. + +This research used resources of the Oak Ridge Leadership Computing Facility at the Oak Ridge National Laboratory, which is supported by the Office of Science of the U.S. Department of Energy under Contract No. DE-AC05-00OR22725. + +Thanks to the Exascale Computing Project PROTEAS-TUNE and ADIOS subprojects, and the ASCR Bluestone. +Thanks to all the Julia community members, packages developers and maintainers for their great work. \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/examples/settings-files.json b/examples/simulations/GrayScott.jl/examples/settings-files.json new file mode 100644 index 0000000000..ab6b9cc9d4 --- /dev/null +++ b/examples/simulations/GrayScott.jl/examples/settings-files.json @@ -0,0 +1,23 @@ +{ + "L": 64, + "Du": 0.2, + "Dv": 0.1, + "F": 0.02, + "k": 0.048, + "dt": 1.0, + "plotgap": 10, + "steps": 10000, + "noise": 0.1, + "output": "gs-julia-1MPI-64L-F32.bp", + "checkpoint": false, + "checkpoint_freq": 700, + "checkpoint_output": "ckpt.bp", + "restart": false, + "restart_input": "ckpt.bp", + "adios_config": "adios2.xml", + "adios_span": false, + "adios_memory_selection": false, + "mesh_type": "image", + "precision": "Float32", + "backend": "CPU" +} \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/gray-scott.jl b/examples/simulations/GrayScott.jl/gray-scott.jl new file mode 100644 index 0000000000..2c1196beb9 --- /dev/null +++ b/examples/simulations/GrayScott.jl/gray-scott.jl @@ -0,0 +1,15 @@ +import GrayScott + +# using Profile +# using PProf + +function julia_main()::Cint + GrayScott.main(ARGS) + return 0 +end + +if !isdefined(Base, :active_repl) + @time julia_main() + # @profile julia_main() + # pprof() +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/scripts/config_crusher.sh b/examples/simulations/GrayScott.jl/scripts/config_crusher.sh new file mode 100644 index 0000000000..3820dd297b --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/config_crusher.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +PROJ_DIR=/gpfs/alpine/proj-shared/csc383 +export JULIA_DEPOT_PATH=$PROJ_DIR/etc/crusher/julia_depot +GS_DIR=$PROJ_DIR/wgodoy/ADIOS2/examples/simulations/GrayScott.jl + +# remove existing generated Manifest.toml +rm -f $GS_DIR/Manifest.toml +rm -f $GS_DIR/LocalPreferences.toml + +# good practice to avoid conflicts with existing default modules +module purge + +# load required modules +module load PrgEnv-cray/8.3.3 # has required gcc +module load cray-mpich +module load rocm/5.4.0 +module load adios2 # only works with PrgEnv-cray + +# existing julia 1.6 module is outdated +export PATH=$PROJ_DIR/opt/crusher/julia-1.9.0-beta3/bin:$PATH + +# Required to point at underlying modules above +export JULIA_AMDGPU_DISABLE_ARTIFACTS=1 +# Required to enable underlying ADIOS2 library from loaded module +export JULIA_ADIOS2_PATH=$OLCF_ADIOS2_ROOT + +# MPIPreferences to use spectrum-mpi +julia --project=$GS_DIR -e 'using Pkg; Pkg.add("MPIPreferences")' +julia --project=$GS_DIR -e 'using MPIPreferences; MPIPreferences.use_system_binary(; library_names=["libmpi_cray"], mpiexec="srun")' + +# Regression being fixed with CUDA v4.0.0. CUDA.jl does lazy loading for portability to systems without NVIDIA GPUs +julia --project=$GS_DIR -e 'using Pkg; Pkg.add(name="CUDA", version="v3.13.1")' + +# Instantiate the project by installing packages in Project.toml +julia --project=$GS_DIR -e 'using Pkg; Pkg.instantiate()' + +# Adds a custom branch in case the development version is needed (for devs to test new features) +julia --project=$GS_DIR -e 'using Pkg; Pkg.add(url="https://github.com/eschnett/ADIOS2.jl.git", rev="main")' + +# Build the new ADIOS2 +julia --project=$GS_DIR -e 'using Pkg; Pkg.build()' +julia --project=$GS_DIR -e 'using Pkg; Pkg.precompile()' diff --git a/examples/simulations/GrayScott.jl/scripts/config_summit.sh b/examples/simulations/GrayScott.jl/scripts/config_summit.sh new file mode 100644 index 0000000000..d5f616ee31 --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/config_summit.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Replace these 3 entries +PROJ_DIR=/gpfs/alpine/proj-shared/csc383 +export JULIA_DEPOT_PATH=$PROJ_DIR/etc/summit/julia_depot +GS_DIR=$PROJ_DIR/wgodoy/ADIOS2/examples/simulations/GrayScott.jl + +# remove existing generated Manifest.toml +rm -f $GS_DIR/Manifest.toml +rm -f $GS_DIR/LocalPreferences.toml + +# good practice to avoid conflicts with existing default modules +# needed to avoid seg fault with MPI +module purge + +# load required modules +module load spectrum-mpi +module load gcc/12.1.0 # needed by julia libraries +module load cuda/11.0.3 # failure with 11.5.2 +module load adios2/2.8.1 +# module load julia/1.8.2 not working with CUDA.jl as it's missing libLLVM-13jl.so +export PATH=$PROJ_DIR/opt/summit/julia-1.9.0-beta3/bin:$PATH + +# Required to enable underlying ADIOS2 library from loaded module +export JULIA_ADIOS2_PATH=$OLCF_ADIOS2_ROOT + +# MPIPreferences to use spectrum-mpi +julia --project=$GS_DIR -e 'using Pkg; Pkg.add("MPIPreferences")' +julia --project=$GS_DIR -e 'using MPIPreferences; MPIPreferences.use_system_binary(; library_names=["libmpi_ibm"], mpiexec="jsrun")' + +# Instantiate the project by installing packages in Project.toml +julia --project=$GS_DIR -e 'using Pkg; Pkg.instantiate()' + +# Adds to LocalPreferences.toml to use underlying system CUDA since CUDA.jl v4.0.0 +# https://cuda.juliagpu.org/stable/installation/overview/#Using-a-local-CUDA +julia --project=$GS_DIR -e 'using CUDA; CUDA.set_runtime_version!("local")' + +# Adds a custom branch in case the development version is needed (for devs to test new features) +julia --project=$GS_DIR -e 'using Pkg; Pkg.add(url="https://github.com/eschnett/ADIOS2.jl.git", rev="main")' + +# Build the new ADIOS2 +julia --project=$GS_DIR -e 'using Pkg; Pkg.build()' +julia --project=$GS_DIR -e 'using Pkg; Pkg.precompile()' diff --git a/examples/simulations/GrayScott.jl/scripts/job_crusher.sh b/examples/simulations/GrayScott.jl/scripts/job_crusher.sh new file mode 100644 index 0000000000..ee4953f6d1 --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/job_crusher.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#SBATCH -A CSC383_crusher +#SBATCH -J gs-julia-1MPI-1GPU +#SBATCH -o %x-%j.out +#SBATCH -e %x-%j.err +#SBATCH -t 0:02:00 +#SBATCH -p batch +#SBATCH -N 1 + +date + +GS_DIR=/gpfs/alpine/proj-shared/csc383/wgodoy/ADIOS2/examples/simulations/GrayScott.jl +GS_EXE=$GS_DIR/gray-scott.jl + +srun -n 1 --gpus=1 julia --project=$GS_DIR $GS_EXE settings-files.json + +# launch this file with sbatch `$ sbatch job_crusher.sh` diff --git a/examples/simulations/GrayScott.jl/scripts/job_summit.sh b/examples/simulations/GrayScott.jl/scripts/job_summit.sh new file mode 100644 index 0000000000..9beffc157f --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/job_summit.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Begin LSF directives +#BSUB -P csc383 +#BSUB -W 00:02 +#BSUB -nnodes 1 +#BSUB -J gs-julia +#BSUB -o output.%J +#BSUB -e output.%J +#BSUB -N godoywf@ornl.gov +# End BSUB directives and begin shell commands + +date +GS_DIR=/gpfs/alpine/proj-shared/csc383/wgodoy/ADIOS2/examples/simulations/GrayScott.jl +GS_EXE=$GS_DIR/gray-scott.jl + +jsrun -n 1 -g 1 julia --project=$GS_DIR $GS_EXE settings-files.json + +# launch this file with bsub `$ bsub job_summit.sh` diff --git a/examples/simulations/GrayScott.jl/src/GrayScott.jl b/examples/simulations/GrayScott.jl/src/GrayScott.jl new file mode 100644 index 0000000000..d50c1abb09 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/GrayScott.jl @@ -0,0 +1,91 @@ +""" +GrayScott.jl is a Simulation and Analysis parallel framework for solving the +Gray-Scott 3D diffusion reaction system of equations of two variables U and V on +a regular Cartesian mesh. + +The bp output files can be visualized with ParaView. +""" +module GrayScott + +import MPI, ADIOS2 + +# contains relevant data containers "structs" for Input, Domain and Fields +include(joinpath("simulation", "Structs.jl")) + +# contains helper functions for general use +include(joinpath("helper", "Helper.jl")) +import .Helper + +# initializes inputs from configuration file +include(joinpath("simulation", "Inputs.jl")) +import .Inputs + +# manages the simulation computation +include(joinpath("simulation", "Simulation.jl")) +import .Simulation + +# manages the I/O +include(joinpath("simulation", "IO.jl")) +import .IO + +function julia_main()::Cint + try + main(ARGS) + catch + Base.invokelatest(Base.display_error, Base.catch_stack()) + return 1 + end + return 0 +end + +function main(args::Vector{String})::Int32 + MPI.Init() + comm = MPI.COMM_WORLD + rank = MPI.Comm_rank(comm) + size = MPI.Comm_size(comm) + + # a data struct that holds settings data from config_file in args + # example config file: ../examples/settings-files.json + settings = Inputs.get_settings(args, comm) + + # initialize MPI Cartesian Domain and Communicator + mpi_cart_domain = Simulation.init_domain(settings, comm) + + # initialize fields + fields = Simulation.init_fields(settings, + mpi_cart_domain, + Helper.get_type(settings.precision)) + + # initialize IOStream struct holding ADIOS-2 components for parallel I/O + stream = IO.init(settings, mpi_cart_domain, fields) + + restart_step::Int32 = 0 + # @TODO: checkpoint-restart + step::Int32 = restart_step + + while step < settings.steps + Simulation.iterate!(fields, settings, mpi_cart_domain) + step += 1 + + if step % settings.plotgap == 0 + if rank == 0 + println("Simulation at step ", step, " writing output step ", + step / settings.plotgap) + end + + IO.write_step!(stream, step, fields) + end + end + + IO.close!(stream) + + # Debugging session or Julia REPL session, not needed overall as it would be + # called when the program ends + if !isinteractive() + MPI.Finalize() + end + + return 0 +end + +end # module GrayScott diff --git a/examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl b/examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl new file mode 100644 index 0000000000..f7fb0bb33f --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl @@ -0,0 +1,160 @@ + +import MPI +import ArgParse +import ADIOS2 + +function _epsilon(d::T)::Bool where {T <: Number} + return (d < 1.0e-20) +end + +""" +Return 2 arrays pdf and bins of a 2D slice +""" +function _compute_pdf(data::Array{T, 3}, shape, count, nbins, min::T, + max::T) where {T} + pdf = Array{T, 2}(undef, nbins, count) + bins = Array{T, 1}(undef, nbins) + bin_width = (max - min) / nbins + + for i in 1:nbins + bins[i] = min + (i - 1) * bin_width + end + + slice_size = shape[2] * shape[3] + # special case: only one bin or small window + if nbins == 1 || _epsilon(max - min) || _epsilon(bin_width) + fill!(pdf, slice_size) + return pdf, bins + end + + # Calculate a PDF for 'nbins' bins for values between 'min' and 'max' + + for c in 1:count + for j in 1:shape[2] + for k in 1:shape[3] + value = data[k, j, c] + + if value > max || value < min + @show value, " is outside [", min, max "]" + end + bin = floor((value - min) / bin_width) + + if bin == nbins + bin = nbins - 1 + end + pdf[bin, c] += 1 + end + end + end +end + +function _parse_arguments(args) + s = ArgParse.ArgParseSettings(description = "gray-scott workflow pdf generator, Julia version") + + # @add_arg_table! s begin + # "--opt1" # an option (will take an argument) + # "--opt2", "-o" # another option, with short form + # "arg1" # a positional argument + # end + + ArgParse.@add_arg_table! s begin + "input" + help = "Name of the input file handle for reading data" + arg_type = String + required = true + "output" + help = "Name of the output file to which data must be written" + arg_type = String + required = true + "N" + help = "Number of bins for the PDF calculation, default = 1000" + arg_type = Int64 + required = false + default = 1000 + "output_inputdata" + help = "YES will write the original variables besides the analysis results" + arg_type = Bool + required = false + default = false + end + + # parse_args return a dictionary with key/value for arguments + parsed_arguments = ArgParse.parse_args(args, s) + return parsed_arguments +end + +function _read_data_write_pdf(inputs, comm) + in_filename = inputs["input"] + out_filename = inputs["output"] + nbins = inputs["N"] + write_inputvars = inputs["output_inputdata"] + + adios = ADIOS2.adios_init_mpi("adios2.xml", comm) + + reader_io = ADIOS2.declare_io(adios, "SimulationOutput") + writer_io = ADIOS2.declare_io(adios, "PDFAnalysisOutput") + + rank = MPI.Comm_rank(comm) + size = MPI.Comm_size(comm) + + if rank == 0 + println("PDF analysis reads from Simulation using engine type: ", + ADIOS2.engine_type(reader_io)) + println("PDF analysis writes using engine type: ", + ADIOS2.engine_type(writer_io)) + end + + # Engines for reading and writing + reader = ADIOS2.open(reader_io, inputs["input"], ADIOS2.mode_read) + writer = ADIOS2.open(writer_io, inputs["output"], ADIOS2.mode_write) + + # break inside if needed + while true + + # timeout is 10 seconds + read_status = ADIOS2.begin_step(reader, ADIOS2.step_mode_read, 10) + + if read_status == ADIOS2.step_status_not_ready + # sleep in seconds, minimum is one milisecond = 0.001 + sleep(1) + continue + else if read_status != ADIOS2.step_status_ok + break + end + + step_sim_out = ADIOS2.current_step(reader) + var_U = ADIOS2.inquire_variable(reader_io, "U") + var_V = ADIOS2.inquire_variable(reader_io, "V") + var_step = ADIOS2.inquire_variable(reader_io, "step") + + shape = ADIOS2.shape(var_U) + + # Split in the slowest dimension + count_z = shape[3] / size + start_z = count_z * rank + + # Last process needs to read all the rest + if rank == size-1 + count_z = shape[3] - count_z * (size-1) + end + + # missing set_selection + start = ( 0,0,start_z) + count = (shape[1], shape[2], count_z) + ADIOS2.set_selection(var_U, start, count) + ADIOS2.set_selection(var_V, start, count) + + # Calculate + + end +end + +function main(args) + MPI.Init() + + inputs = _parse_arguments(args) + comm = MPI.COMM_WORLD + _read_data_write_pdf(inputs, comm) + + MPI.Finalize() +end diff --git a/examples/simulations/GrayScott.jl/src/helper/Helper.jl b/examples/simulations/GrayScott.jl/src/helper/Helper.jl new file mode 100644 index 0000000000..757c571714 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/helper/Helper.jl @@ -0,0 +1,7 @@ + +module Helper + +include("helperMPI.jl") +include("helperString.jl") + +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/src/helper/helperMPI.jl b/examples/simulations/GrayScott.jl/src/helper/helperMPI.jl new file mode 100644 index 0000000000..529d7e0420 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/helper/helperMPI.jl @@ -0,0 +1,15 @@ + +import MPI + +export bcase_file + +function bcast_file_contents(file_name::String, comm, root = 0)::String + size::UInt32 = 0 + data::Vector{UInt8} = [] + if MPI.Comm_rank(comm) == root + data = read(open(file_name, "r")) + end + + data = MPI.bcast(data, comm) + return String(data) +end diff --git a/examples/simulations/GrayScott.jl/src/helper/helperString.jl b/examples/simulations/GrayScott.jl/src/helper/helperString.jl new file mode 100644 index 0000000000..596a2f0b94 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/helper/helperString.jl @@ -0,0 +1,14 @@ + +export get_type + +function get_type(input::String) + if input == "Float64" + return Float64 + elseif input == "Float32" + return Float32 + elseif input == "Float16" + return Float16 + end + + return nothing +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/src/simulation/IO.jl b/examples/simulations/GrayScott.jl/src/simulation/IO.jl new file mode 100644 index 0000000000..deb3a24ae8 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/IO.jl @@ -0,0 +1,106 @@ +module IO + +export init, write_step! + +# import external module +import ADIOS2 + +# internal submodule +import ..Simulation +# types from parent module types in Structs.jl +import ..Settings, ..MPICartDomain, ..Fields, ..IOStream + +function init(settings::Settings, mcd::MPICartDomain, + fields::Fields{T}) where {T} + + # initialize adios MPI using the cartesian communicator + adios = ADIOS2.adios_init_mpi(mcd.cart_comm) + io = ADIOS2.declare_io(adios, "SimulationOutput") + # @TODO: implement ADIOS2.set_engine in ADIOS2.jl + engine = ADIOS2.open(io, settings.output, ADIOS2.mode_write) + + # store simulation run provenance as attributes + ADIOS2.define_attribute(io, "F", settings.F) + ADIOS2.define_attribute(io, "k", settings.k) + ADIOS2.define_attribute(io, "dt", settings.dt) + ADIOS2.define_attribute(io, "Du", settings.Du) + ADIOS2.define_attribute(io, "Dv", settings.Dv) + ADIOS2.define_attribute(io, "noise", settings.noise) + + _add_visualization_schemas(io, settings.L) + + # ADIOS2 requires tuples for the dimensions + # define global variables u and v + shape = (settings.L, settings.L, settings.L) + start = Tuple(mcd.proc_offsets) + count = Tuple(mcd.proc_sizes) + + var_step = ADIOS2.define_variable(io, "step", Int32) + var_U = ADIOS2.define_variable(io, "U", T, shape, start, count) + var_V = ADIOS2.define_variable(io, "V", T, shape, start, count) + + return IOStream(adios, io, engine, var_step, var_U, var_V) +end + +function write_step!(stream::IOStream, step::Int32, fields::Fields{T}) where {T} + + # this creates temporaries similar to Fortran + u_no_ghost, v_no_ghost = Simulation.get_fields(fields) + + # writer engine + w = stream.engine + + ADIOS2.begin_step(w) + ADIOS2.put!(w, stream.var_step, step) + ADIOS2.put!(w, stream.var_U, u_no_ghost) + ADIOS2.put!(w, stream.var_V, v_no_ghost) + ADIOS2.end_step(w) +end + +function close!(stream::IOStream) + ADIOS2.close(stream.engine) + ADIOS2.adios_finalize(stream.adios) +end + +function _add_visualization_schemas(io, length) + + # Fides schema + ADIOS2.define_attribute(io, "Fides_Data_Model", "uniform") + ADIOS2.define_attribute_array(io, "Fides_Origin", [0.0, 0.0, 0.0]) + ADIOS2.define_attribute_array(io, "Fides_Spacing", [0.1, 0.1, 0.1]) + ADIOS2.define_attribute(io, "Fides_Dimension_Variable", "U") + ADIOS2.define_attribute_array(io, "Fides_Variable_List", ["U", "V"]) + ADIOS2.define_attribute_array(io, "Fides_Variable_Associations", + ["points", "points"]) + + # VTX schema + # string concatenation uses *, ^ is for repetition + # if length = 64 + # extent = "0 64 0 64 0 64 " + extent = ("0 " * string(length) * " ")^3 + extent = rstrip(extent) + + # deactive code formatting using JuliaFormatter.jl + # raw strings: " must be escaped with \" + #! format: off + vtx_schema = raw" + + + + + + + + + step + + + + + " + #! format: on + # reactive code formatting using JuliaFormatter.jl + ADIOS2.define_attribute(io, "vtk.xml", vtx_schema) +end + +end diff --git a/examples/simulations/GrayScott.jl/src/simulation/Inputs.jl b/examples/simulations/GrayScott.jl/src/simulation/Inputs.jl new file mode 100644 index 0000000000..a4160ce1d8 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Inputs.jl @@ -0,0 +1,78 @@ + +""" +Submodule used by GrayScott to handle inputs +""" +module Inputs + +export get_settings + +import ArgParse +import JSON + +import ..Helper +# import directly from parent module (GrayScott) +import ..Settings, ..SettingsKeys + +# public facing function +function get_settings(args::Vector{String}, comm)::Settings + config_file = _parse_args(args) + + # check format extension + if !endswith(config_file, ".json") && + !(endswith(config_file, ".yaml") || endswith(config_file, ".yml")) + throw(ArgumentError("config file must be json, yaml format. Extension not recognized.\n")) + end + + config_file_contents::String = Helper.bcast_file_contents(config_file, comm) + + if endswith(config_file, ".json") + return _parse_settings_json(config_file_contents) + end + + return nothing +end + +# local scope functions +function _parse_args(args::Vector{String}; + error_handler = ArgParse.default_handler)::String + s = ArgParse.ArgParseSettings(description = "gray-scott workflow simulation example configuration file, Julia version, GrayScott.jl", + exc_handler = error_handler) + + # @add_arg_table! s begin + # "--opt1" # an option (will take an argument) + # "--opt2", "-o" # another option, with short form + # "arg1" # a positional argument + # end + + ArgParse.@add_arg_table! s begin + "config_file" + help = "configuration file" + arg_type = String + required = true + end + + # parse_args return a dictionary with key/value for arguments + parsed_arguments = ArgParse.parse_args(args, s) + + # key is mandatory, so it's safe to retrieve + config_file::String = parsed_arguments["config_file"] + + return config_file +end + +function _parse_settings_json(json_contents::String)::Settings + json = JSON.parse(json_contents) + settings = Settings() + + # Iterate through dictionary pairs + for (key, value) in json + # Iterate through predefined keys, else ignore (no error if unrecognized) + if key in SettingsKeys + setproperty!(settings, Symbol(key), value) + end + end + + return settings +end + +end # module \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/src/simulation/Simulation.jl b/examples/simulations/GrayScott.jl/src/simulation/Simulation.jl new file mode 100644 index 0000000000..f3cbf3325c --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Simulation.jl @@ -0,0 +1,281 @@ +""" +The present file contains runtime backend for using CPU Threads, and optionally +CUDA.jl and AMDGPU.jl +""" +module Simulation + +export init_domain, init_fields + +import MPI +import Distributions + +# from parent module +import ..Settings, ..MPICartDomain, ..Fields + +# include functions for NVIDIA GPUs using CUDA.jl +include("Simulation_CUDA.jl") +# include functions for AMD GPUs using AMDGPU.jl +include("Simulation_AMDGPU.jl") + +function init_domain(settings::Settings, comm::MPI.Comm)::MPICartDomain + mcd = MPICartDomain() + + # set dims and Cartesian communicator + mcd.dims = MPI.Dims_create(MPI.Comm_size(comm), mcd.dims) + mcd.cart_comm = MPI.Cart_create(comm, mcd.dims) + + # set proc local coordinates in Cartesian communicator + rank = MPI.Comm_rank(comm) + mcd.coords = MPI.Cart_coords(mcd.cart_comm, rank) + + # set proc local mesh sizes + mcd.proc_sizes = settings.L ./ mcd.dims + + for (i, coord) in enumerate(mcd.coords) + if coord < settings.L % mcd.dims[i] + mcd.proc_sizes[i] += 1 + end + end + + # set proc local offsets + for i in 1:3 + mcd.proc_offsets[i] = settings.L / mcd.dims[i] * + mcd.coords[i] + +min(settings.L % mcd.dims[i], mcd.coords[i]) + end + + # get neighbors ranks + mcd.proc_neighbors["west"], + mcd.proc_neighbors["east"] = MPI.Cart_shift(mcd.cart_comm, 0, 1) + mcd.proc_neighbors["down"], + mcd.proc_neighbors["up"] = MPI.Cart_shift(mcd.cart_comm, 1, 1) + mcd.proc_neighbors["south"], + mcd.proc_neighbors["north"] = MPI.Cart_shift(mcd.cart_comm, 2, 1) + + return mcd +end + +""" +Create and Initialize fields for either CPU, CUDA.jl, AMDGPU.jl backends +Multiple dispatch would direct to the appropriate overleaded function +""" +function init_fields(settings::Settings, + mcd::MPICartDomain, T)::Fields{T} + lowercase_backend = lowercase(settings.backend) + if lowercase_backend == "cuda" + return _init_fields_cuda(settings, mcd, T) + elseif lowercase_backend == "amdgpu" + return _init_fields_amdgpu(settings, mcd, T) + end + # everything else would trigger the CPU threads backend + return _init_fields_cpu(settings, mcd, T) +end + +function _init_fields_cpu(settings::Settings, + mcd::MPICartDomain, T)::Fields{T} + size_x = mcd.proc_sizes[1] + size_y = mcd.proc_sizes[2] + size_z = mcd.proc_sizes[3] + + # should be ones + u = ones(T, size_x + 2, size_y + 2, size_z + 2) + v = zeros(T, size_x + 2, size_y + 2, size_z + 2) + + u_temp = zeros(T, size_x + 2, size_y + 2, size_z + 2) + v_temp = zeros(T, size_x + 2, size_y + 2, size_z + 2) + + function is_inside(x, y, z, offsets, sizes)::Bool + if x < offsets[1] || x >= offsets[1] + sizes[1] + return false + end + if y < offsets[2] || y >= offsets[2] + sizes[2] + return false + end + if z < offsets[3] || z >= offsets[3] + sizes[3] + return false + end + + return true + end + + d::Int64 = 6 + + # global locations + minL = Int64(settings.L / 2 - d) + maxL = Int64(settings.L / 2 + d) + + xoff = mcd.proc_offsets[1] + yoff = mcd.proc_offsets[2] + zoff = mcd.proc_offsets[3] + + Threads.@threads for z in minL:maxL + for y in minL:maxL + for x in minL:maxL + if !is_inside(x, y, z, mcd.proc_offsets, mcd.proc_sizes) + continue + end + + # Julia is 1-index, like Fortran :) + u[x - xoff + 2, y - yoff + 2, z - zoff + 2] = 0.25 + v[x - xoff + 2, y - yoff + 2, z - zoff + 2] = 0.33 + end + end + end + + xy_face_t, xz_face_t, yz_face_t = _get_mpi_faces(size_x, size_y, size_z, T) + + fields = Fields(u, v, u_temp, v_temp, xy_face_t, xz_face_t, yz_face_t) + return fields +end + +function iterate!(fields::Fields{T, N, Array{T, N}}, settings::Settings, + mcd::MPICartDomain) where {T, N} + _exchange!(fields, mcd) + # this function is the bottleneck + _calculate!(fields, settings, mcd) + + # swap the names + fields.u, fields.u_temp = fields.u_temp, fields.u + fields.v, fields.v_temp = fields.v_temp, fields.v +end + +function _get_mpi_faces(size_x, size_y, size_z, T) + + ## create a new type taking: count, block length, stride + ## to interoperate with MPI for ghost cell exchange + xy_face_t = MPI.Types.create_vector(size_y + 2, size_x, size_x + 2, + MPI.Datatype(T)) + xz_face_t = MPI.Types.create_vector(size_z, size_x, + (size_x + 2) * (size_y + 2), + MPI.Datatype(T)) + yz_face_t = MPI.Types.create_vector((size_y + 2) * (size_z + 2), 1, + size_x + 2, MPI.Datatype(T)) + MPI.Types.commit!(xy_face_t) + MPI.Types.commit!(xz_face_t) + MPI.Types.commit!(yz_face_t) + + return xy_face_t, xz_face_t, yz_face_t +end + +function _exchange!(fields, mcd) + """ + Send XY face z=size_z+1 to north and receive z=1 from south + """ + function _exchange_xy!(var, size_z, data_type, rank1, rank2, comm) + # to north + send_buf = MPI.Buffer(@view(var[2, 1, size_z + 1]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, 1, 1]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank1, source = rank2) + + # to south + send_buf = MPI.Buffer(@view(var[2, 1, 2]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, 1, size_z + 2]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank2, source = rank1) + end + + """ + Send XZ face y=size_y+1 to up and receive y=1 from down + """ + function _exchange_xz!(var, size_y, data_type, rank1, rank2, comm) + # to up + send_buf = MPI.Buffer(@view(var[2, size_y + 1, 2]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, 1, 2]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank1, source = rank2) + + # to down + send_buf = MPI.Buffer(@view(var[2, 2, 2]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, size_y + 2, 2]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank2, source = rank1) + end + + """ + Send YZ face x=size_x+2 to east and receive x=2 from west + """ + function _exchange_yz!(var, size_x, data_type, rank1, rank2, comm) + # to east + send_buf = MPI.Buffer(@view(var[size_x + 1, 1, 1]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[1, 1, 1]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank1, source = rank2) + + # to west + send_buf = MPI.Buffer(@view(var[2, 1, 1]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[size_x + 2, 1, 1]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank2, source = rank1) + end + + # if already a CPU array, no need to copy, + # otherwise (device) copy to host. + u = typeof(fields.u) <: Array ? fields.u : Array(fields.u) + v = typeof(fields.v) <: Array ? fields.v : Array(fields.v) + + for var in [u, v] + _exchange_xy!(var, mcd.proc_sizes[3], fields.xy_face_t, + mcd.proc_neighbors["north"], mcd.proc_neighbors["south"], + mcd.cart_comm) + + _exchange_xz!(var, mcd.proc_sizes[2], fields.xz_face_t, + mcd.proc_neighbors["up"], mcd.proc_neighbors["down"], + mcd.cart_comm) + + _exchange_yz!(var, mcd.proc_sizes[1], fields.yz_face_t, + mcd.proc_neighbors["east"], mcd.proc_neighbors["west"], + mcd.cart_comm) + end +end + +function _calculate!(fields::Fields{T, N, Array{T, N}}, settings::Settings, + mcd::MPICartDomain) where {T, N} + Du = convert(T, settings.Du) + Dv = convert(T, settings.Dv) + F = convert(T, settings.F) + K = convert(T, settings.k) + noise = convert(T, settings.noise) + dt = convert(T, settings.dt) + + # loop through non-ghost cells, bounds are inclusive + # @TODO: load balancing? option: a big linear loop + # use @inbounds at the right for-loop level, avoid putting it at the top level + Threads.@threads for k in 2:(mcd.proc_sizes[3] + 1) + for j in 2:(mcd.proc_sizes[2] + 1) + @inbounds for i in 2:(mcd.proc_sizes[1] + 1) + u = fields.u[i, j, k] + v = fields.v[i, j, k] + + # introduce a random disturbance on du + du = Du * _laplacian(i, j, k, fields.u) - u * v^2 + + F * (1.0 - u) + + noise * rand(Distributions.Uniform(-1, 1)) + + dv = Dv * _laplacian(i, j, k, fields.v) + u * v^2 - + (F + K) * v + + # advance the next step + fields.u_temp[i, j, k] = u + du * dt + fields.v_temp[i, j, k] = v + dv * dt + end + end + end +end + +""" + 7-point stencil around the cell, + this is equally a host and a device function! +""" +function _laplacian(i, j, k, var) + @inbounds l = var[i - 1, j, k] + var[i + 1, j, k] + var[i, j - 1, k] + + var[i, j + 1, k] + var[i, j, k - 1] + var[i, j, k + 1] - + 6.0 * var[i, j, k] + return l / 6.0 +end + +function get_fields(fields::Fields{T, N, Array{T, N}}) where {T, N} + @inbounds begin + u_no_ghost = fields.u[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + v_no_ghost = fields.v[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + end + return u_no_ghost, v_no_ghost +end + +end # module diff --git a/examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl b/examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl new file mode 100644 index 0000000000..8920167779 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl @@ -0,0 +1,168 @@ + +import AMDGPU + +function _init_fields_amdgpu(settings::Settings, mcd::MPICartDomain, + T)::Fields{T, 3, <:AMDGPU.ROCArray{T, 3}} + size_x = mcd.proc_sizes[1] + size_y = mcd.proc_sizes[2] + size_z = mcd.proc_sizes[3] + + # should be ones + u = AMDGPU.ones(T, size_x + 2, size_y + 2, size_z + 2) + v = AMDGPU.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + u_temp = AMDGPU.zeros(T, size_x + 2, size_y + 2, size_z + 2) + v_temp = AMDGPU.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + roc_offsets = AMDGPU.ROCArray(mcd.proc_offsets) + roc_sizes = AMDGPU.ROCArray(mcd.proc_sizes) + + d::Int64 = 6 + minL = Int64(settings.L / 2 - d) + maxL = Int64(settings.L / 2 + d) + + # @TODO: get ideal grid size and threads + threads = (16, 16) + # grid size must be the total number of threads of each direction + grid = (settings.L, settings.L) + + AMDGPU.wait(AMDGPU.@roc groupsize=threads gridsize=grid _populate_amdgpu!(u, + v, + roc_offsets, + roc_sizes, + minL, + maxL)) + + xy_face_t, xz_face_t, yz_face_t = _get_mpi_faces(size_x, size_y, size_z, T) + + fields = Fields(u, v, u_temp, v_temp, xy_face_t, xz_face_t, yz_face_t) + return fields +end + +function iterate!(fields::Fields{T, N, <:AMDGPU.ROCArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + _exchange!(fields, mcd) + # this function is the bottleneck + _calculate!(fields, settings, mcd) + + # swap the names + fields.u, fields.u_temp = fields.u_temp, fields.u + fields.v, fields.v_temp = fields.v_temp, fields.v +end + +function _populate_amdgpu!(u, v, offsets, sizes, minL, maxL) + function is_inside(x, y, z, offsets, sizes)::Bool + if x < offsets[1] || x >= offsets[1] + sizes[1] + return false + end + if y < offsets[2] || y >= offsets[2] + sizes[2] + return false + end + if z < offsets[3] || z >= offsets[3] + sizes[3] + return false + end + + return true + end + + # local coordinates (this are 1-index already) + lz = (AMDGPU.workgroupIdx().x - Int32(1)) * AMDGPU.workgroupDim().x + + AMDGPU.workitemIdx().x + ly = (AMDGPU.workgroupIdx().y - Int32(1)) * AMDGPU.workgroupDim().y + + AMDGPU.workitemIdx().y + + # This check might not be needed + if lz <= size(u, 3) && ly <= size(u, 2) + + # get global coordinates + z = lz + offsets[3] - 1 + y = ly + offsets[2] - 1 + + if z >= minL && z <= maxL && y >= minL && y <= maxL + xoff = offsets[1] + + for x in minL:maxL + # check if global coordinates for initialization are inside the region + if !is_inside(x, y, z, offsets, sizes) + continue + end + + # Julia is 1-index, like Fortran :) + u[x - xoff + 2, ly + 1, lz + 1] = 0.25 + v[x - xoff + 2, ly + 1, lz + 1] = 0.33 + end + end + end +end + +function _calculate!(fields::Fields{T, N, <:AMDGPU.ROCArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + Du = convert(T, settings.Du) + Dv = convert(T, settings.Dv) + F = convert(T, settings.F) + K = convert(T, settings.k) + noise = convert(T, settings.noise) + dt = convert(T, settings.dt) + + roc_sizes = AMDGPU.ROCArray(mcd.proc_sizes) + + threads = (16, 16) + blocks = (settings.L, settings.L) + + AMDGPU.wait(AMDGPU.@roc groupsize=threads gridsize=grid _calculate_kernel_amdgpu!(fields.u, + fields.v, + fields.u_temp, + fields.v_temp, + roc_sizes, + Du, + Dv, + F, + K, + noise, + dt)) +end + +function _calculate_kernel_amdgpu!(u, v, u_temp, v_temp, sizes, Du, Dv, F, K, + noise, dt) + + # local coordinates (this are 1-index already) + k = (AMDGPU.workgroupIdx().x - Int32(1)) * AMDGPU.workgroupDim().x + + AMDGPU.workitemIdx().x + j = (AMDGPU.workgroupIdx().y - Int32(1)) * AMDGPU.workgroupDim().y + + AMDGPU.workitemIdx().y + + # loop through non-ghost cells + if k >= 2 && k <= sizes[3] + 1 && j >= 2 && j <= sizes[2] + 1 + # bounds are inclusive + for i in 2:(sizes[1] + 1) + u_ijk = u[i, j, k] + v_ijk = v[i, j, k] + + du = Du * _laplacian(i, j, k, u) - u_ijk * v_ijk^2 + + F * (1.0 - u_ijk) + # + noise * AMDGPU.rand(eltype(u)) + # WIP in AMDGPU.jl, works with CUDA.jl + # + rand(Distributions.Uniform(-1, 1)) + + dv = Dv * _laplacian(i, j, k, v) + u_ijk * v_ijk^2 - + (F + K) * v_ijk + + # advance the next step + u_temp[i, j, k] = u_ijk + du * dt + v_temp[i, j, k] = v_ijk + dv * dt + end + end +end + +function get_fields(fields::Fields{T, N, <:AMDGPU.ROCArray{T, N}}) where {T, N} + u = Array(fields.u) + u_no_ghost = u[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + + v = Array(fields.v) + v_no_ghost = v[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + return u_no_ghost, v_no_ghost +end diff --git a/examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl b/examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl new file mode 100644 index 0000000000..ee470f00ec --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl @@ -0,0 +1,160 @@ + +import CUDA + +function _init_fields_cuda(settings::Settings, mcd::MPICartDomain, + T)::Fields{T, 3, <:CUDA.CuArray{T, 3}} + size_x = mcd.proc_sizes[1] + size_y = mcd.proc_sizes[2] + size_z = mcd.proc_sizes[3] + + # should be ones + u = CUDA.ones(T, size_x + 2, size_y + 2, size_z + 2) + v = CUDA.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + u_temp = CUDA.zeros(T, size_x + 2, size_y + 2, size_z + 2) + v_temp = CUDA.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + cu_offsets = CUDA.CuArray(mcd.proc_offsets) + cu_sizes = CUDA.CuArray(mcd.proc_sizes) + + d::Int64 = 6 + minL = Int64(settings.L / 2 - d) + maxL = Int64(settings.L / 2 + d) + + # @TODO: get ideal blocks and threads + threads = (16, 16) + blocks = (settings.L, settings.L) + + CUDA.@cuda threads=threads blocks=blocks _populate_cuda!(u, v, + cu_offsets, + cu_sizes, + minL, maxL) + CUDA.synchronize() + + xy_face_t, xz_face_t, yz_face_t = _get_mpi_faces(size_x, size_y, size_z, T) + + fields = Fields(u, v, u_temp, v_temp, xy_face_t, xz_face_t, yz_face_t) + return fields +end + +function iterate!(fields::Fields{T, N, <:CUDA.CuArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + _exchange!(fields, mcd) + # this function is the bottleneck + _calculate!(fields, settings, mcd) + + # swap the names + fields.u, fields.u_temp = fields.u_temp, fields.u + fields.v, fields.v_temp = fields.v_temp, fields.v +end + +function _populate_cuda!(u, v, offsets, sizes, minL, maxL) + function is_inside(x, y, z, offsets, sizes)::Bool + if x < offsets[1] || x >= offsets[1] + sizes[1] + return false + end + if y < offsets[2] || y >= offsets[2] + sizes[2] + return false + end + if z < offsets[3] || z >= offsets[3] + sizes[3] + return false + end + + return true + end + + # local coordinates (this are 1-index already) + lz = (CUDA.blockIdx().x - Int32(1)) * CUDA.blockDim().x + + CUDA.threadIdx().x + ly = (CUDA.blockIdx().y - Int32(1)) * CUDA.blockDim().y + + CUDA.threadIdx().y + + if lz <= size(u, 3) && ly <= size(u, 2) + + # get global coordinates + z = lz + offsets[3] - 1 + y = ly + offsets[2] - 1 + + if z >= minL && z <= maxL && y >= minL && y <= maxL + xoff = offsets[1] + + for x in minL:maxL + # check if global coordinates for initialization are inside the region + if !is_inside(x, y, z, offsets, sizes) + continue + end + + # Julia is 1-index, like Fortran :) + u[x - xoff + 2, ly + 1, lz + 1] = 0.25 + v[x - xoff + 2, ly + 1, lz + 1] = 0.33 + end + end + end +end + +function _calculate!(fields::Fields{T, N, <:CUDA.CuArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + function _calculate_kernel!(u, v, u_temp, v_temp, sizes, Du, Dv, F, K, + noise, dt) + + # local coordinates (this are 1-index already) + k = (CUDA.blockIdx().x - Int32(1)) * CUDA.blockDim().x + + CUDA.threadIdx().x + j = (CUDA.blockIdx().y - Int32(1)) * CUDA.blockDim().y + + CUDA.threadIdx().y + + # loop through non-ghost cells + if k >= 2 && k <= sizes[3] + 1 && j >= 2 && j <= sizes[2] + 1 + # bounds are inclusive + for i in 2:(sizes[1] + 1) + u_ijk = u[i, j, k] + v_ijk = v[i, j, k] + + du = Du * _laplacian(i, j, k, u) - u_ijk * v_ijk^2 + + F * (1.0 - u_ijk) + + noise * rand(Distributions.Uniform(-1, 1)) + + dv = Dv * _laplacian(i, j, k, v) + u_ijk * v_ijk^2 - + (F + K) * v_ijk + + # advance the next step + u_temp[i, j, k] = u_ijk + du * dt + v_temp[i, j, k] = v_ijk + dv * dt + end + end + end + + Du = convert(T, settings.Du) + Dv = convert(T, settings.Dv) + F = convert(T, settings.F) + K = convert(T, settings.k) + noise = convert(T, settings.noise) + dt = convert(T, settings.dt) + + cu_sizes = CUDA.CuArray(mcd.proc_sizes) + + threads = (16, 16) + blocks = (settings.L, settings.L) + + CUDA.@cuda threads=threads blocks=blocks _calculate_kernel!(fields.u, + fields.v, + fields.u_temp, + fields.v_temp, + cu_sizes, + Du, Dv, F, K, + noise, dt) + CUDA.synchronize() +end + +function get_fields(fields::Fields{T, N, <:CUDA.CuArray{T, N}}) where {T, N} + u = Array(fields.u) + u_no_ghost = u[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + + v = Array(fields.v) + v_no_ghost = v[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + return u_no_ghost, v_no_ghost +end diff --git a/examples/simulations/GrayScott.jl/src/simulation/Structs.jl b/examples/simulations/GrayScott.jl/src/simulation/Structs.jl new file mode 100644 index 0000000000..ca35fb5611 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Structs.jl @@ -0,0 +1,102 @@ + +""" +Settings carry the settings from the simulation config file (json or yaml formats) + +Using Base.@kwdef macro for easy defaults and enable keyword arguments +Settings(Du = 0.2, noise = 0.2) +See: +https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408/24?u=williamfgc +""" +Base.@kwdef mutable struct Settings + L::Int64 = 128 + steps::Int32 = 20000 + plotgap::Int32 = 200 + F::Float64 = 0.04 + k::Float64 = 0 + dt::Float64 = 0.2 + Du::Float64 = 0.05 + Dv::Float64 = 0.1 + noise::Float64 = 0.0 + output::String = "foo.bp" + checkpoint::Bool = false + checkpoint_freq::Int32 = 2000 + checkpoint_output::String = "ckpt.bp" + restart::Bool = false + restart_input::String = "ckpt.bp" + adios_config::String = "adios2.yaml" + adios_span::Bool = false + adios_memory_selection::Bool = false + mesh_type::String = "image" + precision::String = "Float64" + backend::String = "CPU" +end + +SettingsKeys = Set{String}([ + "L", + "steps", + "plotgap", + "F", + "k", + "dt", + "Du", + "Dv", + "noise", + "output", + "checkpoint", + "checkpoint_freq", + "checkpoint_output", + "restart", + "restart_input", + "adios_config", + "adios_span", + "adios_memory_selection", + "mesh_type", + "precision", + "backend", + ]) + +Base.@kwdef mutable struct MPICartDomain + cart_comm::MPI.Comm = MPI.COMM_NULL + + # Cartesian communicator info + # Could used StaticArrays.jl? + # start dims with zeros + dims::Vector{Int32} = zeros(Int32, 3) + coords::Vector{Int32} = zeros(Int32, 3) + + # local process mesh sizes and offsets in Cartesian domain info, using defaults + proc_sizes::Vector{Int64} = [128, 128, 128] + proc_offsets::Vector{Int64} = [1, 1, 1] + + # couldn't use NamedTuples as struct is mutable + proc_neighbors = Dict{String, Int32}("west" => -1, "east" => -1, "up" => -1, + "down" => -1, "north" => -1, + "south" => -1) +end + +""" +Carry the physical field outputs: u and v +Using AbstractArray to allow for Array, CuArray and ROCArray +""" +mutable struct Fields{T, N, A <: AbstractArray{T, N}} + u::A + v::A + u_temp::A + v_temp::A + # MPI Datatypes for halo exchange MPI.Datatype(T) + xy_face_t::MPI.Datatype + xz_face_t::MPI.Datatype + yz_face_t::MPI.Datatype +end + +""" +Carry the I/O information for outputs +""" +struct IOStream + adios::ADIOS2.Adios + io::ADIOS2.AIO + engine::ADIOS2.Engine + var_step::ADIOS2.Variable + var_U::ADIOS2.Variable + var_V::ADIOS2.Variable +end diff --git a/examples/simulations/GrayScott.jl/test/Project.toml b/examples/simulations/GrayScott.jl/test/Project.toml new file mode 100644 index 0000000000..c60df76b67 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/Project.toml @@ -0,0 +1,3 @@ +[deps] +MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl b/examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl new file mode 100644 index 0000000000..46a844a037 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl @@ -0,0 +1,12 @@ + +import GrayScott +import Test: @testset, @test + +@testset "GrayScott" begin MPI.mpiexec() do runcmd + config_file = joinpath(dirname(Base.active_project()), "examples", + "settings-files.json") + + juliacmd = `julia --project gray-scott.jl $config_file` + + @test run(`mpirun -n 4 $juliacmd`).exitcode == 0 +end end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/test/runtests.jl b/examples/simulations/GrayScott.jl/test/runtests.jl new file mode 100644 index 0000000000..e795c94ca9 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/runtests.jl @@ -0,0 +1,26 @@ + +import MPI + +# Run all lightweight unit tests within a single MPI session +MPI.Init() + +verbose = false + +# unit tests for module GrayScott +include(joinpath("unit", "helper", "unit-helperMPI.jl")) + +include(joinpath("unit", "simulation", "unit-Inputs.jl")) +include(joinpath("unit", "simulation", "unit-Simulation.jl")) +include(joinpath("unit", "simulation", "unit-Simulation_CUDA.jl")) +include(joinpath("unit", "simulation", "unit-IO.jl")) + +# unit tests for analysis scripts +include(joinpath("unit", "analysis", "unit-pdfcalc.jl")) + +MPI.Finalize() + +# Command line tests. These are heavier tests launched as separate processes. +# The downside is that only global success can be tested and not internal states. + +# functional tests +# include(joinpath("functional", "functional-GrayScott.jl")) diff --git a/examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl b/examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl new file mode 100644 index 0000000000..87ea9b8478 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl @@ -0,0 +1,19 @@ + +import Test: @testset, @test, @test_throws + +include(joinpath(dirname(Base.active_project()), "src", "analysis", + "pdfcalc.jl")) + +@testset "unit-analysis.pdfcalc._parse_args" begin + inputs = _parse_arguments(["foo.bp", "bar.bp", "1500"]) + @test inputs["input"] == "foo.bp" + @test inputs["output"] == "bar.bp" + @test inputs["N"] == 1500 + @test inputs["output_inputdata"] == false + + inputs = _parse_arguments(["input.bp", "output.bp", "1000", "true"]) + @test inputs["input"] == "input.bp" + @test inputs["output"] == "output.bp" + @test inputs["N"] == 1000 + @test inputs["output_inputdata"] == true +end diff --git a/examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl b/examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl new file mode 100644 index 0000000000..33d9f2202f --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl @@ -0,0 +1,12 @@ + +import Test: @testset, @test, @test_throws +import GrayScott: Helper + +@testset "unit-Helper.bcast_file_contents" begin + config_file = joinpath(dirname(Base.active_project()), "examples", + "settings-files.json") + + file_contents = Helper.bcast_file_contents(config_file, MPI.COMM_WORLD) + file_contents_expected = String(read(open(config_file, "r"))) + @test file_contents == file_contents_expected +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl new file mode 100644 index 0000000000..5a33f90ed9 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl @@ -0,0 +1,36 @@ + +import Test: @testset, @test, @test_throws + +import ADIOS2 + +# import submodule +import GrayScott: IO +# import types +import GrayScott: Settings, MPICartDomain, Fields + +@testset "unit-IO.init" begin + settings = Settings() + mpi_cart_domain = MPICartDomain() + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + @test eltype(fields.u) == Float32 + @test eltype(fields.v) == Float32 + + stream = IO.init(settings, mpi_cart_domain, fields) + + @test ADIOS2.name(stream.engine) == "foo.bp" + IO.close!(stream) + + # @TODO: needs to be done from rank==0 only + # Base.Filesystem.rm("foo.bp", force = true, recursive = true) +end + +@testset "unit-IO.write" begin + settings = Settings() + settings.L = 6 + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + stream = IO.init(settings, mpi_cart_domain, fields) + IO.write_step!(stream, Int32(0), fields) + IO.close!(stream) +end diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl new file mode 100644 index 0000000000..fb77325de5 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl @@ -0,0 +1,15 @@ + +import Test: @testset, @test, @test_throws +import GrayScott: Inputs + +# Unfortunately due to MPI being a Singleton, single MPI.Init() +# these unit tests don't run as independent files + +@testset "unit-Inputs.get_settings" begin + config_file = joinpath(dirname(Base.active_project()), "examples", + "settings-files.json") + Inputs.get_settings([config_file], MPI.COMM_WORLD) + + @test_throws(ArgumentError, + Inputs.get_settings(["hello.nojson"], MPI.COMM_WORLD)) +end diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl new file mode 100644 index 0000000000..ad43a8b49f --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl @@ -0,0 +1,34 @@ + +import Test: @testset, @test, @test_throws +# import submodule +import GrayScott: Simulation +# import types +import GrayScott: Settings, MPICartDomain, Fields + +# Unfortunately due to MPI being a Singleton, single MPI.Init() +# these unit tests don't run as independent files + +@testset "unit-Simulation.init" begin + settings = Settings() + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + @test typeof(fields) == Fields{Float32, 3, Array{Float32, 3}} +end + +@testset "unit-Simulation.iterate" begin + settings = Settings() + settings.L = 2 + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + Simulation.iterate!(fields, settings, mpi_cart_domain) + + if verbose + sleep(0.01) + rank = MPI.Comm_rank(MPI.COMM_WORLD) + @show rank, fields.v + end +end + +#end diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl new file mode 100644 index 0000000000..e3c3a6fc07 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl @@ -0,0 +1,28 @@ + +import Test: @testset, @test, @test_throws +# import submodule +import GrayScott: Simulation +# import types +import GrayScott: Settings, MPICartDomain, Fields + +@testset "unit-Simulation.init_fields-cuda" begin + function test_init_cuda(L) + settings = Settings() + settings.L = L + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + settings.backend = "CUDA" + fields_cuda = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + @test fields.u ≈ Array(fields_cuda.u) + @test fields.v ≈ Array(fields_cuda.v) + end + + test_init_cuda(8) + test_init_cuda(16) + test_init_cuda(32) + test_init_cuda(64) + test_init_cuda(128) +end \ No newline at end of file diff --git a/examples/simulations/gray-scott-kokkos/CMakeLists.txt b/examples/simulations/gray-scott-kokkos/CMakeLists.txt new file mode 100644 index 0000000000..b43362cf3f --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/CMakeLists.txt @@ -0,0 +1,47 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsGrayScottKokkosExample) + +# CXX Compiler settings only in for this example +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(Kokkos 3.7 QUIET) + if(Kokkos_FOUND AND DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +else() + if(DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_Kokkos) + add_executable(adios2_simulations_gray-scott-kokkos + main.cpp + gray-scott.cpp + settings.cpp + writer.cpp + restart.cpp + ) + kokkos_compilation(SOURCE gray-scott.cpp) + target_link_libraries(adios2_simulations_gray-scott-kokkos adios2::cxx11_mpi MPI::MPI_C Kokkos::kokkos) + install(TARGETS adios2_simulations_gray-scott-kokkos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/simulations/gray-scott-kokkos/README.md b/examples/simulations/gray-scott-kokkos/README.md new file mode 100644 index 0000000000..24f6213b5e --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/README.md @@ -0,0 +1,2 @@ +Kokkos version of Gray-Scott. +Please use the installed Gray-Scott example directory but run adios2-gray-scott-kokkos binary. diff --git a/examples/simulations/gray-scott-kokkos/gray-scott.cpp b/examples/simulations/gray-scott-kokkos/gray-scott.cpp new file mode 100644 index 0000000000..b6f6cd4b7c --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/gray-scott.cpp @@ -0,0 +1,330 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * The solver is based on Hiroshi Watanabe's 2D Gray-Scott reaction diffusion + * code available at: https://github.com/kaityo256/sevendayshpc/tree/master/day5 + */ + +#include "gray-scott.h" + +#include +#include // runtime_error +#include + +GrayScott::GrayScott(const Settings &settings, MPI_Comm comm) +: settings(settings), comm(comm), rand_pool(5374857) +{ +} + +GrayScott::~GrayScott() {} + +void GrayScott::init() +{ + init_mpi(); + init_field(); +} + +void GrayScott::iterate() +{ + auto temp_u = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, u); + auto temp_v = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, v); + exchange(temp_u, temp_v); + Kokkos::deep_copy(u, temp_u); + Kokkos::deep_copy(v, temp_v); + + calc(); + + std::swap(u, u2); + std::swap(v, v2); +} + +void GrayScott::restart(Kokkos::View &u_in, + Kokkos::View &v_in) +{ + auto const expected_len = (size_x + 2) * (size_y + 2) * (size_z + 2); + if (u_in.size() == expected_len) + { + u = u_in; + v = v_in; + } + else + { + throw std::runtime_error("Restart with incompatible array size, expected " + + std::to_string(expected_len) + " got " + + std::to_string(u_in.size()) + " elements"); + } +} + +const Kokkos::View GrayScott::u_ghost() const { return u; } + +const Kokkos::View GrayScott::v_ghost() const { return v; } + +Kokkos::View GrayScott::u_noghost() const +{ + return data_noghost(u); +} + +Kokkos::View GrayScott::v_noghost() const +{ + return data_noghost(v); +} + +void GrayScott::u_noghost(Kokkos::View u_no_ghost) const +{ + data_noghost(u, u_no_ghost); +} + +void GrayScott::v_noghost(Kokkos::View v_no_ghost) const +{ + data_noghost(v, v_no_ghost); +} + +Kokkos::View +GrayScott::data_noghost(const Kokkos::View &data) const +{ + Kokkos::View buf("noghost_temp", size_x, size_y, size_z); + data_no_ghost_common(data, buf); + return buf; +} + +void GrayScott::data_noghost(const Kokkos::View &data, + Kokkos::View data_no_ghost) const +{ + data_no_ghost_common(data, data_no_ghost); +} + +void GrayScott::init_field() +{ + Kokkos::resize(u, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(u, 1.0); + Kokkos::resize(v, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(v, 0.0); + Kokkos::resize(u2, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(u2, 0.0); + Kokkos::resize(v2, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(v2, 0.0); + + const int d = 6; + auto const L = settings.L; + auto const settingsL = static_cast(settings.L); + auto const temp_u = u; + auto const temp_v = v; + size_t const ox = offset_x, oy = offset_y, oz = offset_z; + size_t const sx = size_x, sy = size_y; + auto const min_z = std::max(L / 2 - d, offset_z); + auto const max_z = std::min(L / 2 + d, offset_z + size_z); + Kokkos::parallel_for( + "init_buffers", Kokkos::RangePolicy<>(min_z, max_z), KOKKOS_LAMBDA(int z) { + for (int y = settingsL / 2 - d; y < settingsL / 2 + d; y++) + { + if (y < static_cast(oy)) + continue; + if (y >= static_cast(oy + sy)) + continue; + for (int x = settingsL / 2 - d; x < settingsL / 2 + d; x++) + { + if (x < static_cast(ox)) + continue; + if (x >= static_cast(ox + sx)) + continue; + temp_u(x - ox + 1, y - oy + 1, z - oz + 1) = 0.25; + temp_v(x - ox + 1, y - oy + 1, z - oz + 1) = 0.33; + } + } + }); +} + +void GrayScott::calc() +{ + auto const temp_u = u; + auto const temp_v = v; + auto const temp_u2 = u2; + auto const temp_v2 = v2; + auto const Du = settings.Du; + auto const Dv = settings.Dv; + auto const dt = settings.dt; + auto const F = settings.F; + auto const k = settings.k; + auto const noise = settings.noise; + size_t const sx = size_x, sy = size_y, sz = size_z; + auto const random_pool = rand_pool; + Kokkos::parallel_for( + "calc_gray_scott", Kokkos::RangePolicy<>(1, sz + 1), KOKKOS_LAMBDA(int z) { + RandomPool::generator_type generator = random_pool.get_state(); + double ts; + for (int y = 1; y < static_cast(sy) + 1; y++) + { + for (int x = 1; x < static_cast(sx) + 1; x++) + { + double du, dv; + // laplacian for u + ts = 0; + ts += temp_u(x - 1, y, z); + ts += temp_u(x + 1, y, z); + ts += temp_u(x, y - 1, z); + ts += temp_u(x, y + 1, z); + ts += temp_u(x, y, z - 1); + ts += temp_u(x, y, z + 1); + ts += -6.0 * temp_u(x, y, z); + ts /= 6.0; + du = Du * ts; + + // laplacian for v + ts = 0; + ts += temp_v(x - 1, y, z); + ts += temp_v(x + 1, y, z); + ts += temp_v(x, y - 1, z); + ts += temp_v(x, y + 1, z); + ts += temp_v(x, y, z - 1); + ts += temp_v(x, y, z + 1); + ts += -6.0 * temp_v(x, y, z); + ts /= 6.0; + dv = Dv * ts; + + du += (-temp_u(x, y, z) * temp_v(x, y, z) * temp_v(x, y, z) + + F * (1.0 - temp_u(x, y, z))); + dv += (temp_u(x, y, z) * temp_v(x, y, z) * temp_v(x, y, z) - + (F + k) * temp_v(x, y, z)); + du += noise * generator.frand(-1.f, 1.f); + temp_u2(x, y, z) = temp_u(x, y, z) + du * dt; + temp_v2(x, y, z) = temp_v(x, y, z) + dv * dt; + } + } + random_pool.free_state(generator); + }); +} + +void GrayScott::init_mpi() +{ + int dims[3] = {}; + const int periods[3] = {1, 1, 1}; + int coords[3] = {}; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &procs); + + MPI_Dims_create(procs, 3, dims); + npx = dims[0]; + npy = dims[1]; + npz = dims[2]; + + MPI_Cart_create(comm, 3, dims, periods, 0, &cart_comm); + MPI_Cart_coords(cart_comm, rank, 3, coords); + px = coords[0]; + py = coords[1]; + pz = coords[2]; + + size_x = settings.L / npx; + size_y = settings.L / npy; + size_z = settings.L / npz; + + if (px < settings.L % npx) + { + size_x++; + } + if (py < settings.L % npy) + { + size_y++; + } + if (pz < settings.L % npz) + { + size_z++; + } + + offset_x = (settings.L / npx * px) + std::min(settings.L % npx, px); + offset_y = (settings.L / npy * py) + std::min(settings.L % npy, py); + offset_z = (settings.L / npz * pz) + std::min(settings.L % npz, pz); + + MPI_Cart_shift(cart_comm, 0, 1, &west, &east); + MPI_Cart_shift(cart_comm, 1, 1, &down, &up); + MPI_Cart_shift(cart_comm, 2, 1, &south, &north); + + // XY faces: size_x * (size_y + 2) + MPI_Type_vector(static_cast(size_y + 2), static_cast(size_x), + static_cast(size_x + 2), MPI_DOUBLE, &xy_face_type); + MPI_Type_commit(&xy_face_type); + + // XZ faces: size_x * size_z + MPI_Type_vector(static_cast(size_z), static_cast(size_x), + static_cast((size_x + 2) * (size_y + 2)), MPI_DOUBLE, &xz_face_type); + MPI_Type_commit(&xz_face_type); + + // YZ faces: (size_y + 2) * (size_z + 2) + MPI_Type_vector(static_cast((size_y + 2) * (size_z + 2)), 1, static_cast(size_x + 2), + MPI_DOUBLE, &yz_face_type); + MPI_Type_commit(&yz_face_type); +} + +void GrayScott::exchange_xy( + Kokkos::View local_data) const +{ + MPI_Status st; + + // Send XY face z=size_z to north and receive z=0 from south + MPI_Sendrecv(&local_data.data()[l2i(1, 0, static_cast(size_z))], 1, xy_face_type, north, 1, + &local_data.data()[l2i(1, 0, 0)], 1, xy_face_type, south, 1, cart_comm, &st); + // Send XY face z=1 to south and receive z=size_z+1 from north + MPI_Sendrecv(&local_data.data()[l2i(1, 0, 1)], 1, xy_face_type, south, 1, + &local_data.data()[l2i(1, 0, static_cast(size_z + 1))], 1, xy_face_type, + north, 1, cart_comm, &st); +} + +void GrayScott::exchange_xz( + Kokkos::View local_data) const +{ + MPI_Status st; + + // Send XZ face y=size_y to up and receive y=0 from down + MPI_Sendrecv(&local_data.data()[l2i(1, static_cast(size_y), 1)], 1, xz_face_type, up, 2, + &local_data.data()[l2i(1, 0, 1)], 1, xz_face_type, down, 2, cart_comm, &st); + // Send XZ face y=1 to down and receive y=size_y+1 from up + MPI_Sendrecv(&local_data.data()[l2i(1, 1, 1)], 1, xz_face_type, down, 2, + &local_data.data()[l2i(1, static_cast(size_y + 1), 1)], 1, xz_face_type, up, + 2, cart_comm, &st); +} + +void GrayScott::exchange_yz( + Kokkos::View local_data) const +{ + MPI_Status st; + + // Send YZ face x=size_x to east and receive x=0 from west + MPI_Sendrecv(&local_data.data()[l2i(static_cast(size_x), 0, 0)], 1, yz_face_type, east, 3, + &local_data.data()[l2i(0, 0, 0)], 1, yz_face_type, west, 3, cart_comm, &st); + // Send YZ face x=1 to west and receive x=size_x+1 from east + MPI_Sendrecv(&local_data.data()[l2i(1, 0, 0)], 1, yz_face_type, west, 3, + &local_data.data()[l2i(static_cast(size_x + 1), 0, 0)], 1, yz_face_type, east, + 3, cart_comm, &st); +} + +void GrayScott::exchange(Kokkos::View u, + Kokkos::View v) const +{ + exchange_xy(u); + exchange_xz(u); + exchange_yz(u); + + exchange_xy(v); + exchange_xz(v); + exchange_yz(v); +} + +void GrayScott::data_no_ghost_common( + const Kokkos::View &data, + Kokkos::View data_no_ghost) const +{ + auto const sx = size_x; + auto const sy = size_y; + auto const sz = size_z; + Kokkos::parallel_for( + "updateBuffer", Kokkos::RangePolicy<>(1, sz + 1), KOKKOS_LAMBDA(int z) { + for (int y = 1; y < static_cast(sy) + 1; y++) + { + for (int x = 1; x < static_cast(sx) + 1; x++) + { + data_no_ghost(x - 1, y - 1, z - 1) = data(x, y, z); + } + } + }); +} diff --git a/examples/simulations/gray-scott-kokkos/gray-scott.h b/examples/simulations/gray-scott-kokkos/gray-scott.h new file mode 100644 index 0000000000..26553c8c07 --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/gray-scott.h @@ -0,0 +1,102 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + +#ifndef __GRAY_SCOTT_H__ +#define __GRAY_SCOTT_H__ + +#include + +#include +#include +#include + +#include "settings.h" + +class GrayScott +{ +public: + // Dimension of process grid + size_t npx, npy, npz; + // Coordinate of this rank in process grid + size_t px, py, pz; + // Dimension of local array + size_t size_x, size_y, size_z; + // Offset of local array in the global array + size_t offset_x, offset_y, offset_z; + + GrayScott(const Settings &settings, MPI_Comm comm); + ~GrayScott(); + + void init(); + void iterate(); + void restart(Kokkos::View &u, + Kokkos::View &v); + + const Kokkos::View u_ghost() const; + const Kokkos::View v_ghost() const; + + Kokkos::View u_noghost() const; + Kokkos::View v_noghost() const; + + void u_noghost(Kokkos::View u_no_ghost) const; + void v_noghost(Kokkos::View v_no_ghost) const; + + Settings settings; + + Kokkos::View u, v, u2, v2; + + int rank, procs; + int west, east, up, down, north, south; + MPI_Comm comm; + MPI_Comm cart_comm; + + // MPI datatypes for halo exchange + MPI_Datatype xy_face_type; + MPI_Datatype xz_face_type; + MPI_Datatype yz_face_type; + + using RandomPool = Kokkos::Random_XorShift64_Pool; + RandomPool rand_pool; + + // Setup cartesian communicator data types + void init_mpi(); + // Setup initial conditions + void init_field(); + + // Process simulation for one timestep + void calc(); + + // Exchange faces with neighbors + void exchange(Kokkos::View u, + Kokkos::View v) const; + // Exchange XY faces with north/south + void + exchange_xy(Kokkos::View local_data) const; + // Exchange XZ faces with up/down + void + exchange_xz(Kokkos::View local_data) const; + // Exchange YZ faces with west/east + void + exchange_yz(Kokkos::View local_data) const; + + // Return a copy of data with ghosts removed + Kokkos::View + data_noghost(const Kokkos::View &data) const; + + // pointer version + void data_noghost(const Kokkos::View &data, + Kokkos::View no_ghost) const; + + // Convert local coordinate to local index + KOKKOS_FUNCTION int l2i(int x, int y, int z) const + { + return static_cast(x + y * (size_x + 2) + z * (size_x + 2) * (size_y + 2)); + } + + void data_no_ghost_common(const Kokkos::View &data, + Kokkos::View data_no_ghost) const; +}; + +#endif diff --git a/examples/simulations/gray-scott-kokkos/json.hpp b/examples/simulations/gray-scott-kokkos/json.hpp new file mode 100644 index 0000000000..1e7cf51e0a --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/json.hpp @@ -0,0 +1,20274 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ +| | |__ | | | | | | version 3.4.0 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2018 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef NLOHMANN_JSON_HPP +#define NLOHMANN_JSON_HPP + +#define NLOHMANN_JSON_VERSION_MAJOR 3 +#define NLOHMANN_JSON_VERSION_MINOR 4 +#define NLOHMANN_JSON_VERSION_PATCH 0 + +#include // all_of, find, for_each +#include // assert +#include // and, not, or +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#include // istream, ostream +#include // iterator_traits, random_access_iterator_tag +#include // accumulate +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap + +// #include +#ifndef NLOHMANN_JSON_FWD_HPP +#define NLOHMANN_JSON_FWD_HPP + +#include // int64_t, uint64_t +#include // map +#include // allocator +#include // string +#include // vector + +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +namespace nlohmann +{ +/*! +@brief default JSONSerializer template argument + +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template +struct adl_serializer; + +template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer> +class basic_json; + +/*! +@brief JSON Pointer + +A JSON pointer defines a string syntax for identifying a specific value +within a JSON document. It can be used with functions `at` and +`operator[]`. Furthermore, JSON pointers are the base for JSON patches. + +@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) + +@since version 2.0.0 +*/ +template +class json_pointer; + +/*! +@brief default JSON class + +This type is the default specialization of the @ref basic_json class which +uses the standard template types. + +@since version 1.0.0 +*/ +using json = basic_json<>; +} // namespace nlohmann + +#endif + +// #include + + +// This file contains all internal macro definitions +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// disable float-equal warnings on GCC/clang +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdocumentation" +#endif + +// allow for portable deprecation warnings +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) + #define JSON_DEPRECATED __declspec(deprecated) +#else + #define JSON_DEPRECATED +#endif + +// allow to disable exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +// manual branch prediction +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) + #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else + #define JSON_LIKELY(x) x + #define JSON_UNLIKELY(x) x +#endif + +// C++ language standard detection +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + +// #include + + +#include // not +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type + +namespace nlohmann +{ +namespace detail +{ +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +template +using uncvref_t = typename std::remove_cv::type>::type; + +// implementation of C++14 index_sequence and affiliates +// source: https://stackoverflow.com/a/32223343 +template +struct index_sequence +{ + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +template +struct merge_and_renumber; + +template +struct merge_and_renumber, index_sequence> + : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; + +template +struct make_index_sequence + : merge_and_renumber < typename make_index_sequence < N / 2 >::type, + typename make_index_sequence < N - N / 2 >::type > {}; + +template<> struct make_index_sequence<0> : index_sequence<> {}; +template<> struct make_index_sequence<1> : index_sequence<0> {}; + +template +using index_sequence_for = make_index_sequence; + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static constexpr T value{}; +}; + +template +constexpr T static_const::value; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // not +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval + +// #include + +// #include + +// #include + + +#include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + + +// http://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template