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/hooke.cc
[mareframe] / trunk / gadget / hooke.cc Repository:
ViewVC logotype

Diff of /trunk/gadget/hooke.cc

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

revision 15, Tue Sep 1 19:14:33 2015 UTC revision 16, Tue Oct 13 11:29:01 2015 UTC
# Line 139  Line 139 
139  #include "ecosystem.h"  #include "ecosystem.h"
140  #include "global.h"  #include "global.h"
141    
142  #ifndef NO_OPENMP  #ifdef _OPENMP
143  #include "omp.h"  #include "omp.h"
144  #endif  #endif
145    
146  extern Ecosystem* EcoSystem;  extern Ecosystem* EcoSystem;
147  #ifndef NO_OPENMP  #ifdef _OPENMP
148  extern Ecosystem** EcoSystems;  extern Ecosystem** EcoSystems;
149  #endif  #endif
150    
# Line 178  Line 178 
178  }  }
179    
180  /* given a point, look for a better one nearby, one coord at a time */  /* given a point, look for a better one nearby, one coord at a time */
181  #ifndef NO_OPENMP  #ifdef _OPENMP
182  /*  /*
183   * function bestBeraby parallelized with OpenMP   * function bestBeraby parallelized with OpenMP
184   * · 2 threads per coord to parallelize the calculation of +delta/-delta   * · 2 threads per coord to parallelize the calculation of +delta/-delta
# Line 289  Line 289 
289    IntVector trapped(nvars, 0);    IntVector trapped(nvars, 0);
290    
291    EcoSystem->scaleVariables();    EcoSystem->scaleVariables();
292  #ifndef NO_OPENMP  #ifdef _OPENMP
293    int numThr = omp_get_max_threads ( );    int numThr = omp_get_max_threads ( );
294    for (i = 0; i < numThr; i++) // scale the variables for the ecosystem of every thread    for (i = 0; i < numThr; i++) // scale the variables for the ecosystem of every thread
295            EcoSystems[i]->scaleVariables();            EcoSystems[i]->scaleVariables();
# Line 334  Line 334 
334    
335    while (1) {    while (1) {
336      if (isZero(bestf)) {      if (isZero(bestf)) {
337  #ifdef NO_OPENMP  #ifndef _OPENMP
338        iters = EcoSystem->getFuncEval() - offset;        iters = EcoSystem->getFuncEval() - offset;
339  #endif  #endif
340        handle.logMessage(LOGINFO, "Error in Hooke & Jeeves optimisation after", iters, "function evaluations, f(x) = 0");        handle.logMessage(LOGINFO, "Error in Hooke & Jeeves optimisation after", iters, "function evaluations, f(x) = 0");
# Line 359  Line 359 
359      /* find best new point, one coord at a time */      /* find best new point, one coord at a time */
360      for (i = 0; i < nvars; i++)      for (i = 0; i < nvars; i++)
361        trialx[i] = x[i];        trialx[i] = x[i];
362  #ifndef NO_OPENMP  #ifdef _OPENMP
363      newf = this->bestNearbyRepro(delta, trialx, bestf, param);      newf = this->bestNearbyRepro(delta, trialx, bestf, param);
364      if (newf == -1) {      if (newf == -1) {
365          handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");          handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");
# Line 371  Line 371 
371  #endif  #endif
372      /* if too many function evaluations occur, terminate the algorithm */      /* if too many function evaluations occur, terminate the algorithm */
373    
374  #ifdef NO_OPENMP  #ifndef _OPENMP
375      iters = EcoSystem->getFuncEval() - offset;      iters = EcoSystem->getFuncEval() - offset;
376  #endif  #endif
377      if (iters > hookeiter) {      if (iters > hookeiter) {
# Line 441  Line 441 
441        /* only move forward if this is really an improvement    */        /* only move forward if this is really an improvement    */
442        oldf = newf;        oldf = newf;
443        newf = EcoSystem->SimulateAndUpdate(trialx);        newf = EcoSystem->SimulateAndUpdate(trialx);
444  #ifndef NO_OPENMP  #ifdef _OPENMP
445        iters++;        iters++;
446  #endif  #endif
447        if ((isEqual(newf, oldf)) || (newf > oldf)) {        if ((isEqual(newf, oldf)) || (newf > oldf)) {
# Line 454  Line 454 
454        for (i = 0; i < nvars; i++)        for (i = 0; i < nvars; i++)
455          x[i] = trialx[i];          x[i] = trialx[i];
456    
457  #ifndef NO_OPENMP  #ifdef _OPENMP
458        newf = this->bestNearbyRepro(delta, trialx, bestf, param);        newf = this->bestNearbyRepro(delta, trialx, bestf, param);
459        if (newf == -1) {        if (newf == -1) {
460                  handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");                  handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");
# Line 468  Line 468 
468          break;          break;
469    
470        /* if too many function evaluations occur, terminate the algorithm */        /* if too many function evaluations occur, terminate the algorithm */
471  #ifdef NO_OPENMP  #ifndef _OPENMP
472        iters = EcoSystem->getFuncEval() - offset;        iters = EcoSystem->getFuncEval() - offset;
473  #endif  #endif
474        if (iters > hookeiter) {        if (iters > hookeiter) {
# Line 485  Line 485 
485          EcoSystem->storeVariables(score, bestx);          EcoSystem->storeVariables(score, bestx);
486          return;          return;
487        }        }
488      }      } // while (newf < bestf)
489    
490  #ifdef NO_OPENMP  #ifndef _OPENMP
491      iters = EcoSystem->getFuncEval() - offset;      iters = EcoSystem->getFuncEval() - offset;
492  #endif  #endif
493      if (newf < bestf) {      if (newf < bestf) {
# Line 678  Line 678 
678    
679             while (1) {             while (1) {
680               if (isZero(bestf)) {               if (isZero(bestf)) {
681           #ifdef NO_OPENMP           #ifndef _OPENMP
682                 iters = EcoSystem->getFuncEval() - offset;                 iters = EcoSystem->getFuncEval() - offset;
683           #endif           #endif
684                 handle.logMessage(LOGINFO, "Error in Hooke & Jeeves optimisation after", iters, "function evaluations, f(x) = 0");                 handle.logMessage(LOGINFO, "Error in Hooke & Jeeves optimisation after", iters, "function evaluations, f(x) = 0");
# Line 703  Line 703 
703               /* find best new point, one coord at a time */               /* find best new point, one coord at a time */
704               for (i = 0; i < nvars; i++)               for (i = 0; i < nvars; i++)
705                 trialx[i] = x[i];                 trialx[i] = x[i];
706           #ifndef NO_OPENMP           #ifdef _OPENMP
707               newf = this->bestNearbySpec(delta, trialx, bestf, param);               newf = this->bestNearbySpec(delta, trialx, bestf, param);
708               if (newf == -1) {               if (newf == -1) {
709                  handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");                  handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");
# Line 715  Line 715 
715           #endif           #endif
716               /* if too many function evaluations occur, terminate the algorithm */               /* if too many function evaluations occur, terminate the algorithm */
717    
718           #ifdef NO_OPENMP           #ifndef _OPENMP
719               iters = EcoSystem->getFuncEval() - offset;               iters = EcoSystem->getFuncEval() - offset;
720           #endif           #endif
721               if (iters > hookeiter) {               if (iters > hookeiter) {
# Line 785  Line 785 
785                 /* only move forward if this is really an improvement    */                 /* only move forward if this is really an improvement    */
786                 oldf = newf;                 oldf = newf;
787                 newf = EcoSystem->SimulateAndUpdate(trialx);                 newf = EcoSystem->SimulateAndUpdate(trialx);
788           #ifndef NO_OPENMP           #ifdef _OPENMP
789                 iters++;                 iters++;
790           #endif           #endif
791                 if ((isEqual(newf, oldf)) || (newf > oldf)) {                 if ((isEqual(newf, oldf)) || (newf > oldf)) {
# Line 798  Line 798 
798                 for (i = 0; i < nvars; i++)                 for (i = 0; i < nvars; i++)
799                   x[i] = trialx[i];                   x[i] = trialx[i];
800    
801           #ifndef NO_OPENMP           #ifdef _OPENMP
802                 newf = this->bestNearbySpec(delta, trialx, bestf, param);                 newf = this->bestNearbySpec(delta, trialx, bestf, param);
803                 if (newf == -1) {                 if (newf == -1) {
804                          handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");                          handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n");
# Line 812  Line 812 
812                   break;                   break;
813    
814                 /* if too many function evaluations occur, terminate the algorithm */                 /* if too many function evaluations occur, terminate the algorithm */
815           #ifdef NO_OPENMP           #ifndef _OPENMP
816                 iters = EcoSystem->getFuncEval() - offset;                 iters = EcoSystem->getFuncEval() - offset;
817           #endif           #endif
818                 if (iters > hookeiter) {                 if (iters > hookeiter) {
# Line 831  Line 831 
831                 }                 }
832               }               }
833    
834           #ifdef NO_OPENMP           #ifndef _OPENMP
835               iters = EcoSystem->getFuncEval() - offset;               iters = EcoSystem->getFuncEval() - offset;
836           #endif           #endif
837               if (newf < bestf) {               if (newf < bestf) {

Legend:
Removed from v.15  
changed lines
  Added in v.16

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

Powered By FusionForge