07-12-2022 10:40 AM
Hi folks,
I have a question about how LV handles the preallocation/inlining of subVIs and what affect this has on CPU usuage. I've read some resources/gone through the forums and haven't found much that answers my question, which is: Does preallocation and inlining of subVIs increase the CPU usage?
I've attached the VI I've been working on (it is not great code... been trying to move into a state machine structure but is taking some time). The idea is that the VI reads in data from a CSV file that contains some information about the Shared Variable URL, finds and opens this data, creates a folder and files based on current time and data collection "run", and starts collecting data in tab 4. Tab 4 is some what of a producer/consumer architecture (crude) but a timed loop generates data from the Shared Variables and is passed into the next loop which writes this data to a row with date/time information, which is then passed to another loop which handles writing to the file. There are separate loops which handle a syncing and zipping operation, which are on a separate clock.
This VI used to work fairly well; consumed no more than 20% of CPU resources, but (I believe) since moving into preallocating subVIs, the program CPU usage has skyrocketed into the upper 70 to 80% of CPU usage. I am preallocating subVIs for the purpose of running copies of the same VI to collect/write data, and each copy of the VI needs to access the same VIs which to my understanding, needs to have its own space to store data and not overlap with another VI trying to access the same subVI.
In short, should I stop the preallocation to see if the CPU usage will go down? Or is there something more fundamentally broken with my code?
Resources I found to be most relevant: https://forums.ni.com/t5/LabVIEW/Enable-inline-subvi-property/td-p/3698451, https://www.ni.com/docs/...
Solved! Go to Solution.
07-12-2022 11:17 AM
Quick question:
Could it be that you're just getting more done per second with the preallocated clones? 4x the work will probably also create 4x the CPU load.....
Inlining should not increase CPU load unless your code complexity is high and LV cannot apply certain optimisations any more.
07-12-2022 12:12 PM - edited 07-12-2022 01:02 PM
Judging from the block diagram preallocating clone reentrant VIs and inlining subVIs is the least of your worries...
07-12-2022 12:41 PM
My only thought when I opened this was to suggest starting over using an actual framework/architecture. This code is a prime example of spaghetti code.
07-12-2022 01:24 PM
Hi folks,
Yes, my code is VERY bad lol. I am currently the only one in my research group that is putting together this program AND I have pretty minimal programming experience (started LV about 6 months ago, with some intro to programming almost a decade ago at this point). It has been hard-going to say the least. I would like for my program to follow a state machine framework as mentioned before, but there seem to be few resources that point me to a good place to start. Does anyone have any suggestions? I would really appreciate the help 🙂
07-12-2022 01:33 PM
Download the JKI state machine via the JKI package manager. That would be a good starting point.