4 #include "bin/scotch.h"
6 #include "MEDSPLITTER_Graph.hxx"
7 #include "MEDSPLITTER_SCOTCHGraph.hxx"
9 using namespace MEDSPLITTER;
11 SCOTCHGraph::SCOTCHGraph():Graph()
15 SCOTCHGraph::SCOTCHGraph(const MEDMEM::MEDSKYLINEARRAY* graph, int* edgeweight):Graph(graph,edgeweight)
19 SCOTCHGraph::~SCOTCHGraph()
21 if (m_partition!=0) {delete m_partition; m_partition=0;}
22 if (m_graph!=0) {delete m_graph; m_graph=0;}
25 void SCOTCHGraph::partGraph(int ndomain, const string& options_string)
27 // number of graph vertices
28 int n = m_graph->getNumberOf();
31 int * xadj=const_cast<int*>(m_graph->getIndex());
32 int * adjncy = const_cast<int*>(m_graph->getValue());
38 int* partition = new int[n+1];
40 SCOTCH_Graph scotch_graph;
42 SCOTCH_graphInit(&scotch_graph);
45 SCOTCH_graphBuild(&scotch_graph,
47 n, // nb of graph nodes
50 m_cellweight, //graph vertices loads
52 xadj[n], // number of edges
56 SCOTCH_Strat scotch_strategy;
57 SCOTCH_stratInit(&scotch_strategy);
59 //!user-defined options for the strategy
60 if (options_string!="")
61 SCOTCH_stratGraphMap(&scotch_strategy,options_string.c_str());
65 SCOTCH_graphPart(&scotch_graph,nparts,&scotch_strategy,partition);
67 // partition for 1 subdomain
68 for (int i=0; i<n+1; i++)
71 SCOTCH_stratExit(&scotch_strategy);
72 SCOTCH_graphExit(&scotch_graph);
74 int* index=new int [n+1];
76 for (int i=0; i<n; i++)
78 index[i+1]=index[i]+1;
81 //creating a skylinearray with no copy of the index and partition array
82 // the fifth argument true specifies that only the pointers are passed
84 m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, true);