def update_timestep(self, yieldstep, finaltime): #LINDA: # moved the calculation so that it is done after timestep # has been broadcast # # Calculate local timestep # Domain.update_timestep(self, yieldstep, finaltime) import time t0 = time.time() # For some reason it looks like pypar only reduces numeric arrays # hence we need to create some dummy arrays for communication ltimestep = num.ones(1, num.float) ltimestep[0] = self.flux_timestep gtimestep = num.zeros(1, num.float) # Buffer for results #ltimestep = self.flux_timeste #print self.processor, ltimestep, gtimestep gtimestep = pypar.reduce(ltimestep, pypar.MIN, 0, buffer=gtimestep) #print self.processor, ltimestep, gtimestep pypar.broadcast(gtimestep, 0) #print self.processor, ltimestep, gtimestep self.flux_timestep = gtimestep[0] self.communication_reduce_time += time.time() - t0 # LINDA: # Now update time stats # Calculate local timestep Domain.update_timestep(self, yieldstep, finaltime)
def update_timestep(self, yieldstep, finaltime): #LINDA: # moved the calculation so that it is done after timestep # has been broadcast # # Calculate local timestep # Domain.update_timestep(self, yieldstep, finaltime) import time t0 = time.time() # For some reason it looks like pypar only reduces numeric arrays # hence we need to create some dummy arrays for communication ltimestep = num.ones( 1, num.float ) ltimestep[0] = self.flux_timestep gtimestep = num.zeros( 1, num.float ) # Buffer for results #ltimestep = self.flux_timeste #print self.processor, ltimestep, gtimestep gtimestep = pypar.reduce(ltimestep, pypar.MIN, 0, buffer=gtimestep) #print self.processor, ltimestep, gtimestep pypar.broadcast(gtimestep,0) #print self.processor, ltimestep, gtimestep self.flux_timestep = gtimestep[0] self.communication_reduce_time += time.time()-t0 # LINDA: # Now update time stats # Calculate local timestep Domain.update_timestep(self, yieldstep, finaltime)
def dpsi_dt(self, psi, t): """ dp_dt = dpsi_dt(psi, t) Method that serves as input to the odeint() function. Calculates dpsi/dt = -i S**-1 H(t) psi. Parameters ---------- psi : 1D complex array. Wavefunction. t : float. Time. Returns ------- dp_dt : 1D complex array. Derivative of the wavefunction. """ # #To avoid doing anything twice. (odeint tends to do that.) # #--------------------------------------------------------- # novel, result = self.check_novelty(t,psi) # if not novel: # if self.my_id == 0: # print "Time: %2.2f / %2.2f au. Runtime: %2.2f---"%( # t, self.total_duration, (time.time() - self.t_0)/60.) # self.debug_norm(t, psi, result) # # return result # ########################################################## #Making a complex array. psi_complex = psi[:len(psi)/2] + 1j * psi[len(psi)/2:] dp_dt_complex = zeros(psi_complex.shape, dtype = complex) dp_dt_buffer= zeros(psi_complex.shape, dtype = complex) #Do operations. mat_vec = self.mat_vec_product(psi_complex, t) dp_dt_complex[self.my_slice] = self.solve_overlap(-1j * mat_vec) #Add and redistribute. dp_dt_complex = pypar.reduce(dp_dt_complex, pypar.SUM, 0, buffer = dp_dt_buffer) dp_dt_buffer = dp_dt_complex.copy() dp_dt_complex = pypar.broadcast(dp_dt_buffer, 0) #Making a float array. dp_dt = r_[real(dp_dt_buffer), imag(dp_dt_buffer)] if self.my_id == 0: print "Time: %2.2f / %2.2f au. Runtime: %2.2f"%( t, self.total_duration, (time.time() - self.t_0)/60.) self.debug_norm(t, psi, dp_dt) #Store latest result. ---------------------------------- self.prev_out = dp_dt ############################3###########################3 return dp_dt
def raw_reduce(x, buffer, op, source, vanilla=0): pypar.reduce(x, op, source, buffer=buffer, vanilla=0)
for i in range(numproc): assert numpy.allclose(testArray, X[(i * M):((i + 1) * M), :]) assert numpy.allclose(X, Y) print "Gather communication of 2D numeric complex arrays OK" ######################################################## # Test reduce ####################################################### N = 17 # Number of elements # Create one (different) array on each processor # testArray = numpy.array(range(N), 'i') * (myid + 1) X = numpy.zeros(N, 'i') # Buffer for results pypar.reduce(testArray, pypar.SUM, 0, buffer=X) if myid == 0: Y = numpy.zeros(N, 'i') for i in range(numproc): Y = Y + numpy.array(range(N), 'i') * (i + 1) assert numpy.allclose(X, Y) print 'Buffered reduce using pypar.SUM OK' pypar.reduce(testArray, pypar.MAX, 0, buffer=X) if myid == 0: Y = numpy.array(range(N)) * numproc assert numpy.allclose(X, Y) print 'Buffered reduce using pypar.MAX OK' pypar.reduce(testArray, pypar.MIN, 0, buffer=X)
for i in range(numproc): assert numpy.allclose(testArray, X[(i * M): ((i+1)*M), :]) assert numpy.allclose(X, Y) print "Gather communication of 2D numeric complex arrays OK" ######################################################## # Test reduce ####################################################### N = 17 #Number of elements # Create one (different) array on each processor # testArray = numpy.array(range(N), 'i') * (myid+1) X = numpy.zeros(N, 'i') # Buffer for results pypar.reduce(testArray, pypar.SUM, 0, buffer=X) if myid == 0: Y = numpy.zeros(N, 'i') for i in range(numproc): Y = Y + numpy.array(range(N), 'i')*(i+1) assert numpy.allclose(X, Y) print 'Buffered reduce using pypar.SUM OK' pypar.reduce(testArray, pypar.MAX, 0, buffer=X) if myid == 0: Y = numpy.array(range(N))*numproc assert numpy.allclose(X, Y) print 'Buffered reduce using pypar.MAX OK' pypar.reduce(testArray, pypar.MIN, 0, buffer=X)