我正在尝试使用并行python(PP软件包)在python 2.7中执行一个fortran子例程。但是当我使用pp.server()。submit(...)执行它时,什么也没发生。我可能执行错了,我使用了here所述的numpy.f2py.compile()
。有人可以告诉我这是否正确吗?如果没有,我应该怎么改变?
只是说,鉴于其摘自博士学位论文(code,paper),所以该代码几乎肯定是正确的。
在名为“ design_operation”的python 2.7模块中实现的子例程为:
import numpy.f2py
fsource = '''
subroutine matrix_op(grid_x,grid_t,eval_grid,pas,K,L,M,C)
COMPLEX :: i=(0.0,1.0)
INTEGER , intent(in) :: K,L,M
REAL , intent(in) :: pas
INTEGER :: u,v,w
REAL , dimension(1:M) , intent(in) :: grid_x
REAL , dimension(1:K) , intent(in) :: grid_t
REAL , dimension(1:L) , intent(in) :: eval_grid
COMPLEX, dimension(1:L,1:M) , intent(out) :: C
do u=1,L
do v=1,M
do w=1,K
C(u,v) = C(u,v) - i*pas*grid_t(w)*grid_x(v)*exp(-i*grid_t(w)*grid_x(v)*eval_grid(u))
end do
end do
end do
end subroutine matrix_op
'''
numpy.f2py.compile(fsource, modulename='design_operation', verbose=0)
然后,我这样称呼它:
job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)
实际上处于循环中,应在以下位置执行:
job_server = pp.Server()
thread_number = job_server.get_ncpus()
...some unimportant code ...
jobs = []
for k in range(thread_number):
jobs.append(job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)))
for i,job in enumerate(jobs):
if i == 0:
dM = job()
else:
dM = np.concatenate((dM, job()))
job_server.destroy()
return dM
我总是收到以下错误:零维数组无法连接。
因此,我认为错误是由于任务执行不正确而引起的,但也许是我误会了。
堆栈错误为:
An error has occured during the function execution
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\ppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
An error has occured during the function execution
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\ppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
Traceback (most recent call last):
File "<ipython-input-89-6cb5b50fd813>", line 5, in <module>
dM = np.concatenate((dM, job()))#
ValueError: zero-dimensional arrays cannot be concatenated
PS:我认为这里有一些不必要的代码,因此为了更加清晰起见,我没有将其包括在内+ func = list_append的参数正确。
答案 0 :(得分:1)
我注意到您的代码似乎没有将K, L, M
和C
变量传递给Fortran例程。但是,K, L, M
用于确定某些数组的维数,也用作循环计数器。编译器很可能将这些值设置为默认值0
,或者更可能被Python设置为默认值None
。这将解释您的错误消息“ ValueError:零维数组无法连接”。