1 # 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "<stdin>"
# 28 "<stdin>"
using namespace std;
using namespace tbb;
# 48 "<stdin>"
typedef struct OptionData_ {
float s;
float strike;
float r;
float divq;
float v;
float t;
char OptionType;
float divs;
float DGrefval;
} OptionData;
OptionData *data;
float *prices;
int numOptions;
int * otype;
float * sptprice;
float * strike;
float * rate;
float * volatility;
float * otime;
int numError = 0;
int nThreads;
# 82 "<stdin>"
37 float CNDF ( float InputX )
{
int sign;
float OutputX;
float xInput;
float xNPrimeofX;
float expValues;
float xK2;
float xK2_2, xK2_3;
float xK2_4, xK2_5;
float xLocal, xLocal_1;
float xLocal_2, xLocal_3;
if ( InputX < 0.0 ) {
InputX = -InputX;
sign = 1;
} else
sign = 0;
xInput = InputX;
expValues = exp( -0.5f * InputX * InputX );
xNPrimeofX = expValues;
xNPrimeofX = xNPrimeofX * 0.39894228040143270286;
xK2 = 0.2316419 * xInput;
xK2 = 1.0 + xK2;
xK2 = 1.0 / xK2;
xK2_2 = xK2 * xK2;
xK2_3 = xK2_2 * xK2;
xK2_4 = xK2_3 * xK2;
xK2_5 = xK2_4 * xK2;
xLocal_1 = xK2 * 0.319381530;
xLocal_2 = xK2_2 * ( -0.356563782 );
xLocal_3 = xK2_3 * 1.781477937;
xLocal_2 = xLocal_2 + xLocal_3;
xLocal_3 = xK2_4 * ( -1.821255978 );
xLocal_2 = xLocal_2 + xLocal_3;
xLocal_3 = xK2_5 * 1.330274429;
xLocal_2 = xLocal_2 + xLocal_3;
xLocal_1 = xLocal_2 + xLocal_1;
xLocal = xLocal_1 * xNPrimeofX;
xLocal = 1.0 - xLocal;
OutputX = xLocal;
if ( sign ) {
OutputX = 1.0 - OutputX;
}
return OutputX;
}
99 float BlkSchlsEqEuroNoDiv( float sptprice,
float strike, float rate, float volatility,
float time, int otype, float timet )
{
float OptionPrice;
float xStockPrice;
float xStrikePrice;
float xRiskFreeRate;
float xVolatility;
float xTime;
float xSqrtTime;
float logValues;
float xLogTerm;
float xD1;
float xD2;
float xPowerTerm;
float xDen;
float d1;
float d2;
float FutureValueX;
float NofXd1;
float NofXd2;
float NegNofXd1;
float NegNofXd2;
xStockPrice = sptprice;
xStrikePrice = strike;
xRiskFreeRate = rate;
xVolatility = volatility;
xTime = time;
xSqrtTime = sqrt( xTime );
logValues = log( sptprice / strike );
xLogTerm = logValues;
xPowerTerm = xVolatility * xVolatility;
xPowerTerm = xPowerTerm * 0.5;
xD1 = xRiskFreeRate + xPowerTerm;
xD1 = xD1 * xTime;
xD1 = xD1 + xLogTerm;
xDen = xVolatility * xSqrtTime;
xD1 = xD1 / xDen;
xD2 = xD1 - xDen;
d1 = xD1;
d2 = xD2;
NofXd1 = CNDF( d1 );
NofXd2 = CNDF( d2 );
FutureValueX = strike * ( exp( -( rate )*( time ) ) );
if ( otype == 0 ) {
OptionPrice = ( sptprice * NofXd1 ) - ( FutureValueX * NofXd2 );
} else {
NegNofXd1 = ( 1.0 - NofXd1 );
NegNofXd2 = ( 1.0 - NofXd2 );
OptionPrice = ( FutureValueX * NegNofXd2 ) - ( sptprice * NegNofXd1 );
}
return OptionPrice;
}
struct mainWork {
mainWork( ) {}
mainWork( mainWork &w, tbb::split ) {}
void operator( )( const tbb::blocked_range<int> &range ) const {
float price;
int begin = range.begin( );
int end = range.end( );
for ( int i=begin; i!=end; i++ ) {
price = BlkSchlsEqEuroNoDiv( sptprice[i], strike[i],
rate[i], volatility[i], otime[i],
otype[i], 0 );
prices[i] = price;
# 242 "<stdin>"
}
}
};
# 254 "<stdin>"
193 int bs_thread( void *tid_ptr ) {
int j;
tbb::affinity_partitioner a;
mainWork doall;
for ( j=0; j<100; j++ ) {
tbb::parallel_for( tbb::blocked_range<int>( 0, numOptions ), doall, a );
}
return 0;
}
# 344 "<stdin>"
205 int main ( int argc, char **argv )
{
FILE *file;
int i;
int loopnum;
float * buffer;
int * buffer2;
int rv;
printf( "PARSEC Benchmark Suite\n" );
fflush( NULL );
if ( argc != 4 )
{
printf( "Usage:\n\t%s <nthreads> <inputFile> <outputFile>\n", argv[0] );
exit( 1 );
}
nThreads = atoi( argv[1] );
char *inputFile = argv[2];
char *outputFile = argv[3];
file = fopen( inputFile, "r" );
if( file == NULL ) {
printf( "ERROR: Unable to open file `%s'.\n", inputFile );
exit( 1 );
}
rv = fscanf( file, "%i", &numOptions );
if( rv != 1 ) {
printf( "ERROR: Unable to read from file `%s'.\n", inputFile );
fclose( file );
exit( 1 );
}
if( nThreads > numOptions ) {
printf( "WARNING: Not enough work, reducing number of threads to match number of options.\n" );
nThreads = numOptions;
}
# 400 "<stdin>"
data = ( OptionData* )malloc( numOptions*sizeof( OptionData ) );
prices = ( float* )malloc( numOptions*sizeof( float ) );
for ( loopnum = 0; loopnum < numOptions; ++ loopnum )
{
rv = fscanf( file, "%f %f %f %f %f %f %c %f %f", &data[loopnum].s, &data[loopnum].strike, &data[loopnum].r, &data[loopnum].divq, &data[loopnum].v, &data[loopnum].t, &data[loopnum].OptionType, &data[loopnum].divs, &data[loopnum].DGrefval );
if( rv != 9 ) {
printf( "ERROR: Unable to read from file `%s'.\n", inputFile );
fclose( file );
exit( 1 );
}
}
rv = fclose( file );
if( rv != 0 ) {
printf( "ERROR: Unable to close file `%s'.\n", inputFile );
exit( 1 );
}
printf( "Num of Options: %d\n", numOptions );
printf( "Num of Runs: %d\n", 100 );
buffer = ( float * ) malloc( 5 * numOptions * sizeof( float ) + 256 );
sptprice = ( float * ) ( ( ( unsigned long long )buffer + 256 ) & ~( 64 - 1 ) );
strike = sptprice + numOptions;
rate = strike + numOptions;
volatility = rate + numOptions;
otime = volatility + numOptions;
buffer2 = ( int * ) malloc( numOptions * sizeof( float ) + 256 );
otype = ( int * ) ( ( ( unsigned long long )buffer2 + 256 ) & ~( 64 - 1 ) );
for ( i=0; i<numOptions; i++ ) {
otype[i] = ( data[i].OptionType == 'P' ) ? 1 : 0;
sptprice[i] = data[i].s;
strike[i] = data[i].strike;
rate[i] = data[i].r;
volatility[i] = data[i].v;
otime[i] = data[i].t;
}
printf( "Size of data: %d\n", numOptions * ( sizeof( OptionData ) + sizeof( int ) ) );
# 485 "<stdin>"
tbb::task_scheduler_init init( nThreads );
int tid=0;
bs_thread( &tid );
# 508 "<stdin>"
file = fopen( outputFile, "w" );
if( file == NULL ) {
printf( "ERROR: Unable to open file `%s'.\n", outputFile );
exit( 1 );
}
rv = fprintf( file, "%i\n", numOptions );
if( rv < 0 ) {
printf( "ERROR: Unable to write to file `%s'.\n", outputFile );
fclose( file );
exit( 1 );
}
for( i=0; i<numOptions; i++ ) {
rv = fprintf( file, "%.18f\n", prices[i] );
if( rv < 0 ) {
printf( "ERROR: Unable to write to file `%s'.\n", outputFile );
fclose( file );
exit( 1 );
}
}
rv = fclose( file );
if( rv != 0 ) {
printf( "ERROR: Unable to close file `%s'.\n", outputFile );
exit( 1 );
}
free( data );
free( prices );
return 0;
}