--- trunk/gadget/ecosystem.cc 2014/02/10 17:09:07 1 +++ trunk/gadget/ecosystem.cc 2015/07/23 19:00:38 11 @@ -1,6 +1,14 @@ #include "ecosystem.h" #include "runid.h" #include "global.h" +#ifndef NO_OPENMP +#include +#endif + +#ifndef NO_OPENMP +extern Ecosystem** EcoSystems; +//extern StochasticData* data; +#endif Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { @@ -32,7 +40,9 @@ infile.open(filename, ios::in); handle.checkIfFailure(infile, filename); handle.Open(filename); - this->readOptimisation(commin); + unsigned seed; + main.getForcePrint(); + this->readOptimisation(commin, main.getSeed()); handle.Close(); infile.close(); infile.clear(); @@ -101,11 +111,31 @@ void Ecosystem::Optimise() { int i; for (i = 0; i < optvec.Size(); i++) { +#ifndef NO_OPENMP + int j, numThr = omp_get_max_threads ( ); + DoubleVector v = this->getValues(); + for (j = 0; j < numThr; j++) + EcoSystems[j]->Update(v); +#endif optvec[i]->OptimiseLikelihood(); this->writeOptValues(); } } +#ifdef GADGET_OPENMP +void Ecosystem::OptimiseOMP() { + int i; + for (i = 0; i < optvec.Size(); ++i) { + optvec[i]->OptimiseLikelihoodOMP(); + int j, numThr = omp_get_max_threads ( ); + DoubleVector v = this->getValues(); + for (j = 0; j < numThr; j++) + EcoSystems[j]->Update(v); + this->writeOptValues(); + } +} +#endif + double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { int i, j; @@ -148,7 +178,13 @@ for (i = 0; i < likevec.Size(); i++) tmpvec[i] = likevec[i]->getUnweightedLikelihood(); - handle.logMessage(LOGINFO, "\nAfter a total of", funceval, "function evaluations the best point found is"); + int iters = 0; +#ifndef NO_OPENMP + int numThr = omp_get_max_threads ( ); + for (i = 0; i < numThr; i++) + iters += EcoSystems[i]->getFuncEval(); +#endif + handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is"); keeper->writeBestValues(); handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); handle.logMessage(LOGINFO, tmpvec); @@ -158,6 +194,27 @@ handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); } +//#ifdef GADGET_OPENMP +//void Ecosystem::writeOptValuesOMP() { +// int i; +// DoubleVector tmpvec(likevec.Size(), 0.0); +// for (i = 0; i < likevec.Size(); ++i) +// tmpvec[i] = likevec[i]->getUnweightedLikelihood(); +// +// int iters = 0, numThr = omp_get_max_threads ( ); +// for (i = 0; i < numThr; i++) +// iters += EcoSystems[i]->getFuncEval(); +// handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is"); +// keeper->writeBestValues(); +// handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); +// handle.logMessage(LOGINFO, tmpvec); +// if (!isZero(keeper->getBestLikelihoodScore())) // no better point has been found +// handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore()); +// else +// handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); +//} +//#endif + void Ecosystem::writeInitialInformation(const char* const filename) { keeper->openPrintFile(filename); keeper->writeInitialInformation(likevec);