Commit 9e2673b3b32b31052c3ac1c44e1a12534b6f1f5e

Authored by Jürgen Knödlseder
1 parent d85cbf20

On Linux systems, test if libgomp.so.1 can be dlopen()ed.

The gcc 4.2.x compiler series has a feature where libgomp.so.1 cannot be dlopen()ed. In this case, the OpenMP support does not properly work in ctools. We try detecting this, but restrict the analysis so far on Linux systems.
Showing 1 changed file with 42 additions and 26 deletions
configure.ac
@@ -719,7 +719,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <GObservations.hpp>]],,)], @@ -719,7 +719,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <GObservations.hpp>]],,)],
719 # Check if openMP is available 719 # Check if openMP is available
720 m4_ifdef([AC_OPENMP],[AC_OPENMP], [AX_OPENMP([openmp_ok=yes],[openmp_ok=no])]) 720 m4_ifdef([AC_OPENMP],[AC_OPENMP], [AX_OPENMP([openmp_ok=yes],[openmp_ok=no])])
721 if test "x$ac_cv_prog_cxx_openmp" != "xunsupported" && test "x$ac_cv_prog_cxx_openmp" != "x"; then 721 if test "x$ac_cv_prog_cxx_openmp" != "xunsupported" && test "x$ac_cv_prog_cxx_openmp" != "x"; then
722 - openmp_ok=yes 722 + openmp_ok=yes
723 fi 723 fi
724 724
725 # Signal actual test 725 # Signal actual test
@@ -727,47 +727,63 @@ AC_MSG_CHECKING(whether to enable OpenMP) @@ -727,47 +727,63 @@ AC_MSG_CHECKING(whether to enable OpenMP)
727 727
728 # If OpenMP is available 728 # If OpenMP is available
729 if test "x$openmp_ok" = "xyes"; then 729 if test "x$openmp_ok" = "xyes"; then
730 - # If gammalib is compiled with OpenMP, ctools must also be compiled with  
731 - # openmp  
732 - if test "x$gammalib_with_openmp" = "xyes"; then  
733 - enable_openmp="yes"  
734 - else  
735 - # ... otherwise, we use it optionally  
736 - AC_ARG_ENABLE([openmp],  
737 - AS_HELP_STRING([--enable-openmp],  
738 - [turn on OpenMP support [default=yes]]),  
739 - [enable_openmp="$enableval"],  
740 - [enable_openmp="yes"])  
741 - fi 730 +
  731 + # Special Linux test to detect shared libgomp libraries that can not be loaded
  732 + # dynamically
  733 + if test "$OPENMP_CXXFLAGS" = "-fopenmp" -a "$ac_sys_system" = "Linux"; then
  734 + AC_MSG_CHECKING(whether we can dynamically load libgomp)
  735 + SAVED_LDFLAGS=$LDFLAGS
  736 + LDFLAGS="$LDFLAGS -ldl"
  737 + AC_TRY_RUN(AC_LANG_PROGRAM([#include <dlfcn.h>],
  738 + [if (dlopen("libgomp.so.1", RTLD_NOW) == 0) return 1;]),
  739 + [AC_MSG_RESULT(yes)],
  740 + [enable_openmp="no"
  741 + AC_MSG_RESULT(no)
  742 + AC_MSG_WARN([OpenMP detected but shared libgomp.so.1 library cannot be dlopen()ed.])
  743 + AC_MSG_WARN([If you use a gcc 4.2.x compiler, this is a known feature. Try to use gcc >= 4.3.])])
  744 + LDFLAGS=$SAVED_LDFLAGS
  745 + fi
  746 +
  747 + # If gammalib is compiled with OpenMP, ctools must also be compiled with
  748 + # openmp
  749 + if test "x$gammalib_with_openmp" = "xyes"; then
  750 + enable_openmp="yes"
  751 + else
  752 + # ... otherwise, we use it optionally
  753 + AC_ARG_ENABLE([openmp],
  754 + AS_HELP_STRING([--enable-openmp],
  755 + [turn on OpenMP support [default=yes]]),
  756 + [enable_openmp="$enableval"],
  757 + [enable_openmp="yes"])
  758 + fi
  759 +
742 fi 760 fi
743 761
744 # Set compiler flags accordingly 762 # Set compiler flags accordingly
745 if test "x$enable_openmp" = "xyes"; then 763 if test "x$enable_openmp" = "xyes"; then
746 - CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"  
747 - AC_DEFINE([HAVE_OPENMP], [1], [Define if OpenMP is enabled])  
748 - AC_MSG_RESULT(yes) 764 + CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
  765 + AC_DEFINE([HAVE_OPENMP], [1], [Define if OpenMP is enabled])
  766 + AC_MSG_RESULT(yes)
749 else 767 else
750 - enable_openmp=no  
751 - AC_MSG_RESULT(no) 768 + enable_openmp=no
  769 + AC_MSG_RESULT(no)
752 fi 770 fi
753 771
754 # Set system specific settings 772 # Set system specific settings
755 OPENMP_LIB_LDFLAGS= 773 OPENMP_LIB_LDFLAGS=
756 if test "x$enable_openmp" = "xyes"; then 774 if test "x$enable_openmp" = "xyes"; then
757 - case $ac_sys_system/$ac_sys_release in  
758 - Darwin/*)  
759 - #  
760 - #  
761 - OPENMP_LIB_LDFLAGS=-lgomp  
762 - ;;  
763 - esac 775 + case $ac_sys_system/$ac_sys_release in
  776 + Darwin/*)
  777 + OPENMP_LIB_LDFLAGS=-lgomp
  778 + ;;
  779 + esac
764 fi 780 fi
765 AC_SUBST(OPENMP_LIB_LDFLAGS) 781 AC_SUBST(OPENMP_LIB_LDFLAGS)
766 782
767 # Signal if ctools cannot be compiled as gammalibe requires OpenMP but ctools 783 # Signal if ctools cannot be compiled as gammalibe requires OpenMP but ctools
768 # cannot be compiled with OpenMP 784 # cannot be compiled with OpenMP
769 if test "x$enable_openmp" = "xno" && test "x$gammalib_with_openmp" = "xyes"; then 785 if test "x$enable_openmp" = "xno" && test "x$gammalib_with_openmp" = "xyes"; then
770 - AC_MSG_ERROR([The GammaLib library has been built with openMP support but OpenMP is not available on this system. Please install OpenMP or re-build GammaLib without OpenMP support.]) 786 + AC_MSG_ERROR([The GammaLib library has been built with openMP support but OpenMP is not available on this system. Please install OpenMP or re-build GammaLib without OpenMP support.])
771 fi 787 fi
772 AM_CONDITIONAL(OPENMP,test "x$enable_openmp" = "xyes") 788 AM_CONDITIONAL(OPENMP,test "x$enable_openmp" = "xyes")
773 789