--- trunk/gadget/ecosystem.cc 2016/05/25 16:36:33 19 +++ trunk/gadget/ecosystem.cc 2017/04/26 09:06:03 24 @@ -55,12 +55,33 @@ optvec.resize(new OptInfoHooke()); } } - +#ifdef _OPENMP + runParallel=main.runParallel(); + if (!omp_in_parallel()){ + if (main.runOptimise()) + { + switch(runParallel){ + case SPECULATIVE: + handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run parallel speculative optimisation with ", omp_get_max_threads(), " threads"); + break; + case REPRODUCIBLE: + handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run parallel reproducible optimisation with ", omp_get_max_threads(), " threads"); + break; + default: + handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to serial optimisation with ", omp_get_num_threads() , "threads"); + } + } + else + handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run simulation ", omp_get_num_threads(), " threads"); + handle.logMessage(LOGMESSAGE, ""); //write blank line to log file + } +#else if (main.runOptimise()) handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run optimisation"); else handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run simulation"); handle.logMessage(LOGMESSAGE, ""); //write blank line to log file +#endif } Ecosystem::~Ecosystem() { @@ -117,14 +138,31 @@ for (i = 0; i < optvec.Size(); i++) { 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(); + if (runParallel){ + int j, numThr = omp_get_max_threads ( ); //AGT REMOVED + DoubleVector v = this->getValues(); + for (j = 0; j < numThr; j++) + EcoSystems[j]->Update(v); + if(runParallel==SPECULATIVE) + { + handle.logMessage(LOGINFO, "\nCalling Speculative Optimization"); + optvec[i]->OptimiseLikelihoodOMP(); + } + else + { + handle.logMessage(LOGINFO, "\nCalling Reproducible parallel Optimization"); + optvec[i]->OptimiseLikelihoodREP(); + } + } + else + { + handle.logMessage(LOGINFO, "\nCalling Reproducible serial Optimization"); + optvec[i]->OptimiseLikelihood(); + } #else +//#ifdef SPECULATIVE +// optvec[i]->OptimiseLikelihoodOMP(); +//#else optvec[i]->OptimiseLikelihood(); #endif time(&stoptime); @@ -141,6 +179,7 @@ currentval.resize(keeper->numVariables(), 0.0); optflag.resize(keeper->numVariables(), 0); keeper->getOptFlags(optflag); + } j = 0; @@ -176,9 +215,11 @@ int iters = 0; #ifdef _OPENMP - int numThr = omp_get_max_threads ( ); - for (i = 0; i < numThr; i++) + if (runParallel){ + 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();