當前位置: 首頁>>代碼示例>>Python>>正文


Python MPI.ANY_TAG屬性代碼示例

本文整理匯總了Python中mpi4py.MPI.ANY_TAG屬性的典型用法代碼示例。如果您正苦於以下問題:Python MPI.ANY_TAG屬性的具體用法?Python MPI.ANY_TAG怎麽用?Python MPI.ANY_TAG使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在mpi4py.MPI的用法示例。


在下文中一共展示了MPI.ANY_TAG屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: slave_set

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def slave_set(self):
        if self.rank > 0:
#            print("SLAVE : ", self.rank, " starting...")
            status = MPI.Status()
#            print("SLAVE : ", self.rank, " probing for message...")
            msg = self.COMM.Probe(0, MPI.ANY_TAG, status=status)
#            print("SLAVE : ", self.rank, " recieved a message... ", status.Get_tag())
            self.working = True
            if status.Get_tag() == tags.WORK:
                workingBlock = self.COMM.recv(source=0, tag=tags.WORK)
#                print("SLAVE : ", self.rank, " just recieved ", workingBlock)
                self.curr_block = workingBlock
                self.working = True
                return True, workingBlock
            else:
                self.working = False
                workingBlock = self.COMM.recv(source=0, tag=tags.KILL)
#                print("SLAVE : ", self.rank, " dying...")
                return False, 0
        else:
            return False, 0 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:23,代碼來源:mpi_load_balancer.py

示例2: _read

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def _read(self):
        result = super(MPIWrapper, self)._read()
        if result is not None:
            return result

        status = MPI.Status()
        msg = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status)
        tag = status.Get_tag()
        while tag == STATUS_TERMINATED:
            self.terminated += 1
            if self.terminated >= self._num_sources:
                break
            else:
                msg = comm.recv(source=MPI.ANY_SOURCE,
                                tag=MPI.ANY_TAG,
                                status=status)
                tag = status.Get_tag()
        return msg, tag 
開發者ID:dispel4py,項目名稱:dispel4py,代碼行數:20,代碼來源:mpi_process.py

示例3: worker_process

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def worker_process(comm, rank, tags, status):
    # Worker processes execute code below
    name = MPI.Get_processor_name()
    print("I am a worker with rank %d on %s." % (rank, name))
    comm.send(None, dest=0, tag=tags.READY)

    while True:
        print('Recieving ...')
        task = comm.recv(source=0, tag=MPI.ANY_TAG, status=status)
        print('received!')

        tag = status.Get_tag()

        if tag == tags.START:
            # Do the work here
            result = task + 1
            print('attempting to send ...')
            comm.send(result, dest=0, tag=tags.DONE)
            print('sending worked ...')
        elif tag == tags.EXIT:
            print('went through exit')
            break 
開發者ID:hvasbath,項目名稱:beat,代碼行數:24,代碼來源:pt_toy_example.py

示例4: worker

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def worker():
    from mpi4py import MPI
    while True:
        status = MPI.Status()
        ret = MPI.COMM_WORLD.recv(source=0, tag=MPI.ANY_TAG, status=status) 

        if status.tag == 10:
            # Workload received
            func = ret['func']
            if ret.get('unpack'):
                res = func(*ret['input_data'])
            else:
                res = func(ret['input_data'])

            # Done, let's send it back
            MPI.COMM_WORLD.send(dict(job_index=ret['job_index'], output_data=res), dest=0, tag=2)

        elif status.tag == 666:
            # Kill code
            sys.exit(0) 
開發者ID:uchicago-cs,項目名稱:deepdish,代碼行數:22,代碼來源:mpi.py

示例5: _receive_loop

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def _receive_loop(self):
        comm = self.comm 

        while True:

            status = MPI.Status()
            comm.Iprobe(MPI.ANY_SOURCE, MPI.ANY_TAG, status)
            message_src = status.Get_source()
            message_tag = status.Get_tag()

            # results are tuples of (task_id, {'result', 'exception'}, value)
            if message_tag == self.result_tag:
                (task_id, result_stat, result_value) = comm.recv(source = message_src, tag = message_tag)

                ft = self.pending_futures.pop(task_id)

                if result_stat == 'exception':
                    ft._set_exception(*result_value)
# Check with Matt on what else to do for an exception
                else:
                    ft._set_result(result_value)
                    self.task_dest.append(message_src)

            # Check for announcements
            elif message_tag == self.announce_tag:
                messages = comm.recv(source = message_src, tag = message_tag)
                if 'shutdown' in messages:
                    log.debug('exiting _receive_loop()')
                    return 
