Actual source code: ex131.c
2: static char help[] = "Tests MatMult() on MatLoad() matrix \n\n";
4: #include <petscmat.h>
6: int main(int argc,char **args)
7: {
8: Mat A;
9: Vec x,b;
10: PetscViewer fd; /* viewer */
11: char file[PETSC_MAX_PATH_LEN]; /* input file name */
12: PetscBool flg;
14: PetscInitialize(&argc,&args,(char*)0,help);
15: /* Determine file from which we read the matrix A */
16: PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);
19: /* Load matrix A */
20: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
21: MatCreate(PETSC_COMM_WORLD,&A);
22: MatLoad(A,fd);
23: flg = PETSC_FALSE;
24: VecCreate(PETSC_COMM_WORLD,&x);
25: PetscOptionsGetString(NULL,NULL,"-vec",file,sizeof(file),&flg);
26: if (flg) {
27: if (file[0] == '0') {
28: PetscInt m;
29: PetscScalar one = 1.0;
30: PetscInfo(0,"Using vector of ones for RHS\n");
31: MatGetLocalSize(A,&m,NULL);
32: VecSetSizes(x,m,PETSC_DECIDE);
33: VecSetFromOptions(x);
34: VecSet(x,one);
35: }
36: } else {
37: VecLoad(x,fd);
38: PetscViewerDestroy(&fd);
39: }
40: VecDuplicate(x,&b);
41: MatMult(A,x,b);
43: /* Print (for testing only) */
44: MatView(A,0);
45: VecView(b,0);
46: /* Free data structures */
47: MatDestroy(&A);
48: VecDestroy(&x);
49: VecDestroy(&b);
50: PetscFinalize();
51: return 0;
52: }