Skip to content

Commit 5c66e6a

Browse files
Merge pull request #10743 from IoannisPanagiotas/add-msbfs-mem-est
MSBFS mem Estimation
2 parents 1421b13 + d9ab165 commit 5c66e6a

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.msbfs;
21+
22+
import org.neo4j.gds.collections.ha.HugeLongArray;
23+
import org.neo4j.gds.mem.MemoryEstimation;
24+
import org.neo4j.gds.mem.MemoryEstimations;
25+
26+
public final class MSBFSMemoryEstimation {
27+
28+
private MSBFSMemoryEstimation() {}
29+
30+
private static MemoryEstimations.Builder MSBFS(){
31+
32+
return MemoryEstimations.builder(MultiSourceBFSAccessMethods.class)
33+
.perThread("visits", HugeLongArray::memoryEstimation)
34+
.perThread("visitsNext", HugeLongArray::memoryEstimation)
35+
.perThread("seens", HugeLongArray::memoryEstimation);
36+
}
37+
38+
static MemoryEstimation MSBFSWithPredecessorStrategy(){
39+
return MSBFS()
40+
.perThread("seenNext", HugeLongArray::memoryEstimation)
41+
.build();
42+
}
43+
static MemoryEstimation MSBFSWithANPStrategy(){
44+
return MSBFS()
45+
.build();
46+
}
47+
}

algo/src/main/java/org/neo4j/gds/msbfs/SourceNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
package org.neo4j.gds.msbfs;
2121

22-
final class SourceNodes implements BfsSources {
22+
public final class SourceNodes implements BfsSources {
2323
private final long[] sourceNodes;
2424
private final int maxPos;
2525
private final int startPos;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.msbfs;
21+
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.CsvSource;
24+
import org.neo4j.gds.assertions.MemoryEstimationAssert;
25+
import org.neo4j.gds.core.GraphDimensions;
26+
import org.neo4j.gds.core.concurrency.Concurrency;
27+
28+
class MSBFSMemoryEstimationTest {
29+
30+
@ParameterizedTest
31+
@CsvSource({
32+
"100,1,264",
33+
"100,4,360"
34+
})
35+
void shouldWorkForPredecessor(long nodeCount, int concurrency, long expectedMemory){
36+
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithPredecessorStrategy())
37+
.memoryRange(GraphDimensions.of(nodeCount),new Concurrency(concurrency))
38+
.hasSameMinAndMaxEqualTo(expectedMemory);
39+
}
40+
41+
@ParameterizedTest
42+
@CsvSource({
43+
"100,1,216",
44+
"100,4,288"
45+
})
46+
void shouldWorkForANP(long nodeCount, int concurrency, long expectedMemory){
47+
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithANPStrategy())
48+
.memoryRange(GraphDimensions.of(nodeCount),new Concurrency(concurrency))
49+
.hasSameMinAndMaxEqualTo(expectedMemory);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)