Anonymous user
Matrix multiplication: Difference between revisions
m
→[[ALGOL 68]]: use the bold form of the if ~ then ~ else ~ fi syntax. - easier to read blocks.
m (→[[ALGOL 68]]: ALGOL 68 Revised Report allows keywords, types and operators in a different typeface.) |
m (→[[ALGOL 68]]: use the bold form of the if ~ then ~ else ~ fi syntax. - easier to read blocks.) |
||
Line 110:
<u>proc</u> <u>void</u> raise index error := <u>void</u>: <u>goto</u> exception index error;
<u>sema</u> idle cpus = <u>level</u> ( 8 - 1 ); # 8 = number of
# define an operator to slice array into quarters #
Line 122:
<u>op</u> × = (<u>vec</u> a, b)<u>field</u>: ( # dot product #
a[⌈a] × b[⌈b]
<u>field</u> begin, end;
[]<u>proc</u> <u>void</u> thread schedule=(
Line 131:
<u>void</u>: end :=a[<u>right</u> a:] × b[<u>right</u> b:]
);
<u>for</u> thread <u>to</u> ⌈thread schedule <u>do</u> thread schedule[thread] <u>od</u>
<u>par</u> ( # run vector in parallel #
thread schedule[1], # assume parent CPU #
( ↓idle cpus; thread schedule[2]; ↑idle cpus)
)
begin+end
);
<u>op</u> × = (<u>mat</u> a, b)<u>mat</u>: # matrix multiply #
a[⌊a, ] × b[, 2 ⌈b] # dot product #
[⌈a, 2 ⌈b] <u>field</u> out;
[]<u>struct</u>(<u>bool</u> required, <u>proc</u> <u>void</u> thread) schedule = (
( <u>true</u>, # calculate top left corner #
Line 159:
<u>void</u>: out[<u>bot</u> a:, <u>right</u> b:] := a[<u>bot</u> a:, ] × b[, <u>right</u> b:])
);
<u>for</u> thread <u>to</u> ⌈schedule <u>do</u> (required →schedule[thread] | thread →schedule[thread] ) <u>od</u>
<u>par</u> ( # run vector in parallel #
thread →schedule[1], # thread is always required, and assume parent CPU #
Line 169:
( required →schedule[2] | ↓idle cpus; thread →schedule[2]; ↑idle cpus)
)
out
<u>format</u> real fmt = $g(-6,2)$; # width of 6, with no '+' sign, 2 decimals #
Line 199:
exception index error:
putf(stand error, $x"Exception: index error."l$)
Note: In the ALGOL 68 Revised Report the keywords, types and operators were permitted in a different typeface. Hence the underling of these identifiers above. Effectively this puts these identifiers into a different name space.
|