LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Execution questions

Come, come, all the experts!
Today only! Two for the price of one!

First question:
Look at the attached VI. It has a for loop with a 2D array in it. When the array is auto indexed out of the loop the loop runs faster than when it isn't. Why?

Second question:
When I initialize an array to be 99999 by 99999, I usually just get an empty array back. Sometimes, I get a warning message about memory, which I can handle, but I'm wondering why most of the time I get nothing at all.

Both of these are in 7.0 on a XP Pro laptop.

Maybe it really is time to take that LV course...

___________________
Try to take over the world!
0 Kudos
Message 1 of 14
(4,063 Views)
Hi tst,

can you post a pic of the diagram? I only have LV 6.1, but I'd like to be able to have a think about it all the same.

Thanks

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 2 of 14
(4,057 Views)
OK, even without a diagram of code to go by, I'll take a stab at an explanation why the error message only comes sporadically.

When LV allocated an array, it needs to allocate a SINGLE block of memmory to hold the array. When running programs, the RAM gets fragmented with data being created, destroyed, moved and so on. It could be that even with the same amount of free memory available, that LV simply can't locate a single contiguous block of memory large enough for the array at that time. All it takes is a single pesky U8 in the middle of what would otherwise be a perfect home for your 99999x99999 array. Kind of like tiny footprints through an otherwise pristine snow-covered field.

The weather just got nice here, and I miss the snow a bit. Sorry for that.

Either way, that's my take at the moment as to why the error message doesn't always come. As to the execution speed, I'll wait until I can have a look at the code (or a pic of it).

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 14
(4,053 Views)
Shane, here's the VI in 6.1. The flat sequence was replaced, but the beaviour is still there.

I wasn't asking about the error. I asked why do I get an empty array (every time) with no error (usually) when I initalize a large array.

___________________
Try to take over the world!
0 Kudos
Message 4 of 14
(4,050 Views)
Ah OK,

Sorry. I've run the VI on my PC and have observed the same thing you have. I think I have an idea where the execution times are coming from.

As far as I know the compiler for LV is quite clever. By autoindexing the for loop, the appropriate array size is set BEFORE the loop is run to maximise execution time. If the output of the loop is not passed anywhere though, the array is simply not generated. Although the diagram shows the array being indexed, the compiler sees that this isn't actually going anywhere and so it doesn't bother allocating megabytes of data which won't be used anywhere.

Thus, with autoindexing enabled, the compiler skips the allocation, thus saving time. With autoindexing disabled, it doesn't seem to check if the array is being used further, and allocates the single array again and again and again.

If you DO wire the array out of the FOR loop, you'll see that the WITH indexing is again FAR slower than WITHOUT. As expected.

I haven't been able to get the VI to give me an empty array. I've generated the error message, but I don't see the empty array.

Hmmm.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 5 of 14
(4,048 Views)
Thanks, Shane. Your answer sounds reasonable. I figured it was probably something along those lines ("the compiler does this because...").
BTW, your VI didn't run "FAR slower". It took up so much memory it made my machine almost freeze. I couldn't even stop it. I had to crash LV and restart windows. So here is a warning to anyone trying to run it. What's interesting is that it updated the i indicator on the FP up to 12 (or 21) and only then it started running slowly. If the memory allocation is done before the loop starts, I wouldn't even expect it to get that far.
The other issue - it's basically just an empty VI with "Initialize Array" inside it and an indicator coming out of the function. I checked this in 6.1, 7, and 7.1 and you're right - 6.1 gives an error everytime, while 7.1 and 7 usually give an uninitialized array (at least 7. I only ran it a couple of times on 7.1 and that's on a different PC anyway). I'm guessing this is another "protect the memory" issue, I was just wondering why there is no error generated.

Message Edited by tst on 03-15-2005 12:57 PM


___________________
Try to take over the world!
0 Kudos
Message 6 of 14
(4,040 Views)
Oops,

Sorry about the freezing bit. It really RAN on my PC. Only REALLY slow. It didn't hang though.

I seem to get an error message every time I try to allocate an array that's too big, so maybe it's really a LV 7 thing?

About allocating the memory. I guess the system starts accessing the swap file after a few runs with a really large array. I think this is the difference in execution speed. The system will reserve the space in the swap file when starting, but only when it actually ACCESSES the swap file will the execution slow down hugely (As in my case) or freeze (as in your case - again sorry).

That's my take on it anyway, if anyone else knows better, please correct me.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 7 of 14
(4,030 Views)
Hello (hello, hello)...
Is there anybody in there?
Just nod if you can hear me...
All you guys starting with an E and ending with a T...
Doesn't anybody know?
Shane's answer appears correct, but I'm still left wondering why I'm getting an empty array with no error.

___________________
Try to take over the world!
0 Kudos
Message 8 of 14
(3,988 Views)
What a crazy thing : when using auto-indexation, you ask for a 999 x 999 x 8 x 10000 memory space (about 80 Gbytes)!
I'll try to study your problem, but that's not exactly the right moment now : 2 am local time. My wife is getting crazy !

CC
Chilly Charly    (aka CC)
0 Kudos
Message 9 of 14
(3,971 Views)
You can stop worrying. I don't have a problem. This is just a demo. I was only wondering.
How did you get to 80 GB? The initial array had 1M DBLs, which is 8 MB, and the loop iterates 1,000,000 times...
Maybe your wife is right and you shouldn't be answering questions at 2 AM...
Besides, you already passed your 3 r\d limit. You have no business posting further replies... (unless you consider 2 AM a new day).

Like I said, I think Shane's answer sounds reasonable, so I'm more interested in why I didn't get an error when trying to initialize the array in my second question. In 6.1 you do get an error message.

___________________
Try to take over the world!
Message 10 of 14
(3,960 Views)