|
1 | | -from __future__ import absolute_import |
2 | | - |
3 | 1 | import pytest |
4 | 2 |
|
5 | 3 | import os |
|
17 | 15 | from devito.ir.iet import Iteration |
18 | 16 | from devito.tools import as_tuple |
19 | 17 |
|
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="") |
27 | 49 |
|
28 | 50 |
|
29 | 51 | # Testing dimensions for space and time |
@@ -279,19 +301,18 @@ def wrapper(*args, **kwargs): |
279 | 301 | return dec |
280 | 302 |
|
281 | 303 |
|
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 | | - |
290 | 304 | def parallel(item): |
291 | 305 | """Run a test in parallel. |
292 | 306 |
|
293 | 307 | :parameter item: The test item to run. |
294 | 308 | """ |
| 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 | + |
295 | 316 | marker = item.get_closest_marker("parallel") |
296 | 317 | nprocs = as_tuple(marker.kwargs.get("nprocs", 2)) |
297 | 318 | for i in nprocs: |
|
0 commit comments