如何将openmp线程堆栈设置为无限制? [英] How to set openmp thread stack to unlimited?

查看:1925
本文介绍了如何将openmp线程堆栈设置为无限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何将OpenMP堆栈大小设置为无限制吗?

喜欢这个链接:



我还有一个由Fortran编写的项目(客户的复杂代码),如果我设置 OMP_STACKSIZE ,项目运行正常。如果我解除它,该项目将失败。

但是,不同的输入数据有不同的 OMP_STACKSIZE ,所以我必须为每个输入数据尝试它(因为我必须节省内存)。



我可以像pthread( ulimit -s unlimited )一样设置OpenMP堆栈吗?或者有一些方法来动态设置omp堆栈大小?

我正在使用RHEL 6.1和英特尔编译器。



非常感谢!

解决方案

$主线程和工作线程的堆栈之间有很大的区别。 b
$ b主线程的无限制堆栈从用户模式下可用的最高虚拟地址开始,向下增长,直到遇到程序中断(数据段的结尾)或者遇到另一个内存分配(命名或匿名映射),此时程序崩溃。



任何附加堆栈必须放在程序中断和main叠加。由于它们的初始位置(即它们开始之间的距离)决定了它们的最大尺寸(反之亦然 - 指定的最大尺寸决定它们的初始位置),它们不能具有任意的可延伸长度。这就是 pthread_create(3)的Linux实现的原因(几乎所有OpenMP运行时都用于创建新线程):
$ b


在Linux / x86-32上,默认堆栈大小为一个新的线程是2兆字节。在NPTL线程实现下,如果在程序启动时 RLIMIT_STACK 软资源限制具有除unlimited以外的任何值,那么它会确定新线程的默认堆栈大小。使用 pthread_attr_setstacksize(3),可以在用于创建线程的 attr 参数中明确设置堆栈大小属性,以便获得堆栈大小不是默认的。


换句话说,答案是否定的 - 您不能为除主一个。

Can someone tell me how to set OpenMP stack size to unlimited?
Like this link: Why Segmentation fault is happening in this openmp code?

I also have a project written by Fortran (customer‘s complex code), if I set OMP_STACKSIZE, the project is running normally. If I unset it, the project fails.

But, different input data have different OMP_STACKSIZE, so I must try it for each inputdata, (because I must save memory).

Can I set the OpenMP stack like pthread (ulimit -s unlimited)? Or have some way to set omp stack size dynamically?

I'm using RHEL 6.1, and the Intel compiler.

Thanks a lot!

解决方案

There is big difference between how the stacks of the main thread and of the worker threads are implemented.

The "unlimited" stack of the main thread starts at the highest virtual address available in user mode and grows downwards until it meets the program break (the end of the data segment) or hits another memory allocation (either named or anonymous mapping) at which point the program crashes.

Any additional stacks have to be placed somewhere in memory between the program break and the bottom of the main stack. They cannot have an arbitrary extendible length since their initial placements (i.e. the distance between their beginnings) determines their maximum sizes (and vice versa - the specified maximum sizes determine their initial placement). This is the reason why the Linux implementation of pthread_create(3) (used by virtually all OpenMP runtimes in order to create new threads) states:

On Linux/x86-32, the default stack size for a new thread is 2 megabytes. Under the NPTL threading implementation, if the RLIMIT_STACK soft resource limit at the time the program started has any value other than "unlimited", then it determines the default stack size of new threads. Using pthread_attr_setstacksize(3), the stack size attribute can be explicitly set in the attr argument used to create a thread, in order to obtain a stack size other than the default.

In other words, the answer is no - you cannot specify unlimited stack size for threads other than the main one.

这篇关于如何将openmp线程堆栈设置为无限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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