Shared Arrays
Construct a of a bits type T
and size dims
across the processes specified by pids
- all of which have to be on the same host. If N
is specified by calling SharedArray{T,N}(dims)
, then N
must match the length of dims
.
If pids
is left unspecified, the shared array will be mapped across all processes on the current host, including the master. But, localindices
and indexpids
will only refer to worker processes. This facilitates work distribution code to use workers for actual computation with the master process acting as a driver.
If an init
function of the type initfn(S::SharedArray)
is specified, it is called on all the participating workers.
The shared array is valid as long as a reference to the SharedArray
object exists on the node which created the mapping.
SharedArray{T}(filename::AbstractString, dims::NTuple, [offset=0]; mode=nothing, init=false, pids=Int[])
Construct a backed by the file filename
, with element type T
(must be a bits type) and size dims
, across the processes specified by pids
- all of which have to be on the same host. This file is mmapped into the host memory, with the following consequences:
The array data must be represented in binary format (e.g., an ASCII format like CSV cannot be supported)
If pids
is left unspecified, the shared array will be mapped across all processes on the current host, including the master. But, localindices
and indexpids
will only refer to worker processes. This facilitates work distribution code to use workers for actual computation with the master process acting as a driver.
mode
must be one of "r"
, "r+"
, "w+"
, or "a+"
, and defaults to "r+"
if the file specified by filename
already exists, or if not. If an init
function of the type initfn(S::SharedArray)
is specified, it is called on all the participating workers. You cannot specify an init
function if the file is not writable.
SharedArrays.SharedVector — Type
A one-dimensional .
— Type
SharedMatrix
A two-dimensional SharedArray.
Distributed.procs — Method
Get the vector of processes mapping the shared array.
— Function
Returns the actual Array
object backing S
.
— Function
Returns the current worker’s index in the list of workers mapping the SharedArray
(i.e. in the same list returned by procs(S)
), or 0 if the SharedArray
is not mapped locally.
— Function
localindices(S::SharedArray)
Returns a range describing the “default” indices 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)
. In multi-process contexts, returns an empty range in the parent process (or any process for which indexpids returns 0).
It’s worth emphasizing that localindices
exists purely as a convenience, and you can partition work on the array among workers any way you wish. For a SharedArray
, all indices should be equally fast for each worker process.