From 672917989242461fa0bd4f0d95346557ab3d6074 Mon Sep 17 00:00:00 2001 From: Chuck Atkins Date: Thu, 31 Oct 2019 11:12:25 -0400 Subject: [PATCH] Consolidate mpi/nompi bpwriter examples into single sources for each --- examples/hello/bpWriter/CMakeLists.txt | 61 +++++++------- .../hello/bpWriter/helloBPPutDeferred.cpp | 42 +++++++--- .../bpWriter/helloBPPutDeferred_nompi.cpp | 74 ---------------- examples/hello/bpWriter/helloBPSZ.cpp | 47 +++++++---- examples/hello/bpWriter/helloBPSubStreams.cpp | 41 ++++++--- .../{helloBPWriter.f90 => helloBPWriter.F90} | 13 +++ examples/hello/bpWriter/helloBPWriter.c | 20 ++++- examples/hello/bpWriter/helloBPWriter.cpp | 49 ++++++----- examples/hello/bpWriter/helloBPWriter_nompi.c | 84 ------------------- .../hello/bpWriter/helloBPWriter_nompi.cpp | 68 --------------- .../hello/bpWriter/helloBPWriter_nompi.f90 | 54 ------------ 11 files changed, 181 insertions(+), 372 deletions(-) delete mode 100644 examples/hello/bpWriter/helloBPPutDeferred_nompi.cpp rename examples/hello/bpWriter/{helloBPWriter.f90 => helloBPWriter.F90} (91%) delete mode 100644 examples/hello/bpWriter/helloBPWriter_nompi.c delete mode 100644 examples/hello/bpWriter/helloBPWriter_nompi.cpp delete mode 100644 examples/hello/bpWriter/helloBPWriter_nompi.f90 diff --git a/examples/hello/bpWriter/CMakeLists.txt b/examples/hello/bpWriter/CMakeLists.txt index 87c895216e..4d8ddd6ab9 100644 --- a/examples/hello/bpWriter/CMakeLists.txt +++ b/examples/hello/bpWriter/CMakeLists.txt @@ -3,42 +3,41 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -if(ADIOS2_HAVE_MPI) - add_executable(hello_bpWriter helloBPWriter.cpp) - target_link_libraries(hello_bpWriter adios2 MPI::MPI_C) - - add_executable(hello_bpWriter_c helloBPWriter.c) - target_link_libraries(hello_bpWriter_c adios2 MPI::MPI_C) - - if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpWriter_f helloBPWriter.f90) - target_link_libraries(hello_bpWriter_f adios2_f MPI::MPI_Fortran) - set_property(TARGET hello_bpWriter_f PROPERTY LINKER_LANGUAGE Fortran) - endif() - - add_executable(hello_bpPutDeferred helloBPPutDeferred.cpp) - target_link_libraries(hello_bpPutDeferred adios2 MPI::MPI_C) +add_executable(hello_bpWriter helloBPWriter.cpp) +target_link_libraries(hello_bpWriter adios2) + +add_executable(hello_bpWriter_c helloBPWriter.c) +target_link_libraries(hello_bpWriter_c adios2) + +add_executable(hello_bpPutDeferred helloBPPutDeferred.cpp) +target_link_libraries(hello_bpPutDeferred adios2) + +add_executable(hello_bpSubStreams helloBPSubStreams.cpp) +target_link_libraries(hello_bpSubStreams adios2) + +if(ADIOS2_HAVE_SZ) + add_executable(hello_bpSZ helloBPSZ.cpp) + target_link_libraries(hello_bpSZ adios2) +endif() - add_executable(hello_bpSubStreams helloBPSubStreams.cpp) - target_link_libraries(hello_bpSubStreams adios2 MPI::MPI_C adios2) +if(ADIOS2_HAVE_Fortran) + add_executable(hello_bpWriter_f helloBPWriter.F90) + target_link_libraries(hello_bpWriter_f adios2_f) + set_property(TARGET hello_bpWriter_f PROPERTY LINKER_LANGUAGE Fortran) +endif() + +if(ADIOS2_HAVE_MPI) + target_link_libraries(hello_bpWriter MPI::MPI_C) + target_link_libraries(hello_bpWriter_c MPI::MPI_C) + target_link_libraries(hello_bpPutDeferred MPI::MPI_C) + target_link_libraries(hello_bpSubStreams MPI::MPI_C) if(ADIOS2_HAVE_SZ) - add_executable(hello_bpSZ helloBPSZ.cpp) - target_link_libraries(hello_bpSZ adios2 MPI::MPI_C adios2) + target_link_libraries(hello_bpSZ MPI::MPI_C) endif() - -else() - add_executable(hello_bpWriter helloBPWriter_nompi.cpp) - target_link_libraries(hello_bpWriter adios2) - - add_executable(hello_bpWriter_c helloBPWriter_nompi.c) - target_link_libraries(hello_bpWriter_c adios2) if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpWriter_f helloBPWriter_nompi.f90) - target_link_libraries(hello_bpWriter_f adios2_f) + target_compile_definitions(hello_bpWriter_f PUBLIC USE_MPI=1) + target_link_libraries(hello_bpWriter_f MPI::MPI_Fortran) endif() - - add_executable(hello_bpPutDeferred helloBPPutDeferred_nompi.cpp) - target_link_libraries(hello_bpPutDeferred adios2) endif() diff --git a/examples/hello/bpWriter/helloBPPutDeferred.cpp b/examples/hello/bpWriter/helloBPPutDeferred.cpp index d3be11d908..fbe2c77703 100644 --- a/examples/hello/bpWriter/helloBPPutDeferred.cpp +++ b/examples/hello/bpWriter/helloBPPutDeferred.cpp @@ -22,18 +22,26 @@ #include //std::ios_base::failure #include //std::cout -#include #include //std::invalid_argument std::exception #include #include +#ifdef ADIOS2_HAVE_MPI +#include +#endif int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); int rank, size; + +#ifdef ADIOS2_HAVE_MPI + MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); +#else + rank = 0; + size = 1; +#endif /** Application variable */ std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -43,7 +51,11 @@ int main(int argc, char *argv[]) try { /** ADIOS class factory of IO class objects, DebugON is recommended */ +#ifdef ADIOS2_HAVE_MPI adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON); +#else + adios2::ADIOS adios(adios2::DebugON); +#endif /*** IO class object: settings and factory of Settings: Variables, * Parameters, Transports, and Execution: Engines */ @@ -73,24 +85,32 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; + std::cerr << "Invalid argument exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::ios_base::failure &e) { - std::cout << "IO System base failure exception, STOPPING PROGRAM " - "from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; + std::cerr << "IO System base failure exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; - std::cout << e.what() << "\n"; + std::cerr << "Exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/hello/bpWriter/helloBPPutDeferred_nompi.cpp b/examples/hello/bpWriter/helloBPPutDeferred_nompi.cpp deleted file mode 100644 index ab3529ebc0..0000000000 --- a/examples/hello/bpWriter/helloBPPutDeferred_nompi.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 - * variable to a BP File in non MPI mode (needs non-MPI adios2 library). - * - * Created on: Oct 25, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -#include //std::ios_base::failure -#include //std::cout -#include //std::invalid_argument std::exception -#include - -#include - -int main(int argc, char *argv[]) -{ - /** Application variable */ - std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector myInts = {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, DebugON is recommended */ - adios2::ADIOS adios(adios2::DebugON); - - /*** 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) }, { start (local) }, { - * count - * (local) }, all are constant dimensions */ - adios2::Variable bpFloats = bpIO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); - - adios2::Variable bpInts = bpIO.DefineVariable( - "bpInts", {}, {}, {Nx}, adios2::ConstantDims); - - /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpFileWriter = - bpIO.Open("myVectorDeferred.bp", adios2::Mode::Write); - - /** Put variables for buffering, template type is optional */ - bpFileWriter.Put(bpFloats, myFloats.data()); - bpFileWriter.Put(bpInts, myInts.data()); - bpFileWriter.PerformPuts(); - - /** Create bp file, engine becomes unreachable after this*/ - bpFileWriter.Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "IO System base failure exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - - return 0; -} diff --git a/examples/hello/bpWriter/helloBPSZ.cpp b/examples/hello/bpWriter/helloBPSZ.cpp index e7c5621cd3..cf3e59539d 100644 --- a/examples/hello/bpWriter/helloBPSZ.cpp +++ b/examples/hello/bpWriter/helloBPSZ.cpp @@ -10,12 +10,14 @@ #include //std::ios_base::failure #include //std::cout -#include #include //std::iota #include //std::invalid_argument std::exception #include #include +#ifdef ADIOS2_HAVE_MPI +#include +#endif void Usage() { @@ -29,13 +31,19 @@ void Usage() int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); int rank, size; + +#ifdef ADIOS2_HAVE_MPI + MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); +#else + rank = 0; + size = 1; +#endif + try { - if (argc != 3) { throw std::invalid_argument( @@ -53,7 +61,11 @@ int main(int argc, char *argv[]) std::iota(myDoubles.begin(), myDoubles.end(), 0.); /** ADIOS class factory of IO class objects, DebugON is recommended */ +#ifdef ADISO2_HAVE_MPI adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON); +#else + adios2::ADIOS adios(adios2::DebugON); +#endif /*** IO class object: settings and factory of Settings: Variables, * Parameters, Transports, and Execution: Engines */ @@ -97,27 +109,32 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; - Usage(); + std::cerr << "Invalid argument exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::ios_base::failure &e) { - std::cout << "IO System base failure exception, STOPPING PROGRAM " - "from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; - Usage(); + std::cerr << "IO System base failure exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; - std::cout << e.what() << "\n"; - Usage(); + std::cerr << "Exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/hello/bpWriter/helloBPSubStreams.cpp b/examples/hello/bpWriter/helloBPSubStreams.cpp index 27f5167c46..5a07803c95 100644 --- a/examples/hello/bpWriter/helloBPSubStreams.cpp +++ b/examples/hello/bpWriter/helloBPSubStreams.cpp @@ -10,18 +10,25 @@ #include //std::ios_base::failure #include //std::cout -#include #include //std::invalid_argument std::exception #include #include +#ifdef ADIOS2_HAVE_MPI +#include +#endif int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); int rank, size; +#ifdef ADIOS2_HAVE_MPI + MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); +#else + rank = 0; + size = 1; +#endif /** Application variable */ std::vector myFloats = {0, 1}; //, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -34,7 +41,11 @@ int main(int argc, char *argv[]) try { /** ADIOS class factory of IO class objects, DebugON is recommended */ +#ifdef ADIOS2_HAVE_MPI adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON); +#else + adios2::ADIOS adios(adios2::DebugON); +#endif /*** IO class object: settings and factory of Settings: Variables, * Parameters, Transports, and Execution: Engines */ @@ -80,24 +91,32 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; + std::cerr << "Invalid argument exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::ios_base::failure &e) { - std::cout << "IO System base failure exception, STOPPING PROGRAM " - "from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; + std::cerr << "IO System base failure exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::exception &e) { - std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; - std::cout << e.what() << "\n"; + std::cerr << "Exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; + MPI_Abort(MPI_COMM_WORLD, 1); +#endif } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/hello/bpWriter/helloBPWriter.f90 b/examples/hello/bpWriter/helloBPWriter.F90 similarity index 91% rename from examples/hello/bpWriter/helloBPWriter.f90 rename to examples/hello/bpWriter/helloBPWriter.F90 index e37ff5ef11..bc8f4ed33a 100644 --- a/examples/hello/bpWriter/helloBPWriter.f90 +++ b/examples/hello/bpWriter/helloBPWriter.F90 @@ -1,5 +1,7 @@ program helloBPWriter +#ifdef USE_MPI use mpi +#endif use adios2 implicit none @@ -13,10 +15,15 @@ program helloBPWriter type(adios2_engine) :: engine1 character(len=:), allocatable :: var1_name +#ifdef USE_MPI ! Launch MPI call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD, irank, ierr) call MPI_Comm_size(MPI_COMM_WORLD, isize, ierr) +#else + irank = 0 + isize = 1 +#endif ! Application variables inx = 10 @@ -32,7 +39,11 @@ program helloBPWriter count_dims(1) = inx ! Create adios handler passing the communicator, debug mode and error flag +#ifdef USE_MPI call adios2_init(adios, MPI_COMM_WORLD, adios2_debug_mode_on, ierr) +#else + call adios2_init(adios, adios2_debug_mode_on, ierr) +#endif ! Declare an IO process configuration inside adios call adios2_declare_io(io, adios, "ioWriter", ierr) @@ -57,6 +68,8 @@ program helloBPWriter if( allocated(myArray) ) deallocate(myArray) if( allocated(var1_name) ) deallocate(var1_name) +#ifdef USE_MPI call MPI_Finalize(ierr) +#endif end program helloBPWriter diff --git a/examples/hello/bpWriter/helloBPWriter.c b/examples/hello/bpWriter/helloBPWriter.c index 2c477e8c14..87d60fbf7e 100644 --- a/examples/hello/bpWriter/helloBPWriter.c +++ b/examples/hello/bpWriter/helloBPWriter.c @@ -7,12 +7,15 @@ * Created on: Aug 8, 2017 * Author: William F Godoy godoywf@ornl.gov */ -#include #include // printf #include // malloc, free, exit #include +#ifdef ADIOS2_HAVE_MPI +#include +#endif + void check_error(const int error) { if (error) @@ -33,10 +36,16 @@ void check_handler(const void *handler, const char *message) int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); int rank, size; + +#ifdef ADIOS2_HAVE_MPI + MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); +#else + rank = 0; + size = 1; +#endif adios2_error errio; // application input, data in heap @@ -50,7 +59,12 @@ int main(int argc, char *argv[]) myFloats[i] = (float)i; } +#ifdef ADIOS2_HAVE_MPI adios2_adios *adios = adios2_init(MPI_COMM_WORLD, adios2_debug_mode_on); +#else + adios2_adios *adios = adios2_init(adios2_debug_mode_on); +#endif + check_handler(adios, "adios"); adios2_io *io = adios2_declare_io(adios, "BPFile_Write"); @@ -86,7 +100,9 @@ int main(int argc, char *argv[]) free(myFloats); +#ifdef ADISO2_HAVE_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/hello/bpWriter/helloBPWriter.cpp b/examples/hello/bpWriter/helloBPWriter.cpp index 792a20d1bb..c6961ff760 100644 --- a/examples/hello/bpWriter/helloBPWriter.cpp +++ b/examples/hello/bpWriter/helloBPWriter.cpp @@ -11,18 +11,25 @@ #include //std::ios_base::failure #include //std::cout -#include #include //std::invalid_argument std::exception #include #include +#ifdef ADIOS2_HAVE_MPI +#include +#endif int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); int rank, size; +#ifdef ADIOS2_HAVE_MPI + MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); +#else + rank = 0; + size = 1; +#endif /** Application variable */ std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -35,7 +42,11 @@ int main(int argc, char *argv[]) try { /** ADIOS class factory of IO class objects, DebugON is recommended */ +#ifdef ADIOS2_HAVE_MPI adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON); +#else + adios2::ADIOS adios(adios2::DebugON); +#endif /*** IO class object: settings and factory of Settings: Variables, * Parameters, Transports, and Execution: Engines */ @@ -73,38 +84,32 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - if (rank == 0) - { - std::cerr - << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; - std::cerr << e.what() << "\n"; - } + std::cerr << "Invalid argument exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::ios_base::failure &e) { - if (rank == 0) - { - std::cerr << "IO System base failure exception, STOPPING PROGRAM " - "from rank " - << rank << "\n"; - std::cerr << e.what() << "\n"; - } + std::cerr << "IO System base failure exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; MPI_Abort(MPI_COMM_WORLD, 1); +#endif } catch (std::exception &e) { - if (rank == 0) - { - std::cerr << "Exception, STOPPING PROGRAM from rank " << rank - << "\n"; - std::cerr << e.what() << "\n"; - } + std::cerr << "Exception: " << e.what() << "\n"; +#ifdef ADIOS2_HAVE_MPI + std::cerr << "STOPPING PROGRAM from rank " << rank << "\n"; MPI_Abort(MPI_COMM_WORLD, 1); +#endif } +#ifdef ADIOS2_HAVE_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/hello/bpWriter/helloBPWriter_nompi.c b/examples/hello/bpWriter/helloBPWriter_nompi.c deleted file mode 100644 index 252411d4a0..0000000000 --- a/examples/hello/bpWriter/helloBPWriter_nompi.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Distributed under the OSI-approved Apache License, Version 2.0. See - * accompanying file Copyright.txt for details. - * - * helloBPWriter_nompi.c : C bindings non-MPI version of helloBPWriter.cpp - * - * Created on: Aug 8, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -#include // printf -#include // malloc, free, exit - -#include - -void check_error(const int error) -{ - if (error) - { - printf("ERROR: %d\n", error); - exit(error); - } -} - -void check_handler(const void *handler, const char *message) -{ - if (handler == NULL) - { - printf("ERROR: invalid %s handler \n", message); - exit(EXIT_FAILURE); - } -} - -int main(int argc, char *argv[]) -{ - adios2_error errio; - // application input, data in heap - const size_t Nx = 10; - float *myFloats; - myFloats = malloc(sizeof(float) * Nx); - - unsigned int i; - for (i = 0; i < Nx; ++i) - { - myFloats[i] = (float)i; - } - - adios2_adios *adios = adios2_init(adios2_debug_mode_on); - check_handler(adios, "adios"); - adios2_io *io = adios2_declare_io(adios, "BPFile_Write"); - check_handler(io, "io"); - - // dims are allocated in the stack - size_t shape[1]; - shape[0] = Nx; - - size_t start[1]; - start[0] = 0; - - size_t count[1]; - count[0] = Nx; - - adios2_variable *variable = - adios2_define_variable(io, "bpFloats", adios2_type_float, 1, shape, - start, count, adios2_constant_dims_true); - check_handler(variable, "variable"); - - adios2_engine *engine = adios2_open(io, "myVector_c.bp", adios2_mode_write); - check_handler(engine, "engine"); - - errio = adios2_put(engine, variable, myFloats, adios2_mode_deferred); - check_error(errio); - - errio = adios2_close(engine); - check_error(errio); - - // deallocate adios - errio = adios2_finalize(adios); - check_error(errio); - - free(myFloats); - - return 0; -} diff --git a/examples/hello/bpWriter/helloBPWriter_nompi.cpp b/examples/hello/bpWriter/helloBPWriter_nompi.cpp deleted file mode 100644 index 1f181f3c87..0000000000 --- a/examples/hello/bpWriter/helloBPWriter_nompi.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * Created on: Jan 9, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -#include //std::ios_base::failure -#include //std::cout -#include //std::invalid_argument std::exception -#include - -#include - -int main(int argc, char *argv[]) -{ - /** 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, DebugON is recommended */ - adios2::ADIOS adios(adios2::DebugON); - - /*** IO class object: settings and factory of Settings: Variables, - * Parameters, Transports, and Execution: Engines */ - adios2::IO bpIO = adios.DeclareIO("BPFile_N2N"); - - /** global array: name, { shape (total dimensions) }, { start (local) }, - * { count (local) }, all are constant dimensions */ - adios2::Variable bpFloats = bpIO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); - - std::string filename = "myVector_cpp.bp"; - /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpWriter = bpIO.Open(filename, adios2::Mode::Write); - - /** Write variable for buffering */ - bpWriter.Put(bpFloats, myFloats.data()); - - /** Create bp file, engine becomes unreachable after this*/ - bpWriter.Close(); - std::cout << "Wrote file " << filename - << " to disk. It can now be read by running " - "./bin/hello_bpReader.\n"; - } - catch (std::invalid_argument &e) - { - std::cerr << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cerr << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cerr << "IO System base failure exception, STOPPING PROGRAM\n"; - std::cerr << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cerr << "Exception, STOPPING PROGRAM\n"; - std::cerr << e.what() << "\n"; - } - - return 0; -} diff --git a/examples/hello/bpWriter/helloBPWriter_nompi.f90 b/examples/hello/bpWriter/helloBPWriter_nompi.f90 deleted file mode 100644 index 2043e6db7a..0000000000 --- a/examples/hello/bpWriter/helloBPWriter_nompi.f90 +++ /dev/null @@ -1,54 +0,0 @@ -program helloBPWriter - - use adios2 - - implicit none - - integer :: inx, i, ierr - - type(adios2_adios) :: adios - type(adios2_io) :: io - type(adios2_variable) :: var1 - type(adios2_engine) :: engine1 - - real, dimension(:), allocatable :: myArray - integer(kind=8), dimension(1) :: shape_dims, start_dims, count_dims - - !application variables - inx = 10 - allocate( myArray(inx) ) - - do i=1,inx - myArray(i) = i-1 - end do - - shape_dims(1) = inx - start_dims(1) = 0 - count_dims(1) = inx - - ! Initialize adios handler - call adios2_init(adios, adios2_debug_mode_on, ierr) - - ! Declare an IO configuration inside adios - call adios2_declare_io(io, adios, "ioWriter", ierr) - - ! Defines variable metadata to be written in bp file - call adios2_define_variable(var1, io, "myArray", adios2_type_real, 1, & - shape_dims, start_dims, count_dims, & - adios2_constant_dims, ierr) - - ! Open myVector_f.bp in write mode - call adios2_open(engine1, io, "myVector_f.bp", adios2_mode_write, ierr) - - ! Put myArray contents to bp buffer, based on var1 metadata - call adios2_put(engine1, var1, myArray, ierr) - - ! Closes engine1 and deallocates it, becomes unreachable - call adios2_close(engine1, ierr) - - ! Deallocates adios and calls its destructor - call adios2_finalize(adios, ierr) - - deallocate(myArray) - -end program helloBPWriter