You are on page 1of 6

Computer Architectures for

Medical Applications
Exercise 11

Lehrstuhl fr Informatik 3 / Professur fr Hchstleistungsrechnen

2015/07/06

Assignment 10 OpenMP results

int repeat = 1;
double runtime=0.;
for(; runtime<.1; repeat*=2) {
timing(&wcs, &ct);
for(r=0; r<repeat; ++r) {
#pragma omp parallel for
for(i=0; i<N; ++i) {
a[i] = b[i] + c[i] * d[i];
}

if(CONDITION_NEVER_TRUE) dummy(a); // fools the compiler


}
timing(&wce, &ct);
runtime = wce-wcs;
}
repeat/=2;

15/07/06

CAMA 2015 Assignment 11

Assignment 10 OpenMP results

Aggregate
L2

OMP
overhead

15/07/06

CAMA 2015 Assignment 11

Memory BW
saturation

Assignment 10 OpenMP results


The OpenMP overhead can be reduced by having less but bigger parallel
regions (i.e., less overhead due to re-starts of OpenMP thread teams):
int repeat = 1;
double runtime=0.;
for(; runtime<.1; repeat*=2) {
timing(&wcs, &ct);
#pragma omp parallel private(r,i)
for(r=0; r<repeat; ++r) {
#pragma omp for
parallel for
for(i=0; i<N; ++i) {
a[i] = b[i] + c[i] * d[i];
}

if(CONDITION_NEVER_TRUE) dummy(a); // fools the compiler


}
timing(&wce, &ct);
runtime = wce-wcs;
}
repeat/=2;

15/07/06

CAMA 2015 Assignment 11

Assignment 10 OpenMP results


Reduced team
re-start overhead

15/07/06

CAMA 2015 Assignment 11

Assignment 11 More OpenMP


Compute using the Monte Carlo method.
The quarter circle in the rst quadrant with origin at (0,0) and radius 1 has
an area of /4. Look at the random number pairs in [0, 1] [0, 1]. The
probability that such a point lies inside the quarter circle is /4, so given
enough statistics we are able to calculate using this so-called Monte
Carlo method.
1. Write a parallel OpenMP program that performs this task. Use
the rand_r() function to get separate random number sequences for
all threads.
2. Make sure that adding more threads in a weak scaling scenario
actually improves statistics.
3. What is the best relative accuracy that you can achieve with ten
"Emmy" cores in one second of walltime?

15/07/06

CAMA 2015 Assignment 11

You might also like