Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #123 from keisukefukuda/fix-27
Browse files Browse the repository at this point in the history
fix-27
  • Loading branch information
keisukefukuda committed Apr 29, 2019
2 parents 35718e2 + 6553cb0 commit a55a614
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mpienv/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .core import Mpienv, mpienv, UnknownMPI # NOQA
from .core import Mpienv, mpienv, UnknownMPI, AlreadyManagedMpi # NOQA
3 changes: 3 additions & 0 deletions mpienv/command/autodiscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import sys

from mpienv import AlreadyManagedMpi
from mpienv import mpienv


Expand Down Expand Up @@ -139,6 +140,8 @@ def install_mpi(path, mpiexec):
name))
else:
raise
except AlreadyManagedMpi as e:
prints("{} is already managed".format(path))
except RuntimeError as e:
prints("Error occured while "
"adding {}".format(path))
Expand Down
6 changes: 5 additions & 1 deletion mpienv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class UnknownMPI(RuntimeError):
pass


class AlreadyManagedMpi(RuntimeError):
pass


try:
FileNotFoundError
except NameError:
Expand Down Expand Up @@ -249,7 +253,7 @@ def add(self, target, name=None):
if n is not None:
sys.stderr.write("'{}' is already managed "
"as '{}'\n".format(target, n))
exit(1)
raise AlreadyManagedMpi()

if self._installed.get(name) is not None:
sys.stderr.write("Specifed name '{}' is "
Expand Down
26 changes: 15 additions & 11 deletions mpienv/mpibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ def libexec_files(self):

def _generate_exec_script(self, file_name, mpi_args, user_args, keep):
with open(file_name, 'w') as f:
for shell in ['/bin/bash', '/bin/ash', '/bin/sh']:
shells = ['/bin/bash', '/bin/ash', '/bin/sh']
for shell in shells:
if os.path.exists(shell):
f.write('#!{}\n\n'.format(shell))
break
else:
assert False
sys.stderr.write("No available shell found: {}".format(shells))
exit(1)

# Write MPIENV_HOME
f.write("export MPIENV_HOME={}\n\n".format(self.conf['root_dir']))
Expand Down Expand Up @@ -326,18 +328,14 @@ def _generate_exec_script(self, file_name, mpi_args, user_args, keep):
os.chmod(file_name, 0o744)

def exec_(self, cmds, keep, dry_run, verbose, no_python_abspath):
# Determine the temporary shell script name
# Determine the remote hosts
# Transfer the shell script to remote hosts

# We use '/tmp/%%%%.mpienv.sh as a script name
# I think this is OK in most cases
tempfile = _gen_temp_script_name()
remote_hosts = parse_hosts(cmds)

if verbose:
print("tempfile = {}".format(tempfile))
print("hosts = {}".format(remote_hosts))
print("mpienv exec: INFO: tempfile = {}".format(tempfile))
print("mpienv exec: INFO: hosts = {}".format(remote_hosts))

# Run the mpiexec command
mpi_args, user_args = split_mpi_user_prog(cmds)
Expand All @@ -346,10 +344,16 @@ def exec_(self, cmds, keep, dry_run, verbose, no_python_abspath):
if user_args[0] == 'python':
if not no_python_abspath:
user_args[0] = _get_python_interp(user_args[0])
if verbose:
print("mpienv exec: INFO: Python interpreter: {}".format(
user_args[0]
))

if not mpienv.mpienv.config2['DEFAULT'].getboolean('mpi4py'):
sys.stderr.write("mpienv: Warn: It seems that you are trying"
" to run a pythohn progrma, but mpi4py is not"
" ")
sys.stderr.write("mpienv: Warning: "
"It seems that you are trying"
" to run a python program, but mpi4py is not"
" installed")

# Generate a proxy shell script that runs user programs
self._generate_exec_script(tempfile, mpi_args, user_args, keep)
Expand Down

0 comments on commit a55a614

Please sign in to comment.