Skip to content

Commit b1e5f4f

Browse files
committed
Add quickgraph benchmark
1 parent d90574c commit b1e5f4f

10 files changed

Lines changed: 96 additions & 6 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"FSharp.analyzersPath": [
55
"./packages/analyzers"
66
],
7-
"FSharp.suggestSdkScripts": false
7+
"FSharp.suggestSdkScripts": false,
88
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
"problemMatcher": "$msCompile"
2222
}
2323
]
24-
}
24+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
namespace GraphBLAS.FSharp.Benchmarks
2+
3+
open GraphBLAS.FSharp
4+
open GraphBLAS.FSharp.Algorithms
5+
open BenchmarkDotNet.Attributes
6+
open BenchmarkDotNet.Configs
7+
open BenchmarkDotNet.Columns
8+
open System.IO
9+
open System
10+
open System.IO
11+
open System.Text.RegularExpressions
12+
open GraphBLAS.FSharp
13+
open GraphBLAS.FSharp.Predefined
14+
open BenchmarkDotNet.Attributes
15+
open BenchmarkDotNet.Configs
16+
open BenchmarkDotNet.Columns
17+
open BenchmarkDotNet.Filters
18+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
19+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
20+
open OpenCL.Net
21+
open GraphBLAS.FSharp.IO
22+
open QuickGraph
23+
24+
type Config2() =
25+
inherit ManualConfig()
26+
27+
do
28+
base.AddColumn(
29+
MatrixShapeColumn("RowCount", fun mtxReader -> mtxReader.ReadMatrixShape().RowCount) :> IColumn,
30+
MatrixShapeColumn("ColumnCount", fun mtxReader -> mtxReader.ReadMatrixShape().ColumnCount) :> IColumn,
31+
MatrixShapeColumn("NNZ", fun mtxReader -> mtxReader.ReadMatrixShape().Nnz) :> IColumn,
32+
TEPSColumn() :> IColumn,
33+
StatisticColumn.Min,
34+
StatisticColumn.Max
35+
) |> ignore
36+
37+
[<IterationCount(5)>]
38+
[<WarmupCount(3)>]
39+
[<Config(typeof<Config2>)>]
40+
type QGBenchmarks() =
41+
let random = Random()
42+
43+
let graph = AdjacencyGraph<int, Edge<int>>(false)
44+
let mutable source = 0
45+
let mutable bfs = Unchecked.defaultof<Algorithms.Search.BreadthFirstSearchAlgorithm<int, Edge<int>>>
46+
47+
[<ParamsSource("InputMatricesProvider")>]
48+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
49+
50+
[<GlobalSetup>]
51+
member this.BuildMatrixAndSetSource() =
52+
let matrix = this.InputMatrixReader.ReadMatrixBoolean(fun _ -> true)
53+
54+
match matrix with
55+
| MatrixCSR csr -> failwith "Not implemented"
56+
| MatrixCOO coo ->
57+
for i = 0 to coo.Values.Length - 1 do
58+
graph.AddVerticesAndEdge(Edge(coo.Rows.[i], coo.Columns.[i])) |> ignore
59+
60+
source <- random.Next <| Matrix.rowCount matrix
61+
bfs <- Algorithms.Search.BreadthFirstSearchAlgorithm(graph)
62+
63+
[<Benchmark>]
64+
member this.LevelBFS() =
65+
bfs.Compute(source)
66+
67+
static member InputMatricesProvider =
68+
"BFSBenchmarks.txt"
69+
|> Utils.getMatricesFilenames
70+
|> Seq.map
71+
(fun matrixFilename ->
72+
match Path.GetExtension matrixFilename with
73+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix "BFSDatasets" matrixFilename)
74+
| _ -> failwith "Unsupported matrix format"
75+
)

benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<Compile Include="Helpers.fs" />
1818
<Compile Include="BenchmarksBFS.fs" />
1919
<Compile Include="BenchmarksEWiseAdd.fs" />
20+
<Compile Include="BenchmarksQG.fs" />
2021
<Compile Include="Program.fs" />
2122
</ItemGroup>
2223
<Import Project="..\..\.paket\Paket.Restore.targets" />
23-
</Project>
24+
</Project>

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ let main argv =
66
let benchmarks = BenchmarkSwitcher [|
77
// typeof<EWiseAddBenchmarks4Float32>
88
// typeof<EWiseAddBenchmarks4Bool>
9-
typeof<BFSBenchmarks>
9+
// typeof<BFSBenchmarks>
10+
typeof<QGBenchmarks>
1011
|]
1112

1213
benchmarks.Run argv |> ignore

benchmarks/GraphBLAS-sharp.Benchmarks/paket.references

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Microsoft.NETFramework.ReferenceAssemblies
33
BenchmarkDotNet
44
MathNet.Numerics.FSharp
55
MathNet.Numerics.MKL.Win-x64
6+
YC.QuickGraph

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ nuget BenchmarkDotNet
2323
nuget MathNet.Numerics.FSharp
2424
nuget MathNet.Numerics.MKL.Win-x64 2.5.0
2525
nuget TypeShape 9.0.0
26+
nuget YC.QuickGraph 3.7.4
2627

2728
// [ FAKE GROUP ]
2829
group Build

paket.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ NUGET
6565
Microsoft.NETCore.App (>= 2.0) - restriction: >= netcoreapp2.0
6666
System.Runtime.Loader (>= 4.3) - restriction: && (>= netcoreapp1.0) (< netcoreapp2.0)
6767
System.ValueTuple (>= 4.4) - restriction: && (>= netcoreapp1.0) (< netcoreapp2.0)
68+
DotNet.Contracts (1.10.20606.1)
69+
DotParser (1.1)
70+
System.ValueTuple (>= 4.5) - restriction: >= net461
6871
Expecto (8.13.1)
6972
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.0)
7073
Mono.Cecil (>= 0.11) - restriction: || (>= net461) (>= netstandard2.0)
@@ -930,6 +933,10 @@ NUGET
930933
ExtraConstraints.Fody (>= 1.14) - restriction: >= netstandard2.0
931934
Microsoft.Build.Framework (>= 16.6) - restriction: >= netstandard2.0
932935
System.CodeDom (>= 4.7) - restriction: >= netstandard2.0
936+
YC.QuickGraph (3.7.4)
937+
DotNet.Contracts
938+
DotParser (>= 1.0.6)
939+
FSharp.Core
933940
YoloDev.Expecto.TestSdk (0.8)
934941
Expecto (>= 8.10 < 9.0) - restriction: || (>= net461) (>= netcoreapp2.0)
935942
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netcoreapp2.0)

src/GraphBLAS-sharp/IO/MtxReader.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type MtxReader(pathToFile: string) =
2323
member this.Field = field
2424
member this.Symmetry = symmetry
2525

26+
override this.ToString() =
27+
Path.GetFileName pathToFile
28+
2629
member this.ReadMatrixShape() =
2730
use streamReader = new StreamReader(pathToFile)
2831
while streamReader.Peek() = int '%' do

src/GraphBLAS-sharp/Operations/Matrix.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ module Matrix =
3737
methods
3838
*)
3939

40-
let rowCount (matrix: Matrix<'a>) : int = failwith "Not Implemented yet"
41-
let columnCount (matrix: Matrix<'a>) : int = failwith "Not Implemented yet"
40+
let rowCount (matrix: Matrix<'a>) : int = matrix.RowCount
41+
let columnCount (matrix: Matrix<'a>) : int = matrix.ColumnCount
42+
4243
let copy (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
4344
let resize (rowCount: int) (columnCount: int) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
4445

0 commit comments

Comments
 (0)