-
Notifications
You must be signed in to change notification settings - Fork 3
/
openmp_false_sharing.c
50 lines (38 loc) · 998 Bytes
/
openmp_false_sharing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include "papi.h"
#define N 1000
#define NUM_THREADS 48
#define NUM_EVENTS 2
int main(void)
{
int i = 0;
int x[N];
int y[N];
long long values[NUM_EVENTS] = {0, 0};
int events[NUM_EVENTS] = {PAPI_CA_ITV, PAPI_TOT_CYC};
int retval;
if ((retval = PAPI_start_counters(events, NUM_EVENTS)) != PAPI_OK) {
fprintf(stderr, "PAPI Start counter error! %d, %d\n", retval, __LINE__);
exit(1);
}
double sum = 0.0;
double sum_local[NUM_THREADS];
#pragma omp parallel num_threads(NUM_THREADS)
{
int iam = omp_get_thread_num();
#pragma omp for
for (i = 0; i< N; i++) {
sum_local[iam] = x[i] * y[i];
}
#pragma omp atomic
sum += sum_local[iam];
}
if ((retval = PAPI_stop_counters(values, NUM_EVENTS)) != PAPI_OK) {
fprintf(stderr, "PAPI stop counters error! %d, %d\n", retval, __LINE__);
exit(1);
}
printf("Requests for cache line intervention = %d\n", values[0]);
return 0;
}