1 static char help[] = "Test MatCreateRedundantMatrix for rectangular matrix.\n\ 2 Contributed by Jose E. Roman, July 2017\n\n"; 3 4 #include <petscmat.h> 5 int main(int argc,char **args) 6 { 7 Mat A,B; 8 PetscErrorCode ierr; 9 PetscInt m=3,n=4,i,nsubcomm; 10 PetscMPIInt size,rank; 11 12 ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; 13 CHKERRMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size)); 14 CHKERRMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank)); 15 16 nsubcomm = size; 17 CHKERRQ(PetscOptionsGetInt(NULL,NULL,"-nsubcomm",&nsubcomm,NULL)); 18 19 CHKERRQ(MatCreate(PETSC_COMM_WORLD, &A)); 20 CHKERRQ(MatSetSizes(A, m, n, PETSC_DETERMINE, PETSC_DETERMINE)); 21 CHKERRQ(MatSetType(A, MATAIJ)); 22 CHKERRQ(MatSetFromOptions(A)); 23 CHKERRQ(MatSetUp(A)); 24 25 if (rank == 0) { 26 for (i=0;i<size*PetscMin(m,n);i++) { 27 CHKERRQ(MatSetValue(A, i, i, 1.0, INSERT_VALUES)); 28 } 29 } 30 CHKERRQ(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY)); 31 CHKERRQ(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY)); 32 CHKERRQ(MatView(A,PETSC_VIEWER_STDOUT_WORLD)); 33 34 CHKERRQ(MatCreateRedundantMatrix(A, nsubcomm, MPI_COMM_NULL, MAT_INITIAL_MATRIX, &B)); 35 if (nsubcomm==size) { /* B is a sequential matrix */ 36 if (rank == 0) { 37 CHKERRQ(MatView(B,PETSC_VIEWER_STDOUT_SELF)); 38 } 39 } else { 40 MPI_Comm comm; 41 CHKERRQ(PetscObjectGetComm((PetscObject)B,&comm)); 42 CHKERRQ(MatView(B,PETSC_VIEWER_STDOUT_(comm))); 43 } 44 45 CHKERRQ(MatDestroy(&A)); 46 CHKERRQ(MatDestroy(&B)); 47 ierr = PetscFinalize(); 48 return ierr; 49 } 50 51 /*TEST 52 53 test: 54 55 test: 56 suffix: 2 57 nsize: 3 58 59 test: 60 suffix: baij 61 args: -mat_type baij 62 63 test: 64 suffix: baij_2 65 nsize: 3 66 args: -mat_type baij 67 68 test: 69 suffix: dense 70 args: -mat_type dense 71 72 test: 73 suffix: dense_2 74 nsize: 3 75 args: -mat_type dense 76 77 TEST*/ 78