Multiprocessing Simulation Script Tutorial (Python 2)
Name | Location |
---|---|
Multi processing | <Vortex Studio Installation Folder>\tutorials\Python\VortexPython2\PyMultiprocessing\GenerateMultiprocessingMechanism.py |
This example shows some basic usage of the Python 2 "multiprocessing" module in a Vortex Simulation script extension.
With its default settings, it will compute PI to 10000 precision digits and a Fibonacci sequence of 10000 numbers.Â
Scripts
GenerateMultiprocessingMechanism.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 script extension with the appropriate fields, and referring to MultiprocessingExample.py.
The mechanism is then saved as Py2MultiprocessingExample.vxmechanism in the working directory.
MultiprocessingExample.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 2 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 Vortex Studio SDK - Python 2 Scripting for more details about using Python.
Using the tutorial
- The code is fully documented explaining each steps.
- Use python to invokeGenerateMultiprocessingMechanism.py
- A mechanism is saved in file Py2MultiprocessingExample.vxmechanism in the working directory.
- Start the Vortex Editor
- Load Py3MultiprocessingExample.vxmechanism
- Select the script in the explorer
- Press Simulate (Play) button to start the simulation.
- In the Properties panel, look at the frame counter output, number should increaseÂ
- In the Properties panel, check the "Start" input of the script
- UI stays responsive and the Fibonacci computation is completed before PI is finished being computed.
- The time spent calculating is shown and the Done output is checked when calculations are done