Multiprocessing Dynamics Script Tutorial (Python 3)

Name

Location

Multi processing<Vortex Studio Installation Folder>\tutorials\Python\Vortex\PyMultiprocessing\GenerateMechanismWithPy3Multiprocessing.py

This example shows some basic usage of the Python 3 "multiprocessing" module in a Vortex Dynamics script extension.

With its default settings, it will compute PI to 10000 precision digits and a Fibonacci sequence of 10000 numbers. 

Scripts

GenerateMechanismWithPy3Multiprocessing.py

For the dynamics script to be activated. it must be run in the context of a Vortex object, such as a mechanism.

This script will create a mechanism, add a dynamics script extension with the appropriate fields, and referring to Py3Multiprocessing.py.

The mechanism is then saved as Py3MultiprocessingExample.vxmechanism in the working directory.

Py3Multiprocessing.py

The script extension in the mechanism exposes the following inputs:

  •  VxData::Field<bool> Start → when true, starts the computation

 And the following outputs:

  • VxData::Field<std::string> PI → the computed value of PI.
  • VxData::Field<double> PI_Process_Time → the time it took to compute PI
  • VxData::Field<std::string> Fibonacci → the fibonnaci sequence
  • VxData::Field<double> Fibonacci_Process_Time → the time it took to comput the sequence
  • VxData::Field<std::string> Frame_Counter → the current frame
  • VxData::Field<bool> Done → Is set to true when done

To compute PI and fibbonacci, the script's PI() and fib() functions will be called in another python 3 process. 

Each step, the script checks is the result is ready in the queue.

When ready, the values and time taken are set in the outputs.


See Integrating Vortex Studio using Python 3 for more details about using Python.

Using the tutorial

  1. The code is fully documented explaining each steps.
  2. Use python to invoke GenerateMechanismWithPy3Multiprocessing.py
    1. A mechanism is saved in file Py3MultiprocessingExample.vxmechanism in the working directory.
  3. Start the Vortex Editor
  4. Load Py3MultiprocessingExample.vxmechanism
  5. Select the script in the explorer
  6. Press Simulate (Play) button to start the simulation.
    1. In the Properties panel, look at the frame counter output, number should increase 
  7. In the Properties panel, check the "Start" input of the script
    1. UI stays responsive and the Fibonacci computation is completed before PI is finished being computed.
    2. The time spent calculating is shown and the Done output is checked when calculations are done