From 9f486ba4dd66b6fae61af4376e01b77368bc9ef2 Mon Sep 17 00:00:00 2001 From: Wyatt Spear Date: Tue, 30 May 2023 12:33:09 -0700 Subject: [PATCH] Updated adios2 test. --- validation_tests/adios2/Makefile | 13 +- validation_tests/adios2/hello-world.cpp | 76 ------- validation_tests/adios2/helloBPTimeWriter.cpp | 185 ++++++++++++++++++ validation_tests/adios2/run.sh | 2 +- 4 files changed, 194 insertions(+), 82 deletions(-) delete mode 100644 validation_tests/adios2/hello-world.cpp create mode 100644 validation_tests/adios2/helloBPTimeWriter.cpp diff --git a/validation_tests/adios2/Makefile b/validation_tests/adios2/Makefile index 4e9ed07e..2beb56f0 100644 --- a/validation_tests/adios2/Makefile +++ b/validation_tests/adios2/Makefile @@ -1,20 +1,23 @@ CC = $(TEST_CC_MPI) #mpicc CXX = $(TEST_CXX_MPI) #mpic++ CFLAGS = -I$(ADIOS2_ROOT)/include -Wall -CXXFLAGS = -I$(ADIOS2_ROOT)/include -Wall +CXXFLAGS = $(shell adios2-config --cxx-flags -m) LD = $(TEST_CXX_MPI) #mpic++ -LDFLAGS = -L$(ADIOS2_LIB_PATH) -ladios2_cxx11 +LDFLAGS = $(shell adios2-config --cxx-libs -m) -all: hello-world +all: helloBPTimeWriter -hello-world: hello-world.o +helloBPTimeWriter: helloBPTimeWriter.o $(LD) -o $@ $^ $(LDFLAGS) %.o: %.c $(CC) $(CFLAGS) -c $< +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< + clean: - rm -f *.o hello-world + rm -f *.o helloBPTimeWriter .PHONY: clean diff --git a/validation_tests/adios2/hello-world.cpp b/validation_tests/adios2/hello-world.cpp deleted file mode 100644 index 19bc4370..00000000 --- a/validation_tests/adios2/hello-world.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * * 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); - adios2::Variable varGreeting = - io.InquireVariable("Greeting"); - std::string greeting; - reader.Get(varGreeting, greeting); - 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/validation_tests/adios2/helloBPTimeWriter.cpp b/validation_tests/adios2/helloBPTimeWriter.cpp new file mode 100644 index 00000000..3ca86093 --- /dev/null +++ b/validation_tests/adios2/helloBPTimeWriter.cpp @@ -0,0 +1,185 @@ +/* + * 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 + * function for time aggregation. Time step is saved as an additional (global) + * single value variable, just for tracking purposes. + * + * Created on: Feb 16, 2017 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //std::for_each +#include //std::ios_base::failure +#include //std::cout +#include +#include //std::invalid_argument std::exception +#include + +#include + +int main(int argc, char *argv[]) +{ + int provided; + + // MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP + MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + // Application variable + std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const std::size_t Nx = myFloats.size(); + + try + { + /** ADIOS class factory of IO class objects */ + adios2::ADIOS adios(MPI_COMM_WORLD); + + /// WRITE + { + /*** IO class object: settings and factory of Settings: Variables, + * Parameters, Transports, and Execution: Engines */ + adios2::IO bpIO = adios.DeclareIO("BPFile_N2N"); + bpIO.SetParameters({{"Threads", "2"}}); + + /** global array: name, { shape (total dimensions) }, { start + * (local) }, + * { count (local) }, all are constant dimensions */ + const unsigned int variablesSize = 10; + std::vector> bpFloats(variablesSize); + + adios2::Variable bpString = + bpIO.DefineVariable("bpString"); + + for (unsigned int v = 0; v < variablesSize; ++v) + { + std::string namev("bpFloats"); + if (v < 10) + { + namev += "00"; + } + else if (v < 100) + { + namev += "0"; + } + namev += std::to_string(v); + + bpFloats[v] = + bpIO.DefineVariable(namev, {size * Nx}, {rank * Nx}, + {Nx}, adios2::ConstantDims); + } + + /** global single value variable: name */ + adios2::Variable bpTimeStep = + bpIO.DefineVariable("timeStep"); + + /** Engine derived class, spawned to start IO operations */ + adios2::Engine bpWriter = + bpIO.Open("myVector.bp", adios2::Mode::Write); + + for (unsigned int timeStep = 0; timeStep < 3; ++timeStep) + { + bpWriter.BeginStep(); + if (rank == 0) // global single value, only saved by rank 0 + { + bpWriter.Put(bpTimeStep, timeStep); + } + + // template type is optional, but recommended + for (unsigned int v = 0; v < variablesSize; ++v) + { + myFloats[0] = static_cast(v + timeStep); + // Note: Put is deferred, so all variables will see v == 9 + // and myFloats[0] == 9, 10, or 11 + bpWriter.Put(bpFloats[v], myFloats.data()); + } + const std::string myString( + "Hello from rank: " + std::to_string(rank) + + " and timestep: " + std::to_string(timeStep)); + + if (rank == 0) + { + bpWriter.Put(bpString, myString); + } + + bpWriter.EndStep(); + } + + bpWriter.Close(); + } + // MPI_Barrier(MPI_COMM_WORLD); + + if (false) + { /////////////////////READ + // if (rank == 0) + // { + adios2::IO ioReader = adios.DeclareIO("bpReader"); + + adios2::Engine bpReader = + ioReader.Open("myVector.bp", adios2::Mode::Read); + + adios2::Variable bpFloats000 = + ioReader.InquireVariable("bpFloats000"); + + adios2::Variable bpString = + ioReader.InquireVariable("bpString"); + + if (bpFloats000) + { + bpFloats000.SetSelection({{rank * Nx}, {Nx}}); + bpFloats000.SetStepSelection({2, 1}); + + std::vector data(bpFloats000.SelectionSize()); + bpReader.Get(bpFloats000, data.data(), adios2::Mode::Sync); + + std::cout << "Data timestep " << bpFloats000.StepsStart() + << " from rank " << rank << ": "; + for (const auto datum : data) + { + std::cout << datum << " "; + } + std::cout << "\n"; + } + else + { + std::cout << "Variable bpFloats000 not found\n"; + } + + if (bpString) + { + bpString.SetStepSelection({3, 1}); + + std::string myString; + bpReader.Get(bpString, myString, adios2::Mode::Sync); + std::cout << myString << "\n"; + } + + bpReader.Close(); + } + } + catch (std::invalid_argument &e) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " + << rank << "\n"; + std::cout << e.what() << "\n"; + } + catch (std::ios_base::failure &e) + { + std::cout << "IO System base failure exception, STOPPING PROGRAM " + "from rank " + << rank << "\n"; + std::cout << e.what() << "\n"; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; + std::cout << e.what() << "\n"; + } + + MPI_Finalize(); + + return 0; +} diff --git a/validation_tests/adios2/run.sh b/validation_tests/adios2/run.sh index d481359d..f63d5889 100755 --- a/validation_tests/adios2/run.sh +++ b/validation_tests/adios2/run.sh @@ -3,4 +3,4 @@ . ./setup.sh #mpiexec -n 4 -eval $TEST_RUN ./hello-world +eval $TEST_RUN ./helloBPTimeWriter