Skip to content

Commit 86c5614

Browse files
authored
Merge pull request #21 from dpanfilyonok/bfs-benchmark
Merged operations implementation and BFS benchmarks added
2 parents 2027a50 + a8443dd commit 86c5614

86 files changed

Lines changed: 5947 additions & 4317190 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,6 @@ coverage.*.xml
268268
.paket/paket
269269

270270
BenchmarkDotNet.Artifacts/
271+
272+
# Folder for datasets
273+
benchmarks/GraphBLAS-sharp.Benchmarks/Datasets

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3+
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4+
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
"program": "${workspaceFolder}/tests/GraphBLAS-sharp.Tests/bin/Debug/netcoreapp3.1/GraphBLAS-sharp.Tests.dll",
13+
"args": [],
14+
"cwd": "${workspaceFolder}",
15+
"stopAtEntry": false,
16+
"console": "internalConsole"
17+
}
18+
]
19+
}

.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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "build",
8+
"command": "dotnet",
9+
"type": "shell",
10+
"args": [
11+
"build",
12+
// Ask dotnet build to generate full paths for file names.
13+
"/property:GenerateFullPaths=true",
14+
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
15+
"/consoleloggerparameters:NoSummary"
16+
],
17+
"group": "build",
18+
"presentation": {
19+
"reveal": "silent"
20+
},
21+
"problemMatcher": "$msCompile"
22+
}
23+
]
24+
}

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,85 @@ open BenchmarkDotNet.Configs
77
open BenchmarkDotNet.Columns
88
open System.IO
99
open System
10+
open System.Text.RegularExpressions
11+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
12+
open OpenCL.Net
13+
open GraphBLAS.FSharp.IO
14+
open QuickGraph
1015

11-
[<SimpleJob(targetCount=10)>]
12-
type BFSBenchmark4CSRMatrix() =
16+
[<Config(typeof<CommonConfig>)>]
17+
type BFSBenchmarks() =
1318
let random = Random()
1419

15-
let mutable matrix = Unchecked.defaultof<Matrix<bool>>
1620
let mutable source = 0
1721

18-
[<ParamsSource("GraphPaths")>]
19-
member val PathToGraph = "" with get, set
22+
// gb
23+
let mutable matrix = Unchecked.defaultof<Matrix<int>>
24+
25+
// qg
26+
let graph = AdjacencyGraph<int, Edge<int>>(false)
27+
let mutable bfs = Unchecked.defaultof<Algorithms.Search.BreadthFirstSearchAlgorithm<int, Edge<int>>>
28+
29+
[<ParamsSource("AvaliableContextsProvider")>]
30+
member val OclContext = Unchecked.defaultof<ClContext> with get, set
31+
member this.Context =
32+
let (ClContext context) = this.OclContext
33+
context
34+
35+
[<ParamsSource("InputMatricesProvider")>]
36+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
2037

2138
[<GlobalSetup>]
22-
member this.BuildMatrix() =
23-
matrix <- MatrixCSR <| CSRMatrix.FromFile this.PathToGraph
39+
member this.BuildGraph() =
40+
let inputMatrix = this.InputMatrixReader.ReadMatrix(fun _ -> 1)
41+
42+
matrix <-
43+
graphblas {
44+
return! Matrix.switch CSR inputMatrix
45+
>>= Matrix.synchronizeAndReturn
46+
}
47+
|> EvalGB.withClContext this.Context
48+
|> EvalGB.runSync
49+
50+
match inputMatrix with
51+
| MatrixCSR csr -> failwith "Not implemented"
52+
| MatrixCOO coo ->
53+
for i = 0 to coo.Values.Length - 1 do
54+
graph.AddVerticesAndEdge(Edge(coo.Rows.[i], coo.Columns.[i])) |> ignore
55+
56+
bfs <- Algorithms.Search.BreadthFirstSearchAlgorithm(graph)
57+
58+
[<IterationSetup>]
59+
member this.SetSource() =
2460
source <- random.Next <| Matrix.rowCount matrix
2561

2662
[<Benchmark>]
27-
member this.LevelBFS() =
63+
member this.GraphblasLevelBFS() =
2864
BFS.levelSingleSource matrix source
65+
|> EvalGB.withClContext this.Context
66+
|> EvalGB.runSync
67+
68+
[<Benchmark>]
69+
member this.QuickGraphBFS() =
70+
bfs.Compute(source)
71+
72+
[<IterationCleanup>]
73+
member this.ClearBuffers() =
74+
this.Context.Provider.CloseAllBuffers()
75+
76+
[<GlobalCleanup>]
77+
member this.ClearContext() =
78+
let (ClContext context) = this.OclContext
79+
context.Provider.Dispose()
80+
81+
static member AvaliableContextsProvider = Utils.avaliableContexts
2982

30-
/// Sequence of paths to files where data for benchmarking will be taken from
31-
static member GraphPaths = seq {
32-
// Gets all mtx files from following directory
33-
yield! Directory.EnumerateFiles(Path.Combine [|"Datasets"; "1"|], "*.mtx")
34-
}
83+
static member InputMatricesProvider =
84+
"Common.txt"
85+
|> Utils.getMatricesFilenames
86+
|> Seq.map
87+
(fun matrixFilename ->
88+
match Path.GetExtension matrixFilename with
89+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix "Common" matrixFilename)
90+
| _ -> failwith "Unsupported matrix format"
91+
)

0 commit comments

Comments
 (0)