Running commands in parallel or serially

You have the options of running commands in a script serially, in parallel, or serially and in parallel. You can do so by using the SERIAL or PARALLEL script commands in the COMMAND_LINE parameter of DEFINE and UPDATE SCRIPT. Therefore, it is possible to run multiple commands in parallel and wait for them to complete before the next command is run.

About this task

Running commands serially in a script ensures that any preceding commands are complete before proceeding and ensures that any following commands are run serially. When a script starts, all commands are run serially until a PARALLEL command is encountered. Multiple commands that are running in parallel and accessing common resources, such as tape drives, can run serially.

Script return codes remain the same before and after a PARALLEL command is run. When a SERIAL command is encountered, the script return code is set to the maximum return code from any previous commands that were run in parallel.

When you use server commands that support the WAIT parameter after a PARALLEL command, the behavior is as follows:

  • If you specify (or use the default) WAIT=NO, a script does not wait for the completion of the command when a subsequent SERIAL command is encountered. The return code from that command reflects processing only up to the point that the command starts a background process. The final return code from the command is not available to your script.
  • If you specify WAIT=YES, your script waits for the completion of the command when a subsequent SERIAL command is encountered. The return code from that command reflects processing for the entire command.

In most cases, you can use WAIT=YES on commands that are run in parallel.

Restrictions:
  • If the command starts a background process that does not have the WAIT parameter, the command is considered to be complete after the background thread is started. Therefore, the command can run only in parallel.
  • If you specify a script with the PARALLEL command, do not include a SHOW, QUERY, or SELECT command in the script. This restriction applies to all scripts, including scripts that call other scripts.

The following example illustrates how the PARALLEL command is used to back up, migrate, and reclaim storage pools.

/*run multiple commands in parallel and wait for 
them to complete before proceeding*/
PARALLEL
/*back up four storage pools simultaneously*/
BACKUP STGPOOL PRIMPOOL1 COPYPOOL1 WAIT=YES
BACKUP STGPOOL PRIMPOOL2 COPYPOOL2 WAIT=YES
BACKUP STGPOOL PRIMPOOL3 COPYPOOL3 WAIT=YES
BACKUP STGPOOL PRIMPOOL4 COPYPOOL4 WAIT=YES
/*wait for all previous commands to finish*/
SERIAL
/*after the backups complete, migrate stgpools 
simultaneously*/
PARALLEL
MIGRATE STGPOOL PRIMPOOL1 DURATION=90 WAIT=YES
MIGRATE STGPOOL PRIMPOOL2 DURATION=90 WAIT=YES
MIGRATE STGPOOL PRIMPOOL3 DURATION=90 WAIT=YES
MIGRATE STGPOOL PRIMPOOL4 DURATION=90 WAIT=YES
/*wait for all previous commands to finish*/
SERIAL
/*after migration completes, relcaim storage 
pools simultaneously*/
PARALLEL
RECLAIM STGPOOL PRIMPOOL1 DURATION=120 WAIT=YES
RECLAIM STGPOOL PRIMPOOL2 DURATION=120 WAIT=YES
RECLAIM STGPOOL PRIMPOOL3 DURATION=120 WAIT=YES
RECLAIM STGPOOL PRIMPOOL4 DURATION=120 WAIT=YES