feat: add more threads, document rand_r in code.

This commit is contained in:
NunoSempere 2023-06-02 12:50:51 -06:00
parent 58c74ce37d
commit 6b34d9abdb
3 changed files with 7 additions and 1 deletions

View File

@ -46,6 +46,8 @@ multi:
OMP_NUM_THREADS=1 ./$(OUTPUT) && echo OMP_NUM_THREADS=1 ./$(OUTPUT) && echo
OMP_NUM_THREADS=2 ./$(OUTPUT) && echo OMP_NUM_THREADS=2 ./$(OUTPUT) && echo
OMP_NUM_THREADS=4 ./$(OUTPUT) && echo OMP_NUM_THREADS=4 ./$(OUTPUT) && echo
OMP_NUM_THREADS=8 ./$(OUTPUT) && echo
OMP_NUM_THREADS=16 ./$(OUTPUT) && echo
./$(OUTPUT_ONE_THREAD) && echo ./$(OUTPUT_ONE_THREAD) && echo
time-linux: time-linux:
@ -53,6 +55,8 @@ time-linux:
OMP_NUM_THREADS=1 /bin/time -f "Time: %es" ./$(OUTPUT) && echo 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=2 /bin/time -f "Time: %es" ./$(OUTPUT) && echo
OMP_NUM_THREADS=4 /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 /bin/time -f "Time: %es" ./$(OUTPUT_ONE_THREAD) && echo
debian-install-dependencies: debian-install-dependencies:

Binary file not shown.

View File

@ -6,7 +6,7 @@
const float PI = 3.14159265358979323846; const float PI = 3.14159265358979323846;
#define N 100000000 #define N 10000000
//Array helpers //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) float rand_float(float to, unsigned int* seed)
{ {
return ((float)rand_r(seed) / (float)RAND_MAX) * to; 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) float ur_normal(unsigned int* seed)