0

I'm very new to fortran, and frankly anything but the simplest building procedures. I'm trying to compile a large code package on a remote server, it worked on my laptop using gfortran (gfortran-mp-4.8), but it's complaining using ifort (ifort (IFORT) 13.0.0).

These are my errors:

/n/sw/centos6/openmpi-1.6.4_intel-13.0.079/bin/mpif90 -ggdb -c -O2 -fdefault-real-8 -fdefault-double-8 -Wuninitialized  -DMAXBLOCKS=1000 -DNXB=8 -DNYB=8 -DNZB=8 -DN_DIM=3 nrutil.F90
ifort: command line warning #10006: ignoring unknown option '-fdefault-real-8'
ifort: command line warning #10006: ignoring unknown option '-fdefault-double-8'
ifort: command line warning #10157: ignoring option '-W'; argument is of wrong type
nrutil.F90(713): warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL.   [DCOS]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
--------------------------------------^
nrutil.F90(713): error #6404: This name does not have a type, and must have an explicit type.   [DCOS]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
--------------------------------^
nrutil.F90(713): warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL.   [DSIN]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
----------------------------------------------------^
nrutil.F90(713): error #6404: This name does not have a type, and must have an explicit type.   [DSIN]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
----------------------------------------------^
nrutil.F90(713): warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL.   [CMPLX]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
--------------------------------^
nrutil.F90(713): warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL.   [CMPLX]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
----------------------------------------------^
nrutil.F90(713): error #6404: This name does not have a type, and must have an explicit type.   [CMPLX]
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
--------------------------^
compilation aborted for nrutil.F90 (code 1)

and (what I'm hoping is) the relevant code:

...
USE nrtype
implicit none
...

!BL
    FUNCTION zroots_unity(n,nn)
    INTEGER(I4B), INTENT(IN) :: n,nn
    COMPLEX(SPC), DIMENSION(nn) :: zroots_unity
    INTEGER(I4B) :: k
    REAL(SP) :: theta
    zroots_unity(1)=1.0
    theta=TWOPI/n
    k=1
    do
        if (k >= nn) exit
        zroots_unity(k+1)=cmplx(dcos(k*theta),dsin(k*theta),SPC)
        zroots_unity(k+2:min(2*k,nn))=zroots_unity(k+1)*&
            zroots_unity(2:min(k,nn-k))
        k=2*k
    end do
    END FUNCTION zroots_unity
!BL

and the file nrtype includes the definition of TWOPI

MODULE nrtype
    ...
    REAL(SP), PARAMETER :: TWOPI=6.283185307179586476925286766559005768394_sp
    ...
END MODULE nrtype

dcos, dsin and cmplx are built-in functions, right? So it must be complaining about the arguments... but it looks like both k and theta are given explicit types: INTEGER and REAL respectively (I don't know what (I4B) and (SP) mean)...

Any help would be much appreciated

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119

1 Answers1

4

dcos is an obsolete form of cosine where the programming explicitly instructs the compiler that the argument is double precision. The modern way (for decades!) is to just use cos and have the compiler automatically figure out which version to use. Here you have arguments for dcos, etc., which are not double precision, so the compiler is complaining. I recommend not using the "D" forms, so I suggest editing the code.

That said, if the the algorithm requires double precision to have sufficient accuracy, you might want make other changes so that the variables have the expected precision. The best way (IMO) is to appropriately declare the variables. A simple way is with the types provided with the ISO Fortran Environment: see precision of real variable.

You appear to have been making the default real double precision with a gfortran compiler option. That specific compiler option is being rejected by Intel Fortran; the ifort equivalent is "-real-size 64". That's probably the fastest way to get your code working.

"I4B" and "SP" are types provided by a Numerical Recipes module "nrtypes" that are 4-byte integer and single-precision real.

Community
  • 1
  • 1
M. S. B.
  • 28,968
  • 2
  • 46
  • 73
  • Thank you! You are a king among men. – DilithiumMatrix Jun 13 '14 at 03:37
  • Actually, I'm still a little confused. It seems like **just** using `-real-size 64` should fix the problem, but it doesn't --- I also need to use the (linked) `use ISO_FORTRAN_ENV \ real (real64)` fix. Why is that? – DilithiumMatrix Jun 13 '14 at 15:41
  • 2
    @zhermes: Because such a compiler option changes only the *default* kind to 64 bits, that is, wherever you do not explicitly specify a kind. Since your code calls `dcos` (double precision) directly with an explicitly single precision value `theta`, this option does not work. What should work once again is to make `theta` a `real(DP)`, although you then lose this precision by converting to a `SPC` complex, or just use `cos` (by far the cleanest way). – sigma Jun 17 '14 at 17:04