How to set values to the elements of DArray?

2019-06-23 03:55发布

I'm exploring the parallel computing of Julia and tried this:

a=dzeros(5);a[1]=5

but just got this error:

setindex! not defined for DArray{{Float64, 1, Array{Float64, 1}}

Well, I thought the manual said setindex! is fully implemented by DArray. What have I missed?

I was using v0.2.1 for Windows 32-bit.

标签: julia
1条回答
家丑人穷心不美
2楼-- · 2019-06-23 04:39

I'm just an explorer too, but after reading Julia's Distributed Arrays Docs, I tried this which seemed to work.

$ ./julia 
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" to list help topics
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+2703 (2014-04-22 18:57 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 942ae42* (0 days old master)
|__/                   |  i686-redhat-linux

julia> versioninfo()
Julia Version 0.3.0-prerelease+2703
Commit 942ae42* (2014-04-22 18:57 UTC)
Platform Info:
  System: Linux (i686-redhat-linux)
  CPU: Genuine Intel(R) CPU           T2250  @ 1.73GHz
  WORD_SIZE: 32
  BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

julia> a=dzeros(5)
5-element DArray{Float64,1,Array{Float64,1}}:
 0.0
 0.0
 0.0
 0.0
 0.0

julia> localpart(a)[1]=5
5

julia> a
5-element DArray{Float64,1,Array{Float64,1}}:
 5.0
 0.0
 0.0
 0.0
 0.0

julia> 

It seems that distributed arrays aren't "local" until you make them "local".

查看更多
登录 后发表回答