def parallel_map(task, values, task_args=tuple(), task_kwargs={},  <EOL>num_processes=CPU_COUNT):
if len(values) == <NUM_LIT:1>:<EOL><INDENT>return [task(values[<NUM_LIT:0>], *task_args, **task_kwargs)]<EOL><DEDENT>Publisher().publish("<STR_LIT>", len(values))<EOL>nfinished = [<NUM_LIT:0>]<EOL>def _callback(_):<EOL><INDENT>nfinished[<NUM_LIT:0>] += <NUM_LIT:1><EOL>Publisher().publish("<STR_LIT>", nfinished[<NUM_LIT:0>])<EOL><DEDENT>if platform.system() != '<STR_LIT>' and num_processes > <NUM_LIT:1>and os.getenv('<STR_LIT>') == '<STR_LIT>':<EOL><INDENT>os.environ['<STR_LIT>'] = '<STR_LIT>'<EOL>try:<EOL><INDENT>pool = Pool(processes=num_processes)<EOL>async_res = [pool.apply_async(task, (value,) + task_args, task_kwargs,<EOL>_callback) for value in values]<EOL>while not all([item.ready() for item in async_res]):<EOL><INDENT>for item in async_res:<EOL><INDENT>item.wait(timeout=<NUM_LIT:0.1>)<EOL><DEDENT><DEDENT>pool.terminate()<EOL>pool.join()<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pool.terminate()<EOL>pool.join()<EOL>Publisher().publish("<STR_LIT>")<EOL>raise QiskitError('<STR_LIT>')<EOL><DEDENT>Publisher().publish("<STR_LIT>")<EOL>os.environ['<STR_LIT>'] = '<STR_LIT>'<EOL>return [ar.get() for ar in async_res]<EOL><DEDENT>results = []<EOL>for _, value in enumerate(values):<EOL><INDENT>result = task(value, *task_args, **task_kwargs)<EOL>results.append(result)<EOL>_callback(<NUM_LIT:0>)<EOL><DEDENT>Publisher().publish("<STR_LIT>")<EOL>return results<EOL>
Parallel execution of a mapping of `values` to the function `task`. This
is functionally equivalent to::

    result = [task(value, *task_args, **task_kwargs) for value in values]

On Windows this function defaults to a serial implementation to avoid the
overhead from spawning processes in Windows.

Args:
    task (func): Function that is to be called for each value in ``values``.
    values (array_like): List or array of values for which the ``task``
                        function is to be evaluated.
    task_args (list): Optional additional arguments to the ``task`` function.
    task_kwargs (dict): Optional additional keyword argument to the ``task`` function.
    num_processes (int): Number of processes to spawn.

Returns:
    result: The result list contains the value of
            ``task(value, *task_args, **task_kwargs)`` for
                each value in ``values``.

Raises:
    QiskitError: If user interrupts via keyboard.

Events:
    terra.parallel.start: The collection of parallel tasks are about to start.
    terra.parallel.update: One of the parallel task has finished.
    terra.parallel.finish: All the parallel tasks have finished.