stardis-solver

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

commit 4368f3ad2cdb4bfdd41629b31a3b5900c004c041
parent 73ad03ca1d06f87965af76bf97eff3a946647d1b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  3 Jan 2022 16:14:38 +0100

Test the MPI support of the function sdis_compute_power

Diffstat:
Mcmake/CMakeLists.txt | 49++++++++++++++++++++-----------------------------
Msrc/sdis.c | 14+++++++++++++-
Msrc/sdis_realisation_Xd.h | 4++--
Msrc/sdis_solve_probe_Xd.h | 2+-
Msrc/test_sdis_compute_power.c | 82++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
5 files changed, 84 insertions(+), 67 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -199,9 +199,7 @@ if(NOT NO_TEST) register_test(${_name} ${_name}) endfunction() - new_test(test_sdis) new_test(test_sdis_camera) - new_test(test_sdis_compute_power) new_test(test_sdis_conducto_radiative) new_test(test_sdis_conducto_radiative_2d) new_test(test_sdis_contact_resistance) @@ -227,6 +225,8 @@ if(NOT NO_TEST) new_test(test_sdis_volumic_power) new_test(test_sdis_volumic_power4) + build_test(test_sdis) + build_test(test_sdis_compute_power) build_test(test_sdis_solve_medium) build_test(test_sdis_solve_medium_2d) build_test(test_sdis_solve_boundary) @@ -251,40 +251,31 @@ if(NOT NO_TEST) target_link_libraries(test_sdis_solve_probe3_2d ${MATH_LIB}) target_link_libraries(test_sdis_solve_camera Star3DUT) + set(_mpi_tests + test_sdis + test_sdis_compute_power + test_sdis_solve_medium + test_sdis_solve_medium_2d + test_sdis_solve_boundary + test_sdis_solve_boundary_flux + test_sdis_solve_probe2) + if(NOT ENABLE_MPI) - add_test(test_sdis_solve_medium test_sdis_solve_medium) - add_test(test_sdis_solve_medium_2d test_sdis_solve_medium_2d) - add_test(test_sdis_solve_probe2 test_sdis_solve_probe2) - add_test(test_sdis_solve_boundary test_sdis_solve_boundary) - add_test(test_sdis_solve_boundary_flux test_sdis_solve_boundary_flux) + foreach(_test ${_mpi_tests}) + add_test(${_test} ${_test}) + endforeach() else() set_target_properties(test_sdis PROPERTIES COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") set_target_properties(test_sdis_device PROPERTIES COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - set_target_properties(test_sdis_solve_medium PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - set_target_properties(test_sdis_solve_medium_2d PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - set_target_properties(test_sdis_solve_probe2 PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - set_target_properties(test_sdis_solve_boundary PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - set_target_properties(test_sdis_solve_boundary_flux PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - - add_test(test_sdis_solve_medium_mpi_on mpirun -n 2 test_sdis_solve_medium mpi) - add_test(test_sdis_solve_medium_2d_mpi_on mpirun -n 2 test_sdis_solve_medium_2d mpi) - add_test(test_sdis_solve_probe2_mpi_on mpirun -n 2 test_sdis_solve_probe2 mpi) - add_test(test_sdis_solve_boundary_mpi_on mpirun -n 2 test_sdis_solve_boundary mpi) - add_test(test_sdis_solve_boundary_flux_mpi_on mpirun -n 2 test_sdis_solve_boundary_flux mpi) - - add_test(test_sdis_solve_medium_no_mpi test_sdis_solve_medium) - add_test(test_sdis_solve_medium_2d_no_mpi test_sdis_solve_medium_2d) - add_test(test_sdis_solve_probe2_no_mpi test_sdis_solve_probe2) - add_test(test_sdis_solve_boundary_no_mpi test_sdis_solve_boundary) - add_test(test_sdis_solve_boundary_flux_no_mpi test_sdis_solve_boundary_flux) + foreach(_test ${_mpi_tests}) + set_target_properties(${_test} PROPERTIES + COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") + add_test(${_test}_mpi_on mpirun -n 2 ${_test} mpi) + add_test(${_test}_no_mpi ${_test}) + endforeach() endif() rcmake_copy_runtime_libraries(test_sdis_solid_random_walk_robustness) diff --git a/src/sdis.c b/src/sdis.c @@ -42,6 +42,18 @@ /******************************************************************************* * Helper functions ******************************************************************************/ +static INLINE int +check_accum_message(const enum mpi_sdis_message msg) +{ + return msg == MPI_SDIS_MSG_ACCUM_TEMP + || msg == MPI_SDIS_MSG_ACCUM_TIME + || msg == MPI_SDIS_MSG_ACCUM_FLUX_CONVECTIVE + || msg == MPI_SDIS_MSG_ACCUM_FLUX_IMPOSED + || msg == MPI_SDIS_MSG_ACCUM_FLUX_RADIATIVE + || msg == MPI_SDIS_MSG_ACCUM_FLUX_TOTAL + || msg == MPI_SDIS_MSG_ACCUM_MEAN_POWER; +} + static res_T gather_green_functions_no_mpi (struct sdis_scene* scn, @@ -488,7 +500,7 @@ gather_accumulators struct accum* per_proc_acc = NULL; size_t nprocs = 0; res_T res = RES_OK; - ASSERT(dev && per_thread_acc && acc); + ASSERT(dev && per_thread_acc && acc && check_accum_message(msg)); if(!dev->use_mpi) { /* Gather thread accumulators */ diff --git a/src/sdis_realisation_Xd.h b/src/sdis_realisation_Xd.h @@ -49,7 +49,7 @@ check_boundary_realisation_args(const struct boundary_realisation_args* args) && args->rng && args->uv[0] >= 0 && args->uv[0] <= 1 - && args->uv[1] >= 0 + && args->uv[1] >= 0 && args->uv[1] <= 1 && args->time >= 0 && args->picard_order > 0 @@ -64,7 +64,7 @@ check_boundary_flux_realisation_args && args->rng && args->uv[0] >= 0 && args->uv[0] <= 1 - && args->uv[1] >= 0 + && args->uv[1] >= 0 && args->uv[1] <= 1 && args->time >= 0 && args->picard_order > 0 diff --git a/src/sdis_solve_probe_Xd.h b/src/sdis_solve_probe_Xd.h @@ -168,7 +168,7 @@ XD(solve_probe) /* Here we go! Launch the Monte Carlo estimation */ nrealisations = compute_process_realisations_count(scn->dev, args->nrealisations); - register_paths = out_estimator && is_master_process + register_paths = out_estimator && is_master_process ? args->register_paths : SDIS_HEAT_PATH_NONE; omp_set_num_threads((int)scn->dev->nthreads); #pragma omp parallel for schedule(static) diff --git a/src/test_sdis_compute_power.c b/src/test_sdis_compute_power.c @@ -186,9 +186,10 @@ main(int argc, char** argv) size_t nverts = 0; size_t ntris = 0; double ref = 0; + int is_master_process; (void)argc, (void) argv; - OK(sdis_device_create(&SDIS_DEVICE_CREATE_ARGS_DEFAULT, &dev)); + create_default_device(&argc, &argv, &is_master_process, &dev); /* Setup the interface shader */ interf_shader.convection_coef = interface_get_convection_coef; @@ -256,38 +257,48 @@ main(int argc, char** argv) args.time_range[0] = args.time_range[1] = INF; OK(sdis_compute_power(scn, &args, &estimator)); - BA(sdis_estimator_get_power(NULL, &mpow)); - BA(sdis_estimator_get_power(estimator, NULL)); - OK(sdis_estimator_get_power(estimator, &mpow)); - OK(sdis_estimator_get_realisation_time(estimator, &time)); - - /* Check results for solid 0 */ - ref = 4.0/3.0 * PI * POWER0; - printf("Mean power of the solid0 = %g ~ %g +/- %g\n", - ref, mpow.E, mpow.SE); - check_intersection(ref, 1.e-3*ref, mpow.E, 3*mpow.SE); - OK(sdis_estimator_ref_put(estimator)); + if(!is_master_process) { + CHK(estimator == NULL); + } else { + BA(sdis_estimator_get_power(NULL, &mpow)); + BA(sdis_estimator_get_power(estimator, NULL)); + OK(sdis_estimator_get_power(estimator, &mpow)); + OK(sdis_estimator_get_realisation_time(estimator, &time)); + + /* Check results for solid 0 */ + ref = 4.0/3.0 * PI * POWER0; + printf("Mean power of the solid0 = %g ~ %g +/- %g\n", + ref, mpow.E, mpow.SE); + check_intersection(ref, 1.e-3*ref, mpow.E, 3*mpow.SE); + OK(sdis_estimator_ref_put(estimator)); + } - /* Check results for solid 1 */ args.medium = solid1; OK(sdis_compute_power(scn, &args, &estimator)); - OK(sdis_estimator_get_power(estimator, &mpow)); - ref = PI * 10 * POWER1; - printf("Mean power of the solid1 = %g ~ %g +/- %g\n", - ref, mpow.E, mpow.SE); - check_intersection(ref, 1.e-3*ref, mpow.E, 3*mpow.SE); - OK(sdis_estimator_ref_put(estimator)); - - /* Check for a not null time range */ + + if(is_master_process) { + /* Check results for solid 1 */ + OK(sdis_estimator_get_power(estimator, &mpow)); + ref = PI * 10 * POWER1; + printf("Mean power of the solid1 = %g ~ %g +/- %g\n", + ref, mpow.E, mpow.SE); + check_intersection(ref, 1.e-3*ref, mpow.E, 3*mpow.SE); + OK(sdis_estimator_ref_put(estimator)); + } + args.time_range[0] = 0; args.time_range[1] = 10; OK(sdis_compute_power(scn, &args, &estimator)); - OK(sdis_estimator_get_power(estimator, &mpow)); - ref = PI * 10 * POWER1 / 10; - printf("Mean power of the solid1 in [0, 10] s = %g ~ %g +/- %g\n", - ref, mpow.E, mpow.SE); - check_intersection(ref, 1.e-3*ref, mpow.E, 3*mpow.SE); - OK(sdis_estimator_ref_put(estimator)); + + if(is_master_process) { + /* Check for a not null time range */ + OK(sdis_estimator_get_power(estimator, &mpow)); + ref = PI * 10 * POWER1 / 10; + printf("Mean power of the solid1 in [0, 10] s = %g ~ %g +/- %g\n", + ref, mpow.E, mpow.SE); + check_intersection(ref, 1.e-3*ref, mpow.E, 3*mpow.SE); + OK(sdis_estimator_ref_put(estimator)); + } /* Reset the scene with only one solid medium */ OK(sdis_scene_ref_put(scn)); @@ -303,12 +314,14 @@ main(int argc, char** argv) /* Check non constant volumic power */ args.medium = solid0; OK(sdis_compute_power(scn, &args, &estimator)); - OK(sdis_estimator_get_power(estimator, &mpow)); - ref = 4.0/3.0*PI*POWER0 + PI*10*POWER1; - printf("Mean power of the sphere+cylinder = %g ~ %g +/- %g\n", - ref, mpow.E, mpow.SE); - check_intersection(ref, 1e-3*ref, mpow.E, 3*mpow.SE); - OK(sdis_estimator_ref_put(estimator)); + if(is_master_process) { + OK(sdis_estimator_get_power(estimator, &mpow)); + ref = 4.0/3.0*PI*POWER0 + PI*10*POWER1; + printf("Mean power of the sphere+cylinder = %g ~ %g +/- %g\n", + ref, mpow.E, mpow.SE); + check_intersection(ref, 1e-2*ref, mpow.E, 3*mpow.SE); + OK(sdis_estimator_ref_put(estimator)); + } #if 0 { @@ -326,7 +339,6 @@ main(int argc, char** argv) #endif /* Clean up memory */ - OK(sdis_device_ref_put(dev)); OK(sdis_medium_ref_put(fluid)); OK(sdis_medium_ref_put(solid0)); OK(sdis_medium_ref_put(solid1)); @@ -336,6 +348,8 @@ main(int argc, char** argv) OK(s3dut_mesh_ref_put(sphere)); OK(s3dut_mesh_ref_put(cylinder)); + free_default_device(dev); + CHK(mem_allocated_size() == 0); return 0; }