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++) |
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(); |
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 |
} |
} |