# HG changeset patch # User David Bateman # Date 1269710634 -3600 # Node ID bcabc1c4f20c0244793a31f60261b2a3f5a2a575 # Parent 9500a66118dcd4e68ed532341a224ff57959a620 Add detection of OpenMP support to configure. Disabled by default diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-27 David Bateman + + * acinclude.m4 (OCTAVE_CHECK_OPENMP): Macro to check for OpenMP support + * configure.ac: Use it here. Disable OpenMP support by default + 2010-03-25 John W. Eaton * bootstrap.conf (gnulib_modules): Sort the list. diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1065,6 +1065,35 @@ fi ]) dnl +dnl Check for support of OpenMP with a given compiler flag. If +dnl found define HAVE_OPENMP and add the compile flag to CFLAGS +dnl and CXXFLAGS. +dnl +AC_DEFUN([OCTAVE_CHECK_OPENMP], +[AC_MSG_CHECKING([for support of OpenMP]) +XCFLAGS="$CFLAGS" +CFLAGS="$CFLAGS $1" +AC_CACHE_VAL(octave_cv_check_openmp,[ +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +]], [[ +int main(int argc, char* argv[]) +{ + _Pragma("omp parallel") + printf("Hello, world.\n"); + return 0; +} +]])],octave_cv_openmp=yes, octave_cv_openmmp=no, octave_cv_openmp=no)]) +AC_MSG_RESULT($octave_cv_openmp) +if test "$octave_cv_openmp" = yes; then + AC_DEFINE(HAVE_OPENMP,1,[Define if compiler supports OpenMP]) + CXXFLAGS="$CXXFLAGS $1" +else + CFLAGS="$XCFLAGS" +fi +]) +dnl dnl Configure paths for FreeType2 dnl Marcelo Magallon 2001-10-26, based on gtk.m4 by Owen Taylor dnl diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -427,6 +427,26 @@ ;; esac +## Test whether the compiler supports OpenMP. Experimental so disable by +## default. Enable it with the flag --enable-openmp +USE_OPENMP=false +AC_ARG_ENABLE(openmp, + [AS_HELP_STRING([--enable-openmp], + [(EXPERIMENTAL) use OpenMP SMP multi-threading])], + [if test "$enableval" = yes; then USE_OPENMP=true; fi], []) +if $USE_OPENMP; then + case "$canonical_host_type" in + *-*-mingw* | *-*-cygwin* | *-*-gnu*) + OCTAVE_CHECK_OPENMP(-fopenmp) + ;; + *-*-msdosmsvc) + ## FIXME is this the right flag for MSVC? + OCTAVE_CHECK_OPENMP(-openmp) + ;; + ## Add other compilers supporting OpenMP here + esac +fi + AC_SUBST(XTRA_CFLAGS) AC_SUBST(XTRA_CXXFLAGS) @@ -2314,6 +2334,19 @@ warn_msg_printed=true fi +if $USE_OPENMP; then + AC_MSG_WARN([]) + AC_MSG_WARN([You used the EXPERIMENTAL --enable-openmp option.]) + AC_MSG_WARN([Are you sure that is what you want to do?]) + AC_MSG_WARN([]) + AC_MSG_WARN([This option enables experimental SMP multithreding]) + AC_MSG_WARN([code that has had very little testing. There is no]) + AC_MSG_WARN([certainity that the results returned by Octave with]) + AC_MSG_WARN([this option enabled will be correct.]) + AC_MSG_WARN([]) + warn_msg_printed=true +fi + native_graphics=true if test -n "$warn_freetype"; then AC_MSG_WARN([$warn_freetype]) diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2010-03-27 David Bateman + + * oct-openmp.h: New file. + * Makefile.am (INCS): Add it here. + 2010-03-26 Jaroslav Hajek * Sparse.cc (Sparse::index (const idx_vector&, const idx_vector&, bool)): diff --git a/liboctave/Makefile.am b/liboctave/Makefile.am --- a/liboctave/Makefile.am +++ b/liboctave/Makefile.am @@ -223,6 +223,7 @@ oct-mem.h \ oct-mutex.h \ oct-norm.h \ + oct-openmp.h \ oct-passwd.h \ oct-rand.h \ oct-rl-edit.h \ diff --git a/liboctave/oct-openmp.h b/liboctave/oct-openmp.h new file mode 100644 --- /dev/null +++ b/liboctave/oct-openmp.h @@ -0,0 +1,34 @@ +/* + +Copyright (C) 2010 David Bateman + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if !defined (octave_openmp_h) +#define octave_openmp_h 1 + +/* A macro to make using OpenMP easier, and easier to disable */ +#ifdef HAVE_OPENMP +#include +#define OCTAVE_OMP_PRAGMA(x) _Pragma (#x) +#else +#define OCTAVE_OMP_PRAGMA(x) +#endif + +#endif