:py:mod:`bempp.api.utils.pool` ============================== .. py:module:: bempp.api.utils.pool .. autoapi-nested-parse:: Routines to administrate a process pool. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: bempp.api.utils.pool.Pool Functions ~~~~~~~~~ .. autoapisummary:: bempp.api.utils.pool.worker bempp.api.utils.pool.as_array bempp.api.utils.pool.to_buffer bempp.api.utils.pool.from_buffer bempp.api.utils.pool._raise_if_not_worker bempp.api.utils.pool.number_of_workers bempp.api.utils.pool.insert_data bempp.api.utils.pool.is_initialised bempp.api.utils.pool.clear_data bempp.api.utils.pool.get_data bempp.api.utils.pool.get_id bempp.api.utils.pool.remove_key bempp.api.utils.pool.has_key bempp.api.utils.pool.is_worker bempp.api.utils.pool.create_device_pool bempp.api.utils.pool.create_pool bempp.api.utils.pool.nworkers bempp.api.utils.pool.map bempp.api.utils.pool.starmap bempp.api.utils.pool.execute bempp.api.utils.pool._assign_ids bempp.api.utils.pool.shutdown bempp.api.utils.pool._execute_function_without_arguments bempp.api.utils.pool._remove_key_worker bempp.api.utils.pool._init_device_worker bempp.api.utils.pool._clear_data_worker Attributes ~~~~~~~~~~ .. autoapisummary:: bempp.api.utils.pool._DATA bempp.api.utils.pool._MY_ID bempp.api.utils.pool._USE_THREADS bempp.api.utils.pool._POOL bempp.api.utils.pool._NWORKERS bempp.api.utils.pool._IN_WORKER bempp.api.utils.pool._BUFFER .. py:data:: _DATA .. py:data:: _MY_ID .. py:data:: _USE_THREADS .. py:data:: _POOL .. py:data:: _NWORKERS .. py:data:: _IN_WORKER :value: False .. py:data:: _BUFFER .. py:function:: worker(in_queue, out_queue, worker_id, nworkers, buf, log, log_level) Definition of a worker. .. py:function:: as_array(dtype, offset, shape) Return part of the buffer as array. Parameters ---------- dtype : Numpy dtype object The type of the array offset : int Start index in buffer nitems : int Number of items of type dtype .. py:function:: to_buffer(*args) Save a number of numpy arrays to a buffer. .. py:function:: from_buffer(arrays) Retrieve arrays from buffer. arrays is a list of tuples [(dtype1, shape1), (dtype2, shape2), ...], where dtype is the type of the array and shape is a shape tuple. .. py:class:: Pool(nworkers, buffer_size=100, log=False, log_level='info') Bases: :py:obj:`object` A simple pool. This pool is different from the multiprocessing pool in that map operations are guaranteed to execute on all processes, and we can directly target individual processes. .. py:property:: number_of_workers Return number of workers. .. py:method:: _map_impl(fun, args, options) Map implementation. .. py:method:: map(fun, args=None) Map function onto workers. .. py:method:: starmap(fun, args) Map function onto workers. .. py:method:: shutdown() Shutdown all workers. .. py:function:: _raise_if_not_worker(name) Raise exception if not in worker. .. py:function:: number_of_workers() Return number of workers. .. py:function:: insert_data(key, data) Insert data. .. py:function:: is_initialised() Return true if pool is initialised. .. py:function:: clear_data() Clear the data in all workers. .. py:function:: get_data(key) Return data. .. py:function:: get_id() Return my id. .. py:function:: remove_key(key) Remove data from pool. .. py:function:: has_key(key) Return if key exists in pool data. .. py:function:: is_worker() Return true if called from worker process. .. py:function:: create_device_pool(identifier, buffer_size=100, log=False, log_level='info', max_workers=-1, precision=None) Create a pool based on a given platform identifer. identifier : string A unique identifier that is part of the platform name. Used to find the correct platform. buffer_size : int Shared memory buffer size in MB log : Boolean Set to True to log workers. log_level : String Logging level. One of 'debug', 'info', 'warning', 'error', 'critical' max_workers : int Maximum number of workers. If max_workers=-1 (default) the maximum number of workers is identical to the number of devices in the pool. precision : string or None Precision for the devices in the pool. If precision is None use single precision for GPU devices and double precision for CPU devices. If precision is 'single' or 'double' use the corresponding mode for the pool. .. py:function:: create_pool(nworkers, buffer_size=100, log=False, log_level='info') Create a pool. .. py:function:: nworkers() Get number of workers. .. py:function:: map(fun, args) Corresponds to multiprocessing map. .. py:function:: starmap(fun, args) Corresponds to multiprocessing map. .. py:function:: execute(fun, *args) Execute function with the same arguments on all workers. .. py:function:: _assign_ids(nworkers) Assign pool ids. .. py:function:: shutdown() Shutdown the pool. .. py:function:: _execute_function_without_arguments(fun) Execute function without arguments. .. py:function:: _remove_key_worker(key) .. py:function:: _init_device_worker(identifier, precision) Worker to initialise device. .. py:function:: _clear_data_worker() Clear worker.