[petsc-users] Petsc memory consumption keep increasing in my loop

Medane TCHAKOROM medane.tchakorom at univ-fcomte.fr
Fri Sep 24 09:08:01 CDT 2021


Hello,

I have problem with a code i'am working on.

To illustrate my problem, here is an example:


int main(int argc, char *argv[])
{

     PetscErrorCode ierr;

     ierr = PetscInitialize(&argc, &argv, (char *)0, NULL);
     if (ierr)
         return ierr;

     int i = 0;
     for (i = 0; i < 1; i++)
     {
         Mat A;
         ierr = MatCreate(PETSC_COMM_WORLD, &A);
         CHKERRQ(ierr);
         ierr = MatSetSizes(A, 16, 16, PETSC_DECIDE,PETSC_DECIDE);
         CHKERRQ(ierr);
         ierr = MatSetFromOptions(A);
         CHKERRQ(ierr);
         ierr = MatSetUp(A);
         CHKERRQ(ierr);


         ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
         CHKERRQ(ierr);
         ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
         CHKERRQ(ierr);



         /// SOME CODE HERE....

         MatDestroy(&A);


     }


     FILE *fPtr;
     fPtr = fopen("petsc_dump_file.txt", "a");
     PetscMallocDump(fPtr);
     fclose(fPtr);

     ierr = PetscFinalize();
     CHKERRQ(ierr);

     return 0;
}



The problem is , in the loop, the memory consumption keep increasing 
till the end of the program.

I checked memory leak with PetscMallocDump, and found out that the 
problem may be due to matrix creation.

I'am new to Petsc and i don't know if i'am doing something wrong. Thanks


Médane



More information about the petsc-users mailing list