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. --- Makefile | 2 +- order.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 3c6169b..84be93f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ BLOSSOM_DIRS := $(BLOSSOM_DIR) $(BLOSSOM_DIR)/MinCost $(BLOSSOM_DIR)/GEOM BLOSSOM_SOURCES := $(filter-out $(BLOSSOM_DIR)/example.cpp, $(foreach dir, $(BLOSSOM_DIRS), $(wildcard $(dir)/*.cpp))) BLOSSOM_OBJS := $(patsubst %.cpp, %.o, $(BLOSSOM_SOURCES)) -CFLAGS := -flto -O3 -Os -march=native -D_NDEBUG -DPERFECT_MATCHING_DOUBLE +CFLAGS := -flto -fopenmp -O3 -Os -march=native -D_NDEBUG -DPERFECT_MATCHING_DOUBLE CXX = clang++ LD = ld.lld LIBS := -lrt 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-70-g09d2