time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

commit 6b34d9abdb5a44fb2bddb2656ae522c61c2ce1f8
parent 58c74ce37d839977877f35b4bb41ac09a83e7c14
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Fri,  2 Jun 2023 12:50:51 -0600

feat: add more threads, document rand_r in code.

Diffstat:
MC-optimized/makefile | 4++++
MC-optimized/out/samples | 0
MC-optimized/samples.c | 4+++-
3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/C-optimized/makefile b/C-optimized/makefile @@ -46,6 +46,8 @@ multi: OMP_NUM_THREADS=1 ./$(OUTPUT) && echo OMP_NUM_THREADS=2 ./$(OUTPUT) && echo OMP_NUM_THREADS=4 ./$(OUTPUT) && echo + OMP_NUM_THREADS=8 ./$(OUTPUT) && echo + OMP_NUM_THREADS=16 ./$(OUTPUT) && echo ./$(OUTPUT_ONE_THREAD) && echo time-linux: @@ -53,6 +55,8 @@ time-linux: OMP_NUM_THREADS=1 /bin/time -f "Time: %es" ./$(OUTPUT) && echo OMP_NUM_THREADS=2 /bin/time -f "Time: %es" ./$(OUTPUT) && echo OMP_NUM_THREADS=4 /bin/time -f "Time: %es" ./$(OUTPUT) && echo + OMP_NUM_THREADS=8 /bin/time -f "Time: %es" ./$(OUTPUT) && echo + OMP_NUM_THREADS=16 /bin/time -f "Time: %es" ./$(OUTPUT) && echo /bin/time -f "Time: %es" ./$(OUTPUT_ONE_THREAD) && echo debian-install-dependencies: diff --git a/C-optimized/out/samples b/C-optimized/out/samples Binary files differ. diff --git a/C-optimized/samples.c b/C-optimized/samples.c @@ -6,7 +6,7 @@ const float PI = 3.14159265358979323846; -#define N 100000000 +#define N 10000000 //Array helpers @@ -50,6 +50,8 @@ void array_cumsum(float* array_to_sum, float* array_cumsummed, int length) float rand_float(float to, unsigned int* seed) { return ((float)rand_r(seed) / (float)RAND_MAX) * to; + // See: <https://stackoverflow.com/questions/43151361/how-to-create-thread-safe-random-number-generator-in-c-using-rand-r> + // rand() is not thread-safe, as it relies on (shared) hidden state. } float ur_normal(unsigned int* seed)