return nlopt_algorithm_names[a];
}
+/*************************************************************************/
+/* get thread id, if possible, for use in nlopt_srand_time to ensure that
+ different threads have a different default seed even if they are called
+ simultaneously */
+
+#if defined(_WIN32) || defined(__WIN32__)
+# include <windows.h>
+# define my_gettid GetCurrentThreadId
+#elif defined(HAVE_GETTID_SYSCALL)
+# include <unistd.h>
+# include <sys/syscall.h>
+# define my_gettid() syscall(SYS_gettid)
+#elif defined(HAVE_GETPID)
+# include <sys/types.h>
+# include <unistd.h>
+# define my_gettid getpid
+#else
+# define my_gettid() (0)
+#endif
+
/*************************************************************************/
static THREADLOCAL int nlopt_srand_called = 0;
}
void nlopt_srand_time() {
- nlopt_srand(nlopt_time_seed());
+ nlopt_srand(nlopt_time_seed() + my_gettid() * 314159);
}
void nlopt_srand_time_default() {
dnl Checks for libraries and functions
AC_CHECK_LIB(m, sin)
-AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r])
+AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r getpid])
+
+AC_MSG_CHECKING([for gettid syscall])
+AC_TRY_LINK([#include <unistd.h>
+#include <sys/syscall.h>
+], [syscall(SYS_gettid);], [ok=yes], [ok=no])
+if test "$ok" = "yes"; then
+ AC_DEFINE(HAVE_GETTID_SYSCALL,1,[Define if syscall(SYS_gettid) available.])
+fi
+AC_MSG_RESULT(${ok})
AC_MSG_CHECKING([for isnan])
AC_TRY_LINK([#include <math.h>
-], if (!isnan(3.14159)) isnan(2.7183);, ok=yes, ok=no)
+], [if (!isnan(3.14159)) isnan(2.7183);], ok=yes, ok=no)
if test "$ok" = "yes"; then
AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.])
fi
AC_MSG_CHECKING([for isinf])
AC_TRY_LINK([#include <math.h>
-], if (!isinf(3.14159)) isinf(2.7183);, ok=yes, ok=no)
+], [if (!isinf(3.14159)) isinf(2.7183);], ok=yes, ok=no)
if test "$ok" = "yes"; then
AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.])
fi