<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run_multiprocessing(target, jobs, n=1, nproc=None, **kwargs):
 """ 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 -------- [['spam'], ['hamham'], ['eggseggseggs']] [['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 """

    def consumer(f, q_in, q_out):
        while True:
            val = q_in.get()
            if val is None:
                q_in.task_done()
                break
            i, x = val
            res = (i, f(*x))
            q_in.task_done()
            q_out.put(res)

    def mulpmap(f, X, nproc):
        nproc = nproc or multiprocessing.cpu_count()

        q_in = multiprocessing.JoinableQueue()
        q_out = multiprocessing.Queue()
        workers = [multiprocessing.Process(target=consumer, args=(f, q_in, q_out), daemon=True) for _ in range(nproc)]
        sent = [q_in.put((i, x)) for i, x in enumerate(X)]
        num_tasks = len(sent)
        [q_in.put(None) for _ in range(nproc)]  #XXX: poison pill
        [w.start() for w in workers]
        # [w.join() for w in workers]
        q_in.join()
        res = [q_out.get() for _ in range(num_tasks)]
        return [x for (_, x) in sorted(res)]

    res = mulpmap(
        target, ((job, i + 1, j + 1) for (i, job), j in itertools.product(enumerate(jobs), range(n))), nproc)
    return [res[i: i + n] for i in range(0, len(res), n)]