示例#1
0
文件: op2.py 项目: joshcc3/PyOP2
def init(**kwargs):
    """Initialise OP2: select the backend and potentially other configuration
    options.

    :arg backend: Set the hardware-specific backend. Current choices
     are ``"sequential"``, ``"openmp"``, ``"opencl"`` and ``"cuda"``.
    :arg debug: The level of debugging output.
    :arg comm: The MPI communicator to use for parallel communication,
               defaults to `MPI_COMM_WORLD`

    .. note::
       Calling ``init`` again with a different backend raises an exception.
       Changing the backend is not possible. Calling ``init`` again with the
       same backend or not specifying a backend will update the configuration.
       Calling ``init`` after ``exit`` has been called is an error and will
       raise an exception.
    """
    backend = backends.get_backend()
    if backend == 'pyop2.finalised':
        raise RuntimeError("Calling init() after exit() is illegal.")
    if 'backend' in kwargs and backend not in ('pyop2.void', 'pyop2.' + kwargs['backend']):
        raise RuntimeError("Changing the backend is not possible once set.")
    cfg.configure(**kwargs)
    set_log_level(cfg['log_level'])
    if backend == 'pyop2.void':
        backends.set_backend(cfg.backend)
        backends._BackendSelector._backend._setup()
        if 'comm' in kwargs:
            backends._BackendSelector._backend.MPI.comm = kwargs['comm']
        global MPI
        MPI = backends._BackendSelector._backend.MPI  # noqa: backend override
示例#2
0
文件: op2.py 项目: eccstartup/PyOP2
def init(**kwargs):
    """Initialise PyOP2: select the backend and potentially other configuration
    options.

    :arg backend:   Set the hardware-specific backend. Current choices are
                    ``"sequential"``, ``"openmp"``, ``"opencl"``, ``"cuda"``.
    :arg debug:     The level of debugging output.
    :arg comm:      The MPI communicator to use for parallel communication,
                    defaults to `MPI_COMM_WORLD`
    :arg log_level: The log level. Options: DEBUG, INFO, WARNING, ERROR, CRITICAL

    For debugging purposes, `init` accepts all keyword arguments
    accepted by the PyOP2 :class:`Configuration` object, see
    :meth:`Configuration.__init__` for details of further accepted
    options.

    .. note::
       Calling ``init`` again with a different backend raises an exception.
       Changing the backend is not possible. Calling ``init`` again with the
       same backend or not specifying a backend will update the configuration.
       Calling ``init`` after ``exit`` has been called is an error and will
       raise an exception.
    """
    backend = backends.get_backend()
    if backend == 'pyop2.finalised':
        raise RuntimeError("Calling init() after exit() is illegal.")

    if backend != 'pyop2.void' and \
            "backend" in kwargs and \
            backend != "pyop2.%s" % kwargs["backend"]:
        raise RuntimeError("Calling init() for a different backend is illegal.")

    configuration.reconfigure(**kwargs)

    set_log_level(configuration['log_level'])
    if backend == 'pyop2.void':
        try:
            backends.set_backend(configuration["backend"])
        except:
            configuration.reset()
            raise

        backends._BackendSelector._backend._setup()
        if 'comm' in kwargs:
            backends._BackendSelector._backend.MPI.comm = kwargs['comm']
        global MPI
        MPI = backends._BackendSelector._backend.MPI  # noqa: backend override

    init_coffee(configuration['simd_isa'], configuration['compiler'],
                configuration['blas'])