"Fossies" - the Fresh Open Source Software Archive

Member "gretl-2020e/macros/openmp.m4" (29 Aug 2019, 3205 Bytes) of package /linux/misc/gretl-2020e.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # AC_C_OPENMP
    2 # -----------
    3 # Check which options need to be passed to the C compiler to support OpenMP.
    4 # Set the OPENMP_CFLAGS variable to these options.
    5 # The options are necessary at compile time (so the #pragmas are understood)
    6 # and at link time (so the appropriate library is linked with).
    7 # This macro takes care to not produce redundant options if $CC $CFLAGS already
    8 # supports OpenMP. It also is careful to not pass options to compilers that
    9 # misinterpret them; for example, most compilers accept "-openmp" and create
   10 # an output file called 'penmp' rather than activating OpenMP support.
   11 # -----------
   12 AC_DEFUN([AC_C_OPENMP],
   13 [
   14   AC_MSG_CHECKING([whether to use OpenMP])
   15   AC_ARG_ENABLE(openmp,
   16     [AS_HELP_STRING([--enable-openmp], [use OpenMP if available [default=auto]])],
   17     [enable_openmp=$enableval]
   18   )
   19   ac_openmp_result=no
   20   OPENMP_CFLAGS=
   21   if test "$enable_openmp" != "no" ; then
   22     AC_CACHE_VAL([ac_cv_prog_cc_openmp], [
   23       ac_cv_prog_cc_openmp=unsupported
   24       AC_LINK_IFELSE([AC_LANG_SOURCE([
   25 #ifndef _OPENMP
   26  choke me
   27 #endif
   28 #include <omp.h>
   29 int main () { return omp_get_num_threads (); }
   30 	])], [ac_cv_prog_cc_openmp="none needed"])
   31       if test "$ac_cv_prog_cc_openmp" = unsupported; then
   32 	dnl Try these flags:
   33 	dnl   GCC >= 4.2	   -fopenmp
   34 	dnl   SunPRO C  	   -xopenmp
   35 	dnl   Intel C		   -openmp
   36 	dnl   SGI C, PGI C	   -mp
   37 	dnl   Tru64 Compaq C	   -omp
   38 	dnl   IBM C (AIX, Linux)   -qsmp=omp
   39 	for brand in clang GCC SunPRO Intel SGI/PGI Compaq IBM; do
   40 	  case $brand in
   41 	    clang)
   42 	      ac_conditional='defined __clang__'
   43 	      ac_option='-fopenmp=libomp' ;;
   44 	    GCC)
   45 	      ac_conditional='defined __GNUC__'
   46 	      ac_option='-fopenmp' ;;
   47 	    SunPRO)
   48 	      ac_conditional='defined __SUNPRO_C || defined __SUNPRO_CC'
   49 	      ac_option='-xopenmp' ;;
   50 	    Intel)
   51 	      ac_conditional='defined __INTEL_COMPILER'
   52 	      ac_option='-openmp' ;;
   53 	    SGI/PGI)
   54 	      ac_conditional='defined __sgi || defined __PGI || defined __PGIC__'
   55 	      ac_option='-mp' ;;
   56 	    Compaq)
   57 	      ac_conditional='defined __DECC || defined __DECCXX'
   58 	      ac_option='-omp' ;;
   59 	    IBM)
   60 	      ac_conditional='defined __xlc__ || defined __xlC__'
   61 	      ac_option='-qsmp=omp' ;;
   62 	  esac
   63 	  if test $brand = GCC; then
   64 	    if test "$GCC" = yes; then
   65 	      ac_openmp_result=yes
   66 	    else
   67 	      ac_openmp_result=no
   68 	    fi
   69 	  else
   70 	    AC_EGREP_CPP([Brand], [
   71 	      #if $ac_conditional
   72 	       Brand
   73 	      #endif
   74 	      ], [ac_openmp_result=yes], [ac_openmp_result=no])
   75 	  fi
   76 	  if test $ac_openmp_result = yes; then
   77 	    ac_save_CFLAGS=$CFLAGS
   78 	    CFLAGS="$CFLAGS $ac_option"
   79 	    AC_LINK_IFELSE([AC_LANG_SOURCE([
   80 #ifndef _OPENMP
   81  choke me
   82 #endif
   83 #include <omp.h>
   84 int main () { return omp_get_num_threads (); }
   85 	      ])], [ac_cv_prog_cc_openmp=$ac_option])
   86 	    CFLAGS=$ac_save_CFLAGS
   87 	    break
   88 	  fi
   89 	done
   90       fi
   91       ])
   92     dnl AC_MSG_RESULT([$ac_cv_prog_cc_openmp])
   93     case $ac_cv_prog_cc_openmp in
   94       "none needed")
   95         ac_openmp_result=yes
   96 	OPENMP_CFLAGS= ;;
   97       unsupported)
   98         ac_openmp_result=no
   99         OPENMP_CFLAGS= ;;
  100       *)
  101 	OPENMP_CFLAGS=$ac_cv_prog_cc_openmp ;;
  102     esac
  103   fi
  104   AC_MSG_RESULT([$ac_openmp_result])
  105   AC_SUBST([OPENMP_CFLAGS])
  106 ])
  107