diff --git a/base/exports.jl b/base/exports.jl index 81815305b651e0..27e0e51caeddf7 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1242,6 +1242,7 @@ export # shared arrays sdata, indexpids, + localindexes, # paths and file names abspath, diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 33e4cc3a934a68..73641e7437d77e 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -139,6 +139,20 @@ indexpids(S::SharedArray) = S.pidx sdata(S::SharedArray) = S.s sdata(A::AbstractArray) = A +""" + localindexes(S::SharedArray) + +A range describing the "default" indexes to be handled by the current +process. This range should be interpreted in the sense of linear +indexing, i.e., as a sub-range of `1:length(S)`. Returns an empty +range in the parent process (or any one for which `indexpids` returns +0). + +It's worth emphasizing that `localindexes` exists purely as a +convenience, and you can partition work on the array among workers any +way you wish. For a SharedArray, all indexes should be equally fast +for each worker process. +""" localindexes(S::SharedArray) = S.pidx > 0 ? range_1dim(S, S.pidx) : 1:0 unsafe_convert{T}(::Type{Ptr{T}}, S::SharedArray) = unsafe_convert(Ptr{T}, sdata(S)) diff --git a/doc/manual/parallel-computing.rst b/doc/manual/parallel-computing.rst index 9087eed1f30b8e..800966bc646ca5 100644 --- a/doc/manual/parallel-computing.rst +++ b/doc/manual/parallel-computing.rst @@ -533,7 +533,7 @@ Here's a brief example: 3 4 - julia> S = SharedArray(Int, (3,4), init = S -> S[Base.localindexes(S)] = myid()) + julia> S = SharedArray(Int, (3,4), init = S -> S[localindexes(S)] = myid()) 3x4 SharedArray{Int64,2}: 2 2 3 4 2 3 3 4 @@ -548,7 +548,7 @@ Here's a brief example: 2 3 3 4 2 7 4 4 -:func:`Base.localindexes` provides disjoint one-dimensional ranges of indexes, +:func:`localindexes` provides disjoint one-dimensional ranges of indexes, and is sometimes convenient for splitting up tasks among processes. You can, of course, divide the work any way you wish: diff --git a/doc/stdlib/parallel.rst b/doc/stdlib/parallel.rst index 8de090be912953..13412fae8c9c26 100644 --- a/doc/stdlib/parallel.rst +++ b/doc/stdlib/parallel.rst @@ -666,8 +666,8 @@ General Parallel Computing Support Execute an expression on all processes. Errors on any of the processes are collected into a `CompositeException` and thrown. -Shared Arrays (Experimental, UNIX-only feature) ------------------------------------------------ +Shared Arrays +------------- .. function:: SharedArray(T::Type, dims::NTuple; init=false, pids=Int[]) @@ -703,6 +703,7 @@ Shared Arrays (Experimental, UNIX-only feature) Returns the index of the current worker into the ``pids`` vector, i.e., the list of workers mapping the SharedArray +.. function:: localindexes(S::SharedArray) Cluster Manager Interface ------------------------- This interface provides a mechanism to launch and manage Julia workers on different cluster environments.