clear src

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2376 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
boufaras 2011-09-14 13:50:16 +00:00
commit f0caa01b62

View file

@ -32,35 +32,37 @@
Contact: paradiseo-help@lists.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr
*/ */
//Init the number of threads per block
#define BLOCK_SIZE 256
#include <iostream> #include <iostream>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
using namespace std; using namespace std;
//Include GPU Config File
#include "moGPUConfig.h"
__device__ int * dev_a; __device__ int * dev_a;
__device__ int * dev_b; __device__ int * dev_b;
// The general include for eo // The general include for eo
#include <eo> #include <eo>
#include <ga.h> #include <ga.h>
#include <eval/moCudakernelEval.h>
// Fitness function // Fitness function
#include <problems/eval/QAPEval.h> #include <problems/eval/QAPEval.h>
// Cuda Fitness function // Cuda Fitness function
#include <eval/moCudaKswapEval.h> #include <eval/moGPUMappingEvalByCpy.h>
#include <problems/eval/QAPIncrEval.h> #include <problems/eval/QAPIncrEval.h>
//Specific data to QAP problem //Specific data to QAP problem
#include <problems/data/QAPData.h> #include <problems/data/QAPData.h>
// QAP solution // QAP solution
#include <cudaType/moCudaIntVector.h> #include <GPUType/moGPUPermutationVector.h>
// QAP neighbor // Swap neighbor
#include <neighborhood/moKswapNeighbor.h> #include <neighborhood/moGPUXSwapNeighbor.h>
//To compute execution time //To compute execution time
#include <performance/moCudaTimer.h> #include <performance/moGPUTimer.h>
//Kswap neighborhood //Utils to compute size Mapping of x-change position
#include <neighborhood/moCudaKswapNeighborhood.h> #include <neighborhood/moNeighborhoodSizeUtils.h>
// Use an ordered neighborhood without mapping, with local copy of solution
#include <neighborhood/moGPUXChangeNeighborhoodByCpy.h>
// The Solution and neighbor comparator // The Solution and neighbor comparator
#include <comparator/moNeighborComparator.h> #include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h> #include <comparator/moSolNeighborComparator.h>
@ -74,11 +76,11 @@ __device__ int * dev_b;
#include <memory/moDummyIntensification.h> #include <memory/moDummyIntensification.h>
#include <memory/moDummyDiversification.h> #include <memory/moDummyDiversification.h>
#include <memory/moBestImprAspiration.h> #include <memory/moBestImprAspiration.h>
#include <time.h>
typedef moCudaIntVector<eoMinimizingFitness> solution;
typedef moKswapNeighbor<solution> Neighbor; typedef moGPUPermutationVector<eoMinimizingFitness> solution;
typedef moCudaKswapNeighborhood<Neighbor> Neighborhood; typedef moGPUXSwapNeighbor<eoMinimizingFitness> Neighbor;
typedef moGPUXChangeNeighborhoodByCpy<Neighbor> Neighborhood;
int main(int argc, char **argv) int main(int argc, char **argv)
@ -101,21 +103,11 @@ int main(int argc, char **argv)
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// Swap number
eoValueParam<unsigned int> KSwapParam(1, "KSwap", "swap number", 'N');
parser.processParam(KSwapParam, "KSwap" );
unsigned KSwap = KSwapParam.value();
// Iteration number // Iteration number
eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I'); eoValueParam<unsigned int> nbIterationParam(1, "nbIteration", "TS Iteration number", 'I');
parser.processParam( nbIterationParam, "TS Iteration number" ); parser.processParam( nbIterationParam, "TS Iteration number" );
unsigned nbIteration = nbIterationParam.value(); unsigned nbIteration = nbIterationParam.value();
// size tabu list
eoValueParam<unsigned int> sizeTabuListParam(7, "sizeTabuList", "size of the tabu list", 'T');
parser.processParam( sizeTabuListParam, "Search Parameters" );
unsigned sizeTabuList = sizeTabuListParam.value();
// duration tabu list // duration tabu list
eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D'); eoValueParam<unsigned int> durationParam(7, "duration", "duration of the tabu list", 'D');
parser.processParam( durationParam, "Search Parameters" ); parser.processParam( durationParam, "Search Parameters" );
@ -156,7 +148,6 @@ int main(int argc, char **argv)
* ========================================================= */ * ========================================================= */
QAPData<int> _data(argv[1]); QAPData<int> _data(argv[1]);
unsigned vecSize=_data.sizeData;
/* ========================================================= /* =========================================================
* *
@ -164,20 +155,20 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
solution sol(vecSize); solution sol(_data.sizeData);
_data.cudaObject.memCopyGlobalVariable(dev_a,_data.a_d); _data.GPUObject.memCopyGlobalVariable(dev_a,_data.a_d);
_data.cudaObject.memCopyGlobalVariable(dev_b,_data.b_d); _data.GPUObject.memCopyGlobalVariable(dev_b,_data.b_d);
/*========================================================= /*=========================================================
* *
* Evaluation of a solution neighbor's * Evaluation of a solution neighbor's
* *
* ========================================================= */ * ========================================================= */
QAPEval<solution> eval(_data); QAPEval<solution> eval(_data);
unsigned long int sizeMap=sizeMapping(vecSize,1); unsigned long int sizeMap=sizeMapping(_data.sizeData,NB_POS);
QAPIncrEval<Neighbor> incr_eval; QAPIncrEval<Neighbor> incr_eval;
moCudaKswapEval<Neighbor,QAPIncrEval<Neighbor> > cueval(sizeMap,incr_eval); moGPUMappingEvalByCpy<Neighbor,QAPIncrEval<Neighbor> > cueval(sizeMap,incr_eval);
/* ========================================================= /* =========================================================
* *
@ -194,7 +185,7 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize,1,cueval); Neighborhood neighborhood(sizeMap,NB_POS,cueval);
/* ========================================================= /* =========================================================
* *
@ -202,7 +193,7 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
moIterContinuator <Neighbor> continuator(nbIteration); moIterContinuator <Neighbor> continuator(nbIteration);
/* ========================================================= /* =========================================================
* *
@ -210,10 +201,7 @@ int main(int argc, char **argv)
* *
* ========================================================= */ * ========================================================= */
sizeTabuList=(vecSize*(vecSize-1))/2; moIndexedVectorTabuList<Neighbor> tl(sizeMap,(sizeMap/8));
duration=sizeTabuList/8;
// tabu list
moIndexedVectorTabuList<Neighbor> tl(sizeTabuList,duration);
/* ========================================================= /* =========================================================
* *
@ -243,19 +231,17 @@ int main(int argc, char **argv)
eval(sol); eval(sol);
std::cout << "initial: " << sol<< std::endl; std::cout << "initial: " << sol<< std::endl;
// Create timer for timing CUDA calculation moGPUTimer timer;
cudaFuncSetCacheConfig(kernelPermutation<solution,eoMinimizingFitness, Neighbor , QAPIncrEval<Neighbor> >, cudaFuncCachePreferL1);
moCudaTimer timer;
timer.start(); timer.start();
tabuSearch(sol); tabuSearch(sol);
std::cout << "final: " << sol << std::endl; std::cout << "final: " << sol << std::endl;
timer.stop(); timer.stop();
printf("CUDA execution time = %f ms\n",timer.getTime()); printf("Execution time = %f ms\n",timer.getTime());
timer.deleteTimer(); timer.deleteTimer();
_data.cudaObject.free(dev_a); _data.GPUObject.free(dev_a);
_data.cudaObject.free(dev_b); _data.GPUObject.free(dev_b);
return 0; return 0;
} }