Skip to content

Commit 53bf802

Browse files
Merge pull request #692 from opesci/no-mpi
devito without mpi
2 parents d7af6fc + e7be242 commit 53bf802

32 files changed

Lines changed: 204 additions & 173 deletions

‎.travis.yml‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ matrix:
1919
packages:
2020
- gcc-4.9
2121
- g++-4.9
22-
env: DEVITO_ARCH=gcc-4.9 DEVITO_OPENMP=0 INSTALL_TYPE=pip_setup RUN_EXAMPLES=False
22+
env: DEVITO_ARCH=gcc-4.9 DEVITO_OPENMP=0 INSTALL_TYPE=pip_setup RUN_EXAMPLES=False MPI_INSTALL=1
2323
- os: linux
2424
python: "3.6"
2525
addons:
@@ -29,7 +29,7 @@ matrix:
2929
packages:
3030
- gcc-5
3131
- g++-5
32-
env: DEVITO_ARCH=gcc-5 DEVITO_OPENMP=0 RUN_EXAMPLES=True INSTALL_TYPE=conda
32+
env: DEVITO_ARCH=gcc-5 DEVITO_OPENMP=0 RUN_EXAMPLES=False INSTALL_TYPE=conda MPI_INSTALL=0
3333
- os: linux
3434
python: "3.6"
3535
addons:
@@ -39,7 +39,7 @@ matrix:
3939
packages:
4040
- gcc-4.9
4141
- g++-4.9
42-
env: DEVITO_ARCH=gcc-4.9 DEVITO_OPENMP=1 OMP_NUM_THREADS=2 RUN_EXAMPLES=True INSTALL_TYPE=conda
42+
env: DEVITO_ARCH=gcc-4.9 DEVITO_OPENMP=1 OMP_NUM_THREADS=2 RUN_EXAMPLES=True INSTALL_TYPE=conda MPI_INSTALL=1
4343
- os: linux
4444
python: "3.6"
4545
addons:
@@ -49,7 +49,7 @@ matrix:
4949
packages:
5050
- gcc-7
5151
- g++-7
52-
env: DEVITO_ARCH=gcc-7 DEVITO_OPENMP=0 DEVITO_BACKEND=yask YC_CXX=g++-7 INSTALL_TYPE=conda RUN_EXAMPLES=False
52+
env: DEVITO_ARCH=gcc-7 DEVITO_OPENMP=0 DEVITO_BACKEND=yask YC_CXX=g++-7 INSTALL_TYPE=conda RUN_EXAMPLES=False MPI_INSTALL=1
5353
- os: linux
5454
python: "3.6"
5555
addons:
@@ -59,7 +59,7 @@ matrix:
5959
packages:
6060
- gcc-7
6161
- g++-7
62-
env: DEVITO_ARCH=gcc-7 DEVITO_OPENMP=0 DEVITO_BACKEND=ops YC_CXX=g++-7 INSTALL_TYPE=conda RUN_EXAMPLES=False
62+
env: DEVITO_ARCH=gcc-7 DEVITO_OPENMP=0 DEVITO_BACKEND=ops YC_CXX=g++-7 INSTALL_TYPE=conda RUN_EXAMPLES=False MPI_INSTALL=0
6363
allow_failures:
6464
- os: linux
6565
python: "2.7"
@@ -87,7 +87,9 @@ before_install:
8787
- conda update -q conda
8888
# Useful for debugging any issues with conda
8989
- conda info -a
90-
- sudo apt-get install -y -q mpich libmpich-dev
90+
- if [[ "$MPI_INSTALL" == '1' ]]; then
91+
sudo apt-get install -y -q mpich libmpich-dev;
92+
fi
9193

9294
install:
9395
# Install devito with conda
@@ -97,8 +99,13 @@ install:
9799
pip install -e .;
98100
conda list;
99101
fi
102+
- if [[ "$MPI_INSTALL" == '1' ]]; then
103+
pip install -r requirements-optional.txt;
104+
fi
105+
100106
# Install devito with pip
101107
- if [[ $INSTALL_TYPE == 'pip_setup' ]]; then python setup.py install; fi
108+
- if [[ $MPI_INSTALL == '1' ]]; then pip install -e .[extras]; fi
102109

103110
before_script:
104111
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

