Skip to content

Add --enable-openmp to exercise ctlgeom thread-safety in test suite#79

Merged
stevengj merged 1 commit into
NanoComp:masterfrom
Luochenghuang:openmp-tests
May 18, 2026
Merged

Add --enable-openmp to exercise ctlgeom thread-safety in test suite#79
stevengj merged 1 commit into
NanoComp:masterfrom
Luochenghuang:openmp-tests

Conversation

@Luochenghuang
Copy link
Copy Markdown
Contributor

@Luochenghuang Luochenghuang commented May 16, 2026

Closes #78.

Summary

Adds an opt-in --enable-openmp configure flag and wraps the random-point / random-segment loops in utils/geomtst.c and utils/test-prism.c with #pragma omp parallel for, so the ctlgeom entry points they exercise are hit from multiple threads concurrently. The point is to give the test suite teeth against thread-safety regressions in libctlgeom.

Changes

  • m4/ax_openmp.m4: adds the standard AX_OPENMP macro from the autoconf-archive.
  • configure.ac: new --enable-openmp flag (default off). When enabled, runs AX_OPENMP and appends OPENMP_CFLAGS to CFLAGS/LDFLAGS.
  • utils/geomtst.c: random_object_and_lattice() now takes an int perturb_lattice flag (per the issue, so it doesn't race on the global geometry_lattice when called from threads). main() perturbs the lattice once in serial under #ifdef _OPENMP and runs the two test loops with #pragma omp parallel for.
  • utils/test-prism.c: #pragma omp parallel for ... reduction(+:...) on the three random-input loops (test_point_inclusion, test_normal_to_object, test_line_segment_intersection); file-log writes guarded with #pragma omp critical; getenv hoisted out of the inner loop.

No changes to utils/geom.c or utils/geom.scm. Actual thread-safety fixes belong in their own PR (see #75 and follow-ups).

Adds m4/ax_openmp.m4 (autoconf-archive AX_OPENMP) and a --enable-openmp
configure flag that appends OPENMP_CFLAGS to CFLAGS/LDFLAGS.

geomtst.c and test-prism.c are wrapped with #pragma omp parallel for on
the random-point/random-segment test loops so the ctlgeom entry points
they exercise are hammered from multiple threads concurrently.

random_object_and_lattice() in geomtst.c now takes a perturb_lattice
flag; the parallel loops call it with 0 so they don't race on the
global geometry_lattice (perturbed once in serial up-front instead).

test-prism's file writes are guarded with #pragma omp critical, and
counters use reduction(+:...).

Default ./configure leaves OpenMP off and make check is unchanged.
With --enable-openmp, make check will surface races in ctlgeom
(notably reinit_prism via geom_fix_object_ptr).
@stevengj
Copy link
Copy Markdown
Collaborator

I assume the OMP tests currently fail due to the lack of thread safety?

@Luochenghuang
Copy link
Copy Markdown
Contributor Author

Luochenghuang commented May 16, 2026

Yes. With --enable-openmp, test-prism reliably aborts with free(): double free detected in tcache 2. I believe it's reinit_prism racing on free+malloc of the prism's internal arrays when two threads call point_in_objectp(p, the_prism) concurrently.

@stevengj
Copy link
Copy Markdown
Collaborator

Okay, I'll merge this now, and when we have a patch that fixes the thread safety we can enable the tests during CI in that PR.

@stevengj stevengj merged commit 40488c1 into NanoComp:master May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test thread saftety to libctl tests

2 participants