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

Satish Balay balay at mcs.anl.gov
Fri May 11 14:15:13 CDT 2012


The scemantic for using PetscInitialize/PetscFinalize multiple times
is for the user call MPI_Init()/Finalize() separately - and only once.
[MPI standard imposes the restriction on calling MPI_Init()/Finalize()
only once].

MPIUNI is also preserving this scemantic usage aswell.

On Fri, 11 May 2012, Mengda Wu wrote:

> 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;

  MPI_Init(&argc,&args);

> 
>   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;
> 
  MPI_Finalize();

Satish

>   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
> 



More information about the petsc-users mailing list