LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Very poor in array's

Since no one replied between, so I finished that with the help of auto-indexed tunnel, which I don't want to do. Now my code is running 10^9 times. Still it is running from from minutes and I am excited to see Output.

 

Thank you. I will post my code soon here.

0 Kudos
Message 11 of 23
(1,047 Views)

After several minutes run I got some memory notification errors and I stop my run. First, I tried to run my code with for loop count as 10^9 and got the same error at start of my run. After that I changed my for loop to while loop, even it says the same error after 25 minutes approximately.

 

Now, I need to know about these memory contraries. Don't say any thing about arrays. I will again try tomorrow, if I have free time. Until then good night. See you all tomorrow.

 

Download All
0 Kudos
Message 12 of 23
(1,029 Views)

Your code tries to generate arrays with 1e9 elements, which is not reasonable on current hardware.

 

You are trying to generate two U64 arrays (8bytes/element), each with 1e9 elements, meaning you would need 16GB of contiguous memory to succeed for the loop alone. (plus a few extra copies for the array indicator and transfer buffer, the 2D array, etc)

 

Maybe in a few years on a 64 bit OS.

 

You also have a 1ms wait, meaning the loop process will take a million seconds. 😄

0 Kudos
Message 13 of 23
(1,014 Views)

The autoindexing at the loop outputs builds arrays.  Since the compiler cannot determine in advance how many times the loop will iterate, it cannot pre-allocate memory for the arrays.  Every time the arrays outgrow the space which has been allocated, a new smpace must be allocated and the entire array moved to the new location.  Also, arrays must occupy contiguous memory locations, so the repeated reallocation of memeory soon fragments memory and when an contiguous space large enough for the new array exists, you will get an out of memory message.  Pre-allocating an array as large as the largest possible result outside the loop and then using Replace Array Subset will avoid that problem ( up to the limit of your memory).

 

With a 1 millisecond Wait in the loop it will run for over 11 days.  A Wait is important if the loop needs to run at a particular rate or if other parts of the code need to run in parallel.  In this case it just slows things down.  Without it 10 million iterations takes about 3 seconds (Mathscript node disabled because I do not have it).

 

Since the limit value is expressed as an I32, why not just use "i" for the x input? It is generated automatically by the loop (no feedback node or add 1 required).

 

Why combine the two arrays into a 2D array and then immediately index them back out again.  Look at Tools >> Profile >> Show Buffer Allocations.  You need at least three additional memory allocations for the large arrays.

 

Do you really need an array with all the integers up to 1000000000?  What information does it provide?

 

While working through these issues, I suggest that you change the 10000000001 constant to a control, move it outside the loop, and get your program running with smaller values.

 

Lynn

0 Kudos
Message 14 of 23
(1,008 Views)

If you use Initialize array you'll create an empty array, so yes, you'll only see the last number.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 15 of 23
(994 Views)

Using mathscript is kind of cheating, solve it in LV code. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 16 of 23
(999 Views)

Hi Peter,

 

one more issue: when using a case structure with an "default if unwired" output you also tend to loose information (and at the same time create unwanted data)...

 

And when I suggested to calc primes I wanted you to actually use LabVIEW - and not cheat by using a paid toolkit to do the work for you. And you should atleast keep one thing: using predefined functions of toolkits doesn't help in understanding LabVIEW/dataflow (which I thought was the primary goal for this exercise)!

 

- To calc primes you can use big arrays, and you wanted to learn about them...

- I suggested that big range to force you into using efficient programming schemes (including shift registers!) - I thought you wanted to learn that...

- Not wanting to use loops is IMHO not a good way to learn programming and kind of senseless... (It's like learning to drive, but don't wanting to use a steering wheel.)

 

Again I want to suggest reading the BASICS courses provided by NI Smiley Wink

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 17 of 23
(991 Views)

Thank you all guy's....For pointing finger on me..Especially "oh my friend GerdW"

 

Now I am bit doing another work in labview. I will do it in my leisure time.

 

Love NI forum.

0 Kudos
Message 18 of 23
(985 Views)

GerdW wrote:

And when I suggested to calc primes I wanted you to actually use LabVIEW - and not cheat by using a paid toolkit to do the work for you.


Well, starting with LabVIEW 2011, we also have prime factor, so simply looping over the desired number range and looking at the array size of the prime factors output would work. Of course it would take forever. 😮

 

(Long ago, I wrote a VI that is pure LabVIEW and finds all prime number with 8 or less digits in about 5 seconds on my 5 year old laptop (probably faster on a modern computer ;)). Take that as a reference and try to beat it.)

0 Kudos
Message 19 of 23
(983 Views)

Hello altenback,

                                I had copied your logic after a search in forum yesterday. That's basically your idea.Smiley Sad

0 Kudos
Message 20 of 23
(978 Views)