Skip to content

Commit

Permalink
Re-export localindexes [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 3, 2015
1 parent 8dcdf83 commit 1aec2d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ export
# shared arrays
sdata,
indexpids,
localindexes,

# paths and file names
abspath,
Expand Down
14 changes: 14 additions & 0 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/parallel-computing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand Down
5 changes: 3 additions & 2 deletions doc/stdlib/parallel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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[])

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1aec2d3

Please sign in to comment.