Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / utility / gmxomp.h
index 276aee8c13540b3055289c1e6d79fc14b9f0d0e4..f0e67a593f4af86bfbcfe62cf2d5f5c821aa0a52 100644 (file)
@@ -49,9 +49,9 @@
 #ifndef GMX_UTILITY_OMP_H
 #define GMX_UTILITY_OMP_H
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+
+#include <stdio.h>
 
 #ifndef GMX_NATIVE_WINDOWS
 /* Ugly hack because the openmp implementation below hacks into the SIMD
@@ -67,8 +67,7 @@
 #include <windows.h>
 #endif
 
-#include "types/commrec.h"
-#include "mdrun.h"
+#include "basedefinitions.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -113,9 +112,31 @@ void gmx_omp_set_num_threads(int num_threads);
 /*! \brief
  * Check for externally set thread affinity to avoid conflicts with \Gromacs
  * internal setting.
+ *
+ * \param[out] message  Receives the message to be shown to the user.
+ * \returns `true` if we can set thread affinity ourselves.
+ *
+ * While GNU OpenMP does not set affinity by default, the Intel OpenMP library
+ * does.  This conflicts with the internal affinity (especially thread-MPI)
+ * setting, results in incorrectly locked threads, and causes dreadful performance.
+ *
+ * The KMP_AFFINITY environment variable is used by Intel, GOMP_CPU_AFFINITY
+ * by the GNU compilers (Intel also honors it well).  If any of the variables
+ * is set, we should honor it and disable the internal pinning.
+ * When using Intel OpenMP, we will disable affinity if the user did not set it
+ * manually through one of the aforementioned environment variables.
+ *
+ * Note that the Intel OpenMP affinity disabling will only take effect if this
+ * function is called before the OpenMP library gets initialized, which happens
+ * when the first call is made into a compilation unit that contains OpenMP
+ * pragmas.
+ *
+ * If this function returns `false`, the caller is responsible to disable the
+ * pinning, show the message from \p *message to the user, and free the memory
+ * allocated for \p *message.
+ * If the return value is `true`, \p *message is NULL.
  */
-void gmx_omp_check_thread_affinity(FILE *fplog, const t_commrec *cr,
-                                   gmx_hw_opt_t *hw_opt);
+gmx_bool gmx_omp_check_thread_affinity(char **message);
 
 /*! \brief
  * Pause for use in a spin-wait loop.