From f1ae7186b01ddced05a62ba828510cc7be41aa84 Mon Sep 17 00:00:00 2001 From: Norbert Podhorszki <pnorbert@ornl.gov> Date: Fri, 5 May 2017 17:14:53 -0400 Subject: [PATCH] Make multistep example work w/o MPI --- examples/groupless/multistep/CMakeLists.txt | 8 +- .../groupless/multistep/reader_allsteps.cpp | 55 ++------- .../groupless/multistep/reader_stepping.cpp | 105 ++---------------- .../groupless/multistep/writer_multistep.cpp | 19 +++- 4 files changed, 45 insertions(+), 142 deletions(-) diff --git a/examples/groupless/multistep/CMakeLists.txt b/examples/groupless/multistep/CMakeLists.txt index 902a35b6c..9022ff3d8 100644 --- a/examples/groupless/multistep/CMakeLists.txt +++ b/examples/groupless/multistep/CMakeLists.txt @@ -3,22 +3,24 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# +add_executable(writer_multistep writer_multistep.cpp) +add_executable(reader_stepping reader_stepping.cpp) +add_executable(reader_allsteps reader_allsteps.cpp) + if(ADIOS_USE_MPI) find_package(MPI COMPONENTS C REQUIRED) - add_executable(writer_multistep writer_multistep.cpp) target_include_directories(writer_multistep PRIVATE ${MPI_C_INCLUDE_PATH}) target_link_libraries(writer_multistep ${MPI_C_LIBRARIES}) - add_executable(reader_stepping reader_stepping.cpp) target_include_directories(reader_stepping PRIVATE ${MPI_C_INCLUDE_PATH}) target_link_libraries(reader_stepping ${MPI_C_LIBRARIES}) - add_executable(reader_allsteps reader_allsteps.cpp) target_include_directories(reader_allsteps PRIVATE ${MPI_C_INCLUDE_PATH}) target_link_libraries(reader_allsteps ${MPI_C_LIBRARIES}) endif() + target_link_libraries(writer_multistep adios2) target_link_libraries(reader_stepping adios2) target_link_libraries(reader_allsteps adios2) diff --git a/examples/groupless/multistep/reader_allsteps.cpp b/examples/groupless/multistep/reader_allsteps.cpp index f2a4fdf26..d710647fd 100644 --- a/examples/groupless/multistep/reader_allsteps.cpp +++ b/examples/groupless/multistep/reader_allsteps.cpp @@ -12,7 +12,9 @@ #include <vector> #include <adios2.h> +#ifdef ADIOS2_HAVE_MPI #include <mpi.h> +#endif template <class T> T **Make2DArray(int nRows, int nCols) @@ -62,13 +64,19 @@ void Print2DArray(T **ptr, int nRows, int nCols, std::string name) int main(int argc, char *argv[]) { - int rank, nproc; + int rank = 0, nproc = 1; +#ifdef ADIOS2_HAVE_MPI MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); +#endif const bool adiosDebug = true; +#ifdef ADIOS2_HAVE_MPI adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN); +#else + adios::ADIOS adios(adios::Verbose::WARN); +#endif // Info variables from the file int Nwriters; @@ -255,48 +263,6 @@ int main(int argc, char *argv[]) "Irregular array\n"); } -// overloaded Read from Derived -#if 0 - /* Ragged */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varRagged = - bpReader.InquiryVariable("Ragged"); - if (varRagged->m_Shape[1] != adios::VARYING_DIMENSION) - { - throw std::ios_base::failure( - "Unexpected condition: Ragged array's fast dimension " - "is supposed to be VARYING_DIMENSION\n"); - } - // We have here varRagged->sum_nblocks, nsteps, nblocks[], global - if (rank < - varRagged->nblocks[0]) // same as rank < Nwriters in this example - { - // get per-writer size information - varRagged->InquiryBlocks(); - // now we have the dimensions per block - - unsigned long long int count = - varRagged->blockinfo[rank].m_Dimensions[0]; - RaggedArray.resize(count); - - std::unique_ptr<adios::Selection> wbsel = - adios.SelectionWriteblock(rank); - bpReader->Read<float>("Ragged", wbsel, RaggedArray.data()); - - // We can use bounding box selection as well - std::unique_ptr<adios::Selection> rbbsel = - adios.SelectionBoundingBox({1, count}, {rank, 0}); - bpReader->Read<float>("Ragged", rbbsel, RaggedArray.data()); - } - - /* Extra help to process Ragged */ - int maxRaggedDim = - varRagged->GetMaxGlobalDimensions(1); // contains the largest - std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions( - 1); // contains all individual sizes in that dimension - -#endif - // Close file/stream bpReader->Close(); } @@ -325,7 +291,8 @@ int main(int argc, char *argv[]) } } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); - +#endif return 0; } diff --git a/examples/groupless/multistep/reader_stepping.cpp b/examples/groupless/multistep/reader_stepping.cpp index d7c0f3d5a..dbb88b5f2 100644 --- a/examples/groupless/multistep/reader_stepping.cpp +++ b/examples/groupless/multistep/reader_stepping.cpp @@ -12,17 +12,24 @@ #include <vector> #include <adios2.h> +#ifdef ADIOS2_HAVE_MPI #include <mpi.h> - +#endif int main(int argc, char *argv[]) { - int rank, nproc; + int rank = 0, nproc = 1; +#ifdef ADIOS2_HAVE_MPI MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); +#endif const bool adiosDebug = true; - adios::ADIOS adios(MPI_COMM_WORLD); +#ifdef ADIOS2_HAVE_MPI + adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN); +#else + adios::ADIOS adios(adios::Verbose::WARN); +#endif // Info variables from the file int Nwriters; @@ -92,96 +99,6 @@ int main(int argc, char *argv[]) Ny = vNY->m_Data[0]; std::cout << "NY = " << Ny << std::endl; -#if 0 - /* Nparts */ - // Nparts local scalar is presented as a 1D array of Nwriters - // elements. - // We can read all as a 1D array - std::vector<int> partsV(Nwriters); - adios::Variable<unsigned int> *vNproc = - bpReader->InquireVariableUInt("Nproc"); - bpReader->Read<int>("Nparts", - &partsV); // read with string name, no - // selection => read whole array - - /* Nice */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varNice = - bpReader.InquiryVariable("Nice"); - - if (varNice == nullptr) - throw std::ios_base::failure("ERROR: failed to find " - "variable 'myDoubles' in " - "input file\n"); - - // ? how do we know about the type? std::string varNice->m_Type - unsigned long long int gdim = - varMyDoubles->m_Shape[0]; // ?member var or - // member func? - unsigned long long int ldim = gdim / nproc; - unsigned long long int offs = rank * ldim; - if (rank == nproc - 1) - { - ldim = gdim - (ldim * gdim); - } - - NiceArray.reserve(ldim); - - // Make a 1D selection to describe the local dimensions of the - // variable - // we READ and - // its offsets in the global spaces - std::unique_ptr<adios::Selection> bbsel = - adios.SelectionBoundingBox( - {ldim}, {offs}); // local dims and offsets; both as list - varNice->SetSelection(bbsel); - bpReader->Read<double>(varNice, NiceArray.data()); - - /* Ragged */ - // inquiry about a variable, whose name we know - std::shared_ptr<adios::Variable<void>> varRagged = - bpReader.InquiryVariable("Ragged"); - if (varRagged->m_Shape[1] != adios::VARYING_DIMENSION) - { - throw std::ios_base::failure( - "Unexpected condition: Ragged array's fast " - "dimension " - "is supposed to be VARYING_DIMENSION\n"); - } - // We have here varRagged->sum_nblocks, nsteps, nblocks[], - // global - if (rank < varRagged->nblocks[0]) // same as rank < Nwriters in - // this example - { - // get per-writer size information - varRagged->InquiryBlocks(); - // now we have the dimensions per block - - unsigned long long int ldim = - varRagged->blockinfo[rank].m_Dimensions[0]; - RaggedArray.resize(ldim); - - std::unique_ptr<adios::Selection> wbsel = - adios.SelectionWriteblock(rank); - varRagged->SetSelection(wbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); - - // We can use bounding box selection as well - std::unique_ptr<adios::Selection> rbbsel = - adios.SelectionBoundingBox({1, ldim}, {rank, 0}); - varRagged->SetSelection(rbbsel); - bpReader->Read<float>(varRagged, RaggedArray.data()); - } - - /* Extra help to process Ragged */ - int maxRaggedDim = varRagged->GetMaxGlobalDimensions( - 1); // contains the largest - std::vector<int> raggedDims = - varRagged->GetVaryingGlobalDimensions( - 1); // contains all individual sizes in that - // dimension -#endif - // promise to not read more from this step bpReader->Release(); @@ -221,7 +138,9 @@ int main(int argc, char *argv[]) } } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/groupless/multistep/writer_multistep.cpp b/examples/groupless/multistep/writer_multistep.cpp index 9ed6f7c60..fce148ff7 100644 --- a/examples/groupless/multistep/writer_multistep.cpp +++ b/examples/groupless/multistep/writer_multistep.cpp @@ -12,14 +12,18 @@ #include <vector> #include <adios2.h> +#ifdef ADIOS2_HAVE_MPI #include <mpi.h> +#endif int main(int argc, char *argv[]) { - int rank, nproc; + int rank = 0, nproc = 1; +#ifdef ADIOS2_HAVE_MPI MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); +#endif const bool adiosDebug = true; const int NSTEPS = 5; @@ -27,7 +31,11 @@ int main(int argc, char *argv[]) // but always the same sequence at each run srand(rank * 32767); +#ifdef ADIOS2_HAVE_MPI adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::WARN); +#else + adios::ADIOS adios(adios::Verbose::WARN); +#endif // Application variables for output // 1. Global value, constant across processes, constant over time @@ -113,7 +121,12 @@ int main(int argc, char *argv[]) bpWriterSettings.SetEngine("ADIOS1Writer"); // ISO-POSIX file is the default transport // Passing parameters to the transport - bpWriterSettings.AddTransport("File", "library=MPI-IO"); + bpWriterSettings.AddTransport("File" +#ifdef ADIOS2_HAVE_MPI + , + "library=MPI-IO" +#endif + ); // Passing parameters to the engine bpWriterSettings.SetParameters("have_metadata_file", "yes"); // number of aggregators @@ -242,7 +255,9 @@ int main(int argc, char *argv[]) } } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); +#endif return 0; } -- GitLab