level.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:Fluid2d 作者: pvthinker 项目源码 文件源码
def norm(self,x):
        """ norm = sum(x*x) """
        nbduplicates = (self.np0*self.mp0)/(self.np*self.mp)
        # computenorm is done in Fortran
        self.typenorm='l2'
        t0 = time()           
#        MPI.COMM_WORLD.Barrier()
        if self.typenorm=='l2':
            local_sum = computenorm(self.msk,x,self.nh)
            t1 = time()
            self.time['norm']+=t1-t0
            self.ncalls['norm']+=1
            z=MPI.COMM_WORLD.allreduce(local_sum,op=MPI.SUM)/ nbduplicates            
            z=sqrt(z)
            t0 = time()
            self.time['reduce']+=t0-t1
            self.ncalls['reduce']+=1

        if self.typenorm=='inf':
            local_z= computemax(self.msk,x,self.nh)
            t1 = time()
            self.time['norm']+=t1-t0
            self.ncalls['norm']+=1
            z=MPI.COMM_WORLD.allreduce(local_z,op=MPI.MAX)
            t0 = time()
            self.time['reduce']+=t0-t1
            self.ncalls['reduce']+=1
        return z
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号