<?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 Please read the MKL in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109328#M24280</link>
    <description>&lt;P&gt;Please read the MKL documentation for "Nonlinear Optimization Solvers - Jacobian Matrix Calculation Routines". The proper invocation is&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;iret = djacobi(fcn , n, m, fjac, x, eps)&lt;/PRE&gt;

&lt;P&gt;where &lt;STRONG&gt;iret &lt;/STRONG&gt;is an integer status code. The include file mkl_rci.fi contains the interface of this routine, and your calling it as a subroutine is in error.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Apr 2016 01:22:00 GMT</pubDate>
    <dc:creator>mecej4</dc:creator>
    <dc:date>2016-04-29T01:22:00Z</dc:date>
    <item>
      <title>Error : The CALL statement is invoking a function subprogram as a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109327#M24279</link>
      <description>&lt;P&gt;I am trying to learn to use MKL routines. I have written a simple code for calculating the jacobian matrix. However, it ends up with the below error:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;The CALL statement is invoking a function subprogram as a subroutine. [DJACOBI]
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Here is my code and I am compiling it with: &lt;EM&gt;ifort&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;-&lt;/EM&gt;&lt;EM&gt;mkl&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;newton2.f90&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;INCLUDE '/home/vahid/intel/composer_xe_2015.3.187/mkl/include/mkl_rci.f90'

program newton2
    implicit none
    real*8, dimension(3) :: x
    real*8, dimension(3,3) :: fjac
    real*8 :: phi1,phi2,phi3
    integer :: i,m,n
    integer, parameter :: maxit=100
    real*8, parameter :: eps=0.0001

    INCLUDE '/home/vahid/intel/composer_xe_2015.3.187/mkl/include/mkl_rci.fi' 

    external fcn
       
    x(1)=0
    x(2)=0
    x(3)=0
    n=3;m=3

    !Call fcn (m, n, x, f)
        
    call djacobi(fcn , n, m, fjac, x, eps)

    write(*,*) fjac

end program newton2

subroutine fcn (m, n, x, f)
    real*8, dimension(3) :: x,f
    real*8 :: phi1,phi2,phi3
       
    phi1=0 ; phi2 = 0.1; phi3= 0.9;
    f(1) = 2*(800) *(x(1)-0.7)  - 2*(12000)*(x(2)-0.45);
    f(2) = 2*(12000)*(x(2)-0.45)- 2*(1200)*(x(3)-0.9)  ;
    f(3) = x(1)*phi1 + x(2)*phi2 + x(3)*phi3 - 0.42  ;  
      
end subroutine fcn
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 23:27:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109327#M24279</guid>
      <dc:creator>vahid_a_1</dc:creator>
      <dc:date>2016-04-28T23:27:41Z</dc:date>
    </item>
    <item>
      <title>Please read the MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109328#M24280</link>
      <description>&lt;P&gt;Please read the MKL documentation for "Nonlinear Optimization Solvers - Jacobian Matrix Calculation Routines". The proper invocation is&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;iret = djacobi(fcn , n, m, fjac, x, eps)&lt;/PRE&gt;

&lt;P&gt;where &lt;STRONG&gt;iret &lt;/STRONG&gt;is an integer status code. The include file mkl_rci.fi contains the interface of this routine, and your calling it as a subroutine is in error.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 01:22:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109328#M24280</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-04-29T01:22:00Z</dc:date>
    </item>
    <item>
      <title>Thanks @mesej4. Your comment</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109329#M24281</link>
      <description>&lt;P&gt;Thanks @mesej4. Your comment solved the issue.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Now, I have updated the code accordingly and I am trying to finalize the code by writing&amp;nbsp;a simple newton-raphson&amp;nbsp;solver for a system of nonlinear equations. I always have difficulty in the codes which use "interface".&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Here is the updated code. I would like to pass f values from the fcn&amp;nbsp;"subroutine" to the main program and perform a "matmul"&amp;nbsp;operation. However, the elements of array "f" are zero and no information passes through the subroutine to the main program.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program newton2
    implicit none
    real*8, dimension(3) :: x,f
    real*8, dimension(3,3) :: fjac
    integer :: i,m,n
    integer, parameter :: maxit=100
    !! ***** djacobi variables ******
    real*8, parameter :: eps=0.0001
    integer :: res

    !! ***** dgetri variables ******
    integer :: lda,lwork,info
    integer, dimension(3) :: ipiv
    real*8 :: work(3)
    
    !! ***** dgetri variables ****** 
    !INCLUDE '/home/vahid/intel/composer_xe_2015.3.187/mkl/include/mkl_rci.fi' 
    INCLUDE 'mkl_rci.fi' 
    
    INTERFACE fcn
        SUBROUTINE fcn
            REAL*8, DIMENSION(3) :: x
            real*8, dimension(3) :: f
        END SUBROUTINE fcn
    END INTERFACE
    
    !! ************* Input arguments 
    x(1)=0 ; x(2)=0 ; x(3)=0
    n=3;m=3;lda = 3;
    
    !! ************* Jacobi matrix of the user's objective function using the central difference
    res = djacobi(fcn , n, m, fjac, x, eps)
    write(*,*) fjac
    write(*,*) fjac(2,1)
    
    !! ************* The LU factorization of a general m-by-n matrix.
    ipiv = max(1,n)
    call dgetrf( m, n, fjac, lda, ipiv, info )
    write(*,*) fjac
    write(*,*) info
    
    !! ************* The inverse inv(A) of a general matrix A.
    lwork=3*1000
    call dgetri( n, fjac, lda, ipiv, work, lwork, info )
    write(*,*) fjac
    write(*,*) info
    
    !DO i=1,maxit
    write(*,*) x
    write(*,*) f 
    write(*,*) matmul(fjac,f)
    x = x - matmul(fjac,f)
    write(*,*) x

end program newton2

subroutine fcn (m, n, x, f)
    real*8, dimension(3) :: x
    real*8, dimension(3), intent(out) :: f
    real*8 :: phi1,phi2,phi3
       
    phi1=0.0 ; phi2 = 0.1D0; phi3= 0.9D0;
    f(1) = 2*(800) *(x(1)-0.7)  - 2*(12000)*(x(2)-0.45);
    f(2) = 2*(12000)*(x(2)-0.45)- 2*(1200)*(x(3)-0.9)  ;
    f(3) = x(1)*phi1 + x(2)*phi2 + x(3)*phi3 - 0.42  ;

    return
end subroutine fcn
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 17:02:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109329#M24281</guid>
      <dc:creator>vahid_a_1</dc:creator>
      <dc:date>2016-04-29T17:02:39Z</dc:date>
    </item>
    <item>
      <title>The include file 'mkl_rci.fi'</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109330#M24282</link>
      <description>&lt;P&gt;The include file 'mkl_rci.fi' provides the interfaces needed, so you need not provide one for &lt;STRONG&gt;fcn&lt;/STRONG&gt; again. Here is a sketch of what you need:&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;...&lt;/P&gt;

&lt;P&gt;do iter = 1,maxit&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;call fcn(...) &amp;nbsp;! to compute f() at the current x() &amp;nbsp;&amp;lt;&amp;lt;=== you left this out in your code&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;call djacobi(...) &amp;nbsp;! to compute fjac() at the current x()&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;call dgesv() &amp;nbsp; ! to solve for the Newton Raphson correction dx = J&lt;SUP&gt;-1&lt;/SUP&gt;f&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;compute ||dx|| or ||f||, decide whether to terminate iterations&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;x = x - dx&amp;nbsp;&lt;/P&gt;

&lt;P&gt;end do&lt;/P&gt;

&lt;P&gt;If your objective is just to obtain the solution, all that you have to do is to take the example code &lt;STRONG&gt;ex_nlsqp.f&lt;/STRONG&gt;, which is included in the MKL installation, change m and n, put in your functions, build and run.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 18:20:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109330#M24282</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-04-29T18:20:00Z</dc:date>
    </item>
    <item>
      <title> </title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109331#M24283</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Dear&amp;nbsp;&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;mecej4,&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;My objective is to learn to use Intel MKL whenever I need it. Thanks for the suggestions. Everything works now and it solves my&amp;nbsp;main equations. However, I have another question for you. Why using intel MKL makes the code very slow?! I mean very slow...&amp;nbsp;&lt;/P&gt;

&lt;P&gt;To b more precise, &amp;nbsp;I am solving a PDE and at each iteration, the code calls newton-raphson solver to solve a system of nonlinear equations.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I have two &lt;/SPAN&gt;implementation&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;of the code now. I&lt;/SPAN&gt;where in&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt; the 1st one, the newton-&lt;/SPAN&gt;raphson&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt; solver is written by &lt;/SPAN&gt;myslef&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;and the inverse of jacobian is calculated analytically and just placed in the code manually.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;However, in the 2nd &lt;/SPAN&gt;implementation,&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt; I have modified the newton-&lt;/SPAN&gt;raphson&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt; solver by your help and used the MKL routines to do everything in Fortran. (calculating the jacobian and its inverse)&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;The 2nd implementation is very slow. The ratio of&amp;nbsp;&lt;SPAN style="background-color: rgb(255, 217, 222);"&gt;simulation time for 2 million iterations is&lt;/SPAN&gt;&amp;nbsp;: (6minutes / ~3 hours) ---&amp;gt; (my newton-raphson/Intel MKL)&lt;/P&gt;

&lt;P&gt;Both of the implementations work in serial mode.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;mecej4 wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;The include file 'mkl_rci.fi' provides the interfaces needed, so you need not provide one for &lt;STRONG&gt;fcn&lt;/STRONG&gt; again. Here is a sketch of what you need:&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;...&lt;/P&gt;

&lt;P&gt;do iter = 1,maxit&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;call fcn(...) &amp;nbsp;! to compute f() at the current x() &amp;nbsp;&amp;lt;&amp;lt;=== you left this out in your code&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;call djacobi(...) &amp;nbsp;! to compute fjac() at the current x()&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;call dgesv() &amp;nbsp; ! to solve for the Newton Raphson correction dx = J&lt;SUP&gt;-1&lt;/SUP&gt;f&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;compute ||dx|| or ||f||, decide whether to terminate iterations&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;x = x - dx&amp;nbsp;&lt;/P&gt;

&lt;P&gt;end do&lt;/P&gt;

&lt;P&gt;If your objective is just to obtain the solution, all that you have to do is to take the example code &lt;STRONG&gt;ex_nlsqp.f&lt;/STRONG&gt;, which is included in the MKL installation, change m and n, put in your functions, build and run.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 03:04:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109331#M24283</guid>
      <dc:creator>vahid_a_1</dc:creator>
      <dc:date>2016-05-02T03:04:00Z</dc:date>
    </item>
    <item>
      <title>What is the size of the</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109332#M24284</link>
      <description>&lt;P&gt;What is the size of the system of nonlinear equations? If it is large, calculating the Jacobian by calling DJacobi() will be very wasteful and expensive. At the very least, use a variation of Newton-Raphson in which the Jacobian is updated or calculated sparingly, instead of calculating every time -- straight Newton-Raphson is not a good method for solving large systems of nonlinear equations.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;To solve a linear system A x = b, it is not a good approach to form inv(A) and multiply b with that. Instead, call a routine such as DGESV, which will solve the equations twice as fast.&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 03:50:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Error-The-CALL-statement-is-invoking-a-function-subprogram-as-a/m-p/1109332#M24284</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-05-02T03:50:03Z</dc:date>
    </item>
  </channel>
</rss>

