Parallelization

This tutorial provides an example of using the Composite block parallelization feature.

Note

This tutorial requires the workflow from Workflow as a Block.

Before You Begin

This tutorial requires an existing prjTutorials project. If you have not created this project yet, see Tutorial Project first.

  • Open the prjTutorials project.
  • Open wfToySolverBlock (ToySolverBlock.p7wf).
  • Select File ‣ Save Workflow As... to create a copy of the workflow. Save the workflow as wfTestParallelization.
  • Verify that you are editing wfTestParallelization and continue with the tutorial.

Task

As noted before, the original Toy Solver integration workflow cannot process batch input — that is, it does not allow you to specify a list of input vectors and calculate all outputs in one run.

The task is to create a Toy Solver sampling workflow. It shall generate some input sample, process it automatically, and collect output values for analysis.

Solution

Creating a sampling workflow in this example can be divided into the following general steps:

  • Generate an input sample.
  • Reconfigure the Toy Solver integration block to process the input batch in parallel.
  • Collect results to get an output sample.

Input Sample Generation

To simplify the example, let us use a simple random data sample (alternatively, you can use a DoE block as described in the Model Evaluation tutorial, section Test Sample Generation).

Note

If you have already completed the Sampling Loop tutorial, you can copy the GenerateInputs block from there to skip this step.

  • Add a Random block. Name it GenerateInputs.

Configure the block to output a random matrix with a set number of columns (input dimension) and the number of rows as a workflow parameter.

  • Open GenerateInputs configuration. On the Configuration tab, change output mode to matrix. Leave other settings default.
  • Switch to the Ports tab.
  • Assign a value to GenerateInputs.cols, 2.
  • Select GenerateInputs.rows as a parameter.
  • Click b_ok in the configuration dialog to save settings and close the window.

The block will generate a random data sample and output it to GenerateInputs.value. Sample size should be set in Run (the number of matrix rows is a parameter).

Sample Processing

In contrast with the Sampling Loop tutorial, the current example does not process the input sample sequentially but uses block parallelization, a special feature available in Composite blocks (like Model).

../_images/page_tutorials_parallel_01_pe.png
  • Open Model configuration.
  • On the Configuration tab, select “Enable Parallel Execution”.
  • Select the x port from the drop-down list. You can also change the parallelization ratio or leave it default (4).

Note that once you enable parallelization, Model.x and Model.f change their type.

../_images/page_tutorials_parallel_02_ports.png

Both ports now allow List in addition to RealVector. As a result, the output of GenerateInputs.value can now be sent directly to Model.x: pSeven converts the generated RealMatrix to a List of RealVector values, and they are automatically processed by Model.

Note that in order to save results from this workflow you need to monitor Model input and output.

  • Enable monitoring for Model.x and Model.f.

Finally, link GenerateInputs.value to Model.x.

Workflow

Final workflow with a parallel Model block enables processing the generated input sample without using a calculation loop.

../_images/page_tutorials_parallel_03_wf.png

It can be said that when this workflow starts, pSeven creates several virtual copies of the Model block and automatically distributes input points among them. Once any of these virtual blocks finishes calculation, it receives a next point from the sample, so there is no specific processing order.

Note

It is also possible to set the parallelization ratio to 1. It means that only one instance of Toy Solver will run actually, but Model.x will still support the List data type.

Results

To get a Toy Solver response sample, specify the sample size in Run (for example, 500) and run the workflow.

Input and output values are stored to the Model.x and Model.f records respectively.

../_images/page_tutorials_parallel_04_pdb.png

With these results, you can plot response surfaces for Toy Solver outputs, for example:

  • Create a new report.
  • Add Model.x and Model.f to data series.
  • Add a 3D surface plot with two datasets.
../_images/page_tutorials_parallel_05_plot.png
  • First dataset: “Model.x[0]” as X, “Model.x[1]” as Y, “Model.f[0]” as Z.
  • Second dataset: “Model.x[0]” as X, “Model.x[1]” as Y, “Model.f[1]” as Z.