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

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13