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