Changeset 21163
- Timestamp:
- Jan 24, 2009, 10:52:26 AM (17 years ago)
- Location:
- trunk/psModules/src/objects
- Files:
-
- 2 edited
-
pmSourceFitSet.c (modified) (10 diffs)
-
pmSourceFitSet.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceFitSet.c
r20937 r21163 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $9 * @date $Date: 200 8-12-08 02:51:14$8 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-01-24 20:52:26 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 45 45 /********************* Source Model Set Functions ***************************/ 46 46 47 static pmSourceFitSetData *thisSet = NULL; 47 // these functions currently need to use this static variable because of the way psMinimizeLMM 48 // is implemented. We could re-work that structure, but for now it is probably easier to make 49 // this thread safe by pre-allocating separate static variables for each thread. 50 51 static psArray *fitSets = NULL; 52 static pthread_mutex_t fitSetInitMutex = PTHREAD_MUTEX_INITIALIZER; 53 54 // call this before launching the threads 55 bool pmSourceFitSetInit (int nThreads) { 56 57 if (!fitSets) { 58 fitSets = psArrayAlloc (PS_MAX (1, nThreads)); 59 } 60 61 // the allocated elements should be NULL on psArrayAlloc, 62 // and a previously allocated array of fitSets should have been cleared 63 // before pmSourceFitSetInit is called 64 for (int i = 0; i < fitSets->n; i++) { 65 psAssert (fitSets->data[i] == NULL, "failure to init or clear fitSets?"); 66 } 67 return true; 68 } 69 70 void pmSourceFitSetDone () { 71 psFree (fitSets); 72 } 48 73 49 74 static void pmSourceFitSetDataFree (pmSourceFitSetData *set) { … … 62 87 psMemSetDeallocator(set, (psFreeFunc) pmSourceFitSetDataFree); 63 88 64 set->modelSet = psMemIncrRefCounter (modelSet);65 set->paramSet = psArrayAlloc (modelSet->n);66 set->derivSet = psArrayAlloc (modelSet->n);89 set->modelSet = psMemIncrRefCounter (modelSet); 90 set->paramSet = psArrayAlloc (modelSet->n); 91 set->derivSet = psArrayAlloc (modelSet->n); 67 92 set->nParamSet = 0; 93 set->thread = pthread_self(); 68 94 69 95 for (int i = 0; i < modelSet->n; i++) { … … 88 114 } 89 115 116 pmSourceFitSetData *pmSourceFitSetDataSet (psArray *modelSet) { 117 118 pmSourceFitSetData *thisSet = NULL; 119 120 psAssert (fitSets, "pmSourceFitSetInit not called"); 121 122 // find the fitSet used by this thread 123 pthread_t id = pthread_self(); 124 125 // is our ID is already on the stack, abort. 126 // we do not need to lock to do this.... 127 for (int i = 0; i < fitSets->n; i++) { 128 thisSet = fitSets->data[i]; 129 if (!thisSet) continue; 130 if (thisSet->thread == id) { 131 break; 132 } 133 thisSet = NULL; 134 } 135 psAssert (thisSet == NULL, "pmSourceFitSetDataSet() called but previous entry not cleared"); 136 137 thisSet = pmSourceFitSetDataAlloc(modelSet); 138 139 pthread_mutex_lock (&fitSetInitMutex); 140 141 // find an entry that is NULL and place it there 142 for (int i = 0; i < fitSets->n; i++) { 143 if (fitSets->data[i]) continue; 144 fitSets->data[i] = thisSet; 145 pthread_mutex_unlock (&fitSetInitMutex); 146 return thisSet; 147 } 148 pthread_mutex_unlock (&fitSetInitMutex); 149 psAbort ("no empty slot for new pmSourceFitSetData"); 150 return NULL; 151 } 152 153 pmSourceFitSetData *pmSourceFitSetDataGet () { 154 155 psAssert (fitSets, "pmSourceFitSetInit not called"); 156 157 // find the fitSet used by this thread 158 pthread_t id = pthread_self(); 159 160 // can we find our fitSet? we do not need to lock to do this.... 161 pmSourceFitSetData *thisSet = NULL; 162 for (int i = 0; i < fitSets->n; i++) { 163 thisSet = fitSets->data[i]; 164 if (!thisSet) continue; 165 if (thisSet->thread == id) { 166 break; 167 } 168 thisSet = NULL; 169 } 170 psAssert (thisSet != NULL, "pmSourceFitSetDataGet() called, but no entry found"); 171 172 return thisSet; 173 } 174 175 void pmSourceFitSetDataClear () { 176 177 int i; 178 179 psAssert (fitSets, "pmSourceFitSetInit not called"); 180 181 // find the fitSet used by this thread 182 pthread_t id = pthread_self(); 183 184 // can we find our fitSet? we do not need to lock to do this.... 185 pmSourceFitSetData *thisSet = NULL; 186 for (i = 0; i < fitSets->n; i++) { 187 thisSet = fitSets->data[i]; 188 if (!thisSet) continue; 189 if (thisSet->thread == id) { 190 break; 191 } 192 thisSet = NULL; 193 } 194 psAssert (thisSet != NULL, "pmSourceFitSetDataClear() called, but no entry found"); 195 196 psFree (thisSet); 197 fitSets->data[i] = NULL; 198 return; 199 } 90 200 91 201 // this function is called with the full set of parameters and the beta values in a single vector … … 93 203 float *betas) 94 204 { 95 PS_ASSERT_PTR_NON_NULL(thisSet, false); 205 PS_ASSERT_PTR_NON_NULL(fitSets, false); 206 pmSourceFitSetData *thisSet = pmSourceFitSetDataGet(); 96 207 97 208 // nParam is the parameter in the full sequence. determine which single model this comes from … … 190 301 } 191 302 303 // set the model parameters for this fit set 192 304 bool pmSourceFitSetValues (pmSourceFitSetData *set, const psVector *dparam, 193 305 const psVector *param, pmSource *source, … … 242 354 psF32 pmSourceFitSetFunction(psVector *deriv, const psVector *param, const psVector *x) 243 355 { 244 PS_ASSERT_PTR_NON_NULL(thisSet, NAN); 356 pmSourceFitSetData *thisSet = pmSourceFitSetDataGet(); 357 245 358 float chisqSum = 0.0; 246 359 float chisqOne = 0.0; … … 391 504 yErr->n = nPix; 392 505 393 // create the FitSet and set the initial parameter guesses394 thisSet = pmSourceFitSetDataAlloc(modelSet);506 // create the FitSet for this thread and set the initial parameter guesses 507 pmSourceFitSetData *thisSet = pmSourceFitSetDataSet(modelSet); 395 508 396 509 // define param and deriv vectors for complete set of parameters … … 431 544 psFree (params); 432 545 psFree(constraint); 433 psFree (thisSet); 434 thisSet = NULL; 546 pmSourceFitSetDataClear(); // frees thisSet and removes if from the array of fitSets 435 547 return(false); 436 548 } … … 488 600 psFree(params); 489 601 psFree(dparams); 490 psFree(thisSet); 491 492 thisSet = NULL; 602 pmSourceFitSetDataClear(); // frees thisSet and removes if from the array of fitSets 493 603 494 604 bool rc = (onPic && fitStatus); -
trunk/psModules/src/objects/pmSourceFitSet.h
r15562 r21163 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $6 * @date $Date: 200 7-11-10 01:09:20$5 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2009-01-24 20:52:26 $ 7 7 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 8 8 */ … … 19 19 psArray *derivSet; 20 20 int nParamSet; 21 pthread_t thread; 21 22 } pmSourceFitSetData; 23 24 // use this function to init the fit sets based on the number of threads 25 bool pmSourceFitSetInit (int nThreads); 26 void pmSourceFitSetDone (); 22 27 23 28 // initialize data for a group of object models 24 29 pmSourceFitSetData *pmSourceFitSetDataAlloc (psArray *modelSet); 25 30 bool psMemCheckSourceFitSetData(psPtr ptr); 31 32 // functions for selecting the FitSet corresponding to the current thread 33 pmSourceFitSetData *pmSourceFitSetDataSet (psArray *modelSet); 34 pmSourceFitSetData *pmSourceFitSetDataGet (); 35 void pmSourceFitSetDataClear (); 26 36 27 37 // function used to set limits for a group of models
Note:
See TracChangeset
for help on using the changeset viewer.
