Hi there,
another thread here got me curious:
What are my options for parallel programming in VENUS. I no the parallel forking in VENUS but it only works in the main method and not in sub methods. I read about the fork and join library but don’t have any insight into this.
I also don’t think this was covered in the advanced VENUS programming course I attended. Could somebody please enlighten me and send me on the right track to do my research? E.g. I’d like to do stuff while the MPE² is processing samples.
best
Dominik
2 Likes
Have you had a look at the Help menu in Venus?
Generally I’d use hsl blocks and Fork
/Joins
. This is a relatively common idiom in lower level programming languages: CS 365: Lecture 13: Fork/Join Parallelism.
The main catch is that you cant use step variables, as you just give the step name to the Fork
function. As the help says, you have to pass in any variables it does need through global variables.
FWIW, parallelising the MPE2 is possible and can be very useful.
1 Like
As I do not come from a C background: Could you show this in an easy example in the method editor itself? From that snippet I don’t really get the logic.
1 Like
Hi Dominik,
We have a library which can be used in method editor which allows for use of fork and join for flow control while providing a layer of abstraction above using in-line HSL or programming in HSL method editor.
Fork and join lib
To use the fork function, you provide a string variable input (or can hardcode the string) of the name of a local submethod or the name of a library function included with the method. This will asynchronously begin execution of the selected submethod or function in a parallel thread, while immediately continuing execution of subsequent method or function steps in the other thread. The fork function returns a numeric ‘thread handle’ variable, which can be used subsequently used downstream with the join flow control directive.
As @Gareth mentioned, the fork call does not support submethods or functions that use parameters. However, the submethod/function called by the fork can wrap around other functions that use parameters. For external configuration of local variables within the forked function, either approach will require the use of either task-local or global variables.
The join function is optional, but can be extremely useful for flow control depending on what the forked function/thread is doing. Once forking a thread, you can either let the forked thread run in parallel until it completes while the method trucks along, or you can use the join later on in the method as a a bookmark to halt method execution at a desired point until the forked thread has completed or returned. To use the join call, simply provide the numeric thread handle variable returned by the fork.
Another option to communicate or signal between parallel threads is through the use of events. This is their typical use in VENUS.
See below for a basic example of using fork and join for flow control and parallel execution in method editor:
Thanks.
-Nick
10 Likes
Hi Dominik,
I love the contributions by @Gareth and @NickHealy_Hamilton in this thread, but I wanted to highlight another strategy that effectively allowed me to parallel process within submethods. For this, I utilized global event objects.
You can initialize events with global scope by navigating to Method>Global Variables:
Begin your parallel process before your submethod call in main(). Insert a “Wait for Event” step at the start of your process and reference your event handle.
In your submethod, include a “Set Event” step referencing the event handle. This effectively delays the fork until a particular step in your submethod is reached.
I like this approach because it gives me flexibility to trigger a parallel process basically whenever I want to. You can even configure your process accordingly using multiple event handles and conditional statements. It’s also friendly with loops, as when the “Wait for Event” command is run, the event object’s state is reverted so that it may be triggered again. Let me know if you find this helpful!
5 Likes
Hi all,
just wanted to say: Thanks for the help, great new ideas to wrap my head around in the next few weeks
3 Likes
This is amazing - I had been thinking about this question myself just this week. Thanks everyone!
1 Like