标签: intel-fortran

如何使循环计数器不大于最终值?

样本循环:

do i=1,1
    print *,i
enddo
print *,i
Run Code Online (Sandbox Code Playgroud)

给了我2最终的价值i.我如何设置英特尔Fortran的Visual Studio在Windows上给我的最终价值1i

fortran intel-fortran

3
推荐指数
1
解决办法
1890
查看次数

在Fortran 90中的NaN问题

我意识到,如果你写

    Real (Kind(0.d0))::x,y
    x = sqrt(-1.d0)
    y = sqrt(-1.d0)
    if (x == y) then
       write(*,*)'yep, they are equals', x
    endif
Run Code Online (Sandbox Code Playgroud)

它使用ifort编译好.但没有写任何内容,条件总是错误的,你注意到了吗?为什么会这样?

fortran90 intel-fortran

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

在Fortran-90中将参数作为参数传递?

假设我有一个子程序:

subroutine foo(x, Nx)
    implicit none
    integer, intent(IN) :: x
    integer, intent(IN) :: Nx

    select case(x)
        case (1)
            write(*,*) "Minimum value"
        case (Nx)
            write(*,*) "Maximum value"
        case default
            write(*,*) "Somewhere in-between"
    end select
end subroutine foo
Run Code Online (Sandbox Code Playgroud)

假设我的驱动程序看起来像这样:

program main
    implicit none

    interface
        subroutine foo(x,Nx)
            integer, intent(IN)  :: x
            integer, intent(IN)  :: Nx
        end subroutine foo
    end interface

    integer, parameter :: Nx = 100
    integer :: x

    call foo(20, Nx)

end program main
Run Code Online (Sandbox Code Playgroud)

以上程序不会编译,因为在子程序中,case (Nx)无效.具体来说,ifort 16给出以下错误:

错误#6601:在CASE语句中,case-value必须是常量表达式.

换句话说,即使Nx被有效地 …

parameters fortran fortran90 select-case intel-fortran

3
推荐指数
1
解决办法
764
查看次数

逻辑运算顺序(潜在的ifort错误)

在英特尔论坛上将此报告为编译器错误之前,我想知道以下是否符合标准.我的问题是:逻辑运算的顺序是否总是在Fortran中修复?

! main.f90
  interface
     subroutine f(x)
       logical, intent(in), optional :: x
     end subroutine f
  end interface
  call f(.false.)
  call f(.true.)
  call f()
end program

! f.f90
subroutine f(x)
  logical, intent(in), optional :: x
  print*, present(x) .and. x
end subroutine f
Run Code Online (Sandbox Code Playgroud)

gfortran main.f90 f.f90 && ./a.out 版画

F
T
F
Run Code Online (Sandbox Code Playgroud)

ifort main.f90 f.f90 && ./a.out 版画

 F
 T
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              0000000000476D75  Unknown               Unknown  Unknown
a.out              0000000000474997  Unknown               Unknown  Unknown
a.out …
Run Code Online (Sandbox Code Playgroud)

fortran intel-fortran

3
推荐指数
1
解决办法
140
查看次数

在Sublime Text 3上运行英特尔Fortran

Sublime Text 3有一个包将文本编辑器链接到Gfortran,它运行没有任何问题.我想知道如何将英特尔Fortran添加为Sublime Text 3的自定义版本?根据我的理解,我需要继续构建系统并使用类似于下面的代码创建一个新文件(这是gfortran的一个例子).

{
    "cmd": "gfortran ${file} -o ${file_base_name}",
    "selector": "source.modern-fortran, source.fixedform-fortran",
}
Run Code Online (Sandbox Code Playgroud)

我怎么能为英特尔Fortran做这个?

额外:

之前曾问过Linux(我使用的是Windows):Sublime Text 2 Build(Ctrl + B)英特尔Fortran编译器.修复应该是:

