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 |
#ifdef GADGET_OPENMP |
#ifdef SPECULATIVE |
126 |
optvec[i]->OptimiseLikelihoodOMP(); |
optvec[i]->OptimiseLikelihoodOMP(); |
127 |
#else |
#else |
128 |
optvec[i]->OptimiseLikelihood(); |
optvec[i]->OptimiseLikelihood(); |
129 |
#endif |
#endif |
130 |
|
time(&stoptime); |
131 |
this->writeOptValues(); |
this->writeOptValues(); |
132 |
} |
} |
133 |
} |
} |
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 |
|
handle.logMessage(LOGINFO, "\n Runtime for the algorithm was ", difftime(stoptime, starttime)," seconds\n"); |
193 |
} |
} |
194 |
|
|
195 |
void Ecosystem::writeInitialInformation(const char* const filename) { |
void Ecosystem::writeInitialInformation(const char* const 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 |
} |
} |