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 12, Fri Jul 24 18:36:24 2015 UTC revision 24, Wed Apr 26 09:06:03 2017 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  #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    
# Line 51  Line 55 
55        optvec.resize(new OptInfoHooke());        optvec.resize(new OptInfoHooke());
56      }      }
57    }    }
58    #ifdef _OPENMP
59      runParallel=main.runParallel();
60      if (!omp_in_parallel()){
61            if (main.runOptimise())
62            {
63                    switch(runParallel){
64                            case SPECULATIVE:
65                                    handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run parallel speculative optimisation with ", omp_get_max_threads(), " threads");
66                                    break;
67                            case REPRODUCIBLE:
68                                    handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run parallel reproducible optimisation with ", omp_get_max_threads(), " threads");
69                                    break;
70                            default:
71                                    handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to serial optimisation with ", omp_get_num_threads() , "threads");
72                    }
73            }
74            else
75                    handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run simulation ", omp_get_num_threads(), " threads");
76            handle.logMessage(LOGMESSAGE, "");  //write blank line to log file
77      }
78    #else
79    if (main.runOptimise())    if (main.runOptimise())
80      handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run optimisation");      handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run optimisation");
81    else    else
82      handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run simulation");      handle.logMessage(LOGINFO, "\nFinished reading model data files, starting to run simulation");
83    handle.logMessage(LOGMESSAGE, "");  //write blank line to log file    handle.logMessage(LOGMESSAGE, "");  //write blank line to log file
84    #endif
85  }  }
86    
87  Ecosystem::~Ecosystem() {  Ecosystem::~Ecosystem() {
# Line 111  Line 136 
136  void Ecosystem::Optimise() {  void Ecosystem::Optimise() {
137    int i;    int i;
138    for (i = 0; i < optvec.Size(); i++) {    for (i = 0; i < optvec.Size(); i++) {
139  #ifndef NO_OPENMP            time(&starttime);
140            int j, numThr = omp_get_max_threads ( );  #ifdef _OPENMP
141              if (runParallel){
142                    int j, numThr = omp_get_max_threads ( ); //AGT REMOVED
143            DoubleVector v = this->getValues();            DoubleVector v = this->getValues();
144            for (j = 0; j < numThr; j++)            for (j = 0; j < numThr; j++)
145                    EcoSystems[j]->Update(v);                    EcoSystems[j]->Update(v);
146  #endif                  if(runParallel==SPECULATIVE)
147  #ifdef GADGET_OPENMP                  {
148                            handle.logMessage(LOGINFO, "\nCalling Speculative Optimization");
149            optvec[i]->OptimiseLikelihoodOMP();            optvec[i]->OptimiseLikelihoodOMP();
150                    }
151                    else
152                    {
153                            handle.logMessage(LOGINFO, "\nCalling Reproducible parallel Optimization");
154                            optvec[i]->OptimiseLikelihoodREP();
155                    }
156              }
157              else
158              {
159                            handle.logMessage(LOGINFO, "\nCalling Reproducible serial Optimization");
160                     optvec[i]->OptimiseLikelihood();
161            }
162  #else  #else
163    //#ifdef SPECULATIVE
164    //        optvec[i]->OptimiseLikelihoodOMP();
165    //#else
166            optvec[i]->OptimiseLikelihood();            optvec[i]->OptimiseLikelihood();
167  #endif  #endif
168              time(&stoptime);
169      this->writeOptValues();      this->writeOptValues();
170    }    }
171  }  }
# Line 135  Line 179 
179      currentval.resize(keeper->numVariables(), 0.0);      currentval.resize(keeper->numVariables(), 0.0);
180      optflag.resize(keeper->numVariables(), 0);      optflag.resize(keeper->numVariables(), 0);
181      keeper->getOptFlags(optflag);      keeper->getOptFlags(optflag);
182    
183    }    }
184    
185    j = 0;    j = 0;
# Line 169  Line 214 
214      tmpvec[i] = likevec[i]->getUnweightedLikelihood();      tmpvec[i] = likevec[i]->getUnweightedLikelihood();
215    
216    int iters = 0;    int iters = 0;
217  #ifndef NO_OPENMP  #ifdef _OPENMP
218      if (runParallel){
219    int numThr = omp_get_max_threads ( );    int numThr = omp_get_max_threads ( );
220      for (i = 0; i < numThr; i++)      for (i = 0; i < numThr; i++)
221            iters += EcoSystems[i]->getFuncEval();            iters += EcoSystems[i]->getFuncEval();
222      }
223  #endif  #endif
224    handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is");    handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is");
225    keeper->writeBestValues();    keeper->writeBestValues();
# Line 182  Line 229 
229      handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore());      handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore());
230    else    else
231      handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood());      handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood());
232    
233      handle.logMessage(LOGINFO, "\n Runtime for the algorithm was ", difftime(stoptime, starttime)," seconds\n");
234  }  }
235    
236  void Ecosystem::writeInitialInformation(const char* const filename) {  void Ecosystem::writeInitialInformation(const char* const filename) {
# Line 194  Line 243 
243  }  }
244    
245  void Ecosystem::writeParams(const char* const filename, int prec) const {  void Ecosystem::writeParams(const char* const filename, int prec) const {
246    if ((funceval > 0) && (interrupted == 0)) {    if ((funceval > 0) && (interrupted_print == 0)) {
247      //JMB - print the final values to any output files specified      //JMB - print the final values to any output files specified
248      //in case they have been missed by the -print value      //in case they have been missed by the -print value
249      if (printinfo.getPrint())      if (printinfo.getPrint())
250        keeper->writeValues(likevec, printinfo.getPrecision());        keeper->writeValues(likevec, printinfo.getPrecision());
251    }    }
252    keeper->writeParams(optvec, filename, prec, interrupted);    keeper->writeParams(optvec, filename, prec, interrupted_print);
253  }  }

Legend:
Removed from v.12  
changed lines
  Added in v.24

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

Powered By FusionForge