我对 MPI 很陌生。我正在尝试使用进程运行以下MPI_Sendrecv
程序p
。每个进程都有 4 个长度n
为 double 类型的数组(A、B、C、D)。现在这就是我想要做的for i=0,...,p-1
:
进程 i 在进程 (i+1)%p 中将 B 发送给 A
进程 i 在进程 (i-1) 中将 C 发送给 D%p
进程 i 从 (i-1)%p 接收 B 到 A
进程 i 从 (i+1)%p 接收 C 到 D
我有以下代码:
#include<stdio.h>
#include<mpi.h>
#include<math.h>
main(int argc, char *argv[]){
/*Initialize the MPI environment */
/******************************************/
MPI_Init(&argc, &argv);
/*variables that will be used for sending*/
/*and receiving messages. */
/*****************************************/
int n=3;
int p;
int myRank;
int comm;
double A[n];
double C[n];
double B[n];
double D[n];
/*Get the number of processors and their */
/*rank. */
/******************************************/
comm = MPI_COMM_WORLD;
MPI_Comm_size(comm, &p);
MPI_Comm_rank(comm, &myRank);
/*Initialize the arrays with the given */
/*initial values. */
/******************************************/
for(int i=0; i<n; i++){
A[i]=0; D[i]=0;
B[i]=-myRank; C[i]=myRank;
}
int left = myRank-1; int right = myRank+1;
if(left<0){
left = p-1;
}
if(right==p){
right = 0;
}
MPI_Sendrecv(&B,n,MPI_DOUBLE,right,1231,
&A,n,MPI_DOUBLE,left,1231,
comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(&C,n,MPI_DOUBLE,left,1232,
&D,n,MPI_DOUBLE,right,1232,
comm,MPI_STATUS_IGNORE);
/*Close the MPI environment. */
/******************************************/
MPI_Finalize();
/*Print the updated values. */
for(int i=0; i<p; i++){
printf("\n");
for(int j=0; j<n; j++){
if(myRank==i){
printf("rank= %d, Updated Values = A[%d]= %f, B[%d]= %f,
C[%d]= %f, D[%d]= %f\n", myRank,j,A[j],j,B[j],j,C[j],j,D[j]);
}
}
}
}
但是,每当我运行此代码时,我都会得到以下信息:
vincent% mpicc -o hmw2Prob1 hmw2Prob1.c
vincent% mpirun -np 4 hmw2Prob1
2: signal 11 received, exiting..
2: Signal sent from unknown source.
3: signal 11 received, exiting..
3: Signal sent from unknown source.
0: signal 11 received, exiting..
0: Signal sent from unknown source.
1: signal 11 received, exiting..
1: Signal sent from unknown source.
vincent%
我在这里阅读了几篇文章并尝试了一些想法,但到目前为止没有任何效果。我将不胜感激您能提供的任何帮助。