diff --git a/examples/experimental/runtimeconfig/hello/CMakeLists.txt b/examples/experimental/runtimeconfig/hello/CMakeLists.txt index 794404e46d634a5c278741d97930b8f4b379cabc..28adedce753ea338bbb3d6bea81987ab84f2de09 100644 --- a/examples/experimental/runtimeconfig/hello/CMakeLists.txt +++ b/examples/experimental/runtimeconfig/hello/CMakeLists.txt @@ -9,3 +9,6 @@ else() endif() target_link_libraries(helloBPWriterXML adios2) +target_compile_definitions(helloBPWriterXML PRIVATE + -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/helloBPWriter.xml +) diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp b/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp index c367ce33d82cabd9f1d6f9b551d9289de42772c0..dc34fa06e381e70e8563142cd24bd3905c497073 100644 --- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp +++ b/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp @@ -17,6 +17,14 @@ #include <adios2.h> +#define str_helper(X) #X +#define str(X) str_helper(X) + +#ifndef DEFAULT_CONFIG +#define DEFAULT_CONFIG helloBPWriter.xml +#endif +#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG) + int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); @@ -24,6 +32,29 @@ int main(int argc, char *argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); + std::string configFile; + if (argc == 1) + { + configFile = DEFAULT_CONFIG_STR; + } + else if (argc == 2) + { + configFile = argv[1]; + } + else + { + if (rank == 0) + { + std::cerr << "Usage: " << argv[0] << " [/path/to/config.xml]" + << std::endl; + } + return 1; + } + if (rank == 0) + { + std::cout << "Using config file: " << configFile << std::endl; + } + /** Application variable */ std::vector<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; const std::size_t Nx = myFloats.size(); @@ -31,8 +62,7 @@ int main(int argc, char *argv[]) try { /** ADIOS class factory of IO class objects, DebugON is recommended */ - adios2::ADIOS adios("helloBPWriter.xml", MPI_COMM_WORLD, - adios2::DebugON); + adios2::ADIOS adios(configFile, MPI_COMM_WORLD, adios2::DebugON); /*** IO class object: settings and factory of Settings: Variables, * Parameters, Transports, and Execution: Engines */ diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp b/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp index b2bea104f58b1ec86b76351123deec6f79c61c5a..50cf93e0016aec9456e5eaec23efdd68eb041b54 100644 --- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp +++ b/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp @@ -15,8 +15,33 @@ #include <adios2.h> +#define str_helper(X) #X +#define str(X) str_helper(X) + +#ifndef DEFAULT_CONFIG +#define DEFAULT_CONFIG helloBPWriter.xml +#endif +#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG) + int main(int argc, char *argv[]) { + std::string configFile; + if (argc == 1) + { + configFile = DEFAULT_CONFIG_STR; + } + else if (argc == 2) + { + configFile = argv[1]; + } + else + { + std::cerr << "Usage: " << argv[0] << " [/path/to/config.xml]" + << std::endl; + return 1; + } + std::cout << "Using config file: " << configFile << std::endl; + /** Application variable */ std::vector<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; const std::size_t Nx = myFloats.size(); @@ -24,7 +49,7 @@ int main(int argc, char *argv[]) try { /** ADIOS class factory of IO class objects, DebugON is recommended */ - adios2::ADIOS adios("helloBPWriter.xml", adios2::DebugON); + adios2::ADIOS adios(configFile, adios2::DebugON); /*** IO class object: settings and factory of Settings: Variables, * Parameters, Transports, and Execution: Engines */