This function sends an array to a destination node on a given communicator with a specific message tag. Note that there has to be a matching receive issued by the destination node. The general syntax for its use is
mpisend(x,rank,tag,comm)
where x
is the array to send, rank
is the rank of the
node to receive the message, tag
is the message tag, and
comm
is the handle of the communicator to use. If no
communicator is specified, then MPI_COMM_WORLD
is used.
The mpisend
command works by packing the array into a
linear buffer and then sending two messages. The first
message captures the size of the buffer, and the second
contains the actual data. The matching mpirecv
command
reads the two messages, decodes the buffer, and returns
the resulting array.
The mpisend
command is fairly straightforward to use.
Its power is in the ability to send arrays of arbitrary
complexity, including cell arrays, structures, strings, etc.
Here is an example of an mpisend
and mpirecv
being used
on the same node to pass a structure through MPI.
--> mpiinit --> x.color = 'blue'; --> x.pi = 3; --> x.cells = {'2',2}; --> mpisend(x,0,32); --> y = mpirecv(0,32) y = <structure array> - size: [1 1] color: blue pi: [3] cells: {[1 2] cell }