/** Determine the number of threads for module \p mod. * * \p m takes values form the module_nth_t enum and maps these to the * corresponding value in modth_env_var. * * Each number of threads per module takes the default value unless * GMX_*_NUM_THERADS env var is set, case in which its value overrides * the deafult. * * The "group" scheme supports OpenMP only in PME and in thise case all but * the PME nthread values default to 1. */ static void pick_module_nthreads(const gmx::MDLogger &mdlog, int m, gmx_bool bFullOmpSupport, gmx_bool bSepPME) { char *env; int nth; const bool bOMP = GMX_OPENMP; /* The default should never be set through a GMX_*_NUM_THREADS env var * as it's always equal with gnth. */ if (m == emntDefault) { return; } /* check the environment variable */ if ((env = getenv(modth_env_var[m])) != nullptr) { sscanf(env, "%d", &nth); if (!bOMP) { gmx_warning("%s=%d is set, but %s is compiled without OpenMP!", modth_env_var[m], nth, gmx::getProgramContext().displayName()); } /* with the verlet codepath, when any GMX_*_NUM_THREADS env var is set, * OMP_NUM_THREADS also has to be set */ if (bFullOmpSupport && getenv("OMP_NUM_THREADS") == nullptr) { gmx_warning("%s=%d is set, the default number of threads also " "needs to be set with OMP_NUM_THREADS!", modth_env_var[m], nth); } /* with the group scheme warn if any env var except PME is set */ if (!bFullOmpSupport) { if (m != emntPME) { gmx_warning("%s=%d is set, but OpenMP multithreading is not " "supported in %s!", modth_env_var[m], nth, mod_name[m]); nth = 1; } } /* only babble if we are really overriding with a different value */ if ((bSepPME && m == emntPME && nth != modth.gnth_pme) || (nth != modth.gnth)) { GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted( "%s=%d set, overriding the default number of %s threads", modth_env_var[m], nth, mod_name[m]); } } else { /* pick the global PME node nthreads if we are setting the number * of threads in separate PME nodes */ nth = (bSepPME && m == emntPME) ? modth.gnth_pme : modth.gnth; } gmx_omp_nthreads_set(m, nth); }
/** Determine the number of threads for module \p mod. * * \p m takes values form the module_nth_t enum and maps these to the * corresponding value in modth_env_var. * * Each number of threads per module takes the default value unless * GMX_*_NUM_THERADS env var is set, case in which its value overrides * the deafult. * * The "group" scheme supports OpenMP only in PME and in thise case all but * the PME nthread values default to 1. */ static void pick_module_nthreads(FILE *fplog, int m, gmx_bool bSimMaster, gmx_bool bFullOmpSupport, gmx_bool bSepPME) { char *env; int nth; char sbuf[STRLEN]; gmx_bool bOMP; #ifdef GMX_OPENMP bOMP = TRUE; #else bOMP = FALSE; #endif /* GMX_OPENMP */ /* The default should never be set through a GMX_*_NUM_THREADS env var * as it's always equal with gnth. */ if (m == emntDefault) { return; } /* check the environment variable */ if ((env = getenv(modth_env_var[m])) != NULL) { sscanf(env, "%d", &nth); if (!bOMP) { gmx_warning("%s=%d is set, but %s is compiled without OpenMP!", modth_env_var[m], nth, ShortProgram()); } /* with the verlet codepath, when any GMX_*_NUM_THREADS env var is set, * OMP_NUM_THREADS also has to be set */ if (bFullOmpSupport && getenv("OMP_NUM_THREADS") == NULL) { gmx_fatal(FARGS, "%s=%d is set, the default number of threads also " "needs to be set with OMP_NUM_THREADS!", modth_env_var[m], nth); } /* with the group scheme warn if any env var except PME is set */ if (!bFullOmpSupport) { if (m != emntPME) { gmx_warning("%s=%d is set, but OpenMP multithreading is not " "supported in %s!", modth_env_var[m], nth, mod_name[m]); nth = 1; } } /* only babble if we are really overriding with a different value */ if ((bSepPME && m == emntPME && nth != modth.gnth_pme) || (nth != modth.gnth)) { sprintf(sbuf, "%s=%d set, overriding the default number of %s threads", modth_env_var[m], nth, mod_name[m]); if (bSimMaster) { fprintf(stderr, "\n%s\n", sbuf); } if (fplog) { fprintf(fplog, "%s\n", sbuf); } } } else { /* pick the global PME node nthreads if we are setting the number * of threads in separate PME nodes */ nth = (bSepPME && m == emntPME) ? modth.gnth_pme : modth.gnth; } gmx_omp_nthreads_set(m, nth); }