changeset 21554:9f0088f3f335 stable

call openmp function at initialization (bug #47372) Calling an openmp function early in Octave's startup process ensures that the openmp library will be linked with Octave and that shared libraries that use openmp may be safely loaded and unloaded. * configure.ac: Check for omp.h and omp_get_num_threads. * sysdep.cc: Conditionally include <omp.h>. (sysdep_init) Call omp_get_num_threads if it is available.
author John W. Eaton <jwe@octave.org>
date Mon, 28 Mar 2016 22:00:43 -0400
parents e09f4c9f800a
children 12f207a534aa d42aa6780175
files configure.ac libinterp/corefcn/sysdep.cc
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Fri Mar 25 16:58:01 2016 -0400
+++ b/configure.ac	Mon Mar 28 22:00:43 2016 -0400
@@ -450,16 +450,20 @@
   AX_OPENMP([XTRA_CXXFLAGS="$XTRA_CXXFLAGS $OPENMP_CXXFLAGS"; USE_OPENMP=yes], [])
   AC_LANG_POP(C++)
 fi
-dnl Define here since it is skipped if the first argument to
-dnl AX_OPENMP is not empty.
-if test $USE_OPENMP = yes; then
-  AC_DEFINE(HAVE_OPENMP, 1, [Define if OpenMP is enabled])
-fi
+
 ## Set these for any other tests that may require them.  They will be
 ## reset before output files are generated.
 CFLAGS="$CFLAGS $OPENMP_CFLAGS"
 CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
 
+dnl Define here since it is skipped if the first argument to
+dnl AX_OPENMP is not empty.
+if test $USE_OPENMP = yes; then
+  AC_CHECK_HEADERS([omp.h])
+  AC_CHECK_FUNCS([omp_get_num_threads])
+  AC_DEFINE(HAVE_OPENMP, 1, [Define if OpenMP is enabled])
+fi
+
 ### When compiling math for x87, problems may arise in some code comparing
 ### floating-point intermediate results.  The root cause is the extra precision
 ### (~80 bits) of x87 co-processor registers versus the IEEE standard 64 bits.
--- a/libinterp/corefcn/sysdep.cc	Fri Mar 25 16:58:01 2016 -0400
+++ b/libinterp/corefcn/sysdep.cc	Mon Mar 28 22:00:43 2016 -0400
@@ -60,6 +60,10 @@
 #include <ieeefp.h>
 #endif
 
+#if defined (HAVE_OMP_H)
+#include <omp.h>
+#endif
+
 #include "cmd-edit.h"
 #include "file-ops.h"
 #include "lo-mappers.h"
@@ -308,6 +312,12 @@
 void
 sysdep_init (void)
 {
+#if defined (HAVE_OPENMP)
+#if defined (HAVE_OMP_GET_NUM_THREADS)
+  omp_get_num_threads ();
+#endif
+#endif
+
 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
   BSD_init ();
 #elif defined (__MINGW32__)