commit 1abafd3f299066e521a7e141c5e97bc0a6a2c0e1
parent 4b598e09a00c205dfd0d7276e0296c2443c4dba6
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 5 Jul 2024 15:21:08 +0200
Fix a race condition when printing debug info
Use omp critical to avoid parallel printf calls
Diffstat:
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/senc3d_scene_analyze.c b/src/senc3d_scene_analyze.c
@@ -355,6 +355,7 @@ self_hit_filter
< darray_triangle_comp_size_get(ctx->triangles_comp));
if(log_components) {
+ #pragma omp critical
printf("Component #%u: investigating hit "
"(d=%g, n=%g,%g,%g, components: %u, %u)\n",
oc, hit->distance, SPLIT3(hit->normal),
@@ -364,6 +365,7 @@ self_hit_filter
if(hit->distance > ctx->hit_dist) {
/* No improvement */
if(log_components) {
+ #pragma omp critical
printf("Component #%u: further away (%g): reject\n",
oc, ctx->hit_dist);
}
@@ -373,6 +375,7 @@ self_hit_filter
if(hit_comp[SENC3D_FRONT] == oc || hit_comp[SENC3D_BACK] == oc) {
/* Self hit */
if(log_components) {
+ #pragma omp critical
printf("Component #%u: self hit: reject\n", oc);
}
return 1;
@@ -391,6 +394,7 @@ self_hit_filter
if(c == ctx->hit_component) {
/* Cannot change ctx->hit_component */
if(log_components) {
+ #pragma omp critical
printf("Component #%u: hit component #%u and already linked to it:"
" reject\n",
oc, c);
@@ -402,12 +406,14 @@ self_hit_filter
/* The inner component we are trying to link can only be linked to
* an outer component if it is inside */
if(log_components) {
+ #pragma omp critical
printf("Component #%u: hit outer component #%u\n", oc, c);
}
if(!is_component_inside(comp_descriptors[c],
comp_descriptors[oc], ctx))
{
if(log_components) {
+ #pragma omp critical
printf("Component #%u: not inside: reject\n", oc);
}
continue;
@@ -427,10 +433,12 @@ self_hit_filter
ctx->hit_prim = hit->prim;
if(log_components) {
if(v < ctx->current_6volume) {
+ #pragma omp critical
printf("Component #%u: currently the smaller one: "
"keep component #%u\n",
oc, ctx->hit_component);
} else {
+ #pragma omp critical
printf("Component #%u: change from inner to outer: "
"keep component #%u\n",
oc, ctx->hit_component);
@@ -438,6 +446,7 @@ self_hit_filter
}
} else {
if(log_components) {
+ #pragma omp critical
printf("Component #%u: not the smaller one: reject\n", oc);
}
continue;
@@ -449,12 +458,14 @@ self_hit_filter
/* If we've already found a valid outer component, inner components
* should not be considered anymore */
if(log_components) {
+ #pragma omp critical
printf("Component #%u: hit inner component #%u\n", oc, c);
}
if(ctx->hit_component != COMPONENT_NULL__
&& comp_descriptors[ctx->hit_component]->is_outer_border )
{
if(log_components) {
+ #pragma omp critical
printf("Component #%u: already in an outer component: reject\n",
oc);
}
@@ -468,6 +479,7 @@ self_hit_filter
ASSERT(vertices[c_z_id].pos.z >= org_z);
if(vertices[c_z_id].pos.z == org_z) {
if(log_components) {
+ #pragma omp critical
printf("Component #%u: not (even in part) above: reject\n", oc);
}
continue; /* Not above */
@@ -476,6 +488,7 @@ self_hit_filter
comp_descriptors[oc], ctx))
{
if(log_components) {
+ #pragma omp critical
printf("Component #%u: not outside: reject\n", oc);
}
continue; /* Inside */
@@ -490,12 +503,14 @@ self_hit_filter
ctx->hit_dist = 0;
ctx->hit_prim = hit->prim;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: currently the bigger one: "
"keep component #%u\n",
oc, ctx->hit_component);
}
} else {
if(log_components) {
+ #pragma omp critical
printf("Component #%u: not the bigger one: reject\n", oc);
}
continue;
@@ -512,6 +527,7 @@ self_hit_filter
ASSERT(other_id < darray_position_size_get(&ctx->scn->vertices));
if(vertices[other_id].pos.z <= org_z) {
if(log_components) {
+ #pragma omp critical
printf("Component #%u: 2 sides, not (even in part) above: reject\n",
oc);
}
@@ -523,6 +539,7 @@ self_hit_filter
ctx->hit_dist = hit->distance;
ctx->hit_prim = hit->prim;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: 2 sides with same component: "
"keep component #%u\n",
oc, ctx->hit_component);
@@ -542,6 +559,7 @@ self_hit_filter
s = f3_dot(rdir, hit_normal);
ASSERT(!isnan(s));
if(log_components) {
+ #pragma omp critical
printf("Component #%u: had to fix s (was NaN)\n", oc);
}
}
@@ -549,6 +567,7 @@ self_hit_filter
if(ctx->hit_dist == hit->distance && fabsf(ctx->s) >= fabsf(s)) {
/* Same distance with no s improvement: keep the previous hit */
if(log_components) {
+ #pragma omp critical
printf("Component #%u: not improving s (%g VS %g): reject\n",
oc, s, ctx->s);
}
@@ -562,6 +581,7 @@ self_hit_filter
double possible_z = MMAX(vertices[i1].pos.z, vertices[i2].pos.z);
if(possible_z <= org_z) {
if(log_components) {
+ #pragma omp critical
printf("Component #%u: tiny s, not (even in part) above: reject\n",
oc);
}
@@ -573,6 +593,7 @@ self_hit_filter
ctx->hit_dist = hit->distance;
ctx->hit_prim = hit->prim;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: tiny s (%g): "
"keep but don't know the component\n",
oc, s);
@@ -591,6 +612,7 @@ self_hit_filter
ASSERT(other_id < darray_position_size_get(&ctx->scn->vertices));
if(vertices[other_id].pos.z <= org_z) {
if(log_components) {
+ #pragma omp critical
printf("Component #%u: standard s, not (even in part) above: reject\n",
oc);
}
@@ -602,6 +624,7 @@ self_hit_filter
ctx->hit_dist = hit->distance;
ctx->hit_prim = hit->prim;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: standard s, (%g): keep component #%u\n",
oc, s, ctx->hit_component);
}
@@ -1255,6 +1278,7 @@ group_connex_components
ASSERT(id <= ENCLOSURE_MAX__);
cc->enclosure_id = (enclosure_id_t)id;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: is outer, not processed\n", c);
}
continue;
@@ -1282,6 +1306,7 @@ group_connex_components
cc->cc_group_root = CC_GROUP_ROOT_INFINITE;
cc->enclosure_id = 0;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: is part of enclosure #0\n", c);
}
continue;
@@ -1296,6 +1321,7 @@ group_connex_components
* issues (and r==0 is an error) */
r = hit.distance * (1 + FLT_EPSILON) + FLT_EPSILON;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: starting search for components (R=%g) from %g %g %g\n",
c, r, SPLIT3(origin));
}
@@ -1312,6 +1338,7 @@ group_connex_components
cc->cc_group_root = CC_GROUP_ROOT_INFINITE;
cc->enclosure_id = 0;
if(log_components) {
+ #pragma omp critical
printf("Component #%u: is part of enclosure #0\n", c);
}
continue;
@@ -1330,6 +1357,7 @@ group_connex_components
cc->cc_group_root = ctx1.c.ctx1.hit_component;
ASSERT(cc->cc_group_root < cc_count);
if(log_components) {
+ #pragma omp critical
printf("Component #%u: linked to component #%u\n", c, cc->cc_group_root);
}
}