"cmd": ["ifort","$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.fortran90"
Run Code Online (Sandbox Code Playgroud)

但它在我的电脑上不起作用.我收到以下消息:

[WinError 2] The system cannot find the file specified
[cmd: ['ifort', 'C:\\Users\\username\\Desktop\\fortranfile.f90']]
[dir: C:\Users\username\Desktop]
[path: C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.4.210\windows\mpi\intel64\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\compiler;C:\MinGW\bin;C:\cygwin64\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\windows\system32;C:\MinGW\bin]
[Finished]
Run Code Online (Sandbox Code Playgroud)

fortran sublimetext sublimetext3 intel-fortran

3
推荐指数
1
解决办法
605
查看次数

正确设置随机种子的重复性

使用Fortran 90子程序设置随机种子的方法random_seed非常简单.

call random_seed( put=seed )
Run Code Online (Sandbox Code Playgroud)

但我找不到任何关于设置种子的指导方针的信息(当你想要重复性时这是绝对必要的).我过去听过的民间传说认为标量种子应该很大.例如,123456789是一个比123更好的种子.我可以在网上找到的唯一支持就是ifort扩展函数建议ran()使用"大,奇整数值"

我理解这可能是特定于实现的,并且正在使用gfortran 4.8.5,但我也对ifort和(如果可能的话)一般指导方针感兴趣,这些指南独立于实现.这是一些示例代码:

# for compactness, assume seed size of 4, but it will depend on 
# the implementation (e.g. for my version of gfortran 4.8.5 it is 12)

seed1(1:4) = [ 123456789, 987654321, 456789123, 7891234567 ]
seed2(1:4) =   123456789
seed3(1:4) = [         1,         2,         3,          4 ]
Run Code Online (Sandbox Code Playgroud)

我猜这seed1很好,但如果你手动设置它(因为我),因为种子长度可以是12或33或其他什么,这很简单.而且我甚至不确定它没关系,因为我无法找到关于设置这些种子的任何指导方针.也就是说,这些种子应该对我所知道的全部是负数,或者是3位偶数等等,虽然我猜你希望实施会警告你(?).

seed2并且seed3显然更方便设置,而且我所知道的一切都很好.@Ross建议seed2他的回答实际上很好: 随机数生成器(RNG/PRNG)返回种子的更新值

所以我的总结问题是:我怎样才能正确设定种子?是否seed1可以seed3接受任何或全部?

fortran gfortran fortran90 intel-fortran

3
推荐指数
1
解决办法
466
查看次数

从c ++访问fortran模块的变量

目前我正在开发一个需要将fortran代码集成到c ++的项目.在fortran模块中,声明了许多变量和数组.当相应的fortran声明为real*8 rmax并且模块的名称为common_area时,我可以通过将ac变量声明为extern double common_area_mp_rmax_来从c访问integer,float和double类型.但是,当我尝试对数组执行相同操作时,我收到错误.

假设fortran模块中的代码是:real*8,allocationable,dimension(:,:,:) :: x

我把ac双指针作为:

extern "C" { double* common_area_mp_x_; }

现在当我编译整个项目时,它说"`variable_area_mp_x_'的多重定义".我正在使用CMake编译整个项目.有人可以解释我做错了吗?我是fortran的新手,我很难解决这个问题.感谢您的时间和帮助.

谢谢,思想家

c++ fortran fortran-iso-c-binding intel-fortran

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

英特尔 Fortran 形式的标准等效形式 = 'binary'

我对为使用英特尔 Fortran 编译器进行编译而编写的 Fortran 代码有疑问。

我遇到的具体问题是声明OPEN。我尝试重写源代码,以便可以使用免费编译器(即 GNU Fortran)编译它,并且我成功了,但我遇到了一些问题。

有一些带有 的临时文件输出OPEN(access = 'direct', form = 'binary', status = 'replace'...),但form = 'binary'不是标准的,GNU Fortran 编译器不支持。

在网上寻找解决方案后,我发现form = 'unformatted'应该是等效的并且 GNU Fortran 可以处理它。是的,确实如此,我能够编译并且代码运行正确。然而,该代码是科学计算,在以这种方式打开的这些文件中生成大量数据。我的问题是,form = 'unformatted'结果文件比form = 'binary'.

这样,在某些情况下,我没有足够的硬盘空间来成功运行未格式化的格式,而使用二进制文件则可以。是否有英特尔 Fortran 的“二进制文件”的等效项可以与 GNU Fortran 一起使用并产生类似的文件大小?

根据要求,我添加了一个简短的、简化的示例代码:

subroutine init
use module params  ! contains param1, param2, param3, ... which are inetger or real
common /params2/ maxi, maxj, maxk, limit, recnum ! integers defined elsewhere
real*8, allocatable …
Run Code Online (Sandbox Code Playgroud)

file-io fortran binaryfiles gfortran intel-fortran

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

在 Ubuntu 20 上安装 ifort

我正在尝试在 Ubuntu20 上安装 ifort 编译器。我从以下网站下载了安装文件:intel

在此输入图像描述

这是一个扩展名为 .sh 的文件,我将其设为可执行文件:

  Downloads$ chmod +x l_fortran-compiler_p_2021.1.2.62_offline.sh
  Downloads$ ./l_fortran-compiler_p_2021.1.2.62_offline.sh
Run Code Online (Sandbox Code Playgroud)

这打开了软件安装程序:

在此输入图像描述 在此输入图像描述

但是,我无法使用 ifort 编译器。例子:

  ifort -o name name.for
Run Code Online (Sandbox Code Playgroud)

它给出以下消息:

  Command 'ifort' not found, did you mean:

    command 'fort' from deb fort-validator (1.2.0-1)
    command 'isort' from deb isort (4.3.4+ds1-2)

  Try: sudo apt install <deb name>
Run Code Online (Sandbox Code Playgroud)

我需要安装 intel ifort 编译器,因为如果使用 -fast 选项编译,可执行文件会更快。

fortran intel-fortran

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

空数组的边界检查——各种编译器的行为

更新20210914:Absoft 支持确认下面描述的af95/行为是无意的,并且确实是一个错误。af90Absoft 开发人员将努力解决这个问题。其他编译器在这方面的行为是正确的。感谢@Vladimir F 的回答、评论和建议。


我的印象是 Fortran 对于大小为 0 的数组很酷。但是,在 Absoft Pro 21.0 中,我遇到了涉及此类数组的(奇怪的)错误。相比之下,gfortranifortnagforpgfortransunf95g95都对同一段代码感到满意。

下面是一个最小的工作示例。

! testempty.f90

!!!!!! A module that offends AF90/AF95 !!!!!!!!!!!!!!!!!!!!!!!!
module empty_mod

implicit none
private
public :: foo

contains

subroutine foo(n)
implicit none
integer, intent(in) :: n
integer :: a(0)
integer :: b(n - 1)
call bar(a)  ! AF90/AF95 is happy with this line.
call bar(b)  ! AF90/AF95 is …
Run Code Online (Sandbox Code Playgroud)

fortran gfortran intel-fortran pgi-visual-fortran nag-fortran

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