06-18-2007 04:09 PM
06-19-2007 05:28 PM
OK. I did some more research. Now I can programmatically set the Process Affinity in LabView (found an articale in the knowledge base, thank you). I used the Call Library Function Node (with GetCurrentProcess()) to get the handle of the current LabVIEW process; passed this handle into a CIN and locked it to a CPU using SetProcessAffinityMask() API function. But this locks the whole LabVIEW process to that CPU. Still trying to find a way to lock a single thread (while loop) to one CPU. Tried to use Call Library Function (with GetCurrentThread()) , passed the handle to a CIN and tried to lock it to a CPU using SetThreadAffinityMask(). It did not work.
GKB
06-19-2007 05:58 PM
06-07-2010 12:36 PM - edited 06-07-2010 12:37 PM
Hi Gopal,
Do you still have the code that locks LabVIEW process to one CPU by calling GetCurrentProcess()) and SetProcessAffinityMask()? If yes, can you e-mail me the code? Thanks!
Sergey < sliberman@solidusintegration.com >
06-07-2010 01:53 PM
Gopal,
Never mind. I figured out how to do it.
Regards,
Sergey
07-09-2010 04:25 PM
@sliber wrote:
Gopal,
Never mind. I figured out how to do it.
Regards,
Sergey
Sergey-
How about posting your solution with a brief discussion? It might help several others in the future and really that kind of stuff is what the forums are about.
07-12-2010 08:31 AM - edited 07-12-2010 08:34 AM
Jeff,
Sure thing. Attached is a snippet from my code (Affinity0.png). The rationale for this was that some old RS232 drivers are unstable on multicore/multiCPU computers; confining your program to run on one core only ensures their stability. A call to this function can be made in any place in your program.
A different solution to the same problem is to use a free program called runfirst.exe (you can find it here: http://www.activeplus.com/Products/RunFirst). Most likely it uses the same call to the Windows kernel. The difference is that you can use that call to start your program on a single core from the very beginning. A snippet for that call is also attached (RunFirst.png). You'll need to place runfirst.exe into the same folder as the VI that invokes it.
Regards,
Sergey
07-22-2010 05:23 AM
It's possible to modify the snippet above using GetCurrentThread() and SetThreadAffinityMask() .
But there is one thing to keep in mind: According to MSDN GetCurrentThread() returns a pseudohandle that can't be used by other threads:
http://msdn.microsoft.com/en-us/library/ms683182%28VS.85%29.aspx
IMHO you can't just pass it to a CIN, perhaps it would work using DuplicateHandle() . But if you call GetCurrentThread() immediately followed by SetThreadAffinityMask() from within the same while loop it works.
07-22-2010 08:41 AM
See Andrey's post (number 14 in this thread).
This is a preview of the FP of the code he posted.
Problem solved?
Ben