Skip to content

Commit

Permalink
Merge pull request #1849 from chuckatkins/combine-nompi-examples
Browse files Browse the repository at this point in the history
Consolidate mpi/nompi bpwriter examples into single sources for each
  • Loading branch information
Chuck Atkins authored Oct 31, 2019
2 parents bb32963 + 6729179 commit 4bf7f97
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 372 deletions.
61 changes: 30 additions & 31 deletions examples/hello/bpWriter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
42 changes: 31 additions & 11 deletions examples/hello/bpWriter/helloBPPutDeferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@

#include <ios> //std::ios_base::failure
#include <iostream> //std::cout
#include <mpi.h>
#include <stdexcept> //std::invalid_argument std::exception
#include <vector>

#include <adios2.h>
#ifdef ADIOS2_HAVE_MPI
#include <mpi.h>
#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<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}
74 changes: 0 additions & 74 deletions examples/hello/bpWriter/helloBPPutDeferred_nompi.cpp

This file was deleted.

47 changes: 32 additions & 15 deletions examples/hello/bpWriter/helloBPSZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

#include <ios> //std::ios_base::failure
#include <iostream> //std::cout
#include <mpi.h>
#include <numeric> //std::iota
#include <stdexcept> //std::invalid_argument std::exception
#include <vector>

#include <adios2.h>
#ifdef ADIOS2_HAVE_MPI
#include <mpi.h>
#endif

void Usage()
{
Expand All @@ -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(
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit 4bf7f97

Please sign in to comment.