本文介绍了我如何用新的2017 ifort编译Fortran代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 程序parallel_m 
包含
字符(500)函数PARALLEL_message(i_ss)
字符(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) - //&
&修剪( A)// (CPU)的 - //&安培;
& trim(a)//(ROLEs)
endif

结束函数
结束程序parallel_m

浏览预处理器:

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

产生:

#1mod.F
程序parallel_m
包含
字符(500)函数PARALLEL_message(i_ss)
字符(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)
&修剪(a)
&修剪(a)
endif

结束函数
结束程序parallel_m

,同样的
产出在2016年和2015年ifort发布时没有投诉而编制。
这是我得到的错误:

  mod.F(19):error#5082:Syntax error,在期待以下其中一项时找到'&'< LABEL> END-OF-STATEMENT>其中p ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ... 
& trim(a)
------------------------ ^
mod.F(20):error#5082:语法错误,期待以下其中一种时发现'&'< LABEL> END-OF-STATEMENT>其中p ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
& trim(a)
------------------------ ^
编译中止test.f90(代码1)


解决方案

您的程序在预处理后是非法的Fortran,因为 // 被解释为C注释。



不要使用 icc 但是 ifort Ifort 用于Fortran, icc 用于C. Ifort 使用不会丢弃 // 的不同预处理器 fpp


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 sameoutput 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)
解决方案

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

这篇关于我如何用新的2017 ifort编译Fortran代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 09:11