cannam@95: dnl @synopsis AX_OPENMP([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) cannam@95: dnl @summary determine how to compile programs using OpenMP cannam@95: dnl @category InstalledPackages cannam@95: dnl cannam@95: dnl This macro tries to find out how to compile programs that cannam@95: dnl use OpenMP, a standard API and set of compiler directives for cannam@95: dnl parallel programming (see http://www.openmp.org/). cannam@95: dnl cannam@95: dnl On success, it sets the OPENMP_CFLAGS/OPENMP_CXXFLAGS/OPENMP_FFLAGS cannam@95: dnl output variable to the flag (e.g. -omp) used both to compile *and* link cannam@95: dnl OpenMP programs in the current language. cannam@95: dnl cannam@95: dnl NOTE: You are assumed to not only compile your program with these cannam@95: dnl flags, but also link it with them as well. cannam@95: dnl cannam@95: dnl If you want to compile everything with OpenMP, you should set: cannam@95: dnl cannam@95: dnl CFLAGS="$CFLAGS $OPENMP_CFLAGS" cannam@95: dnl #OR# CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS" cannam@95: dnl #OR# FFLAGS="$FFLAGS $OPENMP_FFLAGS" cannam@95: dnl cannam@95: dnl (depending on the selected language). cannam@95: dnl cannam@95: dnl The user can override the default choice by setting the corresponding cannam@95: dnl environment variable (e.g. OPENMP_CFLAGS). cannam@95: dnl cannam@95: dnl ACTION-IF-FOUND is a list of shell commands to run if an OpenMP cannam@95: dnl flag is found, and ACTION-IF-NOT-FOUND is a list of commands cannam@95: dnl to run it if it is not found. If ACTION-IF-FOUND is not specified, cannam@95: dnl the default action will define HAVE_OPENMP. cannam@95: dnl cannam@95: dnl @version 2006-11-20 cannam@95: dnl @license GPLWithACException cannam@95: dnl @author Steven G. Johnson cannam@95: cannam@95: AC_DEFUN([AX_OPENMP], [ cannam@95: AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX cannam@95: cannam@95: AC_CACHE_CHECK([for OpenMP flag of _AC_LANG compiler], ax_cv_[]_AC_LANG_ABBREV[]_openmp, [save[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS cannam@95: ax_cv_[]_AC_LANG_ABBREV[]_openmp=unknown cannam@95: # Flags to try: -fopenmp (gcc), -openmp (icc), -mp (SGI & PGI), cannam@95: # -xopenmp (Sun), -omp (Tru64), -qsmp=omp (AIX), none cannam@95: ax_openmp_flags="-fopenmp -openmp -mp -xopenmp -omp -qsmp=omp none" cannam@95: if test "x$OPENMP_[]_AC_LANG_PREFIX[]FLAGS" != x; then cannam@95: ax_openmp_flags="$OPENMP_[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flags" cannam@95: fi cannam@95: for ax_openmp_flag in $ax_openmp_flags; do cannam@95: case $ax_openmp_flag in cannam@95: none) []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[] ;; cannam@95: *) []_AC_LANG_PREFIX[]FLAGS="$save[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flag" ;; cannam@95: esac cannam@95: AC_TRY_LINK_FUNC(omp_set_num_threads, cannam@95: [ax_cv_[]_AC_LANG_ABBREV[]_openmp=$ax_openmp_flag; break]) cannam@95: done cannam@95: []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[]FLAGS cannam@95: ]) cannam@95: if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" = "xunknown"; then cannam@95: m4_default([$2],:) cannam@95: else cannam@95: if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" != "xnone"; then cannam@95: OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ax_cv_[]_AC_LANG_ABBREV[]_openmp cannam@95: fi cannam@95: m4_default([$1], [AC_DEFINE(HAVE_OPENMP,1,[Define if OpenMP is enabled])]) cannam@95: fi cannam@95: AC_SUBST(OPENMP_[]_AC_LANG_PREFIX[]FLAGS) cannam@95: ])dnl AX_OPENMP