-------- Forwarded Message -------- Subject: <sub.> Request to debug the code Date: Sat, 18 Nov 2017 04:50:42 +0530 From: Nitu <yalamanchi.nit...@students.iiit.ac.in> To: users@lists.open-mpi.orgI've been trying to find the reason for the error,but unable to do so.It is showing Signal: segmentation fault and Signal code: Address not
mapped.Please help me debug the code. Thanks,
#include <mpi.h> #include <stdio.h> #include <stdlib.h> /*typedef struct sl{ int step; int v; struct sl *next; }sl;*/ typedef struct list{ int v; struct list *next; }list; int main() { MPI_Init(NULL,NULL); int *p,n,l,m,i,s=1,k,first,last,kmax,j,y,z; int A[8][8]={{0,1,0,0,0,1,1,0},{1,0,1,0,0,0,1,1},{0,1,0,1,0,0,0,0},{0,0,1,0,1,0,0,1},{0,0,0,1,0,1,1,1},{1,0,0,0,1,0,0,0},{1,1,0,0,1,0,0,1},{0,1,0,1,1,0,1,0}}; int world_size; MPI_Comm_size(MPI_COMM_WORLD, &world_size); int world_rank; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); n=8; MPI_Bcast(&n,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&s,1,MPI_INT,0,MPI_COMM_WORLD); if(world_rank==0) { int max=0; p=&A[0][0]; l=n/(world_size-1); m=n%(world_size-1); for(i=1;i<world_size;i++) { int k; if(i<=m) { MPI_Send(p,(l+1)*n,MPI_INT,i,0,MPI_COMM_WORLD); p=p+(l+1)*n; } else { MPI_Send(p,l*n,MPI_INT,i,0,MPI_COMM_WORLD); p=p+l*n; } MPI_Recv(&k,1,MPI_INT,i,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); if(k>max) max=k; } for(i=1;i<world_size;i++) MPI_Send(&max,1,MPI_INT,i,0,MPI_COMM_WORLD); } else { int *B,len,count,*U=(int *)malloc((n+1)*sizeof(int)),*lc=(int *)malloc((n+1)*sizeof(int)); int Fbd[100][100]; //int *f=(int *)malloc((world_size-1)*(kmax-1)*sizeof(int)); int send_step[100][100]; int send_v[100][100]; //int ll[world_size-1]; //list *sched=(list *)malloc((world_size-1)*(kmax-1)*sizeof(list)); //sl* ll[100]; //pointers //list *ls[kmax][world_size-1]; l=n/(world_size-1); m=n%(world_size-1); for(i=0;i<=n;i++) { U[i]=0; lc[i]=0; for(j=0;j<=n;j++) Fbd[i][j]=0; } for(i=0;i<world_size-1;i++) { for(j=0;j<=100;j++) { send_step[i][j]=0; send_v[i][j]=0; } } if(world_rank<=m) { B=(int *)malloc((l+1)*n*sizeof(int)); MPI_Recv(B,(l+1)*n,MPI_INT,0,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); len=(l+1)*n; first=(l+1)*(world_rank-1); last=first+l; } else { B=(int *)malloc(l*n*sizeof(int)); MPI_Recv(B,l*n,MPI_INT,0,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); len=l*n; first=(l+1)*m+l*(world_rank-m-1); last=first+l-1; } //printf("%d ",world_rank); i=0; while(i<len) { //printf("a"); int temp,proc,v,flag=-1; if(i%n>last || i%n<first) { if(B[i]==1) { temp=i%n; if(temp<(l+1)*m) proc=temp/(l+1)+1; else proc=(temp-m)/l+1; v=first+i/n; if(flag!=v) { flag=v; U[0]++; U[U[0]]=v; } if(U[0]%s==0) k=U[0]/s; else k=U[0]/s+1; send_step[proc-1][0]++; send_v[proc-1][0]++; send_step[proc-1][send_v[proc-1][0]]=k; send_v[proc-1][send_v[proc-1][0]]=v; if(proc<=m) i=(i/n)*n+(l+1)*proc; else i=(i/n)*n+m+l*proc; } else i++; } else i++; } MPI_Send(U,1,MPI_INT,0,0,MPI_COMM_WORLD); MPI_Recv(&kmax,1,MPI_INT,0,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //printf("%d",k); //int *f=(int *)malloc((world_size-1)*(kmax)*sizeof(int)); int sched[100][100][100]; //while() for(i=0;i<world_size-1;i++) for(j=0;j<kmax;j++) { sched[j][i][0]=0; } for(i=1;i<world_size;i++) { count=0; if(i!=world_rank) { MPI_Send(&send_step[i-1][0],1,MPI_INT,i,0,MPI_COMM_WORLD); while(count<send_step[i-1][0]) { count++; int temp[2]; temp[0]=send_step[i-1][count]; temp[1]=send_v[i-1][count]; MPI_Send(&temp,2,MPI_INT,i,0,MPI_COMM_WORLD); } } } for(i=1;i<world_size;i++) { count=0; if(i!=world_rank) { int x; MPI_Recv(&x,1,MPI_INT,i,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); while(count<x) { count++; int temp[2]; MPI_Recv(&temp,2,MPI_INT,i,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //printf("%d ",temp[0]); //printf("%d\n",temp[1]); sched[temp[0]-1][i-1][0]++; sched[temp[0]-1][i-1][sched[temp[0]-1][i-1][0]]=temp[1]; } } } //working fine for(i=0;i<kmax;i++) { int *num=(int *)malloc((world_size-1)*sizeof(int)); if(i<kmax-1) for(j=0;j<world_size-1;j++) { if(j!=world_rank-1) { MPI_Send(&sched[i+1][j][0],1,MPI_INT,j+1,0,MPI_COMM_WORLD); count=0; while(count<sched[i+1][j][0]) { count++; int vertex=sched[i+1][j][count]; MPI_Send(&vertex,1,MPI_INT,j+1,0,MPI_COMM_WORLD); int *F=(int *)malloc((n+1)*sizeof(int)),k,l; for(k=0;k<=n;k++) F[k]=0; for(k=1;k<=U[0];k++) { if((*(B+vertex+(U[k]-first)*n))==1) { for(l=0;l<n;l++) { if(*(B+(U[k]-first)*n+l)==1 && lc[l]!=0) { F[0]++; F[F[0]]=lc[l]; } } } } MPI_Send(F,1,MPI_INT,j+1,0,MPI_COMM_WORLD); if(F[0]!=0) MPI_Send(F+1,F[0],MPI_INT,j+1,0,MPI_COMM_WORLD); free(F); } } } if(i>0) for(j=0;j<world_size-1;j++) { if(j!=world_rank-1) { int it,vertex,x; MPI_Recv(num+j,1,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); for(it=0;it<num[j];it++) { MPI_Recv(&vertex,1,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); MPI_Recv(&x,1,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); int *F=(int *)malloc(x*sizeof(int)),k,y; if(x!=0) MPI_Recv(F,x,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); for(k=0;k<x;k++) { Fbd[vertex][F[k]]=1; } } } } if(i<k) { for(l=i*s+1;(l<=i*s+s && l<=U[0]);l++) { for(y=0;y<=last-first;y++) { if(*(B+(U[l]-first)*n+y+first)==1) { if(lc[y+first]!=0) Fbd[U[l]][lc[y+first]]=1; for(z=0;z<n;z++) if(*(B+y*n+z)==1 && lc[z]!=0) { Fbd[U[l]][lc[z]]=1; } } } for(y=1;y<=n;y++) { if(Fbd[U[l]][y]!=0) { lc[U[l]]=y; break; } } } } for(j=0;j<world_size-1;j++) { if(j!=world_rank-1) { int *temp1=(int *)malloc(sched[i][j][0]*sizeof(int)); int count2; MPI_Send(&sched[i][j][0],1,MPI_INT,j+1,0,MPI_COMM_WORLD); //int *temp1=(int *)malloc(sched[i][j][0]*sizeof(int)); //MPI_Send(&sched[i][j][0],1,MPI_INT,j+1,0,MPI_COMM_WORLD); if(sched[i][j][0]!=0){ MPI_Send(&sched[i][j][1],sched[i][j][0],MPI_INT,j+1,0,MPI_COMM_WORLD); } //Error from here //MPI_Recv(&count2,1,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //Error from here if(sched[i][j][0]!=0) { MPI_Recv(temp1,sched[i][j][0],MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); } //int y; for(y=1;y<=sched[i][j][0];y++) { lc[sched[i][j][y]]=*(temp1+y-1); } } } for(j=0;j<world_size-1;j++) { if(j!=world_rank-1) { MPI_Recv(&count,1,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //printf("%d\n",count); //int count; //MPI_Recv(&count,1,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //printf("%d\n",count); int *temp2=(int *)malloc(count*sizeof(int)); if(count!=0){ MPI_Recv(temp2,count,MPI_INT,j+1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); } //int y; for(y=0;y<count;y++) { temp2[y]=lc[temp2[y]]; } //printf("%d\n",count); //Error from here //MPI_Send(&count,1,MPI_INT,j+1,0,MPI_COMM_WORLD); if(count!=0){ MPI_Send(temp2,count,MPI_INT,j+1,0,MPI_COMM_WORLD); } } } } //for(i=0;i<n;i++) // printf("%d",lc[n-1]); } MPI_Finalize(); return 0; }
_______________________________________________ users mailing list users@lists.open-mpi.org https://lists.open-mpi.org/mailman/listinfo/users