本文整理汇总了Python中pypar.rank函数的典型用法代码示例。如果您正苦于以下问题:Python rank函数的具体用法?Python rank怎么用?Python rank使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rank函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run():
"""
Run the process, handling any parallelisation.
"""
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config",
help="Configuration file",
type=str)
parser.add_argument("-i", "--inputfile",
help="Input DEM file (ascii format)",
type=str)
parser.add_argument("-o", "--output",
help="Output path",
type=str)
parser.add_argument("-v", "--verbose",
help=("Verbose output (not available when invoking"
"parallel run)") )
args = parser.parse_args()
logfile = 'topomult.log'
loglevel = 'INFO'
if args.verbose:
verbose = args.verbose
else:
verbose = False
if args.config:
cfg = ConfigParser.ConfigParser()
cfg.read(args.config)
input_file = cfg.get('Input', 'Filename')
output_path = cfg.get('Output', 'Path')
logfile = cfg.get('Logging', 'LogFile')
loglevel = cfg.get('Logging', 'LogLevel')
verbose = cfg.get('Logging', 'Verbose')
if args.inputfile:
input_file = args.inputfile
if args.output:
output_path = args.output
attemptParallel()
if pp.size() > 1 and pp.rank() > 0:
logfile += '-' + str(pp.rank())
verbose = False # to stop output to console
flStartLog(logfile, loglevel, verbose)
pp.barrier()
work(input_file, output_path,
['n','s','e','w','ne','nw','se','sw'])
pp.barrier()
pp.finalize()
示例2: mprint
def mprint(txt):
"""
Print message txt
with indentation following the node's rank
"""
import pypar
pre = " " * 8 * pypar.rank()
if type(txt) != type('dummy'):
txt = txt.__str__()
pat = "-%d-"
print pre + (pat % pypar.rank()) + txt
示例3: distributed_generator
def distributed_generator(iterable):
"""
Distribute the values from a generator across workers.
"""
RUN, DIE = range(2)
P = pp.size()
if P == 1:
for el in iterable:
yield el
else:
if pp.rank() == 0:
it = iter(iterable)
while True:
try:
first = next(it)
for p in range(1, P):
pp.send(next(it), p, tag=RUN)
yield first
except StopIteration:
for p in range(1, P):
pp.send(666, p, tag=DIE)
break
else:
while True:
el, status = pp.receive(0, tag=pp.any_tag, return_status=True)
if status.tag == DIE:
break
yield el
示例4: __init__
def __init__(self, LookPos, LookDir, LookYaw, WindowRows = 40, WindowCols = 40):
self.LookPos = np.array(LookPos)
self.LookDir = np.array(LookDir)
self.Yaw = LookYaw
self.WindowRows = WindowRows
self.WindowCols = WindowCols
rhop = np.linalg.norm(np.array([LookDir[0],LookDir[1]]))
self.__Lon = math.atan2(LookDir[1], LookDir[0])
self.__Lat = math.atan2(LookDir[2],rhop)
self.start = time.time()
# initialize the MPI
self.numproc = pypar.size()
self.myid = pypar.rank()
self.node = pypar.get_processor_name()
if self.myid != self.numproc - 1:
self.Rows = self.WindowRows/self.numproc
self.RowEnd = self.WindowRows/self.numproc * (self.myid+1) - 1
else:
self.Rows = self.WindowRows/self.numproc + self.WindowRows%self.numproc
self.RowEnd = self.WindowRows
self.RowStart = self.WindowRows/self.numproc * self.myid
self.Window = np.zeros(shape = (self.Rows, self.WindowCols))
示例5: __init__
def __init__(self,
coordinates,
vertices,
boundary = None,
full_send_dict = None,
ghost_recv_dict = None,
velocity = None):
Domain.__init__(self,
coordinates,
vertices,
boundary,
velocity = velocity,
full_send_dict=full_send_dict,
ghost_recv_dict=ghost_recv_dict,
processor=pypar.rank(),
numproc=pypar.size()
)
N = self.number_of_elements
self.communication_time = 0.0
self.communication_reduce_time = 0.0
print 'processor',self.processor
print 'numproc',self.numproc
示例6: __init__
def __init__( s, dataform, global_pt1, global_pt2, spatial_step=(1,1,1) ):
s.myrank = mpi.rank()
s.dataform = dataform
s.global_pt1 = global_pt1
s.global_pt2 = global_pt2
s.spatial_step = spatial_step
s.step = spatial_step[0]
示例7: __init__
def __init__(self, is_parallel=True):
"""
Use is_parallel = False to stop parallelism, eg when running
several scenarios.
"""
if is_parallel is True:
try:
import pypar
except ImportError:
self._not_parallel()
else:
if pypar.size() >= 2:
self.rank = pypar.rank()
self.size = pypar.size()
self.node = pypar.get_processor_name()
self.is_parallel = True
self.file_tag = FILE_TAG_DELIMITER + str(self.rank)
self.log_file_tag = FILE_TAG_DELIMITER + str(self.rank)
else:
self._not_parallel()
else:
self._not_parallel()
# Some constants to identify messages
self.load_event_set = 0
示例8: __init__
def __init__(self):
self.proc = pypar.size()
self.myid = pypar.rank()
self.node = pypar.get_processor_name()
return
示例9: rec_submesh
def rec_submesh(p, verbose=True):
import pypar
numproc = pypar.size()
myid = pypar.rank()
[submesh_cell, triangles_per_proc,\
number_of_full_nodes, number_of_full_triangles] = rec_submesh_flat(p,verbose)
# find the full triangles assigned to this processor
lower_t = 0
for i in range(myid):
lower_t = lower_t+triangles_per_proc[i]
upper_t = lower_t+triangles_per_proc[myid]
# convert the information into a form needed by the GA
# datastructure
[GAnodes, GAtriangles, boundary, quantities, \
ghost_rec, full_send, \
tri_map, node_map, tri_l2g, node_l2g, \
ghost_layer_width] = \
build_local_mesh(submesh_cell, lower_t, upper_t, numproc)
return GAnodes, GAtriangles, boundary, quantities,\
ghost_rec, full_send,\
number_of_full_nodes, number_of_full_triangles, tri_map, node_map,\
tri_l2g, node_l2g, ghost_layer_width
示例10: broadcast_vec
def broadcast_vec( vec, i ):
myid = p.rank()
if myid == i:
for j in xrange(p.size()):
if j != myid:
p.send(vec[i],j)
else:
vec[i] = p.receive(i)
示例11: all_gather
def all_gather( obj ):
myid = p.rank()
nproc = p.size()
result = [ None for i in xrange(nproc) ]
result[myid] = obj
for i in xrange(nproc):
broadcast_vec(result,i)
return result
示例12: __init__
def __init__( s, global_pt1, global_pt2, apply_direction, wavelength, propagation_direction, polarization_angle ):
s.myrank = mpi.rank()
s.global_pt1, s.global_pt2 = global_pt1, global_pt2
s.apply_direction = apply_direction
s.wavelength = wavelength
s.propagation_direction = propagation_direction
s.p_angle = polarization_angle
s.gi1 = global_pt1[0]
s.gi2 = global_pt2[0]
示例13: one_example
def one_example():
txt = ["yes", "no", "when", "what the", "a", "5ive!"]
rank = pypar.rank()
size = pypar.size()
print "I am processor %d of %d. " % (rank, size)
for i, ele in enumerate(txt):
if i % size == rank:
print "i" + str(i) + " P" + str(rank) + " len " + str(len(ele)) + " for " + ele
示例14: run_client
def run_client():
'''
Runs
'''
# Identification
myid = pypar.rank() # id of this process
nproc = pypar.size() # number of processors
print "I am client", myid
pypar.finalize()
示例15: _send_event
def _send_event(self, event, test, err=None):
rank = pp.rank()
if rank > 0:
return
data = pickle.dumps((rank, str(event), err))
data = data.encode("latin1")
header = struct.pack("!I", len(data))
self.stream.write(header + data)
self.stream.flush()