LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parallel writing into a structure array at two positions without losing one modification

Solved!
Go to solution

I have an array containing a structure.

I am addressing the subarray (1 entry) of index i and n parallel using the array subset function because I want to update the entry at position i and n parallel, let's say in a parallel for loop.

So, I use the replace array subset to write into the same array.

Everything is done using a local variable, first reading it, then writing it.

The problem is when writing the updated array into the local variable, I might lose the parallel modification.

So, this approach always writes the whole array. If there was a parallel modification with the old array as input, changes at position n might be lost, when i is modified (although I never address n = i in parallel).

This would be avoided if just the position n is written or just i, when I manipulate those. Is there a way to just write the subset without rewriting the whole variable? Or another workaround?

0 Kudos
Message 1 of 9
(4,354 Views)

Local variables is no-no. It seems array is huge, each variable is a new copy of data. Also race conditions. Each iteration will work with its own copy of array data. The last one to execute will write its data.

 

I would first run parallel loop with index array to get elements to modify and process them. Make sure you do not have non-reentrant VIs there that will make parallelizing useless.

Then replace elements in a loop with array in a shift register. It is fast, does nto need to be parallel.

 

May be using data value reference will help... and it will not generate array copies in every parallel iteration.

 

 

0 Kudos
Message 2 of 9
(4,336 Views)
Solution
Accepted by woltre

>> May be using data value reference will help... and it will not generate array copies in every parallel iteration.

 

This one keeps only one copy of main array and replaces all requested (5) elements.

Edit: it does not help. Inplace element structure disables parallel operation. All other options I know of generate copies of data.

 

Result: no, labview does not work with data references very good and it seems your request is not possible (within labview only).

 

parallel replacement.png

0 Kudos
Message 3 of 9
(4,321 Views)

Just autoindex on both the input and output tunnels of the parallel FOR loop.  LabVIEW will take care of everything else for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 9
(4,303 Views)

Thanks a lot. Reference is a good idea. However, I cannot wait until the parallel loop has finished to write the new array as the parallel loop is collecting measurement data which runs for hours. On the other hand, I need to display the data in the meantime using a while loop which runs in parallel to all the data aquisition. There is nothing like a pointer to the subarray? Or is there an easy way to address variables by name during runtime, which is given by a string? Instead of using an array, I could generate N variables called VarI and then write automatically to Var1, Var2 etc. in the parallel for loop.

0 Kudos
Message 5 of 9
(4,294 Views)

@woltre wrote:

I am addressing the subarray (1 entry) of index i and n parallel using the array subset function because I want to update the entry at position i and n parallel, let's say in a parallel for loop.

 


So you are overwriting two seperate elements at the same time? What does the parallel FOR loop actually do for each iteration? Just replacing an array element does not need any parallelism, it is infinitely fast compared to anything else and the parallelization overhead would probably slow you down.

I really don't think that you need a parallel FOR loop. All you need are a few loops running in parallel to your while loop. 

Note that you can resize the IPE/ARRAY (as seen in alexanders code) to replace two (or more) elements at the same time. The DVR locks access to guarantee that only one part of the code can modify the data ant any given time.

 

What does anything have to do with "Array subset" function you mentioned? Makes no sense.

 

Please show us some simplified code so we don't need to wildely guess.

 

0 Kudos
Message 6 of 9
(4,278 Views)

Here's one way to operate on the same array from varous program locations using a DVR.

 

 

Download All
0 Kudos
Message 7 of 9
(4,267 Views)
Solution
Accepted by woltre

@woltre wrote:

Thanks a lot. Reference is a good idea. However, I cannot wait until the parallel loop has finished to write the new array as the parallel loop is collecting measurement data which runs for hours. On the other hand, I need to display the data in the meantime using a while loop which runs in parallel to all the data aquisition. There is nothing like a pointer to the subarray? Or is there an easy way to address variables by name during runtime, which is given by a string? Instead of using an array, I could generate N variables called VarI and then write automatically to Var1, Var2 etc. in the parallel for loop.


Ok, this is a completely different issue.  What you need to use is a Queue.  I recommend you read up on the Producer/Consumer architecture.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 9
(4,256 Views)

Thanks a lot. The queue did the job. Enquing in parallel, and dequeing and writing in array in series for loops, both processes running in parallel whle loops.

0 Kudos
Message 9 of 9
(4,220 Views)