--- trunk/gadget/hooke.cc 2015/07/23 19:00:38 11 +++ trunk/gadget/hooke.cc 2015/07/24 18:36:24 12 @@ -188,8 +188,12 @@ /* given a point, look for a better one nearby, one coord at a time */ #ifndef NO_OPENMP +/* + * function bestBeraby parallelized with OpenMP + * · 2 threads per coord to parallelize the calculation of +delta/-delta + * · parallelize the calculation of the best nearby of the coord + */ double OptInfoHooke::bestNearbyOMP(DoubleVector& delta, DoubleVector& point, double prevbest, IntVector& param) { -//cout << "beastNearbyINI" << endl; double minf;//, ftmp; int i, j, k; DoubleVector z(point); @@ -215,18 +219,12 @@ } while ( i < nvars) { -// for (int k=0;k= nvars) paral_tokens = nvars - i; -//cout << "i:" << i << endl; omp_set_dynamic(0); omp_set_nested(1); #pragma omp parallel for num_threads(paral_tokens) private(k) for (j = 0; j < paral_tokens; ++j) { -// cout << "thr_for:" << omp_get_num_threads()<SimulateAndUpdate(v1); -// cout << "->" << j << endl; } - #pragma omp section + #pragma omp section { -// cout << "->" << j+paral_tokens << endl; storage[j+paral_tokens].ftmp = EcoSystems[j+paral_tokens]->SimulateAndUpdate(v2); } } -//cout << "-----" << endl; -// cout <getFuncEval() - offset; #endif -// cout << "newf:" << newf << "-" << iters< hookeiter) { handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n"); handle.logMessage(LOGINFO, "The optimisation stopped after", iters, "function evaluations"); @@ -499,7 +480,6 @@ #ifdef NO_OPENMP iters = EcoSystem->getFuncEval() - offset; #endif -// cout << "newf:" << newf << "-" << iters< hookeiter) { handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n"); handle.logMessage(LOGINFO, "The optimisation stopped after", iters, "function evaluations"); @@ -552,11 +532,10 @@ } } +/* Functions to perform the parallelization of the algorithm of HJ with OpenMP*/ #ifdef GADGET_OPENMP - //TODO doc double OptInfoHooke::bestNearbyOMP2(DoubleVector& delta, DoubleVector& point, double prevbest, IntVector& param) { -//cout << "beastNearbyINI" << endl; - double minf;//, ftmp; + double minf; int i, j, k, ii; DoubleVector z(point); int bestId = 0; @@ -569,7 +548,6 @@ minf = prevbest; - int paral_tokens, numThr, nvars = point.Size(); numThr = omp_get_max_threads ( ); @@ -583,18 +561,12 @@ for (ii=0; ii< paral_tokens; ii++) { i = 0; while ( i < nvars) { - // for (int k=0;k= nvars) paral_tokens = nvars - i; - //cout << "i:" << i << endl; omp_set_dynamic(0); omp_set_nested(1); #pragma omp parallel for num_threads(paral_tokens) private(k) for (j = 0; j < paral_tokens; ++j) { - // cout << "thr_for:" << omp_get_num_threads()<SimulateAndUpdate(v1); - // cout << "->" << j << endl; } #pragma omp section { - // cout << "->" << j+paral_tokens << endl; storage[j+paral_tokens].ftmp = EcoSystems[j+paral_tokens]->SimulateAndUpdate(v2); } } - //cout << "-----" << endl; - // cout <getFuncEval() - offset; #endif - // cout << "newf:" << newf << "-" << iters< hookeiter) { handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n"); handle.logMessage(LOGINFO, "The optimisation stopped after", iters, "function evaluations"); @@ -786,7 +741,6 @@ for (i = 0; i < nvars; i++) bestx[i] = trialx[i] * init[i]; EcoSystem->storeVariables(score, bestx); -// EcoSystem->writeOptValuesOMP(); return; } @@ -872,7 +826,6 @@ #ifdef NO_OPENMP iters = EcoSystem->getFuncEval() - offset; #endif - // cout << "newf:" << newf << "-" << iters< hookeiter) { handle.logMessage(LOGINFO, "\nStopping Hooke & Jeeves optimisation algorithm\n"); handle.logMessage(LOGINFO, "The optimisation stopped after", iters, "function evaluations"); @@ -885,7 +838,6 @@ for (i = 0; i < nvars; i++) bestx[i] = trialx[i] * init[i]; EcoSystem->storeVariables(score, bestx); -// EcoSystem->writeOptValuesOMP(); return; } } @@ -916,7 +868,6 @@ score = bestf; handle.logMessage(LOGINFO, "\nHooke & Jeeves finished with a likelihood score of", score); EcoSystem->storeVariables(bestf, bestx); -// EcoSystem->writeOptValuesOMP(); return; }