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 #109 from keisukefukuda/abolish-symlink
Browse files Browse the repository at this point in the history
fixed use command
  • Loading branch information
keisukefukuda committed Mar 5, 2019
2 parents 91d83d6 + c89eb71 commit 277e79c
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 328 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
__pycache__
versions
shims
*.pyc
pylib
dist
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ addons:
packages:
- ibverbs-utils
- libibverbs-dev
- wget
- zsh

before_script:
Expand Down
190 changes: 0 additions & 190 deletions bin/mpienv-init

This file was deleted.

11 changes: 3 additions & 8 deletions mpienv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,15 @@ def mkdir_p(path):
class Mpienv(object):
def __init__(self, root_dir):
self._root_dir = root_dir
self._vers_dir = os.path.join(os.environ.get("MPIENV_VERSIONS_DIR") or
os.path.join(root_dir, 'versions'))
self._shims_dir = os.path.join(self._vers_dir, 'shims')
self._vers_dir = os.path.join(os.path.join(root_dir, 'versions'))
pybin = os.path.realpath(sys.executable)
pybin_enc = re.sub(r'[^a-zA-Z0-9.]', '_', re.sub('^/', '', pybin))

self._mpi_dir = os.path.join(self._vers_dir, 'mpi')
self._pylib_dir = os.path.join(self._vers_dir, 'pylib', pybin_enc)
self._pybuild_dir = os.path.join(self._vers_dir, 'pybuild', pybin_enc)
self._cache_dir = os.environ.get("MPIENV_CACHE_DIR",
os.path.join(root_dir, 'cache'))
self._build_dir = os.environ.get("MPIENV_BUILD_DIR",
os.path.join(root_dir, 'builds'))
self._cache_dir = os.path.join(root_dir, 'cache')
self._build_dir = os.path.join(root_dir, 'builds')

self._make_directories()
self._setup_config()
Expand All @@ -90,7 +86,6 @@ def __init__(self, root_dir):
self._conf['pybuild_dir'] = self._pybuild_dir
self._conf['cache_dir'] = self._cache_dir
self._conf['build_dir'] = self._build_dir
self._conf['shims_dir'] = self._shims_dir

def _make_directories(self):
mkdir_p(self._root_dir)
Expand Down
83 changes: 41 additions & 42 deletions mpienv/mpibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from subprocess import Popen
import sys # NOQA

import mpienv
from mpienv.py import MPI4Py
import mpienv.util as util

Expand Down Expand Up @@ -157,8 +158,7 @@ def run_cmd(self, cmd, extra_envs):
envs = os.environ.copy()
envs.update(extra_envs)

shimd = self.conf['shims_dir']
ld_lib_path = "{}/lib:{}/lib64".format(shimd, shimd)
ld_lib_path = "{}/lib:{}/lib64".format(self.prefix, self.prefix)

# We need to construct LD_LIBRARY_PATH for the child mpiexec process
# because setuid-ed programs ignore 'LD_LIBRARY_PATH'.
Expand All @@ -172,50 +172,49 @@ def run_cmd(self, cmd, extra_envs):
exit(p.returncode)

def use(self, name, mpi4py=False):
# Defined in child classes (Mpich, Mvapich, OpenMPI ,etc)
bin_files = self.bin_files()
lib_files = self.lib_files()
inc_files = self.inc_files()
libexec_files = self.libexec_files()

# sys.stderr.write("use: self={}\n".format(self))
shim = self._conf['shims_dir']
if os.path.exists(shim):
if os.path.islink(shim):
os.unlink(shim)
else:
try:
shutil.rmtree(shim)
except OSError:
os.unlink(shim)

os.mkdir(shim)

for d in ['bin', 'lib', 'include', 'libexec']:
dr = os.path.join(self._conf['shims_dir'], d)
if not os.path.exists(dr):
os.mkdir(dr)

