Octopus
metis.F90
Go to the documentation of this file.
1!! Copyright (C) 2013 M. Oliveira
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21! -----------------------------------------------------------------------
23! -----------------------------------------------------------------------
24
25module metis_oct_m
26 use, intrinsic :: iso_c_binding
27 use, intrinsic :: iso_fortran_env
28 use mpi_oct_m
29 implicit none
30
31 public
32
33 ! Enums used to index the METIS options array
34 ! Default to -1 if METIS is not available. See metis_f.c
35 integer(c_int), bind(c, name="OCT_METIS_NOPTIONS"), protected :: METIS_NOPTIONS
36
37 integer(c_int), bind(c, name="OCT_METIS_OPTION_PTYPE"), protected :: METIS_OPTION_PTYPE
38 integer(c_int), bind(c, name="OCT_METIS_OPTION_OBJTYPE"), protected :: METIS_OPTION_OBJTYPE
39 integer(c_int), bind(c, name="OCT_METIS_OPTION_CTYPE"), protected :: METIS_OPTION_CTYPE
40 integer(c_int), bind(c, name="OCT_METIS_OPTION_IPTYPE"), protected :: METIS_OPTION_IPTYPE
41 integer(c_int), bind(c, name="OCT_METIS_OPTION_RTYPE"), protected :: METIS_OPTION_RTYPE
42 integer(c_int), bind(c, name="OCT_METIS_OPTION_DBGLVL"), protected :: METIS_OPTION_DBGLVL
43 integer(c_int), bind(c, name="OCT_METIS_OPTION_NITER"), protected :: METIS_OPTION_NITER
44 integer(c_int), bind(c, name="OCT_METIS_OPTION_NCUTS"), protected :: METIS_OPTION_NCUTS
45 integer(c_int), bind(c, name="OCT_METIS_OPTION_SEED"), protected :: METIS_OPTION_SEED
46 integer(c_int), bind(c, name="OCT_METIS_OPTION_NO2HOP"), protected :: METIS_OPTION_NO2HOP
47 integer(c_int), bind(c, name="OCT_METIS_OPTION_MINCONN"), protected :: METIS_OPTION_MINCONN
48 integer(c_int), bind(c, name="OCT_METIS_OPTION_CONTIG"), protected :: METIS_OPTION_CONTIG
49 integer(c_int), bind(c, name="OCT_METIS_OPTION_COMPRESS"), protected :: METIS_OPTION_COMPRESS
50 integer(c_int), bind(c, name="OCT_METIS_OPTION_CCORDER"), protected :: METIS_OPTION_CCORDER
51 integer(c_int), bind(c, name="OCT_METIS_OPTION_PFACTOR"), protected :: METIS_OPTION_PFACTOR
52 integer(c_int), bind(c, name="OCT_METIS_OPTION_NSEPS"), protected :: METIS_OPTION_NSEPS
53 integer(c_int), bind(c, name="OCT_METIS_OPTION_UFACTOR"), protected :: METIS_OPTION_UFACTOR
54 integer(c_int), bind(c, name="OCT_METIS_OPTION_NUMBERING"), protected :: METIS_OPTION_NUMBERING
55 integer(c_int), bind(c, name="OCT_METIS_OPTION_HELP"), protected :: METIS_OPTION_HELP
56 integer(c_int), bind(c, name="OCT_METIS_OPTION_TPWGTS"), protected :: METIS_OPTION_TPWGTS
57 integer(c_int), bind(c, name="OCT_METIS_OPTION_NCOMMON"), protected :: METIS_OPTION_NCOMMON
58 integer(c_int), bind(c, name="OCT_METIS_OPTION_NOOUTPUT"), protected :: METIS_OPTION_NOOUTPUT
59 integer(c_int), bind(c, name="OCT_METIS_OPTION_BALANCE"), protected :: METIS_OPTION_BALANCE
60 integer(c_int), bind(c, name="OCT_METIS_OPTION_GTYPE"), protected :: METIS_OPTION_GTYPE
61 integer(c_int), bind(c, name="OCT_METIS_OPTION_UBVEC"), protected :: METIS_OPTION_UBVEC
62 ! Options added after METIS 5.1.0
63 integer(c_int), bind(c, name="OCT_METIS_OPTION_NIPARTS"), protected :: METIS_OPTION_NIPARTS
64 integer(c_int), bind(c, name="OCT_METIS_OPTION_ONDISK"), protected :: METIS_OPTION_ONDISK
65 integer(c_int), bind(c, name="OCT_METIS_OPTION_DROPEDGES"), protected :: METIS_OPTION_DROPEDGES
66 integer(c_int), bind(c, name="OCT_METIS_OPTION_TWOHOP"), protected :: METIS_OPTION_TWOHOP
67 integer(c_int), bind(c, name="OCT_METIS_OPTION_FAST"), protected :: METIS_OPTION_FAST
68
69 !Error code from metis.h
70 integer, parameter :: &
71 METIS_OK = 1, & !< Returned normally
72 metis_error_input = -2, &
73 metis_error_memory = -3, &
74 metis_error = -4
75
76 ! define the integer kind as needed for the metis installation
77#if METIS_IDXTYPEWIDTH == 64
78 integer, parameter :: imetis = int64
79 type(MPI_Datatype), parameter :: MPI_METIS_INT = mpi_integer8
80#else
81 integer, parameter :: imetis = int32
82 type(MPI_Datatype), parameter :: MPI_METIS_INT = mpi_integer
83#endif
84
85 interface
86
87#if defined(HAVE_PARMETIS) || defined(HAVE_METIS)
88 subroutine oct_metis_setdefaultoptions(options)
89 import :: imetis
90 implicit none
91 integer(imetis), intent(inout) :: options
92 end subroutine oct_metis_setdefaultoptions
93
94 integer function oct_metis_partgraphrecursive(nvtxs, ncon, xadj, adjncy, nparts, tpwgts, ubvec, options, objval, part)
95 use, intrinsic :: iso_fortran_env
96 import :: imetis
97 implicit none
98 integer(imetis), intent(in) :: nvtxs
99 integer(imetis), intent(in) :: ncon
100 integer(imetis), intent(in) :: xadj
101 integer(imetis), intent(in) :: adjncy
102 integer(imetis), intent(in) :: nparts
103 real(real32), intent(in) :: tpwgts
105 real(real32), intent(in) :: ubvec
107 integer(imetis), intent(in) :: options
108 integer(imetis), intent(out) :: objval
110 integer(imetis), intent(out) :: part
112 end function oct_metis_partgraphrecursive
114 integer function oct_metis_partgraphkway(nvtxs, ncon, xadj, adjncy, nparts, tpwgts, ubvec, options, objval, part)
115 use, intrinsic :: iso_fortran_env
116 import :: imetis
117 implicit none
118 integer(imetis), intent(in) :: nvtxs
119 integer(imetis), intent(in) :: ncon
120 integer(imetis), intent(in) :: xadj
121 integer(imetis), intent(in) :: adjncy
122 integer(imetis), intent(in) :: nparts
123 real(real32), intent(in) :: tpwgts
125 real(real32), intent(in) :: ubvec
127 integer(imetis), intent(in) :: options
128 integer(imetis), intent(out) :: objval
130 integer(imetis), intent(out) :: part
132 end function oct_metis_partgraphkway
134#endif
135#if defined(HAVE_PARMETIS)
137 subroutine oct_parmetis_v3_partkway(vtxdist, xadj, adjncy, ncon, nparts, tpwgts, ubvec, options, edgecut, part, comm)
138 use, intrinsic :: iso_fortran_env
139 import :: imetis
140 implicit none
141 integer(imetis), intent(in) :: vtxdist
143 integer(imetis), intent(in) :: xadj
144 integer(imetis), intent(in) :: adjncy
145 integer(imetis), intent(in) :: ncon
147 integer(imetis), intent(in) :: nparts
150 real(real32), intent(in) :: tpwgts
157 real(real32), intent(in) :: ubvec
160 integer(imetis), intent(in) :: options
163 integer(imetis), intent(out) :: edgecut
165 integer(imetis), intent(out) :: part
168 integer, intent(in) :: comm
169 end subroutine oct_parmetis_v3_partkway
170
171#endif
172 end interface
174 interface i4_to_imetis
175 module procedure i4_to_imetis_0, i4_to_imetis_1
176 end interface i4_to_imetis
177
178 interface imetis_to_i4
180 end interface imetis_to_i4
181
182 interface i8_to_imetis
183 module procedure i8_to_imetis_0, i8_to_imetis_1
184 end interface i8_to_imetis
186 interface imetis_to_i8
187 module procedure imetis_to_i8_0, imetis_to_i8_1
188 end interface imetis_to_i8
189
190contains
192 integer(imetis) pure function i4_to_imetis_0(ii)
193 integer(int32), intent(in) :: ii
194
195 i4_to_imetis_0 = int(ii, imetis)
196 end function i4_to_imetis_0
197
198 integer(int32) pure function imetis_to_i4_0(ii)
199 integer(imetis), intent(in) :: ii
200
201 imetis_to_i4_0 = int(ii, int32)
202 end function imetis_to_i4_0
203
204 pure function i4_to_imetis_1(ii)
205 integer(int32), intent(in) :: ii(:)
206 integer(imetis) :: i4_to_imetis_1(lbound(ii, 1):ubound(ii, 1))
207
208 i4_to_imetis_1 = int(ii, imetis)
209 end function i4_to_imetis_1
210
211 pure function imetis_to_i4_1(ii)
212 integer(imetis), intent(in) :: ii(:)
213 integer(int32) :: imetis_to_i4_1(lbound(ii, 1, kind=imetis):ubound(ii, 1, kind=imetis))
214
215 imetis_to_i4_1 = int(ii, int32)
216 end function imetis_to_i4_1
218 integer(imetis) pure function i8_to_imetis_0(ii)
219 integer(int64), intent(in) :: ii
220
221 i8_to_imetis_0 = int(ii, imetis)
222 end function i8_to_imetis_0
223
224 integer(int64) pure function imetis_to_i8_0(ii)
225 integer(imetis), intent(in) :: ii
226
227 imetis_to_i8_0 = int(ii, int64)
228 end function imetis_to_i8_0
229
230 pure function i8_to_imetis_1(ii)
231 integer(int64), intent(in) :: ii(:)
232 integer(imetis) :: i8_to_imetis_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
233
234 i8_to_imetis_1 = int(ii, imetis)
235 end function i8_to_imetis_1
236
237 pure function imetis_to_i8_1(ii)
238 integer(imetis), intent(in) :: ii(:)
239 integer(int64) :: imetis_to_i8_1(lbound(ii, 1, kind=imetis):ubound(ii, 1, kind=imetis))
240
241 imetis_to_i8_1 = int(ii, int64)
242 end function imetis_to_i8_1
243end module metis_oct_m
244
245!! Local Variables:
246!! mode: f90
247!! coding: utf-8
248!! End:
This module contains interfaces for METIS and PARMETIS routines.
Definition: metis.F90:97
pure integer(int64) function, dimension(lbound(ii, 1, kind=imetis):ubound(ii, 1, kind=imetis)) imetis_to_i8_1(ii)
Definition: metis.F90:225
pure integer(int32) function, dimension(lbound(ii, 1, kind=imetis):ubound(ii, 1, kind=imetis)) imetis_to_i4_1(ii)
Definition: metis.F90:199
pure integer(imetis) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i8_to_imetis_1(ii)
Definition: metis.F90:218
integer, parameter metis_error_memory
Returned due to insufficient memory.
Definition: metis.F90:142
pure integer(imetis) function, dimension(lbound(ii, 1):ubound(ii, 1)) i4_to_imetis_1(ii)
Definition: metis.F90:192
integer(int32) pure function imetis_to_i4_0(ii)
Definition: metis.F90:186
integer(int64) pure function imetis_to_i8_0(ii)
Definition: metis.F90:212
integer, parameter metis_error_input
Returned due to erroneous inputs and/or options.
Definition: metis.F90:142
integer(imetis) pure function i8_to_imetis_0(ii)
Definition: metis.F90:206
integer(imetis) pure function i4_to_imetis_0(ii)
Definition: metis.F90:180
integer, parameter metis_error
Some other errors.
Definition: metis.F90:142
integer, parameter imetis
Definition: metis.F90:153