Chapter 5
Chapter 5
Chapter 5
Peter Pacheco
Chapter 5
Shared Memory Programming
with OpenMP
. / omp_hello 4
compiling
running with 4 threads
# include <omp.h>
#ifdef _OPENMP
# include <omp.h>
#endif
# ifdef _OPENMP
int my_rank = omp_get_thread_num ( );
int thread_count = omp_get_num_threads ( );
#else
int my_rank = 0;
int thread_count = 1;
# endif
global_result += my_result ;
I don’t
like it.
+, *, -, &, |, ˆ, &&, ||
fibo[ 0 ] = fibo[ 1 ] = 1;
# pragma omp parallel for num_threads(2)
for (i = 2; i < n; i++)
fibo[ i ] = fibo[ i – 1 ] + fibo[ i – 2 ];
but sometimes
we get this
1 1 2 3 5 8 13 21 34 55
this is correct 1123580000
loop dependency
Assignment of work
using cyclic partitioning.
n = 10,000
one thread
run-time = 3.67 seconds.
Cyclic schedule: