--- trunk/gadget/ecosystem.cc 2015/07/23 19:00:38 11 +++ trunk/gadget/ecosystem.cc 2016/05/25 16:36:33 19 @@ -1,19 +1,23 @@ #include "ecosystem.h" #include "runid.h" #include "global.h" -#ifndef NO_OPENMP +#include +#ifdef _OPENMP #include #endif -#ifndef NO_OPENMP +#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; @@ -111,30 +115,22 @@ void Ecosystem::Optimise() { int i; for (i = 0; i < optvec.Size(); i++) { -#ifndef NO_OPENMP + 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 - 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); +#ifdef SPECULATIVE + optvec[i]->OptimiseLikelihoodOMP(); +#else + optvec[i]->OptimiseLikelihood(); +#endif + time(&stoptime); this->writeOptValues(); } } -#endif double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { int i, j; @@ -179,7 +175,7 @@ tmpvec[i] = likevec[i]->getUnweightedLikelihood(); int iters = 0; -#ifndef NO_OPENMP +#ifdef _OPENMP int numThr = omp_get_max_threads ( ); for (i = 0; i < numThr; i++) iters += EcoSystems[i]->getFuncEval(); @@ -192,28 +188,9 @@ handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore()); else 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 + handle.logMessage(LOGINFO, "\n Runtime for the algorithm was ", difftime(stoptime, starttime)," seconds\n"); +} void Ecosystem::writeInitialInformation(const char* const filename) { keeper->openPrintFile(filename); @@ -225,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); }