diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 7518c7e..63e918c 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,10 +1,3 @@ -## C++ standard -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) - -## Compile -find_package(OpenMP) +## Astaroth Utils add_library(astaroth_utils STATIC config_loader.c memory.c verification.c modelsolver.c) -target_link_libraries(astaroth_utils PRIVATE astaroth_core OpenMP::OpenMP_C) -target_compile_options(astaroth_utils PRIVATE -Wall -Wextra -Werror -Wdouble-promotion -Wfloat-conversion -Wshadow) -target_compile_options(astaroth_utils PRIVATE -mavx) +add_dependencies(astaroth_utils dsl_headers) diff --git a/src/utils/config_loader.c b/src/utils/config_loader.c index 6c6340c..2715387 100644 --- a/src/utils/config_loader.c +++ b/src/utils/config_loader.c @@ -24,15 +24,12 @@ * Detailed info. * */ -#include "config_loader.h" +#include "astaroth_utils.h" -#include -#include // UINT_MAX -#include #include // uint8_t, uint32_t -#include // print -#include // memset -//#include "src/core/math_utils.h" +#include + +#include "errchk.h" /** \brief Find the index of the keyword in names @@ -56,7 +53,7 @@ parse_config(const char* path, AcMeshInfo* config) fp = fopen(path, "r"); // For knowing which .conf file will be used printf("Config file path: \n %s \n ", path); - assert(fp != NULL); + ERRCHK_ALWAYS(fp != NULL); const size_t BUF_SIZE = 128; char keyword[BUF_SIZE]; @@ -78,7 +75,7 @@ parse_config(const char* path, AcMeshInfo* config) } AcResult -acUpdateConfig(AcMeshInfo* config) +acUpdateBuiltinParams(AcMeshInfo* config) { config->int_params[AC_mx] = config->int_params[AC_nx] + STENCIL_ORDER; ///////////// PAD TEST @@ -96,7 +93,7 @@ acUpdateConfig(AcMeshInfo* config) config->int_params[AC_nz_max] = config->int_params[AC_nz] + STENCIL_ORDER / 2; /* - // DEPRECATED: Spacing + // DEPRECATED: Spacing TODO // These do not have to be defined by empty projects any more. // These should be set only if stdderiv.h is included config->real_params[AC_inv_dsx] = (AcReal)(1.) / config->real_params[AC_dsx]; @@ -121,14 +118,14 @@ AcResult acLoadConfig(const char* config_path, AcMeshInfo* config) { int retval = AC_SUCCESS; - assert(config_path); + ERRCHK_ALWAYS(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, config); - acUpdateConfig(config); + acUpdateBuiltinParams(config); #if VERBOSE_PRINTING // Defined in astaroth.h printf("###############################################################\n"); printf("Config dimensions loaded:\n"); @@ -137,7 +134,7 @@ acLoadConfig(const char* config_path, AcMeshInfo* config) #endif // sizeof(config) must be a multiple of 4 bytes for this to work - assert(sizeof(*config) % sizeof(uint32_t) == 0); + ERRCHK_ALWAYS(sizeof(*config) % sizeof(uint32_t) == 0); for (size_t i = 0; i < sizeof(*config) / sizeof(uint32_t); ++i) { if (((uint32_t*)config)[i] == (uint32_t)0xFFFFFFFF) { fprintf(stderr, "Some config values may be uninitialized. " diff --git a/src/utils/config_loader.h b/src/utils/config_loader.h deleted file mode 100644 index 4757d2c..0000000 --- a/src/utils/config_loader.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2014-2020, Johannes Pekkila, Miikka Vaisala. - - This file is part of Astaroth. - - Astaroth is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Astaroth is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Astaroth. If not, see . -*/ - -/** - * @file - * \brief Functions for loading and updating AcMeshInfo. - * - */ -#pragma once -#include "astaroth.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** Loads data from the config file */ -AcResult acLoadConfig(const char* config_path, AcMeshInfo* config); - -/** Updates the built-in parameters based on nx, ny and nz */ -AcResult acUpdateConfig(AcMeshInfo* config); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/utils/memory.c b/src/utils/memory.c index 530b0c0..ae50872 100644 --- a/src/utils/memory.c +++ b/src/utils/memory.c @@ -16,12 +16,9 @@ You should have received a copy of the GNU General Public License along with Astaroth. If not, see . */ -#include "memory.h" +#include "astaroth_utils.h" -#include -#include - -#include "src/core/errchk.h" +#include "errchk.h" AcResult acMeshCreate(const AcMeshInfo info, AcMesh* mesh) @@ -96,7 +93,7 @@ acMeshApplyPeriodicBounds(AcMesh* mesh) const int ny_max = info.int_params[AC_ny_max]; const int nz_max = info.int_params[AC_nz_max]; -#pragma omp parallel for + // #pragma omp parallel for for (int k_dst = start.z; k_dst < end.z; ++k_dst) { for (int j_dst = start.y; j_dst < end.y; ++j_dst) { for (int i_dst = start.x; i_dst < end.x; ++i_dst) { diff --git a/src/utils/memory.h b/src/utils/memory.h deleted file mode 100644 index 73a3317..0000000 --- a/src/utils/memory.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (C) 2014-2020, Johannes Pekkila, Miikka Vaisala. - - This file is part of Astaroth. - - Astaroth is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Astaroth is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Astaroth. If not, see . -*/ - -/** - * @file - * \brief Brief info. - * - * Detailed info. - * - */ -#pragma once -#include "astaroth.h" - -#ifdef __cplusplus -extern "C" { -#endif - -AcResult acMeshCreate(const AcMeshInfo mesh_info, AcMesh* mesh); - -AcResult acMeshDestroy(AcMesh* mesh); - -AcResult acMeshSet(const AcReal value, AcMesh* mesh); - -AcResult acMeshRandomize(AcMesh* mesh); - -AcResult acMeshApplyPeriodicBounds(AcMesh* mesh); - -AcResult acMeshClear(AcMesh* mesh); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/utils/modelsolver.c b/src/utils/modelsolver.c index eb0db56..091e691 100644 --- a/src/utils/modelsolver.c +++ b/src/utils/modelsolver.c @@ -24,7 +24,7 @@ * Detailed info. * */ -#include "modelsolver.h" +#include "astaroth_utils.h" #include #include @@ -937,8 +937,8 @@ acModelIntegrateStep(AcMesh mesh, const AcReal dt) // Boundconds acMeshApplyPeriodicBounds(&mesh); -// Alpha step -#pragma omp parallel for + // Alpha step + // #pragma omp parallel for for (int k = nz_min; k < nz_max; ++k) { for (int j = ny_min; j < ny_max; ++j) { for (int i = nx_min; i < nx_max; ++i) { @@ -947,8 +947,8 @@ acModelIntegrateStep(AcMesh mesh, const AcReal dt) } } -// Beta step -#pragma omp parallel for + // Beta step + // #pragma omp parallel for for (int k = nz_min; k < nz_max; ++k) { for (int j = ny_min; j < ny_max; ++j) { for (int i = nx_min; i < nx_max; ++i) { diff --git a/src/utils/modelsolver.h b/src/utils/modelsolver.h deleted file mode 100644 index 66847a2..0000000 --- a/src/utils/modelsolver.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (C) 2014-2020, Johannes Pekkila, Miikka Vaisala. - - This file is part of Astaroth. - - Astaroth is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Astaroth is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Astaroth. If not, see . -*/ - -/** - * @file - * \brief Brief info. - * - * Detailed info. - * - */ -#pragma once -#include "astaroth.h" - -#ifdef __cplusplus -extern "C" { -#endif - -AcResult acModelIntegrateStep(AcMesh mesh, const AcReal dt); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/utils/timer_hires.h b/src/utils/timer_hires.h deleted file mode 100644 index 6d475eb..0000000 --- a/src/utils/timer_hires.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (C) 2014-2020, Johannes Pekkila, Miikka Vaisala. - - This file is part of Astaroth. - - Astaroth is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Astaroth is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Astaroth. If not, see . -*/ - -/** - @file - \brief High-resolution timer. - - Usage: - Timer t; - timer_reset(&t); - timer_diff_nsec(t); - - If there are issues, try compiling with -std=gnu11 -lrt - */ -#pragma once -#include // perror -#include - -typedef struct timespec Timer; -// Contains at least the following members: -// time_t tv_sec; -// long tv_nsec; - -static inline int -timer_reset(Timer* t) -{ - const int retval = clock_gettime(CLOCK_REALTIME, t); - if (retval == -1) - perror("clock_gettime failure"); - - return retval; -} - -static inline long -timer_diff_nsec(const Timer start) -{ - Timer end; - timer_reset(&end); - const long diff = (end.tv_sec - start.tv_sec) * 1000000000l + (end.tv_nsec - start.tv_nsec); - return diff; -} - -static inline void -timer_diff_print(const Timer t) -{ - printf("Time elapsed: %g ms\n", timer_diff_nsec(t) / 1e6); -} diff --git a/src/utils/verification.c b/src/utils/verification.c index 0d8f12c..3277660 100644 --- a/src/utils/verification.c +++ b/src/utils/verification.c @@ -1,9 +1,7 @@ -#include "verification.h" +#include "astaroth_utils.h" #include -#include - -#include "astaroth.h" +#include #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) @@ -171,7 +169,7 @@ print_error_to_screen(const Error error) } /** Returns true when successful, false if errors were found. */ -bool +AcResult acVerifyMesh(const AcMesh model, const AcMesh candidate) { printf("Errors at the point of the maximum absolute error:\n"); @@ -185,5 +183,8 @@ acVerifyMesh(const AcMesh model, const AcMesh candidate) printf("%s\n", errors_found ? "Failure. Found errors in one or more vertex buffers" : "Success. No errors found."); - return !errors_found; + if (errors_found) + return AC_FAILURE; + else + return AC_SUCCESS; } diff --git a/src/utils/verification.h b/src/utils/verification.h deleted file mode 100644 index 2e64746..0000000 --- a/src/utils/verification.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include - -#include "memory.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool acVerifyMesh(const AcMesh model, const AcMesh candidate); - -#ifdef __cplusplus -} // extern "C" -#endif