PandA-2024.02
dotproduct.c
Go to the documentation of this file.
1 /* Parallelizable Dot Product Benchmark
2  *
3  * A.B=A0*B0+A1*B1+A2*B2+A3*B3
4  *
5  *
6  */
7 
8 #define ARRAY_SIZE 6000
9 #define NUMS_OF_ACCEL 6
10 #define OPS_PER_ACCEL ARRAY_SIZE/NUMS_OF_ACCEL
11 
12 #include <stdio.h>
13 #include "dotproduct.h"
14 
16 
17 // Calculate the values for an entire row
18 int product (int * inputA, int * inputB, int startidx, int maxidx)
19 {
20  int i,j;
21  int result = 0;
22  for (i = startidx; i < maxidx; i++){
23  result+= inputA[i]*inputB[i];
24 // printf("index i = %d\n", i);
25  }
26  return result;
27 }
28 
29 int main(){
30  int result=0;
31  int i;
32 
33  #pragma omp parallel for num_threads(NUMS_OF_ACCEL) private(i)
34  for (i=0; i<NUMS_OF_ACCEL; i++) {
35  result_array[i] = product (A_array, B_array, i*OPS_PER_ACCEL, (i+1)*OPS_PER_ACCEL);
36  }
37 
38  //combining the results
39  for (i=0; i<NUMS_OF_ACCEL; i++) {
40  result += result_array[i];
41  }
42 
43  //check final result
44  printf ("Result: %d\n", result);
45  if (result == 60799800) {
46  printf("RESULT: PASS\n");
47  } else {
48  printf("RESULT: FAIL\n");
49  }
50  return 0;
51 }
int B_array[ARRAY_SIZE]
Definition: dotproduct.h:2
int product(int *inputA, int *inputB, int startidx, int maxidx)
Definition: dotproduct.c:18
int result_array[NUMS_OF_ACCEL]
Definition: dotproduct.c:15
#define OPS_PER_ACCEL
Definition: dotproduct.c:10
int main()
Definition: dotproduct.c:28
int result[SIZE]
Definition: adpcm.c:800
int A_array[ARRAY_SIZE]
Definition: dotproduct.h:1
#define NUMS_OF_ACCEL
Definition: dotproduct.c:9

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