From 47fac5086e66e34641582259cf00064f9114d269 Mon Sep 17 00:00:00 2001 From: boufaras Date: Fri, 28 Jan 2011 16:38:00 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2093 331e1502-861f-0410-8da2-ba01fb791d7f --- ParadisEO-GPU/tutoriel/QAP/testSimpleTS.cu | 169 ++++++++++----------- 1 file changed, 79 insertions(+), 90 deletions(-) diff --git a/ParadisEO-GPU/tutoriel/QAP/testSimpleTS.cu b/ParadisEO-GPU/tutoriel/QAP/testSimpleTS.cu index 17f26c401..daf4afba8 100644 --- a/ParadisEO-GPU/tutoriel/QAP/testSimpleTS.cu +++ b/ParadisEO-GPU/tutoriel/QAP/testSimpleTS.cu @@ -11,6 +11,7 @@ __device__ int * dev_b; // The general include for eo #include #include +#include // Fitness function #include // Cuda Fitness function @@ -24,27 +25,22 @@ __device__ int * dev_b; #include //To compute execution time #include -// QAP ordered neighborhood +//Kswap neighborhood #include // The Solution and neighbor comparator #include #include // The Iter continuator #include -// Local search algorithm -#include -// The Tabou Search algorithm explorer -#include -//Algorithm and its components +// The Tabou Search algorithm #include //Tabu list -#include +#include //Memories #include #include #include -//#include - +#include typedef moCudaIntVector solution; typedef moKswapNeighbor Neighbor; @@ -54,97 +50,99 @@ typedef moCudaKswapNeighborhood Neighborhood; int main(int argc, char **argv) { - /* ========================================================= + /* ========================================================= * * Parameters * * ========================================================= */ // First define a parser from the command-line arguments - eoParser parser(argc, argv); + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - // seed - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + // seed + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // Swap number - eoValueParam KSwapParam(1, "KSwap", "swap number", 'N'); - parser.processParam(KSwapParam, "KSwap" ); - unsigned KSwap = KSwapParam.value(); + // Swap number + eoValueParam KSwapParam(1, "KSwap", "swap number", 'N'); + parser.processParam(KSwapParam, "KSwap" ); + unsigned KSwap = KSwapParam.value(); - // Iteration number - eoValueParam nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); - parser.processParam( nbIterationParam, "TS Iteration number" ); - unsigned nbIteration = nbIterationParam.value(); + // Iteration number + eoValueParam nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); + parser.processParam( nbIterationParam, "TS Iteration number" ); + unsigned nbIteration = nbIterationParam.value(); - // size tabu list - eoValueParam sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); - parser.processParam( sizeTabuListParam, "Search Parameters" ); - unsigned sizeTabuList = sizeTabuListParam.value(); + // size tabu list + eoValueParam sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T'); + parser.processParam( sizeTabuListParam, "Search Parameters" ); + unsigned sizeTabuList = sizeTabuListParam.value(); - // duration tabu list - eoValueParam durationParam(7, "duration", "duration of the tabu list", 'D'); - parser.processParam( durationParam, "Search Parameters" ); - unsigned duration = durationParam.value(); + // duration tabu list + eoValueParam durationParam(7, "duration", "duration of the tabu list", 'D'); + parser.processParam( durationParam, "Search Parameters" ); + unsigned duration = durationParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()) { + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { parser.printHelp(cout); exit(1); - } - if (statusParam.value() != "") { - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } + /* ========================================================= * * Random seed * * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); - //srand(time(NULL)); - + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + // rng.reseed(seed); + srand(seed); + /* ========================================================= * * Initilisation of QAP data * * ========================================================= */ - QAPData _data(argv[1]); - unsigned vecSize=_data.sizeData; + QAPData _data(argv[1]); + unsigned vecSize=_data.sizeData; + /* ========================================================= * * Initilisation of the solution * * ========================================================= */ - solution sol(vecSize); - _data.cudaObject.memCopyGlobalVariable(dev_a,_data.a_d); - _data.cudaObject.memCopyGlobalVariable(dev_b,_data.b_d); + solution sol(vecSize); + _data.cudaObject.memCopyGlobalVariable(dev_a,_data.a_d); + _data.cudaObject.memCopyGlobalVariable(dev_b,_data.b_d); - /* ========================================================= + /*========================================================= * * Evaluation of a solution neighbor's * * ========================================================= */ - QAPEval eval(_data); - unsigned long int sizeMap=sizeMapping(vecSize,KSwap); -// std::cout<<"sizeMap : "< incr_eval; - moCudaKswapEval > cueval(sizeMap,incr_eval); + + QAPEval eval(_data); + unsigned long int sizeMap=sizeMapping(vecSize,1); + QAPIncrEval incr_eval; + moCudaKswapEval > cueval(sizeMap,incr_eval); /* ========================================================= * @@ -152,8 +150,8 @@ int main(int argc, char **argv) * * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; /* ========================================================= * @@ -161,27 +159,26 @@ int main(int argc, char **argv) * * ========================================================= */ - Neighborhood neighborhood(vecSize,KSwap,cueval); + Neighborhood neighborhood(vecSize,1,cueval); - /* ========================================================= + /* ========================================================= * * continuator * * ========================================================= */ - moIterContinuator continuator(nbIteration); - - /* ========================================================= + moIterContinuator continuator(nbIteration); + + /* ========================================================= * * tabu list * * ========================================================= */ - //moNeighborVectorTabuList tl(sizeTabuList,0); - sizeTabuList=(vecSize*(vecSize-1))/2; - duration=sizeTabuList/8; - // tabu list - moNeighborVectorTabuList tl(sizeTabuList,duration); + sizeTabuList=(vecSize*(vecSize-1))/2; + duration=sizeTabuList/8; + // tabu list + moIndexedVectorTabuList tl(sizeTabuList,duration); /* ========================================================= * @@ -189,27 +186,18 @@ int main(int argc, char **argv) * * ========================================================= */ - moDummyIntensification inten; - moDummyDiversification div; - moBestImprAspiration asp; - + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + /* ========================================================= * - * An explorer of solution neighborhood's + * The Tabu search algorithm * * ========================================================= */ - moTSexplorer explorer(neighborhood, cueval, comparator, solComparator, tl, inten, div, asp); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moLocalSearch localSearch1(explorer, continuator, eval); - + moTS tabuSearch(neighborhood, eval, cueval, comparator, solComparator, continuator, tl, inten, div, asp); + /* ========================================================= * * Execute the local search from random sollution @@ -221,9 +209,10 @@ int main(int argc, char **argv) std::cout << "initial: " << sol<< std::endl; // Create timer for timing CUDA calculation + cudaFuncSetCacheConfig(kernelPermutation >, cudaFuncCachePreferL1); moCudaTimer timer; timer.start(); - localSearch1(sol); + tabuSearch(sol); std::cout << "final: " << sol << std::endl; timer.stop(); printf("CUDA execution time = %f ms\n",timer.getTime());