mpi - Trouble with MPI_Allgather -
i trying implement matrix matrix multiplication in mpi using rowwise , columnwise broadcast mpi_allgather
. although commented out code part works well, other one(below it) not work(i.e. gives signal -5 , mpi process killed). please? thanks
#include <stdlib.h> #include <string.h> #include "mpi.h" #define n 4 // nxn origininal(big) matrices size 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) hold 2d data of // processors own datatogether data of rowwise neighbours double* myresult; // result of size of nxn(n = n/p) 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); // 1 deimension of local square matrix of nxn // initialize dat for(i = 0; < 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); } } // ------------ 1 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 1 not work---------------------- mpi_allgather( &rowwisea[mydatastartindex], dataperprocess, mpi_double, rowwisea , dataperprocess, mpi_double, myrowpartners ); //----------------------------------------------------- return 0; }
i found bug. should use new rank inside myrowpartners instead of myid in mpi_allgather , in matrix indexes. though..
Comments
Post a Comment