|Title||MP’s high CPU usage on Solaris|
|Author||Hua Peng, StataCorp|
When using Stata/MP under Solaris, users might notice increased CPU usage after executing a parallelized command. For example, on a two-processor SPARCv9 SunOS 5.9 system, using the Unix command top after
. sysuse auto . regress mpg price
will report that CPU usage is close to 50%; i.e., one of the two processors is 100% loaded even though Stata/MP is idle. On a four-processor system, a user might see 100% usage of three processors even when Stata/MP is not running anything.
Sun’s parallel library implementation intentionally behaves this way to improve performance on dedicated systems. According to Sun’s documentation:
“Currently, the starting thread of a program creates bound threads. Once created, these bound threads participate in executing the parallel part of a program (parallel loop, parallel region, etc.) and keep spin-waiting while the sequential part of the program ru"ns. These bound threads never sleep or stop until the program terminates. Having these threads spin-wait generally gives the best performance when a parallelized program runs on a dedicated system. However, threads that are spin-waiting use system resources.”
Hence, users will notice increased CPU usage for Stata/MP as soon as the program executes a parallelized task. The number of processors that will be 100% used is the number of threads minus 1.
This behavior can be controlled by an environment variable, SUNW_MP_THR_IDLE. Possible values include
spin | sleep[ns | nms]
The default value is spin, which gives the best performance on dedicated systems but uses system resources and may not be appropriate if the system is shared by multiple users and programs.
The other choice, sleep[ns | nms], puts the thread to sleep after spin-waiting n units. The wait unit can be seconds (s, the default unit) or milliseconds (ms), where 1s means one second, and 10ms means 10 milliseconds. sleep with no arguments puts the thread to sleep immediately after completing a parallel task.
Changing the value to sleep by using either
[user@host]$ export SUNW_MP_THR_IDLE=sleep
in sh/bash or
[user@host]$ setenv SUNW_MP_THR_IDLE sleep
in csh/tcsh will fix this problem.