~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/sandbox/partitioning/main.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "partition.h"
2
 
#include <iostream>
3
 
#include <fstream>
4
 
 
5
 
using namespace dolfin;
6
 
 
7
 
void partition(Mesh& mesh, int num_part, int max_cells, char* filename,
8
 
               void (partFunc(Graph&, int, int*)), char* plotname)
9
 
{
10
 
  MeshFunction<dolfin::uint> parts;
11
 
  int num_cells = mesh.numCells();
12
 
  std::ofstream resultfile(filename);
13
 
  resultfile << plotname << " with " << num_part << " partitions" << std::endl;
14
 
  resultfile << "Cells " << "Seconds " << "Edgecut " << "Balance" << std::endl;
15
 
  while(num_cells < max_cells)
16
 
  {
17
 
    Graph graph(mesh);
18
 
    parts.init(mesh, mesh.topology().dim());
19
 
 
20
 
    real time = 0;
21
 
    int runs = 0;
22
 
 
23
 
    std::cout << "\nPartitioning mesh with " << num_cells << " cells" << std::endl;
24
 
    do
25
 
    {
26
 
      tic();
27
 
      partFunc(graph, num_part, reinterpret_cast<int*>(parts.values()));
28
 
      time += toc();
29
 
      runs++;
30
 
    }
31
 
    while(time < 1);
32
 
    real runtime = time/runs;
33
 
    int edgecut = GraphPartition::edgecut(graph, num_part, parts.values());
34
 
 
35
 
    resultfile << num_cells << " " << runtime << " " << edgecut << std::endl;
36
 
    std::cout << "Time to partition: " << runtime << std::endl;
37
 
    std::cout << "Edge cut: " << edgecut << std::endl;
38
 
 
39
 
    std::cout << "Refining mesh... " << std::endl;
40
 
    mesh.refine();
41
 
    num_cells = mesh.numCells();
42
 
  }
43
 
  resultfile.close();
44
 
 
45
 
}
46
 
int main(int argc, char* argv[])
47
 
{
48
 
  if(argc != 6)
49
 
  {
50
 
    std::cerr << "Usage: " << argv[0] << 
51
 
      " <metis1|metis2|scotch> <meshfile> <num_part> <max_cells> <resultfile>\n";
52
 
    exit(1);
53
 
  }
54
 
 
55
 
  char* partitioner = argv[1];
56
 
  char* infilename = argv[2];
57
 
  int num_part = atoi(argv[3]);
58
 
  int max_cells = atoi(argv[4]);
59
 
  char* outfilename = argv[5];
60
 
 
61
 
  Mesh mesh(infilename);
62
 
  if(strcmp(partitioner, "metis1") == 0)
63
 
  {
64
 
    std::cout << "Using Metis Kway to partition mesh into " << num_part << " partitions " << std::endl;
65
 
    partition(mesh, num_part, max_cells, outfilename, 
66
 
              metisKwayPartitioning, "Metis Kway");
67
 
    std::cout << "\n\n";
68
 
  }
69
 
  else if(strcmp(partitioner, "metis2") == 0)
70
 
  {
71
 
    std::cout << "Using Metis recursive to partition mesh into " << num_part << " partitions " << std::endl;
72
 
    partition(mesh, num_part, max_cells, outfilename, 
73
 
              metisRecursivePartitioning, "Metis recursive");
74
 
    std::cout << "\n\n";
75
 
  }
76
 
  else if(strcmp(partitioner, "scotch") == 0)
77
 
  {
78
 
    std::cout << "Using Scotch to partition mesh into " << num_part << " partitions " << std::endl;
79
 
    partition(mesh, num_part, max_cells, outfilename,
80
 
                 scotchPartitioning, "Scotch");
81
 
    std::cout << "\n\n";
82
 
  }
83
 
  else
84
 
  {
85
 
    std::cerr << "Usage: " << argv[0] << 
86
 
      " <metis1|metis2|scotch> <meshfile> <num_part> <max_cells> <resultfile>\n";
87
 
    exit(1);
88
 
  }
89
 
}