def run_multiprocessing(target, jobs, n=<NUM_LIT:1>, nproc=None, **kwargs):
def consumer(f, q_in, q_out):<EOL><INDENT>while True:<EOL><INDENT>val = q_in.get()<EOL>if val is None:<EOL><INDENT>q_in.task_done()<EOL>break<EOL><DEDENT>i, x = val<EOL>res = (i, f(*x))<EOL>q_in.task_done()<EOL>q_out.put(res)<EOL><DEDENT><DEDENT>def mulpmap(f, X, nproc):<EOL><INDENT>nproc = nproc or multiprocessing.cpu_count()<EOL>q_in = multiprocessing.JoinableQueue()<EOL>q_out = multiprocessing.Queue()<EOL>workers = [multiprocessing.Process(target=consumer, args=(f, q_in, q_out), daemon=True) for _ in range(nproc)]<EOL>sent = [q_in.put((i, x)) for i, x in enumerate(X)]<EOL>num_tasks = len(sent)<EOL>[q_in.put(None) for _ in range(nproc)]  <EOL>[w.start() for w in workers]<EOL>q_in.join()<EOL>res = [q_out.get() for _ in range(num_tasks)]<EOL>return [x for (_, x) in sorted(res)]<EOL><DEDENT>res = mulpmap(<EOL>target, ((job, i + <NUM_LIT:1>, j + <NUM_LIT:1>) for (i, job), j in itertools.product(enumerate(jobs), range(n))), nproc)<EOL>return [res[i: i + n] for i in range(<NUM_LIT:0>, len(res), n)]<EOL>
Evaluate the given function with each set of arguments, and return a list of results.
This function does in parallel by using `multiprocessing`.

Parameters
----------
target : function
    A function to be evaluated. The function must accepts three arguments,
    which are a list of arguments given as `jobs`, a job and task id (int).
jobs : list
    A list of arguments passed to the function.
    All the argument must be picklable.
n : int, optional
    A number of tasks. Repeat the evaluation `n` times for each job.
    1 for default.
nproc : int, optional
    A number of cores available once.
    If nothing is given, all available cores are used.

Returns
-------
results : list
    A list of results. Each element is a list containing `n` results.

Examples
--------
>>> jobs = ((1, 'spam'), (2, 'ham'), (3, 'eggs'))

>>> target = lambda args, job_id, task_id: (args[1] * args[0])
>>> run_multiprocessing(target, jobs, nproc=2)
[['spam'], ['hamham'], ['eggseggseggs']]

>>> target = lambda args, job_id, task_id: "{:d} {}".format(task_id, args[1] * args[0])
>>> run_multiprocessing(target, jobs, n=2, nproc=2)
[['1 spam', '2 spam'], ['1 hamham', '2 hamham'], ['1 eggseggseggs', '2 eggseggseggs']]

See Also
--------
ecell4.extra.ensemble.run_serial
ecell4.extra.ensemble.run_sge
ecell4.extra.ensemble.run_slurm
ecell4.extra.ensemble.run_multiprocessing
ecell4.extra.ensemble.run_azure