Fix thread-safety bug for user-defined epsilon in meepgeom.cpp#3208
Merged
stevengj merged 1 commit intoNanoComp:masterfrom Apr 27, 2026
Merged
Fix thread-safety bug for user-defined epsilon in meepgeom.cpp#3208stevengj merged 1 commit intoNanoComp:masterfrom
meepgeom.cpp#3208stevengj merged 1 commit intoNanoComp:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause: The
has_user_materialsflag in thegeom_epsilonconstructor (src/meepgeom.cpp:661) is initialized tofalseand only checks geometry objects' materials. It does not check the globaldefault_material, which is wherematerial_function=my_material_func(a Python callback passed at theSimulationlevel) ends up.This causes
is_thread_safe()to returntrue, soset_chi1invtakes the OMP parallel path (PLOOP_OVER_IVECS_Cwithcollapse(3)). Multiple OMP threads then concurrently callget_material_pt, which invokes the Python callback (md->user_func(...)) from non-main threads. Python's interpreter is not safe to call from arbitrary native threads, which causes the segfault intest_user_defined_material.py.Fix: Initialize
has_user_materialsby also checking whetherdefault_materialis aMATERIAL_USER. This ensures the serial code path is used when the default material is a Python callback.Validation:
test_user_defined_material.pynow passes withOMP_NUM_THREADS=1,2, and4.