Next: Awaiting completion, Previous: Sending, Up: Communication statements [Contents][Index]
Sending, mentioned the
<send_stmt>’s UNSUSPECTING
keyword,
which specifies that the targets should not implicitly perform a
receive operation. Because every send must have a matching receive,
coNCePTuaL offers a RECEIVE
statement that
explicitly receives a set of messages. A
<receive_stmt> is much like a
<send_stmt> (see Sending) with the
<source_task> and
<target_tasks> in the reverse order:
<receive_stmt> | ::= | <target_tasks> |
[ ASYNCHRONOUSLY ]
RECEIVE |
||
<message_spec> | ||
FROM
<source_task> |
<target_tasks> is described in Target tasks; <message_spec> is described in Message specifications; and, <source_task> is described in Source tasks.
Like other statements that contain both a
<source_task> and a
<target_tasks>, the RECEIVE
statement propagates
all variables declared by the <source_task>
to the <target_tasks>,
as in
TASKS src-1 RECEIVE A 1 MEGABYTE MESSAGE FROM ALL TASKS src.
However, the RECEIVE
statement is unique
among coNCePTuaL statements in that it can alternatively propagate
all variables declared by the <target_tasks>
to the <source_task>, as
in
ALL TASKS dst RECEIVE A 1 MEGABYTE MESSAGE FROM TASKS dst+1.
The
RECEIVE
statement automatically determines the
direction in which variables should be propagated. If the direction
cannot unambiguously be determined, the coNCePTuaL compiler aborts
with an error message. For example, the RECEIVE
statement in the
following code is ambiguous because the ‘bbb’ in the
expression ‘aaa < bbb’ can
refer to either the one in the LET
statement or the one in the
‘TASKS bbb SUCH THAT bbb > 3’ expression:
LET bbb BE 5 WHILE { TASKS aaa SUCH THAT aaa < bbb RECEIVE A MESSAGE FROM TASKS bbb SUCH THAT bbb > 3 THEN TASKS ccc SUCH THAT ccc > 3 SEND A MESSAGE TO UNSUSPECTING TASKS ddd SUCH THAT ddd < ccc }
For each message sent via a SEND
… TO
UNSUSPECTING
statement there must be a RECEIVE
statement that receives a message of the same size. The
<target_tasks>’s
<message_spec> can, however, specify different
values for message uniqueness, message alignment, and data
touching. In addition, the source and target do not need to agree
on the use of the ASYNCHRONOUSLY
keyword.
The only restriction is that WITH VERIFICATION
will return spurious results if used by the target but not by the
source. Hence, the following <send_stmt> and
<receive_stmt>
correctly match each other:
TASK 0 SENDS 3 4 KILOBYTE MESSAGES TO UNSUSPECTING TASK 1 TASK 1 ASYNCHRONOUSLY RECEIVES 3 UNIQUE 4 KILOBYTE 48 BYTE ALIGNED MESSAGES WITH DATA TOUCHING FROM TASK 0.
In general, it is better to use a single SEND
statement with a
WHO RECEIVES IT
clause (see Sending) than a RECEIVE
plus a matching
SEND
… TO UNSUSPECTING
; the
former is less error-prone than the latter. However, the latter is
useful for programs in which a set of receives is posted, then the
tasks perform various communication, computation, and
synchronization operations, and—towards the end of the program—the
matching sends are posted. That sort of split-phase structure
requires separate
SEND
and RECEIVE
statements.
Next: Awaiting completion, Previous: Sending, Up: Communication statements [Contents][Index]