-
Notifications
You must be signed in to change notification settings - Fork 7
/
data_gen.c
101 lines (91 loc) · 2.93 KB
/
data_gen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (C) 2014-2015, 2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
#define _XOPEN_SOURCE
#define _BSD_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
#include <ia32intrin.h>
#include "euro_opt.h"
tfloat RandRange( tfloat a, tfloat b, struct drand48_data *seed ) {
double r;
drand48_r(seed, &r);
return r*(b-a) + a;
}
/*
// This function allocates arrays to hold input and output parameters
// for the Black-Scholes formula.
// nopt - length of arrays
// Random input parameters
// s0 - initial price
// x - strike price
// t - maturity
// Output arrays for call and put prices
// vcall_compiler, vcall_mkl
// vput_compiler, vput_mkl
*/
void InitData( int nopt, tfloat* *s0, tfloat* *x, tfloat* *t,
tfloat* *vcall_compiler, tfloat* *vput_compiler,
tfloat* *vcall_mkl, tfloat* *vput_mkl
)
{
tfloat *ts0, *tx, *tt, *tvcall_compiler, *tvput_compiler, *tvcall_mkl, *tvput_mkl;
int i;
/* Allocate aligned memory */
ts0 = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
tx = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
tt = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
tvcall_compiler = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
tvput_compiler = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
tvcall_mkl = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
tvput_mkl = (tfloat*)_mm_malloc( nopt * sizeof(tfloat), ALIGN_FACTOR);
if ( (ts0 == NULL) || (tx == NULL) || (tt == NULL) ||
(tvcall_compiler == NULL) || (tvput_compiler == NULL) ||
(tvcall_mkl == NULL) || (tvput_mkl == NULL) )
{
printf("Memory allocation failure\n");
exit(-1);
}
/* NUMA-friendly data init */
#pragma omp parallel
{
struct drand48_data seed;
srand48_r(omp_get_thread_num()+SEED, &seed);
#pragma omp for simd
for ( i = 0; i < nopt; i++ )
{
ts0[i] = RandRange( S0L, S0H, &seed );
tx[i] = RandRange( XL, XH, &seed );
tt[i] = RandRange( TL, TH, &seed );
tvcall_compiler[i] = 0.0;
tvput_compiler[i] = 0.0;
tvcall_mkl[i] = 0.0;
tvput_mkl[i] = 0.0;
}
}
*s0 = ts0;
*x = tx;
*t = tt;
*vcall_compiler = tvcall_compiler;
*vput_compiler = tvput_compiler;
*vcall_mkl = tvcall_mkl;
*vput_mkl = tvput_mkl;
}
/* Deallocate arrays */
void FreeData( tfloat *s0, tfloat *x, tfloat *t,
tfloat *vcall_compiler, tfloat *vput_compiler,
tfloat *vcall_mkl, tfloat *vput_mkl
)
{
/* Free memory */
_mm_free(s0);
_mm_free(x);
_mm_free(t);
_mm_free(vcall_compiler);
_mm_free(vput_compiler);
_mm_free(vcall_mkl);
_mm_free(vput_mkl);
}