From: Mark Roth Hi there, I found a load balance issue with the pthread version of swaptions. This imbalance occurs as the same chunk size is applied for the first N-1 thread, and the very last thread picks up all the remaining work. For example take the simlarge input with 64 swaptions running on 33 threads. The first 32 threads will process 1 swaption each whereas the 33rd thread will process 32 swaptions. - Mark <<<<<< Begin Patch >>>>>>>>>>>>>>> From ad398a80714fab491e80e61368ec7fec4c8af0aa Mon Sep 17 00:00:00 2001 From: Mark Roth Date: Tue, 24 Jan 2012 19:20:00 -0800 Subject: [PATCH] fixed load balance in pthreads version --- HJM_Securities.cpp | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/HJM_Securities.cpp b/HJM_Securities.cpp index 1a99735..f5f7632 100644 --- a/HJM_Securities.cpp +++ b/HJM_Securities.cpp @@ -80,9 +80,19 @@ void * worker(void *arg){ int tid = *((int *)arg); FTYPE pdSwaptionPrice[2]; - int chunksize = nSwaptions/nThreads; - int beg = tid*chunksize; - int end = (tid+1)*chunksize; + int beg, end, chunksize; + if (tid < (nSwaptions % nThreads)) { + chunksize = nSwaptions/nThreads + 1; + beg = tid * chunksize; + end = (tid+1)*chunksize; + } else { + chunksize = nSwaptions/nThreads; + int offsetThread = nSwaptions % nThreads; + int offset = offsetThread * (chunksize + 1); + beg = offset + (tid - offsetThread) * chunksize; + end = offset + (tid - offsetThread + 1) * chunksize; + } + if(tid == nThreads -1 ) end = nSwaptions; -- 1.7.5.4