Since interactions are accomplished by sending and receiving messages, the basic operations in the message-passing programming paradigm are send and receive. In their simplest form, the prototypes of these operations are defined as follows:
send(void *sendbuf, int nelems, int dest)
receive(void *recvbuf, int nelems, int source)
- sendbuf points to a buffer that stores the data to be sent,
- recvbuf points to a buffer that stores the data to be received,
- nelems is the number of data units to be sent and received,
- dest is the identifier of the process that receives the data,
- source is the identifier of the process that sends the data.
1 P0 P1
2
3 a = 100; receive(&a, 1, 0)
4 send(&a, 1, 1); printf("%d\n", a);
5 a=0;