1 2 static char help[] = "Tests MatMPIBAIJ format in sequential run \n"; 3 4 #include <petscmat.h> 5 int main(int argc,char **args) 6 { 7 Mat A,B; 8 PetscInt i,rstart,rend; 9 PetscMPIInt rank,size; 10 PetscScalar v; 11 12 PetscFunctionBeginUser; 13 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 14 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); 15 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size)); 16 17 /* Create a MPIBAIJ matrix */ 18 PetscCall(MatCreate(PETSC_COMM_WORLD,&A)); 19 PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,32,32)); 20 PetscCall(MatSetType(A,MATMPIBAIJ)); 21 PetscCall(MatSeqBAIJSetPreallocation(A,2,2,NULL)); 22 PetscCall(MatMPIBAIJSetPreallocation(A,2,2,NULL,2,NULL)); 23 24 v = 1.0; 25 PetscCall(MatGetOwnershipRange(A,&rstart,&rend)); 26 for (i=rstart; i<rend; i++) { 27 PetscCall(MatSetValues(A,1,&i,1,&i,&v,INSERT_VALUES)); 28 } 29 PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY)); 30 PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY)); 31 32 /* Convert A to AIJ format */ 33 PetscCall(MatConvert(A,MATAIJ,MAT_INITIAL_MATRIX,&B)); 34 35 PetscCall(MatDestroy(&A)); 36 PetscCall(MatDestroy(&B)); 37 PetscCall(PetscFinalize()); 38 return 0; 39 } 40 41 /*TEST 42 43 test: 44 output_file: output/ex160.out 45 46 TEST*/ 47