Prism 6.0 User's Guide

Defining Psets

You can create psets in MP Prism. This section describes the syntax of pset creation.

Syntax for Defining a Pset

This section describes the syntax you can use to specify a pset. As described below, you can assign a name to a pset you specify using this syntax; this provides a useful shorthand for complicated pset specifications.

First, to specify a pset as an argument to a command:

To apply a command to a specific pset, use the pset keyword, followed by a process specification. Put this pset clause at the end of the command line (but before an on window clause, if any). Thus,

print x pset error

prints the values of the variable x in the predefined pset error. (See " Visualizing Multiple Processes in MP Prism" for a discussion of printing variables in MP Prism.)

To specify your own pset as part of this pset clause:

Specify an individual process number. An individual process can constitute a pset. Thus,

print x pset 0

prints the value of x in process 0.

Specify the name of a pset. Name a pset using the define pset command, as described in the section "Naming Psets," below. Thus,

print x pset foo

prints x in the processes you have defined to be members of pset foo.

Specify a list of process numbers. Separate the numbers with commas. Thus,

print x pset 0, 4, 7

prints x in processes 0, 4, and 7.

Ranges and strides are allowed. Use a colon between two process numbers to indicate a range. Use a second colon to indicate the stride to be used within this range. Thus,

print x pset 0:10

prints x in processes 0 through 10. And

print x pset 0:10:2

prints x in processes 0, 2, 4, 6, 8, and 10.

You can also combine comma-separated process numbers and range specifications. For example,

print x pset 0, 1, 3:5, 8

prints x in processes 0, 1, 3, 4, 5, and 8.

Specify a union, difference, or intersection of psets. To specify the union of two psets, use the symbol +, |, or ||. For example,

print x pset 0:2 + 8:10

prints x in processes 0, 1, 2, 8, 9, and 10.

print x pset foo | bar

prints x in processes that are members of either pset foo or pset bar.

Prism evaluates the pset expression from left to right. If a process returns true for the first part of the expression, it is not evaluated further. In the above example, if a process is a member of foo, its value of x is printed; Prism does not check its membership in bar.

Use a minus sign to specify the difference of two psets. For example,

print x pset stopped - foo

prints x in all processes that are stopped except those belonging to the pset foo.

To specify the intersection of two psets, use the &, &&, or * symbol. For example,

print x pset foo & bar

prints x in processes that are members of both pset foo and pset bar. If a process returns false for the first part of the expression, it is not evaluated further. In the above example, if a process is not a member of foo, Prism doesn't bother checking its membership in bar; it won't be printed in any case.

Prism must evaluate a pset expression in each process at the time the command is executed; the processes must be stopped for Prism to do this. The evaluation fails if any of the processes being evaluated are running. Using the predefined pset stopped on the left of an intersection expression is a useful way of ensuring that a command applies only to stopped processes.

Thus,

print x pset stopped & foo

prints x only in the members of foo that are stopped.

Specify a condition to be met. Put braces around an expression that evaluates to true or false in each process. Processes in which the expression is true are part of the set.

Thus,

print x pset { y > 1 }

prints x in processes where y is greater than 1. And

print x pset all - { y == 1 }

prints x in all processes except those in which y is equal to 1.

Membership in a set defined with this syntax can change based on the current state of your program; such a pset is referred to as variable. See " Evaluating Variable Psets " to learn how to update the membership of a variable pset.

For this syntax to work, the variable must be active in all processes in which the expression is evaluated. If the variable isn't active in a process, you get an error message and the command is not executed. To ensure that the command is executed, use the intrinsic isactive in the pset definition. The expression isactive(variable) returns true if variable is on the stack for a process or is a global.

Thus, you could use this syntax to ensure that x is printed:

print x pset stopped && {isactive(x)}

Naming Psets

You can assign a name to a pset. This is convenient if you plan to use the set frequently in your Prism session.

Use the syntax described above to specify the pset. You can use any name except the names that Prism pre-defines; see " Predefined Psets". The name must begin with a letter; it can contain any alphanumeric character, plus the dollar sign ($) and underscore (_).

For example,

define pset odd 1:31:2

creates a pset called odd containing the odd-numbered processes between 1 and 31.

define pset xon { x .NE. 0 }

defines a pset consisting of those processes in which x is not equal to 0. Note that x must be active in all processes for this syntax to work. As described above, you can use the intrinsic isactive to ensure that x is active in the processes that are evaluated. For example,

define pset xon { isactive(x) && (x .NE. 0) }

Both versions create a variable pset whose contents will change based on the value of x. See below for more discussion of variable psets. Finally, note that all processes must be stopped for this syntax to work. To ensure that the definition applies only to stopped processes, use this syntax:

define pset xon stopped && { isactive(x) && (x .NE. 0) }

Dynamic user-defined psets are deleted when you reload a program. To get a list of these psets before reloading, issue the command show psets. You can then use this list to help reissue the define pset commands. See " Viewing the Contents of Psets" for more information about show psets.

Evaluating Variable Psets

Prism evaluates the membership of a variable pset when it is defined. If no processes meet the condition (for example, because the program is not active), Prism prints appropriate error messages, but the set is defined.

Subsequently, you can re-evaluate the membership of the pset by issuing the eval pset command, specifying the name of the pset as its argument. For example,

eval pset xon

evaluates the membership of the pset xon. This causes the display for the pset to be updated in the Psets window.

Note that this evaluation will fail if:

For example, if you issue this command:

define pset foo { x > 0 }

you must make sure that all processes are stopped, and x is active on all processes, when you issue the command

eval pset foo

To ensure that the evaluation succeeds, you would need to use the more complicated syntax described above:

define pset foo stopped && { isactive(x) && (x > 0) }

This ensures that the evaluation takes place only in processes that are stopped and in which x is active.

If an evaluation fails, the membership of the pset remains what it was before you issued the eval pset command.

You can use the eval pset command in event actions; see " Events Taking Pset Qualifiers (MP Prism Only)".

Note the difference between dynamic and variable psets. The membership in both can change as a program executes. Dynamic psets are predefined sets like stopped and interrupted; Prism automatically updates their membership as the program executes. Variable psets are defined by the user, and the user must explicitly update their membership by issuing the eval pset command.