Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ MPI接收阵列_C++_Arrays_Mpi - Fatal编程技术网

C++ MPI接收阵列

C++ MPI接收阵列,c++,arrays,mpi,C++,Arrays,Mpi,我在接收MPI阵列时遇到问题。我在做这样的事情: int *b = new int[5]; for(int i = 0; i < 5; i++) { b[i] = i; } MPI_Send(&b[0], 5, MPI_INT, procesDocelowy, 0, MPI_COMM_WORLD); 我的问题是我无法接收动态分配的数组。我的进程在

我在接收MPI阵列时遇到问题。我在做这样的事情:

int *b = new int[5];
                for(int i = 0; i < 5; i++) {
                    b[i] = i;
                }
                MPI_Send(&b[0], 5, MPI_INT, procesDocelowy, 0, MPI_COMM_WORLD);
我的问题是我无法接收动态分配的数组。我的进程在MPI_recv之后挂起,我得到:

job aborted:
rank: node: exit code: message
0: Majster: terminated
1: Majster: terminated
2: Majster: 0xc0000005: process exited without calling finalize
3: Majster: terminated
这很有趣,因为如果我以静态方式初始化数组,我的意思是

intb[5]接收和接收时

intb[]={1,2,3,4,5}发送时

一切正常


我不能静态初始化数组,我必须动态初始化。有没有办法解决这个问题?

这是因为在调用
MPI\u Recv()
时,您使用
&b
来引用数组。如果使用指向动态地址的指针,则发送指针的地址而不是数组的地址

你的问题到底是什么?我在C++中不好,但是即使我有这样的事情:<代码> int *B=新int(5);对于(int i=0;i<5;i++){b[i]=i;}MPI_Send(&b[0],5,MPI_int,procesDocelowy,0,MPI_COMM_WORLD)
int*res=新的int[5];MPI_Recv(res、5、MPI_INT、0、0、MPI_COMM_WORLD和status);对于(inti=0;i<5;i++){std::难道你也不擅长评论:)请把重要的片段放在方便的地方(pastebin,问题)
job aborted:
rank: node: exit code: message
0: Majster: terminated
1: Majster: terminated
2: Majster: 0xc0000005: process exited without calling finalize
3: Majster: terminated