当前位置: 首页>>代码示例>>Python>>正文


Python MPI.ANY_SOURCE属性代码示例

本文整理汇总了Python中mpi4py.MPI.ANY_SOURCE属性的典型用法代码示例。如果您正苦于以下问题:Python MPI.ANY_SOURCE属性的具体用法?Python MPI.ANY_SOURCE怎么用?Python MPI.ANY_SOURCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在mpi4py.MPI的用法示例。


在下文中一共展示了MPI.ANY_SOURCE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _read

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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

示例2: mpi_master_spin_tasks

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def mpi_master_spin_tasks(task, gdirs):
    comm = OGGM_MPI_COMM
    cfg_store = cfg.pack_config()
    msg_list = ([gdir for gdir in gdirs if gdir is not None] +
                [None] * OGGM_MPI_SIZE)

    _imprint("Starting MPI task distribution...")

    comm.bcast((cfg_store, task), root=OGGM_MPI_ROOT)

    status = MPI.Status()
    for msg in msg_list:
        comm.recv(source=MPI.ANY_SOURCE, status=status)
        comm.send(obj=msg, dest=status.Get_source())

    _imprint("MPI task distribution done, collecting results...")

    comm.gather(sendobj=None, root=OGGM_MPI_ROOT)

    _imprint("MPI task results gotten!") 
开发者ID:OGGM,项目名称:oggm,代码行数:22,代码来源:mpi.py

示例3: id_distribution_loop

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def id_distribution_loop(argc, cfg):
    """
    A loop to distribute event IDs to hungry workers.
    """

    arrivals = load_arrivals(argc.arrivals_file)
    event_ids = arrivals["event_id"].unique()
    # Distribute event IDs.
    for idx in range(len(event_ids)):
        event_id = event_ids[idx]
        requesting_rank = COMM.recv(source=MPI.ANY_SOURCE, tag=ID_REQUEST_TAG)
        COMM.send(event_id, dest=requesting_rank, tag=ID_TRANSMISSION_TAG)
    # Distribute sentinel.
    for irank in range(WORLD_SIZE - 1):
        requesting_rank = COMM.recv(source=MPI.ANY_SOURCE, tag=ID_REQUEST_TAG)
        COMM.send(None, dest=requesting_rank, tag=ID_TRANSMISSION_TAG)

    return (True) 
开发者ID:malcolmw,项目名称:pykonal,代码行数:20,代码来源:eq_loc.py

示例4: __init__

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def __init__(self, rank=None, nonMPIMode=False, logger=None):
        if nonMPIMode:
            self.comm = None
            self.stat = None
            self.nRank = 0
            self.totalRanks = 1
            self.selectSource = None
        else:
            from mpi4py import MPI
            self.comm = MPI.COMM_WORLD
            self.stat = MPI.Status()
            self.nRank = self.comm.Get_rank()
            self.totalRanks = self.comm.Get_size()
            self.selectSource = MPI.ANY_SOURCE

        self.logger = logger

        # for message in rank 0
        self.hasMessage = False
        self.recvQueue = recvQueue
        self.sendQueue = sendQueue


    # get rank of itself 
开发者ID:PanDAWMS,项目名称:pilot,代码行数:26,代码来源:Interaction.py

示例5: run

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def run(self, model):
        
        if self.comm == None:
            
            print('Server communicator not initialized')
            
            return
            
        print('server started')

        while True:
            #  Wait for next request from client
            
            request = self.comm.recv(source=MPI.ANY_SOURCE, tag=199)
                
            #  Do some process work and formulate a reply
            reply = self.process_request(model, request['id'],
                                        request['rank'],request['message'])

            #  Send reply back to client
            self.comm.send(reply, dest=request['rank'], tag=200)
            
            # Do some action work after reply
            self.action_after(model, request['id'],
                                request['rank'], request['message']) 
开发者ID:uoguelph-mlrg,项目名称:Theano-MPI,代码行数:27,代码来源:easgd_server.py

示例6: _handle_message

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def _handle_message(self):
        """Handle received messages.

        Receive record update messages of the form
            ('action', record_id, params)
        where 'action' is the name of an EvalRecord method and params is
        the list of parameters.  The record_id should be recorded in the
        hub's records table (which happens whenever it is referenced in
        a message sent to a worker).

        On a message indicating that the worker is done with the record,
        we add the worker that sent the message back to the free pool.
        """
        logger.debug("Handle incoming message")
        s = MPI.Status()
        data = comm.recv(status=s, source=MPI.ANY_SOURCE, tag=0)
        logger.debug("Received message: %s", data)
        mname = data[0]
        record = self._recids[data[1]]
        method = getattr(record, mname)
        method(*data[2:])
        if mname == 'complete' or mname == 'cancel' or mname == 'kill':
            logger.debug("Re-queueing worker")
            self._workers.append(s.source)
        self.ping() 
开发者ID:SanPen,项目名称:GridCal,代码行数:27,代码来源:mpiserve.py

示例7: _receive_loop

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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

示例8: receive

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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

示例9: _shutdown_slaves

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def _shutdown_slaves():
    global OGGM_MPI_COMM
    if OGGM_MPI_COMM is not None and OGGM_MPI_COMM != MPI.COMM_NULL:
        msgs = [StopIteration] * OGGM_MPI_SIZE
        status = MPI.Status()
        OGGM_MPI_COMM.bcast((None, None), root=OGGM_MPI_ROOT)
        for msg in msgs:
            OGGM_MPI_COMM.recv(source=MPI.ANY_SOURCE, status=status)
            OGGM_MPI_COMM.send(obj=msg, dest=status.Get_source())
        OGGM_MPI_COMM.gather(sendobj=None, root=OGGM_MPI_ROOT)
    OGGM_MPI_COMM = None 
开发者ID:OGGM,项目名称:oggm,代码行数:13,代码来源:mpi.py

示例10: Irecv

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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

示例11: Recv

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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

示例12: wait_for_any_rank

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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: manage

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [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

示例14: recv_any_from_child

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def recv_any_from_child(self,status):
        """Receives any message from any child.  Returns the provided status object,
            populated with information about received message"""
        self.recv( tag='any', source=MPI.ANY_SOURCE, status=status, comm=self.child_comm )
        return status 
开发者ID:vlimant,项目名称:mpi_learn,代码行数:7,代码来源:process.py

示例15: _gather_updated_ages

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import ANY_SOURCE [as 别名]
def _gather_updated_ages(self, total_age):
        total_age.update({0: self._island.generational_age})
        status = MPI.Status()
        while self.comm.iprobe(source=MPI.ANY_SOURCE,
                               tag=AGE_UPDATE,
                               status=status):
            data = self.comm.recv(source=status.Get_source(),
                                  tag=AGE_UPDATE)
            total_age.update(data) 
开发者ID:nasa,项目名称:bingo,代码行数:11,代码来源:parallel_archipelago.py


注:本文中的mpi4py.MPI.ANY_SOURCE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。