xref: /petsc/src/mat/tests/ex160.c (revision 66af8762ec03dbef0e079729eb2a1734a35ed7ff)
1 static char help[] = "Tests MatMPIBAIJ format in sequential run \n";
2 
3 #include <petscmat.h>
4 int main(int argc, char **args)
5 {
6   Mat         A, B;
7   PetscInt    i, rstart, rend;
8   PetscMPIInt rank, size;
9   PetscScalar v;
10 
11   PetscFunctionBeginUser;
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++) PetscCall(MatSetValues(A, 1, &i, 1, &i, &v, INSERT_VALUES));
26   PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
27   PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
28 
29   /* Convert A to AIJ format */
30   PetscCall(MatConvert(A, MATAIJ, MAT_INITIAL_MATRIX, &B));
31 
32   PetscCall(MatDestroy(&A));
33   PetscCall(MatDestroy(&B));
34   PetscCall(PetscFinalize());
35   return 0;
36 }
37 
38 /*TEST
39 
40    test:
41      output_file: output/ex160.out
42 
43 TEST*/
44