openmp on Linux - cpu utilization

General OpenMP discussion

openmp on Linux - cpu utilization

Postby cgolas » Tue Sep 16, 2008 8:20 am

I'm running into an odd problem when I try to enable openmp on a for loop on a Linux machine. The simplified version looks something like this:

#pragma omp parallel for
for (i=0; i < max; i++) {
DoSomethingCpuIntensive();
}

When I compile and run this on Linux, it behaves as expected. As I add threads, more cores on my multi-core machine are used. If I use "top" to look at cpu utilization, I'm at 100%, until the program runs its course. I then add a sleep inside the for loop to slow down the processing. I do this to simulate a period task that requires a lot of cpu, but only at some specified interval. Now the code looks like this:

for (j=0, j<jmax; j++){

#pragma omp parallel for
for (i=0; i < max; i++) {
DoSomethingCpuIntensive();
}

// Wait a bit for the next time...
usleep(millisecs*1000);
}

If "DoSomethingCpuIntensive()" takes 20 msec to complete, and I then sleep for 20 msecs, I'd expect the cpu utilization to drop to about 50% since I'm only doing work about half the time. But, that is not the case. Cpu stays near 90%. If I run this same simple code on Windows, and look at the TaskManager - cpu does indeed track down as I would expect. Linux (Red hat enterprise 4) seems to be the odd man out.
I should mention that I am using versio 10.1.017 (and compile specifying -openmp on the command line) of the Intel compiler for these simple tests. Also note that If I run this single threaded, it behaves as expected; i.e. adding sleeps reduces overall cpu utilization.
Any insight to why this is happening?
cgolas
 
Posts: 1
Joined: Tue Sep 16, 2008 7:48 am

Re: openmp on Linux - cpu utilization

Postby ejd » Tue Sep 16, 2008 5:15 pm

Are the Linux and Windows machines using the same type of CPU? What is the refresh rate on top? I believe the default is on the order of tenths of a second - meaning that it might not be seeing the decrease in utilization.

I believe that the Intel implementation keeps the threads around after the parallel region so that it does not have to go through the process of getting them again for a new region. I would think that they would be "sleeping" while not in use, but it is possible that they are looking for more work. Maybe someone from Intel can address this.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 7 guests