Hi! There are a couple of bugs in the configure scripts regarding threads checking.
In ompi_check_pthread_pids.m4 the actual code for testing is wrong and is also missing a CFLAG save/add-THREAD_CFLAGS/restore resulting in the linking always failing for the -pthread test with gcc. config.log looks like this. ============= configure:50353: checking if threads have different pids (pthreads on linux) configure:50409: gcc -o conftest -DNDEBUG -march=k8 -O3 -msse -msse2 -maccumulate-outgoing-args -finline-functions -fno-strict-aliasing -fexceptions conftest.c -lnsl -lutil -lm >&5 conftest.c: In function 'checkpid': conftest.c:327: warning: cast to pointer from integer of different size /tmp/ccqUaAns.o: In function `main':conftest.c:(.text+0x1f): undefined reference to `pthread_create' :conftest.c:(.text+0x2e): undefined reference to `pthread_join' collect2: ld returned 1 exit status configure:50412: $? = 1 configure: program exited with status 1 ============= Adding the CFLAGS save/add/restore make the code return the right answer both on systems with the old pthreads implementation and NPTL based systems. BUT, the code as it stands is technically incorrect. The patch have a corrected version. There is also two bugs in ompi_config_pthreads.m4. In OMPI_INTL_POSIX_THREADS_LIBS_CXX it is incorrectly setting PTHREAD_LIBS to $pl, in the then-part of the second if-statement, which at the time isn't set yet and forgetting to reset LIBS on failure in the bottom most if-else case in the for pl loop. In OMPI_INTL_POSIX_THREADS_LIBS_FC it is resetting LIBS whether succesfull or not resulting in -lpthread missing when checking for PTHREAD_MUTEX_ERRORCHECK_NP at least for some versions of pgi, (6.1 and older fails, 7.0 seems to always add -lpthread with pgf77 as linker) The output from configure in such a case looks like this: checking if C compiler and POSIX threads work with -lpthread... yes checking if C++ compiler and POSIX threads work with -lpthread... yes checking if F77 compiler and POSIX threads work with -lpthread... yes checking for PTHREAD_MUTEX_ERRORCHECK_NP... no checking for PTHREAD_MUTEX_ERRORCHECK... no (OS: Ubuntu Dapper, Compiler: pgi 6.1) There is also a problem in the F90 modules include flag search. The test currently does: $FC -c conftest-module.f90 $FC conftest.f90 This doesn't work if one has set FCFLAGS=-g in the environment. At least not with pgf90 since it needs the debug symbols from conftest-module.o to be able to link. You have to either add conftest-module.o to the compile line of conftest or make it a three-stager, $FC -c conftest-module.f90; $FC -c conftest.f90; $FC conftest.o conftest-module.o -- Ake Sandgren, HPC2N, Umea University, S-90187 Umea, Sweden Internet: a...@hpc2n.umu.se Phone: +46 90 7866134 Fax: +46 90 7866126 Mobile: +46 70 7716134 WWW: http://www.hpc2n.umu.se
diff -rU 10 site/config/ompi_config_pthreads.m4 p3/config/ompi_config_pthreads.m4 --- site/config/ompi_config_pthreads.m4 2006-08-15 22:14:05.000000000 +0200 +++ p3/config/ompi_config_pthreads.m4 2007-09-27 09:10:21.000000000 +0200 @@ -473,24 +473,24 @@ CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS" fi ;; esac LIBS="$orig_LIBS $PTHREAD_LIBS" AC_LANG_PUSH(C++) OMPI_INTL_PTHREAD_TRY_LINK(ompi_pthread_cxx_success=1, ompi_pthread_cxx_success=0) AC_LANG_POP(C++) if test "$ompi_pthread_cxx_success" = "1"; then - PTHREAD_LIBS="$pl" AC_MSG_RESULT([yes]) else CXXCPPFLAGS="$orig_CXXCPPFLAGS" + LIBS="$orig_LIBS" AC_MSG_RESULT([no]) AC_MSG_ERROR([Can not find working threads configuration. aborting]) fi else for pl in $plibs; do AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $pl]) case "${host_cpu}-${host-_os}" in *-aix* | *-freebsd*) if test "`echo $CXXCPPFLAGS | grep 'D_THREAD_SAFE'`" = ""; then PTRHEAD_CXXCPPFLAGS="-D_THREAD_SAFE" @@ -508,61 +508,62 @@ AC_LANG_PUSH(C++) OMPI_INTL_PTHREAD_TRY_LINK(ompi_pthread_cxx_success=1, ompi_pthread_cxx_success=0) AC_LANG_POP(C++) if test "$ompi_pthread_cxx_success" = "1"; then PTHREAD_LIBS="$pl" AC_MSG_RESULT([yes]) else PTHREAD_CXXCPPFLAGS= CXXCPPFLAGS="$orig_CXXCPPFLAGS" + LIBS="$orig_LIBS" AC_MSG_RESULT([no]) fi done fi fi ])dnl AC_DEFUN([OMPI_INTL_POSIX_THREADS_LIBS_FC],[ # # Fortran compiler # if test "$ompi_pthread_f77_success" = "0" -a "$OMPI_WANT_F77_BINDINGS" = "1"; then if test ! "$ompi_pthread_c_success" = "0" -a ! "$PTHREAD_LIBS" = "" ; then AC_MSG_CHECKING([if F77 compiler and POSIX threads work with $PTHREAD_LIBS]) LIBS="$orig_LIBS $PTHREAD_LIBS" AC_LANG_PUSH(C) OMPI_INTL_PTHREAD_TRY_LINK_F77(ompi_pthread_f77_success=1, ompi_pthread_f77_success=0) AC_LANG_POP(C) - LIBS="$orig_LIBS" if test "$ompi_pthread_f77_success" = "1"; then AC_MSG_RESULT([yes]) else + LIBS="$orig_LIBS" AC_MSG_RESULT([no]) AC_MSG_ERROR([Can not find working threads configuration. aborting]) fi else for pl in $plibs; do AC_MSG_CHECKING([if F77 compiler and POSIX threads work with $pl]) LIBS="$orig_LIBS $pl" AC_LANG_PUSH(C) OMPI_INTL_PTHREAD_TRY_LINK_F77(ompi_pthread_f77_success=1, ompi_pthread_f77_success=0) AC_LANG_POP(C) - LIBS="$orig_LIBS" if test "$ompi_pthread_f77_success" = "1"; then PTHREAD_LIBS="$pl" AC_MSG_RESULT([yes]) break else + LIBS="$orig_LIBS" AC_MSG_RESULT([no]) fi done fi fi ])dnl AC_DEFUN([OMPI_INTL_POSIX_THREADS_LIBS],[ # Begin: OMPI_INTL_POSIX_THREADS_LIBS
diff -rU 10 site/config/ompi_check_pthread_pids.m4 p3/config/ompi_check_pthread_pids.m4 --- site/config/ompi_check_pthread_pids.m4 2006-11-09 19:53:59.000000000 +0100 +++ p3/config/ompi_check_pthread_pids.m4 2007-09-27 09:07:43.000000000 +0200 @@ -26,62 +26,65 @@ # OMPI_THREADS_HAVE_DIFFERENT_PIDS (variable) # # Test for Linux-like threads in the system. We will need to handle things like # getpid() differently in the case of a Linux-like threads model. # AH_TEMPLATE([OMPI_THREADS_HAVE_DIFFERENT_PIDS], [Do threads have different pids (pthreads on linux)]) AC_MSG_CHECKING([if threads have different pids (pthreads on linux)]) +CFLAGS_save="$CFLAGS" +CFLAGS="$CFLAGS $THREAD_CFLAGS" CPPFLAGS_save="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS" LDFLAGS_save="$LDFLAGS" LDFLAGS="$LDFLAGS $THREAD_LDFLAGS" LIBS_save="$LIBS" LIBS="$LIBS $THREAD_LIBS" AC_TRY_RUN([#include <pthread.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> void *checkpid(void *arg); int main() { pthread_t thr; - int pid, retval; + int pid, *retval; pid = getpid(); pthread_create(&thr, NULL, checkpid, &pid); pthread_join(thr, (void **) &retval); - exit(retval); + exit(*retval); } +static int ret; void *checkpid(void *arg) { - int ret; int ppid = *((int *) arg); if (ppid == getpid()) ret = 0; else ret = 1; - pthread_exit((void *) ret); + pthread_exit((void *) &ret); }], [MSG=no OMPI_THREADS_HAVE_DIFFERENT_PIDS=0], [MSG=yes OMPI_THREADS_HAVE_DIFFERENT_PIDS=1], [case $host in *-linux*) MSG="cross compiling - assuming yes" OMPI_THREADS_HAVE_DIFFERENT_PIDS=1 ;; *) MSG="cross compiling - assuming no" OMPI_THREADS_HAVE_DIFFERENT_PIDS=0 ;; esac ]) +CFLAGS="$CFLAGS_save" CPPFLAGS="$CPPFLAGS_save" LDFLAGS="$LDFLAGS_save" LIBS="$LIBS_save" AC_MSG_RESULT([$MSG]) AC_DEFINE_UNQUOTED(OMPI_THREADS_HAVE_DIFFERENT_PIDS, $OMPI_THREADS_HAVE_DIFFERENT_PIDS) # # if pthreads is not available, then the system does not have an insane threads # model