memgraph/src/data_structures/union_find.hpp

91 lines
2.1 KiB
C++
Raw Normal View History

#pragma once
2015-07-01 14:38:03 +08:00
#include <memory>
#include <vector>
2015-07-01 14:38:03 +08:00
template <class uintXX_t = uint32_t>
/**
* UnionFind data structure. Provides means of connectivity
* setting and checking in O(alpha(n)) amortized complexity. Memory
* complexity is linear.
*/
class UnionFind {
public:
/**
* Constructor, creates a UnionFind structure of fixed size.
*
* @param n Number of elements in the data structure.
*/
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
explicit UnionFind(uintXX_t n) : set_count_(n), rank_(n), parent_(n) {
for (auto i = 0; i < n; ++i) rank_[i] = 0, parent_[i] = i;
}
/**
* Connects two elements (and thereby the sets they belong
* to). If they are already connected the function has no effect.
*
* Has O(alpha(n)) amortized time complexity.
*
* @param p First element.
* @param q Second element.
*/
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
void Connect(uintXX_t p, uintXX_t q) {
auto rp = Root(p);
auto rq = Root(q);
2015-07-01 14:38:03 +08:00
// if roots are equal, we don't have to do anything
if (rp == rq) return;
2015-07-01 14:38:03 +08:00
// merge the subtree with the smaller rank to the root of the subtree with
// the larger rank
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
if (rank_[rp] < rank_[rq])
parent_[rp] = rq;
else if (rank_[rp] > rank_[rq])
parent_[rq] = rp;
else
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
parent_[rq] = rp, rank_[rp] += 1;
2015-07-01 14:38:03 +08:00
// update the number of groups
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
set_count_--;
}
2015-07-01 14:38:03 +08:00
/**
* Indicates if two elements are connected. Has amortized O(alpha(n)) time
* complexity.
*
* @param p First element.
* @param q Second element.
* @return See above.
*/
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
bool Find(uintXX_t p, uintXX_t q) { return Root(p) == Root(q); }
2015-07-01 14:38:03 +08:00
/**
* Returns the number of disjoint sets in this UnionFind.
*
* @return See above.
*/
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
uintXX_t Size() const { return set_count_; }
2015-07-01 14:38:03 +08:00
private:
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
uintXX_t set_count_;
// array of subtree ranks
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
std::vector<uintXX_t> rank_;
// array of tree indices
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
std::vector<uintXX_t> parent_;
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
uintXX_t Root(uintXX_t p) {
auto r = p;
auto newp = p;
2015-07-01 14:38:03 +08:00
// find the node connected to itself, that's the root
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
while (parent_[r] != r) r = parent_[r];
2015-07-01 14:38:03 +08:00
// do some path compression to enable faster searches
Add parallel customers/Otto test Summary: Looking for connected components in a random graph. This test performs the following: - Generates a random graph that is NOT sequential in memory (otherwise itertion over edges is 2 or more times faster). - Connectivity by iterating over all the edges. - Ditto over vertices. - Ditto over vertices in parallel. Not done: - Edge filtering based on XY. I could/should add that to see how it affects perf. - Getting component info out from union-find. Local results are encouraging. Iterating over the graph is the bottleneck. Still, I get connectivity of 10M vertices/edges in <7sec (parallel over vertices). Will test on 250M remote now. Locally obtained results (20M/20M, 2 threads) ``` I1115 14:57:55.136875 357 otto_parallel.cpp:50] Generating 2000000 vertices... I1115 14:58:19.057734 357 otto_parallel.cpp:74] Generated 2000000 vertices in 23.9208 seconds. I1115 14:58:19.919221 357 otto_parallel.cpp:82] Generating 2000000 edges... I1115 14:58:39.519951 357 otto_parallel.cpp:93] Generated 2000000 edges in 19.3398 seconds. I1115 14:58:39.520349 357 otto_parallel.cpp:196] Running Edge iteration... I1115 14:58:43.857264 357 otto_parallel.cpp:199] Done in 4.33691 seconds, result: 3999860270398 I1115 14:58:43.857316 357 otto_parallel.cpp:196] Running Vertex iteration... I1115 14:58:49.498181 357 otto_parallel.cpp:199] Done in 5.64087 seconds, result: 4000090070787 I1115 14:58:49.498208 357 otto_parallel.cpp:196] Running Connected components - Edges... I1115 14:58:54.232530 357 otto_parallel.cpp:199] Done in 4.73433 seconds, result: 323935 I1115 14:58:54.232570 357 otto_parallel.cpp:196] Running Connected components - Vertices... I1115 14:59:00.412395 357 otto_parallel.cpp:199] Done in 6.17983 seconds, result: 323935 I1115 14:59:00.412422 357 otto_parallel.cpp:196] Running Parallel connected components - Vertices... I1115 14:59:04.662087 357 otto_parallel.cpp:199] Done in 4.24967 seconds, result: 323935 I1115 14:59:04.662116 357 otto_parallel.cpp:196] Running Expansion... I1115 14:59:13.913015 357 otto_parallel.cpp:199] Done in 9.25091 seconds, result: 323935 ``` Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: buda, teon.banek Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D982
2017-11-22 17:04:12 +08:00
while (p != r) newp = parent_[p], parent_[p] = r, p = newp;
2015-07-01 14:38:03 +08:00
return r;
}
2015-07-01 14:38:03 +08:00
};