1 // Copyright (C) 2017-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPARTITIONER_PTScotchGraph.hxx"
21 #include "MEDPARTITIONER_Utils.hxx"
23 #include "MEDCouplingSkyLineArray.hxx"
24 #include "MEDCouplingMemArray.hxx"
30 #ifdef MED_ENABLE_PTSCOTCH
38 using namespace MEDPARTITIONER;
41 PTSCOTCHGraph::PTSCOTCHGraph(MEDCoupling::MEDCouplingSkyLineArray *graph, int *edgeweight, DataArrayIdType *vlbloctab):Graph(graph,edgeweight),_vlbloctab(vlbloctab)
45 PTSCOTCHGraph::~PTSCOTCHGraph()
49 void PTSCOTCHGraph::partGraph(int ndomain, const std::string& options_string, ParaDomainSelector* sel)
51 if (MyGlobals::_Verbose>10)
52 std::cout << "proc " << MyGlobals::_Rank << " : PTSCOTCHGraph::partGraph" << std::endl;
54 //number of graph vertices
55 int n = FromIdType<int>(_graph->getNumberOf());
57 #ifdef MEDCOUPLING_USE_64BIT_IDS
58 std::vector<int> indexVec( _graph->getIndex(), _graph->getIndexArray()->end() );
59 std::vector<int> valueVec( _graph->getValues(), _graph->getValuesArray()->end() );
60 int * xadj=indexVec.data();
61 int * adjncy=valueVec.data();
63 int * xadj=const_cast<int*>(_graph->getIndex());
64 int * adjncy=const_cast<int*>(_graph->getValues());
69 #if !defined(MED_ENABLE_PTSCOTCH)
70 throw INTERP_KERNEL::Exception("PTSCOTCHGraph::partGraph : PTSCOTCH is not available. Check your products, please.");
73 int* partition = new int[n+1];
75 int* vlbloctab = _vlbloctab?const_cast<int*>(_vlbloctab->begin()):0;
78 SCOTCH_Dgraph scotch_graph;
79 SCOTCH_dgraphInit(&scotch_graph, MPI_COMM_WORLD);
80 SCOTCH_dgraphBuild(&scotch_graph,
81 0, // baseval , base first indice 0
82 n, // vertlocnbr , nb of local graph nodes
83 n, // vertlocmax , should be set to vertlocnbr for graphs without holes
84 xadj, // vertloctab[vertnbr+1] , index vertex table
85 0, // vendloctab , index end vertex table if disjoint, set to zero
86 _cell_weight, // veloloctab , graph vertices loads, set to zero
87 vlbloctab, // vlblocltab , vertex label array : global vertex index
88 xadj[n], // edgelocnbr , number of edges
89 xadj[n], // edgelocsiz , same as edgelocnbr if edgeloctab is compact
90 adjncy, // edgeloctab[edgelocnbr], global indexes of edges
91 0, // edgegsttab , optional, should be computed internally, set to zero
92 _edge_weight); // edloloctab , graph edges loads, set to zero
94 SCOTCH_Strat scotch_strategy;
95 SCOTCH_stratInit(&scotch_strategy);
97 //!user-defined options for the strategy
98 if (options_string!="")
99 SCOTCH_stratGraphMap(&scotch_strategy,options_string.c_str());
103 if (MyGlobals::_Verbose>10) std::cout << "SCOTCHGraph::graphPart SCOTCH_graphPart" << std::endl;
104 SCOTCH_dgraphPart(&scotch_graph,nparts,&scotch_strategy,partition);
106 else //partition for 1 subdomain
108 for (int i=0; i<n+1; i++)
112 SCOTCH_stratExit(&scotch_strategy);
113 SCOTCH_dgraphExit(&scotch_graph);
115 std::vector<mcIdType> index(n+1);
116 std::vector<mcIdType> value(n);
118 for (int i=0; i<n; i++)
120 index[i+1]=index[i]+1;
121 value[i]=ToIdType(partition[i]);
125 //creating a skylinearray with no copy of the index and partition array
126 //the fifth argument true specifies that only the pointers are passed
128 _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value);