Actual source code: ex111.c
1: static char help[] = "Test PtAP \n\
2: Reads PETSc matrix A and P, then comput Pt*A*P \n\
3: Input parameters include\n\
4: -fA <input_file> -fP <input_file>: second files to load (projection) \n\n";
6: #include petscmat.h
8: #undef WRITEFILE
11: PetscInt main(PetscInt argc,char **args)
12: {
13: Mat A,P,C;
14: PetscViewer fd;
15: char file[2][PETSC_MAX_PATH_LEN];
16: PetscTruth flg;
18: PetscReal fill=2.0;
20: PetscInitialize(&argc,&args,(char *)0,help);
21: #ifdef WRITEFILE
22: {
23: PetscViewer viewer;
24: PetscPrintf(PETSC_COMM_WORLD,"writing matrix A in binary to A.dat ...\n");
25: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"A.dat",FILE_MODE_WRITE,&viewer);
26: MatView(A,viewer);
27: PetscViewerDestroy(viewer);
29: PetscPrintf(PETSC_COMM_WORLD,"writing matrix P in binary to P.dat ...\n");
30: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"P.dat",FILE_MODE_WRITE,&viewer);
31: MatView(P,viewer);
32: PetscViewerDestroy(viewer);
33: }
34: #endif
36: /* read the two matrices, A (square) and P (projection) */
37: PetscOptionsGetString(PETSC_NULL,"-fA",file[0],PETSC_MAX_PATH_LEN-1,&flg);
38: if (!flg) SETERRQ(PETSC_ERR_USER,"Must indicate binary file with the -fA options");
39: PetscOptionsGetString(PETSC_NULL,"-fP",file[1],PETSC_MAX_PATH_LEN-1,&flg);
40: if (!flg) SETERRQ(PETSC_ERR_USER,"Must indicate binary file with the -fP options");
41:
42: /* Load matrices */
43: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[0],FILE_MODE_READ,&fd);
44: MatLoad(fd,MATAIJ,&A);
45: PetscViewerDestroy(fd);
46: //MatGetSize(A,&m,&n);
47:
48: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[1],FILE_MODE_READ,&fd);
49: MatLoad(fd,MATAIJ,&P);
50: PetscViewerDestroy(fd);
51:
52: MatPtAP(A,P,MAT_INITIAL_MATRIX,fill,&C);
54: MatDestroy(C);
55: MatDestroy(P);
56: MatDestroy(A);
57: PetscFinalize();
58: return 0;
59: }