開發者ID:westpa,項目名稱:westpa,代碼行數:31,代碼來源:mpi.py

示例6: _create_worker

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def _create_worker(self):
        comm = self.comm

        while True:

            status = MPI.Status()
            comm.Probe(self.master_rank, MPI.ANY_TAG, status)
            message_src = self.master_rank
            message_tag = status.Get_tag()

            # Check for available task 
            if message_tag == self.task_tag:

                task = comm.recv(source = message_src, tag = message_tag)

                try:
                    result_value = task.fn(*task.args, **task.kwargs)
                except Exception as e:
                    result_object = (task.task_id, 'exception', result_value)
                else:
                    result_object = (task.task_id, 'result', result_value)

                comm.send(result_object, dest = self.master_rank, tag = self.result_tag)

            # Check for announcements
            if message_tag == self.announce_tag:
                messages = comm.recv(source = message_src, tag = message_tag)
                if 'shutdown' in messages:
                    return 
開發者ID:westpa,項目名稱:westpa,代碼行數:31,代碼來源:mpi.py

示例7: receive

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def receive(wrapper):
    while wrapper.terminated < wrapper._num_sources:
        status = MPI.Status()
        msg = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status)
        tag = status.Get_tag()
        # print('Received %s, %s' % (msg, tag))
        if tag == STATUS_TERMINATED:
            wrapper.terminated += 1
        else:
            wrapper.input_data.put((msg, tag))
        # self.wrapper.pe.log('Queue size: %s'%self.wrapper.input_data.qsize())
    # put the final terminate block into the queue
    wrapper.input_data.put((None, STATUS_TERMINATED)) 
開發者ID:dispel4py,項目名稱:dispel4py,代碼行數:15,代碼來源:mpi_queue_process.py

示例8: _worker

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def _worker(self, clf):
        """Worker node's operation.

        Receiving tasks from the master to process and sending the result back

        Parameters
        ----------
        clf: classification function
            the classifier to be used in cross validation

        Returns
        -------
        None
        """
        logger.debug(
            'worker %d is running, waiting for tasks from master at rank %d' %
            (MPI.COMM_WORLD.Get_rank(), self.master_rank)
        )
        comm = MPI.COMM_WORLD
        status = MPI.Status()
        while 1:
            task = comm.recv(source=self.master_rank,
                             tag=MPI.ANY_TAG,
                             status=status)
            if status.Get_tag():
                break
            comm.send(self._voxel_scoring(task, clf),
                      dest=self.master_rank) 
開發者ID:brainiak,項目名稱:brainiak,代碼行數:30,代碼來源:voxelselector.py

示例9: Irecv

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def Irecv(self, buf, source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG):
        if isinstance(buf, dndarray.DNDarray):
            buf = buf._DNDarray__array
        if not isinstance(buf, torch.Tensor):
            return MPIRequest(self.handle.Irecv(buf, source, tag))

        rbuf = buf if CUDA_AWARE_MPI else buf.cpu()
        return MPIRequest(self.handle.Irecv(self.as_buffer(rbuf), source, tag), None, rbuf, buf) 
開發者ID:helmholtz-analytics,項目名稱:heat,代碼行數:10,代碼來源:communication.py

示例10: Recv

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def Recv(self, buf, source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=None):
        if isinstance(buf, dndarray.DNDarray):
            buf = buf._DNDarray__array
        if not isinstance(buf, torch.Tensor):
            return self.handle.Recv(buf, source, tag, status)

        rbuf = buf if CUDA_AWARE_MPI else buf.cpu()
        ret = self.handle.Recv(self.as_buffer(rbuf), source, tag, status)

        if isinstance(buf, torch.Tensor) and buf.is_cuda and not CUDA_AWARE_MPI:
            buf.copy_(rbuf)
        return ret 
開發者ID:helmholtz-analytics,項目名稱:heat,代碼行數:14,代碼來源:communication.py

示例11: worker

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def worker(self):
                '''worker processor method which waits for map data or end signal from master'''
                status = MPI.Status()
                while True:
                        job = self.comm.recv(source=0, tag=MPI.ANY_TAG, status=status)
                        if job == -999: #end signal
                                break
                        if  isinstance(job, _func_wrapper):
                                self.function = job.function
                                continue

                        result = self.function(job)
                        self.comm.isend(result, dest=0, tag=status.tag) 
