Skip to content

Commit 468742c

Browse files
Slightly tigthen mem. est
1 parent 3b02a0b commit 468742c

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

algo/src/main/java/org/neo4j/gds/harmonic/HarmonicCentralityAlgorithmEstimateDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020
package org.neo4j.gds.harmonic;
2121

22-
import org.neo4j.gds.mem.MemoryEstimateDefinition;
2322
import org.neo4j.gds.collections.haa.HugeAtomicDoubleArray;
23+
import org.neo4j.gds.mem.MemoryEstimateDefinition;
2424
import org.neo4j.gds.mem.MemoryEstimation;
2525
import org.neo4j.gds.mem.MemoryEstimations;
2626
import org.neo4j.gds.msbfs.MSBFSMemoryEstimation;
@@ -31,7 +31,7 @@ public final class HarmonicCentralityAlgorithmEstimateDefinition implements Memo
3131
public MemoryEstimation memoryEstimation() {
3232
return MemoryEstimations.builder(HarmonicCentrality.class)
3333
.perNode("inverse farness", HugeAtomicDoubleArray::memoryEstimation)
34-
.add("MSBFS", MSBFSMemoryEstimation.MSBFSWithANPStrategy())
34+
.add("MSBFS", MSBFSMemoryEstimation.MSBFSWithANPStrategy(0))
3535
.build();
3636
}
3737

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,38 @@
2020
package org.neo4j.gds.msbfs;
2121

2222
import org.neo4j.gds.collections.ha.HugeLongArray;
23+
import org.neo4j.gds.mem.Estimate;
2324
import org.neo4j.gds.mem.MemoryEstimation;
2425
import org.neo4j.gds.mem.MemoryEstimations;
2526

2627
public final class MSBFSMemoryEstimation {
2728

2829
private MSBFSMemoryEstimation() {}
2930

30-
private static MemoryEstimations.Builder MSBFS(){
3131

32-
return MemoryEstimations.builder(MultiSourceBFSAccessMethods.class)
32+
private static MemoryEstimations.Builder MSBFS(int sourceNodes){
33+
var runnable = MemoryEstimations.builder(MultiSourceBFSRunnable.class).build();
34+
35+
var builder = MemoryEstimations.builder(MultiSourceBFSAccessMethods.class)
3336
.perThread("visits", HugeLongArray::memoryEstimation)
3437
.perThread("visitsNext", HugeLongArray::memoryEstimation)
35-
.perThread("seens", HugeLongArray::memoryEstimation);
38+
.perThread("seens", HugeLongArray::memoryEstimation)
39+
.perThread("runnable", runnable);
40+
41+
if (sourceNodes > 0 ) {
42+
builder.fixed("source nodes", Estimate.sizeOfLongArray(sourceNodes));
43+
}
44+
45+
return builder;
3646
}
3747

38-
public static MemoryEstimation MSBFSWithPredecessorStrategy(){
39-
return MSBFS()
48+
public static MemoryEstimation MSBFSWithPredecessorStrategy(int sourceNodes){
49+
return MSBFS(sourceNodes)
4050
.perThread("seenNext", HugeLongArray::memoryEstimation)
4151
.build();
4252
}
43-
public static MemoryEstimation MSBFSWithANPStrategy(){
44-
return MSBFS()
53+
public static MemoryEstimation MSBFSWithANPStrategy(int sourceNodes){
54+
return MSBFS(sourceNodes)
4555
.build();
4656
}
4757
}

algo/src/test/java/org/neo4j/gds/harmonic/HarmonicCentralityAlgorithmEstimateDefinitionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class HarmonicCentralityAlgorithmEstimateDefinitionTest {
2929

3030
@ParameterizedTest
3131
@CsvSource({
32-
"10_000, 1, 80304",
33-
"10_000, 4, 80376",
34-
"500_000, 4, 4000376",
35-
"10_000_000, 4, 80000376",
36-
"10_000, 2, 80328",
37-
"10_000, 128, 83352"
32+
"10_000, 1, 80_368",
33+
"10_000, 4, 80_632",
34+
"500_000, 4, 4_000_632",
35+
"10_000_000, 4, 80_000_632",
36+
"10_000, 2, 80_456",
37+
"10_000, 128, 91_544"
3838
})
3939
void testMemoryEstimation(long nodeCount, int concurrency, long expectedMemory) {
4040
var memoryEstimation = new HarmonicCentralityAlgorithmEstimateDefinition().memoryEstimation();

algo/src/test/java/org/neo4j/gds/msbfs/MSBFSMemoryEstimationTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,27 @@ class MSBFSMemoryEstimationTest {
2929

3030
@ParameterizedTest
3131
@CsvSource({
32-
"100,1,264",
33-
"100,4,360"
32+
"100,1,0, 328",
33+
"100,1,10, 424",
34+
"100,4,0, 616",
35+
"100,4,10, 712"
36+
3437
})
35-
void shouldWorkForPredecessor(long nodeCount, int concurrency, long expectedMemory){
36-
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithPredecessorStrategy())
38+
void shouldWorkForPredecessor(long nodeCount, int concurrency, int sourceNodesSize, long expectedMemory){
39+
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithPredecessorStrategy(sourceNodesSize))
3740
.memoryRange(GraphDimensions.of(nodeCount),new Concurrency(concurrency))
3841
.hasSameMinAndMaxEqualTo(expectedMemory);
3942
}
4043

4144
@ParameterizedTest
4245
@CsvSource({
43-
"100,1,216",
44-
"100,4,288"
46+
"100,1,0,280",
47+
"100,1,10,376",
48+
"100,4,0,544",
49+
"100,4,10,640"
4550
})
46-
void shouldWorkForANP(long nodeCount, int concurrency, long expectedMemory){
47-
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithANPStrategy())
51+
void shouldWorkForANP(long nodeCount, int concurrency, int sourceNodesSize, long expectedMemory){
52+
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithANPStrategy(sourceNodesSize))
4853
.memoryRange(GraphDimensions.of(nodeCount),new Concurrency(concurrency))
4954
.hasSameMinAndMaxEqualTo(expectedMemory);
5055
}

0 commit comments

Comments
 (0)