fortran 2008 do concurrent构造是一个do循环,它告诉编译器没有迭代会影响任何其他迭代.因此可以安全地并行化.
一个有效的例子:
program main
implicit none
integer :: i
integer, dimension(10) :: array
do concurrent( i= 1: 10)
array(i) = i
end do
end program main
Run Code Online (Sandbox Code Playgroud)
迭代可以按任何顺序完成.你可以在这里阅读更多相关信息.
据我所知,gfortran不会自动并行化这些do concurrent循环,而我记得有关gfortran扩散列表的邮件(这里).它只是将它们转换为经典do循环.
我的问题:你知道一种系统地并行化do concurrent循环的方法吗?例如,使用系统的 openmp语法?
我有一个看起来像这样的函数:
PURE FUNCTION simulate(initial_state, time_specification)
TYPE(ocean), INTENT(IN) :: initial_state
TYPE(simulation_time), INTENT(IN) :: time_specification
TYPE(ocean) :: simulate
REAL :: t = 0.0
! etc
END FUNCTION simulate
Run Code Online (Sandbox Code Playgroud)
gfortran 4.8.1告诉我
REAL :: t = 0.0
1
Error: Initialization of variable at (1) is not allowed in a PURE procedure
Run Code Online (Sandbox Code Playgroud)
据我了解,我应该能够在纯函数中使用局部变量,只要它们没有SAVE属性.那么我做错了什么?
我刚刚在这里阅读了关于在Fortran中使用模块的正确方法的非常好的问题/答案.通过在模块中编写子程序,除了澄清代码之外,还可以使它们显式化.
据我所知,模块必须放在一个文件中,例如"mod_exemple.f90".我编写的程序通常很长,许多子程序确实可以按目的排序,因此可以放在模块中.问题是:那会有很长的模块文件,有数百行.
你能把模块拆分成几个文件吗?是否建议?为什么?你有其他拆分的建议吗?