Segmentation error of MPI program

Post here if you have a question about LAPACK or ScaLAPACK algorithm or data format

Segmentation error of MPI program

Postby MatMat » Tue Apr 15, 2014 5:33 am

I try to do a mpi programm using pdgemm. However I have an initialisation problem of my MPI.
I don't understand how I can initialise argc and argv in this line MPI_Init(&argc, &argv);
It should be by my linux command but I don't find what is it expected.

I compile my programm with:
mpicc t.c -lgslcblas -lscalapack-openmpi -lblacs-openmpi -lblacsCinit-openmpi

Thanks
MatMat
 
Posts: 2
Joined: Tue Apr 15, 2014 5:26 am

Re: Segmentation error of MPI program

Postby MatMat » Tue Apr 15, 2014 11:53 am

The problem is solved :)

But there is some errors:
Valgrind say : Syscall param sched_setaffinity(mask) points to unaddressable byte(s)
I searched on different forum but i don't find an answer.
This my code :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cblas.h>
#include <mpi.h>

typedef struct{
double* tab;
int nrow;
int ncol;
}Matrix;


typedef struct{
int ictxt;
int nprow;
int npcol;
int myrow;
int mycol;
int nb;
int info;
int itemp;
int myrank_mpi;
int nprocs_mpi;
int Zero;
int One;
}InfoParrall;

/*! External procedures prototypes from CBLACS: */
extern void Cblacs_pinfo(int *mypnum, int *nprocs);
extern void Cblacs_get(int ConTxt, int what, int *val);
extern void Cblacs_gridinit(int *ConTxt, char *order, int nprow, int npcol);
extern void Cblacs_gridinfo(int ConTxt, int *nprow, int *npcol,
int *myrow, int *mycol);
extern void Cblacs_gridexit(int ConTxt);
extern void Cblacs_exit(int NotDone);
double* multMM(Matrix A, Matrix B, InfoParrall inf);
double* multVV(Matrix A, Matrix B, InfoParrall inf);
double* rankKK(Matrix A,Matrix X,InfoParrall inf);
double* multV(double* AA, double* X,int M, int nb,int mycol, int myrow, int ZERO,int ONE, int nprow, int npcol,int myrank_mpi,int info,int ictxt,int my,int Acol,int Arow,int Xrow,int Xcol);
double* multM(double* AA, double* X,int M, int nb,int mycol, int myrow, int ZERO,int ONE, int nprow, int npcol,int myrank_mpi,int info,int ictxt,int my,int Acol,int Arow,int Xrow,int Xcol);
double* rankK(double* AA, double* X,int M, int nb,int mycol, int myrow, int ZERO,int ONE, int nprow, int npcol,int myrank_mpi,int info,int ictxt,int my,int Acol,int Arow,int Xrow,int Xcol);
void initialisation(InfoParrall* inf);
// Method 1: matrix-vector multiplication A * v
double* multVV(Matrix A, Matrix B, InfoParrall inf){
return multV(A.tab,B.tab,5,inf.nb,inf.mycol,inf.myrow,0,1,inf.nprow,inf.npcol,inf.myrank_mpi,inf.info,inf.ictxt,A.nrow,A.ncol,A.nrow,B.nrow,B.ncol);
}

double* multV(double* AA, double* X,int M, int nb,int mycol, int myrow, int ZERO,int ONE, int nprow, int npcol,int myrank_mpi,int info,int ictxt,int my,int Acol,int Arow,int Xrow,int Xcol){
int descA[9],descx[9],descy[9];
descinit_(descA, &M, &M, &nb, &nb, &ZERO, &ZERO, &ictxt, &Acol, &info);
descinit_(descx, &M, &ONE, &nb, &ONE, &ZERO, &ZERO, &ictxt, &Xrow, &info);
descinit_(descy, &M, &ONE, &nb, &ONE, &ZERO, &ZERO, &ictxt, &my, &info);
double *y = (double*) calloc(my,sizeof(double));
double alpha = 1.0; double beta = 0.0;
pdgemv_("N",&M,&M,&alpha,AA,AA,Acol,descA,X,Xrow,Xcol,descx,&ONE,&beta,y,Arow,&ONE,descy,&ONE);
return y;
}

//Method 2: matrix-vector multiplication A * v
double* multMM(Matrix A, Matrix B, InfoParrall inf){
return multM(A.tab,B.tab,5,inf.nb,inf.mycol,inf.myrow,inf.Zero,inf.One,inf.nprow,inf.npcol,inf.myrank_mpi,inf.info,inf.ictxt,A.nrow,A.ncol,A.nrow,B.nrow,B.ncol);
}

