Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28591 Discussions

Setting priority and number of processors for a command line application

gillesbourque
Beginner
1,332 Views
Hello,
Not a Fortran question, but somewhat related, in window environment, how to set the priority and the number of processors (4 available) for a command line application?
Any help appreciated.
Sorry that the question is no directly related but I don't know where else to ask.
Gilles
0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,332 Views
Well, the number of processors isn't something you set directly. Rather, you want to control the number of threads your program creates. If it is a single-threaded application, one processor is all you're going to get. If you have at least as many threads as processors, then some or all of them will get farmed out to the processors in parallel.

If you use OpenMP to thread, you can restrict the number of threads created with environment variables.

You can use the "start" command to run a program from the command line and set the priority with the /low, /normal or /high switches.
0 Kudos
jim_dempsey
Beginner
1,332 Views

You can set the affinity under program control.

Or after the program is running you can set the affinity manualy using the Task Manager

From the Task Manager Processes tab, click on the name tab to sort by name (to keep your process from popping up and down) then right click on the name of your program then choose Set Affinity
Or inside the program's execuitable header is are the processor affinity bit masks (one for hard affinity and the other for soft affinity).
...
You can permanently set processor affinity for a non-operating system executable, on both Windows 2000 and Windows NT 4.0, by using the Imagecfg.exe tool from the supportdebugi386 folder of a Windows NT 4.0 CD-ROM, or the Imagecfg.exe tool from the Windows 2000 Server Resource Kit Supplement One.
NOTE: Do NOT use imagecfg on any kernel operating system files.
To permanently set the processor affinity for your 32-bit executable, open a CMD prompt and type: imagecfg -a 0xn Pathyourprogram.exe where 0xn is the affinity mask.
The mask constrains your application to a specific CPU, from 0 - 31, where:
CPU MASK
0 0x1
1 0x2
2 0x4
3 0x8
4 0x10
5 0x20
6 0x40
7 0x80
8 0x100
etc
To set the affinity for "c:utilCountry Codes.exe" to processor 1, I typed:
imagecfg -a 0x2 "c:utilCountry Codes.exe"
and received the
c:utilCountry Codes.exe contains no configuration information
c:utilCountry Codes.exe contains a Subsystem Version of 4.0
c:utilCountry Codes.exe updated with the following configuration information:
Process Affinity Mask: 00000002
When I launch Country Codes.exe, its' affinity is set to CPU 1.
...
0 Kudos
Reply