Bad access on CPP Solution3 with clang (macOS ARM64)
hishnash opened this issue · 3 comments
When running the CPP Solution3 on my M1 Max I get bus error
from playing around with the code it seems that I get this memory error as soon as I create a second instance of Sieve
.
I can reproduce this by modifying the main
function to create 2 Sieve
instances rather than the single one.
My C++ skills are not great so I'm not confident I can find the issue alone however happy to follow and debuting hints you might have to help figure this out.
clang --version
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Incase your interested here are the numbers on the M1 Max for CPP solution 1 and 2.
Solution 1
Passes: 4805, Time: 5.000536, Avg: 0.001041, Limit: 1000000, Count1: 78498, Count2: 78498, Valid: 1
davepl_pol;4805;5.000536;1;algorithm=base,faithful=yes,bits=1
Solution 2
Primes Benchmark (c) 2021 Dave's Garage - http://github.com/davepl/primes
-------------------------------------------------------------------------
Computing primes to 10000000 on 10 threads for 5 seconds.
Passes: 3804, Threads: 10, Time: 5.00959, Average: 0.00131693, Limit: 10000000, Counts: 664579/664579, Valid : Pass
davepl_par;3804;5.00959;10;algorithm=base,faithful=yes,bits=1
Identifying the minimum change needed to tease out this error is a great start. What code exactly are you inserting to create a second Sieve
instance, and where exactly are you inserting it? main()
in PrimeCPP/solution_3/PrimeCPP_CONSTEXPR.cpp
does not create any instances of Sieve
.
https://github.com/PlummersSoftwareLLC/Primes/blob/drag-race/PrimeCPP/solution_3/PrimeCPP_CONSTEXPR.cpp#L154
Maybe that'd help somebody reproduce the error, or give somebody an idea where you might look next.
Oh... I see the issue I had pulled the wrong version of this repo closing this issue (there seems to be another issue but its a compile time now so might be able to open PR with a fix)
:)
it compiles and runs now
Computing primes to 1000000 on 10 threads for 5 seconds.
Passes: 1790593805, Time: 5.000191, Avg: 0.000000, Limit: 1000000, Count1: 78498, Count2: 78498, Valid: 1
flo80_pol_constexpr;1790593805;5.000191;10;algorithm=base,faithful=no,bits=1
Computing primes to 1000000 on 1 thread for 5 seconds.
Passes: 246709311, Time: 5.000061, Avg: 0.000000, Limit: 1000000, Count1: 78498, Count2: 78498, Valid: 1
flo80_pol_constexpr;246709311;5.000061;1;algorithm=base,faithful=no,bits=1
not bad numbers as well :)