Open topic with navigation

TIBCO GridServer® 7.1.0

# Arrays

Arrays are fundamental to achieving parametric parallelism in PDS, because an array variable is implicitly indexed in the task block.

## Construction

You can construct arrays of primitive values in several ways. Write a literal value as follows:

    a = [1, 2, 3, 4, 5]

You can construct an array with autorange expressions. The expression

    begin n end m step k

constructs an array starting with n and proceeding in increments of k until m is reached. More precisely, it constructs

    [n, n+k, n+2k, ..., n+rk]

where r is the largest integer such that n+rk<= m.

The expression

    begin n count c step k

constructs an array of c elements beginning with n and proceeding in increments of k, that is,

    [n, n+k, n+2k, ..., n+(c-1)k].

For example,

    begin 10 end 15 step 2

and

    begin 10 count 3 step 2

both construct the array

    [10, 12, 14].

The third way to construct an array is to use the `split` function, which divides a string into array elements at whitespace. Quoted elements keep embedded whitespace and strip the quotes upon placement into the array. For example, on UNIX machines:

    split(‘ls‘)

returns an array of the files in the current directory.

## Indexing

In most contexts, when a variable containing an array is referenced, the first element is returned. However, in the task block, the element corresponding to the ID of the currently running task is returned. (If the task ID exceeds the array size, the last element of the array is returned.) This feature makes it easy to write the most common kinds of distributed computations. For example, you can set up an array of values and run a command on each one in parallel with the following PDS script:

    args = begin 100 end 200 step 5
    task sizeof($args)
        execute "doit $args"
    end

The `$args` in the execute statement expands to 100 for the first task, 105 for the second, and so on.

Another exception to the first element being returned from an array is that inside a `for` loop, the variable containing the array returns the value at the current iteration of the loop. This is redundant with the loop variable. For example, in `for i in $args log "$i" log "$arg" end`, `$i` and `$arg` are the same every time; the loop variable `$i` is there only for convenience.

Explicit array indexing is unsupported: To obtain an array element other than the first, use one of the following:

| • | Implicit indexing in the task block

| • | The `for` statement

Even within those contexts, assignment to the variable holding the array changes the entire variable value, not the current element.

## Other Features

An array that includes both string and numeric values is legal. Arrays of arrays are not allowed.

You can use the `sizeof` function to determine the number of elements in an array, as shown in the argument to the `task` block in the above example.

You can use the `for` statement to iterate over the elements of an array. See The For and Foreach Statement, for more information.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO GridServer®

Copyright © 2001-2022. TIBCO Software Inc. All Rights Reserved.