開發者ID:EliseJ,項目名稱:astroABC,代碼行數:15,代碼來源:mpi_pool.py

示例12: wait_for_any_rank

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def wait_for_any_rank(self):
        """
        Waits for any message from any rank.
        @return A 3-tuple of (tensor, source rank, tag)
        """
        status = MPI.Status()
        tensor = self.comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status)
        return tensor, status.source, status.tag 
開發者ID:deep500,項目名稱:deep500,代碼行數:10,代碼來源:communication.py

示例13: wait_for_root

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def wait_for_root(self):
        """
        Wait for message from root. Normally these are the updated parameters.
        @return The sent data from the root.
        """
        tensor = self.comm.recv(source=0, tag=MPI.ANY_TAG)
        return tensor 
開發者ID:deep500,項目名稱:deep500,代碼行數:9,代碼來源:communication.py

示例14: work

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def work():
    comm = MPI.COMM_WORLD
    rank = comm.rank
    
    #pr = cProfile.Profile()
    #pr.enable()

    while True:
        status = MPI.Status()
        msg = comm.recv(source=MASTER, tag=MPI.ANY_TAG, status=status)
        event = status.Get_tag()

        if event == Msg.LEARN.value:
            comm.isend(rank, dest=MASTER, tag=Msg.STARTED.value)

            num_iter = msg

            Dts, Trace, Count_zh, Count_sz, count_h, count_z, \
                    alpha_zh, beta_zs, kernel = receive_workload(comm)
            fast_populate(Trace, Count_zh, Count_sz, count_h, \
                    count_z)
            sample(Dts, Trace, Count_zh, Count_sz, count_h, \
                    count_z, alpha_zh, beta_zs, kernel, num_iter, \
                    comm)
            
            comm.isend(rank, dest=MASTER, tag=Msg.FINISHED.value)
        elif event == Msg.SENDRESULTS.value:
            comm.Send([np.array(Trace[:, -1], order='C'), MPI.INT], dest=MASTER)
            comm.Send([Count_zh, MPI.INT], dest=MASTER)
            comm.Send([Count_sz, MPI.INT], dest=MASTER)
            comm.Send([count_h, MPI.INT], dest=MASTER)
            comm.Send([count_z, MPI.INT], dest=MASTER)
            comm.Send([kernel.get_state(), MPI.DOUBLE], dest=MASTER)
        elif event == Msg.STOP.value:
            break
        else:
            print('Unknown message received', msg, event, Msg(event))

    #pr.disable()
    #pr.dump_stats('worker-%d.pstats' % rank) 
開發者ID:flaviovdf,項目名稱:tribeflow,代碼行數:42,代碼來源:plearn.py

示例15: manage

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import ANY_TAG [as 別名]
def manage(comm, num_workers):
    available_to_pair = -1
    finished = {}
    num_finished = 0
    
    for worker_id in xrange(1, num_workers + 1):
        finished[worker_id] = False

    while num_finished != num_workers:
        status = MPI.Status()
        worker_id = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, \
                status=status)
        event = status.Get_tag()

        if event == Msg.STARTED.value:
            print('Worker', worker_id, 'is working!')
        
        elif event == Msg.PAIRME.value:
            if num_finished == num_workers - 1: #only 1 working, pair with self
                comm.isend(worker_id, dest=worker_id, tag=Msg.PAIRED.value)
            else:
                assert available_to_pair != worker_id
                if available_to_pair == -1:
                    available_to_pair = worker_id
                else:
                    comm.isend(available_to_pair, dest=worker_id, \
                            tag=Msg.PAIRED.value)
                    comm.isend(worker_id, dest=available_to_pair, \
                            tag=Msg.PAIRED.value)
                    available_to_pair = -1
        elif event == Msg.FINISHED.value:
            print('Worker', worker_id, 'has finished it\'s iterations!')
            finished[worker_id] = True
            num_finished += 1
            
            #wake up last worker if it's waiting for a pair
            if num_finished == num_workers - 1 and available_to_pair != -1:
                comm.isend(available_to_pair, dest=available_to_pair, \
                        tag=Msg.PAIRED.value)
        else:
            print(0, 'Unknown message received', worker_id, event, Msg(event)) 
開發者ID:flaviovdf,項目名稱:tribeflow,代碼行數:43,代碼來源:plearn.py


注:本文中的mpi4py.MPI.ANY_TAG屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。