多处理:类型错误:不能腌制 fortran 对象

问题描述

考虑这个 fortran 模块 (example.f90)

module mod
  implicit none
contains
  subroutine test(a,b)
    double precision,intent(in) :: a
    double precision,intent(out) :: b
    b = 2.d0*a
  end subroutine
end module

我可以用 f2py 和命令 python -m numpy.f2py -c example.f90 -m example 将它包装起来。

以下 Python 代码不起作用。它产生错误 TypeError: can't pickle fortran objects

from pathos.multiprocessing import ProcessingPool as Pool
from example import mod as mod1

def function(inpt):
    mod = mod1
    def test(x):
        return mod.test(x)
    with Pool(5) as p:
        result = p.map(test,inpt)
    return result

inpt = [1.,2.,3.,4.,5.]
result = function(inpt)
print(result)

尽管如此,当我将 Python 代码稍微更改为以下内容时,它运行时没有错误

from pathos.multiprocessing import ProcessingPool as Pool
from example import mod

def function(inpt):
    def test(x):
        return mod.test(x)
    with Pool(5) as p:
        result = p.map(test,5.]
result = function(inpt)
print(result)

关于在 mod 中重新定义 Fortran 模块对象 function 的事情,把一切都搞砸了。

我正在寻找一种变通方法,它允许我在 function 中重新定义 fortran 模块(即上面的第一个 python 示例)。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)