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 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 13 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); 14 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size)); 15 16 /* Create a MPIBAIJ matrix */ 17 PetscCall(MatCreate(PETSC_COMM_WORLD,&A)); 18 PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,32,32)); 19 PetscCall(MatSetType(A,MATMPIBAIJ)); 20 PetscCall(MatSeqBAIJSetPreallocation(A,2,2,NULL)); 21 PetscCall(MatMPIBAIJSetPreallocation(A,2,2,NULL,2,NULL)); 22 23 v = 1.0; 24 PetscCall(MatGetOwnershipRange(A,&rstart,&rend)); 25 for (i=rstart; i<rend; i++) { 26 PetscCall(MatSetValues(A,1,&i,1,&i,&v,INSERT_VALUES)); 27 } 28 PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY)); 29 PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY)); 30 31 /* Convert A to AIJ format */ 32 PetscCall(MatConvert(A,MATAIJ,MAT_INITIAL_MATRIX,&B)); 33 34 PetscCall(MatDestroy(&A)); 35 PetscCall(MatDestroy(&B)); 36 PetscCall(PetscFinalize()); 37 return 0; 38 } 39 40 /*TEST 41 42 test: 43 output_file: output/ex160.out 44 45 TEST*/ 46