Octopus
metis_f.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2013 M. Oliveira
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18
19*/
20
21#include <config.h>
22
23#include <stdlib.h>
24
25#if defined(HAVE_METIS)
26#include <metis.h>
27#endif
28#if defined(HAVE_PARMETIS)
29#include <mpi.h>
30#include <parmetis.h>
31#endif
32
33#ifdef HAVE_METIS
34
35#if defined(METIS_USE_DOUBLEPRECISION) || REALTYPEWIDTH == 64
36#error METIS must be compiled in single precision for Octopus.
37#endif
38
39// Import metis enums and assign to Octopus-side C constants
40const int OCT_METIS_NOPTIONS = METIS_NOPTIONS;
41
42// Add 1 to map from C to fortran indexing
43const int OCT_METIS_OPTION_PTYPE = METIS_OPTION_PTYPE + 1;
44const int OCT_METIS_OPTION_OBJTYPE = METIS_OPTION_OBJTYPE + 1;
45const int OCT_METIS_OPTION_CTYPE = METIS_OPTION_CTYPE + 1;
46const int OCT_METIS_OPTION_IPTYPE = METIS_OPTION_IPTYPE + 1;
47const int OCT_METIS_OPTION_RTYPE = METIS_OPTION_RTYPE + 1;
48const int OCT_METIS_OPTION_DBGLVL = METIS_OPTION_DBGLVL + 1;
49const int OCT_METIS_OPTION_NITER = METIS_OPTION_NITER + 1;
50const int OCT_METIS_OPTION_NCUTS = METIS_OPTION_NCUTS + 1;
51const int OCT_METIS_OPTION_SEED = METIS_OPTION_SEED + 1;
52const int OCT_METIS_OPTION_NO2HOP = METIS_OPTION_NO2HOP + 1;
53const int OCT_METIS_OPTION_MINCONN = METIS_OPTION_MINCONN + 1;
54const int OCT_METIS_OPTION_CONTIG = METIS_OPTION_CONTIG + 1;
55const int OCT_METIS_OPTION_COMPRESS = METIS_OPTION_COMPRESS + 1;
56const int OCT_METIS_OPTION_CCORDER = METIS_OPTION_CCORDER + 1;
57const int OCT_METIS_OPTION_PFACTOR = METIS_OPTION_PFACTOR + 1;
58const int OCT_METIS_OPTION_NSEPS = METIS_OPTION_NSEPS + 1;
59const int OCT_METIS_OPTION_UFACTOR = METIS_OPTION_UFACTOR + 1;
60const int OCT_METIS_OPTION_NUMBERING = METIS_OPTION_NUMBERING + 1;
61const int OCT_METIS_OPTION_HELP = METIS_OPTION_HELP + 1;
62const int OCT_METIS_OPTION_TPWGTS = METIS_OPTION_TPWGTS + 1;
63const int OCT_METIS_OPTION_NCOMMON = METIS_OPTION_NCOMMON + 1;
64const int OCT_METIS_OPTION_NOOUTPUT = METIS_OPTION_NOOUTPUT + 1;
65const int OCT_METIS_OPTION_BALANCE = METIS_OPTION_BALANCE + 1;
66const int OCT_METIS_OPTION_GTYPE = METIS_OPTION_GTYPE + 1;
67const int OCT_METIS_OPTION_UBVEC = METIS_OPTION_UBVEC + 1;
68
69#if METIS_VER_MAJOR > 5 || (METIS_VER_MAJOR == 5 && METIS_VER_MINOR >= 2)
70const int OCT_METIS_OPTION_NIPARTS = METIS_OPTION_NIPARTS + 1;
71const int OCT_METIS_OPTION_ONDISK = METIS_OPTION_ONDISK + 1;
72const int OCT_METIS_OPTION_DROPEDGES = METIS_OPTION_DROPEDGES + 1;
73const int OCT_METIS_OPTION_TWOHOP = METIS_OPTION_TWOHOP + 1;
74const int OCT_METIS_OPTION_FAST = METIS_OPTION_FAST + 1;
75#else
76const int OCT_METIS_OPTION_NIPARTS = -1;
77const int OCT_METIS_OPTION_ONDISK = -1;
78const int OCT_METIS_OPTION_DROPEDGES = -1;
79const int OCT_METIS_OPTION_TWOHOP = -1;
80const int OCT_METIS_OPTION_FAST = -1;
81#endif
82
83// Initialise options to metis defaults
84void FC_FUNC_(oct_metis_setdefaultoptions,
85 OCT_METIS_SETDEFAULTOPTIONS)(idx_t *options) {
86 METIS_SetDefaultOptions(options);
87}
88
89int FC_FUNC_(oct_metis_partgraphrecursive, OCT_METIS_PARTGRAPHRECURSIVE)(
90 idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, idx_t *nparts,
91 real_t *tpwgts, real_t *ubvec, idx_t *options, idx_t *objval, idx_t *part) {
92
93 return METIS_PartGraphRecursive(nvtxs, ncon, xadj, adjncy, NULL, NULL, NULL,
94 nparts, tpwgts, ubvec, options, objval, part);
95}
96
97int FC_FUNC_(oct_metis_partgraphkway, OCT_METIS_PARTGRAPHKWAY)(
98 idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, idx_t *nparts,
99 real_t *tpwgts, real_t *ubvec, idx_t *options, idx_t *objval, idx_t *part) {
100
101 return METIS_PartGraphKway(nvtxs, ncon, xadj, adjncy, NULL, NULL, NULL,
102 nparts, tpwgts, ubvec, options, objval, part);
103}
104
105#else
106const int OCT_METIS_NOPTIONS = -1;
107
108const int OCT_METIS_OPTION_PTYPE = -1;
109const int OCT_METIS_OPTION_OBJTYPE = -1;
110const int OCT_METIS_OPTION_CTYPE = -1;
111const int OCT_METIS_OPTION_IPTYPE = -1;
112const int OCT_METIS_OPTION_RTYPE = -1;
113const int OCT_METIS_OPTION_DBGLVL = -1;
114const int OCT_METIS_OPTION_NITER = -1;
115const int OCT_METIS_OPTION_NCUTS = -1;
116const int OCT_METIS_OPTION_SEED = -1;
117const int OCT_METIS_OPTION_NO2HOP = -1;
118const int OCT_METIS_OPTION_MINCONN = -1;
119const int OCT_METIS_OPTION_CONTIG = -1;
120const int OCT_METIS_OPTION_COMPRESS = -1;
121const int OCT_METIS_OPTION_CCORDER = -1;
122const int OCT_METIS_OPTION_PFACTOR = -1;
123const int OCT_METIS_OPTION_NSEPS = -1;
124const int OCT_METIS_OPTION_UFACTOR = -1;
125const int OCT_METIS_OPTION_NUMBERING = -1;
126const int OCT_METIS_OPTION_HELP = -1;
127const int OCT_METIS_OPTION_TPWGTS = -1;
128const int OCT_METIS_OPTION_NCOMMON = -1;
129const int OCT_METIS_OPTION_NOOUTPUT = -1;
130const int OCT_METIS_OPTION_BALANCE = -1;
131const int OCT_METIS_OPTION_GTYPE = -1;
132const int OCT_METIS_OPTION_UBVEC = -1;
133const int OCT_METIS_OPTION_NIPARTS = -1;
134const int OCT_METIS_OPTION_ONDISK = -1;
135const int OCT_METIS_OPTION_DROPEDGES = -1;
136const int OCT_METIS_OPTION_TWOHOP = -1;
137const int OCT_METIS_OPTION_FAST = -1;
138#endif
139
140#ifdef HAVE_PARMETIS
141
142void FC_FUNC_(oct_parmetis_v3_partkway,
143 OCT_PARMETIS_V3_PARTKWAY)(idx_t *vtxdist, idx_t *xadj, idx_t *adjncy,
144 idx_t *ncon, idx_t *nparts, real_t *tpwgts,
145 real_t *ubvec, idx_t *options,
146 idx_t *edgecut, idx_t *part,
147 MPI_Fint *fcomm) {
148 idx_t wgtflag = 0, numflag = 1;
149
150 MPI_Comm comm;
151
152 comm = MPI_Comm_f2c(*fcomm);
153
154 ParMETIS_V3_PartKway(vtxdist, xadj, adjncy, NULL, NULL, &wgtflag, &numflag,
155 ncon, nparts, tpwgts, ubvec, options, edgecut, part,
156 &comm);
157}
158
159#endif
void FC_FUNC_(clean_clarg, CLEAN_CLARG)()
Definition: getopt_f.c:7968