Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
manual:chapter5:listproc [2019/10/02 14:08] jojo1973 created |
manual:chapter5:listproc [2019/10/18 13:54] jojo1973 [Group 8: Multiple-result commands] Fixed examples |
||
---|---|---|---|
Line 19: | Line 19: | ||
==== Group 2: Commands that must use DOLIST to parallel process ==== | ==== Group 2: Commands that must use DOLIST to parallel process ==== | ||
- | This group of commands cannot use parallel processing directly, but can be “coerced” into it using the '' | + | This group of commands cannot use parallel processing directly, but can be “coerced” into it using the '' |
* **Stack manipulation commands** A stack manipulation command cannot parallel process because the stack is manipulated as a whole and list objects are treated the same as any other object. Stack commands (such as '' | * **Stack manipulation commands** A stack manipulation command cannot parallel process because the stack is manipulated as a whole and list objects are treated the same as any other object. Stack commands (such as '' | ||
* **Commands that operate on a list as a whole.** Certain commands accept lists as arguments but treat them no differently than any other data object. They perform their function on the object as a whole without respect to its elements. For example, '' | * **Commands that operate on a list as a whole.** Certain commands accept lists as arguments but treat them no differently than any other data object. They perform their function on the object as a whole without respect to its elements. For example, '' | ||
* **List manipulation commands.** List manipulation commands will not parallel process since they operate on list arguments as lists rather than as sets of parallel data. However, a list manipulation command can be forced to parallel process lists of lists by using the '' | * **List manipulation commands.** List manipulation commands will not parallel process since they operate on list arguments as lists rather than as sets of parallel data. However, a list manipulation command can be forced to parallel process lists of lists by using the '' | ||
- | { { 1 2 3 } { 4 5 6 } } | + | 3: { { 1 2 3 } { 4 5 6 } } |
- | 1 | + | 2: 1 |
- | « ΠLIST » | + | 1: « ΠLIST » |
+ | …………………………………………………………………………………… | ||
DOLIST | DOLIST | ||
</ | </ | ||
* **Other commands that have list arguments.** Because a list can hold any number of objects of any type, it is commonly used to hold a variable number of parameters of various types. Some commands accept such lists, and because of this are insensitive to parallel processing, except by using '' | * **Other commands that have list arguments.** Because a list can hold any number of objects of any type, it is commonly used to hold a variable number of parameters of various types. Some commands accept such lists, and because of this are insensitive to parallel processing, except by using '' | ||
* **Index-oriented commands.** Many array commands either establish the size of an array in rows and columns or manipulate individual elements by their row and column indices. These commands expect these row and column indices to be real number pairs collected in lists. For example, < | * **Index-oriented commands.** Many array commands either establish the size of an array in rows and columns or manipulate individual elements by their row and column indices. These commands expect these row and column indices to be real number pairs collected in lists. For example, < | ||
- | { 3 4 } | + | 1: { 3 4 } |
+ | …………………………………………………………………………………… | ||
RANM | RANM | ||
</ | </ | ||
* **Program control commands.** Program control structures and commands do no perform parallel processing and cannot be forced to do so. However, programs containing these structures can be made to parallel process by using '' | * **Program control commands.** Program control structures and commands do no perform parallel processing and cannot be forced to do so. However, programs containing these structures can be made to parallel process by using '' | ||
- | { 1 2 3 4 5 6 } | + | 3: { 1 2 3 4 5 6 } |
- | 1 | + | 2: 1 |
- | « IF | + | 1: « IF |
- | DUP 3 ≤ | + | |
- | THEN | + | |
- | DROP | + | |
- | END | + | |
- | » | + | |
+ | …………………………………………………………………………………… | ||
DOLIST | DOLIST | ||
</ | </ | ||
- | ==== Group 3: commands | + | ==== Group 3: Commands |
FIXME | FIXME | ||
- | ==== Group 4: ADD and + ==== | + | ==== Group 4: Commands that set modes / states ==== |
- | FIXME | + | |
- | + | ||
- | ==== Group 5: Commands that set modes / states ==== | + | |
Commands that store values in system-specific locations so as to control certain modes and machine states can generally be used to parallel process data. The problem is that each successive parameter in the list cancels the setting established by the previous parameter. For example, < | Commands that store values in system-specific locations so as to control certain modes and machine states can generally be used to parallel process data. The problem is that each successive parameter in the list cancels the setting established by the previous parameter. For example, < | ||
- | { 1 2 3 4 5 } | + | 1: { 16 32 48 } |
- | FIX</ | + | …………………………………………………………………………………… |
- | 5 | + | SETPREC</ |
- | FIX | + | 1: 48 |
+ | …………………………………………………………………………………… | ||
+ | SETPREC | ||
</ | </ | ||
- | ==== Group 6: One-argument, | + | ==== Group 5: One-argument, |
These commands are the easiest to use with parallel processing. Simply provide the command with a list of arguments instead of the expected single argument. Some examples: | These commands are the easiest to use with parallel processing. Simply provide the command with a list of arguments instead of the expected single argument. Some examples: | ||
- | * < | + | * < |
+ | 1: { 1 -2 3 -4 } | ||
+ | …………………………………………………………………………………… | ||
ABS | ABS | ||
</ | </ | ||
* < | * < | ||
- | DEG | + | 1: |
- | { 0 30 60 90 } | + | …………………………………………………………………………………… |
SIN | SIN | ||
- | </ | + | </ |
* < | * < | ||
- | { 1 A ' | + | 1: { 1 'A' |
+ | …………………………………………………………………………………… | ||
INV | INV | ||
</ | </ | ||
- | ==== Group 7: Two-arguments, | + | ==== Group 6: Two-arguments, |
Two-argument commands can operate in parallel in any of three different ways: | Two-argument commands can operate in parallel in any of three different ways: | ||
Line 83: | Line 88: | ||
* **object** **{ list }** | * **object** **{ list }** | ||
- | In the first form, parallel elements are combined by the command: | + | In the first form, parallel elements are combined by the command: |
+ | 2: { 1 2 3 } | ||
+ | 1: { 4 5 6 } | ||
+ | …………………………………………………………………………………… | ||
+ | % | ||
+ | </ | ||
- | In the second form, the level 1 object is combined with each element in the level 2 list in succession: | + | In the second form, the level 1 object is combined with each element in the level 2 list in succession: |
+ | 2: { 1 2 3 } | ||
+ | 1: | ||
+ | …………………………………………………………………………………… | ||
+ | %CH | ||
+ | </ | ||
- | In the third form, the level 2 object is combined with each element of the level 1 list in succession: | + | In the third form, the level 2 object is combined with each element of the level 1 list in succession: |
+ | 2: | ||
+ | 1: { 1 2 3 } | ||
+ | …………………………………………………………………………………… | ||
+ | %T | ||
+ | </ | ||
- | ==== Group 8: Multiple-argument, | + | ==== Group 7: Multiple-argument, |
Commands that take multiple (3, 4, or 5) arguments can perform parallel processing only if all arguments are lists. For example, '' | Commands that take multiple (3, 4, or 5) arguments can perform parallel processing only if all arguments are lists. For example, '' | ||
+ | |||
+ | ==== Group 8: Multiple-result commands ==== | ||
+ | Any command that allows parallel processing, but produces multiple results from its input data, will return its results as a single list. For example,< | ||
+ | 2: { 1 2 3 } | ||
+ | 1: { 4 5 6 } | ||
+ | …………………………………………………………………………………… | ||
+ | R→C | ||
+ | </ | ||
+ | 1: { (1, 4) (2, 5) (3, 6) } | ||
+ | …………………………………………………………………………………… | ||
+ | C→R | ||
+ | </ | ||
+ | |||
+ | The following '' | ||
+ | « OVER SIZE | ||
+ | → l n s « | ||
+ | 1 n FOR ' | ||
+ | j s FOR ' | ||
+ | l i GET | ||
+ | n STEP | ||
+ | s n / →LIST | ||
+ | NEXT | ||
+ | » | ||
+ | » | ||
+ | </ | ||
+ | |||
+ | Taking '' | ||
+ | 2: { 1 4 2 5 3 6 } | ||
+ | 1: 2 | ||
+ | …………………………………………………………………………………… | ||
+ | UNMIX | ||
+ | </ | ||
+ | |||
+ | ==== Group 9: Quirky commands ==== | ||
+ | A few commands behave uniquely with respect to parallel processing: | ||
+ | |||
+ | * '' | ||
+ | { 1 3 } | ||
+ | DELALARM | ||
+ | </ | ||
+ | { 3 1 } | ||
+ | DELALARM | ||
+ | </ | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ==== Using DOLIST for parallel processing ==== | ||
+ | Almost any command or user program can be made to work in parallel over a list or lists of data by using the '' | ||
+ | |||
+ | * Level 1 must contain a command, a program object, or the name of a variable that contains a command or program object. | ||
+ | * Level 2 must contain an argument count. | ||
+ | * Level 3 and on are the argument lists. | ||
+ | |||
+ | As an example, the following program takes three objects from the stack, tags them with the names '' | ||
+ | « → a b c « | ||
+ | { a b c } DUP « EVAL » DOLIST | ||
+ | SWAP « →TAG » DOLIST | ||
+ | CLLCD 1 « 1 DISP 1 WAIT » DOLIST | ||
+ | » | ||
+ | » | ||
+ | </ |