1 // Copyright (C) 2007-2015 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_MetisGraph.hxx"
21 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
22 #include "MEDPARTITIONER_Utils.hxx"
24 #include "MEDCouplingSkyLineArray.hxx"
25 #include "InterpKernelException.hxx"
31 #include "MEDPARTITIONER_metis.h"
34 using namespace MEDPARTITIONER;
36 METISGraph::METISGraph():Graph()
40 METISGraph::METISGraph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight)
41 :Graph(graph,edgeweight)
45 METISGraph::~METISGraph()
49 void METISGraph::partGraph(int ndomain,
50 const std::string& options_string,
51 ParaDomainSelector *parallelizer)
54 if (MyGlobals::_Verbose>10)
55 std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph" << std::endl;
57 //number of graph vertices
58 int n=_graph->getNumberOf();
60 int * xadj=const_cast<int*>(_graph->getIndex());
61 int * adjncy=const_cast<int*>(_graph->getValue());
63 int * vwgt=_cell_weight;
64 int * adjwgt=_edge_weight;
65 int wgtflag=(_edge_weight!=0)?1:0+(_cell_weight!=0)?2:0;
72 (0=default_option,option,random_seed) see defs.h
73 #define PMV3_OPTION_DBGLVL 1
74 #define PMV3_OPTION_SEED 2
75 #define PMV3_OPTION_IPART 3
76 #define PMV3_OPTION_PSR 3
77 seems no changes int options[4]={1,0,33,0}; //test for a random seed of 33
79 int options[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
80 #if !defined(MED_ENABLE_METIS)
81 throw INTERP_KERNEL::Exception("METISGraph::partGraph : METIS is not available. Check your products, please.");
85 int* partition=new int[n];
89 if (MyGlobals::_Verbose>10)
90 std::cout << "METISGraph::partGraph METIS_PartGraph METIS_PartGraph(RecursiveOrKway)" << std::endl;
91 if (options_string != "k")
92 MEDPARTITIONER_METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
93 &base, &nparts, options, &edgecut, partition);
95 MEDPARTITIONER_METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
96 &base, &nparts, options, &edgecut, partition);
98 else //force this case because METIS send all 1 in value
100 for (int i=0; i<n; i++)
103 vector<int> index(n+1);
104 vector<int> value(n);
106 for (int i=0; i<n; i++)
108 index[i+1]=index[i]+1;
109 value[i]=partition[i];
113 //creating a skylinearray with no copy of the index and partition array
114 //the fifth argument true specifies that only the pointers are passed
116 _partition = new MEDCoupling::MEDCouplingSkyLineArray(index,value);