1 | // file 3_petsc_mat.c |
---|
2 | // source loadPetscEnv.sh |
---|
3 | // make |
---|
4 | // qsub petscSubmissionScript |
---|
5 | |
---|
6 | |
---|
7 | #include "petscksp.h" |
---|
8 | |
---|
9 | #undef __FUNCT__ |
---|
10 | #define __FUNCT__ "main" |
---|
11 | int main(int argc,char **args) |
---|
12 | { |
---|
13 | |
---|
14 | PetscErrorCode ierr; |
---|
15 | PetscMPIInt rank; |
---|
16 | |
---|
17 | PetscViewer viewer_fd; |
---|
18 | |
---|
19 | Mat mC; |
---|
20 | |
---|
21 | int row_local_min, row_local_max, row_global, col_global; |
---|
22 | |
---|
23 | // Init stage |
---|
24 | |
---|
25 | PetscInitialize(&argc,&args,(char *)0,PETSC_NULL); |
---|
26 | |
---|
27 | MPI_Comm_rank(PETSC_COMM_WORLD, &rank); |
---|
28 | |
---|
29 | // Load matrix |
---|
30 | |
---|
31 | PetscPrintf(PETSC_COMM_WORLD, "\n[%d] Loading data ...", rank); |
---|
32 | |
---|
33 | ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD , "data/mC_200x200.bin" , FILE_MODE_READ , &viewer_fd ); CHKERRQ(ierr); |
---|
34 | ierr = MatCreate(PETSC_COMM_WORLD, &mC); |
---|
35 | ierr = MatSetType(mC, MATAIJ); |
---|
36 | ierr = MatLoad(mC, viewer_fd); CHKERRQ(ierr); |
---|
37 | ierr = PetscViewerDestroy(&viewer_fd); CHKERRQ(ierr); |
---|
38 | |
---|
39 | CHKMEMQ; |
---|
40 | |
---|
41 | PetscPrintf(PETSC_COMM_WORLD, "\n[%d] Loading data done. \n", rank); |
---|
42 | |
---|
43 | // Matrix operations |
---|
44 | |
---|
45 | //MatView(mC, PETSC_VIEWER_STDOUT_WORLD); |
---|
46 | |
---|
47 | MatGetSize(mC,&row_global,&col_global); |
---|
48 | MatGetOwnershipRange(mC,&row_local_min,&row_local_max); |
---|
49 | |
---|
50 | PetscPrintf(PETSC_COMM_SELF, "[%d] global size: %dx%d, range of matrix rows: %d-%d\n", |
---|
51 | rank, row_global, col_global, row_local_min, row_local_max-1); |
---|
52 | |
---|
53 | // Free memory |
---|
54 | |
---|
55 | MatDestroy(&mC); |
---|
56 | ierr = PetscFinalize(); CHKERRQ(ierr); |
---|
57 | |
---|
58 | return 0; |
---|
59 | } |
---|