a
    ƹDf                     @   s@   d Z ddlmZmZmZ ddlmZ dd Z	dd Z
edkr<d	S )
a  
minimal interface to python's ``pp`` (parallel python)  module

Implements a work-alike of the builtin ``map`` function that distributes
work across many processes.  As it uses ``ppft`` to do the
actual parallel processing, code using this must conform to the usual
``ppft`` restrictions (arguments must be serializable, etc).

Notes:
    This module has been deprecated in favor of ``pathos.pools``.
    )__STATEstats__print_stats)Serverc                    sz   d}t ddst|dt d<  fdd}|g}|| | dkrRt d d nt d |  dd	 t|g|R  D S )
a  Split the work of 'function' across the given number of
    processes.  Set 'processes' to None to let Parallel Python
    autodetect the number of children to use.

    Although the calling semantics should be identical to
    __builtin__.map (even using __builtin__.map to process
    arguments), it differs in that it returns a generator instead of a
    list.  This enables lazy evaluation of the results so that other
    work can be done while the subprocesses are still running.

    >>> def rangetotal(n): return n, sum(range(n))
    >>> list(map(rangetotal, range(1, 6)))
    [(1, 0), (2, 1), (3, 3), (4, 6), (5, 10)]
    >>> list(ppmap(1, rangetotal, range(1, 6)))
    [(1, 0), (2, 1), (3, 3), (4, 6), (5, 10)]
    )*serverN	ppserversc                     s   t d j | t dS )zSend a job to the serverr   )globals)r   submitr
   )argsfunction Z/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/pp_map.pyr   i   s    zppmap.<locals>.submitZ
autodetectc                 s   s   | ]}| V  qd S )Nr   ).0Zsubprocr   r   r   	<genexpr>       zppmap.<locals>.<genexpr>)r   getppServerextendZ	set_ncpusmap)Z	processesr   sequence	sequencesr	   r   ar   r   r   ppmap<   s    
r   c                 O   s   d}d}d|v r"|d }| d d|v r<|d }| d d|v rN| d d|v r`| d d|v rr| d d|v r| d d	|v r| d	 d
|v r| d
 d|v r| d tddst|d td< }tt|| |g|R  S )a'  extend python's parallel map function to parallel python

Args:
    function - target function
    sequence - sequence to process in parallel
    ncpus - number of 'local' processors to use  [defaut = 'autodetect']
    servers - available distributed parallel python servers  [default = ()]
    Nr   ZncpusserversZnnodesnodeslauncherZmapperqueueZ	timelimitZ	schedulerr   r   )popr   r   r   listr   )r   r   r   kwdsZprocsr   Z
job_serverr   r   r   pp_map   s$    	

r#   __main__N)__doc__Z	pathos.ppr   r   r   Zprint_statsZpathos.helpers.pp_helperr   r   r   r#   __name__r   r   r   r   <module>+   s   U 