Skip to content

Commit

Permalink
Merge branch 'master' into ferret
Browse files Browse the repository at this point in the history
  • Loading branch information
anasazi committed Jul 11, 2011
2 parents 1863dff + 4ad10e1 commit a572bab
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 264 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ bin/
pkgs/*/*/inputs/
pkgs/*/*/inst/
pkgs/*/*/obj/
pkgs/*/*/run/
2 changes: 1 addition & 1 deletion pkgs/apps/blackscholes/src/blackscholes.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int bs_thread(void *tid_ptr) {

for (j=0; j<NUM_RUNS; j++) {
#ifdef ENABLE_OPENMP
#pragma omp parallel for
#pragma omp parallel for private(i, price, priceDelta)
for (i=0; i<numOptions; i++) {
#else //ENABLE_OPENMP
for (i=start; i<end; i++) {
Expand Down
81 changes: 21 additions & 60 deletions pkgs/apps/blackscholes/src/blackscholes.tbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#ifdef TBB_VERSION
#include "tbb/blocked_range.h"
#include "tbb/parallel_reduce.h"
#include "tbb/parallel_for.h"
#include "tbb/task_scheduler_init.h"
#include "tbb/tick_count.h"
#else
Expand All @@ -26,11 +26,12 @@
#include <string.h>
#include <math.h>

#define PAD 256
#define LINESIZE 64

#ifdef TBB_VERSION
/* created parallel calls to CNDF procedure */
//#define PARALLEL_CNDF
int NUM_TASKS;
using namespace std;
using namespace tbb;
#endif
Expand Down Expand Up @@ -89,17 +90,13 @@ fptype BlkSchlsEqEuroNoDiv( fptype sptprice,
fptype time, int otype, float timet );



#ifdef TBB_VERSION
struct mainWork {
fptype price;
public:
mainWork():price(0){}
mainWork(mainWork &w, tbb::split){price = 0;}

void operator()(const tbb::blocked_range<int> &range) {
fptype local_price=0;
fptype priceDelta;
mainWork(){}
mainWork(mainWork &w, tbb::split){}

void operator()(const tbb::blocked_range<int> &range) const {
fptype price;
int begin = range.begin();
int end = range.end();

Expand All @@ -115,32 +112,25 @@ struct mainWork {
fprintf(stderr,"%lf\t",volatility[i]);
fprintf(stderr,"%lf\t",otime[i]);
#endif
local_price += BlkSchlsEqEuroNoDiv( sptprice[i], strike[i],
rate[i], volatility[i], otime[i],
otype[i], 0);
prices[i] = local_price;
price = BlkSchlsEqEuroNoDiv( sptprice[i], strike[i], rate[i],
volatility[i], otime[i], otype[i], 0);
prices[i] = price;

#ifdef PRINTINFO
fprintf(stderr,"%lf\n",price);
#endif

#ifdef ERR_CHK
priceDelta = data[i].DGrefval - price;
fptype priceDelta = data[i].DGrefval - price;
if( fabs(priceDelta) >= 1e-5 ){
fprintf(stderr,"Error on %d. Computed=%.5f, Ref=%.5f, Delta=%.5f\n",
i, price, data[i].DGrefval, priceDelta);
numError ++;
}
#endif
}

price +=local_price;
}


void join(mainWork &rhs){price += rhs.getPrice();}
fptype getPrice(){return price;}

};


Expand Down Expand Up @@ -358,37 +348,24 @@ fptype BlkSchlsEqEuroNoDiv( fptype sptprice,
#ifdef TBB_VERSION
int bs_thread(void *tid_ptr) {
int j;
fptype price;
fptype priceDelta;
tbb::affinity_partitioner a;

mainWork doall;
for (j=0; j<NUM_RUNS; j++) {
mainWork doall;
tbb::parallel_reduce(tbb::blocked_range<int>(0, numOptions), doall, a);
price = doall.getPrice();
tbb::parallel_for(tbb::blocked_range<int>(0, numOptions), doall, a);
}


return 0;
}
#else // !TBB_VERSION

fptype *price;
int bs_thread(void *tid_ptr) {
int i, j, k;
fptype acc_price;
fptype priceDelta;
int tid = *(int *)tid_ptr;
int start = tid * (numOptions / nThreads);
int end = start + (numOptions / nThreads);

if(tid == (nThreads-1))
end = numOptions;
fptype price;

for (j=0; j<NUM_RUNS; j++) {
price[tid*LINESIZE] = 0;
for (i=start; i<end; i++) {
/* Calling main function to calculate option value based on
for (i=0; i<numOptions; i++) {
/* Calling main function to calculate option value based on
* Black & Sholes's equation.
*/
#ifdef PRINTINFO
Expand All @@ -399,16 +376,16 @@ int bs_thread(void *tid_ptr) {
fprintf(stderr,"%lf\t",otime[i]);
#endif

price[tid*LINESIZE] += BlkSchlsEqEuroNoDiv( sptprice[i], strike[i],
rate[i], volatility[i], otime[i],
otype[i], 0);
price = BlkSchlsEqEuroNoDiv( sptprice[i], strike[i], rate[i],
volatility[i], otime[i], otype[i], 0);
prices[i] = price;

#ifdef PRINTINFO
fprintf(stderr,"%lf\n",price[tid*LINESIZE]);
#endif

#ifdef ERR_CHK
priceDelta = data[i].DGrefval - price;
fptype priceDelta = data[i].DGrefval - price;
if( fabs(priceDelta) >= 1e-4 ){
printf("Error on %d. Computed=%.5f, Ref=%.5f, Delta=%.5f\n",
i, price, data[i].DGrefval, priceDelta);
Expand All @@ -417,20 +394,13 @@ int bs_thread(void *tid_ptr) {
#endif
}

if(tid==0) {
acc_price = 0;
for(i=0;i<nThreads;i++)
acc_price += price[i*LINESIZE];
}
}

return 0;
}

#endif // TBB_VERSION



int main (int argc, char **argv)
{
FILE *file;
Expand Down Expand Up @@ -480,12 +450,6 @@ int main (int argc, char **argv)
nThreads = numOptions;
}

#ifdef TBB_VERSION
//Determine work unit size etc.
NUM_TASKS=(4*nThreads);
if(NUM_TASKS > numOptions) NUM_TASKS = numOptions;
#endif

// alloc spaces for the option data
data = (OptionData*)malloc(numOptions*sizeof(OptionData));
prices = (fptype*)malloc(numOptions*sizeof(fptype));
Expand Down Expand Up @@ -514,9 +478,6 @@ int main (int argc, char **argv)
printf("Parallel CNDF active\n");
#endif

#define PAD 256
#define LINESIZE 64

buffer = (fptype *) malloc(5 * numOptions * sizeof(fptype) + PAD);
sptprice = (fptype *) (((unsigned long long)buffer + PAD) & ~(LINESIZE - 1));
strike = sptprice + numOptions;
Expand Down
Loading

0 comments on commit a572bab

Please sign in to comment.