Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Restricting Number of Cores

allo6
Beginner
1,308 Views
Is there any way that i can turn off any number of cores e.g. i want to use 10 cores out of available 32 cores in multicore machine. Is it possible?

Also is it possible for example JVM to use 2 cores on Quad core machine ?

Thanks.
0 Kudos
13 Replies
fraggy
Beginner
1,308 Views
Quoting - allo6
Is there any way that i can turn off any number of cores e.g. i want to use 10 cores out of available 32 cores in multicore machine. Is it possible?
Also is it possible for example JVM to use 2 cores on Quad core machine ?

1 - just use 10 threads, and you will use only 10 cores of your multicore machine (through a thread pool I mean)
2 - don't know :)

Vincent
0 Kudos
allo6
Beginner
1,308 Views
Quoting - fraggy

1 - just use 10 threads, and you will use only 10 cores of your multicore machine (through a thread pool I mean)
2 - don't know :)

Vincent

OK, Thanks. But i want other idle core to shut down/power off, Any idea ???
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,308 Views
Quoting - allo6
Is there any way that i can turn off any number of cores e.g. i want to use 10 cores out of available 32 cores in multicore machine. Is it possible?

Also is it possible for example JVM to use 2 cores on Quad core machine ?

Thanks.


What are you useing for a threading tool?
What operating system?

If OpenMP, you can seta restriction using environment variable

SET OMP_NUM_THREADS=10

Or at compile tile

export
OMP_NUM_THREADS=10

Or at run time

OMP_SET_NUM_THREADS()

Also, on Windows and Linux you can restrict the number of cores available to a process (applicaiton).
(you will have to look that one up)

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,308 Views
Quoting - allo6

OK, Thanks. But i want other idle core to shut down/power off, Any idea ???

When thread idel it suspends.
0 Kudos
allo6
Beginner
1,308 Views


What are you useing for a threading tool?
What operating system?

If OpenMP, you can seta restriction using environment variable

SET OMP_NUM_THREADS=10

Or at compile tile

export
OMP_NUM_THREADS=10

Or at run time

OMP_SET_NUM_THREADS()

Also, on Windows and Linux you can restrict the number of cores available to a process (applicaiton).
(you will have to look that one up)

Jim Dempsey


I want to do it for Operating system (Solaris/Linux/Windows etc) , to swtich off extra cores, so that my application typically sees less cores(Logical processors) to run its threads
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,308 Views
Quoting - allo6

I want to do it for Operating system (Solaris/Linux/Windows etc) , to swtich off extra cores, so that my application typically sees less cores(Logical processors) to run its threads

The OMP_NUM_THREADS environment variable does this for OpenMP threaded programs. Other threading tools may use a different technique (i.e. read the documentation).

Most operating systems have the concept of Environment Variables (Windows/Solaris/Linux do). A process inherits the environment variables from which it is run. Typically a system has system wide environment variables and the user runs applications (processes) within a command shell (CMD on Windows) and this command shell starts with the environment variables of the environment in which it was spawned from, and subsequent to start, the command shell (copies of)environment variables can be added to, deleted, or changed.

On Windows, you can (stepse vary depending of version of Windows)perform:

Start | Control Pannel | System | Advanced | Environment Variables | User Variables | New

And in there add OMP_NUM_THREADS as variable name and 10 as value.

*** Then rember you did this *** when you next project doesn't use all 16 cores.

Alternately, you can create aBatch file (command script) toissue:

SET OMP_NUM_THREADS=10
YourProgramName.exe

Then create a shortcut to the batch file and launch your application that way. Now the limitation only applies to the application launched by way of the shortcut.

Linux has similar techniques.

Jim Dempsey
0 Kudos
allo6
Beginner
1,308 Views

The OMP_NUM_THREADS environment variable does this for OpenMP threaded programs. Other threading tools may use a different technique (i.e. read the documentation).

Most operating systems have the concept of Environment Variables (Windows/Solaris/Linux do). A process inherits the environment variables from which it is run. Typically a system has system wide environment variables and the user runs applications (processes) within a command shell (CMD on Windows) and this command shell starts with the environment variables of the environment in which it was spawned from, and subsequent to start, the command shell (copies of)environment variables can be added to, deleted, or changed.

On Windows, you can (stepse vary depending of version of Windows)perform:

Start | Control Pannel | System | Advanced | Environment Variables | User Variables | New

And in there add OMP_NUM_THREADS as variable name and 10 as value.

*** Then rember you did this *** when you next project doesn't use all 16 cores.

