Skip to content

Commit

Permalink
PageRankMatrix type
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgarbar committed Dec 2, 2023
1 parent e548294 commit faf242c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Benchmarks(

let mutable funToBenchmark = None
let mutable matrix = Unchecked.defaultof<ClMatrix<float32>>
let mutable matrixPrepared = Unchecked.defaultof<ClMatrix<float32>>
let mutable matrixPrepared = Unchecked.defaultof<PageRankMatrix<float32>>
let mutable matrixHost = Unchecked.defaultof<_>

let accuracy = 0.00000001f
Expand Down
4 changes: 2 additions & 2 deletions src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ module internal PageRank =

transposeInPlace queue DeviceOnly newMatrix
|> ClMatrix.CSR
|> PageRankMatrix
| _ -> failwith "Not implemented"

let run (clContext: ClContext) workGroupSize =
Expand All @@ -154,8 +155,7 @@ module internal PageRank =
let create =
GraphBLAS.FSharp.Vector.create clContext workGroupSize

fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<float32>) accuracy ->

fun (queue: MailboxProcessor<Msg>) (PageRankMatrix matrix) accuracy ->
let vertexCount = matrix.RowCount

//None is 0
Expand Down
33 changes: 33 additions & 0 deletions src/GraphBLAS-sharp.Backend/Objects/Matrix.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,36 @@ type ClMatrix<'a when 'a: struct> =
| ClMatrix.COO matrix -> matrix.NNZ
| ClMatrix.CSC matrix -> matrix.NNZ
| ClMatrix.LIL matrix -> matrix.NNZ

/// <summary>
/// Represents an abstraction over matrix, which is converted to correct format for PageRank algorithm
/// </summary>
type PageRankMatrix<'a when 'a: struct> =
| PageRankMatrix of ClMatrix<'a>
/// <summary>
/// Gets the number of rows in matrix.
/// </summary>
member this.RowCount =
match this with
| PageRankMatrix matrix -> matrix.RowCount

/// <summary>
/// Gets the number of columns in matrix.
/// </summary>
member this.ColumnCount =
match this with
| PageRankMatrix matrix -> matrix.ColumnCount

/// <summary>
/// Release device resources allocated for the matrix.
/// </summary>
member this.Dispose q =
match this with
| PageRankMatrix matrix -> matrix.Dispose q

/// <summary>
/// Gets the number of non-zero elements in matrix.
/// </summary>
member this.NNZ =
match this with
| PageRankMatrix matrix -> matrix.NNZ
3 changes: 2 additions & 1 deletion tests/GraphBLAS-sharp.Tests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ let algorithmsTests =
testList
"Algorithms tests"
[ Algorithms.BFS.tests
Algorithms.SSSP.tests ]
Algorithms.SSSP.tests
Algorithms.PageRank.tests ]
|> testSequenced

let deviceTests =
Expand Down

0 comments on commit faf242c

Please sign in to comment.