forked from OpenMP/Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample_SIMD.8.c
More file actions
50 lines (45 loc) · 792 Bytes
/
Example_SIMD.8.c
File metadata and controls
50 lines (45 loc) · 792 Bytes
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
/*
* @@name: SIMD.8c
* @@type: C
* @@compilable: yes
* @@linkable: yes
* @@expect: success
*/
#include <stdio.h>
#include <math.h>
int P[1000];
float A[1000];
float do_work(float *arr)
{
float pri;
int i;
#pragma omp simd lastprivate(pri)
for (i = 0; i < 999; ++i) {
int j = P[i];
pri = 0.5f;
if (j % 2 == 0) {
pri = A[j+1] + arr[i];
}
A[j] = pri * 1.5f;
pri = pri + A[j];
}
return pri;
}
int main(void)
{
float pri, arr[1000];
int i;
for (i = 0; i < 1000; ++i) {
P[i] = i;
A[i] = i * 1.5f;
arr[i] = i * 1.8f;
}
pri = do_work(&arr[0]);
if (pri == 8237.25) {
printf("passed: result pri = %7.2f (8237.25) \n", pri);
}
else {
printf("failed: result pri = %7.2f (8237.25) \n", pri);
}
return 0;
}