Guest User

Untitled

a guest
Aug 19th, 2019
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pmapdemo.jl
  2. using Distributed
  3. #addprocs(length(Sys.cpu_info())) # uncomment this line for error
  4. @everywhere include(joinpath(@__DIR__, "pmapdemo2.jl"))
  5.  
  6. function main()
  7. # Get source data
  8. source = Dict{String, Any}("t"=>zeros(5),
  9. "x"=>zeros(5,6),
  10. "y"=>zeros(5,3),
  11. "z"=>zeros(5,3))
  12. # Define set of points over which to iterate
  13. iterset = Dict{String, Any}("t"=>source["t"],
  14. "x"=>source["x"],
  15. "y"=>fill(2, size(source["t"])[1], 1),
  16. "z"=>fill(2, size(source["t"])[1], 1))
  17. data = Dict{String, Any}()
  18.  
  19. # Initialise array points to be calculated
  20. MyMod.initialisearray!(data, iterset)
  21. # Calculate each array point
  22. MyMod.calcarray!(data, iterset, source)
  23. @show data
  24. end
  25.  
  26. main()
  27.  
  28. #pmapdemo2.jl
  29. module MyMod
  30.  
  31. using Distributed
  32. @everywhere using SharedArrays
  33.  
  34. # Initialise data array
  35. function initialisearray!(data, fieldset)
  36. zerofield::SharedArray{Float64, 4} = zeros(size(fieldset["t"])[1],
  37. size(fieldset["x"])[2],
  38. size(fieldset["y"])[2],
  39. size(fieldset["z"])[2])
  40. data["field"] = deepcopy(zerofield)
  41. end
  42.  
  43. # Calculate values of array elements according to values in source
  44. function calcpoint!((data, source, a, b, c, d))
  45. data["field"][a,b,c,d] = rand()
  46. end
  47.  
  48. # Set values in array
  49. function calcarray!(data, iterset, source)
  50. for a in eachindex(iterset["t"])
  51. # [additional functionality f(a) here]
  52. b = eachindex(iterset["x"][a,:])
  53. c = eachindex(iterset["y"][a,:])
  54. d = eachindex(iterset["z"][a,:])
  55. pmap(calcpoint!, Iterators.product(Iterators.repeated(data,1), Iterators.repeated(source,1), Iterators.repeated(a,1), b, c, d))
  56. end
  57. end
  58.  
  59. end
  60.  
  61. ERROR: LoadError: On worker 2:
  62. BoundsError: attempt to access 0×0×0×0 Array{Float64,4} at index [1]
  63. setindex! at ./array.jl:767 [inlined]
  64. setindex! at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/SharedArrays/src/SharedArrays.jl:500 [inlined]
  65. _setindex! at ./abstractarray.jl:1043
  66. setindex! at ./abstractarray.jl:1020
  67. calcpoint! at /home/dave/pmapdemo2.jl:25
  68. #112 at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/process_messages.jl:269
  69. run_work_thunk at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/process_messages.jl:56
  70. macro expansion at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/process_messages.jl:269 [inlined]
  71. #111 at ./task.jl:259
  72. Stacktrace:
  73. [1] (::getfield(Base, Symbol("##696#698")))(::Task) at ./asyncmap.jl:178
  74. [2] foreach(::getfield(Base, Symbol("##696#698")), ::Array{Any,1}) at ./abstractarray.jl:1866
  75. [3] maptwice(::Function, ::Channel{Any}, ::Array{Any,1}, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Int64}},Base.OneTo{Int64},Base.OneTo{Int64},Base.OneTo{Int64}}}) at ./asyncmap.jl:178
  76. [4] #async_usemap#681 at ./asyncmap.jl:154 [inlined]
  77. [5] #async_usemap at ./none:0 [inlined]
  78. [6] #asyncmap#680 at ./asyncmap.jl:81 [inlined]
  79. [7] #asyncmap at ./none:0 [inlined]
  80. [8] #pmap#213(::Bool, ::Int64, ::Nothing, ::Array{Any,1}, ::Nothing, ::Function, ::Function, ::WorkerPool, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Int64}},Base.OneTo{Int64},Base.OneTo{Int64},Base.OneTo{Int64}}}) at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:126
  81. [9] pmap(::Function, ::WorkerPool, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Int64}},Base.OneTo{Int64},Base.OneTo{Int64},Base.OneTo{Int64}}}) at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:101
  82. [10] #pmap#223(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Int64}},Base.OneTo{Int64},Base.OneTo{Int64},Base.OneTo{Int64}}}) at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:156
  83. [11] pmap(::Function, ::Base.Iterators.ProductIterator{Tuple{Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Dict{String,Any}}},Base.Iterators.Take{Base.Iterators.Repeated{Int64}},Base.OneTo{Int64},Base.OneTo{Int64},Base.OneTo{Int64}}}) at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:156
  84. [12] calcarray!(::Dict{String,Any}, ::Dict{String,Any}, ::Dict{String,Any}) at /home/dave/pmapdemo2.jl:20
  85. [13] main() at /home/dave/pmapdemo.jl:19
  86. [14] top-level scope at none:0
  87. in expression starting at /home/dave/pmapdemo.jl:23
RAW Paste Data