0

When I run a Fortran code, I get this warning:

Fortran runtime warning: An array temporary was created for argument '_formal_11' of procedure 'zgemm'

related to this part of the code

                   do iw=w0,w1
                   !
                    do a=1,nmodes
                            Vw(a,:)=V(a,:)*w(iw,:)
                    end do
                    
                    call zgemm('N', 'C',&
                                nmodes, nmodes, nbnd*nbnd, &
                                (1.d0,0.0d0),&
                                Vw, nmodes, &
                                V, nmodes, &
                                (0.d0,0.0d0), VwV(iw,:,:), nmodes)
                                
                   end do             
                   !                    

If I have understood well, the warning is related to passing non-continguous arrays which could affect the preformances. I would like to take care of this. However it is not clear to me what exactly is the problem here, and what I could do to solve it.

Gippo
  • 65
  • 5
  • 4
    `VwV(iw,:,:)` is not contiguous. Do you want to pass something contiguous instead, or are you after something else? – francescalus Jun 20 '21 at 14:49
  • Thus if I write the result as `VwV(:,:,iw)` everything is fine? – Gippo Jun 20 '21 at 14:50
  • 4
    That's contiguous, but something completely different. To help us see what your problem is please see [mre] and describe what you are trying to do. – francescalus Jun 20 '21 at 14:52
  • 3
    Sometimes you can redesign your code to use diifferent indexing, sometimes it is impractical. Sometimes it is a hard decision where one must measure the impact at various parts of the codebase. It is impossible to say whether the array temporary actually hurts your performance in a measurable way or not. You should do some profiling first. Remember the Amdahl's law. Is that code part really important for the overall performance? We cannot see anything definitive from seeing a few lines of code. – Vladimir F Героям слава Jun 20 '21 at 15:41

1 Answers1

0

What is going on, is that you activated compiling flags that will warn you of temporary array creation at runtime. Before getting to more explanation, we have to take a better look at what an array is. An array is an area in memory, together with the information needed to interpret it correctly. Those information include but are not limited to the data type of the elements, number of dimensions, The start-index and end-index of each dimension, and most importantly, the gap between two successive element. In very simplistic terms, Fortran 77 and below do not have a built-in mechanism to pass in the gap between successive elements. So when there is no explicit interface of the called subroutine, the compiler ensures that there is no gap between successive element by copying data to a temporary contiguous array. This is a safe mechanism to ensure the predictability of the behavior of the subroutine.

When using modules, Fortran 90 and above use a descriptor to pass those information to the called subroutine; that works hand-in-hand with assumed-shape declaration of arrays. This is also a simplistic description.

In summary, that is a warning that will be of importance only if the performance is affected as Vladimir said.

francescalus
  • 30,576
  • 16
  • 61
  • 96
innoSPG
  • 4,588
  • 1
  • 29
  • 42
  • 1
    Regarding "when there is no explicit interface": with an implicit interface the array dummy arguments are going to be contiguous, but there are certainly times where an array temporary will be created even when there is an explicit interface. – francescalus Jun 21 '21 at 16:55
  • That is right @francescalus. It is not easy to explain everything behind the scene there in few lines. – innoSPG Jun 21 '21 at 17:05