From 75e26045c812994da489c823f35041ec831b7029 Mon Sep 17 00:00:00 2001 From: Maximilien Siavelis Date: Thu, 28 Sep 2017 11:27:55 +0200 Subject: [PATCH] replace scotch by ptscotch --- CMakeLists.txt | 3 ++ src/MEDPartitioner/CMakeLists.txt | 7 ++++ src/MEDPartitioner/MEDPARTITIONER_Graph.hxx | 1 + .../MEDPARTITIONER_MEDPartitioner.cxx | 4 +- .../MEDPARTITIONER_MEDPartitioner.hxx | 2 +- .../MEDPARTITIONER_ScotchGraph.cxx | 39 +++++++++++-------- .../MEDPARTITIONER_ScotchGraph.hxx | 4 +- .../MEDPartitionerCommon.i | 2 +- 8 files changed, 41 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25e1d9fa6..f3c7116ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,9 @@ IF(MEDCOUPLING_BUILD_TESTS) SALOME_LOG_OPTIONAL_PACKAGE(CppUnit SALOME_BUILD_TESTS) ENDIF(MEDCOUPLING_BUILD_TESTS) +FIND_PACKAGE(SalomeMPI REQUIRED) +ADD_DEFINITIONS("-DHAVE_MPI") + IF(MEDCOUPLING_USE_MPI) FIND_PACKAGE(SalomeMPI REQUIRED) ADD_DEFINITIONS("-DHAVE_MPI") diff --git a/src/MEDPartitioner/CMakeLists.txt b/src/MEDPartitioner/CMakeLists.txt index 981fc949a..8ea88ff17 100644 --- a/src/MEDPartitioner/CMakeLists.txt +++ b/src/MEDPartitioner/CMakeLists.txt @@ -56,6 +56,9 @@ IF(MEDCOUPLING_PARTITIONER_PARMETIS) INCLUDE_DIRECTORIES(${PARMETIS_INCLUDE_DIRS}) ENDIF(MEDCOUPLING_PARTITIONER_PARMETIS) +ADD_DEFINITIONS(${MPI_DEFINITIONS}) +INCLUDE_DIRECTORIES(${MPI_INCLUDE_DIRS}) + IF(MEDCOUPLING_USE_MPI) ADD_DEFINITIONS(${MPI_DEFINITIONS}) INCLUDE_DIRECTORIES(${MPI_INCLUDE_DIRS}) @@ -125,6 +128,10 @@ IF(MEDCOUPLING_PARTITIONER_SCOTCH) SET(medpartitionercpp_LDFLAGS ${medpartitionercpp_LDFLAGS} ${SCOTCH_LIBRARIES}) ENDIF(MEDCOUPLING_PARTITIONER_SCOTCH) +SET(medpartitionercpp_SOURCES ${medpartitionercpp_SOURCES} MEDPARTITIONER_UtilsPara.cxx MEDPARTITIONER_JointFinder.cxx) +SET(medpartitionercpp_LDFLAGS ${medpartitionercpp_LDFLAGS} ${MPI_LIBRARIES}) + + IF(${MEDCOUPLING_USE_MPI}) SET(medpartitionercpp_SOURCES ${medpartitionercpp_SOURCES} MEDPARTITIONER_UtilsPara.cxx MEDPARTITIONER_JointFinder.cxx) ADD_EXECUTABLE(medpartitioner_para medpartitioner_para.cxx) diff --git a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx index abf927310..63faaa18f 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx @@ -20,6 +20,7 @@ #ifndef __MEDPARTITIONER_GRAPH_HXX__ #define __MEDPARTITIONER_GRAPH_HXX__ +#include "MEDCouplingMemArray.hxx" #include "MEDPARTITIONER.hxx" #include "MCAuto.hxx" diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index 6ea40a0e6..6f14e85ab 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -137,7 +137,7 @@ MEDCoupling::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData() return _output_collection->retrieveDriver()->getMEDFileData(); } -MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight) +MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight, DataArrayInt* vlbloctab) { MEDPARTITIONER::Graph* cellGraph=0; // will be destroyed by XXXGraph class: @@ -156,7 +156,7 @@ MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCou break; case Graph::SCOTCH: #ifdef MED_ENABLE_SCOTCH - cellGraph=new SCOTCHGraph(arr,edgeweight); + cellGraph=new SCOTCHGraph(arr,edgeweight,vlbloctab); #else throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : SCOTCH is not available. Check your products, please."); #endif diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx index dc80f70eb..0f2de644d 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -42,7 +42,7 @@ namespace MEDPARTITIONER MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); MEDPartitioner(const MEDCoupling::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); MEDPartitioner(const MEDCoupling::MEDFileData* fileData, Graph* graph, bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); - static MEDPARTITIONER::Graph* Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0); + static MEDPARTITIONER::Graph* Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0, DataArrayInt* vlbloctab=0); void write(const std::string& filename); MEDCoupling::MEDFileData* getMEDFileData(); ~MEDPartitioner(); diff --git a/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx b/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx index a0d4686bd..0ab62a639 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx @@ -24,12 +24,13 @@ #include "MEDCouplingSkyLineArray.hxx" #include +#include #ifdef MED_ENABLE_SCOTCH extern "C" { #define restrict -#include "scotch.h" +#include "ptscotch.h" } #endif @@ -39,7 +40,7 @@ SCOTCHGraph::SCOTCHGraph():Graph() { } -SCOTCHGraph::SCOTCHGraph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight):Graph(graph,edgeweight) +SCOTCHGraph::SCOTCHGraph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight, DataArrayInt* vlbloctab):Graph(graph,edgeweight), _vlbloctab(vlbloctab) { } @@ -66,18 +67,24 @@ void SCOTCHGraph::partGraph(int ndomain, const std::string& options_string, Para //output parameters int* partition = new int[n+1]; - SCOTCH_Graph scotch_graph; - SCOTCH_graphInit(&scotch_graph); - SCOTCH_graphBuild(&scotch_graph, - 0, //base first indice 0 - n, //nb of graph nodes - xadj, - 0, - _cell_weight, //graph vertices loads - 0, - xadj[n], //number of edges - adjncy, - _edge_weight); + int* vlbloctab = _vlbloctab?const_cast(_vlbloctab->begin()):0; + + SCOTCH_Dgraph scotch_graph; + SCOTCH_dgraphInit(&scotch_graph, MPI_COMM_WORLD); + SCOTCH_dgraphBuild(&scotch_graph, + 0, // baseval , base first indice 0 + n, // vertlocnbr , nb of local graph nodes + n, // vertlocmax , should be set to vertlocnbr for graphs without holes + xadj, // vertloctab[vertnbr+1] , index vertex table + 0, // vendloctab , index end vertex table if disjoint, set to zero + _cell_weight, // veloloctab , graph vertices loads, set to zero + vlbloctab, // vlblocltab , vertex label array : global vertex index + xadj[n], // edgelocnbr , number of edges + xadj[n], // edgelocsiz , same as edgelocnbr if edgeloctab is compact + adjncy, // edgeloctab[edgelocnbr], global indexes of edges + 0, // edgegsttab , optionnal, should be computed internally, set to zero + _edge_weight); // edloloctab , graph edges loads, set to zero + SCOTCH_Strat scotch_strategy; SCOTCH_stratInit(&scotch_strategy); @@ -88,7 +95,7 @@ void SCOTCHGraph::partGraph(int ndomain, const std::string& options_string, Para if (nparts>1) { if (MyGlobals::_Verbose>10) std::cout << "SCOTCHGraph::graphPart SCOTCH_graphPart" << std::endl; - SCOTCH_graphPart(&scotch_graph,nparts,&scotch_strategy,partition); + SCOTCH_dgraphPart(&scotch_graph,nparts,&scotch_strategy,partition); } else //partition for 1 subdomain { @@ -97,7 +104,7 @@ void SCOTCHGraph::partGraph(int ndomain, const std::string& options_string, Para } SCOTCH_stratExit(&scotch_strategy); - SCOTCH_graphExit(&scotch_graph); + SCOTCH_dgraphExit(&scotch_graph); std::vector index(n+1); std::vector value(n); diff --git a/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.hxx b/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.hxx index cbab99edc..bfcc62727 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.hxx @@ -31,9 +31,11 @@ namespace MEDPARTITIONER { public: SCOTCHGraph(); - SCOTCHGraph(MEDCoupling::MEDCouplingSkyLineArray*, int* edgeweight=0); + SCOTCHGraph(MEDCoupling::MEDCouplingSkyLineArray*, int* edgeweight=0, DataArrayInt* vlbloctab=0); virtual ~SCOTCHGraph(); void partGraph(int ndomain, const std::string& options_string="", ParaDomainSelector* sel=0); + protected: + DataArrayInt* _vlbloctab; }; } diff --git a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i index 350ac7555..31e09e26a 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i +++ b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i @@ -78,7 +78,7 @@ namespace MEDPARTITIONER MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); MEDPartitioner(const MEDCoupling::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); MEDPartitioner(const MEDCoupling::MEDFileData* fileData, Graph* graph, bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); - static MEDPARTITIONER::Graph* Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0) throw(INTERP_KERNEL::Exception); + static MEDPARTITIONER::Graph* Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0, MEDCoupling::DataArrayInt* vlbloctab=0) throw(INTERP_KERNEL::Exception); MEDCoupling::MEDFileData* getMEDFileData() throw(INTERP_KERNEL::Exception); void write(const std::string& filename) throw(INTERP_KERNEL::Exception); }; -- 2.39.2