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

ivf 11.1 created a program with 4 threads but only using one core, why?

rockycez
Beginner
381 Views
I am using ivf 11.1 to parallize my code with openmp. Before the work, I want to try the openmp function first and to investigate whether it works fine on my CPU Q6600. I am surprised to see that the program generate 4 threads indeed. However, when I am checking the usage of the CPU cores, I found only one core is using (25%) (tried few times). Then I turned to my colleague's computer with i7 720q. The program creates 8 threads and also uses one core (13%). I think maybe something setting is wrong. Here is the code:
[fortran]program openmp_test
use omp_lib
implicit none

real*8:: r_double
integer:: i

!$omp parallel do private(i)
do i=1,900000
write(40,*) 'Thread ID',omp_get_thread_num(),'calculated DO no.',i,' = ',dble(i)**3
end do
!$omp end parallel do
end[/fortran]
The program is compiler with the option /Qopenmp.

I want to know which option I have missed resulting the low usage of the multi-core resource.
0 Kudos
5 Replies
TimP
Honored Contributor III
381 Views
You don't leave significant opportunity for parallel work, considering that the write to a single output stream must be serialized implicitly.
0 Kudos
Steven_L_Intel1
Employee
381 Views
I tried it on my Core 2 Duo and saw two threads.
0 Kudos
rockycez
Beginner
381 Views
How about the usage of your CPU? 50%?
0 Kudos
rockycez
Beginner
381 Views
Do you mean that if I replace the I/O code with some function/subroutine doing 'real' work, the usage of CPU will increase?
0 Kudos
Steven_L_Intel1
Employee
381 Views
Yes, if you actually do computational work in the loop, you should see more cores active. As Tim says, all you have is a WRITE to a common unit, so that gets serialized. But if you look at the output, you'll see different thread numbers indicating that they are indeed running in separate threads.
0 Kudos
Reply