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

Commit

Permalink
test passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
keisukefukuda committed Mar 5, 2019
1 parent a32ae0d commit 57e091b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 89 deletions.
2 changes: 1 addition & 1 deletion mpienv/mpienv_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +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
2 changes: 1 addition & 1 deletion mpienv/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
from subprocess import check_call
from subprocess import check_output
from subprocess import check_output # NOQA
from subprocess import PIPE
from subprocess import Popen
import sys
Expand Down
4 changes: 0 additions & 4 deletions mpienv/py.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,13 @@ def use(self):

def clear(self):
pypath = os.environ.get('PYTHONAPTH', "")
sys.stderr.write("** PYTHONPATH={}\n".format(os.environ.get('PYTHONPATH', '')))
sys.stderr.write("** pylib_dir={}\n".format(self._conf['pylib_dir']))
newpath = ':'.join([p for p in pypath.split(':')
if not p.startswith(self._conf['pylib_dir'])])

if newpath == "":
print("unset PYTHONPATH;")
sys.stderr.write("unset PYTHONPATH\n")
else:
sys.stderr.write("export PYTHONPATH={}\n".format(newpath))
print("export PYTHONPATH={};".format(newpath))

def rm(self):
if os.path.exists(self._pylib_dir):
Expand Down
159 changes: 76 additions & 83 deletions tests/test_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,89 +135,6 @@ EOF
rm -f ${tmpfile}
}

test_mpi4py_clear_pypath() {
assertSuccess mpienv autodiscover -q --add ${MPI_PREFIX}

unset PYTHONPATH
assertNull "${PYTHONPATH:-}"

mpienv use ${MPICH}
assertNull "${PYTHONPATH:-}"

mpienv use --mpi4py ${MPICH}
assertNotNull "PYTHONPATH must be set for ${MPICH}" "${PYTHONPATH:-}"

echo "====================="
python -m mpienv.command.use ${MPICH}
echo "====================="
echo "(1) PYTHONPATH=${PYTHONPATH:-}"
mpienv use ${MPICH}
echo "(2) PYTHONPATH=${PYTHONPATH:-}"
assertNull "PYTHONPATH must be NULL" "${PYTHONPATH:-}"

exit 0
}

test_mpi4py() {
export TMPDIR=/tmp
assertSuccess mpienv autodiscover -q --add ${MPI_PREFIX}

local OUT=$(mktemp)
local SCRIPT=$(mktemp)
cat <<EOF >$SCRIPT
from mpi4py import MPI
import sys
#print(MPI.__file__)
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
ans = comm.gather(rank, root=0)
if rank == 0:
print(''.join([str(s) for s in ans]))
EOF
if ! is_ubuntu1404 ; then
echo "============== ${MPICH} =============="
# Ubuntu 14.04's mpich seems to be broken somehow.
mpienv use ${MPICH}
mpienv use --mpi4py ${MPICH}
mpienv exec -host localhost:2 -n 2 $PYTHON -c "from mpi4py import MPI"
assertTrue "$LINENO: import mpi4py should success" $?

mpienv exec -host localhost:2 -n 2 $PYTHON $SCRIPT >$OUT
assertTrue "$LINENO: success" "$?"
assertEquals "$LINENO: 01" "01" "$(cat $OUT)"

mpienv exec -host localhost:2 -n 3 $PYTHON $SCRIPT >$OUT
assertTrue "$LINENO: success" "$?"
assertEquals "$LINENO: 012" "012" "$(cat $OUT)"
fi

echo "============== ${OMPI} =============="
# test Open MPI
mpienv use --mpi4py ${OMPI}

echo PYTHONPATH=$PYTHONPATH

mpienv exec --oversubscribe -n 2 $PYTHON -c "from mpi4py import MPI"
which mpiexec
$PYTHON -c "from mpi4py import MPI; print(MPI.__file__)"
assertTrue "$LINENO: importing mpi4py from ${OMPI}" "$?"

mpiexec --oversubscribe -n 2 $PYTHON $SCRIPT
mpiexec --oversubscribe -n 2 $PYTHON $SCRIPT >$OUT
# mpienv exec --oversubscribe -n 2 $PYTHON $SCRIPT
# mpienv exec --oversubscribe -n 2 $PYTHON $SCRIPT >$OUT
assertEquals "$LINENO: Gather(NP=2) for ${OMPI}" "01" "$(cat $OUT)"

mpienv exec --oversubscribe -n 4 $PYTHON $SCRIPT >$OUT
assertEquals "$LINENO: Gather(NP=4) for ${OMPI}" "0123" "$(cat $OUT)"

rm -f ${SCRIPT}
rm -f ${OUT}
}

