• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pypar.size函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypar.size函数的典型用法代码示例。如果您正苦于以下问题:Python size函数的具体用法?Python size怎么用?Python size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __init__

	def __init__(self, verbose=True):
	
		'''Initialises new Environment objects'''
	
		self.outputDirectory = os.getcwd()
		self.verbose = verbose
	
		#Do the subsequent things once only
		if not Environment.isInitialised:
			#See if a parallel environment is available
			try:
				import pypar
				#If its imported we might have a parallel environment
				Environment.isParallel = True
				self.output('[PEAT-SA] Parallel environment available')
				#Check environment size. 
				#If there is more than one processor there must be a parallel environment
				#If there's only one then its not parallel.
				if pypar.size() == 1:
					self.output('[PEAT-SA] Only one processor - parallel environment disabled')
					Environment.isParallel = False
				else:
					self.output('[PEAT-SA] Parallel environment enabled with %d processors' % pypar.size())
			except BaseException:
				#Importing pypar caused an exception - No parallel environment
				Environment.isParallel = False
				self.output('[PEAT-SA] Parallel environment disabled.\n')

			Environment.isInitialised = True	 
开发者ID:shambo001,项目名称:peat,代码行数:29,代码来源:Environment.py


示例2: _divideArray

	def _divideArray(self, array):
	
		'''Divides an array roughly equally depending on the environment size
		
		Returns: A list with one entry for each node.
		The entry is a tuple giving the start and end elements in array 
		that should be assigned to that node.'''
	
		import pypar
	
		#Divide evenly then add remainder elements to processors
		maxElements = int(math.floor(len(array)/pypar.size()))
		remainder = len(array) - maxElements*pypar.size()
		start = 0
		end = 0
		divisions = []
		for i in range(pypar.size()):
			start = end
			end = end + maxElements
			if remainder != 0:
				end = end + 1
				remainder = remainder - 1
			divisions.append((start, end))
			
		return divisions									
开发者ID:shambo001,项目名称:peat,代码行数:25,代码来源:Environment.py


示例3: balanceArrays

	def balanceArrays(self, arrayFragment):
	
		'''Redistributes the elements in a set of arrays equally across the nodes'''
		
		if Environment.isParallel:
			import pypar
			if self.isRoot():
				completeArray = arrayFragment
				for i in range(1, pypar.size()):
					fragment = pypar.receive(i)
					completeArray.extend(fragment)
				
				#Divide it up
				divisions = self._divideArray(completeArray)
				
				#Send the fragments
				for i in range(1, pypar.size()):
					start, end = divisions[i]
					pypar.send(completeArray[start:end], i)
					
				self.output('[ENV] Rebalanced array divisions %s' % divisions)	
					
				#Assign root fragment	
				start, end = divisions[0]	
				arrayFragment = completeArray[start:end]
			else:
				#Send the fragment
				pypar.send(arrayFragment, 0)
				#Retrieve the array
				arrayFragment = pypar.receive(0)
		else:
			completeArray = arrayFragment
		
		return arrayFragment
开发者ID:shambo001,项目名称:peat,代码行数:34,代码来源:Environment.py


示例4: __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
开发者ID:dynaryu,项目名称:eqrm,代码行数:26,代码来源:parallel.py


示例5: gather

def gather( obj ):
	if root():
		result = [ None for i in xrange(p.size()) ]
		result[0] = obj
		for i in xrange(p.size()-1):
			result[i+1] = p.receive(i+1)
		return result
	else:
		p.send(obj,0)
开发者ID:lelou6666,项目名称:PySOL,代码行数:9,代码来源:mpi.py


示例6: splitArray

	def splitArray(self, array):
	
		'''Splits array between all the processes in the environment.
		
		Each process will be returned a different section of the array to work on'''
	
		if Environment.isParallel:
			import pypar
			#Split the array into sections and return the section for this processor
			divisions = []
			if self.isRoot():
				#Root does the splitting - we send each processor the start and end index
				#NOTE: pypar broadcast won't work even when setting vanilla
				#It always returns message trucated error.
				divisions = self._divideArray(array)	
				for i in range(1,pypar.size()):
					pypar.send(divisions[i], i)
				start = divisions[0][0]
				end = divisions[0][1]
			else:	
				indexes = pypar.receive(0)
				start = indexes[0]
				end = indexes[1]
				
			return array[start:end]
		else:
			return array
开发者ID:shambo001,项目名称:peat,代码行数:27,代码来源:Environment.py


示例7: __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))
开发者ID:asdfvar,项目名称:ray-trace,代码行数:25,代码来源:RayTrace.py


示例8: 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
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:30,代码来源:distribute_mesh.py


示例9: scatter

def scatter( vec ):
	if root():
		for i in xrange(p.size()-1):
			p.send(vec[i+1],i+1)
		return vec[0]
	else:
		return p.receive(0)
开发者ID:lelou6666,项目名称:PySOL,代码行数:7,代码来源:mpi.py


示例10: __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
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:28,代码来源:parallel_advection.py


示例11: broadcast

def broadcast( obj ):
	if root():
		for i in xrange(p.size()-1):
			p.send(obj,i+1)
		return obj
	else:
		return p.receive(0)
开发者ID:lelou6666,项目名称:PySOL,代码行数:7,代码来源:mpi.py


示例12: __init__

    def __init__(self):

        self.proc = pypar.size()
        self.myid = pypar.rank()
        self.node = pypar.get_processor_name()

        return
开发者ID:yongwangCPH,项目名称:peat,代码行数:7,代码来源:ProteinComplexTool_parallel.py


示例13: 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
开发者ID:Mahdisadjadi,项目名称:pypar,代码行数:28,代码来源:functional.py


示例14: 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()
开发者ID:wcarthur,项目名称:topomultipliers,代码行数:59,代码来源:topomult.py


示例15: 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)
开发者ID:lelou6666,项目名称:PySOL,代码行数:8,代码来源:mpi.py


示例16: 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
开发者ID:lelou6666,项目名称:PySOL,代码行数:8,代码来源:mpi.py


示例17: p_sum_all

def p_sum_all( vec ):
	nproc = p.size()
	pcs = [ None for i in xrange(nproc) ]
	if root():
		for i in xrange(nproc):
			pcs[i] = vec[i::nproc]
	temp = scatter(pcs)
	temp = sum(temp)
	pcs = all_gather(temp)
	return sum(pcs)
开发者ID:lelou6666,项目名称:PySOL,代码行数:10,代码来源:mpi.py


示例18: 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
开发者ID:vipkolon,项目名称:eqrm,代码行数:10,代码来源:just_a_parallel_spike.py


示例19: 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()
开发者ID:JoErNanO,项目名称:brian,代码行数:10,代码来源:cluster_client.py


示例20: calc_participant_list

	def calc_participant_list( s ):
		for rank in xrange( 1, mpi.size() ):
			N1 = s.Nx_sum_list[rank-1]
			N2 = s.Nx_sum_list[rank] 
			if s.gi1 >= N1 and s.gi1 <= N2: 
				start_rank = rank
			if s.gi2 >= N1 and s.gi2 <= N2: 
				end_rank = rank

		return range( start_rank, end_rank+1 )
开发者ID:wbkifun,项目名称:fdtd_accelerate,代码行数:10,代码来源:tfsf_mpi.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyparsing.col函数代码示例发布时间:2022-05-27
下一篇:
Python pypar.send函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap