const char help[] = "Test MatCreateLocalRef()\n\n"; #include static PetscErrorCode GetLocalRef(Mat A,IS isrow,IS iscol,Mat *B) { PetscErrorCode ierr; IS istmp; PetscFunctionBegin; ierr = PetscPrintf(PETSC_COMM_WORLD,"Extracting LocalRef with isrow:\n");CHKERRQ(ierr); ierr = ISOnComm(isrow,PETSC_COMM_WORLD,PETSC_COPY_VALUES,&istmp);CHKERRQ(ierr); ierr = ISView(istmp,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISDestroy(&istmp);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"Extracting LocalRef with iscol (only rank=0 shown):\n");CHKERRQ(ierr); ierr = ISOnComm(iscol,PETSC_COMM_WORLD,PETSC_COPY_VALUES,&istmp);CHKERRQ(ierr); ierr = ISView(istmp,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISDestroy(&istmp);CHKERRQ(ierr); ierr = MatCreateLocalRef(A,isrow,iscol,B);CHKERRQ(ierr); PetscFunctionReturn(0); } int main(int argc,char *argv[]) { PetscErrorCode ierr; MPI_Comm comm; Mat J,B; PetscInt i,j,k,l,rstart,rend,m,n,top_bs,row_bs,col_bs,nlocblocks,*idx,nrowblocks,ncolblocks,*ridx,*cidx,*icol,*irow; PetscScalar *vals; ISLocalToGlobalMapping brmap; IS is0,is1; PetscBool diag,blocked; ierr = PetscInitialize(&argc,&argv,0,help);if (ierr) return ierr; comm = PETSC_COMM_WORLD; ierr = PetscOptionsBegin(comm,NULL,"LocalRef Test Options",NULL);CHKERRQ(ierr); { top_bs = 2; row_bs = 2; col_bs = 2; diag = PETSC_FALSE; blocked = PETSC_FALSE; ierr = PetscOptionsInt("-top_bs","Block size of top-level matrix",0,top_bs,&top_bs,NULL);CHKERRQ(ierr); ierr = PetscOptionsInt("-row_bs","Block size of row map",0,row_bs,&row_bs,NULL);CHKERRQ(ierr); ierr = PetscOptionsInt("-col_bs","Block size of col map",0,col_bs,&col_bs,NULL);CHKERRQ(ierr); ierr = PetscOptionsBool("-diag","Extract a diagonal black",0,diag,&diag,NULL);CHKERRQ(ierr); ierr = PetscOptionsBool("-blocked","Use block insertion",0,blocked,&blocked,NULL);CHKERRQ(ierr); } ierr = PetscOptionsEnd();CHKERRQ(ierr); ierr = MatCreate(comm,&J);CHKERRQ(ierr); ierr = MatSetSizes(J,6,6,PETSC_DETERMINE,PETSC_DETERMINE);CHKERRQ(ierr); ierr = MatSetBlockSize(J,top_bs);CHKERRQ(ierr); ierr = MatSetFromOptions(J);CHKERRQ(ierr); ierr = MatSeqBAIJSetPreallocation(J,top_bs,PETSC_DECIDE,0);CHKERRQ(ierr); ierr = MatMPIBAIJSetPreallocation(J,top_bs,PETSC_DECIDE,0,PETSC_DECIDE,0);CHKERRQ(ierr); ierr = MatSetUp(J);CHKERRQ(ierr); ierr = MatGetSize(J,&m,&n);CHKERRQ(ierr); ierr = MatGetOwnershipRange(J,&rstart,&rend);CHKERRQ(ierr); nlocblocks = (rend-rstart)/top_bs + 2; ierr = PetscMalloc1(nlocblocks,&idx);CHKERRQ(ierr); for (i=0; i nrowblocks/2) ^ !rstart); for (i=0; i