04-10-2016 06:14 AM
Hi everyone,
I have written a program which contains multiple parallel while loops (15 or more) which seem to execute simultaneously. For the moment, the application works works perfectly as all the threads ( loops ) start at the same time bringing own cycle time and LV seems to work in parallel. The different while loops have to work constantly without being stopped at any time.
The problem is that the code is beginning to be a real monster because of the the large number of loops in just one frame and each becomes huge. I would like to work in different frames but obviously that is complicated since are infinite loops. On the other hand, I gues I should control the data flow that is becomeing a mess. None of the loops is master over the other and have to run autonomously with its own cycle time. And there are shared variables that could influence on the race condition.
I attached an example of a very simple app where you could imagine that each while loop would be so big.
Thank you very much for the help.
04-10-2016 07:11 AM
04-10-2016 07:28 AM
Because the main frame is so huge (and is getting bigger) and is quite hard to anderstand the code because of the number of while loops.
I can´t use subVIs with infinite loops inside.
It´s more a debugging problem cause the app runs fine.
With the sync loops (notifiers, queus, semaphores...), each loop must wait to start to run. I want every loop run so independently of the rest. Concurrently. I guess we 're talking about asynchrony... Do you know how can I "clean" my code in relation to the number of while loops I have in a single frame?
TY
04-10-2016 07:33 AM
I´m Lolo... don´t know why I can´t log in with my account. Sorry about the posible confusion
04-10-2016 09:48 AM
@Electro0000 wrote:I guess we 're talking about asynchrony...
Electro0000,
Are you also lolobosco?
If all of the While loops are basically executing the same code in parallel, then you certainly are talking about asynchrony. We did a project a few years ago where we were monitoring behavior by taking videos, and we needed to handle 24 stations. We wrote a single sub-VI that managed one station, then used Start Asychronous Call, with the Station Number as a parameter, and called 24 "clones" that all ran simultaneously. Worked like a charm.
Here's what you need to do to make this work:
You may notice that I'm a little vague on whether or not you need the x40 option flag. In our code, we did not set it, yet our cameras all run simultaneously, in parallel, and their sub-VIs are definitely set to Pre-allocated Reentrant Clones. We stop them using a VIG.
Bob Schor
04-10-2016 10:08 AM
Bob,
Yes, I´m Lolo...
It´s very interesting what you mention. I´ve never used any asynchronous app. I need to read about it and follow some rules... I´ll follow your advice of the design.
Thank you very much Bob.
04-10-2016 12:04 PM
Bob,
I´m not really sure how the asynchronous VI works... Would you please attach an example with 2 or 3 while loops (subVIs) running asynchronously and concurrently controlled by a main VI? I would be grateful if you could do so...
04-10-2016 01:16 PM
I really liked this blog, and it might give you idea how to deal with async subVIs...
http://www.walkingthewires.com/2015/07/20/something-happened-events-in-labview/
04-10-2016 01:28 PM - edited 04-10-2016 02:16 PM
@lolobosco wrote:
I´m not really sure how the asynchronous VI works...
Here's a very quick draft. See if it gives you any ideas.
I am using a single DVR to share information across all VIs (main and sub).
The IPE ensures proper locking.
(To add more processes, simply change the array size of the DVR and resize the indicator accordingly.)
04-10-2016 01:29 PM
Hi Blokk,
I like that blog as well but I guess that I need something easier...something like this:
http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/acbr_call_and_collect/
The problem is that my subVI is an infinite while loop and when a make an asynchronous call to it, I can´t collect its results.
I also have tried to make a dynamic process VI but I´ve had no luck...