~ubuntu-branches/ubuntu/maverick/dolfin/maverick

« back to all changes in this revision

Viewing changes to sandbox/partitioning/partition.h

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2009-10-12 14:13:18 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012141318-hkbxl0sq555vqv7d
Tags: 0.9.4-1
* New upstream release. This version cleans up the design of the
  function class by adding a new abstraction for user-defined
  functions called Expression. A number of minor bugfixes and
  improvements have also been made.
* debian/watch: Update for new flat directory structure.
* Update debian/copyright.
* debian/rules: Use explicit paths to PETSc 3.0.0 and SLEPc 3.0.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <dolfin.h>
2
 
#include <iostream>
3
 
 
4
 
#include <parmetis.h>
5
 
extern "C"
6
 
{
7
 
  #include <metis/metis.h>
8
 
  #include <scotch.h>
9
 
}
10
 
using namespace dolfin;
11
 
 
12
 
void metisKwayPartitioning(Graph& graph, int num_part, idxtype* vtx_part)
13
 
{
14
 
  int options[5];
15
 
  int num_vertices = graph.numVertices();
16
 
  int wgtflag = 0;
17
 
  int pnumflag = 0;
18
 
  int edgecut = 0;
19
 
  
20
 
  // This results in segfault
21
 
  //idxtype* adjncy = reinterpret_cast<idxtype*>(graph.connectivity());
22
 
  //idxtype* xadj = reinterpret_cast<idxtype*>(graph.offsets() + 1);
23
 
 
24
 
  // Copying values instead (time to copy << time to partitioning)
25
 
  idxtype* adjncy = new idxtype[graph.numEdges()];
26
 
  idxtype* xadj = new idxtype[graph.numVertices() + 1];
27
 
  for(unsigned int i=0; i<graph.numEdges(); ++i)
28
 
    adjncy[i] = graph.connectivity()[i];
29
 
  for(unsigned int i=0; i<=graph.numVertices(); ++i)
30
 
    xadj[i] = graph.offsets()[i];
31
 
 
32
 
  options[0] = 0;
33
 
  METIS_PartGraphKway(&num_vertices, xadj, adjncy, NULL, NULL, &wgtflag, &pnumflag, &num_part, options, &edgecut, vtx_part);
34
 
}
35
 
 
36
 
void metisRecursivePartitioning(Graph& graph, int num_part, int* vtx_part)
37
 
{
38
 
  int options[5];
39
 
  int num_vertices = graph.numVertices();
40
 
  int wgtflag = 0;
41
 
  int pnumflag = 0;
42
 
  int edgecut = 0;
43
 
  
44
 
  // This results in segfault
45
 
  //idxtype* adjncy = reinterpret_cast<idxtype*>(graph.connectivity());
46
 
  //idxtype* xadj = reinterpret_cast<idxtype*>(graph.offsets() + 1);
47
 
 
48
 
  // Copying values instead (time to copy << time to partitioning)
49
 
  idxtype* adjncy = new idxtype[graph.numEdges()];
50
 
  idxtype* xadj = new idxtype[graph.numVertices() + 1];
51
 
  for(unsigned int i=0; i<graph.numEdges(); ++i)
52
 
    adjncy[i] = graph.connectivity()[i];
53
 
  for(unsigned int i=0; i<=graph.numVertices(); ++i)
54
 
    xadj[i] = graph.offsets()[i];
55
 
 
56
 
  options[0] = 0;
57
 
  METIS_PartGraphRecursive(&num_vertices, xadj, adjncy, NULL, NULL, &wgtflag, &pnumflag, &num_part, options, &edgecut, vtx_part);
58
 
}
59
 
 
60
 
void scotchPartitioning(Graph& graph, int num_part, int* vtx_part)
61
 
{
62
 
  SCOTCH_Graph grafdat;
63
 
  SCOTCH_Strat strat;
64
 
 
65
 
  if (SCOTCH_graphInit (&grafdat) != 0) {
66
 
    std::cerr << "Error in SCOTCH_graphInit. Exiting" << std::endl;
67
 
    exit(1);
68
 
  }
69
 
  if (SCOTCH_graphBuild (&grafdat, 0, static_cast<int>(graph.numVertices()), reinterpret_cast<int*>(graph.offsets()), NULL, NULL, NULL, static_cast<int>(graph.numEdges()), reinterpret_cast<int*>(graph.connectivity()), NULL) != 0) {
70
 
    std::cerr << "Error in SCOTCH_graphBuild. Exiting" << std::endl;
71
 
    exit(1);
72
 
  }
73
 
 
74
 
  SCOTCH_stratInit(&strat);
75
 
 
76
 
  /*
77
 
  if (SCOTCH_stratGraphBipart (&strat, "b{job=t,map=t,poli=S,strat=m{type=h,vert=80,low=h{pass=10}f{bal=0.0005,move=80},asc=b{bnd=d{dif=1,rem=1,pass=40}f{bal=0.005,move=80},org=f{bal=0.005,move=80}}}|m{type=h,vert=80,low=h{pass=10}f{bal=0.0005,move=80},asc=b{bnd=d{dif=1,rem=1,pass=40}f{bal=0.005,move=80},org=f{bal=0.005,move=80}}}}")) {
78
 
  }
79
 
  */
80
 
 
81
 
  if (SCOTCH_graphPart (&grafdat, num_part, &strat, vtx_part) != 0) {
82
 
    std::cerr << "Error in SCOTCH_graphPart. Exiting" << std::endl;
83
 
    exit(1);
84
 
  }
85
 
 
86
 
  SCOTCH_stratExit (&strat);
87
 
  SCOTCH_graphExit (&grafdat);
88
 
}