Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

OpenMP program

venturis
Beginner
575 Views
Dear Doctor,

I have an simple F90 code with the parallel derectives in :

program smp
use dflib
implicit none
integer, parameter
:: sz =100000
real(8), dimension(sz) :: X,W
integer :: i, iflag =1, n =1
real(8) :: res, runtime, begtime, endtime,timef
real(8), parameter :: mlt = 1.0D+02
interface
subroutine Serial(X,W,sz)
integer,intent(in) :: sz
integer :: i,j
real(8),intent( in),dimension(sz) :: X
real(8),intent(out),dimension(sz) :: W
end subroutine Serial
end interface
do i = 1, sz
res = ran(iflag); X(i)= mlt*res*n; n=-n
enddo
write(*,*)" Program started...... "C
begtime = timef()
!$OMP PARALLEL
call Serial(X,W,sz)
!$OMP END PARALLEL
endtime = timef(); runtime=endtime-begtime
write(*,'(A20,F9.4)')" Execution time is :"C,runtime
write(*,*)" Program terminated..."C
end program smp
!
subroutine Serial(X,W,sz)
integer,intent(in) :: sz
integer :: i,j
real(8),intent( in),dimension(sz) :: X
real(8),intent(out),dimension(sz) :: W
!$OMP DO
do i=1,sz
W(i)=0.D0
do j=1,sz
&nbs p; W(i)=W(i)+DABS(x(i)+x(j))
enddo
enddo

!$OMP END DO
end subroutine Serial

This program was compiled and linked successfully in IVF8.1.
However, during execution
the error message "Stack overflow" is occur WHEN sz = 100000. Fortunately, for sz = 10000 all is OK. What's happened???
THANKS.

Core Duo WinXP DELL Inspiron E1505, 2GB of RAM Notebook.

Max.

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
575 Views

It looks like in the program smp the arrays X and W are being created on the stack (most likely due to compiler option switches). You can:

a) Increase the stack (over 2x8x100000) using linker option
b) force X and W to be static arrays by adding SAVEattribute
real, save, dimension(sz) :: X, W
c) Make X and W allocatable and then allocate the memory

Also, in your subroutine Serial, on the !$OMP DO, add PRIVATE(J). The control variable I is private by default, the other variables are shared by default.

Jim Dempsey

0 Kudos
venturis
Beginner
575 Views
THANK YOU SO MUCH, JIM! ALL IS OK NOW, THANKS AGAIN.

Max.

0 Kudos
Reply