Alternately, you can create aBatch file (command script) toissue:

SET OMP_NUM_THREADS=10
YourProgramName.exe

Then create a shortcut to the batch file and launch your application that way. Now the limitation only applies to the application launched by way of the shortcut.

Linux has similar techniques.

Jim Dempsey

Thanks
But i want to use Java (JVM) not OpenMP to use less cores. Any idea please?

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,308 Views
Quoting - allo6

Thanks
But i want to use Java (JVM) not OpenMP to use less cores. Any idea please?


OpenMP is not an application. It is a threading model tool used to build applications.

IF (capitals to stress) your JVM is multi-threaded AND IF the multi-threaded code were compiled using OpenMP as threading tool THEN setting the OMP_NUM_THREADS=10 will fix the problem.

IF your JVM is NOT multi-threaded AND if you run a collection of JVMs AND if you want these collections of JVMs to run ONLY with a sub-set of cores THEN look at using process affinity to restrict each JVM to a subset of 10 cores on your system.

On Windows, run the TaskManager | Processes | Click on title tab "Image Name" to sort alphabetically | Right-click on 1st JVM and set the affinity mask to the cores you want. Repete for all JVMs.

OR

On Windows, in the header of the applicaiton, there exists two bit masks. These contain affinity masks (one is preferred the other is required). Some time spent with Google will get you the information you need to set this mask.

On Linux, from a command line, you can issue (our use option) that in effect says "for all processes spawned from this shell, restrict it to this xxxx affinity mask"

Windows may have a similar thing (google is your friend).

The problem you are having in getting the information you want, is you are not specifying your circumstances to the extent necessary to inform the viewers of this forum with the information they need to provide you with the answer you want.

Jim Dempsey
0 Kudos
Dmitry_Vyukov
Valued Contributor I
1,308 Views
Quoting - allo6
But i want to use Java (JVM) not OpenMP to use less cores. Any idea please?


I believe your JVM must have such command line parameter. Investigate the list of JVM's command line parameters.
0 Kudos
allo6
Beginner
1,308 Views

OpenMP is not an application. It is a threading model tool used to build applications.

IF (capitals to stress) your JVM is multi-threaded AND IF the multi-threaded code were compiled using OpenMP as threading tool THEN setting the OMP_NUM_THREADS=10 will fix the problem.

IF your JVM is NOT multi-threaded AND if you run a collection of JVMs AND if you want these collections of JVMs to run ONLY with a sub-set of cores THEN look at using process affinity to restrict each JVM to a subset of 10 cores on your system.

On Windows, run the TaskManager | Processes | Click on title tab "Image Name" to sort alphabetically | Right-click on 1st JVM and set the affinity mask to the cores you want. Repete for all JVMs.

OR

On Windows, in the header of the applicaiton, there exists two bit masks. These contain affinity masks (one is preferred the other is required). Some time spent with Google will get you the information you need to set this mask.

On Linux, from a command line, you can issue (our use option) that in effect says "for all processes spawned from this shell, restrict it to this xxxx affinity mask"

Windows may have a similar thing (google is your friend).

The problem you are having in getting the information you want, is you are not specifying your circumstances to the extent necessary to inform the viewers of this forum with the information they need to provide you with the answer you want.

Jim Dempsey

Thanks dear, i got the answer in your last reply, Mow hopefully will be able to restrict core for JVM, Thanks
0 Kudos
mmissana
Beginner
1,308 Views
Quoting - allo6
Is there any way that i can turn off any number of cores e.g. i want to use 10 cores out of available 32 cores in multicore machine. Is it possible?

Also is it possible for example JVM to use 2 cores on Quad core machine ?

Thanks.
If you are trying to restrict the number of processors recognized by the operating system, and are using Windows, you could try the /numprocs=number switch in the boot.ini. This switch will limit the number of processors used by Windows. It is useful for performance testing, and troubleshooting hardware issues related to defective CPUs.
0 Kudos
Marcin_Prochownik
1,308 Views
In WinAPI you may play with SetProcessAffinityMask. Using this function you may set processors (cores) on which threads of process may run.

M
0 Kudos
gaston-hillar
Valued Contributor I
1,308 Views

I've recently uploaded a video showing how to change the number of cores using Windows Vista affinity settings. You can do the same for JVM and you will restrict the number of cores. However, you have to take into account L2 and L3 cache issues.

This is the link to my video http://www.youtube.com/watch?v=-Jfg3IHBNS0

It includes a book promotion. However, you can stop it before the promotion :)

Cheers,

Gastn Hillar
0 Kudos
Reply