diff --git a/scripts/lib/CIME/case/case.py b/scripts/lib/CIME/case/case.py index 2305bc4ccc6f..28c602dd1ba4 100644 --- a/scripts/lib/CIME/case/case.py +++ b/scripts/lib/CIME/case/case.py @@ -177,7 +177,10 @@ def initialize_derived_attributes(self): threads_per_core = 1 if (threads_per_node <= max_mpitasks_per_node) else smt_factor self.cores_per_task = self.thread_count / threads_per_core - os.environ["OMP_NUM_THREADS"] = str(self.thread_count) + if self.get_build_threaded(): + os.environ["OMP_NUM_THREADS"] = str(self.thread_count) + elif "OMP_NUM_THREADS" in os.environ: + del os.environ["OMP_NUM_THREADS"] self.srun_binding = smt_factor*max_mpitasks_per_node / self.tasks_per_node @@ -1417,7 +1420,10 @@ def load_env(self, reset=False, job=None, verbose=False): if not self._is_env_loaded or reset: if job is None: job = self.get_primary_job() - os.environ["OMP_NUM_THREADS"] = str(self.thread_count) + if self.get_build_threaded(): + os.environ["OMP_NUM_THREADS"] = str(self.thread_count) + elif "OMP_NUM_THREADS" in os.environ: + del os.environ["OMP_NUM_THREADS"] env_module = self.get_env("mach_specific") env_module.load_env(self, job=job, verbose=verbose) self._is_env_loaded = True diff --git a/scripts/lib/CIME/case/case_run.py b/scripts/lib/CIME/case/case_run.py index f7fc66a4a6bd..4495131eeaa1 100644 --- a/scripts/lib/CIME/case/case_run.py +++ b/scripts/lib/CIME/case/case_run.py @@ -76,7 +76,10 @@ def _run_model_impl(case, lid, skip_pnl=False, da_cycle=0): model = case.get_value("MODEL") # Set OMP_NUM_THREADS - os.environ["OMP_NUM_THREADS"] = str(case.thread_count) + if case.get_build_threaded(): + os.environ["OMP_NUM_THREADS"] = str(case.thread_count) + elif "OMP_NUM_THREADS" in os.environ: + del os.environ["OMP_NUM_THREADS"] # Run the model cmd = case.get_mpirun_cmd(allow_unresolved_envvars=False)