<?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 Andrea, the difficulties that in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobix-with-user-defined-function-imported-from-a-module/m-p/1074931#M22501</link>
    <description>&lt;P&gt;Andrea, the difficulties that you have run into are a consequence of (inadvertently) enabling argument checking because of the way that you structured your module code and some obscure features of the interface that its designers gave to DJACOBIX.&lt;/P&gt;

&lt;P&gt;The MKL example code&amp;nbsp;ex_nlsqp_f90_x.f90, which you used as the basis of your own code, contains&amp;nbsp;&lt;STRONG&gt;extended_powell&lt;/STRONG&gt; as an external subroutine. In fact, the main program declares it to be EXTERNAL and, with some help from %VAL and LOC, things work as long as you do not request that the interfaces be checked.&lt;/P&gt;

&lt;P&gt;In the long run and in production code, you probably should do things properly using ISO_C_BINDING and type conversions using TRANSFER, but that is a lot of work for code used only for testing and intended to be discarded soon after. Here is what I suggest as a "quick fix":&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;Make extended_powell() an external procedure, by moving the body of the subroutine outside the module (or putting it into a separate file) and remove the CONTAINS.&lt;/LI&gt;
	&lt;LI&gt;Declare extended_powell as EXTERNAL in your main program, as in the MKL example.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;That should take care of things for now, but be alert for problems if you use this code in a larger program.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Apr 2017 10:10:00 GMT</pubDate>
    <dc:creator>mecej4</dc:creator>
    <dc:date>2017-04-06T10:10:00Z</dc:date>
    <item>
      <title>djacobix with user defined function imported from a module</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobix-with-user-defined-function-imported-from-a-module/m-p/1074930#M22500</link>
      <description>&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;Hi there, I'm new to this forum, so I hope I'm posting this into the correct section.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I'm trying to use the mkl trust region algorithm to solve a non linear system of equations in a fortran program. I started from the example provided online (ex_nlsqp_f90_x.f90&amp;nbsp;&lt;A href="https://software.intel.com/en-us/node/501498"&gt;https://software.intel.com/en-us/node/501498&lt;/A&gt;) and everything works correctly. Now, because I have to use this in a much bigger program, I need the user defined objective function to be loaded from a separate module. Hence, I splitted the example into 2 separate files, but I'm not able to make it compile correctly.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;So here is the code for module which contains user defined data structure and the objective function&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;module modFun
implicit none
private
public my_data, extended_powell

type :: my_data
      integer a
      integer sum
end type my_data


contains

subroutine extended_powell (m, n, x, f, user_data)
    implicit none
    integer, intent(in) :: m, n
    real*8 , intent(in) :: x(n)
    real*8, intent(out) :: f(m)
    type(my_data) :: user_data
    integer i

    user_data%sum = user_data%sum + user_data%a
    do i = 1, n/4
        f(4*(i-1)+1) = x(4*(i-1)+1) + 10.0 * x(4*(i-1)+2)
        f(4*(i-1)+2) = 2.2360679774998 * (x(4*(i-1)+3) - x(4*(i-1)+4))
        f(4*(i-1)+3) = ( x(4*(i-1)+2) - 2.0 * x(4*(i-1)+3) )**2
        f(4*(i-1)+4) = 3.1622776601684 * (x(4*(i-1)+1) - x(4*(i-1)+4))**2
    end do
end subroutine extended_powell

end module modFun&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;!    nonlinear least square problem without boundary constraints
    include 'mkl_rci.f90'
program EXAMPLE_EX_NLSQP_F90_X
    use MKL_RCI
    use MKL_RCI_type
    use modFun

!   user's objective function
!   n - number of function variables
!   m - dimension of function value
    integer n, m
    parameter (n = 4)
    parameter (m = 4)
!   precisions for stop-criteria (see manual for more details)
    real*8 eps(6)
!   solution vector. contains values x for f(x)
    real*8 x(n)
