02-03-2024 06:38 AM
I am trying to make a calculation and I am using intertwined for-loops. I attach an example that has less input data because of the memory problem. In real my application uses Z2 array (101x261X261X64) and Input Array (5000X64). As a result, intertwined for-loops have taken 4 hours and have given "not-enough memory" errors so I increased Z2 size (51x131X131X64) 8 times less. Is there any way the decrease the calculation time and increase the limit of using memory? (I am using 32-bit Labview Community Ed. 2023 Q1)
Solved! Go to Solution.
02-03-2024 09:15 AM
Can you do a "save for previous, LabVIEW 2020 or below)?
(I currently don't have access to LabVIEW 2023 until later)
Do you really have 4D arrays? What's the datatype?
02-03-2024 12:29 PM
I attached 19 version
02-03-2024 12:50 PM - edited 02-03-2024 12:55 PM
Can you explain what the data represents, where it comes from, and what algorithm you are trying to implement?
Only two of your inputs are on the connector pane (Z, Z2), so where does all the other data comes from?
A 4D array of 101x261X261X64 DBLs already needs several contiguous GB in memory for one data copy you'll never will be able to run it in 32bit LabVIEW. Do the math! Even if you would use SGL, you'll run out of memory!
What's the purpose of the sequence structure? Why do you need that extra loop stack on the left? Why not average the nonzero elements in the main loop.
Why would you hide labels of terminals? A really bad habit! Just to obfuscate the code?
There is no reason in the world to maximize the front panel and diagram to the screen. Another bad habit!
As has been said, there is a fundamental barrier to even run this on 32bit LabVIEW with the full dataset. (And I doubt it is reasonable even on 64bit!)
Here's your code slightly cleaned up so we can actually debug it. This is a literal verbatim rewrite without any attempt at optimization. I see many places to optimize!
In terms of performance, Deep stacks of loops have a relatively large debugging overhead. Your code doubles in speed if debugging is disabled and the outer loop can be parallelize for a speed increase proportional to the number of CPU cores if you remove the incremental timing. (still does not solve your memory problem)
With the 11x27x27x64 4D DBL array of your example and using all default data, the code executes in about 100ms here.
02-03-2024 01:07 PM
Your 4D array data seems very smooth and maybe does not even need to exist in memory, but could be calculated from simple math based on the array indices.
02-03-2024 03:03 PM
Thanks for your replies;
"Can you explain what the data represents, where it comes from, and what algorithm you are trying to implement?": I attached a new file where the data comes from.
"Why would you hide labels of terminals? A really bad habit! Just to obfuscate the code?"
I have attention deficit disorder. The names of the icons distribute the code very much, and this confuses me.
"There is no reason in the world to maximize the front panel and diagram to the screen. Another bad habit!"
you right. and I am not professional I am just trying.
"I see many places to optimize!":
For example?
"Your code doubles in speed if debugging is disabled"
I don't know how I can do it could you tell me the clue?
02-05-2024 10:55 AM
You are confusing us with piles and piles of FOR loops that creates a 4D array with a huge redundancy in the elements.
Maybe you could explain the math behind it instead!
You seem to create three linear ramps which you transform into a gigantic hairball of a 4D (!) array. Can you point to a manual or website that explains the processing of the blue input array based on these three ramps? I get the feeling that this problem is much simpler than you want us to believe. 😄
02-06-2024 11:32 AM
@Yakup1971 wrote:
Thanks for your replies;
Please never ever attach a new VI with exactly the same file name as an older VI. Very confusing to keep things organized.
02-06-2024 12:28 PM
@Yakup1971 wrote:
"Your code doubles in speed if debugging is disabled"
I don't know how I can do it could you tell me the clue?
02-07-2024 02:19 PM
@altenbach wrote:
Maybe you could explain the math behind it instead!
Still waiting for that!
As a small example, here's how your lower left loop could be simplified (but that's not your bottleneck)
Since all your calculations are in DBL, you should covert it to DBL as first step, of course. Fortunately, your inpt data is all positive, else the Sum!=0 is problematic, because e.g. [-5, -2, 0, +5, +2] would sum to zero, even though the data is valid.