Actual source code: ex169.c
2: static char help[] = "Test memory leak when duplicating a redundant matrix.\n\n";
4: /*
5: Include "petscmat.h" so that we can use matrices.
6: automatically includes:
7: petscsys.h - base PETSc routines petscvec.h - vectors
8: petscmat.h - matrices
9: petscis.h - index sets petscviewer.h - viewers
10: */
11: #include <petscmat.h>
13: int main(int argc,char **args)
14: {
15: Mat A,Ar,C;
16: PetscViewer fd; /* viewer */
17: char file[PETSC_MAX_PATH_LEN]; /* input file name */
19: PetscInt ns=2;
20: PetscMPIInt size;
21: PetscSubcomm subc;
22: PetscBool flg;
24: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
25: /*
26: Determine files from which we read the two linear systems
27: (matrix and right-hand-side vector).
28: */
29: PetscOptionsGetString(NULL,NULL,"-f0",file,sizeof(file),&flg);
30: if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f0 option");
31: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
32: MPI_Comm_size(PETSC_COMM_WORLD,&size);
33: PetscPrintf(PETSC_COMM_WORLD,"Reading matrix with %d processors\n",size);
34: MatCreate(PETSC_COMM_WORLD,&A);
35: MatLoad(A,fd);
36: PetscViewerDestroy(&fd);
37: /*
38: Determines amount of subcomunicators
39: */
40: PetscOptionsGetInt(NULL,NULL,"-nsub",&ns,NULL);
41: PetscPrintf(PETSC_COMM_WORLD,"Splitting in %d subcommunicators\n",ns);
42: PetscSubcommCreate(PetscObjectComm((PetscObject)A),&subc);
43: PetscSubcommSetNumber(subc,ns);
44: PetscSubcommSetType(subc,PETSC_SUBCOMM_CONTIGUOUS);
45: PetscSubcommSetFromOptions(subc);
46: MatCreateRedundantMatrix(A,0,PetscSubcommChild(subc),MAT_INITIAL_MATRIX,&Ar);
47: PetscPrintf(PETSC_COMM_WORLD,"Copying matrix\n",ns);
48: MatDuplicate(Ar,MAT_COPY_VALUES,&C);
49: PetscSubcommDestroy(&subc);
51: /*
52: Free memory
53: */
54: MatDestroy(&A);
55: MatDestroy(&Ar);
56: MatDestroy(&C);
57: PetscFinalize();
58: return ierr;
59: }
61: /*TEST
63: test:
64: nsize: 4
65: requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
66: args: -f0 ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64 -malloc_dump
68: TEST*/