!   jacobi matrix
    real*8 fjac(m*n)
...
!   Additional users data
    type(my_data), target :: m_data
...
djacobix (extended_powell,n,m,fjac,x,eps(1),%val(loc(m_data))) /= &amp;amp;
                TR_SUCCESS)
...
end program
&lt;/PRE&gt;

&lt;P&gt;The problem appear to be some characteristic of argument 5, which is the are defined data, hence it has its on type. I tried changing intent, but it doesn't work&lt;/P&gt;

&lt;P style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);"&gt;&lt;SPAN style="font-variant-ligatures: no-common-ligatures"&gt;ex_nlsqp_f90_x_M.f90(170): error #7065: The characteristics of dummy argument 5 of the associated actual procedure differ from the characteristics of dummy argument 5 of the dummy procedure. &amp;nbsp; [EXTENDED_POWELL]&lt;/SPAN&gt;&lt;/P&gt;

&lt;P style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);"&gt;&lt;SPAN style="font-variant-ligatures: no-common-ligatures"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (djacobix (extended_powell,n,m,fjac,x,eps(1),%val(loc(m_data))) /= &amp;amp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);"&gt;&lt;SPAN style="font-variant-ligatures: no-common-ligatures"&gt;--------------------------^&lt;/SPAN&gt;&lt;/P&gt;

&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;

&lt;P&gt;On the other hand&amp;nbsp;&lt;A href="http://technion.ac.il/doc/intel/mkl/mkl_manual/osr/functn_djacobix.htm"&gt;http://technion.ac.il/doc/intel/mkl/mkl_manual/osr/functn_djacobix.htm&lt;/A&gt;&amp;nbsp;it's stated that the first argument of djacobix (i.e. the objective function subroutine) need to be declared as external, which can't done &amp;nbsp;because the obj function need to reside in a module.&lt;/P&gt;

&lt;P&gt;Can anyone help me with this problem providing a working example?&amp;nbsp;&lt;SPAN style="font-size: 1em;"&gt;Thanks a lot. Andrea&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:11:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobix-with-user-defined-function-imported-from-a-module/m-p/1074930#M22500</guid>
      <dc:creator>andrea_r_</dc:creator>
      <dc:date>2017-04-05T15:11:03Z</dc:date>
    </item>
    <item>
      <title>Andrea, the difficulties that</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobix-with-user-defined-function-imported-from-a-module/m-p/1074931#M22501</link>
      <description>&lt;P&gt;Andrea, the difficulties that you have run into are a consequence of (inadvertently) enabling argument checking because of the way that you structured your module code and some obscure features of the interface that its designers gave to DJACOBIX.&lt;/P&gt;

&lt;P&gt;The MKL example code&amp;nbsp;ex_nlsqp_f90_x.f90, which you used as the basis of your own code, contains&amp;nbsp;&lt;STRONG&gt;extended_powell&lt;/STRONG&gt; as an external subroutine. In fact, the main program declares it to be EXTERNAL and, with some help from %VAL and LOC, things work as long as you do not request that the interfaces be checked.&lt;/P&gt;

&lt;P&gt;In the long run and in production code, you probably should do things properly using ISO_C_BINDING and type conversions using TRANSFER, but that is a lot of work for code used only for testing and intended to be discarded soon after. Here is what I suggest as a "quick fix":&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;Make extended_powell() an external procedure, by moving the body of the subroutine outside the module (or putting it into a separate file) and remove the CONTAINS.&lt;/LI&gt;
	&lt;LI&gt;Declare extended_powell as EXTERNAL in your main program, as in the MKL example.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;That should take care of things for now, but be alert for problems if you use this code in a larger program.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 10:10:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobix-with-user-defined-function-imported-from-a-module/m-p/1074931#M22501</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2017-04-06T10:10:00Z</dc:date>
    </item>
  </channel>
</rss>

