summaryrefslogtreecommitdiff
path: root/order.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2022-10-04 15:35:05 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2022-10-04 15:35:05 +0200
commitc6a8f62d7b8784ffdf27229fa711f990b5793c19 (patch)
treebfb5e7e8a4f7cbfd649b03590aae91b74c1cb039 /order.cpp
parent352e1be1bf05de2ba75f93b8375ac52036c8203e (diff)
downloadcode-c6a8f62d7b8784ffdf27229fa711f990b5793c19.tar.gz
code-c6a8f62d7b8784ffdf27229fa711f990b5793c19.tar.bz2
code-c6a8f62d7b8784ffdf27229fa711f990b5793c19.zip
Added cheap parallelization.
Diffstat (limited to 'order.cpp')
-rw-r--r--order.cpp16
1 files changed, 12 insertions, 4 deletions
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<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;