const char *const kmp_env = getenv("KMP_AFFINITY");
const bool bKmpAffinitySet = (kmp_env != NULL);
- /* disable Intel OpenMP affinity if neither KMP_AFFINITY nor
- * GOMP_CPU_AFFINITY is set (Intel uses the GNU env. var as well) */
- if (!bKmpAffinitySet && !bGompCpuAffinitySet)
- {
- int retval;
-
-#ifdef _MSC_VER
- /* Windows not POSIX */
- retval = _putenv_s("KMP_AFFINITY", "disabled");
-#else
- /* POSIX */
- retval = setenv("KMP_AFFINITY", "disabled", 0);
-#endif /* _MSC_VER */
-
- if (debug)
- {
- fprintf(debug, "Disabling Intel OpenMP affinity by setting the KMP_AFFINITY=disabled env. var.\n");
- }
-
- if (retval != 0)
- {
- gmx_warning("Disabling Intel OpenMp affinity setting failed!");
- }
- }
-
- /* turn off internal pinning KMP_AFFINITY != "disabled" */
- if (bKmpAffinitySet && (gmx_strncasecmp(kmp_env, "disabled", 8) != 0))
+ // turn off internal pinning if KMP_AFFINITY is set but does not contain
+ // the settings 'disabled' or 'none'.
+ if (bKmpAffinitySet &&
+ (strstr(kmp_env, "disabled") == NULL) &&
+ (strstr(kmp_env, "none") == NULL))
{
try
{
std::string buf = gmx::formatString(
"NOTE: KMP_AFFINITY set, will turn off %s internal affinity\n"
" setting as the two can conflict and cause performance degradation.\n"
- " To keep using the %s internal affinity setting, set the\n"
- " KMP_AFFINITY=disabled environment variable.",
+ " To keep using the %s internal affinity setting, unset the\n"
+ " KMP_AFFINITY environment variable or set it to 'none' or 'disabled'.",
programName, programName);
*message = gmx_strdup(buf.c_str());
}
* \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