@@ -1,25 +1,22 @@
|
|
1 |
procedure main:
|
2 |
declare values as a dynamic array of float
|
3 |
declare value_count := 0
|
4 |
|
5 |
if process_number = 0 then
|
6 |
declare value := 0
|
7 |
while can_read(stdin) do
|
8 |
append(values, value)
|
9 |
end while
|
10 |
|
11 |
value_count := count(values)
|
12 |
-
for target := 1 to process_count do
|
13 |
-
send(&value_count, 1, target)
|
14 |
-
send(&values, count(values), target)
|
15 |
-
end
|
16 |
-
else
|
17 |
-
receive(&value_count, 1, 0)
|
18 |
-
resize(values, value_count)
|
19 |
-
receive(&values, value_count, 0)
|
20 |
end if
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
for index := 0 to count(values) do
|
23 |
print(process_number, ": ", index, ": ", values[index])
|
24 |
end for
|
25 |
end procedure
|
1 |
procedure main:
|
2 |
declare values as a dynamic array of float
|
3 |
declare value_count := 0
|
4 |
|
5 |
if process_number = 0 then
|
6 |
declare value := 0
|
7 |
while can_read(stdin) do
|
8 |
append(values, value)
|
9 |
end while
|
10 |
|
11 |
value_count := count(values)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
end if
|
13 |
|
14 |
+
// Send a variable or array from the source process to the rest
|
15 |
+
broadcast(&value_count, 1, 0)
|
16 |
+
resize(values, value_count)
|
17 |
+
broadcast(&values, count(values), 0)
|
18 |
+
|
19 |
for index := 0 to count(values) do
|
20 |
print(process_number, ": ", index, ": ", values[index])
|
21 |
end for
|
22 |
end procedure
|