IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 16, 2012, 2:38:37 PM (14 years ago)
Author:
bills
Message:

Several changes to psphot and psphotStack

  1. Add function to compute the memory used by all of the sources
  2. Add function to log memory stats in psphotStack
  3. Don't load or psf match the convolved images into psphotStack unless they are needed.

This saves a lot of time if RADIAL_APERTURES are not enabled and we are measuring on the raw images

  1. Several improvements to the error handling in the Kron measurements. In particular the Mrf value

was being treated as positive when both the numerator and denomiator were negative. This is the cause
of many of the very large kron radius measurements. Set Mrf to NAN in these cases.

  1. Skip kron measurments for source if the previous Mrf measurement was NAN earlier in the process.

This saves memory by not expanding the source images when the kron measurements were actually going
to be skipped

  1. Remove the hack cut on fwhmMaj. Managing the kron radius measurements better fixes the memory explosion

that that helped to reduce.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotStackReadout.c

    r34266 r34317  
    22
    33static bool psphotStackLoadWCS(pmConfig *config, const pmFPAview *view, const char *filerule);
     4static void logMemStats(const char *heading);
    45
    56// we have 3 possible real filesets:
     
    5152    // by the multiple threads, not the total time used by all threads.
    5253    psTimerStart ("psphotReadout");
     54
     55    logMemStats("Start");
    5356
    5457    pmModelClassSetLimits(PM_MODEL_LIMITS_LAX); // allow models to have ugly fits (eg, central cusp)
     
    8285    }
    8386
    84     // Generate the mask and weight images (if not supplied) and set mask bits
     87    // Generate the mask and weight images (if not supplied) and set mask bits.
     88    // This also insures that all invalid pixels are masked (this is done for STACK_CNV in psphotStackMatchPSFs)
    8589    if (!psphotSetMaskAndVariance (config, view, STACK_DET)) {
     90        return psphotReadoutCleanup (config, view, STACK_SRC);
     91    }
     92    if (!psphotSetMaskAndVariance (config, view, STACK_OUT)) {
    8693        return psphotReadoutCleanup (config, view, STACK_SRC);
    8794    }
     
    151158    // psphotDumpTest (config, view, STACK_SRC);
    152159    psMemDump("sourcestats");
     160    logMemStats("sourcestats");
    153161
    154162    // classify sources based on moments, brightness
     
    196204    // window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments)
    197205    // but iterates to an appropriately larger size
    198     psphotKronIterate(config, view, STACK_SRC);
     206    logMemStats("before.kron.1");
     207    psphotKronIterate(config, view, STACK_SRC, 1);
     208    logMemStats("after.kron.1");
    199209
    200210    // identify CRs and extended sources
     
    208218    psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources)
    209219
     220    logMemStats("pass1");
    210221
    211222    // if we only do one pass, skip to extended source analysis
     
    299310    }
    300311
     312    logMemStats("prematch");
     313
    301314    // generate the objects (objects unify the sources from the different images) NOTE: could
    302315    // this just match the detections for the chisq image, and not bother measuring the source
     
    331344    // re-measure the kron mags with models subtracted
    332345    // psphotKronMasked(config, view, STACK_SRC);
    333     psphotKronIterate(config, view, STACK_SRC);
     346    logMemStats("before.kron.2");
     347    psphotKronIterate(config, view, STACK_SRC, 2);
     348    logMemStats("after.kron.2");
    334349
    335350    // measure source size for the remaining sources
     
    353368        return psphotReadoutCleanup (config, view, STACK_SRC);
    354369    }
    355 
    356370
    357371    bool radial_apertures = psMetadataLookupBool(NULL, recipe, "RADIAL_APERTURES");
     
    419433        // psphotEfficiency wants to have the PSF of the image, but since we are measuring on
    420434        // the convolved images we need to generate PSFs for the DET images
    421         if (!psphotChoosePSF (config, view, STACK_DET, false)) { // pass 1
     435        if (!psphotChoosePSF (config, view, STACK_DET, false)) {
    422436            psLogMsg ("psphot", 3, "failure to construct a psf model for raw input");
    423437            return psphotReadoutCleanup (config, view, STACK_DET);
     
    429443    }
    430444    psphotCopyEfficiency (config, view, STACK_OUT, STACK_DET);
     445
     446    logMemStats("final");
     447#if (1)
     448    psphotSourceMemory(config, view, STACK_SRC);
     449    psphotSourceMemory(config, view, STACK_OUT);
     450#endif
    431451
    432452    // replace failed sources?
     
    474494    return true;
    475495}
     496
     497// read the memory usage data from /proc and log them out
     498// This will only work on a system that has /proc (not MacOS for instance) but since this function just
     499// tries to open and read from a file it is safe
     500static void logMemStats(const char *heading) {
     501
     502    // file containing memory statistics for this process proc. See proc(5)
     503    const char* statm_path = "/proc/self/statm";
     504
     505    FILE *f = fopen(statm_path,"r");
     506    if (!f) {
     507        psLogMsg ("psphot", PS_LOG_WARN, "failed to open %s", statm_path);
     508        return;
     509    }
     510
     511    unsigned long vmSize, resident, share, text, lib, data;
     512
     513    int nread;
     514    nread = fscanf(f,"%ld %ld %ld %ld %ld %ld", &vmSize, &resident, &share, &text, &lib, &data);
     515    fclose(f);
     516    if (nread != 6) {
     517        psLogMsg ("psphot", PS_LOG_WARN, "failed to read 6 items from %s", statm_path);
     518        return;
     519    }
     520 
     521    // assuming 4 KB page size here
     522#   define PAGES_TO_MB(_v) (_v * 4.096 / 1024.)
     523    psLogMsg ("psphot", PS_LOG_INFO, "Memory usage at %20s: Total VmSize: %8.2f MB   Resident %8.2f MB   Data: %8.2f MB\n",
     524        heading, PAGES_TO_MB(vmSize), PAGES_TO_MB(resident), PAGES_TO_MB(data));
     525}
     526
     527
    476528
    477529/* here is the process:
Note: See TracChangeset for help on using the changeset viewer.