Simple OpenMP program will not work when compiled with '-static' option $ cat test.f90 use omp_lib implicit none integer, parameter :: NT = 4 integer :: nThreads(NT) print *, 'Call omp_set_dynamic' !$ call omp_set_dynamic(.false.) print *, 'Call omp_set_num_threads' !$ call omp_set_num_threads(NT) print *, 'Now enter the parallel region' !$omp parallel default(none) shared(nThreads) nThreads(omp_get_thread_num()+1) = omp_get_num_threads() !$omp end parallel print*, nThreads END $ gfortran -fopenmp test.f90 $ ./a.out Call omp_set_dynamic Call omp_set_num_threads Now enter the parallel region 4 4 4 4 $ gfortran -static -fopenmp test.f90 $ ./a.out Memory fault $ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30471 offers the following workaround: $ gfortran -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -fopenmp -static test.f90 /usr/lib/../lib64/libpthread.a(sem_open.o): In function `sem_open': (.text+0x46d): warning: the use of `mktemp' is dangerous, better use `mkstemp' $ ./a.out Call omp_set_dynamic Call omp_set_num_threads Now enter the parallel region 4 4 4 4 $ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31604#c5 provides analysis on where the problem is occurring.
*** This bug has been marked as a duplicate of 5784 ***
The issue is GCC uses 1. Mark pthread_foo as weak. 2. Use a weak pthread_xxxx to check if thread is active. 3. It does if (pthread_xxxx) pthread_foo (); With libpthread.a, there is no guarantee that linking in archive member for pthread_xxxx will also include archive member for pthread_foo. When it happens, static executable crashes when calling pthread_foo. We can add if (pthread_foo) pthread_foo (); But it may lead to bad static executable hehavior. The list of pthread_foo is pthread_attr_init pthread_attr_setdetachstate pthread_cond_broadcast pthread_cond_destroy pthread_cond_init pthread_cond_signal pthread_cond_wait pthread_create pthread_detach pthread_exit pthread_getschedparam pthread_getspecific pthread_join pthread_key_create pthread_key_delete pthread_mutex_destroy pthread_mutex_init pthread_mutex_lock pthread_mutex_trylock pthread_mutex_unlock pthread_once pthread_self pthread_setschedparam pthread_setspecific pthread_sigmask __pthread_key_create
*** Bug 260998 has been marked as a duplicate of this bug. *** Seen from the domain http://volichat.com Page where seen: http://volichat.com/adult-chat-rooms Marked for reference. Resolved as fixed @bugzilla.
Closing this issue as duplicate of 5784 (since this issue has spam comment we should use 5784 to discuss). *** This bug has been marked as a duplicate of bug 5784 ***