'Args:
config: same as in :class:`DatasetPredictorBase`.
dataset: same as in :class:`DatasetPredictorBase`.
nr_proc (int): number of processes to use
use_gpu (bool): use GPU or CPU.
If GPU, then ``nr_proc`` cannot be more than what\'s in
CUDA_VISIBLE_DEVICES.
ordered (bool): produce outputs in the original order of the
datapoints. This will be a bit slower. Otherwise, :meth:`get_result` will produce
outputs in any order.'

def __init__(self, config, dataset, nr_proc, use_gpu=True, ordered=True):

    if config.return_input:
        logger.warn('Using    the    option    `return_input`    in    MultiProcessDatasetPredictor    might    be    slow')
    assert (nr_proc > 1), nr_proc
    super(MultiProcessDatasetPredictor, self).__init__(config, dataset)
    self.nr_proc = nr_proc
    self.ordered = ordered
    (self.inqueue, self.inqueue_proc) = dump_dataflow_to_process_queue(self.dataset, (nr_proc * 2), self.nr_proc)
    if use_gpu:
        try:
            gpus = os.environ['CUDA_VISIBLE_DEVICES'].split(',')
            assert (len(gpus) >= self.nr_proc), 'nr_proc={}    while    only    {}    gpus    available'.format(self.nr_proc, len(gpus))
        except KeyError:
            gpus = list(range(self.nr_proc))
    else:
        gpus = (['-1'] * self.nr_proc)
    self.outqueue = multiprocessing.Queue()
    self.workers = [MultiProcessQueuePredictWorker(i, self.inqueue, self.outqueue, self.config) for i in range(self.nr_proc)]
    self.inqueue_proc.start()
    for (p, gpuid) in zip(self.workers, gpus):
        if (gpuid == '-1'):
            logger.info('Worker    {}    uses    CPU'.format(p.idx))
        else:
            logger.info('Worker    {}    uses    GPU    {}'.format(p.idx, gpuid))
        with change_gpu(gpuid):
            p.start()
    if ordered:
        self.result_queue = OrderedResultGatherProc(self.outqueue, nr_producer=self.nr_proc)
        self.result_queue.start()
        ensure_proc_terminate(self.result_queue)
    else:
        self.result_queue = self.outqueue
    ensure_proc_terminate((self.workers + [self.inqueue_proc]))
