<commit_before>include("../../src/SparseAccelerator.jl")
using SparseAccelerator

set_options(SA_ENABLE, SA_VERBOSE, SA_USE_SPMP, SA_CONTEXT)

maxiter = 100

function pagerank(A, p, r) # p: initial rank, r: damping factor
  set_matrix_property(Dict(
    :A => SA_SYMM_STRUCTURED | SA_SYMM_VALUED))

  bytes = maxiter*(nnz(A)*12 + size(A, 1)*3*8)

  t = time()

  for i = 1:maxiter
    Ap = (1-r)*A*p + r

    if i == maxiter
      err = norm(Ap - p)/norm(p)
      println("error = $err")
    end

    p = Ap
  end

  t = time() - t
  println("pagerank takes $t sec ($(bytes/t/1e9) gbps)")

  p
end

A = matrix_market_read(ARGS[1], true, true)
A = spones(A)

m = size(A, 1)
p = repmat([1/m], m)
r = 0.15

d = max(convert(Array{eltype(A),1}, vec(sum(A, 2))), 1) # num of neighbors
A = scale(A,1./d)

x = pagerank(A, p, r)
println("Original: ")
x = pagerank(A, p, r)

@acc x= pagerank(A, p, r)

println("\nAccelerated without reordering: ")
SparseAccelerator.reset_spmp_spmv_time()
SparseAccelerator.reset_knob_spmv_time()
@acc x= pagerank(A, p, r)
t = SparseAccelerator.get_spmp_spmv_time()
bytes = maxiter*(nnz(A)*12 + m*3*8)
println("time spent on spmp spmv $t sec ($(bytes/t/1e9) gbps)")
t = SparseAccelerator.get_knob_spmv_time()
println("time spent on knob spmv $t sec ($(bytes/t/1e9) gbps)")<commit_msg>make pagerank-without-reordering.jl work<commit_after>include("../../src/SparseAccelerator.jl")
using SparseAccelerator

set_options(SA_ENABLE, SA_VERBOSE, SA_USE_SPMP, SA_CONTEXT)

function pagerank(A, p, r, maxiter) # p: initial rank, r: damping factor
  set_matrix_property(Dict(
    :A => SA_SYMM_STRUCTURED | SA_SYMM_VALUED))

  bytes = maxiter*(nnz(A)*12 + size(A, 1)*3*8)

  t = time()

  for i = 1:maxiter
    Ap = (1-r)*A*p + r

    if i == maxiter
      err = norm(Ap - p)/norm(p)
      println("error = $err")
    end

    p = Ap
  end

  t = time() - t
  println("pagerank takes $t sec ($(bytes/t/1e9) gbps)")

  p
end

A = matrix_market_read(ARGS[1], true, true)
A = spones(A)

m = size(A, 1)
p = repmat([1/m], m)
r = 0.15

d = max(convert(Array{eltype(A),1}, vec(sum(A, 2))), 1) # num of neighbors
A = scale(A,1./d)

maxiter = 100

x = pagerank(A, p, r, maxiter)
println("Original: ")
x = pagerank(A, p, r, maxiter)

@acc x= pagerank(A, p, r, maxiter)

println("\nAccelerated without reordering: ")
SparseAccelerator.reset_spmp_spmv_time()
SparseAccelerator.reset_knob_spmv_time()
@acc x= pagerank(A, p, r, maxiter)
t = SparseAccelerator.get_spmp_spmv_time()
bytes = maxiter*(nnz(A)*12 + m*3*8)
println("time spent on spmp spmv $t sec ($(bytes/t/1e9) gbps)")
t = SparseAccelerator.get_knob_spmv_time()
println("time spent on knob spmv $t sec ($(bytes/t/1e9) gbps)")
{'fraction_non_alphanumeric': 0.16827997021593447, 'fraction_numerical': 0.022338049143708117, 'mean_word_length': 4.1772639691714835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3426799', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1158, 'n_words': 268}