Primecount fails at runtime with GCC-12 & MinGW/MSYS2 (Windows 10)
kimwalisch opened this issue · 2 comments
This seems to be an OpenMP issue of GCC-12 & MinGW/MSYS2. I have debugged the issue and found that the error occurs on exit of an omp parallel
section in P2.cpp:
std::cout << "P2_OpenMP()5" << std::endl;
#pragma omp parallel num_threads(threads) reduction(+:sum)
{
std::cout << "P2_OpenMP()6" << std::endl;
int64_t low, high;
while (loadBalancer.get_work(low, high))
sum += P2_thread(x, y, low, high);
std::cout << "P2_OpenMP()7" << std::endl;
}
std::cout << "P2_OpenMP()8" << std::endl;
cd primecount/build
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
./primecount.exe 20000 --P2
...
P2_OpenMP()5
P2_OpenMP()6
P2_OpenMP()7
Since P2_OpenMP()8
is not printed the exit clearly happens when the OpenMP parallel section finishes, so this seems to be a MinGW OpenMP issue. Note that primesieve's test suite completes successfully using the lastest GCC-12 & MinGW/MSYS2, hence this does not seem to be a libprimesieve issue. I have also tried running an older primecount release i.e. v6.4 from 2020 and it causes the same issue, hence the issue is not caused by a bug that I have recently introduced.
GDB stack trace of this issue:
$ gdb ./primecount.exe
(gdb) run 20000 --P2
Starting program: C:\msys64\home\kimwa\primecount\build\primecount.exe 20000 --P2
[New Thread 14820.0x39cc]
[New Thread 14820.0x11d4]
[New Thread 14820.0x3544]
warning: Critical error detected c0000374
Thread 1 received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffc9c88f1d3 in ntdll!RtlIsZeroMemory () from C:\Windows\SYSTEM32\ntdll.dll
(gdb) where
#0 0x00007ffc9c88f1d3 in ntdll!RtlIsZeroMemory ()
from C:\Windows\SYSTEM32\ntdll.dll
#1 0x00007ffc9c897f92 in ntdll!RtlpNtSetValueKey ()
from C:\Windows\SYSTEM32\ntdll.dll
#2 0x00007ffc9c89827a in ntdll!RtlpNtSetValueKey ()
from C:\Windows\SYSTEM32\ntdll.dll
#3 0x00007ffc9c89df01 in ntdll!RtlpNtSetValueKey ()
from C:\Windows\SYSTEM32\ntdll.dll
#4 0x00007ffc9c7b5bf0 in ntdll!RtlGetCurrentServiceSessionId ()
from C:\Windows\SYSTEM32\ntdll.dll
#5 0x00007ffc9c7b47b1 in ntdll!RtlFreeHeap ()
from C:\Windows\SYSTEM32\ntdll.dll
#6 0x00007ffc9bd39c9c in msvcrt!free () from C:\Windows\System32\msvcrt.dll
#7 0x00007ff616cfc797 in (anonymous namespace)::P2_OpenMP<long long> (
x=20000, y=47, threads=1, is_print=false)
at C:/msys64/home/kimwa/primecount/src/P2.cpp:116
#8 0x00007ff616cfc161 in primecount::P2 (x=20000, y=47, threads=16,
is_print=false) at C:/msys64/home/kimwa/primecount/src/P2.cpp:143
#9 0x00007ff616cf5ff3 in primecount::P2 (x=20000, threads=16)
at C:/msys64/home/kimwa/primecount/src/app/main.cpp:234
#10 0x00007ff616cf7149 in main (argc=3, argv=0x1ead8ce1d40)
at C:/msys64/home/kimwa/primecount/src/app/main.cpp:393
I was to able to fix this issue by upgrading MSYS2/MinGW by running the command pacman -Syu
multiple times from the MSYS2 command-line. Then I also had to recompile primecount.