Commit ea36db75 authored by Kumar, Shikhar's avatar Kumar, Shikhar
Browse files

Merge branch 'mpi_config' into 'development'

Adding MPI exec specification

See merge request nstauff/PyGriffin!10
parents dcec3aa1 a1f8be66
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -26,7 +26,9 @@ the user and the user's compute environment.
The `.pygriffin.rc` file uses a configuration format commmonly adopted
by Python modules for customization that is supported by a a parser in
the Python standard library. Specifics on this format can be found
[here](https://docs.fileformat.com/system/ini/).
[here](https://docs.fileformat.com/system/ini/). This file can be located in the base of the PyGriffin repository or in the
user's home directory. A configuration file in the user's home directory will override one found in the repository. When installing PyGriffin using pip, a `.pygriffin.rc` file in the
user's home directory will be necessary.

PyGriffin expects to find an `exec` section in this file containing
the location of the Griffin executable and (optionally) the ISOXML
@@ -51,6 +53,18 @@ print(pyg_config.griffin_exec)
This file can be updated to change the executables used by
PyGriffin the next time the package is imported.

For Griffin execution with MPI, an executable can be specified by
adding a `mpi` entry to the `.pygriffin.rc` file in the `exec` block
as an alternative to providing the executable in the `PATH`
environment variable.

```
[exec]
griffin = /home/griffin_project/griffin-opt
isoxml = /home/griffin_project/isoxml/isoxml-opt
mpi = /path/to/my/mpiexec
```

## Installing

PyGriffin can be installed by using pip (`pip install .` from the repository's
+36 −2
Original line number Diff line number Diff line
@@ -25,9 +25,18 @@ class PyGriffinConfig:
    """

    __MOD_PATH = Path(__file__).parent.absolute()

    if Path(os.path.expanduser('~/.pygriffin.rc')).exists():
        _RC_FILE = Path(os.path.expanduser('~')) / '.pygriffin.rc'
    elif Path(__MOD_PATH.parent / '.pygriffin.rc').exists():
        _RC_FILE = __MOD_PATH.parent / '.pygriffin.rc'
    else:
        raise RuntimeError('PyGriffin config file (.pygriffin.rc) could not be found.')

    def __init__(self, griffin_exec=None, isoxml_exec=None):
    def __init__(self,
                 griffin_exec=None,
                 isoxml_exec=None,
                 mpi_exec=None):

        # always read the config file,
        # even if we don't use it
@@ -73,6 +82,18 @@ class PyGriffinConfig:

        self.detect_mpi()

        # check for a user-defined MPI executable path
        # in the config file

        if self.mpi_enabled:
            user_mpi_exec = self.get_path('exec', 'mpi')
            if user_mpi_exec is not None:
                self.mpi_exec = user_mpi_exec
            elif mpi_exec is not None:
                self.mpi_exec = mpi_exec
            else:
                self._mpi_exec = 'mpiexec'

    def get(self, *args, **kwargs):
        """
        Attempts to get a configuration option from the .rc file.
@@ -90,6 +111,9 @@ class PyGriffinConfig:
        Relative paths are assumed to be relative to the configuration file.
        """
        val = self.get(*args, **kwargs)
        if val is None:
            return val
        # determine path
        path = Path(val)
        if not path.is_absolute():
            path = self._RC_FILE.parent / path
@@ -137,6 +161,16 @@ class PyGriffinConfig:
        cv.check_type('MPI enabled', val, bool)
        self._mpi_enabled = val

    @property
    def mpi_exec(self):
        return self._mpi_exec

    @mpi_exec.setter
    def mpi_exec(self, val):
        self._mpi_exec = cv.check_file('MPI executable',
                                       val,
                                       must_exist=True)

    @griffin_exec.setter
    def griffin_exec(self, val):
        self._griffin_exec = cv.check_file('Griffin executable path',
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ class PyGriffin:

        if self.n_procs > 1:
            if self.config.mpi_enabled:
                cmd += ['mpirun', '-n', str(self.n_procs)]
                cmd += [self.mpi_exec, '-n', str(self.n_procs)]
            else:
                msg = ("MPI is not enabled for this Griffin executable. "
                       "The n_procs argument will be ignored.")
+2 −1
Original line number Diff line number Diff line
[exec]
griffin = griffin_mock
isoxml = isoxml_mock
mpi = mpi_mock
 No newline at end of file

tests/mpi_mock

0 → 100644
+0 −0

Empty file added.

Loading