#ifndef lint static char vcid[] = "$Id: fdmpiaij.c,v 1.1 1996/10/15 18:50:07 bsmith Exp bsmith $"; #endif #include "src/mat/impls/aij/mpi/mpiaij.h" #include "src/vec/vecimpl.h" #include "petsc.h" extern int CreateColmap_MPIAIJ_Private(Mat); int MatFDColoringCreate_MPIAIJ(Mat mat,ISColoring iscoloring,MatFDColoring c) { Mat_MPIAIJ *aij = (Mat_MPIAIJ *) mat->data; int i,*is,n,nrows,j,k,m,*rows = 0,ierr,*A_ci,*A_cj,ncols,col,flg; int nis = iscoloring->n,*ncolsonproc,size,nctot,*cols,*disp,*B_ci,*B_cj; int *rowhit, M = mat->m,cstart = aij->cstart, cend = aij->cend,colb; int *columnsforrow; IS *isa = iscoloring->is; PetscTruth done; c->ncolors = nis; c->ncolumns = (int *) PetscMalloc( nis*sizeof(int) ); CHKPTRQ(c->ncolumns); c->columns = (int **) PetscMalloc( nis*sizeof(int *)); CHKPTRQ(c->columns); c->nrows = (int *) PetscMalloc( nis*sizeof(int) ); CHKPTRQ(c->nrows); c->rows = (int **) PetscMalloc( nis*sizeof(int *)); CHKPTRQ(c->rows); c->columnsforrow = (int **) PetscMalloc( nis*sizeof(int *)); CHKPTRQ(c->columnsforrow); /* Allow access to data structures of local part of matrix */ if (!aij->colmap) { ierr = CreateColmap_MPIAIJ_Private(mat);CHKERRQ(ierr); } ierr = MatGetColumnIJ(aij->A,0,PETSC_FALSE,&ncols,&A_ci,&A_cj,&done); CHKERRQ(ierr); ierr = MatGetColumnIJ(aij->B,0,PETSC_FALSE,&ncols,&B_ci,&B_cj,&done); CHKERRQ(ierr); MPI_Comm_size(mat->comm,&size); ncolsonproc = (int *) PetscMalloc( 2*size*sizeof(int *) ); CHKPTRQ(ncolsonproc); disp = ncolsonproc + size; rowhit = (int *) PetscMalloc( (M+1)*sizeof(int) ); CHKPTRQ(rowhit); columnsforrow = (int *) PetscMalloc( (M+1)*sizeof(int) );CHKPTRQ(columnsforrow); /* Temporary option to allow for debugging/testing */ ierr = OptionsHasName(0,"-matfdcoloring_slow",&flg); for ( i=0; incolumns[i] = n; c->ncolumns[i] = n; if (n) { c->columns[i] = (int *) PetscMalloc( n*sizeof(int) ); CHKPTRQ(c->columns[i]); PetscMemcpy(c->columns[i],is,n*sizeof(int)); } else { c->columns[i] = 0; } /* Determine the total (parallel) number of columns of this color */ MPI_Allgather(&n,1,MPI_INT,ncolsonproc,1,MPI_INT,mat->comm); nctot = 0; for ( j=0; jcomm); /* for ( j=0; j= cstart && col < cend) { /* column is in diagonal block of matrix */ rows = A_cj + A_ci[col-cstart]; m = A_ci[col-cstart+1] - A_ci[col-cstart]; } else { colb = aij->colmap[col] - 1; if (colb == -1) { m = 0; } else { rows = B_cj + B_ci[colb]; m = B_ci[colb+1] - B_ci[colb]; } } /* loop over columns marking them in rowhit */ for ( k=0; knrows[i] = nrows; c->rows[i] = (int *) PetscMalloc((nrows+1)*sizeof(int)); CHKPTRQ(c->rows[i]); c->columnsforrow[i] = (int *) PetscMalloc((nrows+1)*sizeof(int)); CHKPTRQ(c->columnsforrow[i]); nrows = 0; for ( j=0; jrows[i][nrows] = j; c->columnsforrow[i][nrows] = rowhit[j] - 1; nrows++; } } } else {/*-------------------------------------------------------------------------------*/ /* efficient version, using rowhit as a linked list */ int currentcol,fm,mfm; rowhit[M] = M; nrows = 0; /* loop over columns*/ for ( j=0; j= cstart && col < cend) { /* column is in diagonal block of matrix */ rows = A_cj + A_ci[col-cstart]; m = A_ci[col-cstart+1] - A_ci[col-cstart]; } else { colb = aij->colmap[col] - 1; if (colb == -1) { m = 0; } else { rows = B_cj + B_ci[colb]; m = B_ci[colb+1] - B_ci[colb]; } } /* loop over columns marking them in rowhit */ fm = M; /* fm points to first entry in linked list */ for ( k=0; knrows[i] = nrows; c->rows[i] = (int *)PetscMalloc((nrows+1)*sizeof(int));CHKPTRQ(c->rows[i]); c->columnsforrow[i] = (int *)PetscMalloc((nrows+1)*sizeof(int));CHKPTRQ(c->columnsforrow[i]); /* now store the linked list of rows into c->rows[i] */ nrows = 0; fm = rowhit[M]; do { c->rows[i][nrows] = fm; c->columnsforrow[i][nrows++] = columnsforrow[fm]; fm = rowhit[fm]; } while (fm < M); } /* ---------------------------------------------------------------------------------------*/ PetscFree(cols); } PetscFree(rowhit); PetscFree(columnsforrow); PetscFree(ncolsonproc); ierr = MatRestoreColumnIJ(aij->A,0,PETSC_FALSE,&ncols,&A_ci,&A_cj,&done); CHKERRQ(ierr); ierr = MatRestoreColumnIJ(aij->B,0,PETSC_FALSE,&ncols,&B_ci,&B_cj,&done); CHKERRQ(ierr); c->scale = (Scalar *) PetscMalloc( 2*mat->N*sizeof(Scalar) ); CHKPTRQ(c->scale); c->wscale = c->scale + mat->N; return 0; }