formatting tweaks

This commit is contained in:
NunoSempere 2023-05-29 18:48:25 -04:00
parent f64fedc398
commit 28d443a6cf
3 changed files with 36 additions and 17 deletions

View File

@ -1,10 +1,19 @@
# C-Optimized
An optimized version of the original C implementation. <br>
The main changes are an optimization of the mixture function (it passes the functions instead of the whole arrays, reducing in great measure the memory usage and the computation time) and the implementation of multi-threading with OpenMP. <br>
An optimized version of the original C implementation.
The main changes are:
- an optimization of the mixture function (it passes the functions instead of the whole arrays, reducing in great measure the memory usage and the computation time) and
- the implementation of multi-threading with OpenMP.
The mean time of execution is 6 ms. With the following distribution:
![Time histogram](https://i.imgur.com/6iT2PkF.png) <br>
Take into account that the multi-threading introduces a bit of dispersion in the execution time due to the creation and destruction of threads.
Also, the time data has been collected by executing the interior of the main() function 1000 times in a for loop, not executing the program itself 1000 times. <br>
![Time histogram](https://i.imgur.com/6iT2PkF.png)
The hardware used has been an AMD 5800x3D and 16GB of DDR4-3200 MHz.
Take into account that the multi-threading introduces a bit of dispersion in the execution time due to the creation and destruction of threads.
Also, the time data has been collected by executing the interior of the main() function 1000 times in a for loop, not executing the program itself 1000 times.

View File

@ -5,7 +5,7 @@
# make run
# Compiler
CC=gcc -v
CC=gcc
# CC=tcc # <= faster compilation
# Main file
@ -37,7 +37,15 @@ format: $(SRC)
$(FORMATTER) $(SRC)
run: $(SRC) $(OUTPUT)
./$(OUTPUT)
export OMP_NUM_THREADS=4; ./$(OUTPUT)
test: $(SRC) $(OUTPUT)
OMP_NUM_THREADS=1 ./$(OUTPUT)
echo ""
OMP_NUM_THREADS=2 ./$(OUTPUT)
echo ""
OMP_NUM_THREADS=4 ./$(OUTPUT)
# echo "Increasing stack size limit, because we are dealing with 1M samples"
# # ulimit: increase stack size limit
# # -Ss: the soft limit. If you set the hard limit, you then can't raise it

View File

@ -250,6 +250,8 @@ int main()
// Declare variables in play
float p_a, p_b, p_c;
int n_threads = omp_get_max_threads();
// printf("Max threads: %d\n", n_threads);
// omp_set_num_threads(n_threads);
float** dist_mixture = malloc(n_threads * sizeof(float*));
split_array_allocate(dist_mixture, N, n_threads);