for f in bin_files:
bin = os.path.join(shim, 'bin')
self._mirror_file(f, bin)
self._mirror_file(self.mpiexec, bin, 'mpiexec')
self._mirror_file(self.mpicc, bin, 'mpicc')
self._mirror_file(self.mpicxx, bin, 'mpicxx')

for f in lib_files:
self._mirror_file(f, os.path.join(shim, 'lib'))

for f in inc_files:
self._mirror_file(f, os.path.join(shim, 'include'))

for f in libexec_files:
self._mirror_file(f, os.path.join(shim, 'libexec'))
# Check if the specified `name` is the same as the current one
try:
cur_name = mpienv.mpienv.config2['DEFAULT']['name']
cur_mpi4py = mpienv.mpienv.config2.getboolean('DEFAULT', 'mpi4py')
if cur_name == name and cur_mpi4py == mpi4py:
return
except KeyError:
pass

env_path = os.environ.get('PATH', '').split(':')
env_ldlib = os.environ.get('LIBRARY_PATH', '').split(':')

# Remove all directory that contains 'mpiexec' from PATH
bin_dir = os.path.join(self.prefix, 'bin')
assert os.path.exists(os.path.join(bin_dir, 'mpiexec'))
if bin_dir in env_path:
env_path.remove(bin_dir)
env_path = [bin_dir] + env_path

# Remove all directory that contains 'mpiexec'
for dir_name in ['lib', 'lib64']:
lib_dir = os.path.join(self.prefix, dir_name)
if os.path.exists(lib_dir):
# Remove if lib_is already a part of LD_LIBRARY_PATH
if lib_dir in env_ldlib:
env_ldlib.remove(lib_dir)
env_ldlib = [lib_dir] + env_ldlib

mpienv.mpienv.config2['DEFAULT']['active'] = name
mpienv.mpienv.config2['DEFAULT']['mpi4py'] = str(mpi4py)
mpienv.mpienv.config_save()

print('export PATH={}'.format(':'.join(env_path)))
print('export LD_LIBRARY_PATH={}'.format(':'.join(env_ldlib)))

env = os.environ.copy()
env['PATH'] = ':'.join(env_path)
env['LD_LIBRARY_PATH'] = ':'.join(env_ldlib)

py = MPI4Py(self._conf, name)
if mpi4py:
if not py.is_installed():
py.install()
py.install(env)
py.use()
else:
# If --mpi4py is not specified, must modify PYTHONPATH
Expand Down
14 changes: 1 addition & 13 deletions mpienv/mpienv_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@
fi
mkdir -p ${MPIENV_VERSIONS_DIR}
mkdir -p ${MPIENV_VERSIONS_DIR}/shims
if [ ! -f $MPIENV_VERSIONS_DIR/shims ]; then
G=$MPIENV_VERSIONS_DIR/version_global
if [ -f $G ]; then
ln -s $(cat $G) $MPIENV_VERSIONS_DIR/shims
fi
fi
export PATH=$MPIENV_VERSIONS_DIR/shims/bin:${PATH:-}
export LD_LIBRARY_PATH=${MPIENV_VERSIONS_DIR}/shims/lib:${MPIENV_VERSIONS_DIR}/shims/lib64:${LD_LIBRARY_PATH:-} # NOQA
function usage() {
echo "Usage: mpienv [command] [options...]"
Expand All @@ -38,8 +27,7 @@
case "$command" in
"use" )
{
eval $(env PYTHONPATH=$MPIENV_ROOT:${PYTHONPATH:-} \
$PYTHON -m mpienv.command.use $*)
eval "$(env PYTHONPATH=$MPIENV_ROOT:${PYTHONPATH:-} $PYTHON -m mpienv.command.use $*)" # NOQA
if [ -z "${BASH_VERSION:-}" -a ! -z "${ZSH_VERSION:-}" ]; then
rehash
fi
Expand Down
Loading

0 comments on commit 277e79c

Please sign in to comment.