BIE |
/home/weinberg/src/BIE/include/LikelihoodComputation.h00001 // This is really -*- C++ -*- 00002 00003 #ifndef LikelihoodComputation_h 00004 #define LikelihoodComputation_h 00005 00006 #include <iostream> 00007 #include <iomanip> 00008 #include <fstream> 00009 00010 #include <cc++/thread.h> 00011 00012 #include "gvariable.h" 00013 00014 #include "BIEconfig.h" 00015 #include "Simulation.h" 00016 #include "BaseDataTree.h" 00017 #include "gfunction.h" 00018 #include "BIEmpi.h" 00019 00020 #include "RecordOutputStream.h" 00021 #include "MPIStreamFilter.h" 00022 #include "TessToolSender.h" 00023 00024 #include "Serializable.h" 00025 00026 00027 using namespace ost; 00028 00029 namespace BIE { 00030 00036 class Model; 00037 class TessToolSender; 00038 00040 struct thrd_pass_LikeComp { 00041 /* Sat Feb 16 16:32:39 EST 2008 -- bchoi 00042 * non-intrusive serialization code at the bottom of this file 00043 */ 00045 void *t; 00047 int command; 00049 int id; 00050 }; 00051 00052 00059 struct LikeState 00060 { 00061 /* Sat Feb 16 22:11:30 EST 2008 -- bchoi 00062 * non-intrusive serialization code at the bottom of this file 00063 */ 00065 double value; 00067 bool good; 00068 }; 00069 00070 00071 //+ CLICLASS LikelihoodComputation 00073 class LikelihoodComputation: public Serializable 00074 { 00075 00076 private: 00077 00078 /* Sun Apr 27 03:47:36 EDT 2008 00079 * This variable isn't initialized until this object gets passed 00080 * to TemperedSimulation object. (see init() function) 00081 * Trying 00082 */ 00083 Simulation* _simulation; 00084 /* Sat Feb 16 16:34:30 EST 2008 -- bchoi 00085 * not entirely sure this is the right thing to do.. serialize 00086 * semaphore??? 00087 */ 00088 Semaphore * suspendSem; 00089 00090 public: 00091 00093 LikelihoodComputation(); 00094 00096 virtual ~LikelihoodComputation(); 00097 00099 // Must be supplied in derived class. 00100 virtual double Likelihood(State &, int indx)=0; 00101 00102 00104 // Must be supplied in derived class. 00105 virtual double LikelihoodPrevious(State &, int indx)=0; 00106 00107 00109 virtual void init(Simulation*_simulation) { 00110 this->_simulation = _simulation; 00111 } 00112 00114 virtual Simulation* GetSimulation() { return _simulation;} 00115 00117 virtual Model* GetModel() { return _simulation->_model;} 00118 00120 virtual BaseDataTree* GetBaseDataTree() { return _simulation->_dist;} 00121 00123 virtual Integration* GetIntegration() { return _simulation->_intgr;} 00124 00126 virtual LikelihoodFunction* 00127 GetLikeProb() { return _simulation->LP;} 00128 00129 00130 00132 virtual void normEvaluateList(Model *model, Tile *tile, 00133 const vector<double>& x, 00134 const vector<double>& y, 00135 SampleDistribution* sampleDistribution, 00136 vector<double>& evaluations) = 0; 00137 00139 virtual void modelEvaluateList(Model *model, Tile *tile, 00140 const vector<double>& x, 00141 const vector<double>& y, 00142 SampleDistribution* sampleDistribution, 00143 vector< vector<double> >& evaluations) = 0; 00144 00145 00147 virtual void Granularity(int mpi_type) {}; 00148 00150 //+ CLIMETHOD void TileCompare 00152 void TileCompare() { DEBUG_LIKE = true; } 00153 00155 //+ CLIMETHOD void SetTessTool TessToolSender* 00157 void SetTessTool(TessToolSender *ttsender); 00158 00159 //+ CLIMETHOD void SampleNext 00161 void SampleNext(); 00162 00163 //+ CLIMETHOD void SampleNext int 00167 void SampleNext(int sessionid); 00168 00169 //+ CLIMETHOD void SwitchOnCLI 00171 void SwitchOnCLI(); 00172 00173 //+ CLIMETHOD void SuspendSimulation 00175 void SuspendSimulation(); 00176 00177 //+ CLIMETHOD void ResumeSimulation 00179 void ResumeSimulation(); 00180 00181 //+ CLIMETHOD Semaphore* getLikelihoodSem 00183 Semaphore* getLikelihoodSem() {return likelihoodSem;}; 00184 00185 //+ CLIMETHOD void setLikelihoodSem Semaphore* 00187 void setLikelihoodSem(Semaphore *s) {likelihoodSem = s;}; 00188 00189 //+ CLIMETHOD void setCLISem Semaphore* 00191 void setCLISem(Semaphore *s) {switchCLISem = s;}; 00192 00194 void TessToolSynchronize(); 00195 00197 virtual void InitializeTessToolTileDump(); 00198 00200 virtual void TessToolTileDump(Tile *t, SampleDistribution *sd, vector<double>& z); 00201 00203 virtual void FinalizeTessToolTileDump(); 00204 00206 virtual int getNumAndIdsOfTileMasters(int *num, int **idlist); 00207 00209 virtual void BuildTessToolTileDumpBaseStream(); 00210 00212 virtual RecordOutputStream *GetTessToolTileDumpBaseStream() {return rostrm;}; 00214 virtual void SetTessToolTileDumpBaseStream(RecordOutputStream *bstrm) { rostrm = bstrm;}; 00215 00217 virtual RecordOutputStream *AttachMPIFilterToTessTool(RecordOutputStream *rostrm); 00218 00220 virtual void UpdateTessTool(RecordType *rt, RecordOutputStream *rostrm, 00221 MPIStreamFilter *mpifilter); 00222 00224 virtual void TessToolTileDumpToBaseStream(Tile *t, SampleDistribution *sd, vector<double>& z); 00225 00227 00228 00229 void startThread(); 00231 void stopThread(); 00236 virtual void enslave_worker(void * arg) {}; 00237 00239 virtual void free_workers() {}; 00241 00247 virtual bool Serial() = 0; 00248 00249 protected: 00250 00252 thrd_pass_LikeComp td; 00253 00255 pthread_t *t; 00256 00258 00259 bool threading_on; 00260 00262 int parent_id; 00263 00265 Semaphore likelihoodMutex; 00266 00268 void thread_fork(int command); 00269 00271 bool DEBUG_LIKE; 00272 00274 void TileDump(Tile *t, SampleDistribution *sd, vector<double>& z); 00275 00277 void SwitchedOnCLI(); 00278 00282 void ResumedSimulation(); 00283 00287 void SuspendedSimulation(); 00288 00290 void DetachTessTool(); 00291 00293 int encode_command(int); 00294 00296 int decode_command(int); 00297 00299 TessToolSender * tesstool; 00300 00302 00303 00304 int requestSynchronization; 00306 int sampleNext; 00308 int switchCliOn; 00310 int suspendSimulation; 00312 int resumeSimulation; 00314 int detachTessTool; 00316 bool _builtTTBaseStream; 00318 00320 RecordOutputStream * rostrm; 00321 00323 int _sessionId; 00325 int _nextSessionId; 00326 00328 void setPriorFrontier(); 00329 00331 void setCurrentFrontier(); 00332 00334 Frontier *fd_temp; 00335 00337 void StateToBuffer(State&, double*, unsigned int size); 00338 00340 void BufferToState(State&, double*, unsigned int size); 00341 00343 virtual bool Slaves() { return false; } 00344 00345 // AUTO GENERATED BY ../persistence/autopersist.py 00346 private: 00347 friend class boost::serialization::access; 00348 template<class Archive> 00349 void serialize(Archive & ar, const unsigned int version) { 00350 this->pre_serialize(ar, version); 00351 try { 00352 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Serializable); 00353 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00354 } 00355 try { 00356 ar & BOOST_SERIALIZATION_NVP(_simulation); 00357 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00358 } 00359 try { 00360 ar & BOOST_SERIALIZATION_NVP(threading_on); 00361 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00362 } 00363 try { 00364 ar & BOOST_SERIALIZATION_NVP(parent_id); 00365 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00366 } 00367 try { 00368 ar & BOOST_SERIALIZATION_NVP(DEBUG_LIKE); 00369 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00370 } 00371 try { 00372 ar & BOOST_SERIALIZATION_NVP(requestSynchronization); 00373 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00374 } 00375 try { 00376 ar & BOOST_SERIALIZATION_NVP(sampleNext); 00377 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00378 } 00379 try { 00380 ar & BOOST_SERIALIZATION_NVP(switchCliOn); 00381 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00382 } 00383 try { 00384 ar & BOOST_SERIALIZATION_NVP(suspendSimulation); 00385 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00386 } 00387 try { 00388 ar & BOOST_SERIALIZATION_NVP(resumeSimulation); 00389 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00390 } 00391 try { 00392 ar & BOOST_SERIALIZATION_NVP(detachTessTool); 00393 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00394 } 00395 try { 00396 ar & BOOST_SERIALIZATION_NVP(_builtTTBaseStream); 00397 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00398 } 00399 try { 00400 ar & BOOST_SERIALIZATION_NVP(_sessionId); 00401 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00402 } 00403 try { 00404 ar & BOOST_SERIALIZATION_NVP(_nextSessionId); 00405 BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION; 00406 } 00407 this->post_serialize(ar, version); 00408 } 00409 00410 }; 00411 } // namespace BIE 00412 00413 namespace boost { 00414 namespace serialization { 00415 template<class Archive> 00416 inline void serialize(Archive& ar, 00417 thrd_pass_LikeComp& t, 00418 const unsigned int file_version) { 00419 LikelihoodComputation* temp = (LikelihoodComputation*)t.t; 00420 ar & boost::serialization::make_nvp("pointer", temp); 00421 ar & boost::serialization::make_nvp("command", t.command); 00422 ar & boost::serialization::make_nvp("id", t.id); 00423 } 00424 00425 template<class Archive> 00426 inline void serialize(Archive& ar, 00427 LikeState& ls, 00428 const unsigned int file_version) { 00429 ar & boost::serialization::make_nvp("value", ls.value); 00430 ar & boost::serialization::make_nvp("good", ls.good); 00431 } 00432 } 00433 } 00434 00435 BIE_CLASS_EXPORT_KEY(BIE::LikelihoodComputation) 00436 #endif Send suggestions, questions, and feedback to WEINBERG at ASTRO dot UMASS dot EDU. Documentation generated at Fri Mar 26 00:35:10 2010 by
|