#ifndef lint static char vcid[] = "$Id: mpiov.c,v 1.26.1.29 1996/04/26 00:04:17 balay Exp $"; #endif /* Routines to compute overlapping regions of a parallel MPI matrix and to find submatrices that were shared across processors. */ #include "mpiaij.h" #include "src/inline/bitarray.h" static int MatIncreaseOverlap_MPIAIJ_Once(Mat, int, IS *); static int MatIncreaseOverlap_MPIAIJ_Local(Mat , int , char **,int*, int**); static int MatIncreaseOverlap_MPIAIJ_Receive(Mat , int, int **, int**, int* ); extern int MatGetRow_MPIAIJ(Mat,int,int*,int**,Scalar**); extern int MatRestoreRow_MPIAIJ(Mat,int,int*,int**,Scalar**); int MatIncreaseOverlap_MPIAIJ(Mat C, int imax, IS *is, int ov) { int i, ierr; if (ov < 0){ SETERRQ(1," MatIncreaseOverlap_MPIAIJ:Negative overlap specified\n");} for ( i=0; i is[1] mesg [2] = sizeof(is[1]); ----------- mesg [5] = 5 => is[5] mesg [6] = sizeof(is[5]); ----------- mesg [7] mesg [n] datas[1] ----------- mesg[n+1] mesg[m] data(is[5]) ----------- Notes: nrqs - no of requests sent (or to be sent out) nrqr - no of requests recieved (which have to be or which have been processed */ static int MatIncreaseOverlap_MPIAIJ_Once(Mat C, int imax, IS *is) { Mat_MPIAIJ *c = (Mat_MPIAIJ *) C->data; int **idx, *n, *w1, *w2, *w3, *w4, *rtable,**data,len,*idx_i; int size,rank,m,i,j,k,ierr,**rbuf,row,proc,nrqs,msz,**outdat,**ptr; int *ctr,*pa,tag,*tmp,bsz,nrqr,*isz,*isz1,**xdata,bsz1,**rbuf2; char **table; MPI_Comm comm; MPI_Request *s_waits1,*r_waits1,*s_waits2,*r_waits2; MPI_Status *s_status,*recv_status; comm = C->comm; tag = C->tag; size = c->size; rank = c->rank; m = c->M; len = (imax+1)*sizeof(int *) + (imax + m)*sizeof(int); idx = (int **) PetscMalloc(len); CHKPTRQ(idx); n = (int *) (idx + imax); rtable = n + imax; for ( i=0; i proc*/ for ( i=0,j=0; irowners[i+1]; for ( ; jdata; Mat A = c->A, B = c->B; Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data,*b = (Mat_SeqAIJ*)B->data; int start, end, val, max, rstart,cstart, ashift, bshift,*ai, *aj; int *bi, *bj, *garray, i, j, k, row,*data_i,isz_i; char *table_i; rstart = c->rstart; cstart = c->cstart; ashift = a->indexshift; ai = a->i; aj = a->j +ashift; bshift = b->indexshift; bi = b->i; bj = b->j +bshift; garray = c->garray; for ( i=0; idata; Mat A = c->A, B = c->B; Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data,*b = (Mat_SeqAIJ*)B->data; int rstart,cstart, ashift, bshift,*ai, *aj, *bi, *bj, *garray, i, j, k; int row,total_sz,ct, ct1, ct2, ct3,mem_estimate, oct2, l, start, end; int val, max1, max2, rank, m, no_malloc =0, *tmp, new_estimate, ctr; int *rbuf_i,kmax,rbuf_0; char *xtable; rank = c->rank; m = c->M; rstart = c->rstart; cstart = c->cstart; ashift = a->indexshift; ai = a->i; aj = a->j +ashift; bshift = b->indexshift; bi = b->i; bj = b->j +bshift; garray = c->garray; for ( i=0,ct=0,total_sz=0; inz +b->nz)/c->m; mem_estimate = 3*((total_sz > max1 ? total_sz : max1)+1); xdata[0] = (int *)PetscMalloc(mem_estimate*sizeof(int)); CHKPTRQ(xdata[0]); ++no_malloc; xtable = (char *)PetscMalloc((m/BITSPERBYTE+1)*sizeof(char)); CHKPTRQ(xtable); PetscMemzero(isz1,nrqr*sizeof(int)); ct3 = 0; for ( i=0; idata; Mat A = c->A,*submats = *submat; Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data, *b = (Mat_SeqAIJ*)c->B->data, *mat; int **irow,**icol,*nrow,*ncol,*w1,*w2,*w3,*w4,*rtable,start,end,size; int **sbuf1,**sbuf2, rank, m,i,j,k,l,ct1,ct2,ierr, **rbuf1,row,proc; int nrqs, msz, **ptr,index,*req_size,*ctr,*pa,tag,*tmp,tcol,bsz,nrqr; int **rbuf3,*req_source,**sbuf_aj, ashift, **rbuf2, max1,max2,**rmap; int **cmap,**lens,is_no,ncols,*cols,mat_i,*mat_j,tmp2,jmax,*irow_i; int len,ctr_j,*sbuf1_j,*sbuf_aj_i,*rbuf1_i,kmax,*cmap_i,*lens_i; int *rmap_i; MPI_Request *s_waits1,*r_waits1,*s_waits2,*r_waits2,*r_waits3; MPI_Request *r_waits4,*s_waits3,*s_waits4; MPI_Status *r_status1,*r_status2,*s_status1,*s_status3,*s_status2; MPI_Status *r_status3,*r_status4,*s_status4; MPI_Comm comm; Scalar **rbuf4, **sbuf_aa, *vals, *mat_a, *sbuf_aa_i; comm = C->comm; tag = C->tag; size = c->size; rank = c->rank; m = c->M; ashift = a->indexshift; /* Check if the col indices are sorted */ for ( i=0; i proc*/ for ( i=0,j=0; irowners[i+1]; for ( ; jA->data, *sB = (Mat_SeqAIJ*) c->B->data; int *sAi = sA->i, *sBi = sB->i, id, rstart = c->rstart; int *sbuf2_i; for ( i=0; ij, and send them off */ sbuf_aj = (int **)PetscMalloc((nrqr+1)*sizeof(int *));CHKPTRQ(sbuf_aj); for ( i=0,j=0; ii, *b_i = b->i, imark; int *cworkA, *cworkB, cstart = c->cstart, *bmap = c->garray; int *a_j = a->j, *b_j = b->j, shift = a->indexshift,ctmp, *t_cols; for ( i=0; ia, and send them off */ sbuf_aa = (Scalar **)PetscMalloc((nrqr+1)*sizeof(Scalar *));CHKPTRQ(sbuf_aa); for ( i=0,j=0; ii, *b_i = b->i, imark; int *cworkA, *cworkB, cstart = c->cstart, *bmap = c->garray; int *a_j = a->j, *b_j = b->j,shift = a->indexshift; Scalar *vworkA, *vworkB, *a_a = a->a, *b_a = b->a,*t_vals; for ( i=0; iN*sizeof(int); cmap = (int **)PetscMalloc(len); CHKPTRQ(cmap); cmap[0] = (int *)(cmap + ismax); PetscMemzero(cmap[0],(1+ismax*c->N)*sizeof(int)); for ( i=1; iN; } for ( i=0; iM*sizeof(int); rmap = (int **)PetscMalloc(len); CHKPTRQ(rmap); rmap[0] = (int *)(rmap + ismax); PetscMemzero(rmap[0],ismax*c->M*sizeof(int)); for ( i=1; iM;} for ( i=0; idata); if ((mat->m != nrow[i]) || (mat->n != ncol[i])) { SETERRQ(1,"MatGetSubmatrices_MPIAIJ:Cannot reuse matrix. wrong size"); } if (PetscMemcmp(mat->ilen,lens[i], mat->m *sizeof(int))) { SETERRQ(1,"MatGetSubmatrices_MPIAIJ:Cannot reuse matrix. wrong no of nonzeros"); } /* Initial matrix as if empty */ PetscMemzero(mat->ilen,mat->m*sizeof(int)); } } else { *submat = submats = (Mat *)PetscMalloc(ismax*sizeof(Mat)); CHKPTRQ(submats); for ( i=0; idata; imat_ilen = mat->ilen; imat_j = mat->j; imat_i = mat->i; imat_a = mat->a; cmap_i = cmap[i]; rmap_i = rmap[i]; irow_i = irow[i]; jmax = nrow[i]; for ( j=0; jdata; imat_ilen = mat->ilen; imat_j = mat->j; imat_i = mat->i; imat_a = mat->a; max1 = sbuf1_i[2*j]; for ( k=0; k