我对使用gfortran的构造非常满意,直到我用ifort尝试它.虽然我还没有看到它清楚地记录下来.我只是尝试了它并且它有效.我很好奇,但我怎么能调整以下样本,以便ifort 11.1可以咀嚼它.
module A
use iso_c_binding
implicit none
interface
function foo(x) bind(C, name="strlen")
use, intrinsic :: iso_c_binding
character(c_char), intent(in) :: x
integer(c_size_t) :: foo
end function foo
end interface
end module A
module B
use A
! use A, foo0 => foo
implicit none
interface foo
module procedure foo1
procedure foo
end interface foo
contains
function foo1(x)
real, intent(in) :: x
real :: foo1
foo1 = 2. * x
end function foo1
end module B
program C
use B
implicit …Run Code Online (Sandbox Code Playgroud) 当我编译项目时,英特尔Visual Fortran不断给我这种错误.错误可在以下代码中找到:
dimension tairgl(12),eairgl(24),windgl(12),psisgl(12),yenang(98),yunazm(98)
Run Code Online (Sandbox Code Playgroud)
这是编译器给出的错误消息.
Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( [
Run Code Online (Sandbox Code Playgroud)
有人对这个错误有任何想法吗?
我将日期时间值以这种方式声明为字符"1985-01-01-00:00",我想将年,月和日提取为整数.我不知道FORTRAN语言中的确切命令.
我有一个t_file带有终结例程的派生类型,close它只是将" 终结"写入屏幕.还有一个函数返回该类型的实例t_file.这个程序的输出是
Finalization.
Finalization.
Just opened
2000
Done.
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
Just opened输出?我的编译器是英特尔(R)Visual Fortran Composer XE 2011 12.1.3526.2010.
这是代码:
module m_file
implicit none
type t_file
integer::iu=1000
contains
final::close
end type
contains
function openFile() result(f)
implicit none
type(t_file)::f
f%iu = 2000
end function
subroutine close(this)
implicit none
type(t_file)::this
write(*,*) 'Finalization.'
end subroutine
end module
program foo
use m_file
implicit none
type(t_file)::f
f = openFile()
write(*,*) 'Just opened'
write(*,*) f%iu …Run Code Online (Sandbox Code Playgroud) 当我使用运行时检查编译程序时,出现以下错误(我不知道为什么):
ifort -check all test.f90 -o test
./test
forrtl: severe (193): Run-Time Check Failure. The variable 'my_sum$2$_2' is being used without being defined
Image PC Routine Line Source
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000403098 Unknown Unknown Unknown
.
.
.
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000402EAF Unknown Unknown Unknown
sum 0000000000402DE6 Unknown Unknown Unknown
libc.so.6 00007F7FEB268BE5 Unknown Unknown Unknown
sum 0000000000402CD9 Unknown Unknown Unknown
Run Code Online (Sandbox Code Playgroud)
代码是:
program test
implicit …Run Code Online (Sandbox Code Playgroud) 我能够将目标文件".o"编译并输出到我的"obj"文件夹中.但是,我无法将".mod"变成我的"mod"文件夹.以下是我当前的命令:
ifort -c foo.f90 -o../obj/foo.o
Run Code Online (Sandbox Code Playgroud) 在 Fortran 中,可以为指针分配内存,或者不能:
real(kind=jp), target :: bt(100,100)
real(kind=jp), pointer :: pt(:,:)
Run Code Online (Sandbox Code Playgroud)
但是你可以为指针分配内存pt:
allocate(pt(100,100))
Run Code Online (Sandbox Code Playgroud)
我的问题是:利弊是什么?就我所见,为指针分配内存违背了指针的目的并占用了更多内存。当然,我对指针的了解是有限的,所以如果有人能向我解释这里发生了什么,我将不胜感激。
我正在使用混合 FORTRAN 77 和 Fortran 90 代码的模型,此外,我正在使用英特尔编译器编译代码。
这是一些示例代码:
! Author: Svetlana Tkachenko svetlana@members.fsf.org
! License: GPLv3 or later
subroutine myprint(var)
! integer :: var
! print *, 'Hi, my ', var
end subroutine
module testing
type triangle
integer :: point(3)
end type
end module
program main
use testing
type(triangle) :: mytriangle
mytriangle%point(1)=5
call myprint(mytriangle%point(1))
end program
Run Code Online (Sandbox Code Playgroud)
它工作正常ifort -c file.f90,但ifort -warn all -c file.f90导致错误:
blah.f90(4): warning #6717: This name has not been given an explicit type. [VAR]
subroutine myprint(var)
-------------------^
blah.f90(4): remark #7712: This …Run Code Online (Sandbox Code Playgroud) 我有一些 Fortran 代码,我想与 MPI 并行。显然,在 Fortran 中使用 MPI(在我的情况下为 MPICH)的推荐方法是通过mpi_f08模块(关于这个问题的 mpi-forum 条目),但我无法使它工作,因为根本没有创建相应的 mod 文件(与mpi.mod,它的工作原理不同)很好,但它不是最新的 Fortran 标准)。这个讨论给我留下的印象是 gfortran 无法构建 F08 绑定。您可以在下面看到我的配置,gfortran 和 mpich 都已通过 apt install 在 ubuntu 上安装,并且应该是最新的。我不确定一些事情:
使用过时版本的 gfortran 似乎是个问题。这将我的问题简化为如何使用 gfortran-10 构建 MPICH。
为了清楚起见,有我的 gfortran 和 mpich 配置
pavel@pavel:~$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v …Run Code Online (Sandbox Code Playgroud) 我有一个FORTRAN代码,我需要在服务器上运行.我注意到两台机器的结果有点不同.调查一下,我了解到差异从一个返回real值的函数变为一个double precision变量.在locale机器上我使用旧编译器(gnu f95 4.1.2),在远程机器上我使用ifort.
有人能告诉我如何将 OpenMP 堆栈大小设置为无限制吗?
像这个链接:为什么在这个 openmp 代码中发生分段错误?
我也有一个Fortran写的项目(客户的复杂代码),如果我设置了OMP_STACKSIZE,项目运行正常。如果我取消设置,项目就会失败。
但是,不同的输入数据有不同的OMP_STACKSIZE,所以我必须为每个输入数据尝试它,(因为我必须节省内存)。
我可以像 pthread ( ulimit -s unlimited)一样设置 OpenMP 堆栈吗?或者有什么方法可以动态设置 omp 堆栈大小?
我使用的是 RHEL 6.1 和英特尔编译器。
非常感谢!
过去两天我在一个大型 Fortran 项目中调试了一个看似无意义的段错误。当我将代码移到自己的计算机上时,问题就开始了,段错误出现在代码的一部分中,而该部分代码多年来在其他几个系统上都运行良好。我最终找到了段错误的根源,但它是如此令人惊讶的意外(并且依赖于编译器),所以我决定将其发布在这里。
考虑以下 MWE:
program dafuq
implicit none
integer :: a=1
integer, parameter :: b=2
call foo(a,b)
end program dafuq
subroutine foo(a,b)
implicit none
integer, intent(inout) :: a, b
a=b !OK
b=a !causes segfault
end subroutine foo
Run Code Online (Sandbox Code Playgroud)
我可以访问两个 HPC 集群,它们与我的笔记本电脑一起允许我检查这些(有时有点旧)编译器:
事实证明,所有四个编译器都会对上述代码产生段错误,因为变量b被声明为parameter. 因此,在子例程中更改其值是违规的。intent我的问题是,只有最新的 gfortran 在编译期间显示警告(即使使用 -Wall),如果我省略子例程中的规范,该警告也会消失。我怀疑在 C++ 中使用const变量的相同设置会引发一个巨大的危险信号。
现在,为了使其更加晦涩,请考虑以下代码,其中使用数组而不是标量:
program dafuq_array
implicit none
integer :: a(2)=(/1,1/)
integer, parameter :: b(2)=(/2,2/)
call foo(a,b)
end …Run Code Online (Sandbox Code Playgroud) 我的矩阵计算是:C=CA*B
这里 C 是一个对称矩阵,所以我想通过只考虑上三角形然后取相反的 elelement 来加速这个计算。我使用了 OMP,发现我的实现比整个矩阵 C 的正常计算慢。
我还看到 C=C-AxB 的计算比 C=C+AxB 慢。
附上我的程序。请建议我!
Program testspeed
implicit none
integer nstate,nmeas,i,j,l
integer(kind=8) :: tclock1, tclock2, clock_rate
real(kind=8) :: elapsed_time
double precision, allocatable, dimension(:,:):: B,C,A
nstate =20000
nmeas=10000
allocate (B(nmeas,nstate),C(nstate,nstate),A(nstate,nmeas))
A=1d0
B=1d0
call system_clock(tclock1)
write(*,*) "1"
!$omp parallel do
do j = 1, nstate
do l = 1,nmeas
do i = 1, j
C(j,i) = C(j,i) - A(j,l)*B(l,i)
C(i,j)=C(j,i)
end do
end do
end do
!$omp end parallel do
write(*,*) "2" …Run Code Online (Sandbox Code Playgroud) fortran transpose openmp matrix-multiplication intel-fortran
fortran ×13
intel-fortran ×13
gfortran ×2
openmp ×2
casting ×1
compilation ×1
fortran77 ×1
fortran90 ×1
mpi ×1
recursion ×1
runtime ×1
stack-size ×1
transpose ×1