mirror of
https://github.com/RustyRaptor/parallel-programming.git
synced 2026-12-03 15:55:15 -07:00
added autorun in makefile
This commit is contained in:
1 parent
e95d902dda
commit
f092b3b621
2 files changed
+61
-17
No files matched your search
@@ -1,11 +1,64 @@
|
||||
|
||||
all: count_threes
|
||||
|
||||
count_threes: count_threes.c
|
||||
gcc -fopenmp -o count_threes count_threes.c
|
||||
|
||||
run:
|
||||
export OMP_NUM_THREADS=30
|
||||
./count_threes
|
||||
# run with 1 thread
|
||||
export OMP_NUM_THREADS=1
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
awk '{s+=$$1} END {print "1 thread: " s/5}' results.txt
|
||||
|
||||
# run with 2 threads
|
||||
export OMP_NUM_THREADS=2
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
awk '{s+=$$1} END {print "2 threads: " s/5}' results.txt
|
||||
|
||||
# run with 4 threads
|
||||
export OMP_NUM_THREADS=4
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
awk '{s+=$$1} END {print "4 threads: " s/5}' results.txt
|
||||
|
||||
# run with 8 threads
|
||||
export OMP_NUM_THREADS=8
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
awk '{s+=$$1} END {print "8 threads: " s/5}' results.txt
|
||||
|
||||
# run with 16 threads
|
||||
export OMP_NUM_THREADS=16
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
awk '{s+=$$1} END {print "16 threads: " s/5}' results.txt
|
||||
|
||||
# run with 32 threads
|
||||
export OMP_NUM_THREADS=32
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
./count_threes 10000000 >> results.txt
|
||||
awk '{s+=$$1} END {print "32 threads: " s/5}' results.txt
|
||||
|
||||
clean:
|
||||
rm -f count_threes
|
||||
rm -f count_threes results.txt
|
||||
|
||||
@@ -3,25 +3,16 @@
|
||||
#include <time.h>
|
||||
#include <omp.h>
|
||||
|
||||
|
||||
int count3s(int* array, int length)
|
||||
{
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
#pragma omp parallel shared(array, count, length) private(i)
|
||||
{
|
||||
int count_p = 0;
|
||||
|
||||
#pragma omp for
|
||||
for (i = 0; i < length; i++) {
|
||||
if (array[i] == 3) {
|
||||
count_p++;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp critical
|
||||
{
|
||||
count += count_p;
|
||||
#pragma omp parallel for reduction(+:count)
|
||||
for (i = 0; i < length; i++) {
|
||||
if (array[i] == 3) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user