From 67344d83b09376ff3f974563a0c93aaa4e427d62 Mon Sep 17 00:00:00 2001 From: Rutger van Bergen Date: Thu, 7 Nov 2024 12:50:32 +0100 Subject: [PATCH] Combine array and mask approaches in one solution_2 --- PrimeCPP/solution_2/.gitignore | 3 ++- PrimeCPP/solution_2/Dockerfile | 14 +++++++++---- .../PrimeCPP_array.cpp} | 15 +++++++++----- .../{PrimeCPP_PAR.cpp => PrimeCPP_mask.cpp} | 19 +++++++++++++----- PrimeCPP/solution_2/benchmark.sh | 9 +++++++++ PrimeCPP/solution_2/primes_par.exe | Bin 62304 -> 0 bytes PrimeCPP/solution_2/run.cmd | 11 ++++++++-- PrimeCPP/solution_2/run.sh | 15 ++++++++++++-- PrimeCPP/solution_2a/Dockerfile | 13 ------------ PrimeCPP/solution_2a/run.cmd | 2 -- PrimeCPP/solution_2a/run.sh | 6 ------ 11 files changed, 67 insertions(+), 40 deletions(-) rename PrimeCPP/{solution_2a/PrimeCPP_PAR.cpp => solution_2/PrimeCPP_array.cpp} (96%) rename PrimeCPP/solution_2/{PrimeCPP_PAR.cpp => PrimeCPP_mask.cpp} (96%) create mode 100755 PrimeCPP/solution_2/benchmark.sh delete mode 100755 PrimeCPP/solution_2/primes_par.exe delete mode 100644 PrimeCPP/solution_2a/Dockerfile delete mode 100644 PrimeCPP/solution_2a/run.cmd delete mode 100755 PrimeCPP/solution_2a/run.sh diff --git a/PrimeCPP/solution_2/.gitignore b/PrimeCPP/solution_2/.gitignore index 5b1fd1a1c..2cafdba9f 100644 --- a/PrimeCPP/solution_2/.gitignore +++ b/PrimeCPP/solution_2/.gitignore @@ -1 +1,2 @@ -.vscore/** \ No newline at end of file +.vscore/** +*.exe \ No newline at end of file diff --git a/PrimeCPP/solution_2/Dockerfile b/PrimeCPP/solution_2/Dockerfile index f6c0ceb2f..d56ddc06a 100644 --- a/PrimeCPP/solution_2/Dockerfile +++ b/PrimeCPP/solution_2/Dockerfile @@ -1,13 +1,19 @@ FROM ubuntu:22.04 AS build RUN apt-get update -qq \ - && apt-get install -y clang + && apt-get install -y bash clang WORKDIR /opt/app COPY *.cpp . -RUN clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_PAR.cpp -oprimes_par +RUN clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_array.cpp -oprimes_array +RUN clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_mask.cpp -oprimes_mask FROM ubuntu:22.04 -COPY --from=build /opt/app/primes_par /usr/local/bin -ENTRYPOINT [ "primes_par", "-l", "1000000" ] \ No newline at end of file +COPY --from=build /opt/app/primes_array /opt/app/primes_mask /opt/app/ + +WORKDIR /opt/app +COPY benchmark.sh . + +ENTRYPOINT [ "./benchmark.sh"] +CMD ["both", "-l", "1000000" ] \ No newline at end of file diff --git a/PrimeCPP/solution_2a/PrimeCPP_PAR.cpp b/PrimeCPP/solution_2/PrimeCPP_array.cpp similarity index 96% rename from PrimeCPP/solution_2a/PrimeCPP_PAR.cpp rename to PrimeCPP/solution_2/PrimeCPP_array.cpp index 017e8220a..4edd24af0 100644 --- a/PrimeCPP/solution_2a/PrimeCPP_PAR.cpp +++ b/PrimeCPP/solution_2/PrimeCPP_array.cpp @@ -25,7 +25,6 @@ const uint64_t DEFAULT_UPPER_LIMIT = 10'000'000LLU; class BitArray { uint8_t *array; - size_t arrSize; size_t logicalSize; static constexpr size_t arraySize(size_t size) @@ -41,9 +40,9 @@ class BitArray { public: explicit BitArray(size_t size) : logicalSize(size) { - arrSize = (size + 1) / 2; // Only store bits for odd numbers + auto arrSize = (size + 1) / 2; // Only store bits for odd numbers array = new uint8_t[arraySize(arrSize)]; - fill_n(array, arrSize, 0x00); + std::memset(array, 0x00, arraySize(arrSize)); } ~BitArray() { delete[] array; } @@ -103,14 +102,20 @@ class prime_sieve while (factor <= q) { // Find the next prime number - for (NULL; factor <= q; factor += 2) + for (; factor <= q; factor += 2) + { if (Bits.get(factor)) + { break; + } + } // Mark multiples of the prime number as not prime uint64_t start = factor * factor; for (uint64_t num = start; num <= Bits.size(); num += factor * 2) + { Bits.set(num); + } factor += 2; } @@ -201,7 +206,7 @@ class prime_sieve // Following 2 lines added by rbergen to conform to drag race output format cout << "\n"; - cout << "davepl_par;" << passes << ";" << duration << ";" << threads << ";algorithm=base,faithful=yes,bits=1\n"; + cout << "davepl_array;" << passes << ";" << duration << ";" << threads << ";algorithm=base,faithful=yes,bits=1\n"; } }; diff --git a/PrimeCPP/solution_2/PrimeCPP_PAR.cpp b/PrimeCPP/solution_2/PrimeCPP_mask.cpp similarity index 96% rename from PrimeCPP/solution_2/PrimeCPP_PAR.cpp rename to PrimeCPP/solution_2/PrimeCPP_mask.cpp index be5864816..58ea0dac6 100644 --- a/PrimeCPP/solution_2/PrimeCPP_PAR.cpp +++ b/PrimeCPP/solution_2/PrimeCPP_mask.cpp @@ -70,6 +70,15 @@ class BitArray { return ~mask; } + uint32_t rol(uint32_t value, size_t bits) + { + bits %= 32; + if (bits == 0) + return value; + // Ensure that the number of bits to rotate is within 0-31 + return (value << bits) | (value >> (32 - bits)); + } + void setFlagsFalse(size_t n, size_t skip) { if (skip <= 12) { @@ -78,7 +87,7 @@ class BitArray { size_t bit_pos = n % 32; size_t curr_n = n; - while (curr_n < arrSize) + while (curr_n < size()) { // Build mask for current word starting at bit_pos uint32_t mask = buildSkipMask(skip, bit_pos); @@ -90,7 +99,7 @@ class BitArray { size_t bits_remaining = 32 - bit_pos; curr_n += ((bits_remaining + skip - 1) / skip) * skip; - if (curr_n >= arrSize) break; + if (curr_n >= size()) break; word_idx = index(curr_n); bit_pos = curr_n % 32; @@ -101,7 +110,7 @@ class BitArray { // Original implementation for larger skips auto rolling_mask = ~uint32_t(1 << (n % 32)); auto roll_bits = skip % 32; - while (n < arrSize) { + while (n < size()) { array[index(n)] &= rolling_mask; n += skip; rolling_mask = rol(rolling_mask, roll_bits); @@ -254,7 +263,7 @@ class prime_sieve // Following 2 lines added by rbergen to conform to drag race output format cout << "\n"; - cout << "davepl_par;" << passes << ";" << duration << ";" << threads << ";algorithm=base,faithful=yes,bits=1\n"; + cout << "davepl_mask;" << passes << ";" << duration << ";" << threads << ";algorithm=base,faithful=yes,bits=1\n"; } }; @@ -429,4 +438,4 @@ int main(int argc, char **argv) // On success return the count of primes found; on failure, return 0 return (int) result; -} \ No newline at end of file +} diff --git a/PrimeCPP/solution_2/benchmark.sh b/PrimeCPP/solution_2/benchmark.sh new file mode 100755 index 000000000..a1cd0ea64 --- /dev/null +++ b/PrimeCPP/solution_2/benchmark.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if [[ $1 == both || $1 == 1 || $1 == array ]]; then + ./primes_array ${@:2} +fi + +if [[ $1 == both || $1 == 2 || $1 == mask ]]; then + ./primes_mask ${@:2} +fi diff --git a/PrimeCPP/solution_2/primes_par.exe b/PrimeCPP/solution_2/primes_par.exe deleted file mode 100755 index c815cbfcf1741a58a60a4acb1c6a2bc2822d5d62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 62304 zcmeHw3tZIIw*UUk@R%9UPzO{@8GIDr3lMo!<^YnQrXHk|z5Fr2C?mr|7*w=kd{ijv zamvbrUA0c#fV5*BI48Sx#qyl2tmEr?yxr~*&3i(zQnQ@#X7m59{re647_d5z`+t3Y zzuNA-_G9g}*Is+=wIA&H6dMYc4JV3o)2C$b0wzm& z2&Q&*eE~kqQj928IjRe)x|03zT|r$$-={JXf|dAmGCuH-f1EBNRdqMmA7B0o315d?f?#b|>D~e0t8!G@$`;8<{`j(2 zO86$oNC;Mb{b=fjoS&?WfTUd^a{`i(ZD&eb>g@j;#97_BoCtEq5Y3X_CV&}AdlD8>vzON@;zF7Eeesn34 zD5#{1U{Nfn>XtSiU6dk!Z4$nC9}Hja3LYb~u`9KEe9p?5Ju_=sj>Ijb3(}xA%URnb zKYx=s>+FWTfxMl8ha67`i8*~9Zj$F*Sx7Y(Z}n6P%y z0(uI^j-8M&0YupfIGw4={A@bZRnPqMYN{O8(g_)I5#(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lub&Ys4f|2H#l7)#?!SAaIe}b z@?&A5f$pw|2{?ZSQF0o7kO)7FW6hBcs)-PZNTOm^K>`RtoU-HSG&_rMFQi*Ld<^H* zWM$>fCDd~DVp(~SmEXz9nY)x@NKB9j<7c}L(FRuW%QK*!7xX1l!5l=+%R)7FA6mL4 zz|YK3qm*MhlILaPU^P!ZS4~Vs9y%Vdk)|3pxiahT#iL;wG1=I(nMJ@13{(EZ(+_@xjG zD4H8Zho!(S4POW+k5Pyi@HX?Pjq># zG_Vsz65Xt<0*rkO?r9ZsaFaqI$)tJyA7NAim|RqjODsfhj>OQVJ%&oJ+lD`7IwJnl z)fcGJ3S8#F6-1nBV@Tt`pRPD6E9jO~ zIdkV0&a%Zrs-UYgC28{AG3_=~{x;2l@z`Y?bhG;>Xpu?iMhqWxq-4=TWBRU?N3KXd8|->4;5`qm78uAZ`)U1ki~m!u&{zj`!%p zrHhO0CJlbZ@h5$gfrNhoU#C^k?`lrKwJN5|iu+mY$YiDu6HK<~pX53hLaleg=$*NuDm$I=Dk zf;USKAHI0!`=4~a{y^E_zx?-er_$P{C$&X9lljhy?9c_r$F2S3_LpvZ`NF;5wSV~K zeKWRg5)*&-z^Va1^Zw$GSD!gFmv7dmoO=$@eegiO JejOKz{{;yy2mAm4 diff --git a/PrimeCPP/solution_2/run.cmd b/PrimeCPP/solution_2/run.cmd index 3390a0df2..aee24f625 100644 --- a/PrimeCPP/solution_2/run.cmd +++ b/PrimeCPP/solution_2/run.cmd @@ -1,2 +1,9 @@ -g++ -Ofast PrimeCPP_PAR.cpp -std=c++17 -lstdc++ -oPrimes_par_gcc.exe -.\Primes_par_gcc.exe +IF "%1" == "" || "%1" == "1" || "%1" == "array" ( + g++ -Ofast PrimeCPP_array.cpp -std=c++17 -lstdc++ -oPrimes_array.exe + .\Primes_array.exe +) + +IF "%1" == "" || "%1" == "2" || "%1" == "mask" ( + g++ -Ofast PrimeCPP_mask.cpp -std=c++17 -lstdc++ -oPrimes_mask.exe + .\Primes_mask.exe +) diff --git a/PrimeCPP/solution_2/run.sh b/PrimeCPP/solution_2/run.sh index ea150e106..70f698fa5 100755 --- a/PrimeCPP/solution_2/run.sh +++ b/PrimeCPP/solution_2/run.sh @@ -1,6 +1,17 @@ +#!/bin/bash + # g++ -Ofast -std=c++17 -lc++ PrimeCPP.cpp -oPrimes.exe # gcc -Ofast -std=c++17 PrimeCPP.cpp -lc++ -oPrimes_gcc.exe # clang -Ofast -std=c++17 -lc++ PrimeCPP.cpp -oPrimes_clang.exe -clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_PAR.cpp -oprimes_par.exe -./primes_par.exe +if [[ "$#" -eq "0" -o "$1" -eq "1" -o "$1" -eq "array" ]]; then + echo "Building and running the array approach" + clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_array.cpp -oprimes_array.exe + ./primes_array.exe +fi + +if [[ "$#" -eq "0" -o "$1" -eq "2" -o "$1" -eq "mask" ]]; then + echo "Building and running the mask approach" + clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_mask.cpp -oprimes_mask.exe + ./primes_mask.exe +fi diff --git a/PrimeCPP/solution_2a/Dockerfile b/PrimeCPP/solution_2a/Dockerfile deleted file mode 100644 index f6c0ceb2f..000000000 --- a/PrimeCPP/solution_2a/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM ubuntu:22.04 AS build - -RUN apt-get update -qq \ - && apt-get install -y clang - -WORKDIR /opt/app -COPY *.cpp . -RUN clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_PAR.cpp -oprimes_par - -FROM ubuntu:22.04 -COPY --from=build /opt/app/primes_par /usr/local/bin - -ENTRYPOINT [ "primes_par", "-l", "1000000" ] \ No newline at end of file diff --git a/PrimeCPP/solution_2a/run.cmd b/PrimeCPP/solution_2a/run.cmd deleted file mode 100644 index 3390a0df2..000000000 --- a/PrimeCPP/solution_2a/run.cmd +++ /dev/null @@ -1,2 +0,0 @@ -g++ -Ofast PrimeCPP_PAR.cpp -std=c++17 -lstdc++ -oPrimes_par_gcc.exe -.\Primes_par_gcc.exe diff --git a/PrimeCPP/solution_2a/run.sh b/PrimeCPP/solution_2a/run.sh deleted file mode 100755 index dc59d3612..000000000 --- a/PrimeCPP/solution_2a/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -# g++ -Ofast -std=c++17 -lc++ PrimeCPP.cpp -oPrimes.exe -# gcc -Ofast -std=c++17 PrimeCPP.cpp -lc++ -oPrimes_gcc.exe -# clang -Ofast -std=c++17 -lc++ PrimeCPP.cpp -oPrimes_clang.exe - -clang++ -march=native -mtune=native -pthread -Ofast -std=c++17 PrimeCPP_PAR.cpp -oprimes_par.exe -./primes_par.exe -t 1