htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

commit 4c5feb5052d2dcaca5319634d83f85e91958957b
parent 50bcc00519b822cf6aa8f3264ef00790dd9013c1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 14 Feb 2025 11:44:58 +0100

core : profile update for the htrdr_buffer_layout_check function

Returns an error code instead of an integer considered as a Boolean.
This defines the type of error detected. In addition, this is the
profile of other functions of this type.

The internal function that checks the arguments of the htrdr_draw_map
function has also been updated accordingly.

Diffstat:
Msrc/core/htrdr_buffer.c | 3+--
Msrc/core/htrdr_buffer.h | 31++++++++++++++++++++++++-------
Msrc/core/htrdr_draw_map.c | 34++++++++++++++++++++++++----------
3 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/src/core/htrdr_buffer.c b/src/core/htrdr_buffer.c @@ -67,9 +67,8 @@ htrdr_buffer_create res_T res = RES_OK; ASSERT(htrdr && layout && out_buf); - if(!htrdr_buffer_layout_check(layout)) { + if((res = htrdr_buffer_layout_check(layout)) != RES_OK) { htrdr_log_err(htrdr, "Invalid buffer memory layout.\n"); - res = RES_BAD_ARG; goto error; } diff --git a/src/core/htrdr_buffer.h b/src/core/htrdr_buffer.h @@ -65,15 +65,32 @@ htrdr_buffer_layout_eq && a->alignment == b->alignment; } -static INLINE int +static INLINE res_T htrdr_buffer_layout_check(const struct htrdr_buffer_layout* layout) { - return layout - && layout->width - && layout->height - && layout->elmt_size - && layout->width*layout->elmt_size <= layout->pitch - && IS_POW2(layout->alignment); + if(!layout) return RES_BAD_ARG; + + /* Invalid resolution */ + if(!layout->width || !layout->height) { + return RES_BAD_ARG; + } + + /* An element cannot be empty */ + if(!layout->elmt_size) { + return RES_BAD_ARG; + } + + /* Check pitch consistency */ + if(!layout->width*layout->elmt_size > layout->pitch) { + return RES_BAD_ARG; + } + + /* Ensure that the alignement is a power of two */ + if(!IS_POW2(layout->alignment)) { + return RES_BAD_ARG; + } + + return RES_OK; } /* Forward declarations */ diff --git a/src/core/htrdr_draw_map.c b/src/core/htrdr_draw_map.c @@ -65,20 +65,26 @@ struct tile { /******************************************************************************* * Helper functions ******************************************************************************/ -static INLINE int +static INLINE res_T check_draw_map_args(const struct htrdr_draw_map_args* args) { - return args - && args->draw_pixel - && args->spp - && htrdr_buffer_layout_check(&args->buffer_layout); + if(!args) return RES_BAD_ARG; + + /* A functor must be defined */ + if(!args->draw_pixel) return RES_BAD_ARG; + + /* The number of realisations cannot be null */ + if(!args->spp) return RES_BAD_ARG; + + /* Check buffer layout consistency */ + return htrdr_buffer_layout_check(&args->buffer_layout); } static INLINE void tile_ref_get(struct tile* tile) { ASSERT(tile); - tile_ref_get(tile); + ref_get(&tile->ref); } static INLINE void @@ -192,7 +198,8 @@ mpi_gather_tiles struct list_node* node = NULL; struct tile* tile = NULL; res_T res = RES_OK; - ASSERT(htrdr && tiles && htrdr_buffer_layout_check(buf_layout)); + ASSERT(htrdr && tiles); + ASSERT(htrdr_buffer_layout_check(buf_layout) == RES_OK); ASSERT(htrdr->mpi_rank != 0 || buf); (void)ntiles; @@ -278,7 +285,7 @@ draw_tile size_t npixels; size_t mcode; /* Morton code of tile pixel */ ASSERT(htrdr && tile_org && tile_sz && pix_sz && rng && tile); - ASSERT(check_draw_map_args(args)); + ASSERT(check_draw_map_args(args) == RES_OK); (void)tile_mcode; /* Adjust the #pixels to process them wrt a morton order */ @@ -332,9 +339,14 @@ draw_map size_t proc_ntiles = 0; ATOMIC nsolved_tiles = 0; ATOMIC res = RES_OK; - ASSERT(htrdr && check_draw_map_args(args) && work && tiles); + + /* Pre conditions */ + ASSERT(check_draw_map_args(args) == RES_OK); + ASSERT(htrdr && work && tiles); ASSERT(ntiles_x && ntiles_y && ntiles_adjusted >= ntiles_x*ntiles_y); ASSERT(pix_sz && pix_sz[0] > 0 && pix_sz[1] > 0); + + /* Avoid the "unused variable" warning */ (void)ntiles_x, (void)ntiles_y; res = ssp_rng_create(htrdr->allocator, SSP_RNG_MT19937_64, &rng_proc); @@ -501,7 +513,7 @@ htrdr_draw_map ATOMIC probe_thieves = 1; ATOMIC res = RES_OK; - ASSERT(htrdr && check_draw_map_args(args)); + ASSERT(htrdr && check_draw_map_args(args) == RES_OK); ASSERT(htrdr->mpi_rank != 0 || buf); #ifndef NDEBUG @@ -553,6 +565,8 @@ htrdr_draw_map proc_work_add_chunk(&work, mcode); } + /* On the master process, request and print the progress report, since the + * other processes have been able to start the calculation */ if(htrdr->mpi_rank == 0) { fetch_mpi_progress(htrdr, HTRDR_MPI_PROGRESS_RENDERING); print_mpi_progress(htrdr, HTRDR_MPI_PROGRESS_RENDERING);