Skip to content

Fix multiple bugs in wignerseitz.f90#61

Open
yurivict wants to merge 1 commit intogrimme-lab:mainfrom
yurivict:FreeBSD
Open

Fix multiple bugs in wignerseitz.f90#61
yurivict wants to merge 1 commit intogrimme-lab:mainfrom
yurivict:FreeBSD

Conversation

@yurivict
Copy link
Copy Markdown

The patch fixes three bugs in wignerseitz.f90:

  1. Unallocated private allocatable (tridx): Per OpenMP spec §2.15.3.3, private copies of allocatables start unallocated. The original code allocated tridx before the parallel region then listed it as private, causing undefined behavior when get_pairs tried to use the unallocated array. Fixed by allocating tridx inside the parallel region (same pattern used correctly in eeq.f90).
  2. Race condition on self%nimg_max: Multiple threads wrote self%nimg_max = max(nimg, self%nimg_max) simultaneously without synchronization. Fixed with a local variable and reduction(max:nimg_max).
  3. Missing termination in get_pairs do-loop: When all img translations happen to be equidistant (e.g., in high-symmetry crystals), the loop would exhaust all mask entries, then minloc with an all-false mask returns pos=0 (undefined per Fortran standard, gfortran returns 0), causing dist(0) out-of-bounds. Fixed with if (iws >= img) exit guard.

The original symptom was the crash in the pbc testcase.

The patch fixes three bugs in wignerseitz.f90:

 1. Unallocated private allocatable (tridx): Per OpenMP spec §2.15.3.3, private
    copies of allocatables start unallocated. The original code allocated tridx
    before the parallel region then listed it as private, causing undefined
    behavior when get_pairs tried to use the unallocated array.
    Fixed by allocating tridx inside the parallel region (same pattern used
    correctly in eeq.f90).
 2. Race condition on self%nimg_max: Multiple threads wrote self%nimg_max =
    max(nimg, self%nimg_max) simultaneously without synchronization.
    Fixed with a local variable and reduction(max:nimg_max).
 3. Missing termination in get_pairs do-loop: When all img translations
    happen to be equidistant (e.g., in high-symmetry crystals), the loop would
    exhaust all mask entries, then minloc with an all-false mask returns pos=0
    (undefined per Fortran standard, gfortran returns 0), causing
    dist(0) out-of-bounds. Fixed with if (iws >= img) exit guard.

The original symptom was the crash in the pbc testcase.
@thfroitzheim thfroitzheim requested a review from lmseidler April 14, 2026 12:41
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.68%. Comparing base (282626e) to head (dab7451).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #61       +/-   ##
===========================================
- Coverage   51.57%   30.68%   -20.90%     
===========================================
  Files          18        2       -16     
  Lines        1648      176     -1472     
  Branches      746       72      -674     
===========================================
- Hits          850       54      -796     
+ Misses        390       85      -305     
+ Partials      408       37      -371     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant