IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 31, 2008, 2:13:59 PM (18 years ago)
Author:
eugene
Message:

adding multithread capability

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMergeLoop_Threaded.c

    r18757 r18839  
    3636
    3737    // General combination parameters
    38     int rows = psMetadataLookupS32(NULL, arguments, "ROWS"); // Number of rows to read per chunk
    3938    int iter = psMetadataLookupS32(NULL, arguments, "ITER"); // Number of rejection iterations
    4039    float rej = psMetadataLookupF32(NULL, arguments, "REJ"); // Rejection level
     
    175174                fileGroup->read = false;
    176175                fileGroup->busy = false;
     176                fileGroup->lastScan = 0;
     177                fileGroup->firstScan = 0;
    177178                fileGroups->data[i] = fileGroup;
    178179            }
    179180
     181            // call the init functions
     182            switch (type) {
     183              case PPMERGE_TYPE_BIAS:
     184              case PPMERGE_TYPE_FLAT:
     185              case PPMERGE_TYPE_FRINGE:
     186                psAssert (fileGroups->n > 0, "no valid file groups defined");
     187                ppMergeFileGroup *fileGroup = fileGroups->data[0];
     188                if (!pmReadoutCombinePrepare(outRO, fileGroup->readouts, combination)) {
     189                    goto ERROR;
     190                }
     191                break;
     192
     193              default:
     194                fprintf (stderr, "not yet ready");
     195                goto ERROR;
     196            }
     197
    180198            // Read input data by chunks
     199            // psTimerStart ("ppMergeLoop");
    181200            for (int numChunk = 0; true; numChunk++) {
    182                
     201
     202                bool status = false;
    183203                ppMergeFileGroup *fileGroup = ppMergeReadChunk (&status, fileGroups, config, numChunk);
    184204                if (!status) goto ERROR;
    185205                if (!fileGroup) break;
    186206
     207                psThreadJob *job = NULL;
     208
    187209                switch (type) {
    188210                  case PPMERGE_TYPE_SHUTTER:
    189                     if (nThreads) {
    190                         // allocate a job
    191                         psThreadJob *job = psThreadJobAlloc ("PPMERGE_SHUTTER_CORRECTION", 0);
    192 
    193                         // construct the arguments for this job
    194                         psArrayAdd (job->args, 1, outRO);
    195                         psArrayAdd (job->args, 1, fileGroup);
    196                         psArrayAdd (job->args, 1, psScalarAlloc(shutterRef, PS_TYPE_F32))
    197                         psArrayAdd (job->args, 1, shutters->data[cellNum]);
    198                         psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
    199                         psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
    200                         psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
    201 
    202                         psThreadJobAddPending (job);
    203                     } else {
    204                         if (!pmShutterCorrectionGenerate(outRO, NULL, fileGroup->readouts, shutterRef, shutters->data[cellNum], iter, rej, maskVal)) {
    205                             goto ERROR;
    206                         }
    207                         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;
    208226                    }
    209227                    break;
    210228                  case PPMERGE_TYPE_DARK:
    211                     if (nThreads) {
    212                         // allocate a job
    213                         psThreadJob *job = psThreadJobAlloc ("PPMERGE_DARK_COMBINE", 0);
    214 
    215                         // construct the arguments for this job
    216                         psArrayAdd (job->args, 1, outCell);
    217                         psArrayAdd (job->args, 1, fileGroup);
    218                         psArrayAdd (job->args, 1, darkOrdinates);
    219                         psArrayAdd (job->args, 1, darkNorm);
    220                         psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
    221                         psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
    222                         psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
    223 
    224                         psThreadJobAddPending (job);
    225                     } else {
    226                         if (!pmDarkCombine(outCell, fileGroup->readouts, darkOrdinates, darkNorm, iter, rej, maskVal)) {
    227                             goto ERROR;
    228                         }
    229                         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;
    230244                    }
    231245                    break;
     
    233247                  case PPMERGE_TYPE_FLAT:
    234248                  case PPMERGE_TYPE_FRINGE:
    235                     if (nThreads) {
    236                         // allocate a job
    237                         psThreadJob *job = psThreadJobAlloc ("PPMERGE_READOUT_COMBINE", 0);
    238 
    239                         // construct the arguments for this job
    240                         psArrayAdd (job->args, 1, outRO);
    241                         psArrayAdd (job->args, 1, fileGroup);
    242                         psArrayAdd (job->args, 1, zeros);
    243                         psArrayAdd (job->args, 1, scales);
    244                         psArrayAdd (job->args, 1, combination);
    245 
    246                         psThreadJobAddPending (job);
    247                     } else {
    248                         if (!pmReadoutCombine(outRO, fileGroup->readouts, zeros, scales, combination)) {
    249                             goto ERROR;
    250                         }
    251                         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;
    252262                    }
    253263                    break;
     
    258268
    259269            // wait for the threads to finish and manage results
    260             if (nThreads) {
    261                 // wait here for the threaded jobs to finish
    262                 if (!psThreadPoolWait ()) {
    263                     psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
    264                     return false;
    265                 }
    266                 fprintf (stderr, "success for threaded jobs\n");
    267 
    268                 // we don't care about the results, just dump the done queue jobs
    269                 psThreadJob *job = NULL;
    270                 while ((job = psThreadJobGetDone()) != NULL) {
    271                     psFree (job);
    272                 }
     270            if (!psThreadPoolWait ()) {
     271                psError(PS_ERR_UNKNOWN, false, "Unable to combine images.");
     272                return false;
    273273            }
     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
     281            psFree(fileGroups);
    274282
    275283            // Get list of cells for concepts averaging
    276284            psList *inCells = psListAlloc(NULL); // List of cells
    277285            for (int i = 0; i < numFiles; i++) {
    278                 pmReadout *readout = readouts->data[i]; // Readout of interest
    279                 psListAdd(inCells, PS_LIST_TAIL, readout->parent);
     286                pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i);
     287                pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell
     288                psListAdd(inCells, PS_LIST_TAIL, inCell);
    280289            }
    281290            if (!pmConceptsAverageCells(outCell, inCells, NULL, NULL, true)) {
     
    286295            }
    287296            psFree(inCells);
    288 
    289             psFree(fileGroups);
     297            // fprintf (stdout, "done ppMergeLoop for cell : %f\n", psTimerMark ("ppMergeLoop"));
    290298
    291299            // Plug supplementary images into their own FPAs
Note: See TracChangeset for help on using the changeset viewer.