Download PGI User's Guide

Transcript
Example: Large Array and Small Memory Model in Fortran
enddo
enddo
!$omp end parallel
print *, “M =”,M,”,
N =”,N
print *, “c(M,N) = “,
c(m,n)
end
When compiled with the PGF95 compiler using –mcmodel=medium:
% pgf95 –mp –o mat mat.f –i8 –mcmodel=medium
% setenv OMP_NUM_THREADS 2
% mat
M = 16000 , N = 16000
c(M,N) = 480032000.0000000
Example: Large Array and Small Memory Model in Fortran
The next example uses large arrays, but not statically declared. It is broken into a main and subroutine
so you can put the subroutine into a shared library. Dynamic allocation of large arrays saves space in the
size of executable, saves time initializing data, and the routines can also be compiled with 32-bit
compilers, by just decreasing the parameter size below. This example works on Win64 as well.
% cat mat_allo.f program mat_allo
integer i, j integer size, m, n parameter (size=16000)
parameter (m=size,n=size) double precision,allocatable::a(:,:),b(:,:),c(:,:)
allocate(a(m,n),b(m,n), c(m,n)) do i = 100, m, 1
do j = 100, n, 1 a(i,j) = 10000.0D0 * dble(i) + dble(j)
b(i,j) = 20000.0D0 * dble(i) + dble(j)
enddo enddo call mat_add(a,b,c,m,n) print *, “M =”,m,”,
N =”,n
print *, “c(M,N) = “, c(m,n)
end subroutine mat_add(a,b,c,m,n) integer m, n,
i, j double precision a(m,n),b(m,n),c(m,n)
!$omp do
do i = 1, m
do j = 1, n
c(i,j) = a(i,j) + b(i,j)
enddo
enddo return end% pgf95 –o mat_allo
mat_allo.f –i8 –Mlarge_arrays
-mp -fast
237