Double allocation error in mesh3d.F90

Bug #1808503 reported by Yann Pouillon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Siesta
Status tracked in Trunk
4.0
Fix Committed
Low
Unassigned
4.1
Fix Committed
Low
Unassigned
Trunk
Fix Committed
Low
Alberto Garcia

Bug Description

In the trunk branch, for revnos > 740 (I didn't go earlier), if I compile SIESTA with GCC and the following FFLAGS for debugging:

    -g3 -ggdb -fPIC -fbacktrace -fcheck=bounds,do,mem,pointer,recursion -fimplicit-none -finit-real=snan -fno-automatic -fno-omit-frame-pointer -O0

I get a runtime error about the nodeboxes array in SiestaXC/mesh3d.F90:

    At line 2992 of file /home/pouillon/siesta/honpas/siesta-honpas/Src/SiestaXC/mesh3d.F90
    Fortran runtime error: Attempting to allocate already allocated variable 'nodeboxes'

GCC 5.4, 6.3 and 6.4 give me the same error, while other compilers with equivalent flags don't detect it. Without the -fcheck and -fno-automatic flags, the error disappears.

The attached patch fixes this minor issue.

Revision history for this message
Yann Pouillon (pouillon) wrote :
Revision history for this message
Nick Papior (nickpapior) wrote :

Having a 2nd look at the code, it may be even easier to delete the `nodesBoxes`, i.e. something like this:

=== modified file 'Src/SiestaXC/mesh3d.F90'
--- Src/SiestaXC/mesh3d.F90 2017-02-17 13:28:06 +0000
+++ Src/SiestaXC/mesh3d.F90 2018-12-14 10:29:28 +0000
@@ -2926,7 +2926,7 @@
   character(len=*),parameter:: errHead = myName//'ERROR: '
   integer, parameter:: maxFactors = 100 ! Max prime factors in nNodes
   type(distrType),pointer:: distr, newDistr, oldDistr
- integer,allocatable:: axisBox(:,:,:), nodeBoxes(:,:,:), partBox(:,:,:)
+ integer,allocatable:: axisBox(:,:,:), partBox(:,:,:)
   integer:: axis, axisNodes(3), blockSize, boxSize, &
             factor(maxFactors), groupSize, &
             i1, i2, i3, iAxis, iBox, iDistr, iFac, iID, iNode, iPow, &
@@ -2989,9 +2989,7 @@
 ! Handle box argument with priority
   if (present(box)) then
     ! Collect all node boxes and store them
- allocate( nodeBoxes(2,3,0:totNodes-1) )
- call gatherBoxes( box, nodeBoxes )
- distr%box = nodeBoxes
+ call gatherBoxes( box, distr%box )
     goto 999 ! Exit, since no other arguments must be considered in this case
   end if ! (present(box))

Revision history for this message
Yann Pouillon (pouillon) wrote :

Sure, that's also what I would have done. I only proposed a minimalistic patch because I didn't know about your intentions regarding the variable nor the possible side effects in LibGridXC.

Revision history for this message
Alberto Garcia (albertog) wrote :

In f95 and later, non-saved local (to a routine) allocatable arrays must be allocated on exit from the routine. This is why the use of '-fno-automatic' triggers the bug, but every other (modern) compilation fails to detect it.
Despite requiring de facto a f2003 compiler, I guess we should guard against these kind of standard-flavor-dependent issues by being more conservative. In this case, by explicit deallocation of the array.
I wonder if there are enough compiler flags to detect more complicated issues.

Changed in siesta:
importance: Undecided → Low
assignee: nobody → Alberto Garcia (albertog)
status: New → Triaged
Revision history for this message
Alberto Garcia (albertog) wrote :

Of course, I meant "must be DEallocated on exit..." in the above comment.

Changed in siesta:
status: Triaged → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.