Table of Contents

Parallel processing with lists

Parallel processing is the idea that, generally, if a command can be applied to one or more individual arguments, then it can also be extended to be applied to one or more sets of arguments.

General rules for parallel processing

As a rule-of-thumb, a given command can use parallel list processing if all the following are true:

The remainder of this chapter describes how the many and various commands available on the calculator are grouped with respect to parallel processing.

Group 1: Commands that cannot parallel process

A command must take arguments before it can parallel process, since a zero-argument command (such as DEPTH, VARS, or RAND) has no arguments with which to form a group.

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 DOLIST command (see Using DOLIST for parallel processing later in this chapter). This group consists of several subgroups:

Group 3: Commands that sometimes work with parallel processing

FIXME

Group 4: 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,

1:                  { 16 32 48 }
……………………………………………………………………………………
SETPREC

is effectively the same as

1:                            48
……………………………………………………………………………………
SETPREC

Group 5: One-argument, one-result commands

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:

Group 6: Two-arguments, one-result commands

Two-argument commands can operate in parallel in any of three different ways:

In the first form, parallel elements are combined by the command:

2:                     { 1 2 3 }
1:                     { 4 5 6 }
……………………………………………………………………………………
%

returns { .04 .1 .18 }.

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:                            30
……………………………………………………………………………………
%CH

returns { 2900 1400 900 }.

In the third form, the level 2 object is combined with each element of the level 1 list in succession:

2:                            50
1:                     { 1 2 3 }
……………………………………………………………………………………
%T

returns { 2 4 6 }.

Group 7: Multiple-argument, one-result commands

Commands that take multiple (3, 4, or 5) arguments can perform parallel processing only if all arguments are lists. For example, { 'SIN(X)' 'COS(X)' 'TAN(X)' } { X X X } { 0 0 0 } ROOT returns { 0 90 0 }. Notice that lists must be used even though the level 1 and level 2 lists each contain multiples of the same element. FIXME

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

produces, as expected { (1, 4) (2, 5) (3, 6) }, but

1:      { (1, 4) (2, 5) (3, 6) }
……………………………………………………………………………………
C→R

produces { 1 4 2 5 3 6 } rather than the more expected { 1 2 3 } { 4 5 6 }.

The following UNMIX program will unmix the data given the number of expected result lists:

« OVER SIZE
  → l n s « 
    1 n FOR 'j'
      j s FOR 'i'
        l i GET
      n STEP 
      s n / →LIST
    NEXT
  »
»

Taking { 1 4 2 5 3 6 } from above as the result of C→R (a command which should return two results),

2:               { 1 4 2 5 3 6 }
1:                             2
……………………………………………………………………………………
UNMIX

gives { 1 2 3 } { 4 5 6 }.

Group 9: Quirky commands

A few commands behave uniquely with respect to parallel processing:

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 DOLIST command. Use DOLIST as follows.

As an example, the following program takes three objects from the stack, tags them with the names a, b, and c, and displays them one after the other in line 1 of the display.

« → a b c «
    { a b c } DUP « EVAL » DOLIST
    SWAP « →TAG » DOLIST
    CLLCD 1 « 1 DISP 1 WAIT » DOLIST
  »
»

FIXME