Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion benchmarks/benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
using FixedEffects, Random, Statistics
using FixedEffects, Random, Statistics, BenchmarkTools, GroupedArrays
Random.seed!(1234)


function scatter!(y::AbstractVector, α::Number, fecoef::AbstractVector,
refs::AbstractVector, cache::AbstractVector; chunksize = 1_000_000)
GroupedArrays.@spawn_for_chunks chunksize for i in eachindex(y)
@inbounds y[i] += α * fecoef[refs[i]] * cache[i]
end
end

n = 10_000_000
N = 1_000_000
refs = rand(1:N, n)
fecoef = rand(N)
cache = rand(n)
y = zeros(n)
@btime scatter!(y, 1.0, fecoef, refs, cache; chunksize = 1_000_000)
@btime scatter!(y, 1.0, fecoef, refs, cache; chunksize = 100_000)



N = 10000000
K = 100
id1 = rand(1:div(N, K), N)
Expand Down
4 changes: 2 additions & 2 deletions src/SolverCPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end

function scatter!(y::AbstractVector, α::Number, fecoef::AbstractVector,
refs::AbstractVector, cache::AbstractVector)
@spawn_for_chunks 1_000_000 for i in eachindex(y)
@spawn_for_chunks 100_000 for i in eachindex(y)
@inbounds y[i] += α * fecoef[refs[i]] * cache[i]
end
end
Expand Down Expand Up @@ -85,7 +85,7 @@ function scale!(scale::AbstractVector, refs::AbstractVector, interaction::Abstra
end

function cache!(cache::AbstractVector, refs::AbstractVector, interaction::AbstractVector, weights::AbstractVector, scale::AbstractVector)
@spawn_for_chunks 1_000_000 for i in eachindex(cache)
@spawn_for_chunks 100_000 for i in eachindex(cache)
@inbounds @fastmath cache[i] = interaction[i] * sqrt(weights[i]) * scale[refs[i]]
end
end
Expand Down