#ifndef lint static char vcid[] = "$Id: mpiov.c,v 1.9 1996/01/31 20:22:46 balay Exp balay $"; #endif #include "mpiaij.h" #include "inline/bitarray.h" int MatIncreaseOverlap_MPIAIJ_private(Mat, int, IS *); int MatIncreaseOverlap_MPIAIJ(Mat C, int is_max, IS *is, int ov) { int i, ierr; if (ov < 0){ SETERRQ(1," MatIncreaseOverlap_MPIAIJ: negative overlap specified\n");} for (i =0; idata; Mat A = c->A, B = c->B; Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data,*b = (Mat_SeqAIJ*)B->data; int **idx, *n, *w1, *w2, *w3, *w4, *rtable,**data; int size, rank, m,i,j,k, ierr, **rbuf, row, proc, mct, msz, **outdat, **ptr; int *ctr, sum, *pa, tag, *tmp,bsz, nmsg , *isz, *isz1, **xdata,rstart; int cstart, *ai, *aj, *bi, *bj, *garray, bsz1, **rbuf2, ashift, bshift; char **table, *xtable; MPI_Comm comm; MPI_Request *send_waits,*recv_waits,*send_waits2,*recv_waits2 ; MPI_Status *send_status ,*recv_status; double space, fr, maxs; /* assume overlap = 1 */ comm = C->comm; tag = C->tag; size = c->size; 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; TrSpace( &space, &fr, &maxs ); /* MPIU_printf(MPI_COMM_SELF,"[%d] acclcated space = %f fragments = %f max ever allocated = %f\n", rank, space, fr, maxs); */ idx = (int **)PetscMalloc((is_max+1)*sizeof(int *)); CHKPTRQ(idx); n = (int *)PetscMalloc((is_max+1)*sizeof(int )); CHKPTRQ(n); rtable = (int *)PetscMalloc((m+1)*sizeof(int )); CHKPTRQ(rtable); /* Hash table for maping row ->proc */ for ( i=0 ; i proc*/ for( i=0, j=0; i< size; i++) { for (; j rowners[i+1]; j++) { rtable[j] = i; } } /* evaluate communication - mesg to who, length of mesg, and buffer space required. Based on this, buffers are allocated, and data copied into them*/ w1 = (int *)PetscMalloc((size)*4*sizeof(int )); CHKPTRQ(w1); /* mesg size */ w2 = w1 + size; /* if w2[i] marked, then a message to proc i*/ w3 = w2 + size; /* no of IS that needs to be sent to proc i */ w4 = w3 + size; /* temp work space used in determining w1, w2, w3 */ PetscMemzero(w1,(size)*3*sizeof(int)); /* initialise work vector*/ for ( i=0; inz +b->nz)/c->m; mem_estimate = 3* (total_sz > max1?total_sz:max1) ; xdata = (int **)PetscMalloc((nmsg+1)*sizeof(int *)); CHKPTRQ(xdata); xdata[0] = (int *)PetscMalloc(mem_estimate *sizeof(int)); CHKPTRQ(xdata[0]); xtable = (char *)PetscMalloc((m/8+1)); CHKPTRQ(xtable); isz1 = (int *)PetscMalloc((nmsg+1) *sizeof(int)); CHKPTRQ(isz1); PetscMemzero((void *)isz1,(nmsg+1) *sizeof(int)); for (i =0; i< nmsg; i++) { /* for easch mesg from proc i */ ct1 = 2*rbuf[i][0]+1; ct2 = 2*rbuf[i][0]+1; for (j = 1, max1= rbuf[i][0]; j<=max1; j++) { /* for each IS from proc i*/ PetscMemzero((void *)xtable,(m/8+1)); oct2 = ct2; for (k =0; k < rbuf[i][2*j]; k++, ct1++) { row = rbuf[i][ct1]; if(!BT_LOOKUP(xtable,row)) { xdata[i][ct2++] = row;} /* if(!xtable[row]++) { xdata[i][ct2++] = row;} */ } for ( k=oct2, max2 =ct2 ; k< max2; k++) { row = xdata[i][k] - rstart; start = ai[row]; end = ai[row+1]; for ( l=start; l < end; l++) { val = aj[l] +ashift + cstart; if(!BT_LOOKUP(xtable,val)) { xdata[i][ct2++] = val;} /* if(!xtable[val]++) { xdata[i][ct2++] = val;} */ } start = bi[row]; end = bi[row+1]; for ( l=start; l < end; l++) { val = garray[bj[l]+bshift] ; if(!BT_LOOKUP(xtable,val)) { xdata[i][ct2++] = val;} /* if(!xtable[val]++) { xdata[i][ct2++] = val;} */ } } /* Update the header*/ xdata[i][2*j] = ct2-oct2; /* Undo the vector isz1 and use only a var*/ xdata[i][2*j-1] = rbuf[i][2*j-1]; } xdata[i][0] = rbuf[i][0]; xdata[i+1] = xdata[i] +ct2; isz1[i] = ct2; /* size of each message */ } } /* need isz, xdata;*/ /* Send the data back*/ /* Do a global reduction to know the buffer space req for incoming messages*/ { int *rw1, *rw2; rw1 = (int *)PetscMalloc(2*size*sizeof(int)); CHKPTRQ(rw1); PetscMemzero((void*)rw1,2*size*sizeof(int)); rw2 = rw1+size; for (i =0; i < nmsg ; ++i) { proc = recv_status[i].MPI_SOURCE; rw1[proc] = isz1[i]; } MPI_Allreduce((void *)rw1, (void *)rw2, size, MPI_INT, MPI_MAX, comm); bsz1 = rw2[rank]; PetscFree(rw1); } /* Allocate buffers*/ /* Allocate memory for recv buffers . Prob none if nmsg = 0 ???? */ rbuf2 = (int**) PetscMalloc((mct+1) *sizeof(int*)); CHKPTRQ(rbuf2); rbuf2[0] = (int *) PetscMalloc((mct*bsz1+1) * sizeof(int)); CHKPTRQ(rbuf2[0]); for (i=1; i