[petsc-users] [BUG]: error occurs when calling PetscInitialize and PetscFinalize multiple times

Mengda Wu wumengda at gmail.com
Fri May 11 13:58:59 CDT 2012


Hello all,

   I am using Petsc-3.2-p7 complied under cygwin and using Petsc's uni-mpi
implementation. I found I cannot call PetscInitialize and PetscFinalize
multiple times.
Here is the code (between ==) that can reproduce the error. It seems that
the second PetscFinalize() generates an error at line 1221 at pinit.c
which is
 ierr = MPI_Finalize();CHKERRQ(ierr);


==============================================================
#include "petscksp.h"
#include <iostream>

int main(int argc,char *args[])
{
  PetscErrorCode ierr;
  PetscMPIInt    size;

  PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);
  std::cout << "Initialize 1" << std::endl;

  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
  if (size != 1) SETERRQ(PETSC_COMM_WORLD,1,"This is a uniprocessor example
only!");

  ierr = PetscFinalize();
  std::cout << "Finalize 1" << std::endl;

  PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);
  std::cout << "Initialize 2" << std::endl;
  ierr = PetscFinalize();
  std::cout << "Finalize 2" << std::endl;

  PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);
  std::cout << "Initialize 3" << std::endl;
  ierr = PetscFinalize();
  std::cout << "Finalize 3" << std::endl;

  PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);
  std::cout << "Initialize 4" << std::endl;
  ierr = PetscFinalize();
  std::cout << "Finalize 4" << std::endl;

  return 0;
}
==============================================================

I got the following output:
Initialize 1
Finalize 1
Initialize 2
[0]PETSC ERROR: PetscFinalize() line 1221 in
src/sys/objects/D:\Library\PETSc\pe
tsc-3.2\src\sys\objects\pinit.c
Finalize 2
Initialize 3
Options have not been enabled.
You might have forgotten to call PetscInitialize().

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.


Thanks,
Mengda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120511/3a09d541/attachment.htm>


More information about the petsc-users mailing list