-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello_world_sync.cpp
62 lines (36 loc) · 942 Bytes
/
hello_world_sync.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <omp.h>
int some_calc(int array[], int num_threads) {
int result = 0;
for (int i=0; i<num_threads; i++) {
result += array[i];
}
return result;
}
int some_calc(int array) {
int result_func = 0;
result_func = array;
return result_func;
}
int main() {
int num_threads = 4;
omp_set_num_threads(num_threads);
int array[num_threads];
int result = 0;
// int my_calculated_variables[num_threads];
int my_calculated_variable;
int iterations = 1000;
#pragma omp parallel
{
int ID = omp_get_thread_num();
// array[ID] = ID*ID;
//#pragma omp barrier
for (int i=ID; i<iterations; i+=num_threads) {
my_calculated_variable = i*i;
result += some_calc(my_calculated_variable);
}
// my_calculated_variables[ID] = some_calc(array, num_threads) + ID;
}
printf("%d \n", my_calculated_variable);
return 0;
}