diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-10-04 15:35:05 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-10-04 15:35:05 +0200 |
commit | c6a8f62d7b8784ffdf27229fa711f990b5793c19 (patch) | |
tree | bfb5e7e8a4f7cbfd649b03590aae91b74c1cb039 | |
parent | 352e1be1bf05de2ba75f93b8375ac52036c8203e (diff) | |
download | code-c6a8f62d7b8784ffdf27229fa711f990b5793c19.tar.gz code-c6a8f62d7b8784ffdf27229fa711f990b5793c19.tar.bz2 code-c6a8f62d7b8784ffdf27229fa711f990b5793c19.zip |
Added cheap parallelization.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | order.cpp | 16 |
2 files changed, 13 insertions, 5 deletions
@@ -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
@@ -25,8 +25,14 @@ int main(int argc, char* argv[]) { Rng r; Graph G(n, r); - std::vector<Coordinate> data(G.vertices.size() / 2); +#pragma omp declare reduction(vec_int_plus : std::vector<long int> : \ + std::transform(omp_out.begin(), omp_out.end(), omp_in.begin(), omp_out.begin(), std::plus<long int>())) \ + initializer(omp_priv = decltype(omp_orig)(omp_orig.size())) + std::vector<long int> data_x(G.vertices.size() / 2); + std::vector<long int> 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; |