Julia is an open-source language that is dynamic, fast, and user-friendly.
A shared array uses memory that has been shared with the system to map the same array across many processes. In SharedArray, each process has access to the entire array.
A shared array is beneficial when we have to make large amounts of data jointly accessible to multiple processes on the same machine.
The syntax to create a shared array is as follows.
init
functionSharedArray{T}(dims::NTuple; init=false, pids=Int[])
SharedArray{T,N}(...)
T
: This is the bits type.dims
: This is the size.pids
: These specify these processes. The processes are on the same host.N
: The value for this has to be the same as dims
.Note: When
pids
is not provided, the shared array is mapped across all processes, including the master process.
init
functionSharedArray{T}(file::AbstractString, dims::NTuple, [offset=0]; mode=nothing, init=false, pids=Int[])
SharedArray{T,N}(...)
In this scenario, the shared array is backed by the file with the filename
, with size dims
, element type T
(must be a bits type), processes that are specified by pids
, and all the processes must be on the same host. The file is going to be mapped into the host memory with the following implications:
The array data is to be in binary format.
If a change is made to the array values, the values on the disk would also change.
The mode
can only be one of r
, r+
, w+
, and a+
. If the filename
is not specified, the mode will be w+
, otherwise by default it is r+
.
The offset
permits us to skip a given number of bytes at the beginning of the file.
Note: An
init
function cannot be specified if the file is unwritable.
Free Resources