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 
23 struct thread_data
24 {
25  int startidx;
26  int maxidx;
27 };
28 
29 void *black_scholes(void* threadarg)
30 {
31 
32  int i;
33  fixedpt sum = 0;
34  struct thread_data* arg = (struct thread_data*) threadarg;
35  int startidx = arg->startidx;
36  int maxidx = arg->maxidx;
37  fixedpt u;
38  for (i = startidx; i < maxidx; i++)
39  {
40  fixedpt seed = seeds[i];
41  u = asset_path_test (seed);
42  //printf("u = %d\n", u >> (FIXEDPT_BITS - FIXEDPT_WBITS));
43  result[i] = u;
44  sum += (u >> FIXEDPT_BITS - FIXEDPT_WBITS);
45  }
46 
47  pthread_exit((void*)sum);
48 }
49 
50 int main ( void )
51 {
52 
53  legup_start_counter(0);
54  int run = RUN;
55  int i;
56  fixedpt sum = 0;
57  //create the thread variables
58  fixedpt result[NUM_ACCEL] = {0};
59  pthread_t threads[NUM_ACCEL];
60  struct thread_data data[NUM_ACCEL];
61 
62  for (i = 0; i < NUM_ACCEL; i++)
63  {
64  //initialize structs to pass into accels
65  data[i].startidx = i * OPS_PER_ACCEL;
66  data[i].maxidx = (i + 1) * OPS_PER_ACCEL;
67  }
68 
69  //launch threads
70  for (i = 0; i < NUM_ACCEL; i++)
71  {
72  pthread_create(&threads[i], NULL, black_scholes, (void *)&data[i]);
73  }
74 
75  //join the threads
76  for (i = 0; i < NUM_ACCEL; i++)
77  {
78  pthread_join(threads[i], (void**)&result[i]);
79  }
80 
81  for (i = 0; i < NUM_ACCEL; i++)
82  {
83  sum += result[i];
84  }
85 
86  int perf_counter = legup_stop_counter(0);
87  printf("perf_counter = %d\n", perf_counter);
88  printf("sum = %d\n", sum); // the golden result will be the SUM of the prices
89  if (sum == 10752)
90  {
91  printf("RESULT: PASS\n");
92  }
93  else
94  {
95  printf("RESULT: FAIL\n");
96  }
97 
98  return (int)sum;
99 }
100 
102 {
103 
104  int n = 100;
105  fixedpt mu, s0, sigma, t1;
106  fixedpt s;
107  //int holdSeed = seed;
108 
109  s0 = 13107200; // fixedpt_rconst(200.0);
110 // printf("%d\n", s0>> (FIXEDPT_BITS - FIXEDPT_WBITS));
111 
112  mu = 16384; // fixedpt_rconst(0.25);
113 // printf("%d\n", mu>> (FIXEDPT_BITS - FIXEDPT_WBITS));
114 
115  sigma = 4391; //fixedpt_rconst(0.067);
116 // printf("%d\n", sigma>> (FIXEDPT_BITS - FIXEDPT_WBITS));
117 
118  t1 = 131072; // fixedpt_rconst(2.0);
119 // printf("%d\n", t1>> (FIXEDPT_BITS - FIXEDPT_WBITS));
120 
121  s = asset_path_fixed_simplified ( s0, mu, sigma, t1, n, &seed);
122 
123  return s;
124 }
125 /******************************************************************************/
126 
127 
#define NULL
#define OPS_PER_ACCEL
Definition: main.c:10
#define FIXEDPT_BITS
Definition: fixedptc.h:75
int maxidx
Definition: main.c:26
#define NUM_ACCEL
Definition: main.c:8
int sum
Definition: dotproduct.h:3
fixedpt black_scholes()
Definition: main.c:22
int startidx
Definition: main.c:25
#define RUN
Definition: main.c:9
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
list threads
Definition: test_panda.py:871
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