Actual source code: ex135.c
1: static const char help[] = "Test parallel assembly of SBAIJ matrices\n\n";
3: #include <petscmat.h>
5: PetscErrorCode Assemble(MPI_Comm comm,PetscInt n,MatType mtype)
6: {
7: Mat A;
8: PetscInt first,last,i;
9: PetscMPIInt rank,size;
11: MatCreate(PETSC_COMM_WORLD,&A);
12: MatSetSizes(A, PETSC_DECIDE,PETSC_DECIDE,n,n);
13: MatSetType(A,MATMPISBAIJ);
14: MatSetFromOptions(A);
15: MPI_Comm_size(comm,&size);
16: MPI_Comm_rank(comm,&rank);
17: if (rank < size-1) {
18: MatMPISBAIJSetPreallocation(A,1,1,NULL,1,NULL);
19: } else {
20: MatMPISBAIJSetPreallocation(A,1,2,NULL,0,NULL);
21: }
22: MatGetOwnershipRange(A,&first,&last);
23: MatSetOption(A,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_TRUE);
24: last--;
25: for (i=first; i<=last; i++) {
26: MatSetValue(A,i,i,2.,INSERT_VALUES);
27: if (i != n-1) MatSetValue(A,i,n-1,-1.,INSERT_VALUES);
28: }
29: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
30: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
31: MatDestroy(&A);
32: return 0;
33: }
35: int main(int argc,char *argv[])
36: {
37: MPI_Comm comm;
38: PetscInt n = 6;
40: PetscInitialize(&argc,&argv,NULL,help);
41: comm = PETSC_COMM_WORLD;
42: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
43: Assemble(comm,n,MATMPISBAIJ);
44: PetscFinalize();
45: return 0;
46: }
48: /*TEST
50: test:
51: nsize: 4
52: args: -n 1000 -mat_view ascii::ascii_info_detail
53: requires: double !complex !defined(PETSC_USE_64BIT_INDICES)
55: TEST*/