MPI_Allgather的问题
我尝试使用MPI_Allgather的问题,mpi,Mpi,我尝试使用MPI\u Allgather的行和列广播在MPI中实现矩阵乘法。虽然注释掉的代码部分工作正常,但另一部分(在它下面)不工作(即给出信号-5,mpi进程被终止)。需要帮忙吗? 谢谢 #include <stdlib.h> #include <string.h> #include "mpi.h" #define N 4 // NxN is origininal(big) matrices size to multiply int SqrtRoot(int
MPI\u Allgather
的行和列广播在MPI中实现矩阵乘法。虽然注释掉的代码部分工作正常,但另一部分(在它下面)不工作(即给出信号-5,mpi进程被终止)。需要帮忙吗?
谢谢
#include <stdlib.h>
#include <string.h>
#include "mpi.h"
#define N 4 // NxN is origininal(big) matrices size to multiply
int SqrtRoot(int a)
{
switch(a)
{
case 1: return 1 ;
case 4: return 2;
case 9: return 3;
case 16: return 4;
default: return -1;
}
}
int main( argc, argv )
int argc;
char **argv;
{
int myID, p;
double t1,t2;
double *RowwiseA, *ColWiseB; // 1D array of size N*N/sqrt(p) to hold the 2D data of
// processors own datatogether with data of its rowwise neighbours
double* MyResult; // my result of size of nxn(n = N/p) is also stored 1D
int mydatastartindex;
int i,j,n;
MPI_Comm MyRowPartners, MyColPartners;
MPI_Init( &argc, &argv );
MPI_Comm_size( MPI_COMM_WORLD, &p );
MPI_Comm_rank( MPI_COMM_WORLD, &myID );
MPI_Comm_split(MPI_COMM_WORLD,myID/SqrtRoot(p), myID,&MyRowPartners);
MPI_Comm_split(MPI_COMM_WORLD,myID%SqrtRoot(p), myID,&MyColPartners);
int DataPerProcess = N*N/(p);
RowwiseA = (double*) malloc(N*N/SqrtRoot(p) * sizeof(double));
ColWiseB = (double*) malloc(N*N/SqrtRoot(p) * sizeof(double));
MyResult = (double*) malloc(N*N/p * sizeof(double));
mydatastartindex = myID * DataPerProcess;
n = SqrtRoot(N*N/p); // one deimension of local square matrix of nxn
// initialize my dat
for(i = 0; i < n; i++){
for(j = 0; j < n; j++) {
RowwiseA [mydatastartindex + i*n + j] = (i + j) * (myID + 1);
ColWiseB [mydatastartindex + i*n + j] = (i - j) * (myID + 1);
}
}
// ------------ THIS ONE WORKS ------------------
//double* sum = (double*)malloc(4*sizeof(double));
//
//double mydata = myID*1.0f;
//MPI_Allgather(
// &mydata ,
// 1,
// MPI_DOUBLE,
// sum,
// 1,
// MPI_DOUBLE,
// MyRowPartners
// );
//
//--------------------------------------------------
//--------THIS ONE DOES NOT WORK----------------------
MPI_Allgather(
&RowwiseA[mydatastartindex],
DataPerProcess,
MPI_DOUBLE,
RowwiseA ,
DataPerProcess,
MPI_DOUBLE,
MyRowPartners
);
//-----------------------------------------------------
return 0;
}
#包括
#包括
#包括“mpi.h”
#定义n4//NxN是要乘以的原始(大)矩阵大小
intsqrtroot(inta)
{
开关(a)
{
案例1:返回1;
案例4:返回2;
案例9:返回3;
案例16:返回4;
默认值:return-1;
}
}
int main(argc、argv)
int-argc;
字符**argv;
{
int-myID,p;
双t1,t2;
double*RowwiseA,*ColWiseB;//N*N/sqrt(p)大小的1D数组,用于保存
//处理器拥有数据及其行邻居的数据
double*MyResult;//我的大小为nxn(n=n/p)的结果也存储为1D
int-mydatastartindex;
inti,j,n;
MPI_通信MyRowPartners、MyColPartners;
MPI_Init(&argc,&argv);
MPI通信大小(MPI通信世界和p);
MPI通信等级(MPI通信世界和myID);
MPI_Comm_split(MPI_Comm_WORLD、myID/SqrtRoot(p)、myID和MyRowPartners);
MPI_Comm_split(MPI_Comm_WORLD,myID%SqrtRoot(p),myID和myclpartners);
int DataPerProcess=N*N/(p);
RowwiseA=(双*)malloc(N*N/SqrtRoot(p)*sizeof(双));
ColWiseB=(double*)malloc(N*N/SqrtRoot(p)*sizeof(double));
MyResult=(双精度*)malloc(N*N/p*sizeof(双精度));
mydatastartindex=myID*DataPerProcess;
n=SqrtRoot(n*n/p);//nxn的局部方阵的一次降维
//初始化我的dat
对于(i=0;i
我发现了这个bug。我应该在MyRowPartners中使用新的排名,而不是myID
在MPI_ALLgather和矩阵索引中。不过,谢谢。当您在StackOverflow上回答自己的问题时,几天后您仍然可以将答案标记为正确。我鼓励你这样做,尽管这个问题可能会被关闭,因为答案不太可能帮助其他人。这个问题与你的情况非常相关。