1 2 static char help[] = "Test MatCreate() with MAT_STRUCTURE_ONLY .\n\n"; 3 4 #include <petscmat.h> 5 6 int main(int argc,char **argv) 7 { 8 Mat mat; 9 PetscInt m = 7,n,i,j,rstart,rend; 10 PetscMPIInt size; 11 PetscScalar v; 12 PetscBool struct_only=PETSC_TRUE; 13 14 PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); 15 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size)); 16 PetscCheck(size == 1,PETSC_COMM_WORLD,PETSC_ERR_WRONG_MPI_SIZE,"This is a uniprocessor example only!"); 17 18 PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_COMMON)); 19 PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,NULL)); 20 PetscCall(PetscOptionsGetBool(NULL,NULL,"-struct_only",&struct_only,NULL)); 21 n = m; 22 23 /* ------- Assemble matrix, test MatValid() --------- */ 24 PetscCall(MatCreate(PETSC_COMM_WORLD,&mat)); 25 PetscCall(MatSetSizes(mat,PETSC_DECIDE,PETSC_DECIDE,m,n)); 26 PetscCall(MatSetFromOptions(mat)); 27 if (struct_only) PetscCall(MatSetOption(mat,MAT_STRUCTURE_ONLY,PETSC_TRUE)); 28 PetscCall(MatSetUp(mat)); 29 PetscCall(MatGetOwnershipRange(mat,&rstart,&rend)); 30 for (i=rstart; i<rend; i++) { 31 for (j=0; j<n; j++) { 32 v = 10.0*i+j; 33 PetscCall(MatSetValues(mat,1,&i,1,&j,&v,INSERT_VALUES)); 34 } 35 } 36 PetscCall(MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY)); 37 PetscCall(MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY)); 38 PetscCall(MatView(mat,PETSC_VIEWER_STDOUT_WORLD)); 39 40 /* Free data structures */ 41 PetscCall(MatDestroy(&mat)); 42 PetscCall(PetscFinalize()); 43 return 0; 44 } 45 46 /*TEST 47 48 test: 49 output_file: output/ex107.out 50 51 test: 52 suffix: 2 53 args: -mat_type baij -mat_block_size 2 -m 10 54 55 TEST*/ 56