|
From: Gordon K. <kin...@us...> - 2004-05-11 06:00:28
|
Update of /cvsroot/teem/teem/src/hoover In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4697 Modified Files: hoover.h methodsHoover.c rays.c Log Message: improved load balancing of hooverRender- now scanlines are doled out as fast as they are finished, rather than assigning each thread to every Nth scanline Index: hoover.h =================================================================== RCS file: /cvsroot/teem/teem/src/hoover/hoover.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** hoover.h 19 Feb 2004 03:44:57 -0000 1.23 --- hoover.h 11 May 2004 06:00:17 -0000 1.24 *************** *** 84,88 **** ** 4) image information ** 5) opaque "user information" pointer ! ** 6) the number of threads to spawn ** 7) the callbacks */ --- 84,88 ---- ** 4) image information ** 5) opaque "user information" pointer ! ** 6) stuff about multi-threading ** 7) the callbacks */ *************** *** 90,109 **** /******** 1) camera information */ ! limnCamera *cam; /* camera info */ /******** 2) volume information: size and spacing, centering */ ! int volSize[3]; /* X,Y,Z resolution of volume */ ! double volSpacing[3]; /* distance between samples in X,Y,Z direction */ ! int volCentering; /* either nrrdCenterNode or nrrdCenterCell */ /******** 3) image information: dimensions + centering */ ! int imgSize[2], /* # samples of image along U and V axes */ ! imgCentering; /* either nrrdCenterNode or nrrdCenterCell */ /******** 4) opaque "user information" pointer */ ! void *user; /* passed to all callbacks */ ! /******** 5) the number of threads to spawn */ ! int numThreads; /* number of threads to spawn per rendering */ /* --- 90,111 ---- /******** 1) camera information */ ! limnCamera *cam; /* camera info */ /******** 2) volume information: size and spacing, centering */ ! int volSize[3]; /* X,Y,Z resolution of volume */ ! double volSpacing[3]; /* distance between samples in X,Y,Z direction */ ! int volCentering; /* either nrrdCenterNode or nrrdCenterCell */ /******** 3) image information: dimensions + centering */ ! int imgSize[2], /* # samples of image along U and V axes */ ! imgCentering; /* either nrrdCenterNode or nrrdCenterCell */ /******** 4) opaque "user information" pointer */ ! void *user; /* passed to all callbacks */ ! /******** 5) stuff about multi-threading */ ! int numThreads, /* number of threads to spawn per rendering */ ! workIdx; /* next work assignment (such as a scanline) */ ! airThreadMutex *workMutex; /* mutex around work assignment */ /* *************** *** 172,182 **** ** ** This is not a terribly flexible scheme (don't forget, this is ! ** hoover) in that it enforces rather rigid constraints on how ! ** multi-threading works: one thread can not render multiple rays ** simulatenously. If there were more args to sample() (like a ** ray, or an integral rayIndex), then this would be possible, ** but it would mean that _hooverThreadBody() would have to ! ** implement all the smarts about which samples belong on which rays ! ** belong with which threads. ** ** At some point now or in the future, an effort will be made to --- 174,184 ---- ** ** This is not a terribly flexible scheme (don't forget, this is ! ** hoover) in that it imposes some constraints on how multi-threading ! ** can work: one thread can not render multiple rays ** simulatenously. If there were more args to sample() (like a ** ray, or an integral rayIndex), then this would be possible, ** but it would mean that _hooverThreadBody() would have to ! ** implement all the smarts about which samples belong on which rays, ! ** and which rays belong with which threads. ** ** At some point now or in the future, an effort will be made to Index: rays.c =================================================================== RCS file: /cvsroot/teem/teem/src/hoover/rays.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** rays.c 10 May 2004 19:29:22 -0000 1.30 --- rays.c 11 May 2004 06:00:17 -0000 1.31 *************** *** 199,207 **** } ! /* for now, the load-balancing among P processors is simplistic: the ! Nth thread (0-based numbering) gets scanlines N, N+P, N+2P, N+3P, ! etc., until it goes beyond the last scanline */ ! vI = arg->whichThread; ! while (vI < arg->ctx->imgSize[1]) { if (nrrdCenterCell == arg->ctx->imgCentering) { v = uvScale*AIR_AFFINE(-0.5, vI, arg->ctx->imgSize[1]-0.5, --- 199,220 ---- } ! while (1) { ! /* the work assignment is simply the next scanline to be rendered: ! the result of all this is setting vI */ ! if (arg->ctx->workMutex) { ! airThreadMutexLock(arg->ctx->workMutex); ! } ! vI = arg->ctx->workIdx; ! if (arg->ctx->workIdx < arg->ctx->imgSize[1]) { ! arg->ctx->workIdx += 1; ! } ! if (arg->ctx->workMutex) { ! airThreadMutexUnlock(arg->ctx->workMutex); ! } ! if (vI == arg->ctx->imgSize[1]) { ! /* we're done! */ ! break; ! } ! if (nrrdCenterCell == arg->ctx->imgCentering) { v = uvScale*AIR_AFFINE(-0.5, vI, arg->ctx->imgSize[1]-0.5, *************** *** 290,295 **** } } /* end this scanline */ ! vI += arg->ctx->numThreads; ! } /* end skipping through scanlines */ if ( (ret = (arg->ctx->threadEnd)(thread, --- 303,307 ---- } } /* end this scanline */ ! } /* end while(1) assignment of scanlines */ if ( (ret = (arg->ctx->threadEnd)(thread, *************** *** 353,356 **** --- 365,374 ---- thread[threadIdx] = airThreadNew(); } + ctx->workIdx = 0; + if (1 < ctx->numThreads) { + ctx->workMutex = airThreadMutexNew(); + } else { + ctx->workMutex = NULL; + } /* (done): call airThreadStart() once per thread, passing the *************** *** 366,370 **** from this copy errArg->errCode into *errCodeP, and return errArg->whichErr */ ! if (1 < ctx->numThreads && !airThreadCapable) { fprintf(stderr, "%s: WARNING: not multi-threaded; will do %d " --- 384,388 ---- from this copy errArg->errCode into *errCodeP, and return errArg->whichErr */ ! if (1 < ctx->numThreads && !airThreadCapable) { fprintf(stderr, "%s: WARNING: not multi-threaded; will do %d " *************** *** 397,400 **** --- 415,422 ---- } + if (1 < ctx->numThreads) { + ctx->workMutex = airThreadMutexNix(ctx->workMutex); + } + if ( (ret = (ctx->renderEnd)(render, ctx->user)) ) { *errCodeP = ret; Index: methodsHoover.c =================================================================== RCS file: /cvsroot/teem/teem/src/hoover/methodsHoover.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** methodsHoover.c 10 May 2004 19:31:52 -0000 1.10 --- methodsHoover.c 11 May 2004 06:00:17 -0000 1.11 *************** *** 34,37 **** --- 34,39 ---- ctx->user = NULL; ctx->numThreads = 1; + ctx->workIdx = 0; + ctx->workMutex = NULL; ctx->renderBegin = hooverStubRenderBegin; ctx->threadBegin = hooverStubThreadBegin; *************** *** 154,157 **** --- 156,160 ---- if (ctx) { limnCameraNix(ctx->cam); + /* workMutex is cleaned up at end of render */ free(ctx); } |