star-enclosures-2d

Extract enclosures from 2D geometry
git clone git://git.meso-star.fr/star-enclosures-2d.git
Log | Files | Refs | README | LICENSE

commit 31f5a4c86245f4c9446190fd7a2f71fe4a57014a
parent b3fa344203d933d15e6e28dd09d244b066b86474
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 20 Apr 2018 14:40:46 +0200

 BugFix: possible omp runtime error.

Race condition could lead to some threads not involved in some omp constructs.

Diffstat:
Msrc/senc2d_scene_analyze.c | 64++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/src/senc2d_scene_analyze.c b/src/senc2d_scene_analyze.c @@ -510,11 +510,11 @@ extract_connex_components if(s2d_scn) S2D(scene_ref_put(s2d_scn)); if(s2d_shp) S2D(shape_ref_put(s2d_shp)); } - if(*res != RES_OK) return; #ifndef NDEBUG /* Need to wait for all threads done to be able to check stuff */ #pragma omp barrier + if(*res != RES_OK) return; #pragma omp single { ASSERT(*component_count == @@ -1077,6 +1077,7 @@ senc2d_scene_analyze /* Used as args to have shared vars between threads in functions */ struct cc_descriptor* infinity_first_cc = NULL; res_T res = RES_OK; + res_T res2 = RES_OK; if(!scn || !out_desc) return RES_BAD_ARG; @@ -1118,15 +1119,6 @@ senc2d_scene_analyze * released / data produced by step 1 cannot be used * until next sync point */ - if(res != RES_OK) { - #pragma omp single nowait - { - log_err(scn->dev, - "%s: could not build neighbourhoods from scene.\n", FUNC_NAME); - } /* No barrier here */ - } - if(res != RES_OK) goto error_; - /* The first thread here allocates some data. * Barrier needed at the end to ensure data created before any use. */ #pragma omp single @@ -1142,10 +1134,22 @@ senc2d_scene_analyze segments_comp_initialized = 1; OK2(darray_segment_comp_resize(&segments_comp, scn->nusegs)); tmp_error: - if(tmp_res != RES_OK) res = tmp_res; + if(tmp_res != RES_OK) res2 = tmp_res; } /* Implicit barrier here: constraints on step 1 data are now met */ - if(res != RES_OK) goto error_; + + if(res != RES_OK || res2 != RES_OK) { + #pragma omp single nowait + { + if(res != RES_OK) { + log_err(scn->dev, + "%s: could not build neighbourhoods from scene.\n", FUNC_NAME); + } else { + res = res2; + } + } + goto error_; + } /* One thread releases some data before going to step 2, * the others go to step 2 without sync */ @@ -1162,17 +1166,17 @@ senc2d_scene_analyze * released / data produced by step 2 cannot be used * until next sync point */ + #pragma omp barrier + /* Constraints on step 2 data are now met */ + if(res != RES_OK) { #pragma omp single nowait { log_err(scn->dev, "%s: could not extract connex components from scene.\n", FUNC_NAME); } /* No barrier here */ + goto error_; } - if(res != RES_OK) goto error_; - - #pragma omp barrier - /* Constraints on step 2 data are now met */ /* One thread releases some data before going to step 3, * the others go to step 3 without sync */ @@ -1188,6 +1192,15 @@ senc2d_scene_analyze /* Barrier at the end of step 3: data used in step 3 can be released / * data produced by step 3 can be used */ + if(res != RES_OK) { + #pragma omp single nowait + { + log_err(scn->dev, + "%s: could not group connex components from scene.\n", FUNC_NAME); + } + goto error_; + } + /* One thread releases some data before going to step 4, * the others go to step 4 without sync */ #pragma omp single nowait @@ -1196,31 +1209,22 @@ senc2d_scene_analyze s2d_view = NULL; } /* No barrier here */ - if(res != RES_OK) { - #pragma omp single nowait - { - log_err(scn->dev, - "%s: could not group connex components from scene.\n", FUNC_NAME); - } /* No barrier here */ - } - if(res != RES_OK) goto error_; - /* Step 4: Build result */ build_result(desc, &connex_components, &segments_comp, &res); /* No barrier at the end of step 4: data used in step 4 cannot be * released / data produced by step 4 cannot be used * until next sync point */ + #pragma omp barrier + /* Constraints on step 4 data are now met */ + if(res != RES_OK) { #pragma omp single nowait { log_err(scn->dev, "%s: could not build result.\n", FUNC_NAME); - } /* No barrier here */ + } + goto error_; } - if(res != RES_OK) goto error_; - - #pragma omp barrier - /* Constraints on step 4 data are now met */ /* Some threads release data */ #pragma omp sections nowait