--- trunk/gadget/ecosystem.cc 2014/02/10 17:09:07 1 +++ trunk/gadget/ecosystem.cc 2016/05/25 16:36:33 19 @@ -1,11 +1,23 @@ #include "ecosystem.h" #include "runid.h" #include "global.h" +#include +#ifdef _OPENMP +#include +#endif + +#ifdef _OPENMP +extern Ecosystem** EcoSystems; +//extern StochasticData* data; +#endif +extern volatile int interrupted_print; + +time_t starttime, stoptime; Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { funceval = 0; - interrupted = 0; + //interrupted = 0; likelihood = 0.0; keeper = new Keeper; @@ -32,7 +44,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,7 +115,19 @@ void Ecosystem::Optimise() { int i; for (i = 0; i < optvec.Size(); i++) { - optvec[i]->OptimiseLikelihood(); + time(&starttime); +#ifdef _OPENMP + int j, numThr = omp_get_max_threads ( ); + DoubleVector v = this->getValues(); + for (j = 0; j < numThr; j++) + EcoSystems[j]->Update(v); +#endif +#ifdef SPECULATIVE + optvec[i]->OptimiseLikelihoodOMP(); +#else + optvec[i]->OptimiseLikelihood(); +#endif + time(&stoptime); this->writeOptValues(); } } @@ -148,7 +174,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; +#ifdef _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); @@ -156,6 +188,8 @@ handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore()); else handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); + + handle.logMessage(LOGINFO, "\n Runtime for the algorithm was ", difftime(stoptime, starttime)," seconds\n"); } void Ecosystem::writeInitialInformation(const char* const filename) { @@ -168,11 +202,11 @@ } void Ecosystem::writeParams(const char* const filename, int prec) const { - if ((funceval > 0) && (interrupted == 0)) { + if ((funceval > 0) && (interrupted_print == 0)) { //JMB - print the final values to any output files specified //in case they have been missed by the -print value if (printinfo.getPrint()) keeper->writeValues(likevec, printinfo.getPrecision()); } - keeper->writeParams(optvec, filename, prec, interrupted); + keeper->writeParams(optvec, filename, prec, interrupted_print); }