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 |
#ifdef _OPENMP |
5 |
#include <omp.h> |
#include <omp.h> |
6 |
#endif |
#endif |
7 |
|
|
8 |
#ifndef NO_OPENMP |
#ifdef _OPENMP |
9 |
extern Ecosystem** EcoSystems; |
extern Ecosystem** EcoSystems; |
10 |
//extern StochasticData* data; |
//extern StochasticData* data; |
11 |
#endif |
#endif |
12 |
|
extern volatile int interrupted_print; |
13 |
|
|
14 |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
15 |
|
|
16 |
funceval = 0; |
funceval = 0; |
17 |
interrupted = 0; |
//interrupted = 0; |
18 |
likelihood = 0.0; |
likelihood = 0.0; |
19 |
keeper = new Keeper; |
keeper = new Keeper; |
20 |
|
|
112 |
void Ecosystem::Optimise() { |
void Ecosystem::Optimise() { |
113 |
int i; |
int i; |
114 |
for (i = 0; i < optvec.Size(); i++) { |
for (i = 0; i < optvec.Size(); i++) { |
115 |
#ifndef NO_OPENMP |
#ifdef _OPENMP |
116 |
int j, numThr = omp_get_max_threads ( ); |
int j, numThr = omp_get_max_threads ( ); |
117 |
DoubleVector v = this->getValues(); |
DoubleVector v = this->getValues(); |
118 |
for (j = 0; j < numThr; j++) |
for (j = 0; j < numThr; j++) |
119 |
EcoSystems[j]->Update(v); |
EcoSystems[j]->Update(v); |
120 |
#endif |
#endif |
121 |
optvec[i]->OptimiseLikelihood(); |
#ifdef SPECULATIVE |
|
this->writeOptValues(); |
|
|
} |
|
|
} |
|
|
|
|
|
#ifdef GADGET_OPENMP |
|
|
void Ecosystem::OptimiseOMP() { |
|
|
int i; |
|
|
for (i = 0; i < optvec.Size(); ++i) { |
|
122 |
optvec[i]->OptimiseLikelihoodOMP(); |
optvec[i]->OptimiseLikelihoodOMP(); |
123 |
int j, numThr = omp_get_max_threads ( ); |
#else |
124 |
DoubleVector v = this->getValues(); |
optvec[i]->OptimiseLikelihood(); |
125 |
for (j = 0; j < numThr; j++) |
#endif |
|
EcoSystems[j]->Update(v); |
|
126 |
this->writeOptValues(); |
this->writeOptValues(); |
127 |
} |
} |
128 |
} |
} |
|
#endif |
|
129 |
|
|
130 |
double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { |
double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { |
131 |
int i, j; |
int i, j; |
170 |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
171 |
|
|
172 |
int iters = 0; |
int iters = 0; |
173 |
#ifndef NO_OPENMP |
#ifdef _OPENMP |
174 |
int numThr = omp_get_max_threads ( ); |
int numThr = omp_get_max_threads ( ); |
175 |
for (i = 0; i < numThr; i++) |
for (i = 0; i < numThr; i++) |
176 |
iters += EcoSystems[i]->getFuncEval(); |
iters += EcoSystems[i]->getFuncEval(); |
185 |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
186 |
} |
} |
187 |
|
|
|
//#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 |
|
|
|
|
188 |
void Ecosystem::writeInitialInformation(const char* const filename) { |
void Ecosystem::writeInitialInformation(const char* const filename) { |
189 |
keeper->openPrintFile(filename); |
keeper->openPrintFile(filename); |
190 |
keeper->writeInitialInformation(likevec); |
keeper->writeInitialInformation(likevec); |
195 |
} |
} |
196 |
|
|
197 |
void Ecosystem::writeParams(const char* const filename, int prec) const { |
void Ecosystem::writeParams(const char* const filename, int prec) const { |
198 |
if ((funceval > 0) && (interrupted == 0)) { |
if ((funceval > 0) && (interrupted_print == 0)) { |
199 |
//JMB - print the final values to any output files specified |
//JMB - print the final values to any output files specified |
200 |
//in case they have been missed by the -print value |
//in case they have been missed by the -print value |
201 |
if (printinfo.getPrint()) |
if (printinfo.getPrint()) |
202 |
keeper->writeValues(likevec, printinfo.getPrecision()); |
keeper->writeValues(likevec, printinfo.getPrecision()); |
203 |
} |
} |
204 |
keeper->writeParams(optvec, filename, prec, interrupted); |
keeper->writeParams(optvec, filename, prec, interrupted_print); |
205 |
} |
} |