#-----------------------------------------------------------
test_qc() {
autopep8 --exclude pylib --diff -r . --global-config .pep8 | tee check_autopep8
Expand Down Expand Up @@ -391,6 +308,82 @@ EOF
rm -f ${SRC} ${OUT} a.out
}

test_mpi4py_clear_pypath() {
assertSuccess mpienv autodiscover -q --add ${MPI_PREFIX}

unset PYTHONPATH
assertNull "${PYTHONPATH:-}"

mpienv use ${MPICH}
assertNull "${PYTHONPATH:-}"

mpienv use --mpi4py ${MPICH}
assertNotNull "PYTHONPATH must be set for ${MPICH}" "${PYTHONPATH:-}"

mpienv use ${MPICH}
assertNull "PYTHONPATH must be NULL" "${PYTHONPATH:-}"
}

test_mpi4py() {
export TMPDIR=/tmp
assertSuccess mpienv autodiscover -q --add ${MPI_PREFIX}

local OUT=$(mktemp)
local SCRIPT=$(mktemp)
cat <<EOF >$SCRIPT
from mpi4py import MPI
import sys
#print(MPI.__file__)
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
ans = comm.gather(rank, root=0)
if rank == 0:
print(''.join([str(s) for s in ans]))
EOF
if ! is_ubuntu1404 ; then
echo "============== ${MPICH} =============="
# Ubuntu 14.04's mpich seems to be broken somehow.
mpienv use ${MPICH}
mpienv use --mpi4py ${MPICH}
mpienv exec -host localhost:2 -n 2 $PYTHON -c "from mpi4py import MPI"
assertTrue "$LINENO: import mpi4py should success" $?

mpienv exec -host localhost:2 -n 2 $PYTHON $SCRIPT >$OUT
assertTrue "$LINENO: success" "$?"
assertEquals "$LINENO: 01" "01" "$(cat $OUT)"

mpienv exec -host localhost:2 -n 3 $PYTHON $SCRIPT >$OUT
assertTrue "$LINENO: success" "$?"
assertEquals "$LINENO: 012" "012" "$(cat $OUT)"
fi

echo "============== ${OMPI} =============="
# test Open MPI
mpienv use --mpi4py ${OMPI}

echo PYTHONPATH=$PYTHONPATH

mpienv exec --oversubscribe -n 2 $PYTHON -c "from mpi4py import MPI"
which mpiexec
$PYTHON -c "from mpi4py import MPI; print(MPI.__file__)"
assertTrue "$LINENO: importing mpi4py from ${OMPI}" "$?"

mpiexec --oversubscribe -n 2 $PYTHON $SCRIPT
mpiexec --oversubscribe -n 2 $PYTHON $SCRIPT >$OUT
# mpienv exec --oversubscribe -n 2 $PYTHON $SCRIPT
# mpienv exec --oversubscribe -n 2 $PYTHON $SCRIPT >$OUT
assertEquals "$LINENO: Gather(NP=2) for ${OMPI}" "01" "$(cat $OUT)"

mpienv exec --oversubscribe -n 4 $PYTHON $SCRIPT >$OUT
assertEquals "$LINENO: Gather(NP=4) for ${OMPI}" "0123" "$(cat $OUT)"

rm -f ${SCRIPT}
rm -f ${OUT}
}


test_reg_issue10(){
# Regression test for #10
Expand Down

0 comments on commit 57e091b

Please sign in to comment.