Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: Ensure compiler check catches permission errors #2340

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/user/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def test(problem, **kwargs):
"DEVITO_MPI is unset. Setting `DEVITO_MPI=basic`..."
% MPI.COMM_WORLD.size)
configuration['mpi'] = 'basic'
except TypeError:
except (TypeError, ModuleNotFoundError):
# MPI not available
pass

Expand Down
8 changes: 3 additions & 5 deletions devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
check_call, run)
import platform
import warnings
import sys
import time

import numpy.ctypeslib as npct
Expand All @@ -18,7 +17,7 @@
IntelDevice, get_nvidia_cc, check_cuda_runtime,
get_m1_llvm_path)
from devito.exceptions import CompilationError
from devito.logger import debug, warning, error
from devito.logger import debug, warning
from devito.parameters import configuration
from devito.tools import (as_list, change_directory, filter_ordered,
memoized_func, make_tempdir)
Expand All @@ -42,12 +41,11 @@ def sniff_compiler_version(cc, allow_fail=False):
return Version("0")
except UnicodeDecodeError:
return Version("0")
except FileNotFoundError:
except OSError:
if allow_fail:
return Version("0")
else:
error("The `%s` compiler isn't available on this system" % cc)
sys.exit(1)
raise RuntimeError("The `%s` compiler isn't available on this system" % cc)
mloubout marked this conversation as resolved.
Show resolved Hide resolved

if ver.startswith("gcc"):
compiler = "gcc"
Expand Down
8 changes: 7 additions & 1 deletion devito/mpi/distributed.py
gbruer15 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ def cleanup():
if init_by_devito and MPI.Is_initialized() and not MPI.Is_finalized():
MPI.Finalize()
atexit.register(cleanup)
except ImportError:
gbruer15 marked this conversation as resolved.
Show resolved Hide resolved
except ImportError as e:
# Dummy fallback in case mpi4py/MPI aren't available
class NoneMetaclass(type):
def __getattr__(self, name):
return None

class MPI(object, metaclass=NoneMetaclass):
init_error = e

@classmethod
def Init(cls):
raise cls.init_error

@classmethod
def Is_initialized(cls):
return False
Expand Down
12 changes: 12 additions & 0 deletions tests/test_arch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from devito.arch.compiler import sniff_compiler_version


@pytest.mark.parametrize("cc", [
"doesn'texist",
"/root/doesn'texist",
])
def test_sniff_compiler_version(cc):
with pytest.raises(RuntimeError, match=cc):
sniff_compiler_version(cc)
Loading