Fortran通过f2py扩展到Python:如何配置?

时间:2013-05-14 13:44:13

标签: python fortran profiler f2py cprofile

我正在使用通过f2py(Ver.2)编译的Fortran(gfortran 4.4.7)编写的Python(2.7.2)扩展。

我可以使用cProfile来分析Python部分,但结果不会提供有关Fortran函数的任何信息。相反,时间归因于调用Fortran函数的Python函数。

我为我构建的所有Fortran对象启用了“-pg -O”标志,并在f2py调用中通过以下方式启用了共享对象:f2py --opt="-pg -O" ...

有关如何获取Fortran信息的任何提示都非常受欢迎。

如果有人使用类似的设置,使用不同的探查器,我也会感兴趣。

3 个答案:

答案 0 :(得分:1)

查看python扩展分析器yep

答案 1 :(得分:1)

Fortran函数调用显示为:

<ipython-input-51-f4bf36c6a947>:84(<module>). 

我知道,你无法识别被调用的模块,但至少这会给你一个想法。

另一种方法是将它包装到Python函数中,然后查看Python函数的时间。

答案 2 :(得分:0)

此工作流程似乎运作良好:

    1. 使用 callgrind 来分析您的代码(这会生成一个像callgrind.out.27237这样的文件):
  

valgrind --tool = callgrind python my_python_script_calling_f2py_functions.py arg1 arg2

  

gprof2dot -f callgrind callgrind.out.27237&gt; callgrind.dot

  

dot -Tjpg callgrind.dot -o callgrind.jpg