PandA-2024.02
examples
omp_simd
add
modified
add.c
Go to the documentation of this file.
1
#define NUM_ACCELS 8
2
#define ARRAY_SIZE 10000
3
#define OPS_PER_ACCEL ARRAY_SIZE/NUM_ACCELS
4
5
#include <stdio.h>
6
#include "
add.h
"
7
8
int
output
[
NUM_ACCELS
];
9
10
#pragma omp declare simd
11
void
add
(
int
accelnum,
int
startidx,
int
endidx)
12
{
13
int
sum
= 0;
14
int
i;
15
for
(i = 0; i <
OPS_PER_ACCEL
; i++)
16
{
17
sum +=
array
[i+startidx];
18
}
19
output
[accelnum] =
sum
;
20
}
21
22
23
int
24
main
()
25
{
26
int
sum
= 0;
27
int
i;
28
29
#pragma omp simd
30
for
(i = 0; i <
NUM_ACCELS
; i++)
31
{
32
add
(i, i *
OPS_PER_ACCEL
, (i + 1)*OPS_PER_ACCEL);
33
}
34
35
//combine results
36
for
(i = 0; i <
NUM_ACCELS
; i++)
37
{
38
sum +=
output
[i];
39
}
40
41
//check result
42
printf (
"Result: %d\n"
, sum);
43
if
(sum == 55000)
44
{
45
printf(
"RESULT: PASS\n"
);
46
}
47
else
48
{
49
printf(
"RESULT: FAIL\n"
);
50
}
51
52
return
0;
53
}
NUM_ACCELS
#define NUM_ACCELS
Definition:
add.c:1
sum
int sum
Definition:
dotproduct.h:3
output
int output[NUM_ACCELS]
Definition:
add.c:8
add
void add(int accelnum, int startidx, int endidx)
Definition:
add.c:11
add.h
main
int main()
Definition:
add.c:35
OPS_PER_ACCEL
#define OPS_PER_ACCEL
Definition:
add.c:3
array
int array[ARRAY_SIZE]
Definition:
add.h:1
Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by
1.8.13