Actual source code: ex60.c
petsc-3.14.6 2021-03-30
2: static char help[] = "Tests MatGetColumnVector().";
4: #include <petscmat.h>
6: int main(int argc,char **args)
7: {
8: Mat C;
9: PetscInt i,j,m = 3,n = 2,Ii,J,col = 0;
10: PetscMPIInt size,rank;
12: PetscScalar v;
13: Vec yy;
15: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
16: PetscOptionsGetInt(NULL,NULL,"-col",&col,NULL);
18: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
19: MPI_Comm_size(PETSC_COMM_WORLD,&size);
20: n = 2*size;
22: /* create the matrix for the five point stencil, YET AGAIN*/
23: MatCreate(PETSC_COMM_WORLD,&C);
24: MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n);
25: MatSetFromOptions(C);
26: MatSeqAIJSetPreallocation(C,5,NULL);
27: MatMPIAIJSetPreallocation(C,5,NULL,5,NULL);
28: MatSetUp(C);
30: for (i=0; i<m; i++) {
31: for (j=2*rank; j<2*rank+2; j++) {
32: v = -1.0; Ii = j + n*i;
33: if (i>0) {J = Ii - n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
34: if (i<m-1) {J = Ii + n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
35: if (j>0) {J = Ii - 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
36: if (j<n-1) {J = Ii + 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
37: v = 4.0; MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);
38: }
39: }
40: MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
41: MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
42: MatView(C,PETSC_VIEWER_STDOUT_WORLD);
44: MatCreateVecs(C,NULL,&yy);
45: VecSetFromOptions(yy);
47: MatGetColumnVector(C,yy,col);
49: VecView(yy,PETSC_VIEWER_STDOUT_WORLD);
51: VecDestroy(&yy);
52: MatDestroy(&C);
53: PetscFinalize();
54: return ierr;
55: }
58: /*TEST
60: test:
61: nsize: 3
62: args: -col 7
64: test:
65: suffix: dense
66: nsize: 3
67: args: -col 7 -mat_type dense -vec_type {{mpi standard}}
68: filter: grep -v type
70: test:
71: requires: cuda
72: suffix: dense_cuda
73: nsize: 3
74: output_file: output/ex60_dense.out
75: args: -col 7 -mat_type {{mpidense mpidensecuda}} -vec_type {{mpi standard cuda mpicuda}}
76: filter: grep -v type
78: TEST*/