def __init__(self, name, function, halos): self._function = function self._halos = halos super(MPIMsg, self).__init__(name, 'msg', self.fields) # Required for buffer allocation/deallocation before/after jumping/returning # to/from C-land self._allocator = default_allocator() self._memfree_args = []
def __init__(self, name, target, halos, language=None): self._target = target self._halos = halos self._language = language super().__init__(name, 'msg', self.fields) # Required for buffer allocation/deallocation before/after jumping/returning # to/from C-land self._allocator = default_allocator(language) self._memfree_args = []
def __init__(self, name, function, halos, fields=None): self._function = function self._halos = halos fields = (fields or []) + [ (MPIMsg._C_field_bufs, c_void_p), (MPIMsg._C_field_bufg, c_void_p), (MPIMsg._C_field_sizes, POINTER(c_int)), (MPIMsg._C_field_rrecv, MPIMsg.c_mpirequest_p), (MPIMsg._C_field_rsend, MPIMsg.c_mpirequest_p), ] super(MPIMsg, self).__init__(name, 'msg', fields) # Required for buffer allocation/deallocation before/after jumping/returning # to/from C-land self._allocator = default_allocator() self._memfree_args = []
def __init__(self, *args, **kwargs): if not self._cached(): super(DiscreteFunction, self).__init__(*args, **kwargs) # There may or may not be a `Grid` attached to the DiscreteFunction self._grid = kwargs.get('grid') # A `Distributor` to handle domain decomposition (only relevant for MPI) self._distributor = self.__distributor_setup__(**kwargs) # Staggering metadata self._staggered = self.__staggered_setup__(**kwargs) # Symbolic (finite difference) coefficients self._coefficients = kwargs.get('coefficients', 'standard') if self._coefficients not in ('standard', 'symbolic'): raise ValueError("coefficients must be `standard` or `symbolic`") # Data-related properties and data initialization self._data = None self._first_touch = kwargs.get('first_touch', configuration['first-touch']) self._allocator = kwargs.get('allocator', default_allocator()) initializer = kwargs.get('initializer') if initializer is None or callable(initializer): # Initialization postponed until the first access to .data self._initializer = initializer elif isinstance(initializer, (np.ndarray, list, tuple)): # Allocate memory and initialize it. Note that we do *not* hold # a reference to the user-provided buffer self._initializer = None if len(initializer) > 0: self.data_with_halo[:] = initializer else: # This is a corner case -- we might get here, for example, when # running with MPI and some processes get 0-size arrays after # domain decomposition. We touch the data anyway to avoid the # case ``self._data is None`` self.data else: raise ValueError("`initializer` must be callable or buffer, not %s" % type(initializer))
def _data_alignment(self): """ The base virtual address of the data carried by the object is a multiple of the alignment. """ return default_allocator().guaranteed_alignment
def parse_kwargs(**kwargs): """ Parse keyword arguments provided to an Operator. """ # `dse` -- deprecated, dropped dse = kwargs.pop("dse", None) if dse is not None: warning( "The `dse` argument is deprecated. " "The optimization level is now controlled via the `opt` argument") # `dle` -- deprecated, replaced by `opt` if 'dle' in kwargs: warning( "The `dle` argument is deprecated. " "The optimization level is now controlled via the `opt` argument") dle = kwargs.pop('dle') if 'opt' in kwargs: warning( "Both `dle` and `opt` were passed; ignoring `dle` argument") opt = kwargs.pop('opt') else: warning("Setting `opt=%s`" % str(dle)) opt = dle elif 'opt' in kwargs: opt = kwargs.pop('opt') else: opt = configuration['opt'] if not opt or isinstance(opt, str): mode, options = opt, {} elif isinstance(opt, tuple): if len(opt) == 0: mode, options = 'noop', {} elif isinstance(opt[-1], dict): if len(opt) == 2: mode, options = opt else: mode, options = tuple(flatten(i.split(',') for i in opt[:-1])), opt[-1] else: mode, options = tuple(flatten(i.split(',') for i in opt)), {} else: raise InvalidOperator("Illegal `opt=%s`" % str(opt)) # `opt`, deprecated kwargs kwopenmp = kwargs.get('openmp', options.get('openmp')) if kwopenmp is None: openmp = kwargs.get('language', configuration['language']) == 'openmp' else: openmp = kwopenmp # `opt`, options options = dict(options) options.setdefault('openmp', openmp) options.setdefault('mpi', configuration['mpi']) for k, v in configuration['opt-options'].items(): options.setdefault(k, v) # Handle deprecations deprecated_options = ('cire-mincost-inv', 'cire-mincost-sops', 'cire-maxalias') for i in deprecated_options: try: options.pop(i) warning("Ignoring deprecated optimization option `%s`" % i) except KeyError: pass kwargs['options'] = options # `opt`, mode if mode is None: mode = 'noop' kwargs['mode'] = mode # `platform` platform = kwargs.get('platform') if platform is not None: if not isinstance(platform, str): raise ValueError("Argument `platform` should be a `str`") if platform not in configuration._accepted['platform']: raise InvalidOperator("Illegal `platform=%s`" % str(platform)) kwargs['platform'] = platform_registry[platform]() else: kwargs['platform'] = configuration['platform'] # `language` language = kwargs.get('language') if language is not None: if not isinstance(language, str): raise ValueError("Argument `language` should be a `str`") if language not in configuration._accepted['language']: raise InvalidOperator("Illegal `language=%s`" % str(language)) kwargs['language'] = language elif kwopenmp is not None: # Handle deprecated `openmp` kwarg for backward compatibility kwargs['language'] = 'openmp' if openmp else 'C' else: kwargs['language'] = configuration['language'] # `compiler` compiler = kwargs.get('compiler') if compiler is not None: if not isinstance(compiler, str): raise ValueError("Argument `compiler` should be a `str`") if compiler not in configuration._accepted['compiler']: raise InvalidOperator("Illegal `compiler=%s`" % str(compiler)) kwargs['compiler'] = compiler_registry[compiler]( platform=kwargs['platform'], language=kwargs['language']) elif any([platform, language]): kwargs['compiler'] =\ configuration['compiler'].__new_with__(platform=kwargs['platform'], language=kwargs['language']) else: kwargs['compiler'] = configuration['compiler'].__new_with__() # `allocator` kwargs['allocator'] = default_allocator( '%s.%s' % (kwargs['compiler'].__class__.__name__, kwargs['language'])) return kwargs