<bdo id='tAfI4'></bdo><ul id='tAfI4'></ul>

<small id='tAfI4'></small><noframes id='tAfI4'>

<tfoot id='tAfI4'></tfoot>
    1. <legend id='tAfI4'><style id='tAfI4'><dir id='tAfI4'><q id='tAfI4'></q></dir></style></legend>

        <i id='tAfI4'><tr id='tAfI4'><dt id='tAfI4'><q id='tAfI4'><span id='tAfI4'><b id='tAfI4'><form id='tAfI4'><ins id='tAfI4'></ins><ul id='tAfI4'></ul><sub id='tAfI4'></sub></form><legend id='tAfI4'></legend><bdo id='tAfI4'><pre id='tAfI4'><center id='tAfI4'></center></pre></bdo></b><th id='tAfI4'></th></span></q></dt></tr></i><div id='tAfI4'><tfoot id='tAfI4'></tfoot><dl id='tAfI4'><fieldset id='tAfI4'></fieldset></dl></div>
      1. numpy.f2py 从 fortran 的子程序返回时发生错误

        时间:2023-09-12
      2. <i id='MUmOf'><tr id='MUmOf'><dt id='MUmOf'><q id='MUmOf'><span id='MUmOf'><b id='MUmOf'><form id='MUmOf'><ins id='MUmOf'></ins><ul id='MUmOf'></ul><sub id='MUmOf'></sub></form><legend id='MUmOf'></legend><bdo id='MUmOf'><pre id='MUmOf'><center id='MUmOf'></center></pre></bdo></b><th id='MUmOf'></th></span></q></dt></tr></i><div id='MUmOf'><tfoot id='MUmOf'></tfoot><dl id='MUmOf'><fieldset id='MUmOf'></fieldset></dl></div>

        <small id='MUmOf'></small><noframes id='MUmOf'>

              <legend id='MUmOf'><style id='MUmOf'><dir id='MUmOf'><q id='MUmOf'></q></dir></style></legend>

                  <tbody id='MUmOf'></tbody>
              1. <tfoot id='MUmOf'></tfoot>
                  <bdo id='MUmOf'></bdo><ul id='MUmOf'></ul>
                  本文介绍了numpy.f2py 从 fortran 的子程序返回时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使 hoge 尽可能简单,但仍然会出现错误.请告诉我有什么问题.

                  这是我的 Fortran 子程序代码.

                  子程序 hoge(d)复杂(种类(0d0)),意图(出)::d(5,10,15)!5 10 15 没有特殊含义..!这两行有效..!整数,参数 :: dp = kind(0d0)!复杂(dp),意图(out)::d(5,10,15)做我=1,15做 j=1,10做 k=1,5d(k,j,i)=0结束结束结束!反而!d(1:5,1:10,1:15)=0 或!d(:,:,:)=0 也会带来错误.!打印*,'返回'返回结束子程序

                  我想使用 Fortran 子例程.我编译如下

                  python -m numpy.f2py -c hoge.f90 -m hoge

                  并如下使用

                  进口猪hoge.hoge()

                  那么结果就是下面的三行:

                  返回双重免费或腐败(出)中止(核心转储)

                  我完全不知道...请告诉我有什么问题.

                  当线路发生如下变化时

                  做 j=1,10 ->做 j=1,5

                  错误不会发生...(供您参考..)1..6带来了错误.

                  解决方案

                  根据 F2PY 用户指南和参考手册:

                  <块引用>

                  目前F2PY只能处理<type spec>(kind=<kindselector>)<kindselector> 是数字整数的声明(例如 1、2、4,...),但不是函数调用 KIND(..) 或任何其他表达式.

                  因此,您的代码示例中的声明 complex(kind(0d0)) 正是 f2py 无法解释的函数调用或其他表达式.

                  正如您所发现的(但在代码中已注释掉),一种解决方法是首先生成一个整数种类说明符(integer, parameter :: dp = kind(0d0)),然后然后在复杂变量 complex(dp) 的种类说明符中使用它.

                  如果您无法像这样更改 Fortran 源代码,文档会进一步概述 映射文件(默认名称为 .f2py_f2cmap 或使用命令传递可以创建和使用行标志 --f2cmap ).在你的情况下,你可以例如使用包含以下内容的默认文件:

                  $ cat .f2py_f2cmap{'complex': {'KIND(0D0)': 'complex_double'}}

                  并像以前一样编译,以获得所需的行为.

                  I made hoge as simple as possible and errors still coming. Please tell me what problems are.

                  This is my Fortran subroutine code.

                  subroutine hoge(d)
                    complex(kind(0d0)), intent(out):: d(5,10,15) ! 5 10 15 does not have special meanings..
                  
                    ! these two lines works..
                    ! integer, parameter :: dp = kind(0d0)
                    ! complex(dp), intent(out) :: d(5,10,15)
                  
                    do i=1,15
                      do j=1,10
                        do k=1,5
                          d(k,j,i)=0
                        enddo
                      enddo
                    enddo
                    ! instead 
                    ! d(1:5,1:10,1:15)=0 or
                    ! d(:,:,:)=0 also brings the error.
                    !
                    print*,'returning'
                    return
                  end subroutine hoge
                  

                  I want to use a Fortran subroutine. I compiled like below

                  python -m numpy.f2py -c hoge.f90 -m hoge
                  

                  and use as below

                  import hoge
                  hoge.hoge()
                  

                  then the result is the three lines below:

                  Returning
                  double free or corruption (out)
                  Aborted (core dumped)
                  

                  I totally have no idea... please tell me what problems are.

                  When the line has a change like below

                  do j=1,10   -> do j=1,5
                  

                  the error does not occur... (for your information..) 1..6 brings the error.

                  解决方案

                  According to the F2PY User Guide and Reference Manual:

                  Currently, F2PY can handle only <type spec>(kind=<kindselector>)
                  declarations where <kindselector> is a numeric integer (e.g. 1, 2,
                  4,…), but not a function call KIND(..) or any other expression.

                  Thus, the declaration complex(kind(0d0)) in your code example is exactly the kind of function call or other expression that f2py cannot interpret.

                  As you have found out (but commented out in the code), one work around is to first generate an integer kind specifier (integer, parameter :: dp = kind(0d0)), and then use that in the kind specifier of your complex variable complex(dp).

                  If changing the Fortran source code like this is not an option for you, the documentation further outlines how a mapping file (with default name .f2py_f2cmap or passed using command line flag --f2cmap <filename>) can be created and used instead. In your case, you can e.g. use the default file with the following contents:

                  $ cat .f2py_f2cmap
                  {'complex': {'KIND(0D0)': 'complex_double'}}
                  

                  and compile as before, to get the desired behaviour.

                  这篇关于numpy.f2py 从 fortran 的子程序返回时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否可以使用 MPI 将数据从 Fortran 程序发送到 P 下一篇:Fortran 相当于 numpy.where() 函数?

                  相关文章

                  最新文章

                  <legend id='fcYgC'><style id='fcYgC'><dir id='fcYgC'><q id='fcYgC'></q></dir></style></legend>

                  1. <tfoot id='fcYgC'></tfoot>
                  2. <i id='fcYgC'><tr id='fcYgC'><dt id='fcYgC'><q id='fcYgC'><span id='fcYgC'><b id='fcYgC'><form id='fcYgC'><ins id='fcYgC'></ins><ul id='fcYgC'></ul><sub id='fcYgC'></sub></form><legend id='fcYgC'></legend><bdo id='fcYgC'><pre id='fcYgC'><center id='fcYgC'></center></pre></bdo></b><th id='fcYgC'></th></span></q></dt></tr></i><div id='fcYgC'><tfoot id='fcYgC'></tfoot><dl id='fcYgC'><fieldset id='fcYgC'></fieldset></dl></div>

                    <small id='fcYgC'></small><noframes id='fcYgC'>

                    • <bdo id='fcYgC'></bdo><ul id='fcYgC'></ul>