GithubHelp home page GithubHelp logo

mpienv's Introduction

Build Status MIT License

mpienv

MPI environment selector for Pythonisa

Background and motivation

Managing multiple MPI installations is hard. It's even harder if you use MPI through Python.

Environmental setting over SSH (non-interactive sessions)

As often asked on Stack Overflow (such as this question), setting environmental variables on remote hosts are sometimes hard, in particular on Ubuntu platforms.

MPI and mpi4py

When you have multiple MPI installations, it is time-consuming and error-prone situation. To switch the active MPI, it is not enough to modify PATH and LD_LIBRARY_PATH. It is because the mpi4py library binary, namely MPI.so, is linked to the previous MPI installation.

To properly switch the MPI installation, you need to reinstall mpi4py everytime you switch MPI.

$ pip uninstall -y mpi4py
$ pip install mpi4py --no-cache-dir

Mpienv is designed to avoid such issues and provide a smooth workflow to work on multiple Python and MPI combinations.

Installation

First, install mpienv via pip

$ pip install mpienv

How to start

After installing, insert the following line into your .bashrc or any other initialization shell script.

$ eval "$(mpienv-init)"

OK, let's see what mpienv does.

$ mpienv list

# no output

The list command prints a list of MPI instances. As of now, there should be no output from the command because mpienv has no information about your system. Let's find MPI libraries on your system by hitting:

The autodiscover command will traverse the directories of you system and find all installed MPI libraries. The output would look like the following (it would take some time):

$ mpienv autodiscover

$ mpienv autodiscover /usr/local/Cellar

--------------------------------------
Found /usr/local/Cellar/mpich/3.3/bin/mpiexec
Type    : MPICH
Version : 3.3
Path    : /usr/local/Cellar/mpich/3.3

# (...snip...)

The command searches several possible locations on your system. If you have any idea of location where MPIs are installed, you can specify them to save time:

$ mpienv autodiscover path1 path2 ...

After you find MPI installations on your system, you can register them using mpienv add command.

$ mpienv add /opt/local

Let's check if the MPI is added properly:

$ mpienv list

Installed MPIs:

   mpich-3.3a1 -> /opt/local

If you are too lazy to add all the found MPIs manually, you can just use

$ mpienv autodiscover [--add|-a]

This command automatically adds all the MPI installations.

Activating an MPI

Let's assume your mpienv list shows the folloing:

$ mpienv list
Installed MPIs:

   mpich-3.2     -> /Users/keisukefukuda/mpi/mpich-3.2
   mpich-3.3a1   -> /opt/local
 * openmpi-2.1.1 -> /Users/keisukefukuda/mpi/openmpi-2.1.1

The * mark indicates that the MPI openmpi-2.1.1 is active, which means it's on the PATH and LD_LIBRARYPATH environment variables. You can check that openmpi-2.1.1 is active.

$ mpiexec --version
mpiexec (OpenRTE) 2.1.1

Report bugs to http://www.open-mpi.org/community/help/

You can switch the active MPI using use command.

$ mpienv use mpich-3.2
$ mpienv list

Installed MPIs:

 * mpich-3.2     -> /Users/keisukefukuda/mpi/mpich-3.2
   mpich-3.3a1   -> /opt/local
   openmpi-2.1.1 -> /Users/keisukefukuda/mpi/openmpi-2.1.1

$ mpiexec --version
HYDRA build details:
    Version:                                 3.2
    Release Date:                            Wed Nov 11 22:06:48 CST 2015
    CC:                              gcc
    CXX:                             g++
    F77:
    F90:
    Configure options:  
    # (snip)
    Process Manager:                         pmi
    Launchers available:                     ssh rsh fork slurm ll lsf sge manual persist
    Topology libraries available:            hwloc
    Resource management kernels available:   user slurm ll lsf sge pbs cobalt
    Checkpointing libraries available:
    Demux engines available:                 poll select

"mpich-3.2" is now active.

Running MPI applications

To run your MPI application, you need to specify a few options to the mpiexec command.

$ # If you use Open MPI
$ mpienv list

Installed MPIs:

  mvapich2-2.2  -> /usr/local
  openmpi-1.6.5 -> /usr
* openmpi-2.1.1 -> /home/kfukuda/mpi/openmpi-2.1.1

$ mpienv exec -n ${NP} --hostfile ${HOSTFILE} ./your.app
$ # If you use MPICH/MVAPICH
$ mpienv list

Installed MPIs:

* mvapich2-2.2  -> /usr/local
  openmpi-1.6.5 -> /usr
  openmpi-2.1.1 -> /home/kfukuda/mpi/openmpi-2.1.1

$ mpienv exec --genvall -n ${NP} --hostfile ${HOSTFILE} ./your.app

If you are curious about what mpienv exec does, try --dry-run. It shows the command to execute and the content of a generated helper shell script.

