def check_synced(self): synced = True if self._is_root(): vars = self._get_flat_vars() MPIUtil.bcast(vars) else: vars_local = self._get_flat_vars() vars_root = np.empty_like(vars_local) MPIUtil.bcast(vars_root) synced = (vars_local == vars_root).all() return synced
def check_synced(self): synced = True if MPIUtil.is_root_proc(): vars = np.concatenate([self.mean, self.mean_sq]) MPIUtil.bcast(vars) else: vars_local = np.concatenate([self.mean, self.mean_sq]) vars_root = np.empty_like(vars_local) MPIUtil.bcast(vars_root) synced = (vars_local == vars_root).all() return synced
def save_records(self, filename): def numpy_1d_array_to_string(arr): line = '' arr = list(arr) for i in range(0, len(arr)): if i < len(arr) - 1: line += '{:.10}'.format(arr[i]) + ' ' else: line += '{:.10}'.format(arr[i]) return line trajectories_list = MPIUtilExtend.gather(self._trajectories) if MPIUtil.is_root_proc(): trajectories = trajectories_list[0] for i in range(1, len(trajectories_list)): trajectories += trajectories_list[i] with open(filename, 'w') as fout: for records in trajectories: for record in records: line = '' for entry in record: line += numpy_1d_array_to_string(entry) + '\n' fout.write(line) fout.write('\n') self._record_smaple_count += len(records) _root_sample_count = np.array(self._record_smaple_count, dtype=np.float32) MPIUtil.bcast(_root_sample_count) else: _root_sample_count = np.array([0], dtype=np.float32) MPIUtil.bcast(_root_sample_count) self._record_smaple_count = int(_root_sample_count[0]) Logger.print('Record Sample Count: ' + str(self._record_smaple_count)) self._trajectories.clear() return
def sync(self): vars = self._get_flat_vars() MPIUtil.bcast(vars) self._set_flat_vars(vars) return