0

I apologize in advance if this is somewhat redundant, I have reviewed the other posts that reference the use of Metis with Fortran code. Also I am very much a noobie, so please use small words and say them slow! :p

I am trying to us Metis 5.1.0 to partition a mesh in a fortran code I have written. I am wondering about the basics of compiling fortran code with calls to c libraries? How do I do that? Is that done at compile time or do I need some sort of include statement in the code? Currently when I try to compile I have the following relevant snippets:

The top of the program ( do I even need to have an include or use statement?)

PROGRAM ONEDGRIDGEN
IMPLICIT NONE
!include 'meshpart.c'
!use 'meshpart.c'

The makefile (in which I am sure there are errors)

CC = gcc
FC = gfortran
FCFLAG1 = -g -fbacktrace -ffree-line-length-0 -fdefault-real-8
FCFLAG2 =
CCFLAG  =
OBJ   = 1Dgridgen_Mod
OBJ2  = meshpart

1Dgridgen: ${OBJ}.f95
        ${FC} -o ${OBJ} ${OBJ}.f95 ${OBJ2}.c ${FCFLAG1}

The subroutine relevant to call the metis partitioning (using direct calling)

SUBROUTINE METIS_CALL(ne,nn,eptr,eind)
use iso_c_binding
IMPLICIT NONE

integer(c_int),INTENT(IN):: ne,nn
integer(c_int)::nparts,objval,ncommon 
integer(c_int),dimension(0:((nn)*2-1)),INTENT(IN)::eind
integer(c_int),dimension(nn),INTENT(IN)::eptr
integer(c_int),dimension(:),allocatable::epart,npart 
integer,pointer::vwgt=>null(), vsize=>null(), options=>null() 
real(kind=8),pointer::tpwgts=>null()       

ALLOCATE(epart(ne),npart(nn))
ncommon = 1

write(*,*) 'How many domains do you wish to have?'
read(*,*) nparts

CALL METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,ncommon,nparts,tpwgts,options,objval,epart,npart)

write(*,*) 'epart', epart
write(*,*) 'npart', npart


END SUBROUTINE METIS_CALL

When I try to compile I get the following error

gfortran -o 1Dgridgen_Mod 1Dgridgen_Mod.f95 meshpart.c -g -fbacktrace -ffree-line-length-0 -fdefault-real-8
cc1: warning: command line option "-fbacktrace" is valid for Fortran but not for C
cc1: warning: command line option "-ffree-line-length-0" is valid for Fortran but not for C
cc1: warning: command line option "-fdefault-real-8" is valid for Fortran but not for C
In file included from meshpart.c:15:
metislib.h:17:19: error: GKlib.h: No such file or directory
metislib.h:24:19: error: metis.h: No such file or directory
metislib.h:25:20: error: rename.h: No such file or directory
metislib.h:26:24: error: gklib_defs.h: No such file or directory
metislib.h:28:18: error: defs.h: No such file or directory
metislib.h:29:20: error: struct.h: No such file or directory
metislib.h:30:20: error: macros.h: No such file or directory
metislib.h:31:19: error: proto.h: No such file or directory
meshpart.c:22: error: expected ')' before '*' token
meshpart.c:90: error: expected ')' before '*' token
meshpart.c:179: error: expected ')' before 'nrows'
make: *** [1Dgridgen] Error 1

I can see that my make file is wrong, but I'm wondering why when I reference the c library I need from metis why it gives me errors for the c library, when my code and everything 'lives' in the same folder as the metis library meshpart.c. Would metis installed properly not have it's libraries and necessary components linked or referenced properly?

Thanks for any help anyone can offer!! And once again thanks for you patience I understand this is a pretty basic question.

spacegirl1923
  • 173
  • 2
  • 11

1 Answers1

0

What is meshpart.c? You should be able to call METIS directly from Fortran. METIS also has a routine that can partition a mesh directly. Here's an example:

program test
  implicit none
  integer, parameter   :: nels=2, nnds=6, npel=4
  integer              :: eptr(nels+1), nodes(nels*npel), epart(nels), npart(nnds), n
  integer, pointer     :: vwgt=>null(), vsize=>null(), mopts=>null()
  real(8), pointer     :: tpwgts=>null()
  eptr=(/0,4,8/)
  nodes=(/0,1,2,3,1,4,5,2/) ! Element 1 has nodes 0 1 2 3
                            ! Element 2 has nodes 1 4 5 2
  call METIS_PartMeshNodal(nels,nnds,eptr,nodes,vwgt,vsize,2,tpwgts,mopts,n,epart,npart) 
  print*, npart; print*, epart
end program test

And here's the output:

[stali@submit libmetis]$ gfortran test.f90 libmetis.a 
[stali@submit libmetis]$ ./a.out 
       0           0           1           0           1           1
       0           1

Hope that helps.

stali
  • 321
  • 2
  • 9
  • when I try to just simply compile as you have suggested, I get the error: mfrisbey@hord-lan% make -f 1DGridgenmake gfortran -o 1Dgridgen_Mod 1Dgridgen_Mod.f95 -g -fbacktrace -ffree-line-length-0 -fdefault-real-8 libmetis.a gfortran: libmetis.a: No such file or directory make: *** [1Dgridgen] Error 1 Should there be such a file? Is this an error in how I built/installed Metis? – spacegirl1923 Nov 15 '13 at 17:16
  • You'll have to post the whole code. You also need to link properly, e.g., gfortran foo.f90 -L/opt/metis/lib -lmetis. Btw any reason to not call METIS directly from Fortran. – stali Nov 15 '13 at 19:42
  • Thanks! Got it figured out...I was referencing what I thought was the path to the library originally but had a typo and so tried to switch to the other method posted above, which is incorrect. Correcting the path to the library fixed it for the most part – spacegirl1923 Nov 21 '13 at 21:01