1 // Copyright (C) 2007-2012 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.
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 #ifdef MED_ENABLE_PARMETIS
23 #ifdef MED_ENABLE_METIS
29 #include "MEDSPLITTER_METISGraph.hxx"
30 #include "MEDSPLITTER_ParaDomainSelector.hxx"
32 using namespace MEDSPLITTER;
34 METISGraph::METISGraph():Graph()
38 METISGraph::METISGraph(MEDMEM::MEDSKYLINEARRAY* graph, int* edgeweight)
39 :Graph(graph,edgeweight)
43 METISGraph::~METISGraph()
47 void METISGraph::partGraph(int ndomain,
48 const string& options_string,
49 ParaDomainSelector* parallelizer)
51 // number of graph vertices
52 int n = m_graph->getNumberOf();
55 int * xadj=const_cast<int*>(m_graph->getIndex());
56 int * adjncy = const_cast<int*>(m_graph->getValue());
58 int * vwgt=m_cellweight;
59 int * adjwgt=m_edgeweight;
60 int wgtflag=(m_edgeweight!=0)?1:0+(m_cellweight!=0)?2:0;
69 int options[5]={0,0,0,0,0};
73 int* partition = new int[n];
79 #ifdef MED_ENABLE_PARMETIS
80 // distribution of vertices of the graph among the processors
81 int * vtxdist = parallelizer ? parallelizer->getNbVertOfProcs() : 0;
82 MPI_Comm comm = MPI_COMM_WORLD;
84 ParMETIS_PartKway( vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag,
85 &base, &nparts, options, &edgecut, partition, &comm );
87 throw MED_EXCEPTION("ParMETIS is not available. Check your products, please.");
92 #ifdef MED_ENABLE_METIS
93 if (options_string != "k")
94 METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
95 &base, &nparts, options, &edgecut, partition);
97 METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
98 &base, &nparts, options, &edgecut, partition);
100 throw MED_EXCEPTION("METIS is not available. Check your products, please.");
106 for (int i=0; i<n; i++)
110 int* index=new int [n+1];
112 for (int i=0; i<n; i++)
114 index[i+1]=index[i]+1;
118 //creating a skylinearray with no copy of the index and partition array
119 // the fifth argument true specifies that only the pointers are passed
121 m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, true);