### Build ADIOS2 Example (helloWorld) Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/downloadAndBuild.rst.txt To build an example like 'helloWorld', navigate to its directory, create a build folder, and configure CMake using the ADIOS2 build directory path. CMake must be installed. ```bash cd Path-To-ADIOS2/examples/hello/helloWorld mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . ``` -------------------------------- ### Compile and Run ADIOS2 Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/attributes.rst.txt Instructions for compiling and running the ADIOS2 C++ example using CMake and MPI. Assumes ADIOS2 is installed. ```bash cd Path-To-ADIOS2/examples/hello/bpAttributeWriteRead mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . mpirun -np 2 ./adios2_hello_bpAttributeWriteRead_mpi ``` -------------------------------- ### Compile and Run ADIOS2 Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/variables.rst.txt Instructions for compiling and running an ADIOS2 MPI reader example. This involves navigating to the example directory, creating a build directory, configuring with CMake, building the executable, and running with mpirun. ```bash cd Path-To-ADIOS2/examples/hello/bpReader mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . mpirun -np 2 ./adios2_hello_bpReader_mpi ``` -------------------------------- ### Compile and Run ADIOS2 Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/helloWorld.rst.txt Commands to compile and run the ADIOS2 "Hello World" C++ example. This includes navigating to the example directory, creating a build directory, configuring with CMake, building the executable, and running it. ```bash cd Path-To-ADIOS2/examples/hello/helloWorld mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . ./adios2_hello_helloWorld ``` -------------------------------- ### Full Example Header Source: https://adios2.readthedocs.io/en/v2.10.2/tutorials/steps.html Header comment for the bpStepsWriteRead.cpp example file, including license and purpose. ```cpp /* * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * * bpStepsWriteRead.cpp Simple example of writing and reading data through ADIOS2 BP engine with ``` -------------------------------- ### Get in Deferred Mode Examples Source: https://adios2.readthedocs.io/en/v2.10.2/components/components.html Demonstrates calling Get in Deferred mode, which allows grouping of Get calls before data transport. The data pointer should not be modified until PerformPuts, EndStep, or Close. ```c++ Get(variable, data); Get(variable, data, adios2::Mode::Deferred); ``` ```c++ std::vector data; // resize memory to expected size data.resize(varBlockSize); // valid if all memory is populated // data.reserve(varBlockSize); // Gets data pointer to adios2 engine // associated with current variable metadata engine.Get(variable, data.data() ); // optionally pass data std::vector // leave resize to adios2 //engine.Get(variable, data); // "data pointer" must be the same as in Get engine.EndStep(); // "data contents" are now ready //engine.PerformPuts(); //engine.Close(); // now data pointer can be reused or modified ``` -------------------------------- ### Python Write Example Source: https://adios2.readthedocs.io/en/v2.10.2/index.html A basic example of writing data to an ADIOS2 file using the Python API. Ensure the 'adios2' Python package is installed. ```python import adios2 import numpy as np adios = adios2.adios(comm=None) # Declare IO object io = adios.declare_io("MyIO") # Open the engine engine = io.open("my_file.bp", adios2.Mode.Write) # Define and write data data = np.arange(10, dtype=np.float32) engine.write("myFloats", data) # Close the engine engine.close() ``` -------------------------------- ### Install ADIOS2 Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html Install the compiled ADIOS2 library to a specified path. Set the installation prefix using -DCMAKE_INSTALL_PREFIX before running 'make install'. ```bash cmake ../ADIOS2 -DCMAKE_INSTALL_PREFIX=/path/to/where/adios/will/be/installed make install ``` -------------------------------- ### Complete Hello World Example Source: https://adios2.readthedocs.io/en/v2.10.2/tutorials/helloWorld.html The complete C++ code for the ADIOS2 'Hello World' example, including necessary headers and function definitions for writing and reading a string. ```cpp /* * 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.BeginStep(); writer.Put(varGreeting, greeting); writer.EndStep(); 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 ``` -------------------------------- ### Build ADIOS2 Example (helloWorld) Source: https://adios2.readthedocs.io/en/v2.10.2/tutorials/downloadAndBuild.html Compile a specific ADIOS2 example like 'helloWorld'. This requires setting the ADIOS2_DIR variable to point to your ADIOS2 build directory. ```bash cd Path-To-ADIOS2/examples/hello/helloWorld mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . ``` -------------------------------- ### Compile and Run ADIOS2 SZ Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/operators.rst.txt Instructions to compile and run the ADIOS2 SZ compression example using CMake. ```bash cd Path-To-ADIOS2/examples/hello/bpOperatorSZWriter mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . ``` -------------------------------- ### Install and Load SZ Compression with Spack Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/operators.rst.txt Use Spack to install and load the SZ compression library, which is automatically detected by ADIOS. ```bash git clone https://github.com/spack/spack.git ~/spack cd ~/spack . share/spack/setup-env.sh spack install sz spack load sz ``` -------------------------------- ### ADIOS2 BP Steps Write/Read Example (C++) Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/steps.rst.txt A complete C++ example demonstrating writing and reading data in BP file format using ADIOS2, including MPI integration. This code is derived from the ADIOS2 examples. ```cpp #include #include #include #include #include int main(int argc, char* argv[]) { MPI_Init(&argc, &argv); int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); adios2::ADIOS adios(MPI_COMM_WORLD); adios2::IO io = adios.DeclareIO("MyIO"); // General const adios2::Params engineParams = { {"verbose", "1"}, {"with_metadata_tree", "true"} }; adios2::Engine writer = io.Open("BPFileStepsWriteRead.bp", adios2::Mode::Write, MPI_COMM_WORLD, engineParams); // Define variables adios2::Variable varFloats = io.DefineVariable("bpFloats", {10, 10000}, {adios2::LocalValueDim, adios2::LocalValueDim}, {adios2::ConstantDims, adios2::ConstantDims}); adios2::Variable varStep = io.DefineVariable("bpStep"); // Write data std::vector floats(100000); for (size_t i = 0; i < floats.size(); ++i) { floats[i] = static_cast(i + rank * 100000); } for (int step = 0; step < 10; ++step) { writer.Put(varFloats, floats.data()); writer.Put(varStep, static_cast(step)); writer.Advance(); } writer.Close(); // Read data adios2::Engine reader = io.Open("BPFileStepsWriteRead.bp", adios2::Mode::Read, MPI_COMM_WORLD, engineParams); std::vector readFloats; uint32_t readStep; for (int step = 0; step < 10; ++step) { reader.Get(varFloats, readFloats); reader.Get(varStep, readStep); // Process data if (readStep != static_cast(step)) { std::cerr << "Error: Step mismatch! Expected " << step << ", got " << readStep << std::endl; } } reader.Close(); MPI_Finalize(); return 0; } ``` -------------------------------- ### Run ADIOS2 Examples Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html Execute Python examples for ADIOS2 using mpirun or directly. Ensure the Python interpreter is compatible and the PYTHONPATH is set correctly. ```bash $ mpirun -n 4 python helloBPWriter.py ``` ```bash $ python helloBPWriter.py ``` -------------------------------- ### Compile and Run ADIOS2 BP Steps Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/steps.rst.txt Instructions for compiling and running the ADIOS2 C++ example for writing and reading BP files with MPI. Ensure you set the ADIOS2_DIR correctly during CMake configuration. ```bash cd Path-To-ADIOS2/examples/hello/bpStepsWriteRead mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . mpirun -np 2 ./adios2_hello_bpStepsWriteRead_mpi ``` -------------------------------- ### Python Hello World Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/helloWorld.rst.txt The Python version of the ADIOS2 "Hello World" tutorial, demonstrating similar functionality to the C++ example but using Python bindings. ```python import adios2 import sys def writer(adios, greeting): io = adios.DeclareIO("hello-world-writer") varGreeting = io.DefineVariable("Greeting", "", adios2.dims(0), adios2.dims(0), adios2.dims(0)) w_engine = io.Open("hello-world-python.bp", adios2.Mode.Write) w_engine.BeginStep() w_engine.Put(varGreeting, greeting) w_engine.EndStep() w_engine.Close() def reader(adios): io = adios.DeclareIO("hello-world-reader") r_engine = io.Open("hello-world-python.bp", adios2.Mode.Read) r_engine.BeginStep() varGreeting = io.InquireVariable("Greeting") greeting = r_engine.Get(varGreeting) r_engine.EndStep() r_engine.Close() return greeting if __name__ == "__main__": adios = adios2.ADIOS(sys.argv) greeting = "Hello World from ADIOS2 (Python)" writer(adios, greeting) message = reader(adios) print(message) adios.RemoveIO("hello-world-writer") adios.RemoveIO("hello-world-reader") ``` -------------------------------- ### Run ADIOS2 Example with SZWriter Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/operators.rst.txt Execute an ADIOS2 MPI example that utilizes SZWriter for compression. Ensure the executable is in your PATH. ```bash mpirun -np 2 ./adios2_hello_bpOperatorSZWriter_mpi 20 0.000001 ``` -------------------------------- ### Start sst_conn_tool in listening mode Source: https://adios2.readthedocs.io/en/v2.10.2/ecosystem/utilities.html Run sst_conn_tool without arguments to start it in listening mode, displaying connection parameters. ```bash bin/sst_conn_tool ``` -------------------------------- ### Compilation and Execution Instructions Source: https://adios2.readthedocs.io/en/v2.10.2/tutorials/steps.html Provides commands to compile the ADIOS2 example using CMake and run the executable with MPI. It includes steps for navigating to the example directory, creating a build directory, configuring with CMake, building the project, and executing with `mpirun`. ```bash cd Path-To-ADIOS2/examples/hello/bpStepsWriteRead mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . mpirun -np 2 ./adios2_hello_bpStepsWriteRead_mpi ``` -------------------------------- ### Compile and Run ADIOS2 MPI Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/variables.rst.txt Provides commands to compile and run an ADIOS2 MPI C++ example using CMake and mpirun. ```bash cd Path-To-ADIOS2/examples/hello/bpWriter mkdir build cd build cmake -DADIOS2_DIR=Path-To-ADIOS2/build/ .. cmake --build . mpirun -np 2 ./adios2_hello_bpWriter_mpi ``` -------------------------------- ### Python Read Example Step-by-Step Source: https://adios2.readthedocs.io/en/v2.10.2/api_python/api_python.html This example demonstrates reading data from an ADIOS2 stream step-by-step. It inspects available variables, reads scalar and array data, and retrieves attributes. This code does not require MPI. ```python import numpy as np from adios2 import Stream with Stream("cfd.bp", "r") as s: # steps comes from the stream for _ in s.steps(): # track current step print(f"Current step is {s.current_step()}") # inspect variables in current step for name, info in s.available_variables().items(): print("variable_name: " + name, end=" ") for key, value in info.items(): print("\t" + key + ": " + value, end=" ") print() if s.current_step() == 0: nproc = s.read("nproc") print(f"nproc is {nproc} of type {type(nproc)}") # read variables return a numpy array with corresponding selection physical_time = s.read("physical_time") print(f"physical_time is {physical_time} of type {type(physical_time)}") temperature = s.read("temperature") temp_unit = s.read_attribute("temperature/unit") print(f"temperature array size is {temperature.size} of shape {temperature.shape}") print(f"temperature unit is {temp_unit} of type {type(temp_unit)}") pressure = s.read("pressure") press_unit = s.read_attribute("pressure/unit") print(f"pressure unit is {press_unit} of type {type(press_unit)}") print() ``` ```bash $ python3 adios2-doc-read.py Current step is 0 variable_name: nproc AvailableStepsCount: 1 Max: 4 Min: 4 Shape: SingleValue: true Type: int64_t variable_name: physical_time AvailableStepsCount: 1 Max: 0 Min: 0 Shape: SingleValue: true Type: double variable_name: pressure AvailableStepsCount: 1 Max: 1 Min: 1 Shape: 40 SingleValue: false Type: double variable_name: temperature AvailableStepsCount: 1 Max: 0 Min: 0 Shape: 40 SingleValue: false Type: double nproc is 4 of type physical_time is 0.0 of type temperature array size is 40 of shape (40,) temperature unit is K of type pressure unit is Pa of type Current step is 1 variable_name: physical_time AvailableStepsCount: 1 Max: 0.01 Min: 0.01 Shape: SingleValue: true Type: double variable_name: pressure AvailableStepsCount: 1 Max: 1 Min: 1 Shape: 40 SingleValue: false Type: double variable_name: temperature AvailableStepsCount: 1 Max: 0 Min: 0 Shape: 40 SingleValue: false Type: double physical_time is 0.01 of type temperature array size is 40 of shape (40,) temperature unit is K of type pressure unit is Pa of type ... ``` -------------------------------- ### Build, Test, and Install ADIOS2 Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html This sequence of commands builds an optimized release version of ADIOS2, runs tests, and installs it to a specified prefix. Ensure you are in the build directory before running CMake. ```bash $ cd build $ cmake -DADIOS2_USE_Fortran=ON -DADIOS2_USE_Python=OFF -DADIOS2_USE_ZeroMQ=OFF -DADIOS2_USE_Fortran=ON -DCMAKE_INSTALL_PREFIX=/opt/adios2/2.9.0 -DCMAKE_BUILD_Type=Release ../ADIOS2 $ make -j16 $ ctest $ make install ``` -------------------------------- ### Python Binding Examples Source: https://adios2.readthedocs.io/en/v2.10.2/api_python/api_python.html List of example Python scripts demonstrating the usage of ADIOS2 bindings for various scenarios. ```APIDOC ## Python Binding Examples ### Description This section lists example Python scripts available in the ADIOS2 repository that utilize the Python bindings. ### Examples #### Simple File-Based Examples - `examples/hello/helloWorld/hello-world-bindings.py` - `examples/hello/bpReader/bpReaderHeatMap2D-bindings.py` - `examples/hello/bpWriter/bpWriter-bindings.py` #### Staging Examples (SST and DataMan Engines) - `examples/hello/sstWriter/sstWriter-bindings.py` - `examples/hello/sstReader/sstReader-bindings.py` ``` -------------------------------- ### Full Example: bpAttributeWriteRead.cpp Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/attributes.rst.txt The complete C++ source code for the bpAttributeWriteRead example, demonstrating attribute and variable read/write operations with ADIOS2 and MPI. Excludes try/catch blocks and optional MPI usage. ```cpp #include #include #include #include #include "adios2.h" void writer(adios2::ADIOS &adios, int rank, int size, std::vector &myFloats) { adios2::IO adios_out = adios.DeclareIO("WriteIO"); adios2::Engine bpWriter = adios_out.Open("fileAttributes.bp", adios2::Mode::Write); // Write string attribute std::vector strings = {"Hello", "World", "ADIOS2"}; adios2::Attribute attrStrings = adios_out.CreateAttribute("Array_of_Strings", strings.size()); attrStrings.Set(strings.data()); // Write double attribute double d = 1.0; adios2::Attribute attrDouble = adios_out.CreateAttribute("Attr_Double", 1); attrDouble.Set(&d); // Write double array attribute std::vector doubles = {1.0, 2.0, 3.0, 4.0, 5.0}; adios2::Attribute arrayOfDoubles = adios_out.CreateAttribute("Array_of_Doubles", doubles.size()); arrayOfDoubles.Set(doubles.data()); // Write float variable adios2::Variable bpFloats = adios_out.DefineVariable("bpFloats", {size * 10}, {size * 10, 1}, {"all"}); bpWriter.Put(bpFloats, myFloats.data()); bpWriter.Close(); } void reader(adios2::ADIOS &adios, int rank, int size) { adios2::IO adios_in = adios.DeclareIO("ReadIO"); adios2::Engine bpReader = adios_in.Open("fileAttributes.bp", adios2::Mode::Read); // Read string attribute adios2::Attribute arrayOfStrings = adios_in.InquireAttribute("Array_of_Strings"); if (arrayOfStrings) { std::cout << arrayOfStrings.Name() << ": "; for (const auto &value : arrayOfStrings.Data()) { std::cout << value << " "; } std::cout << "\n"; } // Read double attribute adios2::Attribute attrDouble = adios_in.InquireAttribute("Attr_Double"); if (attrDouble) { std::cout << attrDouble.Name() << ": " << attrDouble.Data()[0] << "\n"; } // Read double array attribute adios2::Attribute arrayOfDoubles = adios_in.InquireAttribute("Array_of_Doubles"); if (arrayOfDoubles) { std::cout << arrayOfDoubles.Name() << ": "; for (const auto &value : arrayOfDoubles.Data()) { std::cout << value << " "; } std::cout << "\n"; } // Read float variable adios2::Variable bpFloats = adios_in.InquireVariable("bpFloats"); const std::size_t Nx = 10; std::vector myFloats(Nx); if (bpFloats) { bpFloats.SetSelection({{Nx * rank}, {Nx}}); bpReader.Get(bpFloats, myFloats.data()); } bpReader.EndStep(); } int main(int argc, char **argv) { MPI_Init(&argc, &argv); int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); adios2::ADIOS adios("adios2.xml", MPI_COMM_WORLD); const std::size_t Nx = 10; std::vector myFloats(Nx * size); for (std::size_t i = 0; i < myFloats.size(); ++i) { myFloats[i] = static_cast(i); } writer(adios, rank, size, myFloats); reader(adios, rank, size); MPI_Finalize(); return 0; } ``` -------------------------------- ### ADIOS2 Test Output Example Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html Example output from the ADIOS2 test suite, showing the status of individual tests and an overall summary. ```text Test project /home/wfg/workspace/build Start 1: ADIOSInterfaceWriteTest.DefineVarChar1x10 1/46 Test #1: ADIOSInterfaceWriteTest.DefineVarChar1x10 ....................... Passed 0.06 sec Start 2: ADIOSInterfaceWriteTest.DefineVarShort1x10 2/46 Test #2: ADIOSInterfaceWriteTest.DefineVarShort1x10 ...................... Passed 0.04 sec Start 3: ADIOSInterfaceWriteTest.DefineVarInt1x10 3/46 Test #3: ADIOSInterfaceWriteTest.DefineVarInt1x10 ........................ Passed 0.04 sec Start 4: ADIOSInterfaceWriteTest.DefineVarLong1x10 ... 128/130 Test #128: ADIOSZfpWrapper.UnsupportedCall .......................................... Passed 0.05 sec Start 129: ADIOSZfpWrapper.MissingMandatoryParameter 129/130 Test #129: ADIOSZfpWrapper.MissingMandatoryParameter ................................ Passed 0.05 sec Start 130: */TestManyVars.DontRedefineVars/* 130/130 Test #130: */TestManyVars.DontRedefineVars/* ........................................ Passed 0.08 sec 100% tests passed, 0 tests failed out of 130 Total Test time (real) = 204.82 sec ``` -------------------------------- ### Full C++ Example Code for SZ Compression Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/operators.rst.txt The complete C++ code for the ADIOS2 SZ compression example, excluding try/catch blocks and optional MPI usage. ```cpp #include #include #include #include #include #include #ifdef ADIOS2_USE_MPI #include #endif int main(int argc, char **argv) { int rank, size; int provided; #ifdef ADIOS2_USE_MPI MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); #else rank = 0; size = 1; #endif // Number of elements per process std::size_t Nx = 100; // Compression accuracy double accuracy = 0.01; if (argc > 1) { Nx = std::stoull(argv[1]); } if (argc > 2) { accuracy = std::stod(argv[2]); } // Application variables std::vector myFloats(Nx); std::vector myDoubles(Nx); std::iota(myFloats.begin(), myFloats.end(), static_cast(rank * Nx)); std::iota(myDoubles.begin(), myDoubles.end(), static_cast(rank * Nx)); // ADIOS2 instance and IO object adios2::ADIOS adios(MPI_COMM_WORLD); adios2::IO bpIO = adios.DeclareIO("BPFile_SZ"); // Define variables adios2::Variable bpFloats = bpIO.DefineVariable( "bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); adios2::Variable bpDoubles = bpIO.DefineVariable( "bpDoubles", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); // Define SZ operator adios2::Operator op = bpIO.DefineOperator("SZCompressor", "sz"); bpFloats.AddOperation(op, {{"accuracy", std::to_string(accuracy)}}); bpDoubles.AddOperation(op, {{"accuracy", std::to_string(accuracy)}}); // Define attribute for accuracy adios2::Attribute attribute = bpIO.DefineAttribute("accuracy", accuracy); // Open file for writing adios2::Engine bpWriter = bpIO.Open("SZexample.bp", adios2::Mode::Write); for (unsigned int step = 0; step < 3; ++step) { bpWriter.BeginStep(); bpWriter.Put(bpDoubles, myDoubles.data()); bpWriter.Put(bpFloats, myFloats.data()); bpWriter.EndStep(); // Modify data for the next step std::transform(myFloats.begin(), myFloats.end(), myFloats.begin(), [&](float v) -> float { return v + 1.0f * rank; }); std::transform(myDoubles.begin(), myDoubles.end(), myDoubles.begin(), [&](double v) -> double { return v + 1.0 * rank; }); } // Close file bpWriter.Close(); // Finalize MPI #ifdef ADIOS2_USE_MPI MPI_Finalize(); #endif return 0; } ``` -------------------------------- ### Full C++ Example for SZ Compression Operator Source: https://adios2.readthedocs.io/en/v2.10.2/tutorials/operators.html Complete C++ code for the ADIOS2 SZ compression operator example. Includes necessary headers, MPI initialization, data definition, variable and operator definition, file writing, and cleanup. ```cpp /* * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * * bpOperatorSZWriter.cpp : example using operator by passing compression arguments * * Created on: Aug 3, 2018 * Author: William F Godoy godoywf@ornl.gov */ #include //std::transform #include //std::ios_base::failure #include //std::cout #include //std::iota #include //std::invalid_argument std::exception #include #include "adios2.h" #if ADIOS2_USE_MPI #include #endif void Usage() { std::cout << "\n"; std::cout << "USAGE:\n"; std::cout << "./adios2_hello_bpOperatorSZWriter Nx sz_accuracy\n"; std::cout << "\t Nx: size of float and double arrays to be compressed\n"; std::cout << "\t sz_accuracy: absolute accuracy e.g. 0.1, 0.001, to skip " "compression: -1\n\n"; } ``` -------------------------------- ### Inquire and Get Attributes Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/attributes.rst.txt Inquire specific attributes by type and name, then access their data if found. This example shows inquiring for a float attribute and an array of strings. ```cpp adios2::Attribute singleString = bpIO.InquireAttribute("Single_String"); if (singleString) { std::cout << singleString.Name() << ": " << singleString.Data()[0] << "\n"; } adios2::Attribute arrayOfStrings = bpIO.InquireAttribute("Array_of_Strings"); if (arrayOfStrings) ``` -------------------------------- ### Get in Sync Mode Example Source: https://adios2.readthedocs.io/en/v2.10.2/components/components.html Use Sync mode only when necessary, as the data pointer becomes reusable immediately after the call. This is suitable for memory-bound applications or temporary data. ```c++ Get(variable, *data, adios2::Mode::Sync); ``` ```c++ .. code-block:: c++ std::vector data; // resize memory to expected size data.resize(varBlockSize); // valid if all memory is populated // data.reserve(varBlockSize); // Gets data pointer to adios2 engine // associated with current variable metadata engine.Get(variable, data.data() ); // "data contents" are ready // "data pointer" can be reused by the application ``` -------------------------------- ### Complete C++ Hello World Example Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/helloWorld.rst.txt The complete C++ source code for the ADIOS2 "Hello World" tutorial, combining initialization, writing, and reading operations. ```cpp #include #include #include #include "adios2/api/adios2.h" 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.BeginStep(); writer.Put(varGreeting, greeting); writer.EndStep(); writer.Close(); } std::string reader(adios2::ADIOS& adios) { adios2::IO io = adios.DeclareIO("hello-world-reader"); reader.BeginStep(); adios2::Variable varGreeting = io.InquireVariable("Greeting"); adios2::Engine reader = io.Open("hello-world-cpp.bp", adios2::Mode::Read); std::string greeting; reader.BeginStep(); reader.Get(varGreeting, greeting); reader.EndStep(); reader.Close(); return greeting; } int main() { adios2::ADIOS adios; const std::string greeting("Hello World from ADIOS2"); writer(adios, greeting); std::string message = reader(adios); std::cout << message << std::endl; return 0; } ``` -------------------------------- ### Get ADIOS 2 Flags with adios2-config Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html Use `adios2-config` to retrieve C++ compiler flags and linker flags for non-CMake build systems. Specify the installation prefix when running the command. ```bash $ /path/to/install-prefix/bin/adios2-config --cxxflags ADIOS2_DIR: /path/to/install-prefix -isystem /path/to/install-prefix/include -isystem /opt/ohpc/pub/mpi/openmpi3-gnu7/3.1.0/include -pthread -std=gnu++11 ``` ```bash $ /path/to/install-prefix/bin/adios2-config --cxxlibs ADIOS2_DIR: /path/to/install-prefix -Wl,-rpath,/path/to/install-prefix/lib:/opt/ohpc/pub/mpi/openmpi3-gnu7/3.1.0/lib /path/to/install-prefix/lib/libadios2.so.2.4.0 -pthread -Wl,-rpath -Wl,/opt/ohpc/pub/mpi/openmpi3-gnu7/3.1.0/lib -Wl,--enable-new-dtags -pthread /opt/ohpc/pub/mpi/openmpi3-gnu7/3.1.0/lib/libmpi.so -Wl,-rpath-link,/path/to/install-prefix/lib ``` -------------------------------- ### Enable Specific Features with CMake Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html If a feature is OFF in the CMake configuration report, you can manually enable it and specify dependency paths. For example, to enable Blosc2, use -DADIOS2_USE_Blosc2=ON and provide the installation path. ```bash cmake ... -DADIOS2_USE_Blosc2=ON -DCMAKE_PREFIX_PATH="" ``` -------------------------------- ### C++11 Read Step-by-Step Example Source: https://adios2.readthedocs.io/en/v2.10.2/index.html Illustrates reading data step-by-step using the C++11 high-level API. This is useful for processing data as it becomes available. ```cpp #include "adios2/cxx11/ADIOS.h" int main(int argc, char **argv) { adios2::ADIOS adios(MPI_COMM_WORLD); adios2::IO io = adios2::IO("MyIO"); adios2::Engine reader = io.Open("my_file.bp", adios2::Mode::Read); for (size_t step = 0; reader.BeginStep() == adios2::StepStatus::OK; ++step) { size_t numFloats; reader.InquireVariable("myFloats", &numFloats); std::vector myFloats(numFloats); reader.Read("myFloats", myFloats.data(), numFloats); reader.EndStep(); } reader.Close(); return 0; } ``` -------------------------------- ### Retrieve Specific Data Slice with bpls Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/advanced/campaign_management.rst.txt Query and retrieve a specific subset of data from a campaign archive using `bpls`. This example demonstrates fetching a 4x4x4 block from a larger dataset, starting at a specified offset. ```bash $ bpls -l csc143/demoproject/frontier_gray-scott_100 -d gs.bp/U -s "-1,30,30,30" -c "1,4,4,4" -n 4 double gs.bp/U 10*{64, 64, 64} slice (9:9, 30:33, 30:33, 30:33) (9,30,30,30) 0.89189 0.899854 0.899854 0.891891 (9,30,31,30) 0.899851 0.908278 0.908278 0.899852 (9,30,32,30) 0.899849 0.908276 0.908277 0.899851 (9,30,33,30) 0.891885 0.899848 0.899849 0.891886 (9,31,30,30) 0.89985 0.908276 0.908276 0.899849 (9,31,31,30) 0.908274 0.916977 0.916977 0.908274 (9,31,32,30) 0.908273 0.916976 0.916976 0.908273 (9,31,33,30) 0.899844 0.908271 0.908271 0.899844 (9,32,30,30) 0.89985 0.908276 0.908275 0.899848 (9,32,31,30) 0.908274 0.916976 0.916976 0.908272 (9,32,32,30) 0.908272 0.916975 0.916974 0.908271 (9,32,33,30) 0.899844 0.90827 0.90827 0.899842 (9,33,30,30) 0.89189 0.899851 0.899851 0.891886 ``` -------------------------------- ### Writing Data from a GPU Buffer (Explicit Memory Space) Source: https://adios2.readthedocs.io/en/v2.10.2/advanced/gpu_aware.html Example of writing data from a GPU buffer where the memory space is explicitly set to GPU using `SetMemorySpace`. This overrides automatic detection for subsequent Puts or Gets. ```c++ data.SetMemorySpace(adios2::MemorySpace::GPU); for (size_t step = 0; step < nSteps; ++step) { bpWriter.BeginStep(); bpWriter.Put(data, gpuSimData, adios2::Mode::Deferred); // or Sync bpWriter.EndStep(); } ``` -------------------------------- ### Define Variable in ADIOS2 Source: https://adios2.readthedocs.io/en/v2.10.2/components/components.html Use `DefineVariable` to subscribe to data in ADIOS2. Provide a unique name, shape, start, count, and an optional flag for constant dimensions. Data is not passed at this stage; it's handled by `Put` and `Get` functions. ```cpp /** Signature */ adios2::Variable DefineVariable(const std::string name, const adios2::Dims &shape = {}, // Shape of global object const adios2::Dims &start = {}, // Where to begin writing const adios2::Dims &count = {}, // Where to end writing const bool constantDims = false); /** Example */ /** global array of floats with constant dimensions */ adios2::Variable varFloats = io.DefineVariable("bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); ``` -------------------------------- ### Configure ADIOS2 Build with CMake Source: https://adios2.readthedocs.io/en/v2.10.2/setting_up/setting_up.html Create a build directory and configure the ADIOS2 build using CMake. Enable examples by setting -DADIOS2_BUILD_EXAMPLES=ON. ```bash mkdir adios2-build && cd adios2-build cmake ../ADIOS2 -DADIOS2_BUILD_EXAMPLES=ON ``` -------------------------------- ### Read Variable Chunks with SetSelection in ADIOS2 Source: https://adios2.readthedocs.io/en/v2.10.2/_sources/tutorials/variables.rst.txt Read specific chunks of variables using SetSelection and Get. This example demonstrates reading float and integer arrays, printing contents only from rank 0. Ensure the variable exists before attempting to read. ```cpp const std::size_t Nx = 10; if (bpFloats) // means found { std::vector myFloats; // read only the chunk corresponding to our rank bpFloats.SetSelection({{Nx * rank}, {Nx}}); bpReader.Get(bpFloats, myFloats, adios2::Mode::Sync); if (rank == 0) { std::cout << "MyFloats: \n"; for (const auto number : myFloats) { std::cout << number << " "; } std::cout << "\n"; } } if (bpInts) // means not found { std::vector myInts; // read only the chunk corresponding to our rank bpInts.SetSelection({{Nx * rank}, {Nx}}); bpReader.Get(bpInts, myInts, adios2::Mode::Sync); if (rank == 0) { std::cout << "myInts: \n"; for (const auto number : myInts) { std::cout << number << " "; } std::cout << "\n"; } } ``` -------------------------------- ### Python Read Step-by-Step Example Source: https://adios2.readthedocs.io/en/v2.10.2/index.html Demonstrates reading data from an ADIOS2 file step-by-step using the Python API. This allows processing data as it arrives. ```python import adios2 import numpy as np adios = adios2.adios(comm=None) # Declare IO object io = adios.declare_io("MyIO") # Open the engine engine = io.open("my_file.bp", adios2.Mode.Read) # Read data step-by-step while True: step = engine.begin_step() if step == adios2.StepStatus.EndOfStream: break # Inquire variable and read data var_info = engine.inquire_variable("myFloats") data = engine.read("myFloats", var_info) engine.end_step() # Close the engine engine.close() ``` -------------------------------- ### Set Memory Selection Source: https://adios2.readthedocs.io/en/v2.10.2/api_full/api_full.html Sets the local start (offset) point to the memory pointer passed at Put and the memory local dimensions (count). Used for non-contiguous memory writes and reads (e.g. multidimensional ghost-cells). Currently not working for calls to Get. ```APIDOC ## adios2_set_memory_selection ### Description Set the local start (offset) point to the memory pointer passed at Put and the memory local dimensions (count). Used for non-contiguous memory writes and reads (e.g. multidimensional ghost-cells). Currently not working for calls to Get. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (0) adios2_error 0: success, see enum adios2_error for errors #### Response Example N/A ``` -------------------------------- ### adios2_set_memory_selection Source: https://adios2.readthedocs.io/en/v2.10.2/api_full/api_full.html Sets the local start (offset) point to the memory pointer passed at adios2_put and the memory local dimensions (count). Used for non-contiguous memory writes and reads (e.g. multidimensional ghost-cells). Currently Get only works for formats based on BP. ```APIDOC ## adios2_set_memory_selection ### Description Sets the local start (offset) point to the memory pointer passed at adios2_put and the memory local dimensions (count). Used for non-contiguous memory writes and reads (e.g. multidimensional ghost-cells). Currently Get only works for formats based on BP. ### Method SUBROUTINE ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (0) - **ierr** (integer) - error code #### Response Example N/A ``` -------------------------------- ### Set Memory Selection (Fortran) Source: https://adios2.readthedocs.io/en/v2.10.2/api_full/api_full.html Sets the local start offset and dimensions for memory pointers used in `adios2_put` and `adios2_get`. This is useful for non-contiguous memory access, such as multidimensional ghost-cells. Currently, `Get` only works for BP formats. Ensure all parameters are correctly specified. ```Fortran subroutine adios2_set_memory_selection(variable, ndims, memory_start_dims, memory_count_dims, ierr) ! WHERE ! variable handler type(adios2_variable), intent(in) :: variable ! no. of dimensions of the variable integer, intent(in) :: ndims ! memory start offsets integer(kind=8), dimension(:), intent(in) :: memory_start_dims ! no. of elements in each dimension integer(kind=8), dimension(:), intent(in) :: memory_count_dims ! error code integer, intent(out) :: ierr end subroutine adios2_set_memory_selection ```