bempp_cl.api.utils.pool ======================= .. py:module:: bempp_cl.api.utils.pool .. autoapi-nested-parse:: Routines to administrate a process pool. Attributes ---------- .. autoapisummary:: bempp_cl.api.utils.pool._DATA bempp_cl.api.utils.pool._MY_ID bempp_cl.api.utils.pool._USE_THREADS bempp_cl.api.utils.pool._POOL bempp_cl.api.utils.pool._NWORKERS bempp_cl.api.utils.pool._IN_WORKER bempp_cl.api.utils.pool._BUFFER Classes ------- .. autoapisummary:: bempp_cl.api.utils.pool.Pool Functions --------- .. autoapisummary:: bempp_cl.api.utils.pool.worker bempp_cl.api.utils.pool.as_array bempp_cl.api.utils.pool.to_buffer bempp_cl.api.utils.pool.from_buffer bempp_cl.api.utils.pool._raise_if_not_worker bempp_cl.api.utils.pool.number_of_workers bempp_cl.api.utils.pool.insert_data bempp_cl.api.utils.pool.is_initialised bempp_cl.api.utils.pool.clear_data bempp_cl.api.utils.pool.get_data bempp_cl.api.utils.pool.get_id bempp_cl.api.utils.pool.remove_key bempp_cl.api.utils.pool.has_key bempp_cl.api.utils.pool.is_worker bempp_cl.api.utils.pool.create_device_pool bempp_cl.api.utils.pool.create_pool bempp_cl.api.utils.pool.nworkers bempp_cl.api.utils.pool.map bempp_cl.api.utils.pool.starmap bempp_cl.api.utils.pool.execute bempp_cl.api.utils.pool._assign_ids bempp_cl.api.utils.pool.shutdown bempp_cl.api.utils.pool._execute_function_without_arguments bempp_cl.api.utils.pool._remove_key_worker bempp_cl.api.utils.pool._init_device_worker bempp_cl.api.utils.pool._clear_data_worker Module Contents --------------- .. py:data:: _DATA .. py:data:: _MY_ID :value: None .. py:data:: _USE_THREADS :value: None .. py:data:: _POOL :value: None .. py:data:: _NWORKERS :value: None .. py:data:: _IN_WORKER :value: False .. py:data:: _BUFFER :value: None .. 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:attribute:: _nworkers .. py:attribute:: _senders .. py:attribute:: _receivers .. py:attribute:: _workers .. 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.