PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

error about default logical variable value with pgi compiler

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
novelbean



Joined: 29 Jul 2012
Posts: 2

PostPosted: Sun Jul 29, 2012 11:30 pm    Post subject: error about default logical variable value with pgi compiler Reply with quote

i have encountered an error about logical variable value assigned by pgi compiler.

the following is my code for test:
module kinds
implicit none
integer,parameter :: &
log_kind=kind(.true.)
end module kinds

program testlog
use kinds
implicit none
logical(log_kind),allocatable :: doqp2(:)
integer i,j,k,m
m=5
allocate(doqp2(m))
call test_log(m,doqp2)
print*,doqp2(1:m)
print*,doqp2(1:10)
deallocate(doqp2)
end

subroutine test_log(m,doqp2)
use kinds
implicit none
logical(log_kind) :: doqp2(m)
integer i,j,k,m
do i=1,m
doqp2(i) = .true.
enddo
end subroutine test_log

after compling it , i used the pgi version 11.9 and i have try the 10.6 too, them give the result is :
T T T T T
T T T T T F F F F T
the last logical value is not F but T, but i compiled it with ifort , which give the another result as follows:
T T T T T
T T T T T T T T T F
the last five logical value in the second line show contrary result.

then i compiled it with other compiler , the result is as following:
with gfortran:
T T T T T
T T T T T T F F F F

with f95:
T T T T T
T T T T T T F F F F

it seems that gfortran and f95 can give the correct result, just because the system deem the those unassigned logical value is FALSE, but in the above result compiled with pgf90 are not all FALSE.


would you like give me some advices?

thanks.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6134
Location: The Portland Group Inc.

PostPosted: Mon Jul 30, 2012 9:19 am    Post subject: Reply with quote

Hi novelbean,

The upper bound of the array is 5, but you're printing out 10 elements. Hence, anything after the 5th element will contain junk values. To fix, you need to either increase the size of your array ( M >= 10) or not print beyond the end of the array.

Hope this helps,
Mat
Back to top
View user's profile
novelbean



Joined: 29 Jul 2012
Posts: 2

PostPosted: Mon Jul 30, 2012 11:20 pm    Post subject: Reply with quote

mkcolg wrote:
Hi novelbean,

The upper bound of the array is 5, but you're printing out 10 elements. Hence, anything after the 5th element will contain junk values. To fix, you need to either increase the size of your array ( M >= 10) or not print beyond the end of the array.

Hope this helps,
Mat


thank for your answer.
i have thought those logical variables value unassigned beforehand the fortran system would assign them FALSE value.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6134
Location: The Portland Group Inc.

PostPosted: Tue Jul 31, 2012 7:47 am    Post subject: Reply with quote

Hi novelbean,

You can never assume that memory is initialised and should always initialize the values yourself. There are cases where memory is initilzed to zero (like with a SAVE statement) but this is not standard and may vary by platform and compiler.

However, in this case you do initialize your array, it's just that you are also accessing memory beyond the end of the array. While here the only consequence is printing junk values, in other cases you can cause your program to crash with a segmentation violation (i.e. accessing protected memory) or get wrong answers.

Reading and writing uninitialised memory (aka a UMR) and out-of-bounds errors are two of the most frequent sources of program error.

Hope this helps,
Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group