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 <path/to/config/file/relative/to/ac_run/path>. config/astaroth.conf is selected by default if the custom path is not supplied to ac_run.

This commit is contained in:
jpekkila
2019-09-18 19:22:15 +03:00
parent 3bb6ca1712
commit 24f46324e0
10 changed files with 32 additions and 30 deletions

View File

@@ -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(BUILD_MPI_TEST "Builds a C program to test whether MPI works" OFF)
option(DOUBLE_PRECISION "Generates double precision code" OFF) option(DOUBLE_PRECISION "Generates double precision code" OFF)
option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON) 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 ## Compile the Astaroth Code compiler
find_package(FLEX) find_package(FLEX)

View File

@@ -30,11 +30,4 @@ target_link_libraries(astaroth_standalone PRIVATE astaroth_core "${OpenMP_CXX_FL
add_executable(ac_run main.cc) add_executable(ac_run main.cc)
target_link_libraries(ac_run PRIVATE astaroth_standalone) target_link_libraries(ac_run PRIVATE astaroth_standalone)
add_definitions(-DAC_DEFAULT_CONFIG="${CMAKE_SOURCE_DIR}/config/astaroth.conf")
# 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()

View File

@@ -456,7 +456,7 @@ check_rk3(const AcMeshInfo& mesh_info)
} }
int int
run_autotest(void) run_autotest(const char* config_path)
{ {
#if GEN_TEST_RESULT == 1 #if GEN_TEST_RESULT == 1
char testresult_path[256]; char testresult_path[256];
@@ -471,7 +471,7 @@ run_autotest(void)
/* Parse configs */ /* Parse configs */
AcMeshInfo config; AcMeshInfo config;
load_config(&config); load_config(config_path, &config);
if (STENCIL_ORDER > 6) if (STENCIL_ORDER > 6)
printf("WARNING!!! If the stencil order is larger than the computational domain some " printf("WARNING!!! If the stencil order is larger than the computational domain some "

View File

@@ -41,13 +41,13 @@
#include <vector> #include <vector>
int int
run_benchmark(void) run_benchmark(const char* config_path)
{ {
const int nn = 256; const int nn = 256;
const int num_iters = 100; const int num_iters = 100;
AcMeshInfo mesh_info; 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_nx] = nn;
mesh_info.int_params[AC_ny] = mesh_info.int_params[AC_nx]; mesh_info.int_params[AC_ny] = mesh_info.int_params[AC_nx];
mesh_info.int_params[AC_nz] = mesh_info.int_params[AC_nx]; mesh_info.int_params[AC_nz] = mesh_info.int_params[AC_nx];

View File

@@ -159,14 +159,16 @@ update_config(AcMeshInfo* config)
\return 0 on success, -1 if there are potentially uninitialized values. \return 0 on success, -1 if there are potentially uninitialized values.
*/ */
int int
load_config(AcMeshInfo* config) load_config(const char* config_path, AcMeshInfo* config)
{ {
int retval = 0; int retval = 0;
ERRCHK(config_path);
// memset reads the second parameter as a byte even though it says int in // memset reads the second parameter as a byte even though it says int in
// the function declaration // the function declaration
memset(config, (uint8_t)0xFF, sizeof(*config)); memset(config, (uint8_t)0xFF, sizeof(*config));
parse_config(CONFIG_PATH "astaroth.conf", config); parse_config(config_path, config);
update_config(config); update_config(config);
// sizeof(config) must be a multiple of 4 bytes for this to work // sizeof(config) must be a multiple of 4 bytes for this to work

View File

@@ -26,7 +26,7 @@
#include "astaroth.h" #include "astaroth.h"
/** Loads data from the config file */ /** 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, /** 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 * ny and nz. Must be called after modifying the config struct or otherwise

View File

@@ -73,16 +73,24 @@ main(int argc, char* argv[])
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
printf("%d: %s\n", i, argv[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) { 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) if (strcmp(argv[1], "-t") == 0)
return run_autotest(); return run_autotest(config_path);
else if (strcmp(argv[1], "-b") == 0) else if (strcmp(argv[1], "-b") == 0)
return run_benchmark(); return run_benchmark(config_path);
else if (strcmp(argv[1], "-s") == 0) 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 else
WARNING("Unrecognized option"); WARNING("Unrecognized option");
} }

View File

@@ -354,11 +354,11 @@ check_input(const float& dt)
} }
int int
run_renderer(void) run_renderer(const char* config_path)
{ {
/* Parse configs */ /* Parse configs */
AcMeshInfo mesh_info; 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]); renderer_init(mesh_info.int_params[AC_mx], mesh_info.int_params[AC_my]);
AcMesh* mesh = acmesh_create(mesh_info); AcMesh* mesh = acmesh_create(mesh_info);
@@ -455,7 +455,7 @@ run_renderer(void)
#else // BUILD_RT_VISUALIZATION == 0 #else // BUILD_RT_VISUALIZATION == 0
#include "src/core/errchk.h" #include "src/core/errchk.h"
int int
run_renderer(void) run_renderer(const char* /*config_path*/)
{ {
WARNING("Real-time visualization module not built. Set BUILD_RT_VISUALIZATION=ON with cmake."); WARNING("Real-time visualization module not built. Set BUILD_RT_VISUALIZATION=ON with cmake.");
return 1; return 1;

View File

@@ -26,10 +26,10 @@
*/ */
#pragma once #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);

View File

@@ -223,11 +223,11 @@ print_diagnostics(const int step, const AcReal dt, const AcReal t_step, FILE* di
*/ */
int int
run_simulation(void) run_simulation(const char* config_path)
{ {
/* Parse configs */ /* Parse configs */
AcMeshInfo mesh_info; AcMeshInfo mesh_info;
load_config(&mesh_info); load_config(config_path, &mesh_info);
AcMesh* mesh = acmesh_create(mesh_info); AcMesh* mesh = acmesh_create(mesh_info);
// TODO: This need to be possible to define in astaroth.conf // TODO: This need to be possible to define in astaroth.conf