如果这有点多余,我提前道歉,我已经回顾了其他帖子,这些帖子引用了Metis与Fortran代码的使用。我也非常喜欢,所以请用小词说慢一点! :P
我正在尝试使用Metis 5.1.0在我编写的fortran代码中对网格进行分区。我想知道通过调用c库来编译fortran代码的基础知识?我怎么做?这是在编译时完成还是在代码中需要某种include语句?目前,当我尝试编译时,我有以下相关的片段:
程序的顶部(我是否需要包含或使用声明?)
PROGRAM ONEDGRIDGEN
IMPLICIT NONE
!include 'meshpart.c'
!use 'meshpart.c'
makefile(我确信有错误)
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}
与调用metis分区相关的子例程(使用直接调用)
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
当我尝试编译时,我收到以下错误
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
我可以看到我的make文件是错误的,但是我想知道为什么当我从metis引用我需要的c库时为什么它给了我c库的错误,当我的代码和一切'生活'在同一个文件夹作为metis库meshpart.c。是否正确安装了metis而没有正确链接或引用它的库和必要组件?
感谢任何人提供的任何帮助!!再次感谢您的耐心,我理解这是一个非常基本的问题。
答案 0 :(得分:0)
什么是meshpart.c?您应该可以直接从Fortran致电METIS。 METIS还有一个可以直接划分网格的例程。这是一个例子:
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
这是输出:
[stali@submit libmetis]$ gfortran test.f90 libmetis.a
[stali@submit libmetis]$ ./a.out
0 0 1 0 1 1
0 1
希望有所帮助。