LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Waiting for timeouts in parallel for loop

Solved!
Go to solution

Hello,

I'm currently working on a project where I communicate with a set number of devices over TCP. This happens in parallel, which is no problem as long as the number of devices doesn't change. I now want to open up my project to support cases with different numbers of hardware devices, which I would like to do in a for loop (i.e. read device information from DB into an array and iterate over all the elements).

I have read up on parallel execution of a single for loop, but it seems like logical cores is a limiting factor for number of parallel processes. Unfortunately I also have to consider substantial delays in the communication which results in significant wait times for each loop iteration.

As you can see I this creates a lot of idle time which quickly adds up (running with 10 devices on 4 logical cores takes three times the delay to complete whereas without the loop it would only take the delay time as all connections are waiting at the same time.

 

Hopefully someone can point me towards a solution.

Thanks

0 Kudos
Message 1 of 6
(2,531 Views)

As long as you are using TCP, timeouts shouldn't be a real issue since a timeout is related to a specific connection.

 

Create a reentrant VI to handle a connection to one device, then launch as many copies of it as you need to handle the numbr of devices you have.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 6
(2,525 Views)

I would use the Asynchronous Call By Reference.  What you do is you run a FOR loop to iterate over all of your instruments, calling the ACBR to run a copy of your intrumentation VI.  This copy will just be out there in the ether, but you will have a reference to the call.  Then in another for loop, you can use the Wait For Completion node to wait for each asynchronous call to stop.


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 3 of 6
(2,522 Views)

Hello Mike,

this is exactly what I'm doing at the moment (without a loop). However, this means I have 10 calls of the same VI with no way of quickly adapting to a different(arbitrarily high) number of devices.

 

Crossrulz solution sounds like what I'm looking for. I will try this and report back.

Thanks to both of you.

0 Kudos
Message 4 of 6
(2,517 Views)

Hello again.

I had a look at calling my VI by reference and it seems to do what I was looking for. However, using this I have trouble matching the output of my VI to the input it is called with.

I created a small example demonstrating my issue. I would expect the Array to contain the values 0, 1, 2...6, 0, 1, 2, ... and so on, but the order seems to be completely random.

Download All
0 Kudos
Message 5 of 6
(2,504 Views)
Solution

Move the Open VI Reference into the first FOR loop.

 

You are using the same reference for all of the instances.  So the Wait For Asynchronous Call will just see that one of them completed and pass out the results.  By placing the Open VI Reference inside of your FOR loop, you will have a different reference for each call of your VI.


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 6 of 6
(2,484 Views)