Skip to content

Commit

Permalink
trying to remove OpenMPI environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BerengerBerthoul committed Sep 3, 2024
1 parent 7177f25 commit acb4ea7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
32 changes: 27 additions & 5 deletions pytest_parallel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@
#from mpi4py import MPI
#from logger import consoleLogger

# --------------------------------------------------------------------------
def save_shell_env_without_mpi_vars():
r = subprocess.run(['env','--null'], stdout=subprocess.PIPE) # `--null`: end each output line with NUL, required by `sbatch --export-file`
assert r.returncode==0, 'SLURM scheduler: error when writing `env` to `pytest_slurm/env_vars.sh`'
env_vars = r.stdout

env_vars_no_mpi = b''
openmpi_vars = (
b'OMPI_',
b'PRTE_',
b'PMIX_',
b'OPAL_',
)
for var in env_vars.split(b'\0'):
if not var.startswith(openmpi_vars):
env_vars_no_mpi += var + b'\0'
#print(env_vars_no_mpi)
#print('\n\n\n\n')

#env_vars_no_mpi.replace(b'\n',b'\0')# end each output line with NUL, required by `sbatch --export-file`
#with open('env_vars_toto.sh','wb') as f:
# f.write(env_vars_no_mpi)
#assert 0
return env_vars_no_mpi


# --------------------------------------------------------------------------
def pytest_addoption(parser):
parser.addoption(
Expand Down Expand Up @@ -50,11 +76,7 @@ def pytest_addoption(parser):
' when we are about to register and environment for SLURM' \
' (because importing mpi4py.MPI makes the current process look like and MPI process,' \
' and SLURM does not like that)'

r = subprocess.run(['env','--null'], stdout=subprocess.PIPE) # `--null`: end each output line with NUL, required by `sbatch --export-file`

assert r.returncode==0, 'SLURM scheduler: error when writing `env` to `pytest_slurm/env_vars.sh`'
pytest._pytest_parallel_env_vars = r.stdout
pytest._pytest_parallel_env_vars = save_shell_env_without_mpi_vars()

# --------------------------------------------------------------------------
@pytest.hookimpl(trylast=True)
Expand Down
4 changes: 2 additions & 2 deletions pytest_parallel/process_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def submit_items(items_to_run, socket, main_invoke_params, slurm_ntasks, slurm_c
pytest_slurm = f'{slurm_header}\n\n{cmds}'
Path('pytest_slurm').mkdir(exist_ok=True)
with open('pytest_slurm/job.sh','w') as f:
f.write(pytest_slurm)
f.write(pytest_slurm)

# submit SLURM job
with open('pytest_slurm/env_vars.sh','wb') as f:
f.write(pytest._pytest_parallel_env_vars)
f.write(pytest._pytest_parallel_env_vars)

if slurm_conf['sub_command'] is None:
if slurm_conf['export_env']:
Expand Down

0 comments on commit acb4ea7

Please sign in to comment.