LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How sort array without using Sort 1d Array?

Oh man, that stop logic! There is no reason to use local variables (and certainly no reason to make the "True" case wire a "True" constant). I can try out your VI but it's going to cost you, you're going to have to upload the the actual VI and not a screenshot.

0 Kudos
Message 11 of 22
(3,515 Views)

Maybe you are right. 

0 Kudos
Message 12 of 22
(3,508 Views)

@crisdragon wrote:

Maybe you are right. 


Just looking at it for 1 second: Your VI is still full of race conditions. There is no guarantee that the local variable in the upper ight gets read only after the same local variable gets written in the case below, but the outcome critically depends on the order. Use dataflow!

 

(I have not looked at the overall algorithm yet.)

0 Kudos
Message 13 of 22
(3,492 Views)

Hi Cris,

 

It works for me 1000 times out of 1000! You will have to add the input array and output array to the top left and right terminals respectively to run this snippet.

 

test sort array.png

0 Kudos
Message 14 of 22
(3,467 Views)
What is "it" that works?
0 Kudos
Message 15 of 22
(3,461 Views)

I'm referring to zad1d.vi in message 12. It appears to give the same output as the native 1D sort function.

0 Kudos
Message 16 of 22
(3,459 Views)
Sorry, posting from mobile, cannot see message numbers. If it works now, we are lucky that the compiler decided on a good order of operations. This could change whenever seemingly benign changes are made to the code, causing a recompile, or the VI upgraded or downgraded to a different version.
Even if both orders give a good result, it is a glaring programming error that teaches bad habits that can bite us in the future.
0 Kudos
Message 17 of 22
(3,443 Views)

Hi gregoryj,

 

because a VI with known race conditions will work in your example case (computer, CPU, dataset, compiler options, OS, moon phase, many more) it will work always as expected?

 

What's the problem to remove race conditons and clean up such a small VI?

check.png

Atleast the OP should have done this…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 18 of 22
(3,420 Views)

Here is version that fixes the race conditions, and also uses the inplace element structure and swap functions to simplify the array manipulation code.

Message 19 of 22
(3,404 Views)

Hi GerdW,

 

I made no such claim


It works for me 1000 times out of 1000!


 

And I fully expect a waning moon to throw it off Smiley Very Happy

 

0 Kudos
Message 20 of 22
(3,402 Views)