--- trunk/gadget/hooke.cc 2015/07/23 19:00:38 11 +++ trunk/gadget/hooke.cc 2015/07/30 12:36:46 14 @@ -156,17 +156,9 @@ DoubleVector z(point); minf = prevbest; -// for (int k=0;kSimulateAndUpdate(z); -// cout << i <<"-z["<< param[i]<<"]:" <= 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) + omp_set_nested(1); //permit the nested parallelization +#pragma omp parallel for num_threads(paral_tokens) private(k) //parallelize the parameters (numThr/2) 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 <scaleVariables(); #ifndef NO_OPENMP int numThr = omp_get_max_threads ( ); - for (i = 0; i < numThr; i++) + for (i = 0; i < numThr; i++) // scale the variables for the ecosystem of every thread EcoSystems[i]->scaleVariables(); #endif EcoSystem->getOptScaledValues(x); @@ -337,7 +312,6 @@ bestx[i] = x[i]; trialx[i] = x[i]; param[i] = i; - //FIXME rand_r delta[i] = ((2 * (rand() % 2)) - 1) * rho; //JMB - randomise the sign } @@ -371,7 +345,6 @@ /* randomize the order of the parameters once in a while */ rchange = 0; while (rchange < nvars) { - //FIXME rand_r rnumber = rand() % nvars; rcheck = 1; for (i = 0; i < rchange; i++) @@ -401,7 +374,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"); @@ -499,7 +471,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 +523,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 +539,6 @@ minf = prevbest; - int paral_tokens, numThr, nvars = point.Size(); numThr = omp_get_max_threads ( ); @@ -583,18 +552,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 <scaleVariables(); - #ifndef NO_OPENMP int numThr = omp_get_max_threads ( ); - for (i = 0; i < numThr; i++) + for (i = 0; i < numThr; i++) // scale the variables for the ecosystem of every thread EcoSystems[i]->scaleVariables(); - #endif EcoSystem->getOptScaledValues(x); EcoSystem->getOptLowerBounds(lowerb); EcoSystem->getOptUpperBounds(upperb); @@ -709,7 +656,6 @@ bestx[i] = x[i]; trialx[i] = x[i]; param[i] = i; - //FIXME rand_r delta[i] = ((2 * (rand() % 2)) - 1) * rho; //JMB - randomise the sign } @@ -743,7 +689,6 @@ /* randomize the order of the parameters once in a while */ rchange = 0; while (rchange < nvars) { - //FIXME rand_r rnumber = rand() % nvars; rcheck = 1; for (i = 0; i < rchange; i++) @@ -773,7 +718,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"); @@ -786,7 +730,6 @@ for (i = 0; i < nvars; i++) bestx[i] = trialx[i] * init[i]; EcoSystem->storeVariables(score, bestx); -// EcoSystem->writeOptValuesOMP(); return; } @@ -872,7 +815,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 +827,6 @@ for (i = 0; i < nvars; i++) bestx[i] = trialx[i] * init[i]; EcoSystem->storeVariables(score, bestx); -// EcoSystem->writeOptValuesOMP(); return; } } @@ -916,7 +857,6 @@ score = bestf; handle.logMessage(LOGINFO, "\nHooke & Jeeves finished with a likelihood score of", score); EcoSystem->storeVariables(bestf, bestx); -// EcoSystem->writeOptValuesOMP(); return; }