Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

variables in blocks in subroutines are nonlocal?

$
0
0

Hi,

The program below exits with "error" on my machine. It looks as if the variable r in the block is shared by the openmp loop, but it surely shouldn't be?

Thank you,

UM

 

program mfort
	implicit none

	integer	:: i
	real	:: x(1000)=[(i,i=1,1000)], y(1000)


!$omp parallel do
	do i=1,1000
		call sub(x(i),y(i))
	enddo

	contains

	subroutine sub(x,y)
		real	:: x,y,z
		integer	:: i

		block
			real	:: r
			r=x
			z=0
			do i=1,1000
				z=z+cos(real(i))			! waste some time
			enddo
			if(r .ne. x) then
				print *,"error"
				stop
			endif
			y=r+z
		end block
	end subroutine

end program

 

AttachmentSize
Downloadapplication/octet-streamtest3.f90466 bytes

Viewing all articles
Browse latest Browse all 5691

Trending Articles