I wrote the following code for calling Metis using Fortran and C, but still getting segmentation fault. The target of the code is to do partition for the input file chanelElements
.
module metis_vars
use iso_c_binding
! Variables
integer :: ia, ic
integer(kind=c_int) :: ne, nn
integer(kind=c_int) :: ncommon, objval
integer(kind=c_int) :: nparts
integer(kind=c_int), allocatable, dimension(:) :: eptr, eind
integer(kind=c_int), allocatable, dimension(:) :: epart, npart
type(c_ptr) :: vwgt, vsize, tpwgts
integer :: opts(0:40)
interface
subroutine METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,ncommon,nparts,tpwgts,opts, &
objval,epart,npart)bind(C, name="METIS_PartMeshDual")
!subroutine METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,nparts,tpwgts,opts,objval,epart,npart) &
! bind(C, name="METIS_PartMeshDual")
! use binding module
use iso_c_binding
! declare variables with C++ types semantics
integer(kind=c_int) :: ne, nn, ncommon, objval, nparts
integer(kind=c_int), dimension(*) :: eptr, eind
integer(kind=c_int), dimension(*) :: epart, npart
type(c_ptr), value :: vwgt, vsize, tpwgts
integer(kind=c_int) :: opts(0:40)
! printf('Hi');
end subroutine METIS_PartMeshDual
end interface
end module
and the main program is
program METIS_PART_1
use iso_c_binding
use metis_vars
implicit none
open(unit=15, file="chanelData.dat")
open(unit=1, file='channelElements.mesh')
read(1,*), ne
!ne = 2000
nn = ne * 8
allocate( eptr(ne+1), eind(8*ne) )
allocate( epart(ne), npart(nn) )
do ic=1,ne
ia = (ic-1) * 8 + 1
read(1,*), eind(ia:ia+7)
write(15,*), eind(ia:ia+7)
! print*, eind(ia:ia+7)
eptr(ic) = ia
! write(15,*),' ia: ', ia
enddo
close(15)
close(1)
nparts = 4
ncommon = 2
vwgt = c_null_ptr
vsize = c_null_ptr
tpwgts = c_null_ptr
!opts = c_null_ptr
opts = 0
opts(0) = 1
opts(7) = 1
! opts(0) = 1
! opts(7) = 1
print*, ' -----------------------'
print*, ' ne: ', ne
print*, ' nn: ', nn
call METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,ncommon,nparts,tpwgts, &
opts,objval,epart,npart)
! call METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,nparts,tpwgts,opts,objval,&
! epart,npart)
print*, ' objval: ', objval
end program METIS_PART_1
I compile using and got error:
fobeidat@envenio05:~/Metis/metis-5.1.0/graphs$ gfortran test3.f90 libmetis.a
fobeidat@envenio05:~/Metis/metis-5.1.0/graphs$ ./a.out
-----------------------
ne: 2000
nn: 16000
Segmentation fault (core dumped)