-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
118 lines (91 loc) · 2.74 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include "metis.h"
// See the mesh here:
// https://github.com/dfroger/metis4py/blob/master/part_mesh_nodal.ipynb
// Number of elements in the mesh (18 triangles).
#define NE 18
// Number of nodes in the mesh (16 points).
#define NN 16
// All node have equal weight.
#define VWGT NULL
// All node have equal size.
#define VSIZE NULL
// All partition have equal weight.
#define TPWGTS NULL
// No options.
#define OPTIONS NULL
int main()
{
// =====================================
// Set Metis inputs values.
// =====================================
// Number of elements in the mesh (18 triangles).
idx_t ne = NE;
// Number of nodes in the mesh (16 points).
idx_t nn = NN;
// Indices for eind.
idx_t eptr[NE+1] = { 0, 3, 6, 9,
12,15,18,21,
24,27,30,33,
36,39,42,45,
48,51,54};
// Triangles point indices.
idx_t eind[NE*3] = {0, 4, 1, 1, 5, 2, 2, 6, 3,
4, 8, 5, 5, 9, 6, 6,10, 7,
8, 9,12, 9,10,13, 10,11,14,
1, 4, 5, 2, 5, 6, 3, 6, 7,
5, 8, 9, 6, 9,10, 7,10,11,
9,12,13, 10,13,14, 11,14,15};
// Number of partition.
idx_t nparts = 3;
// =====================================
// Allocate Metis outputs.
// =====================================
// Total communication volume.
idx_t objval;
// Element and node partition vectors.
idx_t epart[NE];
idx_t npart[NN];
// =====================================
// Call Metis function.
// =====================================
int err = METIS_PartMeshNodal(&ne, &nn, eptr, eind, VWGT, VSIZE,
&nparts, TPWGTS, OPTIONS, &objval,
epart, npart);
// =====================================
// Print Metis results.
// =====================================
switch (err)
{
case METIS_OK:
break;
case METIS_ERROR_INPUT:
printf("error input\n");
return 1;
break;
case METIS_ERROR_MEMORY:
printf("error memory\n");
return 1;
break;
case METIS_ERROR:
printf("error\n");
return 1;
break;
default:
printf("Unexpected return value: %d\n", err);
return 1;
break;
}
printf("objval: %"PRId64"\n", objval);
printf("epart: ");
idx_t i;
for (i= 0 ; i < ne ; i++)
printf("%"PRId64" ", epart[i]);
printf("\n");
printf("npart: ");
for (i= 0 ; i < nn ; i++)
printf("%"PRId64" ", npart[i]);
printf("\n");
printf("%lu\n", sizeof(idx_t));
return 0;
}