本文整理汇总了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
示例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
示例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
示例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)
示例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
示例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
示例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))
示例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)
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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))