Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Diff of /trunk/gadget/ecosystem.cc
[mareframe] / trunk / gadget / ecosystem.cc Repository:
ViewVC logotype

Diff of /trunk/gadget/ecosystem.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1, Mon Feb 10 17:09:07 2014 UTC revision 19, Wed May 25 16:36:33 2016 UTC
# Line 1  Line 1 
1  #include "ecosystem.h"  #include "ecosystem.h"
2  #include "runid.h"  #include "runid.h"
3  #include "global.h"  #include "global.h"
4    #include <ctime>
5    #ifdef _OPENMP
6    #include <omp.h>
7    #endif
8    
9    #ifdef _OPENMP
10    extern Ecosystem** EcoSystems;
11    //extern StochasticData* data;
12    #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    
# Line 32  Line 44 
44        infile.open(filename, ios::in);        infile.open(filename, ios::in);
45        handle.checkIfFailure(infile, filename);        handle.checkIfFailure(infile, filename);
46        handle.Open(filename);        handle.Open(filename);
47        this->readOptimisation(commin);        unsigned seed;
48          main.getForcePrint();
49          this->readOptimisation(commin, main.getSeed());
50        handle.Close();        handle.Close();
51        infile.close();        infile.close();
52        infile.clear();        infile.clear();
# Line 101  Line 115 
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              time(&starttime);
119    #ifdef _OPENMP
120              int j, numThr = omp_get_max_threads ( );
121              DoubleVector v = this->getValues();
122              for (j = 0; j < numThr; j++)
123                      EcoSystems[j]->Update(v);
124    #endif
125    #ifdef SPECULATIVE
126              optvec[i]->OptimiseLikelihoodOMP();
127    #else
128      optvec[i]->OptimiseLikelihood();      optvec[i]->OptimiseLikelihood();
129    #endif
130              time(&stoptime);
131      this->writeOptValues();      this->writeOptValues();
132    }    }
133  }  }
# Line 148  Line 174 
174    for (i = 0; i < likevec.Size(); i++)    for (i = 0; i < likevec.Size(); i++)
175      tmpvec[i] = likevec[i]->getUnweightedLikelihood();      tmpvec[i] = likevec[i]->getUnweightedLikelihood();
176    
177    handle.logMessage(LOGINFO, "\nAfter a total of", funceval, "function evaluations the best point found is");    int iters = 0;
178    #ifdef _OPENMP
179      int numThr = omp_get_max_threads ( );
180        for (i = 0; i < numThr; i++)
181              iters += EcoSystems[i]->getFuncEval();
182    #endif
183      handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is");
184    keeper->writeBestValues();    keeper->writeBestValues();
185    handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are");    handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are");
186    handle.logMessage(LOGINFO, tmpvec);    handle.logMessage(LOGINFO, tmpvec);
# Line 156  Line 188 
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) {
# Line 168  Line 202 
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  }  }

Legend:
Removed from v.1  
changed lines
  Added in v.19

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge