<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385721#M161399</link>
    <description>&lt;P&gt;Ah I see, I made that change for both psi and B and it did indeed get rid of the warning. Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 19 May 2022 19:00:12 GMT</pubDate>
    <dc:creator>tidges</dc:creator>
    <dc:date>2022-05-19T19:00:12Z</dc:date>
    <item>
      <title>Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385504#M161379</link>
      <description>&lt;P&gt;I'm getting this warning from my code, and I think I understand generally what it means (a temporary array is created because the one provided is not contiguous in memory), but I'm confused because I thought all of my array slices were already contiguous, as they're of the form (n:m,j).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function is (approximately) as follows:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;    function schrodStep(EJ0, EJ1, EJ2, psi, B)
    !Calculate the 9-level Schrodinger eqn
        real(RK), intent(in) :: EJ0, EJ1, EJ2
        real(RK), dimension(nPhis_overall, 3), intent(in) :: B
		real(RK), dimension(nPhis_overall) :: Bx, By, Bz
        complex(RK), dimension(nPhis_overall, nStates), intent(in) :: psi
        complex(RK), dimension(nPhis_overall, nStates) :: schrodStep
        complex(RK), dimension(nPhis_overall) :: psiJ0m0, psiJ1mn1, psiJ1m0, psiJ1m1, psiJ2mn2, psiJ2mn1, psiJ2m0, psiJ2m1, psiJ2m2

		Bx = B(1:nPhis_overall, 1)
		By = B(1:nPhis_overall, 2)
		Bz = B(1:nPhis_overall, 3)

		psiJ0m0 = psi(1:nPhis_overall, 1)
                !and so on, until
		psiJ2m2 = psi(1:nPhis_overall, 9)

        schrodStep(1:nPhis_overall, 1) = (xi*psiJ1mn1*(Bx-ci*By)/SQRT(3.0_RK) - xi*psiJ1m1*(Bx+ci*By)/SQRT(3.0_RK) &amp;amp;
        + SQRT(2.0_RK/3.0_RK)*xi*psiJ1m0*Bz + psiJ0m0*EJ0)*-ci/hbar
        !And similar lines for the other 8 levels
end function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;I get the warning for both array arguments (psi and B). This is the core function of a numerical integration, so if it's causing any inefficiency it would be a big deal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 05:58:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385504#M161379</guid>
      <dc:creator>tidges</dc:creator>
      <dc:date>2022-05-19T05:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385522#M161380</link>
      <description>&lt;P&gt;Which line (or lines) is the warning specifically reported for?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what I can tell, there are no non-intrinsic function references within the code that you show.... is the warning being reported against references to schrodStep?&amp;nbsp; If so, please show the declarations for the actual arguments in the function reference and the source of the reference itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 06:59:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385522#M161380</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2022-05-19T06:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385673#M161392</link>
      <description>&lt;P&gt;The excerpt you provided is not compilable. If you can provide (ideally as an attachment rather than inline) a source that compiles on its own, we can check to see where this warning may be coming from.&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 16:18:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385673#M161392</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2022-05-19T16:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385691#M161394</link>
      <description>&lt;P&gt;Sure, there's a "resultsStem" parameter which will need to be changed to a writeable directory in order to run but I think that's the only change needed. The calls to my function are lines 192-195, and that is where the warning points to.&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 16:59:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385691#M161394</guid>
      <dc:creator>tidges</dc:creator>
      <dc:date>2022-05-19T16:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385701#M161395</link>
      <description>&lt;P&gt;I attached the full code in my reply to Steve, but I've tried to keep only the relevant lines here to make it easier to parse (though obviously it's not longer working code):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;program hello
    use iso_fortran_env, only: int16, int32, real64
    use ifport
    implicit none

    integer, parameter :: RK=real64, Ishort=int16, Ilong=int32

    integer(Ilong) :: nFreqs, nPhis, nPhis_overall, expNum, parLoopInd, folStat
    integer(Ishort) :: init_i, nStates=9
    real(RK), dimension(:), allocatable :: phis, phis_loop, phis_overall, freqs_loop, loopArr, chirpScales
    real(RK) :: t_max, h, t, tT, tD
    complex(RK), parameter :: ci=(0.0_RK,1.0_RK), c0=(0.0_RK,0.0_RK), c1=(1.0_RK,0.0_RK)
    complex(RK), dimension(:,:), allocatable :: psi, psi_new, k, k1, k2, k3, k4
    real(RK), dimension(:,:), allocatable :: B, B_Step, B_halfStep, B_background
    complex(RK), dimension(:), allocatable :: psi_vec

    allocate(psi_vec(nStates))
    psi_vec = SQRT([c0, c0, c1, c0, c0, c0, c0, c0, c0])
    allocate(B_background(nPhis_overall,3))
    B_background(1:nPhis_overall, 1) = 0.0_RK !Residual background B field (x,y,z)
    B_background(1:nPhis_overall, 2) = 0.0_RK
    B_background(1:nPhis_overall, 3) = 0.0_RK

	do parLoopInd=1,SIZE(loopArr) !Whole run loop for changing parameters
		allocate(psi_new(nPhis_overall,nStates), psi(nPhis_overall,nStates))
		allocate(B(nPhis_overall,3), B_Step(nPhis_overall,3), B_halfStep(nPhis_overall,3))
		do expNum=1,size(expTypes) !A/B experiment loop
			do j=1,nPhis !Phis pulse loop
				do i=1,nFreqs !Freqs loop
					!Runge-Kutta initialising
					t = 0.0_RK
					do init_i=1,nPhis_overall
						psi_new(init_i, 1:nStates) = psi_vec
					end do
                    B_step(1:nPhis_overall, 1) = 0.0_RK
                    B_step(1:nPhis_overall, 2) = 0.0_RK
                    B_step(1:nPhis_overall, 3) = Bz0
					do while (t.LT.t_max) !Runge-Kutta loop
						!z-polarised microwaves with some y component, and z-aligned DC B field. Use previous stepped value to save on calculations
						psi = psi_new
						B = B_step
						B_halfStep(1:nPhis_overall, 1) = 0.0_RK
						B_halfStep(1:nPhis_overall, 2) = getB_mw(t+h/2.0_RK)*SIND(theta_MW)
						B_halfStep(1:nPhis_overall, 3) = Bz0 + getB_mw(t+h/2.0_RK)*COSD(theta_MW)
						B_step(1:nPhis_overall, 1) = 0.0_RK
						B_step(1:nPhis_overall, 2) = getB_mw(t+h)*SIND(theta_MW)
						B_step(1:nPhis_overall, 3) = Bz0 + getB_mw(t+h)*COSD(theta_MW)

						k1 = schrodStep(EJ0, EJ1, EJ2, psi, B+B_background)
						k2 = schrodStep(EJ0, EJ1, EJ2, psi+h*k1/2.0_RK, B_halfStep+B_background)
						k3 = schrodStep(EJ0, EJ1, EJ2, psi+h*k2/2.0_RK, B_halfStep+B_background)
						k4 = schrodStep(EJ0, EJ1, EJ2, psi+h*k3, B_step+B_background)
						k = (k1 + 2.0_RK*k2 + 2.0_RK*k3 + k4)/6.0_RK

						psi_new = psi + h*k
						t = t+h
					end do !Runge-Kutta time loop
				end do !Freqs loop
			end do !Phis pulse loop
			deallocate(phis)
		end do !A/B experiment loop
		deallocate(B, B_halfStep, B_Step, psi, psi_new)
	end do !Whole run loop for changing parameters
end program
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;and getB_mw() looks like this (nothing interesting, just returns a vector of dimension nPhis_overall because that's the dimension of the 'phis' variable in the argument of the sine at the end)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;    function getB_mw(t)
    !Gives two-pulse profile, scaled
        real(RK), intent(in) :: t
        real(RK), dimension(nPhis_overall) :: getB_mw

        if (expType .EQ. 'A') then
            amp = (TANH(t-10.0_RK)-TANH(t-tD-10.0_RK)+TANH(t-tT-10.0_RK)-TANH(t-tT-tD-10.0_RK))/2 + &amp;amp;
                   0.008_RK*powerLvl*(EXP(-(t-9.0_RK)**2.0_RK/2.0_RK))!+EXP(-(t-309.0_RK)**2.0_RK/2.0_RK))
        else if (expType .EQ. 'B') then
            amp = (TANH(t-10.0_RK)-TANH(t-tD-10.0_RK)+TANH(t-tT-10.0_RK)-TANH(t-tT-tD-10.0_RK))/2 + &amp;amp;
                   0.008_RK*powerLvl*EXP(-(t-309.0_RK)**2.0_RK/2.0_RK)
        end if
        getB_mw = amp*SIN(2*pi*freqRF*t+phis)
    end function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The warning points to the Runge-Kutta lines, 49-52 in the first excerpt here.&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 17:38:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385701#M161395</guid>
      <dc:creator>tidges</dc:creator>
      <dc:date>2022-05-19T17:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385714#M161397</link>
      <description>&lt;P&gt;Thanks - I can reproduce this&lt;STRIKE&gt; and it's a bug&lt;/STRIKE&gt;. &lt;STRIKE&gt;The compiler is improperly calculating the shape for expressions such as B+B_Background for the purpose of the contiguity check.&lt;/STRIKE&gt; A workaround is to declare an additional allocatable array, I called it BX and then do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;BX = B+B_background; k1 = schrodStep(EJ0, EJ1, EJ2, psi, BX)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't have to explicitly allocate BX.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me see if I can come up with a minimal test case.&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 19:09:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385714#M161397</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2022-05-19T19:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385721#M161399</link>
      <description>&lt;P&gt;Ah I see, I made that change for both psi and B and it did indeed get rid of the warning. Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 19:00:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385721#M161399</guid>
      <dc:creator>tidges</dc:creator>
      <dc:date>2022-05-19T19:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Warning 406: In call to FUNCTION, an array temporary was created for argument #n</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385724#M161401</link>
      <description>&lt;P&gt;I have a small reproducer, but I'm uncertain that it's a bug. In reality, the compiler IS creating an array temporary to hold the expression B+B_background, and is not incorrectly calculating the shape. I might argue that this warning ought not to be issued for expressions, but maybe the programmer would like to know if any temporary copy is made. I know there are cases in I/O statements where this warning can inexplicably be generated.&lt;/P&gt;
&lt;P&gt;Of course, this warning is only generated if you explicitly ask for /check:arg_temp_created, as that's not the default. Maybe you could just turn this off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 19:07:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Warning-406-In-call-to-FUNCTION-an-array-temporary-was-created/m-p/1385724#M161401</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2022-05-19T19:07:55Z</dc:date>
    </item>
  </channel>
</rss>

