Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: re-export localindexes [ci skip] #12423

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 6 additions & 3 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,10 @@ 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)

Blah blah
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was me testing the new documentation system---see the history in #12423. This will not be part of the final commit.


Cluster Manager Interface
-------------------------
This interface provides a mechanism to launch and manage Julia workers on different cluster environments.
Expand Down Expand Up @@ -773,4 +777,3 @@ Cluster Manager Interface
Called by cluster managers using custom transports. It should be called when the custom transport implementation receives the
first message from a remote worker. The custom transport must manage a logical connection to the remote worker and provide two
AsyncStream objects, one for incoming messages and the other for messages addressed to the remote worker.