double* multM(double* AA, double* X,int M, int nb,int mycol, int myrow, int ZERO,int ONE, int nprow, int npcol,int myrank_mpi,int info,int ictxt,int my,int Acol,int Arow,int Xrow,int Xcol){
int descA[10],descx[10],descy[10];
int i=0;
for(i=0;i<10;++i){
descA[i]=0;
descx[i]=0;
descy[i]=0;
}
descinit_(descA, &M, &M, &nb, &nb, &ZERO, &ZERO, &ictxt, &Acol, &info);
descinit_(descx, &M, &ONE, &nb, &ONE, &ZERO, &ZERO, &ictxt, &Xrow, &info);
descinit_(descy, &M, &ONE, &nb, &ONE, &ZERO, &ZERO, &ictxt, &my, &info);

double *y = (double*) malloc(M*M*sizeof(double));
double alpha = 1.0; double beta = 0.0;
pdgemm_("N","N",&M,&M,&Acol,&alpha,AA,Arow,Acol,descA,X,Xrow,Xcol,descx,&beta,y,Arow,Acol,descy);
return y;
}



// Method 3 :rank-k updates C = C + u * v^T
double* rankK(double* AA, double* X,int M, int nb,int mycol, int myrow, int ZERO,int ONE, int nprow, int npcol,int myrank_mpi,int info,int ictxt,int my,int Acol,int Arow,int Xrow,int Xcol){
int descA[9],descx[9],descy[9];
descinit_(descA, &M, &M, &nb, &nb, &ZERO, &ZERO, &ictxt, &Acol, &info);
descinit_(descx, &M, &ONE, &nb, &ONE, &ZERO, &ZERO, &ictxt, &Xrow, &info);
descinit_(descy, &M, &ONE, &nb, &ONE, &ZERO, &ZERO, &ictxt, &my, &info);

double *y = (double*) malloc(M*M*sizeof(double));
double alpha = 1.0; double beta = 0.0;
pdgemm_("N","T",&M,&M,&Acol,&alpha,AA,Arow,Acol,descA,X,Xrow,Xcol,descx,&beta,y,Arow,Acol,descy);
return y;
}

double* rankKK(Matrix A,Matrix X,InfoParrall inf){
return rankK(A.tab,X.tab,5,inf.nb,inf.mycol,inf.myrow,inf.Zero,inf.One,inf.nprow,inf.npcol,inf.myrank_mpi,inf.info,inf.ictxt,A.ncol,A.ncol,A.nrow,X.nrow,X.ncol);
}

void initialisation(InfoParrall* inf){
inf->ictxt=0;
inf->nprow=0;
inf->npcol=0;
inf->myrow=0;
inf->mycol=0;
inf->nb=0;
inf->info=0;
inf->itemp=0;
inf->myrank_mpi=0;
inf->nprocs_mpi=0;
inf->Zero=0;
inf->One=1;
}


int main(int argc, char **argv) {
/************ MPI ***************************/
int myrank_mpi=0;
int nprocs_mpi=0;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank_mpi);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs_mpi);
/************ BLACS ***************************/
InfoParrall inf;
initialisation (&inf);
int ZERO=0,ONE=1;
inf.Zero=0;
inf.One=1;
inf.nprow = 2; inf.npcol = 2; inf.nb =2;
Cblacs_pinfo( &(inf.myrank_mpi), &(inf.nprocs_mpi) ) ;
Cblacs_get( -1, 0, &(inf.ictxt) );
Cblacs_gridinit( &(inf.ictxt), "Row", inf.nprow, inf.npcol );
Cblacs_gridinfo( inf.ictxt, &(inf.nprow), &(inf.npcol), &(inf.myrow), &(inf.mycol) );

// Initialisation de matrix
int M=5;
int i,j;
Matrix AA;
AA.tab = (double*) malloc(M*M*sizeof(double));
for(i=0;i<M;i++){
for(j=0;j<M;j++){
AA.tab[i*M+j]=i;
}
}
//matrix X
Matrix X;
X.tab = (double*) malloc(M*M*sizeof(double));
for(i=0;i<M;i++){
for(j=0;j<M;j++){
X.tab[i*M+j]=1;
}
}

AA.nrow = numroc_( &M, &(inf.nb), &(inf.myrow), &ZERO, &(inf.nprow) );
AA.ncol = numroc_( &M, &(inf.nb), &(inf.mycol), &ZERO, &(inf.npcol) );
X.nrow = numroc_( &M, &(inf.nb), &(inf.myrow), &ZERO, &(inf.nprow) );
X.ncol=numroc_( &M, &(inf.nb), &(inf.mycol), &ZERO, &(inf.npcol) );
int my = numroc_( &M, &(inf.nb), &(inf.myrow), &ZERO, &(inf.nprow) );
double* y=(double*) malloc(M*M*sizeof(double));
y=multMM(AA,X,inf);

Cblacs_barrier((inf.ictxt),"A");


for(i=0;i<my;i++){
printf("rank=%d %.2f \n", (inf.myrank_mpi),y[i]);
}
free(AA.tab);
free(X.tab);
Cblacs_gridexit( 0 );
MPI_Finalize();
return 0;
}

MatMat
 
Posts: 2
Joined: Tue Apr 15, 2014 5:26 am


Return to Algorithm / Data

Who is online

Users browsing this forum: No registered users and 3 guests