IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 31, 2008, 1:24:22 PM (18 years ago)
Author:
eugene
Message:

some threading simplifications: threaded and unthreaded use the same code; added concept of a thread task

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/ppMerge/src/ppMergeLoop_Threaded.c

    r18815 r18822  
    197197
    198198            // Read input data by chunks
    199             psTimerStart ("ppMergeLoop");
     199            // psTimerStart ("ppMergeLoop");
    200200            for (int numChunk = 0; true; numChunk++) {
    201201
     
    205205                if (!fileGroup) break;
    206206
     207                psThreadJob *job = NULL;
     208
    207209                switch (type) {
    208210                  case PPMERGE_TYPE_SHUTTER:
    209                     if (nThreads) {
    210                         // allocate a job
    211                         psThreadJob *job = psThreadJobAlloc ("PPMERGE_SHUTTER_CORRECTION", 0);
    212 
    213                         // construct the arguments for this job
    214                         psArrayAdd (job->args, 1, outRO);
    215                         psArrayAdd (job->args, 1, fileGroup);
    216                         psArrayAdd (job->args, 1, psScalarAlloc(shutterRef, PS_TYPE_F32));
    217                         psArrayAdd (job->args, 1, shutters->data[cellNum]);
    218                         psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
    219                         psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
    220                         psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
    221 
    222                         psThreadJobAddPending (job);
    223                     } else {
    224                         if (!pmShutterCorrectionGenerate(outRO, NULL, fileGroup->readouts, shutterRef, shutters->data[cellNum], iter, rej, maskVal)) {
    225                             goto ERROR;
    226                         }
    227                         fileGroup->busy = false;
     211                    // allocate a job
     212                    job = psThreadJobAlloc ("PPMERGE_SHUTTER_CORRECTION");
     213
     214                    // construct the arguments for this job
     215                    psArrayAdd (job->args, 1, outRO);
     216                    psArrayAdd (job->args, 1, fileGroup);
     217                    psArrayAdd (job->args, 1, psScalarAlloc(shutterRef, PS_TYPE_F32));
     218                    psArrayAdd (job->args, 1, shutters->data[cellNum]);
     219                    psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
     220                    psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
     221                    psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
     222
     223                    // call: pmShutterCorrectionGenerate(outRO, NULL, fileGroup->readouts, shutterRef, shutters->data[cellNum], iter, rej, maskVal)
     224                    if (!psThreadJobAddPending (job)) {
     225                        goto ERROR;
    228226                    }
    229227                    break;
    230228                  case PPMERGE_TYPE_DARK:
    231                     if (nThreads) {
    232                         // allocate a job
    233                         psThreadJob *job = psThreadJobAlloc ("PPMERGE_DARK_COMBINE", 0);
    234 
    235                         // construct the arguments for this job
    236                         psArrayAdd (job->args, 1, outCell);
    237                         psArrayAdd (job->args, 1, fileGroup);
    238                         psArrayAdd (job->args, 1, darkOrdinates);
    239                         psArrayAdd (job->args, 1, darkNorm);
    240                         psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
    241                         psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
    242                         psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
    243 
    244                         psThreadJobAddPending (job);
    245                     } else {
    246                         if (!pmDarkCombine(outCell, fileGroup->readouts, darkOrdinates, darkNorm, iter, rej, maskVal)) {
    247                             goto ERROR;
    248                         }
    249                         fileGroup->busy = false;
     229                    // allocate a job
     230                    job = psThreadJobAlloc ("PPMERGE_DARK_COMBINE");
     231
     232                    // construct the arguments for this job
     233                    psArrayAdd (job->args, 1, outCell);
     234                    psArrayAdd (job->args, 1, fileGroup);
     235                    psArrayAdd (job->args, 1, darkOrdinates);
     236                    psArrayAdd (job->args, 1, darkNorm);
     237                    psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
     238                    psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
     239                    psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
     240
     241                    // call: pmDarkCombine(outCell, fileGroup->readouts, darkOrdinates, darkNorm, iter, rej, maskVal);
     242                    if (!psThreadJobAddPending (job)) {                 
     243                        goto ERROR;
    250244                    }
    251245                    break;
     
    253247                  case PPMERGE_TYPE_FLAT:
    254248                  case PPMERGE_TYPE_FRINGE:
    255                     if (nThreads) {
    256                         // allocate a job
    257                         psThreadJob *job = psThreadJobAlloc ("PPMERGE_READOUT_COMBINE", 0);
    258 
    259                         // construct the arguments for this job
    260                         psArrayAdd (job->args, 1, outRO);
    261                         psArrayAdd (job->args, 1, fileGroup);
    262                         psArrayAdd (job->args, 1, zeros);
    263                         psArrayAdd (job->args, 1, scales);
    264                         psArrayAdd (job->args, 1, combination);
    265 
    266                         psThreadJobAddPending (job);
    267                     } else {
    268                         if (!pmReadoutCombine(outRO, fileGroup->readouts, zeros, scales, combination)) {
    269                             goto ERROR;
    270                         }
    271                         fileGroup->busy = false;
     249                    // allocate a job
     250                    job = psThreadJobAlloc ("PPMERGE_READOUT_COMBINE");
     251
     252                    // construct the arguments for this job
     253                    psArrayAdd (job->args, 1, outRO);
     254                    psArrayAdd (job->args, 1, fileGroup);
     255                    psArrayAdd (job->args, 1, zeros);
     256                    psArrayAdd (job->args, 1, scales);
     257                    psArrayAdd (job->args, 1, combination);
     258
     259                    // call: pmReadoutCombine(outRO, fileGroup->readouts, zeros, scales, combination);
     260                    if (!psThreadJobAddPending (job)) {
     261                        goto ERROR;
    272262                    }
    273263                    break;
     
    278268
    279269            // wait for the threads to finish and manage results
    280             if (nThreads) {
    281                 // wait here for the threaded jobs to finish
    282                 if (!psThreadPoolWait ()) {
    283                     psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
    284                     return false;
    285                 }
    286                 fprintf (stderr, "success for threaded jobs\n");
    287 
    288                 // we don't care about the results, just dump the done queue jobs
    289                 psThreadJob *job = NULL;
    290                 while ((job = psThreadJobGetDone()) != NULL) {
    291                     psFree (job);
    292                 }
     270            if (!psThreadPoolWait ()) {
     271                psError(PS_ERR_UNKNOWN, false, "Unable to combine images.");
     272                return false;
    293273            }
     274
     275            // we don't care about the results, just dump the done queue jobs
     276            psThreadJob *job = NULL;
     277            while ((job = psThreadJobGetDone()) != NULL) {
     278                psFree (job);
     279            }
     280
    294281            psFree(fileGroups);
    295282
     
    308295            }
    309296            psFree(inCells);
    310             fprintf (stdout, "done ppMergeLoop for cell : %f\n", psTimerMark ("ppMergeLoop"));
     297            // fprintf (stdout, "done ppMergeLoop for cell : %f\n", psTimerMark ("ppMergeLoop"));
    311298
    312299            // Plug supplementary images into their own FPAs
Note: See TracChangeset for help on using the changeset viewer.