ESCOMP / mizuRoute

Reach-based river routing model
http://escomp.github.io/mizuRoute/
GNU General Public License v3.0
42 stars 52 forks source link

NAG compiler complains when swap function is called on identical inputs #397

Closed ekluzek closed 1 year ago

ekluzek commented 1 year ago

The NAG compiler on izumi complains about the following in nr_utils.f90

 ! private subroutine
 SUBROUTINE swap(a,b)
 INTEGER(I4B), INTENT(INOUT) :: a,b
 INTEGER(I4B) :: dum
 dum=a
 a=b
 b=dum
 END SUBROUTINE swap

It complains about the change in a dummy argument changing another dummy argument at the same time.

There must be some way to override this protection or maybe there is an intrinsic that does this same thing?

Completion(send) Runtime Error: /fs/cgd/data0/erik/ctsm_worktree/mizuroute/components/mizuRoute/route/build/src/nr_utils.f90, line 163: Assignment to A affects dummy argument B Program terminated by fatal error /fs/cgd/data0

ekluzek commented 1 year ago

This is because of the -C=alias option for the nag compiler. In the makefile we have -C=all, which turns it and other compiler checking options on.

I tried adding the "volatile" attribute and that still aborted the same way.

ekluzek commented 1 year ago

OK, it turns out the problem isn't the swap function itself, it's if the swap function is called with arguments that are the same (i.e. a==b). In this case the swap would be OK, but it doesn't really need to be done. So the change needed is to NOT call swap when a==b.