- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried to use OpenMP to parallelize an inner loop. The code is as the following
******************************************************************************************
program test
implicit none
implicit none
REAL(8)::time1,time2
real(8),allocatable,dimension(:)::b
integer:: k,j,i
real(8),allocatable,dimension(:)::b
integer:: k,j,i
j=70000
allocate(b(j))
b=0.0D+00
allocate(b(j))
b=0.0D+00
call cpu_time(time1)
do k=1,40000
do i=1,j
b(i)=real(i,kind=8)
enddo
enddo
call cpu_time(time2)
write(*,*)'The cpu time (s) by the sequential code is',time2-time1
do k=1,40000
do i=1,j
b(i)=real(i,kind=8)
enddo
enddo
call cpu_time(time2)
write(*,*)'The cpu time (s) by the sequential code is',time2-time1
call cpu_time(time1)
do k=1,40000
!$OMP PARALLEL DO private(i)
do i=1,j
b(i)=real(i,kind=8)
enddo
!$OMP END PARALLEL DO
enddo
call cpu_time(time2)
write(*,*)'The cpu time (s) by the parallel code is',time2-time1
end program test
do k=1,40000
!$OMP PARALLEL DO private(i)
do i=1,j
b(i)=real(i,kind=8)
enddo
!$OMP END PARALLEL DO
enddo
call cpu_time(time2)
write(*,*)'The cpu time (s) by the parallel code is',time2-time1
end program test
******************************************************************************************
The file name of the code is 'test.f90'. I built from the command line:
ifort /Qopenmp test.f90
The results are:
The cpu time (s) by the sequential code is 1.98437500000000
The cpu time (s) cost by the parallel code is 3.85937500000000
The parallel code is much slower than the sequential code. Why?
I will greatly appreciate your contribution in this problem.
Thanks a lot.
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page