简体   繁体   English

TypeError:recv()获得了意外的关键字参数“ dest”

[英]TypeError: recv() got an unexpected keyword argument 'dest'

I am trying to use MPI in python to do some parallel computing for midpoint integration. 我正在尝试在python中使用MPI进行一些并行计算以实现中点集成。 I am not really familiar with MPI and I have looked around at some examples to produce what I have thus far. 我对MPI并不是很熟悉,我环顾了一些示例以得出到目前为止的结果。 I am having trouble with a couple of errors where MPI.COMM does not recognize a couple of input arguments. 我遇到了一些错误,其中MPI.COMM无法识别几个输入参数。 Again I am not that familiar with MPI. 同样,我对MPI不太熟悉。

Below I have attached my code: 下面附上我的代码:

from mpi4py import MPI
import numpy as np
from numpy import *
import time

#initialize variables
n = 10e5 #number of increments within each process
a = 0.0; #lower bound
b = 5.0; #upper bound
dest = 0; #define the process that computes the final result

#Functions
def integral(my_a, num, h):
    s = 0;
    h2 = h/2;
    for i in range(0,num):
        temp = my_a + i*h;
        s = s + fct(temp+h2)*h;
    return (s)

def fct(x):
    return x**2;

#Start the MPI process
comm = MPI.COMM_WORLD
p = comm.Get_size(); #gather number of processes
print "Number of processes (p): ", p;
myid = comm.Get_rank() #gather rank of the comm (number of cores)
print "Rank of (p): ", myid;

h = (b-a)/n; #length of increment
num = int(n/p); #number of intervals calculated by each process
print "Number of intervals calculated by a process: ", num;
my_range = (b-a)/p; #range per process
my_a = a + myid*my_range; #next lower limit
ti = time.clock();
my_result = integral(my_a,num,h) #get the result

print "Process " + str(myid) + " has the partial result of " + str(my_result) + ".";

if myid == 0:
    result = my_result;
    for i in range(1,p):
        source = 1;
        comm.recv(my_result, dest=1, tag=123);
        result = result + my_result;
    print "The result = " + str(result) + ".";

else :
    comm.send(my_result, source=0, tag=123);
    MPI_Finalize();


tf = time.clock();
print "Time(s): ", tf-ti;

Here is the error that I get when I try to run this code: 这是我尝试运行此代码时遇到的错误:

--------------------------------------------------------------------------
*******************************-VirtualBox ~/Documents/ME701/HW/HW5 $ mpirun -np 2 python HW5_prb3.py
Number of processes (p):  2
Rank of (p):  1
Number of intervals calculated by a process:  500000
Number of processes (p):  2
Rank of (p):  0
Number of intervals calculated by a process:  500000
Process 1 has the partial result of 36.4583333333.
Traceback (most recent call last):
  File "HW5_prb3.py", line 50, in <module>
    comm.send(my_result, source=0, tag=123);
  File "Comm.pyx", line 1127, in mpi4py.MPI.Comm.send (src/mpi4py.MPI.c:90067)
**TypeError: send() got an unexpected keyword argument 'source'**
Process 0 has the partial result of 5.20833333333.
Traceback (most recent call last):
  File "HW5_prb3.py", line 45, in <module>
    comm.recv(my_result, dest=1, tag=123);
  File "Comm.pyx", line 1142, in mpi4py.MPI.Comm.recv (src/mpi4py.MPI.c:90513)
**TypeError: recv() got an unexpected keyword argument 'dest'**
-------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code.. Per user-direction, the job has been aborted.
-------------------------------------------------------
--------------------------------------------------------------------------
mpirun detected that one or more processes exited with non-zero status, thus causing
the job to be terminated. The first process to do so was:

  Process name: [[45152,1],1]
  Exit code:    1
--------------------------------------------------------------------------
*******************************-VirtualBox ~/Documents/ME701/HW/HW5 $ 

The answer to the midpoint integration should be 41.66667. 中点积分的答案应该是41.66667。 My teacher just wants us to perform a simple time study on parallel computing so we can see the power of it. 我的老师只是希望我们对并行计算进行简单的时间研究,以便我们了解它的强大功能。

Thank you for your time. 感谢您的时间。

I guess you just mixed up send and recv arguments - source is the process rank you receive data from, and dest (short for destination ) is the rank of the process you send data to (you can see the docs , if you want). 我猜你只是混了sendrecv参数- source是从接收数据的处理等级和dest (简称目标 )是您发送数据(你可以看到进程的秩文档 ,如果你想)。

So, just interchanging source and dest keywords in send and receive should be fine. 因此,只需在send和receive中交换sourcedest关键字就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:得到一个意外的关键字参数 - TypeError: got an unexpected keyword argument 类型错误:function() 得到了一个意外的关键字参数“njobs” - TypeError: function() got an unexpected keyword argument 'njobs' 类型错误:_log() 得到了意外的关键字参数“stacklevel” - TypeError: _log() got an unexpected keyword argument 'stacklevel' 类型错误:有一个意外的关键字参数“条目” - TypeError: got an unexpected keyword argument 'entry' TypeError:editProfile()得到了意外的关键字参数“ obj” - TypeError: editProfile() got an unexpected keyword argument 'obj' 类型错误:启动()有一个意外的关键字参数“超时” - TypeError: initiate() got an unexpected keyword argument 'timeout' 类型错误:tensor() 得到了一个意外的关键字参数“名称” - TypeError: tensor() got an unexpected keyword argument 'names' 类型错误:videoResponsive() 得到了一个意外的关键字参数“宽度” - TypeError: videoResponsive() got an unexpected keyword argument 'width' 类型错误:agg() 得到了一个意外的关键字参数 - TypeError: agg() got an unexpected keyword argument TypeError:post()得到了意外的关键字参数&#39;slug&#39; - TypeError: post() got an unexpected keyword argument 'slug'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM