标签: intel-fortran

如何在Fortran 90中使用include语句?

我有一些.h文件用于FORTRAN 77中的某些模块(我自己没有写过).我想在Fortran 90中编写一个新例程并使用这些.h文件.我尝试使用include 'foo.h',当我尝试编译时(使用ifort版本13.0.0.079 Build 20120731)我收到以下错误:

Syntax error, found IDENTIFIER 'FOO' when expecting one of: ( % [ : . = => C FOO COMMOM

我也试过使用include foo.h,是什么给了我以下错误: error #5082: Syntax error, found IDENTIFIER 'FOO' when expecting one of: <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> INCLUDE FOO.h ----------^

error #6274: This statement must not appear in the specification part of a module INCLUDE foo.h --^

error #6236: A specification statement cannot appear in the executable section. !$ use omp_lib ---^ …

fortran fortran77 fortran90 intel-fortran

2
推荐指数
1
解决办法
8700
查看次数

如何逐行写一个巨大的矩阵(fortran 90)

我想逐行将一个包含大量数据的矩阵写入文件.例如,我有一个矩阵100*100,我想在文件中以100*100的形式.但是,它不起作用.以下是我的代码和一些描述.N和M是几百个左右的整数.RECL是预期的长度我设置文件,但在这里似乎这个命令不起作用.当N设置为99且M设置为200时,输出为198行.Vec是双精度复数矩阵.我怎么能输出Vec的值保持其原始格式N*M?我的编译命令是"ifort -o out test.f90".

open(unit=2, file='graph1.txt', ACTION="write", STATUS="replace",RECL=40*M+10)
do i=1,N
 do j=1,M
  write(2, '(F)', advance='no') real(Vec(i,j)) 
 end do
  write(2, *) '' 
end do
Run Code Online (Sandbox Code Playgroud)

按照@george的建议,我编写了一个这样的程序:

program test
implicit none

integer i,j

open(unit=2, file='graph1.txt', ACTION="write", STATUS="replace")
do i=1,500
 write(2, '(1600F14.7)')( 0.00001 ,j=1,499)
end do

close(2)

end
Run Code Online (Sandbox Code Playgroud)

有了这段代码,问题就解决了!也许我上次没有正确编译.

fortran matrix intel-fortran

2
推荐指数
1
解决办法
2万
查看次数

fortran中的多重定义链接错误(ifort - gfortran)

好吧,我有这个问题(描述很长,但我觉得很容易解决).我有三个档案:

nrtype.f90,它有一些愚蠢的定义,但它被以下文件使用:

module nrtype
    integer, parameter :: I4B = SELECTED_INT_KIND(9)
    integer, parameter :: I2B = SELECTED_INT_KIND(4)
    integer, parameter :: I1B = SELECTED_INT_KIND(2)
    integer, parameter :: SP = KIND(1.0)
    integer, parameter :: DP = KIND(1.0D0)
endmodule nrtype
Run Code Online (Sandbox Code Playgroud)

LUd.f90,这是部分工作:

module descomposicionLU
    use nrtype

    implicit none

contains

subroutine LUd(A, LU, bk)
    implicit none

    real(DP), intent (in), dimension(:,:)                 :: A
    real(DP), intent (out), dimension(:,:)                :: LU
    integer(I2B), dimension(size(A,1),2)                  :: bk

        <more code that doesn't worth to mention>

endsubroutine LUd

<more code that …
Run Code Online (Sandbox Code Playgroud)

linker fortran gfortran intel-fortran

2
推荐指数
1
解决办法
2796
查看次数

使用BIND(C,NAME ="name")属性时,为什么不导出我的fortran函数

我习惯使用以下语法

    subroutine CalcA(A,N)
    !DEC$ ATTRIBUTES DLLEXPORT :: CALCA
    !DEC$ ATTRIBUTES ALIAS:'CalcA' :: CalcA
    IMPLICIT NONE        
    ...
    end subroutine CalcA
Run Code Online (Sandbox Code Playgroud)

它在.dll中生成导出的函数 DependencyWalker

所以现在我ISO_C_BINDING用以下代码尝试新的

    subroutine CalcA(A,N) BIND(C, NAME="CalcA")
    USE, INTRINSIC :: ISO_C_BINDING
    IMPLICIT NONE        
    ...        
    end subroutine CalcA
Run Code Online (Sandbox Code Playgroud)

但是没有创建导出功能

DependencyWalker

那我在这里错过了什么?新的如何iso_c_binding取代已弃用的!DEC$ ATTRIBUTE DLLEXPORT声明?

PS.我通过VS2010在Win7-64平台上使用英特尔Fortran XE 2013.

interop fortran fortran-iso-c-binding intel-fortran

2
推荐指数
1
解决办法
1343
查看次数

在Fortran中,如何从数组中删除第N个元素?

例如我有数组(/ 1,3,4,5,7,9,11 /),如何删除它的第3个元素?我找不到这确实是一个阵列的功能,也没有我发现一个循环的优雅的解决方案,因为我不知道如何追加到一个数组(这意味着,新增一个元素前面定义的元素旁边.)

我想从数组中删除所有偶数元素......我知道只有一个元素.

我可以使用MINLOC找到它的索引,但我不知道如何从数组中删除一个元素.

arrays fortran matrix intel-fortran

2
推荐指数
1
解决办法
5750
查看次数

ifort行长度限制

所以似乎有一些关于gfortran的线宽限制的问题,但不是关于ifort的一个问题.编译时我遇到以下问题:

../../../src/70_gw/gwls_lineqsolver.F90(298): error #5082: Syntax error, found IDENTIFIER 'ENDIF' when expecting one of: ( * ) :: , <END-OF-STATEMENT> ; + . - (/ [ : ] /) ' ** / // > ...
&"        endif
----------^
../../../src/70_gw/gwls_lineqsolver.F90(298): error #6404: This name does not have a type, and must have an explicit type.   [ENDIF]
&"        endif
----------^
../../../src/70_gw/gwls_lineqsolver.F90(297): warning #6043: This Hollerith or character constant is too long and cannot be used in the current numeric context.   ['=# of valence …
Run Code Online (Sandbox Code Playgroud)

fortran intel-fortran

2
推荐指数
1
解决办法
2869
查看次数

在英特尔Fortran中编译单个与多个源文件

我一直在使用不同文件中的模块和子程序编译项目.每个子程序都写在单独的文件中.模块也一样.然后,我测试了将这些文件单独编译为目标文件(-c),然后与优化标志链接,并使用cat合并整个源代码并将相同的过程应用于此单个源文件.我发现,编译单个文件生成的可执行文件比多个文件生成的可执行文件快40%,尽管两者使用完全相同的标记.我想知道是否有人知道它为什么会发生,并且如果英特尔Fortran编译器上有任何标志编译多个文件,因为它们是单个文件.

performance fortran intel-fortran

2
推荐指数
1
解决办法
486
查看次数

为什么将"complex*16"更改为"complex(16)"会导致fortran中的运行时间不合理地增加?

这个fortran代码最初是用Fortran 77格式编写的(我将在稍后展示).在我得到它之后,我通过转换工具将其更改为f90自由格式.使用intel fortran编译器 ifort,编译和运行与以前一样好.

然后我想做得更多,我想改造非标准的,过时的数据类型声明F77的风格,如:real*8,complex*16等到F90的标准real(8),complex(16).

但我发现了一件令人难以置信的事情.我只是将一个"复杂*16"改为"复杂(16)",然后运行时间从10秒增加到2分钟.怎么会这样!!??有人可以在fortran中解释这种异常行为吗?


以下是详细信息

源文件可以下载 源代码下载链接1源代码下载链接2

首先,您可以使用ifort编译f90文件,忽略所有警告

ifort -w test-16.f90
Run Code Online (Sandbox Code Playgroud)

并运行

./a.out
Run Code Online (Sandbox Code Playgroud)

它将在大约10秒内完成(取决于您的计算机).

现在,我们做了一个小改动.转到第734行,此行显示

  Complex *16 ch, clamda, czero, cspw, com, phase, ctemp
Run Code Online (Sandbox Code Playgroud)

它是f77过时的风格,所以改成f90标准

  Complex(16) ch, clamda, czero, cspw, com, phase, ctemp
Run Code Online (Sandbox Code Playgroud)

并以相同的方式编译,ifort将显示错误

/tmp/ifortvaXMFi.o: In function `fite4_':
test-(16).f90:(.text+0x9ecf): undefined reference to `dimag_'
test-(16).f90:(.text+0xa354): undefined reference to `dimag_'
Run Code Online (Sandbox Code Playgroud)

我不知道为什么,但我发现第744行有一个非常可疑的句子

  aimag(ctemp) = dimag(ctemp)
Run Code Online (Sandbox Code Playgroud)

我真的不明白什么意思.但整个代码只有三个"ctemp"出现的地方.显然,这条线是多余的.所以我们可以安全地删除它.

因此在删除第744行后,编译就可以了.但是我之前说的运行时间增加到超过2分钟.这真是难以置信,这里有什么不对?

fortran declaration fortran77 intel-fortran

2
推荐指数
1
解决办法
1016
查看次数

调用带有可选参数的子例程时缺少实际参数

我的 IDE 是带有集成 Intel Fortran 编译器的 Visual Studio 2010。编译器版本为:Intel Parallel Studio XE 2011。

我在 Fortran 中没有经验的程序员,所以我需要一些关于在派生类型的公共过程中使用可选参数的帮助。这是我的示例代码:

MODULE DERIVED_TYPE

 TYPE , PUBLIC :: SOME_TYPE

  INTEGER , PRIVATE :: V_INT

   CONTAINS

      PROCEDURE , PUBLIC :: CALL_V_INT => CALL_DATA_V_INT
      PROCEDURE , PUBLIC :: TAKE_V_INT => TAKE_DATA_V_INT

 END TYPE SOME_TYPE

 PRIVATE :: CALL_DATA_V_INT
 PRIVATE :: TAKE_DATA_V_INT

CONTAINS

! PUBLIC PROCEDURES

  SUBROUTINE CALL_DATA_V_INT( THIS , IA , IB , IC )

    CLASS( SOME_TYPE ) :: THIS
    INTEGER , INTENT( IN ) :: IA , IC …
Run Code Online (Sandbox Code Playgroud)

fortran intel-fortran

2
推荐指数
1
解决办法
2344
查看次数

Stack problems when copying from array to another in Fortran?

If I am doing the following copy in Fortran

 arr(i1:i2) = u(1:n) 
Run Code Online (Sandbox Code Playgroud)

where SIZE(arr(i1:i2)) == SIZE(u(1:n)) and the size is relative big, e.g 2M elements of double precision.

If variable arr is a pointer alias to another allocatable array. Would Fortran use the stack or heap memory to handle the copy assignment.?

If it is using the stack, is there any specific reason for that choice.?

How could one possibly avoid the compiler using the stack to not get a …

fortran segmentation-fault intel-fortran

2
推荐指数
1
解决办法
154
查看次数