How do I compile this Fortran code with new 2017 ifort?

混江龙づ霸主 提交于 2019-12-02 17:58:09

问题


I have the following fortran code that compiles with pre 2017 ifort:

program parallel_m
contains
   character(500) function PARALLEL_message(i_ss)
     character(50)    :: Short_Description = " "
     integer :: i_s =0 
     integer :: n_threads = 0 
     !
     PARALLEL_message=" "
     !
     if (i_s>0) then
       if (len_trim("test this ")==0) return
     endif
     !
     if (i_s==0) then
       PARALLEL_message=trim("10")//"(CPU)"
       if (n_threads>0) PARALLEL_message=trim(PARALLEL_message)//"-"//trim("200")//"(threads)"
     else
       PARALLEL_message=trim("a")//"(environment)-"//&
      &                 trim("a")//"(CPUs)-"//&
      &                 trim("a")//"(ROLEs)"
     endif
     !
   end function
end program parallel_m

Going through the preprocessor :

icc -ansi -E  example.F  > test.f90

Which produces:

# 1 "mod.F"
program parallel_m
contains
   character(500) function PARALLEL_message(i_ss)
     character(50)    :: Short_Description = " "
     integer :: i_s =0 
     integer :: n_threads = 0 
     !
     PARALLEL_message=" "
     !
     if (i_s>0) then
       if (len_trim("test this ")==0) return
     endif
     !
     if (i_s==0) then
       PARALLEL_message=trim("10")
       if (n_threads>0) PARALLEL_message=trim(PARALLEL_message)
     else
       PARALLEL_message=trim("a")
      &                 trim("a")
      &                 trim("a")
     endif
     !
   end function
end program parallel_m

This unfortunately with intel 2017 does not compile, the same output compiles without complaint on 2016 and 2015 ifort releases. this is the error that I get:

mod.F(19): error #5082: Syntax error, found '&' when expecting one of: <LABEL> <END-OF-STATEMENT> ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
      &                 trim("a")
------------------------^
mod.F(20): error #5082: Syntax error, found '&' when expecting one of: <LABEL> <END-OF-STATEMENT> ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
      &                 trim("a")
------------------------^
compilation aborted for test.f90 (code 1)

回答1:


Your program is illegal Fortran after the preprocessing because the // is interpretted as a C comment.

Simply do not use icc but ifort. Ifort is for Fortran, icc is for C. Ifort uses a different preprocessor fpp which does not discard //.



来源:https://stackoverflow.com/questions/40112130/how-do-i-compile-this-fortran-code-with-new-2017-ifort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!