Skip to content

Instantly share code, notes, and snippets.

@maartenvd
Created May 26, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maartenvd/86b90c530535d605507ad7641a6437bf to your computer and use it in GitHub Desktop.
Save maartenvd/86b90c530535d605507ad7641a6437bf to your computer and use it in GitHub Desktop.
using Base.Threads;
struct SimpleType{T}
a::Vector{Matrix{T}}
end
Base.length(t::SimpleType) = length(t.a)
Base.getindex(t::SimpleType,i) = t.a[i];
function functional_eigprob(fun,vector)
#very simplified powermethod
fun(fun(vector))
end
function dofun(state::SimpleType)
for i in 1:10
jobs = map(1:length(state)) do loc
vec = rand(5);
acjob = @Threads.spawn functional_eigprob(vec) do x
@show threadid(),pointer_from_objref(state[1])
state[loc]*x
end
acjob
end
fetch.(jobs)
state = SimpleType([rand(5,5) for i in 1:10]);
@show pointer_from_objref(state[1])
end
end
dofun(SimpleType([rand(5,5) for i in 1:10]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment