Reputation: 181124
I am trying to build a third-party OpenMP program with gfortran / libgomp, but I'm running into trouble with its use of extensions for retrieving and setting the stacksize-var ICV. The source comes with alternatives for Intel Fortran (kmp_get_stacksize()
and kmp_set_stacksize()
) and for the Portland Group compiler (omp_get_stack_size()
and omp_set_stack_size()
), but how can one accomplish the same thing with GNU Fortran and libgomp?
I am aware of the OMP_STACKSIZE
and GOMP_STACKSIZE
environment variables, but it is my understanding that the actual ICV is separate, so that programmatically setting one of these after program startup will not affect the ICV, and that reading one reports only on that environment variable, not on the ICV.
It is acceptable for the solution to be specific to gfortran and / or libgomp running on Linux.
I'm using gfortran and libgomp from GCC 4.8.5.
Upvotes: 4
Views: 337
Reputation: 22670
The standard itself does not provide a way to modify or retrieve the stacksize-var ICV. So you are doomed to use implementation-specific solutions.
Now libgomp forwards the values specified by environment variables directly to pthread.
So you could say that libgomp stores stacksize-var within gomp_thread_attr
. Unfortunately that seems to be a local symbol in libgomp
and I don't believe you can reasonably access this.
libgomp's initialize_env
is already called during library initialization, not at the first parallel region, so modifying the environment variable is in fact not effective.
For the non-master threads you can at least read the actual value. Although pthread may use an aligned stack size, so it may not be the same value that libgomp specifies.
size_t stacksize;
pthread_attr_t attr;
// TODO check return values
pthread_getattr_np(pthread_self(), &attr);
pthread_attr_getstacksize(&attr, &stacksize);
Upvotes: 3