如果这有点多余,我很抱歉,我已经回顾了引用Metis与Fortran代码一起使用的其他文章。我也是一个noobie,所以请用一些小词,然后说慢! :p在Fortran代码中使用Metis库...基本知识
我想让我们知道梅蒂斯5.1.0在我写的fortran代码中划分网格。我想知道用c库调用编译fortran代码的基础知识吗?我怎么做?这是在编译时完成的,还是在代码中需要某种包含语句?目前,当我尝试编译,我有以下相关的片段:
程序的顶部(我甚至需要一个包括或使用的语句?)
PROGRAM ONEDGRIDGEN
IMPLICIT NONE
!include 'meshpart.c'
!use 'meshpart.c'
生成文件(以我敢肯定有错误)
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}
相关致电梅蒂斯划分子程序(使用DIR ECT调用)
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库meshpart.c一起存放在同一个文件夹中时,我引用了我从metis需要的c库,为什么它会给c库带来错误。 metis是否安装正确,没有它的库和必要的组件链接或引用正确?
感谢任何人可以提供帮助!再次感谢您的耐心,我明白这是一个非常基本的问题。
当我尝试只是简单编译如你所说,我得到的错误:mfrisbey @霍德兰%使-f 1DGridgenmake gfortran -o 1Dgridgen_Mod 1Dgridgen_Mod.f95 -g -fbacktrace -ffree线长度0 -fdefault-real-8 libmetis.a gfortran:libmetis.a:没有这样的文件或目录 make:*** [1Dgridgen]错误1 应该有这样的文件吗?这是我建立/安装Metis的错误吗? – spacegirl1923
另请注意,meshpart.c是METIS_PartMeshDual/Nodal例程的所在地。 – spacegirl1923
您必须发布完整的代码。您还需要正确链接,例如,gfortran foo.f90 -L/opt/metis/lib -lmetis。顺便说一句,不要直接从Fortran中调用METIS。 – stali