From c6a8f62d7b8784ffdf27229fa711f990b5793c19 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 4 Oct 2022 15:35:05 +0200 Subject: Added cheap parallelization. --- order.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'order.cpp') diff --git a/order.cpp b/order.cpp index 3ca57af..c2deb38 100644 --- a/order.cpp +++ b/order.cpp @@ -25,8 +25,14 @@ int main(int argc, char* argv[]) { Rng r; Graph G(n, r); - std::vector data(G.vertices.size() / 2); +#pragma omp declare reduction(vec_int_plus : std::vector : \ + std::transform(omp_out.begin(), omp_out.end(), omp_in.begin(), omp_out.begin(), std::plus())) \ + initializer(omp_priv = decltype(omp_orig)(omp_orig.size())) + std::vector data_x(G.vertices.size() / 2); + std::vector data_y(G.vertices.size() / 2); + +#pragma omp parallel for reduction(vec_int_plus : data_x) reduction(vec_int_plus : data_y) for (unsigned i = 0; i < m; i++) { PerfectMatching pm(G.vertices.size(), G.edges.size()); @@ -40,15 +46,17 @@ int main(int argc, char* argv[]) { for (unsigned i = 0; i < G.vertices.size() / 2; i++) { unsigned j = pm.GetMatch(i); - data[i] += G.vertices[i].coordinate; - data[i] -= G.vertices[j].coordinate; + data_x[i] += G.vertices[i].coordinate[0]; + data_y[i] += G.vertices[i].coordinate[1]; + data_x[i] -= G.vertices[j].coordinate[0]; + data_y[i] -= G.vertices[j].coordinate[1]; } } std::cout << n << std::endl; for (unsigned i = 0; i < G.vertices.size() / 2; i++) { - std::cout << data[i][0] << " " << data[i][1] << std::endl; + std::cout << data_x[i] << " " << data_y[i] << std::endl; } return 0; -- cgit v1.2.3-54-g00ecf