Basic Parallel Programming with OpenMP: A guide to cutting your scientific calculations in smaller pieces. by Thomas la Cour Jansen

Basic Parallel Programming with OpenMP: A guide to cutting your scientific calculations in smaller pieces. by Thomas la Cour Jansen

Author:Thomas la Cour Jansen [Jansen, Thomas la Cour]
Language: eng
Format: azw3
Tags: Computers & Technology
Publisher: TLC Publishing
Published: 2017-08-25T04:00:00+00:00


program multi

use omp_lib

C Initialize

integer, parameter :: ndim = 8000

real*8 :: ma,mb,mc,aa

common/junk/ ma(ndim,ndim), mb(ndim,ndim), mc(ndim,ndim)

integer, parameter :: fd = 11

integer :: i,j,k,l, myid,t1,t2,count_rate,count_max

integer :: chunk

open(fd,file='TimeInfo',form='formatted')

!$omp parallel

myid = OMP_GET_THREAD_NUM()

if (myid .eq. 0) then

write(fd,"('Number of CPUs is ',i4)") OMP_GET_NUM_THREADS()

endif

!$omp end parallel

chunk=10

C Initialize timing

call system_clock(count_max=count_max, count_rate=count_rate)

call system_clock(t1)

C Loops for constructing matrices

!$omp parallel do shared(ma,mb,mc,chunk) private(i,j)

do i=1,ndim

do j=1,ndim

ma(i,j)=0

mb(i,j)=0

mc(i,j)=0

if (i .ne. j) then

ma(i,j)=1.0/(i-j)

mb(i,j)=1.0/(i-j)**3

end if

enddo

enddo

!$omp end parallel do

C Loop for doing matrix multiplication

!$omp parallel do shared(ma,mb,mc,chunk) private(i,j,k)

do i=1,ndim

do k=1,ndim

aa=ma(i,k)

do j=1,ndim

mc(i,j)=mc(i,j)+aa*mb(k,j)

enddo

enddo

enddo

!$omp end parallel do

C Find wall time usage

call system_clock(t2)

dt = t2-t1

secs = real(dt)/real(count_rate)

write(fd,"('For n=',i6,', time is ',f12.2,' seconds')") ndim,

C secs

close(fd)

end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.