1 // Copyright (C) 2007-2016 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_ParMetisGraph.hxx"
21 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
22 #include "MEDPARTITIONER_Utils.hxx"
24 #include "MEDCouplingSkyLineArray.hxx"
25 #include "InterpKernelException.hxx"
29 #ifdef MED_ENABLE_PARMETIS
31 // #if PARMETIS_MAJOR_VERSION == 4
32 // #define ParMETIS_PartKway ParMETIS_V3_PartKway
36 using namespace MEDPARTITIONER;
38 ParMETISGraph::ParMETISGraph():Graph()
42 ParMETISGraph::ParMETISGraph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight)
43 :Graph(graph,edgeweight)
47 ParMETISGraph::~ParMETISGraph()
51 void ParMETISGraph::partGraph(int ndomain,
52 const std::string& options_string,
53 ParaDomainSelector *parallelizer)
56 vector<int> ran,vx,va; //for randomize
58 if (MyGlobals::_Verbose>10)
59 std::cout << "proc " << MyGlobals::_Rank << " : ParMETISGraph::partGraph" << std::endl;
61 // number of graph vertices
62 int n=_graph->getNumberOf();
64 int * xadj=const_cast<int*>(_graph->getIndex());
65 int * adjncy=const_cast<int*>(_graph->getValue());
67 int * vwgt=_cell_weight;
68 int * adjwgt=_edge_weight;
69 int wgtflag=(_edge_weight!=0)?1:0+(_cell_weight!=0)?2:0;
76 (0=default_option,option,random_seed) see defs.h
77 #define PMV3_OPTION_DBGLVL 1
78 #define PMV3_OPTION_SEED 2
79 #define PMV3_OPTION_IPART 3
80 #define PMV3_OPTION_PSR 3
81 seems no changes int options[4]={1,0,33,0}; //test for a random seed of 33
83 int options[4]={0,0,0,0};
86 #if !defined(MED_ENABLE_PARMETIS)
87 throw INTERP_KERNEL::Exception("ParMETISGraph::partGraph : PARMETIS is not available. Check your products, please.");
89 int* partition=new int[n];
91 if (MyGlobals::_Verbose>10)
92 std::cout << "proc " << MyGlobals::_Rank << " : ParMETISGraph::partGraph ParMETIS_PartKway new" << std::endl;
93 int * vtxdist=parallelizer->getProcVtxdist();
94 MPI_Comm comm=MPI_COMM_WORLD;
95 ParMETIS_PartKway(vtxdist, xadj, adjncy, vwgt,
96 adjwgt, &wgtflag, &base, &nparts, options,
97 &edgecut, partition, &comm );
100 /*doc from parmetis.h
101 void __cdecl ParMETIS_PartKway(
102 idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
103 idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options,
104 int *edgecut, idxtype *part, MPI_Comm *comm);
106 void __cdecl ParMETIS_V3_PartKway(
107 idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
108 idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, int *nparts,
109 float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part,
113 vector<int> index(n+1);
114 vector<int> value(n);
116 if (ran.size()>0 && MyGlobals::_Atomize==0) //there is randomize
118 if (MyGlobals::_Is0verbose>100)
119 std::cout << "randomize" << std::endl;
120 for (int i=0; i<n; i++)
122 index[i+1]=index[i]+1;
123 value[ran[i]]=partition[i];
128 for (int i=0; i<n; i++)
130 index[i+1]=index[i]+1;
131 value[i]=partition[i];
136 //creating a skylinearray with no copy of the index and partition array
137 //the fifth argument true specifies that only the pointers are passed
140 _partition = new MEDCoupling::MEDCouplingSkyLineArray(index,value);