def time(self, str=None): """ Return current total time. :arg string str: string to append after time. If None time printing will be suppressed. :return: Current total time as float. """ if (str is not None) and (self._lo > self._l): pio.pprint(self._tt, "s :", str) return self._tt
def reset(self, str=None): """ Resets the timer. Returns the time taken up until the reset. :arg string str: If not None will print time followed by string. """ _tt = self._tt + time.time() - self._ts self._tt = 0.0 self._ts = time.time() if (str is not None) and (self._lo > self._l): pio.pprint(_tt, "s :", str) return _tt
def _get_cell_distribution(global_cell_array=None, dims=None, top=None): # blocks per cell _bsc = [ int(math.ceil(float(global_cell_array[0]) / float(dims[0]))), int(math.ceil(float(global_cell_array[1]) / float(dims[1]))), int(math.ceil(float(global_cell_array[2]) / float(dims[2]))) ] # print dims # print _bsc # Calculate global distribution of cells _bs = [] for ix in range(3): _tmp = [] if (_bsc[ix] * (dims[ix] - 1)) < global_cell_array[ix]: for iy in range(dims[ix] - 1): _tmp.append(int(_bsc[ix])) _tmp.append(int(global_cell_array[0] - (dims[ix] - 1) * _bsc[ix])) else: R = global_cell_array[ix] % dims[ix] for iy in range(R): _tmp.append(_bsc[ix]) for iy in range(dims[ix] - R): _tmp.append( (global_cell_array[ix] - R * _bsc[ix]) // (dims[ix] - R)) assert len(_tmp) == dims[ix], "DD size missmatch, dim: " + str( ix) + " " + str(_tmp[:]) _tsum = 0 for tx in _tmp: _tsum += tx assert _tsum == global_cell_array[ ix], "DD failure to assign cells, dim: " + str(ix) + " " + str( _tmp[:]) _bs.append(_tmp) if runtime.VERBOSE > 1: pio.pprint("Cell layout", _bs) # Get local cell array local_cell_array = (_bs[0][top[0]], _bs[1][top[1]], _bs[2][top[2]]) return local_cell_array, _bs
def stop(self, str=''): """ Stop timer and print time. :arg string str: string to append after time. If None time printing will be suppressed. """ if (self._lo > self._l) and (self._running is True): self._tt += time.time() - self._ts if (self._lo > self._l) and str is not None: pio.pprint(self._tt, "s :", str) t_tmp = self._tt self._ts = 0.0 self._tt = 0.0 self._running = False return t_tmp
def tick(self): """ Method to call per iteration. """ if (self._timing is False) and (runtime.TIMER > 0): self.timer.start() self._count += 1 if (float(self._count) / self._max_it) * 100 > self._curr_p: if runtime.TIMER > 0: pio.pprint(self._curr_p, "%", self.timer.reset(), 's') else: pio.pprint(self._curr_p, "%") self._curr_p += self._p
def __init__(self, steps=None, items=None): self._s = collections.defaultdict(list) if (steps is not None) and (items is not None): assert len(steps) == len( items ), "Schedule error, mis-match between number of steps and number of items." for ix in zip(steps, items): if (ix[0] > 0) and (ix[1] is not None): assert (inspect.isfunction(ix[1]) or inspect.ismethod(ix[1])) is True, "Schedule error: Passed argument" \ " is not a function/method." self._s[ix[0]].append(ix[1]) else: pio.pprint( "Schedule warning: steps<1 and None type functions will be ignored." ) self._count = 0
def evaluate(self): """ Evaluate VAF using the current velocities held in the state with the velocities in V0. :arg double t: Time within block of integration. """ if runtime.TIMER > 0: start = time.time() _t = self._state.time _Ni = 1. / self._state.as_func('npart_local') self._datdict['VT'] = self._state.velocities self._loop.execute(None, self._datdict, {'Ni': ctypes.c_double(_Ni)}) self._V.append(self._VAF[0]) self._T.append(_t) if runtime.TIMER > 0: end = time.time() pio.pprint("VAF time taken:", end - start, "s")