/*$Id: sbaijov.c,v 1.65 2001/08/06 21:15:42 bsmith Exp $*/ /* Routines to compute overlapping regions of a parallel MPI matrix. Used for finding submatrices that were shared across processors. */ #include "src/mat/impls/sbaij/mpi/mpisbaij.h" #include "petscbt.h" static int MatIncreaseOverlap_MPISBAIJ_Once(Mat,int,IS *); static int MatIncreaseOverlap_MPISBAIJ_Local(Mat,int *,int,int **,PetscBT*); /* this function is sasme as MatCompressIndicesGeneral_MPIBAIJ -- should be removed! */ #undef __FUNCT__ #define __FUNCT__ "MatCompressIndicesGeneral_MPISBAIJ" static int MatCompressIndicesGeneral_MPISBAIJ(Mat C,int imax,const IS is_in[],IS is_out[]) { Mat_MPISBAIJ *baij = (Mat_MPISBAIJ*)C->data; int ierr,isz,bs = baij->bs,n,i,j,*idx,ival; #if defined (PETSC_USE_CTABLE) PetscTable gid1_lid1; int tt, gid1, *nidx; PetscTablePosition tpos; #else int Nbs,*nidx; PetscBT table; #endif PetscFunctionBegin; /* printf(" ...MatCompressIndicesGeneral_MPISBAIJ is called ...\n"); */ #if defined (PETSC_USE_CTABLE) ierr = PetscTableCreate(baij->mbs,&gid1_lid1);CHKERRQ(ierr); #else Nbs = baij->Nbs; ierr = PetscMalloc((Nbs+1)*sizeof(int),&nidx);CHKERRQ(ierr); ierr = PetscBTCreate(Nbs,table);CHKERRQ(ierr); #endif for (i=0; iNbs) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"index greater than mat-dim"); if(!PetscBTLookupSet(table,ival)) { nidx[isz++] = ival;} #endif } ierr = ISRestoreIndices(is_in[i],&idx);CHKERRQ(ierr); #if defined (PETSC_USE_CTABLE) ierr = PetscMalloc((isz+1)*sizeof(int),&nidx);CHKERRQ(ierr); ierr = PetscTableGetHeadPosition(gid1_lid1,&tpos);CHKERRQ(ierr); j = 0; while (tpos) { ierr = PetscTableGetNext(gid1_lid1,&tpos,&gid1,&tt);CHKERRQ(ierr); if (tt-- > isz) { SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"index greater than array-dim"); } nidx[tt] = gid1 - 1; j++; } if (j != isz) { SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"table error: jj != isz"); } ierr = ISCreateGeneral(PETSC_COMM_SELF,isz,nidx,(is_out+i));CHKERRQ(ierr); ierr = PetscFree(nidx);CHKERRQ(ierr); #else ierr = ISCreateGeneral(PETSC_COMM_SELF,isz,nidx,(is_out+i));CHKERRQ(ierr); #endif } #if defined (PETSC_USE_CTABLE) ierr = PetscTableDelete(gid1_lid1);CHKERRQ(ierr); #else ierr = PetscBTDestroy(table);CHKERRQ(ierr); ierr = PetscFree(nidx);CHKERRQ(ierr); #endif PetscFunctionReturn(0); } #undef __FUNCT__ #define __FUNCT__ "MatExpandIndices_MPISBAIJ" static int MatExpandIndices_MPISBAIJ(Mat C,int imax,const IS is_in[],IS is_out[]) { Mat_MPISBAIJ *baij = (Mat_MPISBAIJ*)C->data; int ierr,bs = baij->bs,n,i,j,k,*idx,*nidx; #if defined (PETSC_USE_CTABLE) int maxsz; #else int Nbs = baij->Nbs; #endif PetscFunctionBegin; /* printf(" ... MatExpandIndices_MPISBAIJ is called ...\n"); */ #if defined (PETSC_USE_CTABLE) /* Now check max size */ for (i=0,maxsz=0; i maxsz) maxsz = n*bs; } ierr = PetscMalloc((maxsz+1)*sizeof(int),&nidx);CHKERRQ(ierr); #else ierr = PetscMalloc((Nbs*bs+1)*sizeof(int),&nidx);CHKERRQ(ierr); #endif for (i=0; idata; int len,*idx_i,isz,col,*n,*data1,*data2,*data2_i,*data,*data_i, size,rank,Mbs,i,j,k,ierr,nrqs,*odata1,*odata2, tag1,tag2,flag,proc_id,**odata2_ptr; char *t_p; MPI_Comm comm; MPI_Request *s_waits,r_req; MPI_Status *s_status,r_status; PetscBT *table; /* mark indices of this processor's is[] */ PetscBT table_i; PetscBT otable; /* mark indices of other processors' is[] */ PetscFunctionBegin; comm = C->comm; size = c->size; rank = c->rank; Mbs = c->Mbs; ierr = PetscObjectGetNewTag((PetscObject)C,&tag1);CHKERRQ(ierr); ierr = PetscObjectGetNewTag((PetscObject)C,&tag2);CHKERRQ(ierr); /* create tables for marking indices */ len = is_max*sizeof(PetscBT) + (Mbs/PETSC_BITS_PER_BYTE+1)*is_max*sizeof(char) + 1; ierr = PetscMalloc(len,&table);CHKERRQ(ierr); t_p = (char *)(table + is_max); for (i=0; idata; Mat_SeqSBAIJ *a = (Mat_SeqSBAIJ*)(c->A)->data; Mat_SeqBAIJ *b = (Mat_SeqBAIJ*)(c->B)->data; int ierr,row,mbs,Mbs,*nidx,*nidx_i,col,isz,isz0,*ai,*aj,*bi,*bj,*garray,rstart,l; int a_start,a_end,b_start,b_end,i,j,k,is_max,*idx_i,n; PetscBT table0; /* mark the indices of input is[] for look up */ PetscBT table_i; /* poits to i-th table. When whose=OTHER, a single table is used for all is[] */ PetscFunctionBegin; Mbs = c->Mbs; mbs = a->mbs; ai = a->i; aj = a->j; bi = b->i; bj = b->j; garray = c->garray; rstart = c->rstart; is_max = data[0]; ierr = PetscBTCreate(Mbs,table0);CHKERRQ(ierr); ierr = PetscMalloc((1+is_max*(Mbs+1))*sizeof(int),&nidx);CHKERRQ(ierr); nidx[0] = is_max; idx_i = data + is_max + 1; /* ptr to input is[0] array */ nidx_i = nidx + is_max + 1; /* ptr to output is[0] array */ for (i=0; i 0) { isz0 = 0; for (j=0; j= Mbs) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"index col %d >= Mbs %d",col,Mbs); if(!PetscBTLookupSet(table_i,col)) { ierr = PetscBTSet(table0,col);CHKERRQ(ierr); if (whose == MINE) {nidx_i[isz0] = col;} isz0++; } } if (whose == MINE) {isz = isz0;} k = 0; /* no. of indices from input is[i] that have been examined */ for (row=0; row= isz0) break; /* for (row=0; row 0) */ if (i < is_max - 1){ idx_i += n; /* ptr to input is[i+1] array */ nidx_i += isz; /* ptr to output is[i+1] array */ } nidx[1+i] = isz; /* size of new is[i] */ } /* for each is */ *data_new = nidx; ierr = PetscBTDestroy(table0);CHKERRQ(ierr); PetscFunctionReturn(0); }