[英]MPI send and receive large data to self
I try to send and receive a large array to self-rank using MPI.我尝试使用 MPI 发送和接收一个大型数组以进行自我排序。 The code works well for small arrays (array size <10000) when I further increase the array size to 100000, it will deadlock.
当我将数组大小进一步增加到 100000 时,该代码适用于小型 arrays(数组大小<10000),它会死锁。 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我通过以下方式编译代码:mpicc
command for the run: mpirun -np 1./运行命令:mpirun -np 1./
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
and MPI_Irecv
.MPI_Isend
和MPI_Irecv
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.