MPI将大量数据发送给自我
我尝试使用MPI发送并接收一个大型阵列。该代码适用于小阵列(阵列尺寸< 10000)时,当我将阵列大小进一步增加到100000时,它将死去。 Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Status stat;
int N = 100000;
// Allocate memory for A on CPU
double *A = (double*)malloc(N*sizeof(double));
double *B = (double*)malloc(N*sizeof(double));
// Initialize all elements of A to 0.0
for(int i=0; i<N; i++){
A[i] = 0.0;
}
int tag1 = 10;
int tag2 = 20;
//printf("rank=%d",rank);
MPI_Send(A, N, MPI_DOUBLE, 0, tag1, MPI_COMM_WORLD);
MPI_Recv(B, N, MPI_DOUBLE, 0, tag1, MPI_COMM_WORLD, &stat);
MPI_Finalize();
return 0;
}
I compile the code by: mpicc
运行的命令:Mpirun -NP 1 ./
I try to send and receive a large array to self-rank using MPI. The code works well for small arrays (array size <10000) when I further increase the array size to 100000, it will deadlock. Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Status stat;
int N = 100000;
// Allocate memory for A on CPU
double *A = (double*)malloc(N*sizeof(double));
double *B = (double*)malloc(N*sizeof(double));
// Initialize all elements of A to 0.0
for(int i=0; i<N; i++){
A[i] = 0.0;
}
int tag1 = 10;
int tag2 = 20;
//printf("rank=%d",rank);
MPI_Send(A, N, MPI_DOUBLE, 0, tag1, MPI_COMM_WORLD);
MPI_Recv(B, N, MPI_DOUBLE, 0, tag1, MPI_COMM_WORLD, &stat);
MPI_Finalize();
return 0;
}
I compile the code by: mpicc
command for the run: mpirun -np 1 ./
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是发送和接收的定义:它们正在阻止。在发送发送后,发送后的声明将不会执行。
mpi_isend
和mpi_irecv
。That's the definition of send and receive: they are blocking. The statement after the send will not execute until the send has been successfully completed.
MPI_Isend
andMPI_Irecv
.