1 |
#include "ecosystem.h" |
#include "ecosystem.h" |
2 |
#include "runid.h" |
#include "runid.h" |
3 |
#include "global.h" |
#include "global.h" |
4 |
#ifndef NO_OPENMP |
#include <ctime> |
5 |
|
#ifdef _OPENMP |
6 |
#include <omp.h> |
#include <omp.h> |
7 |
#endif |
#endif |
8 |
|
|
9 |
#ifndef NO_OPENMP |
#ifdef _OPENMP |
10 |
extern Ecosystem** EcoSystems; |
extern Ecosystem** EcoSystems; |
11 |
//extern StochasticData* data; |
//extern StochasticData* data; |
12 |
#endif |
#endif |
13 |
|
extern volatile int interrupted_print; |
14 |
|
|
15 |
|
time_t starttime, stoptime; |
16 |
|
|
17 |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
18 |
|
|
19 |
funceval = 0; |
funceval = 0; |
20 |
interrupted = 0; |
//interrupted = 0; |
21 |
likelihood = 0.0; |
likelihood = 0.0; |
22 |
keeper = new Keeper; |
keeper = new Keeper; |
23 |
|
|
115 |
void Ecosystem::Optimise() { |
void Ecosystem::Optimise() { |
116 |
int i; |
int i; |
117 |
for (i = 0; i < optvec.Size(); i++) { |
for (i = 0; i < optvec.Size(); i++) { |
118 |
#ifndef NO_OPENMP |
time(&starttime); |
119 |
|
#ifdef _OPENMP |
120 |
int j, numThr = omp_get_max_threads ( ); |
int j, numThr = omp_get_max_threads ( ); |
121 |
DoubleVector v = this->getValues(); |
DoubleVector v = this->getValues(); |
122 |
for (j = 0; j < numThr; j++) |
for (j = 0; j < numThr; j++) |
123 |
EcoSystems[j]->Update(v); |
EcoSystems[j]->Update(v); |
124 |
#endif |
#endif |
125 |
optvec[i]->OptimiseLikelihood(); |
#ifdef SPECULATIVE |
|
this->writeOptValues(); |
|
|
} |
|
|
} |
|
|
|
|
|
#ifdef GADGET_OPENMP |
|
|
void Ecosystem::OptimiseOMP() { |
|
|
int i; |
|
|
for (i = 0; i < optvec.Size(); ++i) { |
|
126 |
optvec[i]->OptimiseLikelihoodOMP(); |
optvec[i]->OptimiseLikelihoodOMP(); |
127 |
int j, numThr = omp_get_max_threads ( ); |
#else |
128 |
DoubleVector v = this->getValues(); |
optvec[i]->OptimiseLikelihood(); |
129 |
for (j = 0; j < numThr; j++) |
#endif |
130 |
EcoSystems[j]->Update(v); |
time(&stoptime); |
131 |
this->writeOptValues(); |
this->writeOptValues(); |
132 |
} |
} |
133 |
} |
} |
|
#endif |
|
134 |
|
|
135 |
double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { |
double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { |
136 |
int i, j; |
int i, j; |
175 |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
176 |
|
|
177 |
int iters = 0; |
int iters = 0; |
178 |
#ifndef NO_OPENMP |
#ifdef _OPENMP |
179 |
int numThr = omp_get_max_threads ( ); |
int numThr = omp_get_max_threads ( ); |
180 |
for (i = 0; i < numThr; i++) |
for (i = 0; i < numThr; i++) |
181 |
iters += EcoSystems[i]->getFuncEval(); |
iters += EcoSystems[i]->getFuncEval(); |
188 |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore()); |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore()); |
189 |
else |
else |
190 |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
|
} |
|
191 |
|
|
192 |
//#ifdef GADGET_OPENMP |
handle.logMessage(LOGINFO, "\n Runtime for the algorithm was ", difftime(stoptime, starttime)," seconds\n"); |
193 |
//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 |
|
194 |
|
|
195 |
void Ecosystem::writeInitialInformation(const char* const filename) { |
void Ecosystem::writeInitialInformation(const char* const filename) { |
196 |
keeper->openPrintFile(filename); |
keeper->openPrintFile(filename); |
202 |
} |
} |
203 |
|
|
204 |
void Ecosystem::writeParams(const char* const filename, int prec) const { |
void Ecosystem::writeParams(const char* const filename, int prec) const { |
205 |
if ((funceval > 0) && (interrupted == 0)) { |
if ((funceval > 0) && (interrupted_print == 0)) { |
206 |
//JMB - print the final values to any output files specified |
//JMB - print the final values to any output files specified |
207 |
//in case they have been missed by the -print value |
//in case they have been missed by the -print value |
208 |
if (printinfo.getPrint()) |
if (printinfo.getPrint()) |
209 |
keeper->writeValues(likevec, printinfo.getPrecision()); |
keeper->writeValues(likevec, printinfo.getPrecision()); |
210 |
} |
} |
211 |
keeper->writeParams(optvec, filename, prec, interrupted); |
keeper->writeParams(optvec, filename, prec, interrupted_print); |
212 |
} |
} |