From 1310ef8da28eacf6d259ee8f5ae81be4c85e0fa5 Mon Sep 17 00:00:00 2001 From: Berenger Bramas <bbramas@mpcdf.mpg.de> Date: Tue, 14 Mar 2017 10:37:19 +0100 Subject: [PATCH] clean merge by putting interaction counting into the define simgrid macro section --- .../Core/FGroupTaskStarpuAlgorithm.hpp | 52 ++-- Tests/GroupTree/testBlockedUniform.cpp | 287 +----------------- 2 files changed, 29 insertions(+), 310 deletions(-) diff --git a/Src/GroupTree/Core/FGroupTaskStarpuAlgorithm.hpp b/Src/GroupTree/Core/FGroupTaskStarpuAlgorithm.hpp index 48cba36e8..50f952e2a 100644 --- a/Src/GroupTree/Core/FGroupTaskStarpuAlgorithm.hpp +++ b/Src/GroupTree/Core/FGroupTaskStarpuAlgorithm.hpp @@ -1143,9 +1143,7 @@ protected: // put the right codelet task->cl = &m2m_cl; - // put args values - char *arg_buffer; - size_t arg_buffer_size; +#ifdef STARPU_SIMGRID_MLR_MODELS size_t nbChildParent = 0; { CellContainerClass*const currentCells = tree->getCellGroup(idxLevel, idxGroup); @@ -1171,8 +1169,7 @@ protected: idxParentCell += 1; } } - -#ifdef STARPU_SIMGRID_MLR_MODELS + double *parameters = (double*) calloc(1,m2m_cl.model->nparameters*sizeof(double)); parameters[0] = (double) idxLevel; parameters[1] = (double) tree->getCellGroup(idxLevel,idxGroup)->getNumberOfCellsInBlock(); @@ -1184,6 +1181,9 @@ protected: parameters[6] = (double) nbChildParent; #endif + // put args values + char *arg_buffer; + size_t arg_buffer_size; starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size, STARPU_VALUE, &wrapperptr, sizeof(wrapperptr), STARPU_VALUE, &idxLevel, sizeof(idxLevel), @@ -1225,9 +1225,7 @@ protected: // put the right codelet task->cl = &m2m_cl; - // put args values - char *arg_buffer; - size_t arg_buffer_size; +#ifdef STARPU_SIMGRID_MLR_MODELS size_t nbChildParent = 0; { CellContainerClass*const currentCells = tree->getCellGroup(idxLevel, idxGroup); @@ -1254,7 +1252,6 @@ protected: idxParentCell += 1; } } -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,m2m_cl.model->nparameters*sizeof(double)); parameters[0] = (double) idxLevel; parameters[1] = (double) tree->getCellGroup(idxLevel,idxGroup)->getNumberOfCellsInBlock(); @@ -1265,6 +1262,9 @@ protected: FMath::Max(tree->getCellGroup(idxLevel,idxGroup)->getStartingIndex(), tree->getCellGroup(idxLevel+1,idxSubGroup)->getStartingIndex()>>3); parameters[6] = (double) nbChildParent; #endif + // put args values + char *arg_buffer; + size_t arg_buffer_size; starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size, STARPU_VALUE, &wrapperptr, sizeof(wrapperptr), @@ -1309,6 +1309,7 @@ protected: if(inner){ FLOG( timerInBlock.tic() ); for(int idxGroup = 0 ; idxGroup < tree->getNbCellGroupAtLevel(idxLevel) ; ++idxGroup){ +#ifdef STARPU_SIMGRID_MLR_MODELS size_t nbM2LInteractions = 0; { CellContainerClass*const currentCells = tree->getCellGroup(idxLevel, idxGroup); @@ -1332,7 +1333,6 @@ protected: } } } -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,m2l_cl_in.model->nparameters*sizeof(double)); parameters[0] = (double) idxLevel; parameters[1] = (double) tree->getCellGroup(idxLevel,idxGroup)->getNumberOfCellsInBlock(); @@ -1371,6 +1371,7 @@ protected: for(int idxInteraction = 0; idxInteraction < int(externalInteractionsAllLevel[idxLevel][idxGroup].size()) ; ++idxInteraction){ const int interactionid = externalInteractionsAllLevel[idxLevel][idxGroup][idxInteraction].otherBlockId; const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsAllLevel[idxLevel][idxGroup][idxInteraction].interactions; +#ifdef STARPU_SIMGRID_MLR_MODELS int nbDiff0 = 0; int nbDiff1 = 0; { @@ -1388,8 +1389,6 @@ protected: } } } - int mode = 1; -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,m2l_cl_inout.model->nparameters*sizeof(double)); parameters[0] = (double) idxLevel; parameters[1] = (double) tree->getCellGroup(idxLevel,idxGroup)->getNumberOfCellsInBlock(); @@ -1400,6 +1399,7 @@ protected: parameters[6] = (double) nbDiff0; parameters[7] = (double) nbDiff1; #endif + int mode = 1; starpu_insert_task(&m2l_cl_inout, STARPU_VALUE, &wrapperptr, sizeof(wrapperptr), @@ -1505,9 +1505,7 @@ protected: else{ task->cl = &l2l_cl; } - // put args values - char *arg_buffer; - size_t arg_buffer_size; +#ifdef STARPU_SIMGRID_MLR_MODELS size_t nbChildParent = 0; { CellContainerClass*const currentCells = tree->getCellGroup(idxLevel, idxGroup); @@ -1533,7 +1531,6 @@ protected: idxParentCell += 1; } } -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,l2l_cl.model->nparameters*sizeof(double)); parameters[0] = (double) idxLevel; parameters[1] = (double) tree->getCellGroup(idxLevel,idxGroup)->getNumberOfCellsInBlock(); @@ -1544,7 +1541,10 @@ protected: FMath::Max(tree->getCellGroup(idxLevel,idxGroup)->getStartingIndex(), tree->getCellGroup(idxLevel+1,idxSubGroup)->getStartingIndex()>>3); parameters[6] = (double) nbChildParent; #endif - + + // put args values + char *arg_buffer; + size_t arg_buffer_size; starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size, STARPU_VALUE, &wrapperptr, sizeof(wrapperptr), STARPU_VALUE, &idxLevel, sizeof(idxLevel), @@ -1590,9 +1590,7 @@ protected: else{ task->cl = &l2l_cl; } - // put args values - char *arg_buffer; - size_t arg_buffer_size; +#ifdef STARPU_SIMGRID_MLR_MODELS size_t nbChildParent = 0; { CellContainerClass*const currentCells = tree->getCellGroup(idxLevel, idxGroup); @@ -1618,7 +1616,6 @@ protected: idxParentCell += 1; } } -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,l2l_cl.model->nparameters*sizeof(double)); parameters[0] = (double) idxLevel; parameters[1] = (double) tree->getCellGroup(idxLevel,idxGroup)->getNumberOfCellsInBlock(); @@ -1630,6 +1627,9 @@ protected: parameters[6] = (double) nbChildParent; #endif + // put args values + char *arg_buffer; + size_t arg_buffer_size; starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size, STARPU_VALUE, &wrapperptr, sizeof(wrapperptr), STARPU_VALUE, &idxLevel, sizeof(idxLevel), @@ -1673,6 +1673,7 @@ protected: for(int idxInteraction = 0; idxInteraction < int(externalInteractionsLeafLevel[idxGroup].size()) ; ++idxInteraction){ const int interactionid = externalInteractionsLeafLevel[idxGroup][idxInteraction].otherBlockId; const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsLeafLevel[idxGroup][idxInteraction].interactions; +#ifdef STARPU_SIMGRID_MLR_MODELS int nbDiff0 = 0; int nbDiff1 = 0; size_t nbInteractions = 0; @@ -1696,7 +1697,6 @@ protected: } } } -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,p2p_cl_inout.model->nparameters*sizeof(double)); parameters[0] = (double) tree->getParticleGroup(idxGroup)->getNumberOfLeavesInBlock(); parameters[1] = (double) tree->getParticleGroup(idxGroup)->getSizeOfInterval(); @@ -1705,9 +1705,9 @@ protected: parameters[4] = (double) tree->getParticleGroup(interactionid)->getSizeOfInterval(); parameters[5] = (double) tree->getParticleGroup(interactionid)->getNbParticlesInGroup(); parameters[6] = (double) outsideInteractions->size(); - parameters[7] = (double) nbDiff0; - parameters[8] = (double) nbDiff1; - parameters[9] = (double) nbInteractions; + parameters[7] = (double) nbDiff0; + parameters[8] = (double) nbDiff1; + parameters[9] = (double) nbInteractions; #endif starpu_insert_task(&p2p_cl_inout, @@ -1750,6 +1750,7 @@ protected: FLOG( timerOutBlock.tac() ); FLOG( timerInBlock.tic() ); for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){ +#ifdef STARPU_SIMGRID_MLR_MODELS size_t nbInteractions = 0; { ParticleGroupClass* containers = tree->getParticleGroup(idxGroup); @@ -1778,7 +1779,6 @@ protected: } } } -#ifdef STARPU_SIMGRID_MLR_MODELS double *parameters = (double*) calloc(1,p2p_cl_in.model->nparameters*sizeof(double)); parameters[0] = (double) tree->getParticleGroup(idxGroup)->getNumberOfLeavesInBlock(); parameters[1] = (double) tree->getParticleGroup(idxGroup)->getSizeOfInterval(); diff --git a/Tests/GroupTree/testBlockedUniform.cpp b/Tests/GroupTree/testBlockedUniform.cpp index dc45347e7..d7ff31f95 100644 --- a/Tests/GroupTree/testBlockedUniform.cpp +++ b/Tests/GroupTree/testBlockedUniform.cpp @@ -45,282 +45,10 @@ #define RANDOM_PARTICLES -template <class FReal> -class FSphericalRandomLoader : public FAbstractLoader<FReal> { -protected: - const int nbParticles; //< the number of particles - const FReal boxWidth; //< the box width - const FPoint<FReal> centerOfBox; //< The center of box - const bool nu; - const bool snu; - const bool su; - const bool elu; - const bool ssnu; - const bool elsu; - - - FReal rotationMatrix[3][3]; - - void initRotationMatrix(){ - const FReal alpha = FMath::FPi<FReal>()/8; - const FReal omega = FMath::FPi<FReal>()/4; - - FReal yrotation[3][3]; - yrotation[0][0] = FMath::Cos(alpha); yrotation[0][1] = 0.0; yrotation[0][2] = FMath::Sin(alpha); - yrotation[1][0] = 0.0; yrotation[1][1] = 1.0; yrotation[1][2] = 0.0; - yrotation[2][0] = -FMath::Sin(alpha); yrotation[2][1] = 0.0; yrotation[2][2] = FMath::Cos(alpha); - - FReal zrotation[3][3]; - zrotation[0][0] = FMath::Cos(omega); zrotation[0][1] = -FMath::Sin(omega); zrotation[0][2] = 0.0; - zrotation[1][0] = FMath::Sin(omega); zrotation[1][1] = FMath::Cos(omega); zrotation[1][2] = 0.0; - zrotation[2][0] = 0.0; zrotation[2][1] = 0.0; zrotation[2][2] = 1.0; - - for(int i = 0 ; i < 3 ; ++i){ - for(int j = 0 ; j < 3 ; ++j){ - FReal sum = 0.0; - for(int k = 0 ; k < 3 ; ++k){ - sum += zrotation[i][k] * yrotation[k][j]; - } - rotationMatrix[i][j] = sum; - } - } - } - -public: - /** - * The constructor need the simulation data - */ - FSphericalRandomLoader(const int inNbParticles, const bool inNu = false, - const bool inSnu = false, - const bool inSu = false, - const bool inElu = false, - const bool inSsnu = false, - const bool inElsu = false) - : nbParticles(inNbParticles), boxWidth(1.0), centerOfBox(0,0,0), nu(inNu), - snu(inSnu), su(inSu), elu(inElu), ssnu(inSsnu), elsu(inElsu) { - srand48(static_cast<unsigned int>(0)); - if( !nu && !snu && !su && !elu && !ssnu && !elsu ){ - std::cout << "UNIFORM" << std::endl; - } - else if( snu ){ - std::cout << "slightly NON UNIFORM" << std::endl; - } - else if( su ){ - std::cout << "SPHERICAL UNIFORM" << std::endl; - } - else if( elu ){ - std::cout << "ELLIPSE UNIFORM" << std::endl; - } - else if( elsu ){ - std::cout << "ELLIPSE NON UNIFORM" << std::endl; - initRotationMatrix(); - } - else if( ssnu ){ - std::cout << "spherical Slightly non UNIFORM" << std::endl; - } - else{ - std::cout << "NON UNIFORM" << std::endl; - } - } - - /** - * Default destructor - */ - virtual ~FSphericalRandomLoader(){ - } - - /** - * @return true - */ - bool isOpen() const{ - return true; - } - - /** - * To get the number of particles from this loader - * @param the number of particles the loader can fill - */ - FSize getNumberOfParticles() const{ - return FSize(this->nbParticles); - } - - /** - * The center of the box - * @return box center - */ - FPoint<FReal> getCenterOfBox() const{ - return this->centerOfBox; - } - - /** - * The box width - * @return box width - */ - FReal getBoxWidth() const{ - return this->boxWidth; - } - - /** - * Fill a particle - * @warning to work with the loader, particles has to expose a setPosition method - * @param the particle to fill - */ - void fillParticle(FPoint<FReal>* partPtr){ - FPoint<FReal>& inParticle = *partPtr; - if( !nu && !snu && !su && !elu && !ssnu && !elsu ){ - inParticle.setPosition( - (getRandom() * boxWidth) + centerOfBox.getX() - boxWidth/2, - (getRandom() * boxWidth) + centerOfBox.getY() - boxWidth/2, - (getRandom() * boxWidth) + centerOfBox.getZ() - boxWidth/2); - } - else if( snu ){ - const FReal XCenter = centerOfBox.getX(); - const FReal YCenter = centerOfBox.getY(); - const FReal ZCenter = centerOfBox.getZ(); - - const FReal rayon = FReal(0.4); - const FReal thresh = FReal(0.15); - const FReal threshDiv2 = thresh/2; - - // Generate particles - const FReal theta = getRandom() * FMath::FPi<FReal>(); - const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2); - - const FReal px = rayon * FMath::Cos(omega) * FMath::Sin(theta) + XCenter + thresh * getRandom() - threshDiv2; - const FReal py = rayon * FMath::Sin(omega) * FMath::Sin(theta) + YCenter + thresh * getRandom() - threshDiv2; - const FReal pz = rayon * FMath::Cos(theta) + ZCenter + thresh * getRandom() - threshDiv2; - - inParticle.setPosition(px,py,pz); - } - else if( su ){ - //http://www.cs.cmu.edu/~mws/rpos.html - const FReal r = 0.4; - - const FReal pz = getRandom()*2.0*r - r; - const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2); - - const FReal theta = FMath::ASin(pz/r); - - const FReal px = r * cos(theta) * cos(omega); - const FReal py = r * cos(theta) * sin(omega); - - inParticle.setPosition(px,py,pz); - } - else if( elu ){ - const FReal a = 0.4; - const FReal b = 0.15; - - const FReal maxPerimeter = 2.0 * FMath::FPi<FReal>() * a; - - FReal px = 0; - // rayon du cercle pour ce x - FReal subr = 0; - - do { - px = (getRandom() * a * 2) - a; - subr = FMath::Sqrt( (1.0 - ((px*px)/(a*a))) * (b*b) ); - } while( (getRandom()*maxPerimeter) > subr ); - - // on genere un angle - const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2); - // on recupere py et pz sur le cercle - const FReal py = FMath::Cos(omega) * subr; - const FReal pz = FMath::Sin(omega) * subr; - - inParticle.setPosition(px,py,pz); - } - else if( elsu ){ - const FReal a = 0.5; - const FReal b = 0.1; - - const FReal MaxDensity = 10.0; - const FReal maxPerimeter = 2.0 * FMath::FPi<FReal>() * a ; - - FReal px = 0; - // rayon du cercle pour ce x - FReal subr = 0; - FReal coef = 1.0; - - do { - //px = ( ((getRandom()*8.0+getRandom())/9.0) * a * 2) - a; - px = (getRandom() * a * 2.0) - a; - - coef = FMath::Abs(px) * MaxDensity/a + 1.0; - - subr = FMath::Sqrt( (1.0 - ((px*px)/(a*a))) * (b*b) ); - - } while( (getRandom()*maxPerimeter) > subr * coef ); - - // on genere un angle - const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2); - // on recupere py et pz sur le cercle - const FReal py = FMath::Cos(omega) * subr; - const FReal pz = FMath::Sin(omega) * subr; - - // inParticle.setPosition(px,py,pz); - inParticle.setPosition(px * rotationMatrix[0][0] + py * rotationMatrix[0][1]+ pz * rotationMatrix[0][2], - px * rotationMatrix[1][0] + py * rotationMatrix[1][1]+ pz * rotationMatrix[1][2], - px * rotationMatrix[2][0] + py * rotationMatrix[2][1]+ pz * rotationMatrix[2][2]); - - } - else if( ssnu ){ - const FReal XCenter = centerOfBox.getX(); - const FReal YCenter = centerOfBox.getY(); - const FReal ZCenter = centerOfBox.getZ(); - - const FReal rayon = FReal(0.4); - - // Generate particles - /*static const int NbAcc = 2; - FReal acc = 0; - for(int idx = 0 ; idx < NbAcc ; ++idx){ - acc += getRandom()/FReal(NbAcc); - }*/ - FReal acc = ((getRandom()*8)+getRandom())/9; - - const FReal theta = acc * FMath::FPi<FReal>(); - const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2); - - const FReal px = rayon * FMath::Cos(omega) * FMath::Sin(theta) + XCenter ; - const FReal py = rayon * FMath::Sin(omega) * FMath::Sin(theta) + YCenter ; - const FReal pz = rayon * FMath::Cos(theta) + ZCenter ; - - inParticle.setPosition(px,py,pz); - } - else{ - const FReal XCenter = centerOfBox.getX(); - const FReal YCenter = centerOfBox.getY(); - const FReal ZCenter = centerOfBox.getZ(); - - const FReal rayon = FReal(0.4); - - const FReal theta = getRandom() * FMath::FPi<FReal>(); - const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2); - - const FReal px = rayon * FMath::Cos(omega) * FMath::Sin(theta) + XCenter ; - const FReal py = rayon * FMath::Sin(omega) * FMath::Sin(theta) + YCenter ; - const FReal pz = rayon * FMath::Cos(theta) + ZCenter ; - - inParticle.setPosition(px,py,pz); - } - } - - /** Get a random number between 0 & 1 */ - FReal getRandom() const{ - return FReal(drand48()); - } -}; - -extern "C" { int main(int argc, char* argv[]){ const FParameterNames LocalOptionBlocSize { {"-bs"}, "The size of the block of the blocked tree"}; const FParameterNames LocalOptionNoValidate { {"-no-validation"}, "To avoid comparing with direct computation"}; - const FParameterNames LocalOptionNonUnif { {"-nonunif"}, "To generate non uniform"}; - const FParameterNames LocalOptionProlateNonUnif { {"-prolate-nonunif"}, "To generate prolate non unif distribution"}; - const FParameterNames LocalOptionProlate { {"-prolate"}, "To generate prolate distribution"}; - const FParameterNames LocalOptionSpherical { {"-spherical"}, "To generate spherical distribution"}; - const FParameterNames LocalOptionSphericalNonUnif { {"-spherical-nonunif"}, "To generate spherical non unif distribution"}; - FHelpDescribeAndExit(argc, argv, "Test the blocked tree by counting the particles.", + FHelpDescribeAndExit(argc, argv, "Perform Lagrange Kernel based simulation with StarPU", FParameterDefinitions::OctreeHeight, #ifdef RANDOM_PARTICLES FParameterDefinitions::NbParticles, @@ -328,8 +56,6 @@ int main(int argc, char* argv[]){ FParameterDefinitions::InputFile, #endif FParameterDefinitions::NbThreads, - LocalOptionProlateNonUnif, LocalOptionProlate, - LocalOptionSpherical, LocalOptionSphericalNonUnif,LocalOptionNonUnif, LocalOptionBlocSize, LocalOptionNoValidate); // Initialize the types @@ -365,14 +91,7 @@ int main(int argc, char* argv[]){ // Load the particles #ifdef RANDOM_PARTICLES - const bool prolate = FParameters::existParameter(argc,argv,LocalOptionProlate.options); - const bool prolatenonunif = FParameters::existParameter(argc,argv,LocalOptionProlateNonUnif.options); - const bool spherical = FParameters::existParameter(argc,argv,LocalOptionSpherical.options); - const bool sphericalnonunif = FParameters::existParameter(argc,argv,LocalOptionSphericalNonUnif.options); - const bool nonunif = FParameters::existParameter(argc,argv,LocalOptionNonUnif.options); - FSphericalRandomLoader<FReal> loader(FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 2000), - nonunif, false, spherical, prolate, sphericalnonunif, prolatenonunif); - + FRandomLoader<FReal> loader(FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 2000), 1.0, FPoint<FReal>(0,0,0), 0); #else const char* const filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma"); FFmaGenericLoader<FReal> loader(filename); @@ -484,4 +203,4 @@ int main(int argc, char* argv[]){ return 0; } -} + -- GitLab