stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit c09a1dc1ebb049a4f96b954098fa70fb61d72b19
parent c1e777aeae3d9a19392f619b15ed70da25dbc4a6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  9 Dec 2021 16:07:27 +0100

Refactoring of the solve_probe2 test

Diffstat:
Msrc/test_sdis_solve_probe2.c | 34+++-------------------------------
Msrc/test_sdis_utils.c | 1-
Msrc/test_sdis_utils.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/src/test_sdis_solve_probe2.c b/src/test_sdis_solve_probe2.c @@ -20,10 +20,6 @@ #include <string.h> -#ifdef SDIS_ENABLE_MPI - #include <mpi.h> -#endif - /* * The scene is composed of a solid cube whose temperature is unknown. The * convection coefficient with the surrounding fluid is null. The temperature @@ -151,7 +147,6 @@ interface_get_temperature int main(int argc, char** argv) { - struct sdis_device_create_args dev_args = SDIS_DEVICE_CREATE_ARGS_DEFAULT; struct sdis_mc T = SDIS_MC_NULL; struct sdis_mc time = SDIS_MC_NULL; struct sdis_device* dev = NULL; @@ -177,30 +172,10 @@ main(int argc, char** argv) const size_t N = 10000; size_t nreals; size_t nfails; -#ifdef SDIS_ENABLE_MPI - int mpi_thread_support; - int mpi_rank; -#endif - int is_master_process = 0; + int is_master_process; (void)argc, (void)argv; -#ifndef SDIS_ENABLE_MPI - OK(sdis_device_create(&dev_args, &dev)); - is_master_process = 1; -#else - CHK(MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_thread_support) - == MPI_SUCCESS); - CHK(mpi_thread_support >= MPI_THREAD_SERIALIZED); - dev_args.use_mpi = argc >= 2 && !strcmp(argv[1], "mpi"); - OK(sdis_device_create(&dev_args, &dev)); - if(dev_args.use_mpi) { - OK(sdis_device_get_mpi_rank(dev, &mpi_rank)); - is_master_process = mpi_rank == 0; - } else { - CHK(sdis_device_get_mpi_rank(dev, &mpi_rank) == RES_BAD_OP); - is_master_process = 1; - } -#endif + create_default_device(&argc, &argv, &is_master_process, &dev); /* Create the fluid medium */ fluid_shader.temperature = temperature_unknown; @@ -316,12 +291,9 @@ main(int argc, char** argv) if(estimator2) OK(sdis_estimator_ref_put(estimator2)); if(green) OK(sdis_green_function_ref_put(green)); OK(sdis_scene_ref_put(scn)); - OK(sdis_device_ref_put(dev)); + free_default_device(dev); CHK(mem_allocated_size() == 0); -#ifdef SDIS_ENABLE_MPI - CHK(MPI_Finalize() == MPI_SUCCESS); -#endif return 0; } diff --git a/src/test_sdis_utils.c b/src/test_sdis_utils.c @@ -425,4 +425,3 @@ check_green_serialization OK(sdis_green_function_ref_put(green2)); } - diff --git a/src/test_sdis_utils.h b/src/test_sdis_utils.h @@ -21,6 +21,11 @@ #include <rsys/double33.h> #include <rsys/mem_allocator.h> #include <stdio.h> +#include <string.h> + +#ifdef SDIS_ENABLE_MPI + #include <mpi.h> +#endif #define BOLTZMANN_CONSTANT 5.6696e-8 /* W/m^2/K^4 */ @@ -198,6 +203,66 @@ static const struct sdis_interface_shader DUMMY_INTERFACE_SHADER = { }; /******************************************************************************* + * Device creation + ******************************************************************************/ +#ifndef SDIS_ENABLE_MPI + +static INLINE void +create_default_device + (int* argc, + char*** argv, + int* is_master_process, + struct sdis_device** dev) +{ + (void)argc, (void)argv; + CHK(dev && is_master_process); + OK(sdis_device_create(&SDIS_DEVICE_CREATE_ARGS_DEFAULT, dev)); + *is_master_process = 1; +} + +#else + +static INLINE void +create_default_device + (int* pargc, + char*** pargv, + int* is_master_process, + struct sdis_device** out_dev) +{ + struct sdis_device_create_args dev_args = SDIS_DEVICE_CREATE_ARGS_DEFAULT; + struct sdis_device* dev = NULL; + int mpi_thread_support; + int mpi_rank; + CHK(pargc && pargv && is_master_process && out_dev); + + CHK(MPI_Init_thread + (pargc, pargv, MPI_THREAD_SERIALIZED, &mpi_thread_support) == MPI_SUCCESS); + CHK(mpi_thread_support >= MPI_THREAD_SERIALIZED); + + dev_args.use_mpi = *pargc >= 2 && !strcmp((*pargv)[1], "mpi"); + OK(sdis_device_create(&dev_args, &dev)); + + if(dev_args.use_mpi) { + OK(sdis_device_get_mpi_rank(dev, &mpi_rank)); + *is_master_process = mpi_rank == 0; + } else { + CHK(sdis_device_get_mpi_rank(dev, &mpi_rank) == RES_BAD_OP); + *is_master_process = 1; + } + *out_dev = dev; +} +#endif + +static INLINE void +free_default_device(struct sdis_device* dev) +{ + OK(sdis_device_ref_put(dev)); +#ifdef SDIS_ENABLE_MPI + CHK(MPI_Finalize() == MPI_SUCCESS); +#endif +} + +/******************************************************************************* * Miscellaneous ******************************************************************************/ static INLINE void