$ mpienv exec --dry-run -n 2 hostname
mpienv exec: INFO: tempfile = /tmp/KeisukenoMacBook-Pro.local.50192.20190430150049.mpienv.sh
mpienv exec: INFO: hosts = ['localhost']
/usr/local/Cellar/mpich/3.3/bin/mpiexec -n 2 /tmp/KeisukenoMacBook-Pro.local.50192.20190430150049.mpienv.sh

/tmp/KeisukenoMacBook-Pro.local.50192.20190430150049.mpienv.sh
---
#!/bin/bash

export MPIENV_HOME=/Users/keisukefukuda/.mpienv

export PATH=/usr/local/Cellar/mpich/3.3/bin:/Users/keisukefukuda/.cargo/bin:/Users/keisukefukuda/local/bin:/Users/keisukefukuda/.pyenv/shims:/Users/keisukefukuda/.pyenv/bin:/Users/keisukefukuda/.cargo/bin:/usr/local/bin:/Users/keisukefukuda/lcoal/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/TeX/texbin

export LD_LIBRARY_PATH=/usr/local/Cellar/mpich/3.3/lib:

export PYTHONPATH=/Users/keisukefukuda/.mpienv/versions/pylib/Users_keisukefukuda_.pyenv_versions_3.6.1_bin_python3.6/mpich-3.3:

export MPIENV_MPI_TYPE="MPICH"
export MPIENV_MPI_VERSION="3.3"
export MPIENV_MPI_NAME="mpich-3.3"

hostname
 

Of course, you can use mpiexec as usual.

Using Python together

If you use MPI with Python and want to swtich multiple MPI installations, what annoys you is that mpi4py is tied to a single MPI instance when it is compiled and installed. This means that you have to do

$ pip uninstall mpi4py

$ # switch MPI

$ pip install mpi4py --no-cache

every time you swtich to another MPI.

mpienv supports this use case.

$ mpienv use --mpi4py openmpi-2.1.1

This command installs an mpi4py instance on a specific location using pip's -t option, and set PYTHONPATH environment variable to activate it.

# Now openmpi-2.1.1 is active
$ mpienv use mpich-3.2
$ mpiexec -n 2 python -c "from mpi4py import MPI; print(MPI.COMM_WORLD.Get_rank())"

### Error!

$ mpienv use --mpi4py mpich-3.2
$ mpiexec -n 2 python -c "from mpi4py import MPI; print(MPI.COMM_WORLD.Get_rank())"
0
1

OK, now your mpi4py is properly set up. To run Python script on multiple nodes, you need to pass an additional environment variable PYTHONPATH.

$ # Open MPI
$ mpiexec --prefix /home/kfukuda/mpi/openmpi-2.1.1 -x PYTHONPATH -n ${NP} --hostfile ${HOSTFILE} ./your.app

$ # MPICH/MVAPICH
$ mpiexec --genvall -n ${NP} --hostfile ${HOSTFILE} ./your.app

mpienv's People

Contributors

dtaniwaki avatar k5342 avatar keisukefukuda avatar levelfour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mpienv's Issues

Add `check` command

Add mpienv check command perform configuration check.
Items to be checked would include:

  • mpicc/mpicxx and mpiexec works properly can compile a simple program
  • If the physical node has IB, checks if the MPI installation supports IB.
  • If the physical node has NVIDIA GPU(s), checks if the MPI installation is CUDA-aware.

Code refactoring

  • Separate classes for each MPI instance, so make it easier to support new MPI (vendor MPIs)
  • Remove all MPI-dependent branch
  • Remove get_info() functions and use get_mpi()
  • Rename Manager class to MpiEnv or any better name
  • Resolve all codeclimate issues

add prefix command

When using Open MPI, prefix command would be useful to pass to --prefix argument

Cannot call rmtree on a symbolic link

Traceback (most recent call last):
File "/home/kfukuda/mpienv/bin/use.py", line 22, in
main()
File "/home/kfukuda/mpienv/bin/use.py", line 18, in main
mpienv.use(args.name, mpi4py=args.mpi4py)
File "/home/kfukuda/mpienv/mpienv/init.py", line 300, in use
mpi.use(name, mpi4py=mpi4py)
File "/home/kfukuda/mpienv/mpienv/mpibase.py", line 184, in use
shutil.rmtree(shim)
File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/shutil.py", line 484, in rmtree
onerror(os.path.islink, path, sys.exc_info())
File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/shutil.py", line 482, in rmtree
raise OSError("Cannot call rmtree on a symbolic link")
OSError: Cannot call rmtree on a symbolic link

mpienv add error

When I used mpienv add command to add mpi path by the following command, mpienv output error.

$ mpienv add /usr/bin/
Traceback (most recent call last):
  File "/home/ssuzuki/.mpienv/bin/add.py", line 22, in <module>
    main()
  File "/home/ssuzuki/.mpienv/bin/add.py", line 18, in main
    manager.add(args.path, args.name)
  File "/home/ssuzuki/.mpienv/common.py", line 304, in add
    name = info['default_name']
KeyError: 'default_name'

How can I solve it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.