How do I compile this Fortran code with new 2017 i

2019-03-06 06:41发布

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条回答
Bombasti
2楼-- · 2019-03-06 06:53

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 //.

查看更多
登录 后发表回答