我有一些使用intel fortran编译器ifort编译的fortran代码.当我使用gprof进行配置文件测试时,我得到的大部分时间用于IO操作,我想找到文件的结尾,但我找不到更多关于此的文档:
index % time self children called name
<spontaneous>
[1] 20.6 0.07 0.00 _IO_wfile_seekoff [1]
-----------------------------------------------
<spontaneous>
[2] 20.6 0.07 0.00 sforcepf_ [2]
-----------------------------------------------
<spontaneous>
[3] 20.6 0.02 0.05 _IO_wfile_underflow [3]
0.01 0.04 258716/258717 strncmp [4]
-----------------------------------------------
0.00 0.00 1/258717 _IO_wdefault_doallocate [15]
0.01 0.04 258716/258717 _IO_wfile_underflow [3]
[4] 14.7 0.01 0.04 258717 strncmp [4]
0.04 0.00 3104592/3109256 strerror_r [5]
-----------------------------------------------
0.00 0.00 4664/3109256 __strcmp_sse42 [14]
0.04 0.00 3104592/3109256 strncmp [4]
[5] 11.8 0.04 0.00 3109256 strerror_r [5]
-----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
那么,问题是,这个IO是针对Linux,还是针对ifort,还是针对fortran?我正在尝试优化此代码,并且在google中找不到有关此条款的有用信息.
我正在尝试编写一个程序,无论何时使用GFortran编译,无论何时执行无效操作都会停止.有了ifort,我可以这样做:
use ieee_exceptions
....
logical :: halt
....
call ieee_get_halting_mode(IEEE_USUAL,halt)
call ieee_set_halting_mode(IEEE_USUAL,.True.)
....
! Something that may stop the program
....
call ieee_set_halting_mode(IEEE_USUAL,halt)
Run Code Online (Sandbox Code Playgroud)
GFortran有一个类似于ifort的模块ieee_exceptions吗?或者更好的是有没有办法停止停止模式而不知道程序将如何编译或将使用哪个编译器?
为什么ifort和gfortran之间有不同的行为?用ifort编译它返回false并且gfortran为true.我之前在自己的代码中遇到了这个问题并决定使用子程序,但最近的一个问题让我质疑这种行为.
function allocateArray(size)
integer, allocatable, dimension(:) :: allocateArray
integer size
allocate(allocateArray(size))
end function allocateArray
Run Code Online (Sandbox Code Playgroud)
从主程序
integer, allocatable, dimension(:) :: a
a = allocateArray(10)
print *, allocated(a)
Run Code Online (Sandbox Code Playgroud) 我正在修改一个用Fortran 77编写的模型中的代码,但我遇到了一件奇怪的事情.在某些文件中,行的第一列中有一个标签"d",如下例所示:
d real*8 co2rootfix,co2rootloss,co2shootfix
d character komma*1
d open(unit=87,file='crop_CO2.csv',status='unknown')
d write(87,*) 'date,co2rootfix,co2rootloss,co2shootfix'
d open(unit=88,file='crop_dm.csv',status='unknown')
d write(88,*) 'date,wrtpot,wrt,wstpot,wst,rdpot,rd,laipot,lai,
d &gwrt,gwst,drrt,drlv,drst'
Run Code Online (Sandbox Code Playgroud)
奇怪的是,它是由英特尔的ifort编译器成功编译的.但是,gfortran逻辑上返回以下错误:
错误:语句标签中的非数字字符(1)
我想知道:
是否可以在ifort编译器中抑制特定警告消息仍然打开其他警告?更具体地说,我想关闭以下警告消息:
警告 #7601:F2008 标准不允许内部过程是实参过程名称。(R1214.4)。
(顺便说一下,这是与 F2008 标准实现相关的一些问题ifort)。我在ifort 13.0.1 20121010Linux 机器上使用。
我是Linux下gdb的初学者.当我尝试调试使用ifort和-c,-g选项编译的程序时,我想检查几个数组的绑定.不幸的是我在谷歌找不到任何信息如何打印与gdb调试器绑定的数组.
[更新]
我有一个带可分配的公共数组的模块,它在这个模块的子程序中正确分配.在主程序中(在调用子程序之后)我尝试使用whatis并查看(*,*)而不是形状.
给出以下 Fortran 代码:
integer, parameter :: double = kind(1.0d0)
integer :: integerTest
real(double) :: doubleTest
complex(double) :: complexTest
integer :: testSize
integer :: ierr
integerTest = 0
doubleTest = real(0.d0, kind=double)
complexTest = cmplx(0.d0, 0.d0, kind=double)
call MPI_SIZEOF(integerTest, testSize, ierr)
! ...
call MPI_SIZEOF(doubleTest, testSize, ierr)
! ...
call MPI_SIZEOF(complexTest, testSize, ierr)
Run Code Online (Sandbox Code Playgroud)
使用 Intel MPI 编译时,出现错误:
error #6285: There is no matching specific subroutine for this generic subroutine call. [MPI_SIZEOF]
Run Code Online (Sandbox Code Playgroud)
在线上
call MPI_SIZEOF(complexTest, testSize, ierr)
Run Code Online (Sandbox Code Playgroud)
使用 OpenMPI 编译和执行此代码不会出现任何问题。出现这个错误的原因是什么?看起来它正在寻找 类型的特定匹配complexTest …
我尝试向此模块添加一个由@VladimirF编写的过程,该过程在 Fortran 2003 中实现通用链表。为了方便起见,我希望能够将列表的内容作为数组输出,因此我将以下过程添加到列出名为的文件中的模块lists.f90:
subroutine list_as_array(self, arrayOut)
class(list),intent(inout) :: self
class(*),dimension(1:self%length),intent(out) :: arrayOut
integer :: i
type(list_node), pointer :: nodeIter
nodeIter = self%first
do i = 1,self%length
arrayOut(i) = nodeIter%item ! <---ERROR here
if (i<self%length) then
nodeIter = nodeIter%next
end if
end do
end subroutine list_as_array
Run Code Online (Sandbox Code Playgroud)
ifort 18.0.0给出以下错误:
lists.f90(324): error #8304: In an intrinsic assignment statement, variable shall not be a non-allocatable polymorphic. [ARRAYOUT]
arrayOut(i) = nodeIter%item
------^
Run Code Online (Sandbox Code Playgroud)
我对 F2003+ 中的多态性不熟悉,所以我不理解错误消息或其上下文。出了什么问题,如何修复?
我写了这段代码:
program exponent
implicit none
real(8) :: sum
integer(8) :: i
integer :: limit
real :: start, end
sum = 0d0
limit = 10000000
call CPU_TIME(start)
do i=1, limit
sum = sum + exp(i*1.d0/limit)
end do
call CPU_TIME(end)
print *, sum
print '("Time = ",f6.3," seconds.")',end-start
end program exponent
Run Code Online (Sandbox Code Playgroud)
我在 CentOS Linux 7 上使用 gfortran 10.1.0 和 ifort 19.1.3.304 编译它:
ifort *.f90 -O3 -o intel.out
gfortran *.f90 -O3 -o gnu.out
输出是:
格努:
17182819.143730670
Time = 0.248 seconds.
Run Code Online (Sandbox Code Playgroud)
英特尔:
17182819.1437313
Time …Run Code Online (Sandbox Code Playgroud) 当将 exe 复制到另一台计算机(具有 2022 Intel 处理器)时,在一台 Windows 计算机中使用 Visual Studio 2019 在 2018 Intel 处理器上编译的 Fortran 代码是否可能会产生稍微不同的结果?您能否列出导致此行为的可能原因?
fortran ×10
intel-fortran ×10
gfortran ×4
assembly ×1
compilation ×1
fast-math ×1
fortran77 ×1
gdb ×1
gprof ×1
intel ×1
mpi ×1
performance ×1
polymorphism ×1