From 8c0875076e176e53bd27b3606fbe3adb0d339026 Mon Sep 17 00:00:00 2001 From: cvw Date: Wed, 21 Mar 2012 14:01:01 +0000 Subject: [PATCH] add single partitioner and test metis --- .../Test/MEDPARTITIONERTest.cxx | 458 ++++++++++++++++++ .../Test/MEDPARTITIONERTest.hxx | 34 +- .../Test/MEDPARTITIONERTestPara.cxx | 21 +- src/MEDPartitioner/Test/Makefile.am | 23 +- 4 files changed, 501 insertions(+), 35 deletions(-) diff --git a/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx b/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx index 2131ff4c0..cbd0f63d9 100644 --- a/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx +++ b/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx @@ -714,3 +714,461 @@ void MEDPARTITIONERTest::verifyTestMeshWithVecFieldOnNodes() } mf->decrRef(); } + +void MEDPARTITIONERTest::createTestMeshes() +{ + createTestMeshWithoutField(); + createTestMeshWithVecFieldOnCells(); + createTestMeshWithVecFieldOnNodes(); +} + +void MEDPARTITIONERTest::deleteTestMeshes() +{ + string cmd="rm *tmp_testMesh*"; + if (_verbose) cout<setGlobalNumerotationDefault(collection.getParaDomainSelector()); + //Creating the graph and partitioning it + auto_ptr< MEDPARTITIONER::Topology > new_topo; + new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS) ); + //Creating a new mesh collection from the partitioning + MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups); + + //example to create files + //MyGlobals::_General_Informations.clear(); + //MyGlobals::_General_Informations.push_back(SerializeFromString("finalMeshName=Merge")); + //if (MyGlobals::_Verbose>100) cout << "generalInformations : \n"<setGlobalNumerotationDefault(collection.getParaDomainSelector()); + + for (int ndomains=1 ; ndomains<=16 ; ndomains++) + { + //Creating the graph and partitioning it + auto_ptr< MEDPARTITIONER::Topology > new_topo; + new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS) ); + //Creating a new mesh collection from the partitioning + MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups); + + CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes()); + CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes()); + CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells()); + CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces()); + } +//#endif +} + +void MEDPARTITIONERTest::testMetisSmallSize() +{ +//#if defined(MED_ENABLE_PARMETIS) || defined(MED_ENABLE_METIS) + setSmallSize(); + createTestMeshes(); + launchMetisMedpartitionerOnTestMeshes(); + verifyMetisMedpartitionerOnSmallSizeForMesh(); + verifyMetisMedpartitionerOnSmallSizeForFieldOnCells(); + verifyMetisMedpartitionerOnSmallSizeForFieldOnGaussNe(); +//#endif +} + +void MEDPARTITIONERTest::launchMetisMedpartitionerOnTestMeshes() +{ + int res; + string cmd,execName,sourceName,targetName; + + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner"; + + cmd="which "+execName+" 2>/dev/null 1>/dev/null"; //no trace + res=system(cmd.c_str()); + CPPUNIT_ASSERT_EQUAL(0, res); + + cmd=execName+" --ndomains=2 --split-method=metis"; //on same proc + sourceName=_file_name; + targetName=_file_name; + targetName.replace(targetName.find(".med"),4,"_partitionedTo2_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose); + if (_verbose) cout<getLevel0Mesh(false); + ParaMEDMEM::MEDCouplingUMesh* faceMesh=initialMesh->getLevelM1Mesh(false); + + cmd=execName+" --ndomains=5 --split-method=metis"; //on same proc + sourceName=fileName; + targetName=fileName; + targetName.replace(targetName.find(".med"),4,"_partitionedTo5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose); + if (_verbose) cout<cellMeshes=collection.getMesh(); + CPPUNIT_ASSERT_EQUAL(5, (int) cellMeshes.size()); + int nbcells=0; + for (std::size_t i = 0; i < cellMeshes.size(); i++) + nbcells+=cellMeshes[i]->getNumberOfCells(); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells); + + std::vectorfaceMeshes=collection.getFaceMesh(); + CPPUNIT_ASSERT_EQUAL(5, (int) faceMeshes.size()); + int nbfaces=0; + for (std::size_t i=0; i < faceMeshes.size(); i++) + nbfaces+=faceMeshes[i]->getNumberOfCells(); + CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), nbfaces); + + //merge split meshes and test equality + cmd=execName+" --ndomains=1 --split-method=metis"; //on same proc + sourceName=targetName+".xml"; + targetName=fileName; + targetName.replace(targetName.find(".med"),4,"_remergedFrom5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose); + if (_verbose) cout<getLevel0Mesh(false); + ParaMEDMEM::MEDCouplingUMesh* refusedFaceMesh=refusedMesh->getLevelM1Mesh(false); + + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), refusedFaceMesh->getNumberOfCells()); + + /*not the good job + ParaMEDMEM::MEDCouplingMesh* mergeCell=cellMesh->mergeMyselfWith(refusedCellMesh); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), mergeCell->getNumberOfCells()); + + ParaMEDMEM::MEDCouplingMesh* mergeFace=faceMesh->mergeMyselfWith(refusedFaceMesh); + CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), mergeFace->getNumberOfCells()); + + CPPUNIT_ASSERT(faceMesh->isEqual(refusedFaceMesh,1e-12)); + */ + + std::vector meshes; + std::vector corr; + meshes.push_back(cellMesh); + refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9); + meshes.push_back(refusedCellMesh); + MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); + + meshes.resize(0); + for (std::size_t i = 0; i < corr.size(); i++) + corr[i]->decrRef(); + corr.resize(0); + meshes.push_back(faceMesh); + refusedFaceMesh->tryToShareSameCoordsPermute(*faceMesh, 1e-9); + meshes.push_back(refusedFaceMesh); + MEDCouplingUMesh* fusedFace=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); + CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), fusedFace->getNumberOfCells()); + + for (std::size_t i = 0; i < corr.size(); i++) + corr[i]->decrRef(); + fusedFace->decrRef(); + refusedFaceMesh->decrRef(); + faceMesh->decrRef(); + fusedCell->decrRef(); + refusedCellMesh->decrRef(); + cellMesh->decrRef(); + //done in ~collection + //for (int i = 0; i < faceMeshes.size(); i++) faceMeshes[i]->decrRef(); + //for (int i = 0; i < cellMeshes.size(); i++) cellMeshes[i]->decrRef(); +} + +void MEDPARTITIONERTest::verifyMetisMedpartitionerOnSmallSizeForFieldOnCells() +{ + int res; + string fileName,cmd,execName,sourceName,targetName,input; + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner"; + fileName=_file_name; + fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnCells.med"); + + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str()); + ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false); + + cmd=execName+" --ndomains=5 --split-method=metis"; //on same proc + sourceName=fileName; + targetName=fileName; + targetName.replace(targetName.find(".med"),4,"_partitionedTo5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose); + if (_verbose) cout<getLevel0Mesh(false); + + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); + + std::vector meshes; + std::vector corr; + meshes.push_back(cellMesh); + refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9); + meshes.push_back(refusedCellMesh); + MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); + + MEDCouplingFieldDouble* field1=MEDLoader::ReadFieldCell(fileName.c_str(),initialMesh->getName(),0,"VectorFieldOnCells",0,1); + MEDCouplingFieldDouble* field2=MEDLoader::ReadFieldCell(refusedName.c_str(),refusedCellMesh->getName(),0,"VectorFieldOnCells",0,1); + + int nbcells=corr[1]->getNumberOfTuples(); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells); + //use corr to test equality of field + DataArrayDouble* f1=field1->getArray(); + DataArrayDouble* f2=field2->getArray(); + if (_verbose>300) + { + cout<<"\nf1 : "<reprZip(); + cout<<"\nf2 : "<reprZip(); //field2->advancedRepradvancedRepr(); + for (std::size_t i = 0; i < corr.size(); i++) + cout << "\ncorr " << i << " : " << corr[i]->reprZip(); + + } + int nbequal=0; + int nbcomp=field1->getNumberOfComponents(); + double* p1=f1->getPointer(); + double* p2=f2->getPointer(); + int* pc=corr[1]->getPointer(); + for (int i = 0; i < nbcells; i++) + { + int i1=pc[i]*nbcomp; + int i2=i*nbcomp; + for (int j = 0; j < nbcomp; j++) + { + if (p1[i1+j]==p2[i2+j]) nbequal++; + //cout<<" "<decrRef(); + field1->decrRef(); + field2->decrRef(); + fusedCell->decrRef(); + refusedCellMesh->decrRef(); + cellMesh->decrRef(); +} + +void MEDPARTITIONERTest::verifyMetisMedpartitionerOnSmallSizeForFieldOnGaussNe() +{ + int res; + string fileName,cmd,execName,sourceName,targetName,input; + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner"; + fileName=_file_name; + fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnGaussNe.med"); + + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str()); + ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false); + + cmd=execName+" --ndomains=5 --split-method=metis"; //on same proc + sourceName=fileName; + targetName=fileName; + targetName.replace(targetName.find(".med"),4,"_partitionedTo5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose); + if (_verbose) cout<getLevel0Mesh(false); + + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); + + std::vector meshes; + std::vector corr; + meshes.push_back(cellMesh); + refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9); + meshes.push_back(refusedCellMesh); + MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); + + MEDCouplingFieldDouble* field1=MEDLoader::ReadField(ON_GAUSS_NE,fileName.c_str(),initialMesh->getName(),0,"MyFieldOnGaussNE",5,6); + MEDCouplingFieldDouble* field2=MEDLoader::ReadField(ON_GAUSS_NE,refusedName.c_str(),refusedCellMesh->getName(),0,"MyFieldOnGaussNE",5,6); + + int nbcells=corr[1]->getNumberOfTuples(); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells); + //use corr to test equality of field + DataArrayDouble* f1=field1->getArray(); + DataArrayDouble* f2=field2->getArray(); + if (_verbose>300) + { + cout << "\nf1 : " << f1->reprZip(); //123.4 for 12th cell,3rd component, 4th gausspoint + cout << "\nf2 : " << f2->reprZip(); //field2->advancedRepradvancedRepr(); + for (std::size_t i = 0; i < corr.size(); i++) + cout << "\ncorr " << i << " : " << corr[i]->reprZip(); + + } + int nbequal=0; + int nbptgauss=8; + int nbcomp=field1->getNumberOfComponents(); + double* p1=f1->getPointer(); + double* p2=f2->getPointer(); + int* pc=corr[1]->getPointer(); + for (int i = 0; i < nbcells; i++) + { + int i1=pc[i]*nbcomp*nbptgauss; + int i2=i*nbcomp*nbptgauss; + for (int j = 0; j < nbcomp*nbptgauss; j++) + { + if (p1[i1+j]==p2[i2+j]) nbequal++; + //cout<<" "<decrRef(); + field1->decrRef(); + field2->decrRef(); + fusedCell->decrRef(); + refusedCellMesh->decrRef(); + cellMesh->decrRef(); +} + diff --git a/src/MEDPartitioner/Test/MEDPARTITIONERTest.hxx b/src/MEDPartitioner/Test/MEDPARTITIONERTest.hxx index 1278b458e..50b3b8be5 100644 --- a/src/MEDPartitioner/Test/MEDPARTITIONERTest.hxx +++ b/src/MEDPartitioner/Test/MEDPARTITIONERTest.hxx @@ -33,9 +33,19 @@ class MEDPARTITIONERTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( MEDPARTITIONERTest ); - CPPUNIT_TEST( testSmallSize ); - CPPUNIT_TEST( testMedianSize ); - CPPUNIT_TEST( testHugeSize ); + CPPUNIT_TEST( testMeshCollectionSingle ); + CPPUNIT_TEST( testMeshCollectionXml ); + CPPUNIT_TEST( testMeshCollectionSinglePartitionMetis ); + CPPUNIT_TEST( testMeshCollectionComplexPartitionMetis ); + CPPUNIT_TEST( testMetisSmallSize ); + +#if defined(HAVE_MPI2) && defined(MED_ENABLE_PARMETIS) + //test with mpi on system + CPPUNIT_TEST( testMpirunSmallSize ); + CPPUNIT_TEST( testMpirunMedianSize ); + CPPUNIT_TEST( testMpirunHugeSize ); +#endif + //CPPUNIT_TEST( deleteTestMeshes ); CPPUNIT_TEST_SUITE_END(); @@ -68,11 +78,15 @@ public: void createTestMeshWithVecFieldOnCells(); void createTestMeshWithVecFieldOnNodes(); void verifyTestMeshWithVecFieldOnNodes(); + void verifyMetisMedpartitionerOnSmallSizeForMesh(); + void verifyMetisMedpartitionerOnSmallSizeForFieldOnCells(); + void verifyMetisMedpartitionerOnSmallSizeForFieldOnGaussNe(); void verifyMedpartitionerOnSmallSizeForMesh(); void verifyMedpartitionerOnSmallSizeForFieldOnCells(); void verifyMedpartitionerOnSmallSizeForFieldOnGaussNe(); void createTestMeshes(); void createHugeTestMesh(int ni, int nj, int nk, int nbx, int nby, int nbz, int nbTarget); + void launchMetisMedpartitionerOnTestMeshes(); void launchMedpartitionerOnTestMeshes(); void launchMedpartitionerOnHugeTestMeshes(); void deleteTestMeshes(); @@ -80,9 +94,17 @@ public: //for CPPUNIT_TEST void setUp(); void tearDown(); - void testSmallSize(); - void testMedianSize(); - void testHugeSize(); + void testMeshCollectionSingle(); + void testMeshCollectionXml(); + void testMeshCollectionSinglePartitionMetis(); + void testMeshCollectionComplexPartitionMetis(); + void testMetisSmallSize(); + +#if defined(HAVE_MPI2) && defined(MED_ENABLE_PARMETIS) + void testMpirunSmallSize(); + void testMpirunMedianSize(); + void testMpirunHugeSize(); +#endif }; #endif diff --git a/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx b/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx index e5332e2e7..75b1d688e 100644 --- a/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx +++ b/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx @@ -328,21 +328,6 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() cellMesh->decrRef(); } -void MEDPARTITIONERTest::createTestMeshes() -{ - createTestMeshWithoutField(); - createTestMeshWithVecFieldOnCells(); - createTestMeshWithVecFieldOnNodes(); -} - - -void MEDPARTITIONERTest::deleteTestMeshes() -{ - string cmd="rm *tmp_testMesh*"; - if (_verbose) cout<