03-18-2011 08:37 AM
So if you have a for loop with some value wired to P in the for loop, how do you determine which of the concurrent threads (i.e. a thread id) is running which loop? Is there a native labview way or do I have to go looking around the Windows API?
- Chris
03-18-2011 09:06 AM
Chris,
why is this for interest for you? Since you cannot influence this by any means, i find this a rather useless info even if there is any option (which i doubt).
Norbert
03-18-2011 09:15 AM
I want certain threads to use certain resources so those resources are divided evenly across the threads. Otherwise, they will arbitrarily compete for certain resources and the execution will bog down. This is trivial in an OpenMP Parallel For Loop in the for of
This is a trivial function in other parallel programming paradigms (i.e. Matlab or OpenMP).
03-18-2011 09:21 AM
Hi majoris,
so you have a FOR loop which does (by definition) the very same execution in each iteration - and you want to change that behaviour to do different things in each iteration???
You could use the loop count ("i") for your decision, but then you get a state machine instead...
03-18-2011 09:26 AM
LabVIEW has the advantage, that you do not need to care about this when programming for multiple threads. LV does create, schedule and manage threads for you without the need for personal effort.
Most people see this as an advantage from LV over other languages.
What are those "certain ressources"?
Norbert
03-18-2011 09:30 AM
Exactly,
Just because the for loop uses the same code for every iteration doesn't mean the code can't contain branches inside the executed code (imagine putting a case structure that did something different based on i). Instead, I want to branch off the thread id. To my knowledge, the iteration counter isn't the same as the current thread. But yes, logically what I want to do is
parfor i as 0 to n over p processors
curr_proc = get_thread_id
if curr_proc == 1
use this resource
if curr_proc == 2
use this resource
...
end parfor
03-18-2011 10:35 AM - edited 03-18-2011 10:37 AM
This is an excellent question and I have asked that in the past, e.g. at the original NI WEEK presentation. I have the same issues with a FORTRAN dll that needs to run in N instances but I have not figured out a way to keep the instances seperate except creating four copies of the dll, all with unique names. (CodeA.dll, CodeB.dll, etc.). If we had access to the parallel instance, I could use a single parallel FOR loop containing a case structure with cases 0...3 and a dll in each.
All is not lost, because we can create a small subVI that can generate the parallell instance number as an output when placed in a parallel FOR loop, but there are restrictions. I am busy at the moment, but I'll try to dig up my code later.
08-04-2011 09:41 AM
LabVIEW 2011 provides the information you requested.
08-04-2011 10:44 AM
It makes me sad we will not be upgrading to Labview 2011 immediately : \
Thanks though!
08-05-2011 04:18 PM
Hello majoris,
If I follow your problem correctly (enhanced by altenbach's post) I understand you have multiple resources available to you and you would like to utilize these within your for loop that is running in parallel instances.
Your problem occurs when you want to use a resources and it is difficult to determine which resource is available for use. If you use only a single resource then the parallel instances eventually become sequential as the resource can only be accessed at a single time (defeating the purpose of parallel instances).
If possible I would use error wires for flow control where possible and if that is not available then a flat sequence structure may be needed. Here is what I would implement:
Create an array with a number of boolean indicators as you have resources
Iterate through the array to find the first available resource index and mark it as in use (toogle boolean value)
Use this index to select an appropriate resource
(flow control needed here)
Access the resource then when complete
Mark the index as not in use (toggle boolean value again)
Anthony