fork ....;hs, reduce

Description:

Execute a code block in a node.

Syntax:

fork  ….;hs reduce

Note:

The statement executes fork code block on a sequence of nodes hs while distributing referenced cellset variables (including cell names) among the nodes, and populates the return values into the fork cell. The execution will be given to another node if end msg failure happens. The redistribution will uses the default method.

Parameter:

….

A parameter sequence

hs

The node sequence in which each server is represented by a string in the form of "address:port number", like "192. 168. 0. 86: 4001".

s

A sequence consisting of integer sequences; can be omitted

reduce

The parameter can be absent; when the number of tasks is greater than that of the nodes, perform reduce on subtasks on the same node; store the last cumulative value in fork cell and the current computing result in reduce cell; the referenced cellset variables will be distributed among the nodes

Example:

Single parameter

 

A

B

 

1

fork [[1,20,6,14,5],[32,8]];["192.168.1.100:8989"]

 

Execute the fork code block and return a sequence of results returned by all threads

IMG_256

2

 

=connect("demo")

 

3

 

=B2.query("select * from EMPLOYEE where EID in (?) ",A1)

 

4

 

=B2.close()

 

5

 

return B3

 

 

 

A

B

 

1

[192.168.0.116:8281,192.168.0.129:8281]

 

 

2

[English,Math,PE]

 

 

3

fork  A2;A1

 

Give parameters English and PE to node 192.168.0.116:8281, and parameter Math to node 192.168.0.129:8281. A3 returns result as follows:

4

 

=connect("demo")

 

5

 

=B4.query("select * from SCORES  where SUBJECT=?",A3)

 

6

reduce

=A3|A6

 

 

Multiple parameters

 

A

B

 

1

fork [[1,20,6,14,5],[32,8],[3,4],23,12,89,56,90,231,333,111,231],"F";["192.168.1.100:8989","192.168.1.100:8282","192.168.1.100:8283"]

 

A1 returns result as follows:

2

 

=connect("demo")

 

3

 

=B2.query("select * from EMPLOYEE where EID in (?) and GENDER=?",A1(1),A1(2))

 

4

 

=B2.close()

 

5

 

return B3

 

Related function:

  callx()

  fork Ai,...