Fortran,Open MP,间接递归和有限的堆栈内存 [英] Fortran, Open MP, indirect recursion, and limited stack memory

查看:183
本文介绍了Fortran,Open MP,间接递归和有限的堆栈内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于其他文章,关于堆栈空间,OpenMP及其处理方法的回复很多.但是,我找不到真正理解OpenMP为什么调整编译器选项的信息:​​

There are many responses on other posts related to the issue of stack space, OpenMP, and how to deal with it. However, I could not find information to truly understand why OpenMP adjusts the compiler options:

gfortran中的-fopenmp暗示-frecursive的原因是什么?

What is the reasoning behind why -fopenmp in gfortran implies -frecursive?

文档说:

通过强制在堆栈上分配所有本地数组来允许间接递归

Allow indirect recursion by forcing all local arrays to be allocated on the stack

但是,我没有上下文可以理解这一点.为什么并行化需要间接递归?

However, I don't have the context to understand this. Why would parallelization require indirect recursion?

为什么并行化希望所有本地数组都在堆栈上?

Why would parallelization want all local arrays to be on the stack?

我想理解,所以我知道重写这些选项的后果,例如,使用-fmax-stack-var-size=n以避免堆栈溢出的问题.

I wish to understand so I know the consequences of overriding these options, say, with -fmax-stack-var-size=n, to avoid issues with stack overflows.

推荐答案

如果不使用-frecursive,则编译器会将超出限制-fmax-stack-var-size =的局部变量放置在静态内存中,而不是堆栈中.也就是说,它们的行为就好像它们具有SAVE属性一样,并且它们在所有线程之间共享.这些语义对于多线程程序是无意义的,因此-fopenmp意味着-frecursive.

Without -frecursive, the compiler will put local variables exceeding the limit -fmax-stack-var-size= in static memory instead of the stack. That is, they will behave as if they have the SAVE attribute, and they are shared among all the threads. These semantics are non-sensical for a multi-threaded program, hence -fopenmp implies -frecursive.

由于多线程程序的日益普及,并且由于F2018指定默认情况下过程是递归的,因此此行为将在以后的GFortran版本中更改,最有可能是在超过堆栈的大小限制时切换到堆分配变量而不是使用静态内存.但是目前,这不是一个选择.

Due to the increasing prevalence of multi-threaded programs, and because F2018 specifies that procedures are recursive by default, this behavior will change in a future release of GFortran, most likely by switching to heap allocation when exceeding the size limit for stack variables instead of using static memory. But for now, this is not an option.

这篇关于Fortran,Open MP,间接递归和有限的堆栈内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