--- trunk/gadget/ecosystem.cc 2015/07/24 18:36:24 12 +++ 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,17 +115,19 @@ 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 -#ifdef GADGET_OPENMP +#ifdef SPECULATIVE optvec[i]->OptimiseLikelihoodOMP(); #else optvec[i]->OptimiseLikelihood(); #endif + time(&stoptime); this->writeOptValues(); } } @@ -169,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(); @@ -182,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) { @@ -194,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); }