Fix bug where too many simulations were being run

This commit is contained in:
Kevin Keogh
2017-07-30 18:03:07 -04:00
parent 824ed8441a
commit b1ca1c9097
2 changed files with 4 additions and 2 deletions

Binary file not shown.

View File

@@ -101,6 +101,7 @@ void gbm(struct Option *opt)
pthread_t *threads; pthread_t *threads;
struct Option *options; struct Option *options;
options = malloc(sizeof(struct Option) * NUM_THREADS); options = malloc(sizeof(struct Option) * NUM_THREADS);
opt->sims = opt->sims / NUM_THREADS;
for(i=0; i<NUM_THREADS; i++) { for(i=0; i<NUM_THREADS; i++) {
options[i] = *opt; options[i] = *opt;
options[i].expiry_date = opt->expiry_date; options[i].expiry_date = opt->expiry_date;
@@ -108,7 +109,6 @@ void gbm(struct Option *opt)
} }
threads = malloc(sizeof(pthread_t) * NUM_THREADS); threads = malloc(sizeof(pthread_t) * NUM_THREADS);
opt->sims = opt->sims / NUM_THREADS;
for(i=0; i<NUM_THREADS; i++) { for(i=0; i<NUM_THREADS; i++) {
if (pthread_create(&threads[i], NULL, run_simulations, &options[i])) { if (pthread_create(&threads[i], NULL, run_simulations, &options[i])) {
@@ -116,11 +116,12 @@ void gbm(struct Option *opt)
} }
} }
opt->sims = 0;
for(i=0; i<NUM_THREADS; i++) { for(i=0; i<NUM_THREADS; i++) {
void *res; void *res;
struct Option *result; struct Option *result;
pthread_join(threads[i], &res); pthread_join(threads[i], &res);
printf("got here opt assignment too!\n");
result = (struct Option*) res; result = (struct Option*) res;
opt->fv += result->fv / NUM_THREADS; opt->fv += result->fv / NUM_THREADS;
opt->delta += result->delta / NUM_THREADS; opt->delta += result->delta / NUM_THREADS;
@@ -130,4 +131,5 @@ void gbm(struct Option *opt)
opt->rho += result->rho / NUM_THREADS; opt->rho += result->rho / NUM_THREADS;
opt->sims += result->sims; opt->sims += result->sims;
} }
} }