SharedArray
represents an array, which is shared across multiple processes, on a single machine.
SharedArrays.SharedArray
—TypeSharedArray{T}(dims::NTuple; init=false, pids=Int[])SharedArray{T,N}(...)
Construct aSharedArray
of a bits typeT
and sizedims
across the processes specified bypids
- all of which have to be on the same host. IfN
is specified by callingSharedArray{T,N}(dims)
, thenN
must match the length ofdims
.
Ifpids
is left unspecified, the shared array will be mapped across all processes on the current host, including the master. But,localindices
andindexpids
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 aninit
function of the typeinitfn(S::SharedArray)
is specified, it is called on all the participating workers.
The shared array is valid as long as a reference to theSharedArray
object exists on the node which created the mapping.
SharedArray{T}(filename::AbstractString, dims::NTuple, [offset=0]; mode=nothing, init=false, pids=Int[])SharedArray{T,N}(...)
Construct aSharedArray
backed by the filefilename
, with element typeT
(must be a bits type) and sizedims
, across the processes specified bypids
- 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)
Any changes you make to the array values (e.g.,A[3] = 0
) will also change the values on disk
Ifpids
is left unspecified, the shared array will be mapped across all processes on the current host, including the master. But,localindices
andindexpids
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 byfilename
already exists, or"w+"
if not. If aninit
function of the typeinitfn(S::SharedArray)
is specified, it is called on all the participating workers. You cannot specify aninit
function if the file is not writable.
offset
allows you to skip the specified number of bytes at the beginning of the file.
SharedArrays.SharedVector
—TypeSharedVector
A one-dimensionalSharedArray
.
SharedArrays.SharedMatrix
—TypeSharedMatrix
A two-dimensionalSharedArray
.
Distributed.procs
—Methodprocs(S::SharedArray)
Get the vector of processes mapping the shared array.
SharedArrays.sdata
—Functionsdata(S::SharedArray)
Return the actualArray
object backingS
.
SharedArrays.indexpids
—Functionindexpids(S::SharedArray)
Return the current worker's index in the list of workers mapping theSharedArray
(i.e. in the same list returned byprocs(S)
), or 0 if theSharedArray
is not mapped locally.
SharedArrays.localindices
—Functionlocalindices(S::SharedArray)
Return 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 of1:length(S)
. In multi-process contexts, returns an empty range in the parent process (or any process for whichindexpids
returns 0).
It's worth emphasizing thatlocalindices
exists purely as a convenience, and you can partition work on the array among workers any way you wish. For aSharedArray
, all indices should be equally fast for each worker process.
Settings
This document was generated withDocumenter.jl version 1.8.0 onWednesday 9 July 2025. Using Julia version 1.11.6.