Changeset 20399
- Timestamp:
- Oct 26, 2008, 2:21:25 PM (18 years ago)
- Location:
- branches/eam_branch_20081026/psphot
- Files:
-
- 1 added
- 8 edited
-
doc/notes.txt (modified) (1 diff)
-
src/Makefile.am (modified) (1 diff)
-
src/psphot.c (modified) (1 diff)
-
src/psphot.h (modified) (3 diffs)
-
src/psphotArguments.c (modified) (1 diff)
-
src/psphotCleanup.c (modified) (1 diff)
-
src/psphotGuessModels.c (modified) (8 diffs)
-
src/psphotReadout.c (modified) (2 diffs)
-
src/psphotSetThreads.c (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20081026/psphot/doc/notes.txt
r18555 r20399 1 2 2008.10.26 3 4 (note: this is unoptimized) 5 0 threads: built models for 3921 objects: 15.223455 sec 6 built models for 2868 objects: 10.698732 sec 7 8 2 threads: built models for 3921 objects: 37.529655 sec 9 built models for 2862 objects: 28.142142 sec 10 11 (clearly, the threading is doing bad things, at least without optimization..) 12 13 old code (no threading): 14 built models for 3923 objects: 15.265046 sec 15 built models for 2842 objects: 10.840331 sec 16 17 (so, the threaded version without threading is OK) 1 18 2 19 2008.06.25 -
branches/eam_branch_20081026/psphot/src/Makefile.am
r20079 r20399 18 18 19 19 libpsphot_la_SOURCES = \ 20 psphotSetThreads.c \ 20 21 psphotErrorCodes.c \ 21 22 psphotImageQuality.c \ -
branches/eam_branch_20081026/psphot/src/psphot.c
r14655 r20399 12 12 psphotErrorRegister(); // register our error codes/messages 13 13 psphotModelClassInit (); // load implementation-specific models 14 psphotSetThreads (); 15 14 16 15 17 // load command-line arguments, options, and system config data -
branches/eam_branch_20081026/psphot/src/psphot.h
r20080 r20399 13 13 #define PSPHOT_RECIPE_PSF_FAKE_ALLOW "PSF.FAKE.ALLOW" // Name for recipe component permitting fake PSFs 14 14 15 typedef struct { 16 pmReadout *readout; 17 psArray *sources; 18 pmPSF *psf; 19 psRegion *region; 20 psMaskType maskVal; 21 psMaskType markVal; 22 } psphotGuessModelForRegionArgs; 15 23 16 24 // top-level psphot functions … … 41 49 bool psphotMomentsStats (pmReadout *readout, psMetadata *recipe, psArray *sources); 42 50 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final); 43 bool psphotGuessModels (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf); 51 bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf); 52 bool psphotGuessModelForRegion (psphotGuessModelForRegionArgs *args); 44 53 bool psphotBlendFit (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf); 45 54 bool psphotReplaceUnfitSources (psArray *sources, psMaskType maskVal); … … 51 60 bool psphotExtendedSourceAnalysis (pmReadout *readout, psArray *sources, psMetadata *recipe); 52 61 bool psphotExtendedSourceFits (pmReadout *readout, psArray *sources, psMetadata *recipe); 62 bool psphotSetThreads (); 53 63 54 64 // used by psphotFindDetections -
branches/eam_branch_20081026/psphot/src/psphotArguments.c
r19869 r20399 29 29 // these options override the PSPHOT recipe values loaded from recipe files 30 30 psMetadata *options = pmConfigRecipeOptions (config, PSPHOT_RECIPE); 31 32 // Number of threads 33 if ((N = psArgumentGet(argc, argv, "-threads"))) { 34 psArgumentRemove(N, &argc, argv); 35 int nThreads = atoi(argv[N]); 36 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NTHREADS", 0, "number of psphot threads", nThreads); 37 psArgumentRemove(N, &argc, argv); 38 39 // create the thread pool with number of desired threads, supplying our thread launcher function 40 // XXX need to determine the number of threads from the config data 41 psThreadPoolInit (nThreads); 42 } 43 psphotSetThreads(); 31 44 32 45 // run the test model (requires X,Y coordinate) -
branches/eam_branch_20081026/psphot/src/psphotCleanup.c
r14655 r20399 5 5 psFree (config); 6 6 7 psThreadPoolFinalize (); 7 8 psTimerStop (); 8 9 psMemCheckCorruption (stderr, true); -
branches/eam_branch_20081026/psphot/src/psphotGuessModels.c
r19881 r20399 1 1 # include "psphotInternal.h" 2 3 bool psphotChooseCellSizes (int *Cx, int *Cy, pmReadout *readout, int nThreads); 4 psphotGuessModelForRegionArgs *psphotGuessModelForRegionArgsAlloc(); 5 bool psphotGuessModelForRegion (psphotGuessModelForRegionArgs *args); 2 6 3 7 // A guess for when the moments aren't available … … 16 20 } 17 21 22 # define NFILL 4 23 18 24 // construct an initial PSF model for each object 19 bool psphotGuessModels (pm Readout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf) {25 bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) { 20 26 21 27 bool status; 22 28 23 29 psTimerStart ("psphot"); 30 31 // select the appropriate recipe information 32 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 33 assert (recipe); 34 35 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 36 if (!status) { 37 nThreads = 0; 38 } 24 39 25 40 // bit-masks to test for good/bad pixels … … 37 52 psphotInitRadiusPSF (recipe, psf->type); 38 53 54 // the strategy here is to divide the image into 2x2 blocks of cells and cycle through 55 // the four discontiguous sets of cells, threading all within a set and blocking between 56 // sets 57 58 // we divide the image region into 2*2 blocks of size Nx*Ny, the image will have 59 // Cx*Cy blocks so that (2Nx)Cx = numCols, (2Ny)Cy = numRows. We want to choose Cx and 60 // Cy so that (2Nx)Cx * (2Ny)Cy = 4 * NFILL * nThreads -- each of the four sets of cells 61 // has enough cells to allow NFILL cells for each thread (to better distribute heavy and 62 // light load cells 63 64 // choose Cx, Cy: 65 int Cx = 1, Cy = 1; 66 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 67 68 // the array runs from readout->image->col0 to readout->image->col0 + readout->image->numCols 69 int Xo = readout->image->col0; 70 int Yo = readout->image->row0; 71 int Nx = readout->image->numCols / (2*Cx); 72 int Ny = readout->image->numRows / (2*Cy); 73 74 // we can thread all of the cells within a set, but need to block between sets 75 for (int jy = 0; jy < 2; jy++) { 76 for (int jx = 0; jx < 2; jx++) { 77 78 // generate jobs for all of the Cx*Cy cells in this set 79 for (int ix = 0; ix < Cx; ix++) { 80 for (int iy = 0; iy < Cy; iy++) { 81 82 int x0 = (2*ix + jx)*Nx + Xo; 83 int x1 = x0 + Nx; 84 85 int y0 = (2*iy + jy)*Ny + Yo; 86 int y1 = y0 + Ny; 87 88 if (readout->image->numCols + Xo - x1 < Nx) { 89 x1 = readout->image->numCols + Xo; 90 } 91 if (readout->image->numRows + Yo - y1 < Ny) { 92 y1 = readout->image->numRows + Yo; 93 } 94 95 // fprintf (stderr, "launch %d,%d - %d,%d\n", x0, y0, x1, y1); 96 97 psRegion *cellRegion = psRegionAlloc (x0, x1, y0, y1); 98 *cellRegion = psRegionForImage (readout->image, *cellRegion); 99 // if we got the math above right, this should be a NOP 100 101 psphotGuessModelForRegionArgs *args = psphotGuessModelForRegionArgsAlloc(); 102 args->readout = psMemIncrRefCounter(readout); 103 args->sources = psMemIncrRefCounter(sources); 104 args->psf = psMemIncrRefCounter(psf); 105 args->region = psMemIncrRefCounter(cellRegion); 106 107 args->maskVal = maskVal; 108 args->markVal = markVal; 109 110 // allocate a job -- if threads are not defined, this just runs the job 111 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL"); 112 psArrayAdd(job->args, 1, args); 113 if (!psThreadJobAddPending(job)) { 114 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 115 return false; 116 } 117 psFree(cellRegion); 118 psFree(job); 119 psFree(args); 120 } 121 } 122 123 // wait for the threads to finish and manage results 124 // wait here for the threaded jobs to finish 125 // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy); 126 if (!psThreadPoolWait (false)) { 127 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 128 return false; 129 } 130 131 // we have only supplied one type of job, so we can assume the types here 132 psThreadJob *job = NULL; 133 while ((job = psThreadJobGetDone()) != NULL) { 134 // we have no returned data from this operation 135 if (job->args->n < 1) { 136 fprintf (stderr, "error with job\n"); 137 } 138 psFree(job); 139 } 140 } 141 } 142 143 psLogMsg ("psphot.models", 4, "built models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot")); 144 return true; 145 } 146 147 static void psphotGuessModelForRegionArgsFree(psphotGuessModelForRegionArgs *args) 148 { 149 psFree(args->readout); 150 psFree(args->sources); 151 psFree(args->psf); 152 psFree(args->region); 153 return; 154 } 155 156 psphotGuessModelForRegionArgs *psphotGuessModelForRegionArgsAlloc() 157 { 158 psphotGuessModelForRegionArgs *args = psAlloc(sizeof(psphotGuessModelForRegionArgs)); 159 psMemSetDeallocator(args, (psFreeFunc)psphotGuessModelForRegionArgsFree); 160 161 args->readout = NULL; 162 args->sources = NULL; 163 args->psf = NULL; 164 args->region = NULL; 165 166 args->maskVal = 0; 167 args->markVal = 0; 168 return args; 169 } 170 171 // construct models only for sources in the specified region 172 bool psphotGuessModelForRegion (psphotGuessModelForRegionArgs *args) { 173 174 pmReadout *readout = args->readout; 175 psArray *sources = args->sources; 176 pmPSF *psf = args->psf; 177 psRegion *region = args->region; 178 psMaskType maskVal = args->maskVal; 179 psMaskType markVal = args->markVal; 180 181 int nSrc = 0; 182 39 183 for (int i = 0; i < sources->n; i++) { 40 184 pmSource *source = sources->data[i]; … … 43 187 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 44 188 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 45 189 if (!source->peak) continue; 190 191 if (source->peak->xf < region->x0) continue; 192 if (source->peak->yf < region->y0) continue; 193 if (source->peak->xf >= region->x1) continue; 194 if (source->peak->yf >= region->y1) continue; 195 196 nSrc ++; 197 46 198 // XXX if a source is faint, it will not have moments measured. 47 199 // it must be modelled as a PSF. In this case, we need to use … … 53 205 } else { 54 206 // use the source moments, etc to guess basic model parameters 55 modelEXT = pmSourceModelGuess (source, psf->type); 207 modelEXT = pmSourceModelGuess (source, psf->type); // ALLOC 56 208 if (!modelEXT) { 57 209 modelEXT = wildGuess(source, psf); … … 68 220 69 221 // set PSF parameters for this model (apply 2D shape model) 70 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); 222 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC 71 223 if (modelPSF == NULL) { 72 224 psError(PSPHOT_ERR_PSF, false, … … 92 244 // XXX need to define the guess flux? 93 245 // set the fit radius based on the object flux limit and the model 246 // this function affects the mask pixels 94 247 psphotCheckRadiusPSF (readout, source, modelPSF, markVal); 95 248 … … 99 252 100 253 pmSourceCacheModel (source, maskVal); 101 } 102 psLogMsg ("psphot.models", 4, "built models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot")); 254 255 } 256 257 // fprintf (stderr, "%d for region %lf,%lf - %lf,%lf\n", nSrc, region->x0, region->y0, region->x1, region->y1); 103 258 return true; 104 259 } 105 260 106 // XXX do we always know which model is supposed to be used? 261 bool psphotChooseCellSizes (int *Cx, int *Cy, pmReadout *readout, int nThreads) { 262 263 int nCells = nThreads * NFILL; // number of cells in a single set 264 int C = sqrt(nCells) + 0.5; 265 266 // we need to assign Cx and Cy based on the dimensionality of the image 267 // crude way to find most evenly balanced factors of nCells: 268 for (int i = C; i >= 1; i--) { 269 int C1 = nCells / C; 270 int C2 = nCells / C1; 271 if (C1*C2 != nCells) continue; 272 273 if (readout->image->numRows > readout->image->numCols) { 274 *Cx = PS_MAX (C1, C2); 275 *Cy = PS_MIN (C1, C2); 276 } else { 277 *Cx = PS_MAX (C1, C2); 278 *Cy = PS_MIN (C1, C2); 279 } 280 return true; 281 } 282 *Cx = 1; 283 *Cy = 1; 284 285 return true; 286 } -
branches/eam_branch_20081026/psphot/src/psphotReadout.c
r20171 r20399 149 149 150 150 // construct an initial model for each object 151 psphotGuessModels ( readout, sources, recipe, psf);151 psphotGuessModels (config, readout, sources, psf); 152 152 153 153 // XXX test output of models … … 207 207 208 208 // create full input models 209 psphotGuessModels ( readout, newSources, recipe, psf);209 psphotGuessModels (config, readout, newSources, psf); 210 210 211 211 // replace all sources so fit below applies to all at once
Note:
See TracChangeset
for help on using the changeset viewer.
