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

Multi-Threaded Fortran code only runs one 1 CPU

j_gaffney07
Beginner
334 Views
Hi All

Following the Intel seminar at Imperial college, I have decided to multi-thread a large Fortran code to run on my Core 2 Duo running Ubuntu 8.04 LTS. After a bit of messing about i now have a source that compiles and runs. I have parallelised over a do loop that calls a series of recursive subroutines:

!$OMP PARALLEL
!$OMP& DEFAULT(private)
!$OMP& FIRSTPRIVATE(ii)
!$OMP& COPYIN(...*module variables*...)
!$OMP& REDUCTION(+:num1,num2,num3)
!$OMP& REDUCTION(+:protot,frastg)
!$OMP& REDUCTION(+:res1,res2)
!
!$OMP DO
do i=0,(nkj(ipar)+1),1
!
ii(ipar)=i
!
call recursivesub(ii,ival,num1,num2,num3,protot,recursivesub,res1,res2,frastg,pvfn)
!
enddo
!$OMP END DO NOWAIT
!
!$OMP END PARALLEL


(note the rest of the code is written in F77 so i have to pass the subroutine to itself as a dummy). The reduction variables are the results of the whole group of recursive subroutines; the variables defined by the COPYIN are not modified by the threaded region, and the array ii does not need to know about the other threads. The problem i have is that if i compile this with

ifort blah -autodouble -fast -openmp

the compiler reports that it has parallelized the region and loop, but when i run it the process never goes above 50% of my processing power (i.e, only one core??). The final result is the same as the serial code. If i use OMP_GET_NUM_THREADS() it returns 2. Is this a bug with ifort and ubuntu or a problem with my code? It seems like a pretty simple modification.

Thanks for your help!

Jim
0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
334 Views

Hi Jim,

Let me first say that I am a Windoz programmer but I think I can give you some suggestions none-the-less.

1) Is nkj(ipar) == 0?
(i.e. is your do loop only 1 iteration)
2) In the do loop insert diagnostic code to display the omp thread (team member) number and value of i.
(i.e. assure each thread is performing ~1/2 the work)
3) Assuming multiple iterations and multiple threads are working, next see if the F77 code is calling runtime library functions that are OpenMP safe through serialization locks.

I do not know if the documentation list the serialized OpenMP safe functions/subroutines but a short list includes

READ, WRITE, RAND, DRAND

4) If both threads are running then check to see if they are being forced to run on the same core. (Check on options relating to thread affinity).

Jim Dempsey

0 Kudos
j_gaffney07
Beginner
334 Views
Hi

Thanks alot for your reply Jim. At first glance i dont think that i have any of the problems you suggested, but there is something funny going on...

Thanks again!
0 Kudos
jimdempseyatthecove
Honored Contributor III
334 Views

Don't trust your first glance. Insert diagnostic code to verify what you see is what you have. More often than not, diagnostic code exposes false assumptions.

Jim Dempsey

0 Kudos
Reply