1 2 static char help[] = "Tests MatLoad() MatView() for MPIBAIJ.\n\n"; 3 4 #include <petscmat.h> 5 6 int main(int argc,char **args) 7 { 8 Mat A,B; 9 char file[PETSC_MAX_PATH_LEN]; 10 PetscBool flg; 11 PetscViewer fd; 12 13 PetscFunctionBeginUser; 14 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 15 PetscCall(PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg)); 16 PetscCheck(flg,PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f option"); 17 18 /* 19 Open binary file. Note that we use FILE_MODE_READ to indicate 20 reading from this file. 21 */ 22 PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd)); 23 24 /* 25 Load the matrix; then destroy the viewer. 26 */ 27 PetscCall(MatCreate(PETSC_COMM_WORLD,&A)); 28 PetscCall(MatSetFromOptions(A)); 29 PetscCall(MatLoad(A,fd)); 30 PetscCall(PetscViewerDestroy(&fd)); 31 32 /* 33 Open another binary file. Note that we use FILE_MODE_WRITE to indicate writing to the file 34 */ 35 PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_WRITE,&fd)); 36 PetscCall(PetscViewerBinarySetFlowControl(fd,3)); 37 /* 38 Save the matrix and vector; then destroy the viewer. 39 */ 40 PetscCall(MatView(A,fd)); 41 PetscCall(PetscViewerDestroy(&fd)); 42 43 /* load the new matrix */ 44 PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_READ,&fd)); 45 PetscCall(MatCreate(PETSC_COMM_WORLD,&B)); 46 PetscCall(MatSetFromOptions(B)); 47 PetscCall(MatLoad(B,fd)); 48 PetscCall(PetscViewerDestroy(&fd)); 49 50 PetscCall(MatEqual(A,B,&flg)); 51 if (flg) { 52 PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Matrices are equal\n")); 53 } else { 54 PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Matrices are not equal\n")); 55 } 56 57 PetscCall(MatDestroy(&A)); 58 PetscCall(MatDestroy(&B)); 59 PetscCall(PetscFinalize()); 60 return 0; 61 } 62 63 /*TEST 64 65 test: 66 nsize: 3 67 requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES) 68 args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info 69 70 test: 71 suffix: 2 72 nsize: 5 73 requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES) 74 args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info 75 76 test: 77 suffix: 3 78 nsize: 7 79 requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES) 80 args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info 81 82 test: 83 suffix: 4 84 nsize: 3 85 requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES) 86 args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij 87 88 test: 89 suffix: 5 90 nsize: 5 91 requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES) 92 args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij 93 94 test: 95 suffix: 6 96 nsize: 7 97 requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES) 98 args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij 99 100 TEST*/ 101