I am doing research on computational electromagnetics laboratory with supercomputers. Here, we are working with clusters to solve problems includes over 500M unknowns. At this point we have a problem with parallelizing all these calculations. Until now, we have been working with MPI to communicate among nodes, however, we are about to decide using OpenMP to enable communication between processors in a node in terms of benefits of OpenMP. Notwithstanding, we could not get any efficiency from openMP(probably because of the false coding). Actually the point is I don't know what is the wrong with the code I will give.
It tooks the same time with sequential pure code without any OpenMP directives. When I use 'top' command 8 processors was working with %100 performance during the paralllel section.
gfortran --version | head -1 GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
PROGRAM dotproduct
USE omp_lib
IMPLICIT none
INTEGER ::h,m,i,TID,NTHREADS,j,ierr
REAL :: start,end
REAL, ALLOCATABLE, DIMENSION(:,:) :: a
REAL, ALLOCATABLE, DIMENSION(:) :: x
REAL, ALLOCATABLE, DIMENSION(:) :: b
m= 20000
OPEN(UNIT=1,FILE='matrix20000.dat',STATUS='UNKNOWN')
OPEN(UNIT=2,FILE='vector20000.dat',STATUS='UNKNOWN')
ALLOCATE(a(m,m))
ALLOCATE(x(m))
ALLOCATE(b(m))
REWIND(1)
REWIND(2)
WRITE(*,*) ' Reading is just started'
READ(1,*), a(:,:)
READ(2,*), x(:)
WRITE(*,*) ' Reading is over'
WRITE(*,*) ' Calculating will be started after parallelization'
!$OMP PARALLEL PRIVATE(i,TID,j),SHARED(NTHREADS,m,a,x,b)
TID= omp_get_thread_num()
IF(TID == 0) THEN
NTHREADS = OMP_GET_NUM_THREADS()
PRINT*, 'Starting matrix multiple example with', NTHREADS
END IF
CALL cpu_time(start)
!$OMP DO
DO i=1, m
b(i)= 0
DO j=1, m
b(i) = b(i)+ a(i,j)*x(j)
END DO
END DO
!$OMP END DO
!$OMP END PARALLEL
CALL cpu_time(end)
WRITE(*,*) end-start,' seconds'
!DO i=1,m
! WRITE(*,*) b(i)
!END DO
DEALLOCATE(a) !----Deallocation
DEALLOCATE(x)
DEALLOCATE(b)
END PROGRAM dotproduct