maxloc oddity: bug or feature?

All,

I recently encountered what I thought was a bug in Intel’s compiler but it turned out to be a…feature? That is, absent a flag, the behavior I wanted wasn’t reproduced.

However, when I tried the same code with PGI, I also got some odd behavior. To wit, the code:

program test

   implicit none

   integer, parameter :: nvars = 12
   character(len=*), parameter :: vars(nvars)=(/ &
                    ' dw', ' ps', ' pw', ' rw',  &
                    '  q', 'spd', '  t', ' uv',  &
                    'sst', 'gps', 'lag', 'tcp' /)
   integer :: ivars(nvars)
   logical :: lvars(nvars)
   integer :: i
   character(len=3) :: var
   integer :: is(1)

   integer :: iis

   is = 0
   iis = 0

   do i=1,nvars
      ivars(i) = i
   end do

   var = 'X'

   write (*,*) 'var: ', var
   write (*,*) 'vars: ', vars
   write (*,*) 'ivars: ', ivars
   write (*,*) 'vars==var: ', vars==var

   is = maxloc(ivars,vars==var)
   write (*,*) 'is: ', is

   lvars = vars==var
   write (*,*) 'lvars: ', lvars

   iis = maxloc(ivars,dim=1,mask=lvars)
   write (*,*) 'iis: ', iis

end program test

And when run:

(1040) $ pgfortran --version  

pgfortran 16.3-0 64-bit target on x86-64 Linux -tp haswell 
The Portland Group - PGI Compilers and Tools
Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
(1041) $ pgfortran test.F90 && ./a.out 
 var: X  
 vars:  dw ps pw rw  qspd  t uvsstgpslagtcp
 ivars:             1            2            3            4            5 
            6            7            8            9           10           11 
           12
 vars==var:   F  F  F  F  F  F  F  F  F  F  F  F
 is:             0
 lvars:   F  F  F  F  F  F  F  F  F  F  F  F
 iis:        -12800

I believe both is and iis should be zero to the standard (case (ii) of MAXLOC). My question now is: does PGI have a similar option to Intel’s that causes both is and iis to be zero? Or is this a bug?

Matt

Matt,

This has been replicated and logged as TPR 22472.

dave

Matt,

More information.
The standard says:

  1. maxloc(ivars,dim=1,mask=lvars) is the same as maxloc(ivars,mask=lvars)
    since the rank of ivars is 1
  2. the result of maxloc is 0 since all of the elements of lvar are false

So, we have a bug with maxloc(ivars,dim=1,mask=lvars); our result for
maxloc(ivars,mask=lvars) is correct.

We noticed the intel compilers were returning one instead of zero,
but we may not have the most current version.

dave

Dave,

Intel replied on the thread I linked to. That is a “feature”:

You want “-assume noold_maxminloc” or “-standard-semantics”.

I guess the faster max/minloc isn’t standard-conforming. So…yay?

TPR 22472 - pgfortran - problems with maxloc
has been fixed in the current 16.5 release.

Thanks again for the report.

dave