‎Jenkinsfile‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pipeline {
1919
environment {
2020
HOME="${WORKSPACE}"
2121
DEVITO_OPENMP=0
22+
INSTALL_MPI=1
2223
PYTHONPATH="${WORKSPACE}/lib/python3.6/site-packages/"
2324
}
2425
steps {
@@ -27,13 +28,14 @@ pipeline {
2728
runPipTests()
2829
}
2930
}
30-
stage('Build and test gcc-4.9 OpenMP container') {
31+
stage('Build and test gcc-4.9 OpenMP container no MPI') {
3132
agent { dockerfile { label 'azure-linux-8core'
3233
filename 'Dockerfile.jenkins'
3334
additionalBuildArgs "--build-arg gccvers=4.9" } }
3435
environment {
3536
HOME="${WORKSPACE}"
3637
DEVITO_OPENMP=1
38+
INSTALL_MPI=0
3739
OMP_NUM_THREADS=2
3840
}
3941
steps {
@@ -52,10 +54,12 @@ pipeline {
5254
environment {
5355
HOME="${WORKSPACE}"
5456
DEVITO_OPENMP=0
57+
INSTALL_MPI=1
5558
}
5659
steps {
5760
cleanWorkspace()
5861
condaInstallDevito()
62+
condaInstallMPI()
5963
runCondaTests()
6064
runExamples()
6165
runCodecov()
@@ -70,11 +74,13 @@ pipeline {
7074
HOME="${WORKSPACE}"
7175
DEVITO_BACKEND="yask"
7276
DEVITO_OPENMP="0"
77+
INSTALL_MPI="1"
7378
YC_CXX="g++-7"
7479
}
7580
steps {
7681
cleanWorkspace()
7782
condaInstallDevito()
83+
condaInstallMPI()
7884
installYask()
7985
runCondaTests()
8086
runCodecov()
@@ -104,10 +110,12 @@ pipeline {
104110
environment {
105111
HOME="${WORKSPACE}"
106112
DEVITO_OPENMP=0
113+
INSTALL_MPI=1
107114
}
108115
steps {
109116
cleanWorkspace()
110117
condaInstallDevito()
118+
condaInstallMPI()
111119
runCondaTests()
112120
runExamples()
113121
runCodecov()
@@ -130,6 +138,10 @@ def condaInstallDevito () {
130138
sh 'source activate devito ; flake8 --exclude .conda,.git --builtins=ArgumentError .'
131139
}
132140

141+
def condaInstallMPI () {
142+
sh 'source activate devito ; pip install -r requirements-optional.txt'
143+
}
144+
133145
def pipInstallDevito () {
134146
sh "mkdir -p ${WORKSPACE}/lib/python3.6/site-packages/"
135147
sh "python setup.py install --prefix=${WORKSPACE}"

‎devito/__init__.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import os
42
from subprocess import PIPE, Popen
53
from collections import namedtuple

‎devito/mpi/distributed.py‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,26 @@
1919
# Do not prematurely initialize MPI
2020
# This allows launching a Devito program from within another Python program
2121
# that has *already* initialized MPI
22-
import mpi4py
23-
mpi4py.rc(initialize=False, finalize=False)
24-
from mpi4py import MPI # noqa
22+
try:
23+
import mpi4py
24+
mpi4py.rc(initialize=False, finalize=False)
25+
from mpi4py import MPI # noqa
26+
except ImportError:
27+
# Dummy fallback in case mpi4py/MPI aren't available
28+
class MPI(object):
29+
COMM_NULL = None
30+
31+
@classmethod
32+
def Is_initialized(cls):
33+
return False
34+
35+
def _sizeof(comm):
36+
return None
37+
38+
@property
39+
def Comm(self):
40+
return None
41+
2542

2643
__all__ = ['Distributor', 'SparseDistributor', 'MPI']
2744

‎environment.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ dependencies:
88
- sympy==1.2
99
- cgen
1010
- scipy
11-
- mpi4py
1211
- matplotlib
1312
- pytest
1413
- flake8>=2.1.0

‎requirements-optional.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mpi4py
2+
matplotlib

‎requirements.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
numpy==1.14
22
sympy>=1.2
33
scipy
4-
mpi4py
5-
matplotlib
64
pytest-runner
75
flake8>=2.1.0
86
jedi

‎setup.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
with open('requirements.txt') as f:
66
required = f.read().splitlines()
77

8+
with open('requirements-optional.txt') as f:
9+
optionals = f.read().splitlines()
10+
811
reqs = []
912
links = []
1013
for ir in required:
@@ -14,6 +17,15 @@
1417
else:
1518
reqs += [ir]
1619

20+
opt_reqs = []
21+
opt_links = []
22+
for ir in optionals:
23+
if ir[0:3] == 'git':
24+
opt_links += [ir + '#egg=' + ir.split('/')[-1] + '-0']
25+
opt_reqs += [ir.split('/')[-1]]
26+
else:
27+
opt_reqs += [ir]
28+
1729
setup(name='devito',
1830
version=versioneer.get_version(),
1931
cmdclass=versioneer.get_cmdclass(),
@@ -25,11 +37,12 @@
2537
equations defined in SymPy to create and execute highly
2638
optimised Finite Difference kernels on multiple computer
2739
platforms.""",
28-
url='http://www.opesci.org/devito',
40+
url='http://www.devitoproject.org',
2941
author="Imperial College London",
3042
author_email='opesci@imperial.ac.uk',
3143
license='MIT',
3244
packages=find_packages(exclude=['docs', 'tests', 'examples']),
3345
install_requires=reqs,
46+
extras_require={'extras': opt_reqs},
3447
dependency_links=links,
3548
test_suite='tests')

‎tests/conftest.py‎

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import pytest
42

53
import os
@@ -17,13 +15,37 @@
1715
from devito.ir.iet import Iteration
1816
from devito.tools import as_tuple
1917

20-
21-
def skipif_backend(backends):
22-
conditions = []
23-
for b in backends:
24-
conditions.append(b == configuration['backend'])
25-
return pytest.mark.skipif(any(conditions),
26-
reason="{} testing is currently restricted".format(b))
18+
try:
19+
from mpi4py import MPI # noqa
20+
except ImportError:
21+
MPI = None
22+
23+
24+
def skipif(items):
25+
items = as_tuple(items)
26+
# Sanity check
27+
accepted = set(configuration._accepted['backend'])
28+
accepted.update({'no%s' % i for i in configuration._accepted['backend']})
29+
accepted.update({'nompi'})
30+
unknown = sorted(set(items) - accepted)
31+
if unknown:
32+
raise ValueError("Illegal skipif argument(s) `%s`" % unknown)
33+
for i in items:
34+
# Skip if no MPI
35+
if i == 'nompi':
36+
if MPI is None:
37+
return pytest.mark.skipif(True, reason="mpi4py/MPI not installed")
38+
continue
39+
# Skip if an unsupported backend
40+
if i == configuration['backend']:
41+
return pytest.mark.skipif(True, reason="`%s` backend unsupported" % i)
42+
try:
43+
_, noi = i.split('no')
44+
if noi != configuration['backend']:
45+
return pytest.mark.skipif(True, reason="`%s` backend unsupported" % i)
46+
except ValueError:
47+
pass
48+
return pytest.mark.skipif(False, reason="")
2749

2850

2951
# Testing dimensions for space and time
@@ -279,19 +301,18 @@ def wrapper(*args, **kwargs):
279301
return dec
280302

281303

282-
# Support to run MPI tests
283-
# This is partly extracted from:
284-
# `https://github.com/firedrakeproject/firedrake/blob/master/tests/conftest.py`
285-
286-
mpi_exec = 'mpiexec'
287-
mpi_distro = sniff_mpi_distro(mpi_exec)
288-
289-
290304
def parallel(item):
291305
"""Run a test in parallel.
292306
293307
:parameter item: The test item to run.
294308
"""
309+
# Support to run MPI tests
310+
# This is partly extracted from:
311+
# `https://github.com/firedrakeproject/firedrake/blob/master/tests/conftest.py`
312+
313+
mpi_exec = 'mpiexec'
314+
mpi_distro = sniff_mpi_distro(mpi_exec)
315+
295316
marker = item.get_closest_marker("parallel")
296317
nprocs = as_tuple(marker.kwargs.get("nprocs", 2))
297318
for i in nprocs:

‎tests/test_adjoint.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import numpy as np
22
import pytest
33
from numpy import linalg
4-
from conftest import unit_box, points
5-
from devito import clear_cache, Operator, configuration
4+
5+
from conftest import unit_box, points, skipif
6+
from devito import clear_cache, Operator
67
from devito.logger import info
78
from examples.seismic import demo_model, Receiver
89
from examples.seismic.acoustic import acoustic_setup
910

10-
pytestmark = pytest.mark.skipif(configuration['backend'] == 'yask' or
11-
configuration['backend'] == 'ops',
12-
reason="testing is currently restricted")
11+
pytestmark = skipif(['yask', 'ops'])
1312

1413
presets = {
1514
'constant': {'preset': 'constant-isotropic'},

0 commit comments

Comments
 (0)