From 24f46324e0dc2f97c9f9e03f4ae8b3319ed4b49c Mon Sep 17 00:00:00 2001 From: jpekkila Date: Wed, 18 Sep 2019 19:22:15 +0300 Subject: [PATCH] Deprecated the old style of selecting a config file (was a compile-time parameter). The config file is now a runtime parameter and can be changed without recompilation. Usage: ./ac_run -s . config/astaroth.conf is selected by default if the custom path is not supplied to ac_run. --- CMakeLists.txt | 1 - src/standalone/CMakeLists.txt | 9 +-------- src/standalone/autotest.cc | 4 ++-- src/standalone/benchmark.cc | 4 ++-- src/standalone/config_loader.cc | 6 ++++-- src/standalone/config_loader.h | 2 +- src/standalone/main.cc | 18 +++++++++++++----- src/standalone/renderer.cc | 6 +++--- src/standalone/run.h | 8 ++++---- src/standalone/simulation.cc | 4 ++-- 10 files changed, 32 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e46e06..6954dad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,6 @@ option(BUILD_C_API_TEST "Builds a C program to test whether the API is c option(BUILD_MPI_TEST "Builds a C program to test whether MPI works" OFF) option(DOUBLE_PRECISION "Generates double precision code" OFF) option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON) -option(ALTER_CONF "If enabled, loads astaroth.conf from the build directory" OFF) ## Compile the Astaroth Code compiler find_package(FLEX) diff --git a/src/standalone/CMakeLists.txt b/src/standalone/CMakeLists.txt index 0a61ede..b49ba98 100644 --- a/src/standalone/CMakeLists.txt +++ b/src/standalone/CMakeLists.txt @@ -30,11 +30,4 @@ target_link_libraries(astaroth_standalone PRIVATE astaroth_core "${OpenMP_CXX_FL add_executable(ac_run main.cc) target_link_libraries(ac_run PRIVATE astaroth_standalone) - -# Define the config directory -if (ALTER_CONF) - # ASTAROTH_CONF_PATH supplied by ac_mkbuilddir.sh - target_compile_definitions(astaroth_standalone PRIVATE CONFIG_PATH="${ASTAROTH_CONF_PATH}/") -else() - target_compile_definitions(astaroth_standalone PRIVATE CONFIG_PATH="${CMAKE_SOURCE_DIR}/config/") -endif() +add_definitions(-DAC_DEFAULT_CONFIG="${CMAKE_SOURCE_DIR}/config/astaroth.conf") diff --git a/src/standalone/autotest.cc b/src/standalone/autotest.cc index f484b30..76f5a63 100644 --- a/src/standalone/autotest.cc +++ b/src/standalone/autotest.cc @@ -456,7 +456,7 @@ check_rk3(const AcMeshInfo& mesh_info) } int -run_autotest(void) +run_autotest(const char* config_path) { #if GEN_TEST_RESULT == 1 char testresult_path[256]; @@ -471,7 +471,7 @@ run_autotest(void) /* Parse configs */ AcMeshInfo config; - load_config(&config); + load_config(config_path, &config); if (STENCIL_ORDER > 6) printf("WARNING!!! If the stencil order is larger than the computational domain some " diff --git a/src/standalone/benchmark.cc b/src/standalone/benchmark.cc index 1a6a919..39a1e4d 100644 --- a/src/standalone/benchmark.cc +++ b/src/standalone/benchmark.cc @@ -41,13 +41,13 @@ #include int -run_benchmark(void) +run_benchmark(const char* config_path) { const int nn = 256; const int num_iters = 100; AcMeshInfo mesh_info; - load_config(&mesh_info); + load_config(config_path, &mesh_info); mesh_info.int_params[AC_nx] = nn; mesh_info.int_params[AC_ny] = mesh_info.int_params[AC_nx]; mesh_info.int_params[AC_nz] = mesh_info.int_params[AC_nx]; diff --git a/src/standalone/config_loader.cc b/src/standalone/config_loader.cc index 98098ff..e06e2e3 100644 --- a/src/standalone/config_loader.cc +++ b/src/standalone/config_loader.cc @@ -159,14 +159,16 @@ update_config(AcMeshInfo* config) \return 0 on success, -1 if there are potentially uninitialized values. */ int -load_config(AcMeshInfo* config) +load_config(const char* config_path, AcMeshInfo* config) { int retval = 0; + ERRCHK(config_path); + // memset reads the second parameter as a byte even though it says int in // the function declaration memset(config, (uint8_t)0xFF, sizeof(*config)); - parse_config(CONFIG_PATH "astaroth.conf", config); + parse_config(config_path, config); update_config(config); // sizeof(config) must be a multiple of 4 bytes for this to work diff --git a/src/standalone/config_loader.h b/src/standalone/config_loader.h index c1db21a..5753197 100644 --- a/src/standalone/config_loader.h +++ b/src/standalone/config_loader.h @@ -26,7 +26,7 @@ #include "astaroth.h" /** Loads data from the config file */ -int load_config(AcMeshInfo* config); +int load_config(const char* config_path, AcMeshInfo* config); /** Recalculates the portion of int parameters which get their values from nx, * ny and nz. Must be called after modifying the config struct or otherwise diff --git a/src/standalone/main.cc b/src/standalone/main.cc index 48d5fc6..24f3575 100644 --- a/src/standalone/main.cc +++ b/src/standalone/main.cc @@ -73,16 +73,24 @@ main(int argc, char* argv[]) for (int i = 0; i < argc; ++i) printf("%d: %s\n", i, argv[i]); + const size_t buf_size = 256; + char config_path[buf_size]; + (argc == 3) ? strncpy(config_path, argv[2], buf_size) + : strncpy(config_path, AC_DEFAULT_CONFIG, buf_size); + + printf("Config path: %s\n", config_path); if (argc == 1) { - return run_renderer(); + return run_renderer(config_path); } - else if (argc == 2) { + else if (argc == 2 || argc == 3) { if (strcmp(argv[1], "-t") == 0) - return run_autotest(); + return run_autotest(config_path); else if (strcmp(argv[1], "-b") == 0) - return run_benchmark(); + return run_benchmark(config_path); else if (strcmp(argv[1], "-s") == 0) - return run_simulation(); + return run_simulation(config_path); + else if (strcmp(argv[1], "-r") == 0) + return run_renderer(config_path); else WARNING("Unrecognized option"); } diff --git a/src/standalone/renderer.cc b/src/standalone/renderer.cc index be36a37..8edefd8 100644 --- a/src/standalone/renderer.cc +++ b/src/standalone/renderer.cc @@ -354,11 +354,11 @@ check_input(const float& dt) } int -run_renderer(void) +run_renderer(const char* config_path) { /* Parse configs */ AcMeshInfo mesh_info; - load_config(&mesh_info); + load_config(config_path, &mesh_info); renderer_init(mesh_info.int_params[AC_mx], mesh_info.int_params[AC_my]); AcMesh* mesh = acmesh_create(mesh_info); @@ -455,7 +455,7 @@ run_renderer(void) #else // BUILD_RT_VISUALIZATION == 0 #include "src/core/errchk.h" int -run_renderer(void) +run_renderer(const char* /*config_path*/) { WARNING("Real-time visualization module not built. Set BUILD_RT_VISUALIZATION=ON with cmake."); return 1; diff --git a/src/standalone/run.h b/src/standalone/run.h index 805ee2c..6f1b325 100644 --- a/src/standalone/run.h +++ b/src/standalone/run.h @@ -26,10 +26,10 @@ */ #pragma once -int run_autotest(void); +int run_autotest(const char* config_path); -int run_simulation(void); +int run_simulation(const char* config_path); -int run_benchmark(void); +int run_benchmark(const char* config_path); -int run_renderer(void); +int run_renderer(const char* config_path); diff --git a/src/standalone/simulation.cc b/src/standalone/simulation.cc index bdf0b18..11a991f 100644 --- a/src/standalone/simulation.cc +++ b/src/standalone/simulation.cc @@ -223,11 +223,11 @@ print_diagnostics(const int step, const AcReal dt, const AcReal t_step, FILE* di */ int -run_simulation(void) +run_simulation(const char* config_path) { /* Parse configs */ AcMeshInfo mesh_info; - load_config(&mesh_info); + load_config(config_path, &mesh_info); AcMesh* mesh = acmesh_create(mesh_info); // TODO: This need to be possible to define in astaroth.conf