# HG changeset patch # User John W. Eaton # Date 1459216843 14400 # Node ID 9f0088f3f335224cf0032cc4a11127a60f526a89 # Parent e09f4c9f800ab8dca506ec34edde20fe7407f442 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 . (sysdep_init) Call omp_get_num_threads if it is available. diff -r e09f4c9f800a -r 9f0088f3f335 configure.ac --- 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. diff -r e09f4c9f800a -r 9f0088f3f335 libinterp/corefcn/sysdep.cc --- 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 #endif +#if defined (HAVE_OMP_H) +#include +#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__)