32-bit Stack Limitations on 64-bit Linux

The 32-bit stack on a 64-bit Linux system is limited when using libpthread.

This example demonstrates that using libpthread will force your stack to be no larger than 2MB, regardliss of how you set 'limit stacksize' to a larger value.

% cat stack.c
#include 
#define MB  (1024*1024)
#define Z   2
void
f()
{
char b[Z*MB];
b[0]='a';
}
void
g()
{
char c[1];
c[0]='a';
}
main()
{
system("tcsh -c \"limit stacksize\"");
omp_set_num_threads(2);
 #pragma parallel
g();   /* does nothing  to increase stack */
 #pragma end parallel
f();  /* attempts to declare/use a 2mb array outside parallel region */
printf("passed with a %dmb array declared \n",Z);
exit(0);
}

% pgcc -V -o stack_nomp stack.c
pgcc 5.2-2
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2004, STMicroelectronics, Inc.  All Rights Reserved.
PGC/x86 Linux/x86 5.2-2
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2004, STMicroelectronics, Inc.  All Rights Reserved.

% ldd stack_nomp
libc.so.6 => /lib/libc.so.6 (0x5556e000)
libpgc.so => /usr/pgi_rel/linux86/5.1/lib/libpgc.so (0x556a4000)
libm.so.6 => /lib/libm.so.6 (0x556b8000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

% stack_nomp
stacksize   8192 kbytes
Warning: omp_set_num_threads (2) greater than available cpus (1)
passed with a 2mb array declared

Now include libpthread by compiling -mp, so the pragmas are read. Note that in the threaded areas, no large stack usage goes on.

% pgcc -V -o stack_mp stack.c -mp
% ldd stack_mp
libpthread.so.0 => /lib/libpthread.so.0 (0x5556e000)
libc.so.6 => /lib/libc.so.6 (0x555c1000)
libpgc.so => /usr/pgi_rel/linux86/5.1/lib/libpgc.so (0x556f7000)
libm.so.6 => /lib/libm.so.6 (0x5570b000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

% stack_mp
stacksize   unlimited
Segmentation fault

The same executable on a 32-bit RHEL 3.0 system

% stack_nomp
stacksize   10240 kbytes
Warning: omp_set_num_threads (2) greater than available cpus (1)
passed with a 2mb array declared

% stack_mp
stacksize   10240 kbytes
passed with a 2mb array declared

64-bit compilations of this example work w/o problem when stacksize is set to a proper size, in either mp or nomp.

Click me