C 在Fortran代码中使用Metis库…基础

C 在Fortran代码中使用Metis库…基础,c,compiler-errors,fortran,metis,C,Compiler Errors,Fortran,Metis,如果这有点多余,我提前向您道歉,我已经回顾了其他引用Metis与Fortran代码结合使用的文章。另外,我也是一个不折不扣的人,所以请用小词慢慢说p 我正在尝试使用Metis 5.1.0在我编写的fortran代码中对网格进行分区。我想知道通过调用c库编译fortran代码的基础知识?我该怎么做?这是在编译时完成的还是代码中需要某种include语句?目前,当我尝试编译时,我有以下相关代码段: 程序顶部(我是否需要包含或使用语句?) makefile(我确信其中有错误) 与调用metis分区

如果这有点多余,我提前向您道歉,我已经回顾了其他引用Metis与Fortran代码结合使用的文章。另外,我也是一个不折不扣的人,所以请用小词慢慢说p

我正在尝试使用Metis 5.1.0在我编写的fortran代码中对网格进行分区。我想知道通过调用c库编译fortran代码的基础知识?我该怎么做?这是在编译时完成的还是代码中需要某种include语句?目前,当我尝试编译时,我有以下相关代码段:

程序顶部(我是否需要包含或使用语句?)


makefile(我确信其中有错误)


与调用metis分区相关的子例程(使用直接调用)


当我试图编译时,我得到了以下错误

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是否会正确安装?其库和必要的组件是否会正确链接或引用


谢谢任何人能提供的帮助!!再次感谢您的耐心,我知道这是一个非常基本的问题。

什么是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

希望这能有所帮助。

当我尝试按照您的建议进行简单编译时,会出现以下错误: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:没有这样的文件或目录make:**[1Dgridgen]错误1应该有这样的文件吗?这是我如何构建/安装Metis的错误吗?您必须发布整个代码。您还需要正确链接,例如gfortran foo.f90-L/opt/metis/lib-lmetis。顺便说一句,有什么理由不直接从Fortran打电话给METIS。谢谢!弄明白了…我最初是在引用我认为是指向库的路径,但有一个输入错误,所以试图切换到上面发布的另一个方法,这是不正确的。更正库的路径在很大程度上修复了它
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
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