LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Preallocated Reentrant VI within Parallelized For Loop

Solved!
Go to solution

Hello,

 

I searched around a bit and couldn't find anything related to this specific question.

 

If I have a subVI within a parallelized For loop and the subVI is set to preallocated clone reentrant execution, will the subVI act as multiple memory speces depending on the For loop iteration number? My specific application is a subVI containingvibration analyisis VIs that use previous data in their averaging and filters.

 

Thank you!

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 1 of 40
(7,067 Views)

Ok well I did some of my own testing and disproved my question. At the same time, I'm see some weird results with possible workaround to this memory space issue...

 

See snippet below. Can anyone explain this?

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 40
(7,035 Views)

Your snippet did not include the subVI. What's in it?

 

Your guess is wrong. You cannot predict in which order the clones execute. It is random.

 

Show the parallel instance terminal and autoindex its output at the right loop boundary to see in what order they actually execute, it might change from one run to the next..

Message 3 of 40
(7,012 Views)

The subVI is just a single feedback node that stores the output integer. Every time the subVI runs, it adds the input to this stored value.

 

I don't care which order the clones execute, I care that the memory space of each clone remains the same based on the index. i.e. Index 2 of the For loop always pulls from the same memory space each time the For loop is run.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 40
(6,961 Views)

James.Morris wrote:

I don't care which order the clones execute, I care that the memory space of each clone remains the same based on the index. i.e. Index 2 of the For loop always pulls from the same memory space each time the For loop is run.


What index? There is no fixed relation between the iteration terminal and the parallel instance. Can you explain in more details what your are trying to achieve? I am sure there is a better solution to the problem that does not have this requirement. 

 

(Maybe you can also play with the chunk size option, but I have not tried.)


@James.M wrote:

The subVI is just a single feedback node that stores the output integer. Every time the subVI runs, it adds the input to this stored value.


You should not expect us to rewrite subVIs based on a verbal descriptions. To get better feedback, please attach all subVIs.

If we first have to create subVIs based on vague descriptions, most will probably move to the next post instead. 😉

0 Kudos
Message 5 of 40
(6,948 Views)

I'm actually in a bit of a strange situation right now because my LabVIEW is in a state of complete reinstall, so I'm unable to recreate anything until tomorrow or later. Sorry for the inconvenience this causes in debugging ability.

 

What I'm trying to do is create a seperate memory space for different sets of data using the same subVI. My specific application is a subVI containing vibration analyisis VIs that use previous data in their averaging and filters.
e.g. 4 sets of data come in, I analyze them seperate from each other and spit out 4 values. Now 4 new sets of data come in and each set is from the same sensor as its counterpart in the first set of data. I need the new sets of data to use the same memory space as their predecessors, so that any averaging the analysis VIs do isn't messed up.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 40
(6,939 Views)

I recently tried to do a similar thing, but couldn't find a way to get the desired behavior "for free" simply by putting a prealloacted reentrant vi into a parallelized For loop.  I ended up using a workaround where VI Server opens and calls the separate reentrant instances.

 

I have several identical test stations which produce continuous data broken down into smaller packets.  I'm doing live "real time" processing on the data as well, and some of that processing has internal state to remember (integrators, hysteresis stuff, debounce, etc.).   I wanted to put the reentrant processing vi's inside a parallelized For loop and get my multiple distinct reentrant instances without extra coding.  No combination of auto-indexing, or indexing by iteration # or parallel instance # seemed to preserve correspondence between a given station array index and a specific reentrant instance of my processing vi.

 

What I settled for was a VI Server approach.  On first call, I open an array of VI Server references to the reentrant processing vi.  I do this at run-time when my processing thread "finds out" how many stations are represented in the array of data packets.  Then I use "Call By Reference" to perform the processing.   I then close all the references when I shut the thread down.  As soon as I did it this way, the 1:1 correspondence I needed started working just fine.

 

Unfortunately, I find myself needing to do the same kind of thing again in a process monitoring thread.  It's not a *really* big deal using VI Server but I'm nagged by the thought that I expect there should be a simpler way that I'm missing.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 7 of 40
(6,887 Views)

@Kevin_Price wrote:

 No combination of auto-indexing, or indexing by iteration # or parallel instance # seemed to preserve correspondence between a given station array index and a specific reentrant instance of my processing vi.


You can configure the parallel for loop to output the parallel instance. RIght-click the P terminal to change, the wire it to a case strcuture.

0 Kudos
Message 8 of 40
(6,871 Views)

@altenbach wrote:
You can configure the parallel for loop to output the parallel instance. RIght-click the P terminal to change, the wire it to a case strcuture.

 

This sounds like the solution to grabbing the respective memory spaces, but I'm having an issue. See attach VIs. My output for "Parallel Instances" is coming out as [0,0,0,0] every time. Shouldn't it output something like [1,3,2,0] or a mix there-of?

 

Edit: I ran it a little faster and it started outputing "1" sometimes, but still mostly just zeros. I'm assuming this means it only uses the other parallel instances when needed? Is there a way to force it to always use each parallel instance?

 

Thanks,

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 9 of 40
(6,862 Views)

@James.M wrote:
I ran it a little faster and it started outputing "1" sometimes, but still mostly just zeros. I'm assuming this means it only uses the other parallel instances when needed? Is there a way to force it to always use each parallel instance?

 


I added a 100ms delay to inside the loop and now each iteration is a different instance. I also added a boolean comparison to the preallocated subVI to output true if the input is ever different than the previous run. It is outputing false always. See attached VIs again.

Edit: I did it with a 1ms delay and it works as well.

 

Is this a solution? I don't really know because I wouldn't want to add a delay to every For loop...

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 10 of 40
(6,856 Views)