PandA-2024.02
main.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <stdint.h>
6 #include <pthread.h>
7 
8 #define NUM_ACCEL 4
9 #define RUN 32
10 #define OPS_PER_ACCEL RUN/NUM_ACCEL
11 
12 #include "black_scholes.h"
13 #include "fixedptc.h"
14 #include "fixedptc.c"
15 #include "black_scholes.c"
16 #include "seed.h"
17 
18 fixedpt asset_path_test ( int seed );
19 
20 //pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
21 //int dummySeed = 123;
22 
24 {
25  int startidx;
26  int maxidx;
27 };
28 
29 inline fixedpt black_scholes(int startidx) __attribute__((always_inline));
31 {
32 
33  int i;
34  fixedpt sum = 0;
35  fixedpt u;
36  for(i=0; i < OPS_PER_ACCEL; i++)
37  {
38  fixedpt seed = seeds[i+startidx];
39  u = asset_path_test (seed);
40  result[i] = u;
41  sum += (u >> FIXEDPT_BITS - FIXEDPT_WBITS);
42  }
43  return sum;
44 }
45 
46 int main ( void )
47 {
48 
49  int run = RUN;
50  int i;
51  fixedpt sum = 0;
52  //create the thread variables
53  fixedpt result[NUM_ACCEL] = {0};
54 
55 #pragma omp simd
56  for (i = 0; i < NUM_ACCEL; i++)
57  {
58  result[i] = black_scholes(i * OPS_PER_ACCEL);
59  }
60 
61 
62  for (i = 0; i < NUM_ACCEL; i++)
63  {
64  sum += result[i];
65  }
66 
67  printf("sum = %d\n", sum); // the golden result will be the SUM of the prices
68  if (sum == 10752)
69  {
70  printf("RESULT: PASS\n");
71  return 0;
72  }
73  else
74  {
75  printf("RESULT: FAIL\n");
76  return 1;
77  }
78 }
79 
80 inline fixedpt asset_path_test (int seed) __attribute__((always_inline));
82 {
83 
84  int n = 100;
85  fixedpt mu, s0, sigma, t1;
86  fixedpt s;
87  //int holdSeed = seed;
88 
89  s0 = 13107200; // fixedpt_rconst(200.0);
90 // printf("%d\n", s0>> (FIXEDPT_BITS - FIXEDPT_WBITS));
91 
92  mu = 16384; // fixedpt_rconst(0.25);
93 // printf("%d\n", mu>> (FIXEDPT_BITS - FIXEDPT_WBITS));
94 
95  sigma = 4391; //fixedpt_rconst(0.067);
96 // printf("%d\n", sigma>> (FIXEDPT_BITS - FIXEDPT_WBITS));
97 
98  t1 = 131072; // fixedpt_rconst(2.0);
99 // printf("%d\n", t1>> (FIXEDPT_BITS - FIXEDPT_WBITS));
100 
101  s = asset_path_fixed_simplified ( s0, mu, sigma, t1, n, &seed);
102 
103  return s;
104 }
105 /******************************************************************************/
106 
107 
#define FIXEDPT_BITS
Definition: fixedptc.h:75
void __attribute__((noinline))
Definition: main.c:7
#define OPS_PER_ACCEL
Definition: main.c:10
int maxidx
Definition: main.c:26
int sum
Definition: dotproduct.h:3
fixedpt black_scholes()
Definition: main.c:22
#define NUM_ACCEL
Definition: main.c:8
int startidx
Definition: main.c:25
int result[SIZE]
Definition: adpcm.c:800
fixedpt asset_path_fixed_simplified(fixedpt s0, fixedpt mu, fixedpt sigma, fixedpt t1, int n, int *seed)
Definition: black_scholes.c:5
fixedpt asset_path_test(int seed)
Definition: main.c:12
#define RUN
Definition: main.c:9
void main()
Definition: main.c:670
int32_t fixedpt
Definition: fixedptc.h:79
int seeds[NUMPHOTONS]
Definition: tiny_fixed.h:1
#define FIXEDPT_WBITS
Definition: fixedptc.h:95

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