g = GaussSolver(np.array(rows), comm, n) res = g.calc() print(formatting(comm.rank, format_action('result', rows=res))) for proc in range(1, comm.size): res += comm.recv(source=proc) res.sort(key=lambda row: row[-1]) x = [] for row in res: x.append(row[0]) totalTimer.finish() print(formatting(comm.rank, format_action('result'))) write_vector(x, out) print(formatting(comm.rank, format_action('answer', x=x))) else: procTimer = Timer('proc{}'.format(comm.rank)) n = comm.bcast(None, root=MASTER) step = n // comm.size if not step: sys.exit()
) square = ProcSquare( full_region=Region(right=cols, bottom=rows), region=region, left_top=point, step_x=step_x, step_y=step_y ) print formatting(comm.rank, '\n$\tcoord:\t{0}\n$\tregion:\t{1}\n$\tpoint:\t{2}'.format(coords, region, point)) cart_comm.barrier() iterations = 0 if comm.rank == master: t_init.finish(comm.rank) t_calc = Timer('calculation') while min_diff > epsilon: square.exch(cart_comm) square.calc() diff = square.diff iterations += 1 min_diff = cart_comm.allreduce(diff, op=MPI.MAX) if comm.rank == master: t_calc.finish(master) t_calc = Timer('collecting results') results = [] for i in range(rows):
for i in range(step): comm.send(A[cur + i] + [cur + i], dest=proc) # send row with index as last element cur += step inversed = _do_inversion(comm, rows) A_inv = inversed for proc in range(1, comm.size): A_inv += comm.recv(source=proc) A_inv.sort(key=lambda row: row[-1]) A_inv = np.delete(A_inv, -1, 1) print(formatting(comm.rank, format_action('merge results'))) t_inv.finish() write_matrix(A_inv, out) x = np.dot(A_inv, b) print( formatting(comm.rank, format_action('product A_inv on b', x=x.tolist()))) out.write(('{}\n' + '{:.3f}\t' * len(x)).format(1, *x)) t.finish() else: t = Timer('proc{}'.format(comm.rank)) n = comm.bcast(None, root=master) step = n / comm.size if not step:
diff_proc_max = dm diff_max_global = comm.reduce(diff_proc_max, op=MPI.MAX, root=MASTER) diff_max_global = comm.bcast(diff_max_global, root=MASTER) iter += 1 if comm.rank == MASTER: print(f'[END] iterations: {iter}') with open('output.txt', 'w') as file: for i in range(n // comm.size + 1): for j in range(N): file.write(f'{u[i, j]} ') vec = np.zeros(N) for k in range(1, comm.size): size = (n // comm.size + 2) if k == LAST else (n // comm.size + 1) for i in range(1, size): vec = comm.recv(source=k) for val in vec: file.write(f'{val} ') totalTimer.finish() else: for i in range((n // comm.size + 2) if comm.rank == LAST else (n // comm.size + 1)): comm.send(u[i], dest=MASTER)