Fazeleh
Fazeleh

Reputation: 1128

How can we call SharedArray in Julia?

I have a function and I want to call it in the main function. all of arguments is sharedArray and we have one variable that is type. when I want to run the program I got an error.

@everywhere type dty{T <: Real}
    ...... (some variable)
end

@everywhere function func2!(v::dty,
                          out::SharedArray,
                          out2::SharedArray)
........
end

function func1()
...
out    = SharedArray{Float64,2}(n,m)
out2   = SharedArray{Float64,2}(n,m)
......
func2!(v , out, out2)
end

Error:

MethodError: no method matching func2!(::dty{Float64}, ::Array{Float64,2}, ::SharedArray{Float64,2}, ::SharedArray{Float64,2})
Closest candidates are:
  func2!(::dty, ::SharedArray, ::SharedArray) at In[3]:64

Upvotes: 1

Views: 179

Answers (1)

Chris Rackauckas
Chris Rackauckas

Reputation: 19132

You can just define

@everywhere function func2!(v,
                          out,
                          out2)

and it'll work. Those dispatch designations don't do anything for performance. If you want to restrict it to "things which are arrays", then you can do

@everywhere function func2!(v,
                          out::AbstractArray,
                          out2::AbstractArray)

Again, this doesn't hurt performance and is only for setting dispatches and throwing errors. What happened in your code is you had out::SharedArray, when then threw an error when out was not a SharedArray (your example doesn't show why it wasn't a SharedArray, but the error message is saying out was a Matrix)

Upvotes: 2

Related Questions