968aa4926a
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
81 lines
1.7 KiB
C++
81 lines
1.7 KiB
C++
#include <stdlib.h>
|
|
#include <iostream>
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "data_structures/union_find.hpp"
|
|
|
|
void ExpectFully(UnionFind<> &uf, bool connected, int from = 0, int to = -1) {
|
|
if (to == -1) to = uf.Size();
|
|
|
|
for (int i = from; i < to; i++)
|
|
for (int j = from; j < to; j++)
|
|
if (i != j) EXPECT_EQ(uf.Find(i, j), connected);
|
|
}
|
|
|
|
TEST(UnionFindTest, InitialSizeTest) {
|
|
for (int i = 0; i < 10; i++) {
|
|
UnionFind<> uf(i);
|
|
EXPECT_EQ(i, uf.Size());
|
|
}
|
|
}
|
|
|
|
TEST(UnionFindTest, ModifiedSizeTest) {
|
|
UnionFind<> uf(10);
|
|
EXPECT_EQ(10, uf.Size());
|
|
|
|
uf.Connect(0, 0);
|
|
EXPECT_EQ(10, uf.Size());
|
|
|
|
uf.Connect(0, 1);
|
|
EXPECT_EQ(9, uf.Size());
|
|
|
|
uf.Connect(2, 3);
|
|
EXPECT_EQ(8, uf.Size());
|
|
|
|
uf.Connect(0, 2);
|
|
EXPECT_EQ(7, uf.Size());
|
|
|
|
uf.Connect(1, 3);
|
|
EXPECT_EQ(7, uf.Size());
|
|
}
|
|
|
|
TEST(UnionFindTest, Disconectivity) {
|
|
UnionFind<> uf(10);
|
|
ExpectFully(uf, false);
|
|
}
|
|
|
|
TEST(UnionFindTest, ConnectivityAlongChain) {
|
|
UnionFind<> uf(10);
|
|
for (unsigned int i = 1; i < uf.Size(); i++) uf.Connect(i - 1, i);
|
|
ExpectFully(uf, true);
|
|
}
|
|
|
|
TEST(UnionFindTest, ConnectivityOnTree) {
|
|
UnionFind<> uf(10);
|
|
ExpectFully(uf, false);
|
|
|
|
uf.Connect(0, 1);
|
|
uf.Connect(0, 2);
|
|
ExpectFully(uf, true, 0, 3);
|
|
ExpectFully(uf, false, 2);
|
|
|
|
uf.Connect(2, 3);
|
|
ExpectFully(uf, true, 0, 4);
|
|
ExpectFully(uf, false, 3);
|
|
}
|
|
|
|
TEST(UnionFindTest, DisjointChains) {
|
|
UnionFind<> uf(30);
|
|
for (int i = 0; i < 30; i++) uf.Connect(i, i % 10 == 0 ? i : i - 1);
|
|
|
|
for (int i = 0; i < 30; i++)
|
|
for (int j = 0; j < 30; j++)
|
|
EXPECT_EQ(uf.Find(i, j), (j - (j % 10)) == (i - (i % 10)));
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|