Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编写Makefile以编译.f程序和使用为Ifort编写的.f90代码为gfortan编译器编写的代码_Makefile_Fortran_Gfortran_Intel Fortran - Fatal编程技术网

编写Makefile以编译.f程序和使用为Ifort编写的.f90代码为gfortan编译器编写的代码

编写Makefile以编译.f程序和使用为Ifort编写的.f90代码为gfortan编译器编写的代码,makefile,fortran,gfortran,intel-fortran,Makefile,Fortran,Gfortran,Intel Fortran,我有一套写在gfortran中编译的.f代码和一个生成程序的Makefile 我想在这个程序中使用NewCode.f90作为附加代码,但这是一个.f90,并且是使用Ifort编写的。我编写了一个make文件,以便它编译ifort中的所有代码,因为这是NewCode.f90所需的: FC=ifort ARCH = linux include SYS.$(ARCH) MYFLGS = -O0 -pg -g -fbounds-check -Wall -fbacktrace -finit-real

我有一套写在gfortran中编译的.f代码和一个生成程序的Makefile

我想在这个程序中使用NewCode.f90作为附加代码,但这是一个.f90,并且是使用Ifort编写的。我编写了一个make文件,以便它编译ifort中的所有代码,因为这是NewCode.f90所需的:

FC=ifort

ARCH = linux

include SYS.$(ARCH)

MYFLGS = -O0 -pg -g -fbounds-check -Wall -fbacktrace -finit-real=nan
LINKFLAGS = -L$(MKLROOT)
FFLAGS = $(MYFLGS) -I$(INCDIR) -static

.SUFFIXES: .o .f .c .f90

.f.o:
    $(FC) $(FFLAGS) -c $*.f
NewCode.o NewCode.f90:
    $(FC) $(FFLAGS) -ffree-form NewCode.f90 -c
.c.o:
    $(CC) $(CFLAGS) -c $*.c

OBJ =   code1.o code2.o code3.o NewCode.o

default:    nonlinear

nonlinear:  setnl Program

setnl:
/bin/rm -f *.o *.bak core par.h
/bin/ln -sf INCLUDE/nonlinear.par par.h

clean:
/bin/rm -f *.o *.bak core par.h
/bin/rm -rf ../bin/*

cleanarch:
/bin/rm -f *.o *.bak core par.h
/bin/rm -f $(INSTDIR)/program


program:    program.f program.o $(OBJ) par.h
            $(FC) $(FFLAGS) $(LINKFLAGS) -o $@ program.o $(OBJ) $(LIBS)  -Wl,--start-group -L$(MKLROOT)/lib/intel64 -lmkl_gf_ilp64 -lmkl_core -lmkl_sequential -Wl,--end-group -lpthread
当我创建这个文件时,使用ifort编译器编译(我认为)fortran 70编写的文件时会遇到问题。例如,程序调用IPARITY函数:

FUNCTION IPARITY(l)
IMPLICIT REAL*4 (A-H, O-Z)

k = l/2
kk = 2*k - l
IF ( kk.EQ.0 ) THEN
  IPARITY = 1
ELSE
  IPARITY = -1
END IF
RETURN
END
例如,将其称为:

PRINT *,IPARITY(1)
当我使用gfortran编译这个程序时,这个函数被编译和调用没有任何问题,但是当我使用ifort编译它时,有问题。编译器似乎希望IPARITY是一个数组:

An array-valued argument is required in this context. 
我曾尝试使用gfortran编译fortran 70中编写的文件,并使用ifort编译fortran 90中的文件,但我没有完全正确地做到这一点:

COMP=ifort
ARCH=linux 
...
...
.f.o:
    $(FC) $(FFLAGS) -c $*.f
NewCode.o NewCode.f90:
    $(COMP) $(FFLAGS) -ffree-form NewCode.f90 -c
.c.o:
    $(CC) $(CFLAGS) -c $*.c
...
...
...
program: program.f program.o $(OBJ) par.h
            $(FC) $(FFLAGS) $(LINKFLAGS) -o $@ program.o $(OBJ) $(LIBS)  -Wl,--start-group -L$(MKLROOT)/lib/intel64 -lmkl_gf_ilp64 -lmkl_core -lmkl_sequential -Wl,--end-group -lpthread
但是,我将组合器设置为:

program:    program.f program.o $(OBJ) par.h
            $(FC) ...

我分别在.f90和.f代码中得到错误

我认为需要的是makefile中的标记:

  .f.o:
  $(FC) $(FFLAGS) -c $*.f
这将告诉编译器它正在读取fortran 70代码,但仍能正确编译。或组合器行中的标志,允许使用不同编译器编译的不同代码一起生成程序

欢迎您提供任何建议

多谢各位


James

您的代码仍然非常不完整,但我至少会尝试从您的代码片段中猜出绝密的其余部分是什么

您可能无法将
IPARITY
声明为
EXTERNAL
,尽管对于外部函数,您始终应该这样做。Fortran 2008中调用了不同的函数,因此编译器认为您需要这个函数。要告诉它您想要自己的外部过程,请将其声明为
external

     EXTERNAL IPARITY
     integer iparity
     ...
     print *,IPARITY(4)
或者,如果使用Fortran 90或更高版本,则使用接口块

     interface
       integer function iparity(i)
         integer i
       end function
     end interface
     ...
     print *,IPARITY(4)

对于您将来的所有程序,我强烈建议您至少使用Fortran 90,并在所有范围内使用
implicit none
。此外,通过使用模块,您可以避免这些问题,并获得许多其他优势。

什么应该“用.f90编写,并使用Ifort编写”。确切的意思是?makefiles可能与此无关,请发布源代码。当我说“编写…”我的意思是,当使用ifort编译.f90文件时,如果运行没有任何问题,那么当使用gfortran编译时,代码中的一些基本行会出现错误。我在问题中举了一个例子。类似地,当我使用gfortran编译.f文件时,它们运行没有问题,但在读取数组等简单的行上会中断。。当使用IFORT编译它们时。我最初认为“-ffree form”命令意味着可以使用gfortran编译.f90文件,但这似乎没有达到目的。发布一些更完整的代码!!!可能您只是缺少了一些外部代码。我敢打赌代码是FORTRAN77,因此标准中没有
隐式none
     interface
       integer function iparity(i)
         integer i
       end function
     end interface
     ...
     print *,IPARITY(4)