【问题标题】:MPI recieving arraysMPI 接收数组
【发布时间】:2015-03-08 23:16:45
【问题描述】:

我在接收 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);

这就是我发送数组的方式。 接收:

int *b = new int[5];
            MPI_Recv(&b, 5, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);

我的问题是我无法接收动态分配的数组。我的进程在 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

这很有趣,因为如果我以静态方式初始化我的数组,我的意思是

int b[5];接收时和

int b[] = {1,2,3,4,5}; 发送时

一切正常。

我不能以静态方式初始化数组,我必须动态地这样做。任何想法如何解决这个问题?

【问题讨论】:

  • 您的问题究竟是什么?

标签: c++ arrays mpi


【解决方案1】:

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

【讨论】:

  • 我的 C++ 不好,但即使我有这样的东西:int *b = new int[5]; for(int i = 0; i &lt; 5; i++) { b[i] = i; } MPI_Send(&amp;b[0], 5, MPI_INT, procesDocelowy, 0, MPI_COMM_WORLD);int *res = new int[5]; MPI_Recv(res, 5, MPI_INT, 0, 0, MPI_COMM_WORLD, &amp;status); for(int i = 0; i &lt; 5;i++) { std::cout &lt;&lt; res[i] &lt;&lt; " "; } 我的过程仍然无法正常工作。
  • 那么你也不是很擅长 cmets :) 请把重要的 sn-ps 放在方便的地方(pastebin,问题)
猜你喜欢
  • 2018-05-02
  • 2018-11-11
  • 1970-01-01
  • 2012-10-18
  • 2011-08-19
  • 2014-08-11
  • 2014-09-17
相关资源
最近更新 更多