prev
Menu
next
Data Transferring
There are two ways to transfer data to another parallel activity.
One is the shared data port, and the other is the message port.
DECLARE STRUCTURE
The structure is a template of a data structure.
EXAMPLE.
DECLARE STRUCTURE struct1: STRING, 3 of NUMERIC, 2 of NUMERIC(10), NUMERIC(10,10)
This defines the data template named struct1 consists one string variable, three numerical variables, two one-dimentional numeircal arrays of size 10, and a two-dimentional array of size 10 by 10.
Data Transferring Via SHARED Ports
DECLARE-SHARED statements declare shared data ports.
EXAMPLE.
DECLARE SHARED share1 OF struct1
This declares share1 is a shared data port of type strict1.
A SHARED data port can be an array.
DECLARE SHARED share2(0 to 1) OF struct1This prepares two data ports share2(0) and share2(1).
DECLARE NUMERIC A(10), B(10,10) PUT TO share1 FROM "abc", 1,2,3,A,B
This writes to share1. Items following FROM correspond to the structure of share1.
DECLARE NUMERIC D(10),E(10,10) GET FROM share1 TO s$, A, B, C, D, E
This reads from share1. Variables following TO correspond to the structure of share1.
Note.
Execution of a PUT statement and a GET statement can be independed from each other.
A shared port can be re-written before any GET statement has been executed.
A Shared port can be read repeatedly independed from exection of PUT statements.
Data Transferring Via MESSAGE Ports
DECLARE MESSAGE statements declare message ports.
Example.
DECLARE MESSAGE mes1 OF struct1 DECLARE MESSAGE mes2 OF struct1
These declare two message ports of type struct1.
A Message port cannot be an array.
Data transferring via message ports is executed with SEND TO and RECEIVE FROM statements.
Example.
DECLARE NUMERIC A(10), B(10,10) SEND TO mes1 FROM "abc", 1,2,3,A,B
This writes on mes1 and waits until mes1 is received by someone. Items following FROM correspond to the structure of mes1.
DECLARE NUMERIC D(10),E(10,10) RECEIVE FROM mes1 TO s$, A, B, C, D, E
This reads from mes1 and set it empty. Variables following TO correspond to the structure of mes1.
When share1 is empty, This waits until someone writes on mes1.
Note.
SEND TO and RECEIVE FROM may cause deadlocks.
Examle Wrong.
PARACT p1 SEND TO mes1 FROM …… RECEIVE FROM mes2 TO …… END PARACT PARACT p2 SEND TO mes2 FROM …… RECEIVE FROM mes1 TO …… END PARACT
Parallel activity p1 waits until mes1 is recieved by p2, while p2 waits until mes2 is received by p1.
Examle Right.
PARACT p1 SEND TO mes1 FROM …… RECEIVE FROM mes2 TO …… END PARACT PARACT p2 RECEIVE FROM mes1 TO …… SEND TO mes2 FROM …… END PARACT
After finishing data transferring via mes1, data transferring goes via mes2.
Location of the declare statements
DECLARE STRUCTUE, DECLARE SHARED, DECLARE MESSAGE statments must be located above the first PARACT-line.
The fisrt line can be a PROGRAM-line. No other statements can be located here.