Hello all,<br><br> 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.<br>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 <br>
which is<br> ierr = MPI_Finalize();CHKERRQ(ierr);<br><br><br>==============================================================<br>#include "petscksp.h"<br>#include <iostream><br><br>int main(int argc,char *args[])<br>
{<br> PetscErrorCode ierr;<br> PetscMPIInt size;<br><br> PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);<br> std::cout << "Initialize 1" << std::endl;<br> <br> ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);<br>
if (size != 1) SETERRQ(PETSC_COMM_WORLD,1,"This is a uniprocessor example only!");<br><br> ierr = PetscFinalize();<br> std::cout << "Finalize 1" << std::endl;<br><br> PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);<br>
std::cout << "Initialize 2" << std::endl;<br> ierr = PetscFinalize();<br> std::cout << "Finalize 2" << std::endl;<br><br> PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);<br>
std::cout << "Initialize 3" << std::endl;<br> ierr = PetscFinalize();<br> std::cout << "Finalize 3" << std::endl;<br><br> PetscInitialize(&argc,&args,(char *)0, PETSC_NULL);<br>
std::cout << "Initialize 4" << std::endl;<br> ierr = PetscFinalize();<br> std::cout << "Finalize 4" << std::endl;<br><br> return 0;<br>}<br>==============================================================<br>
<br>I got the following output:<br>Initialize 1<br>Finalize 1<br>Initialize 2<br>[0]PETSC ERROR: PetscFinalize() line 1221 in src/sys/objects/D:\Library\PETSc\pe<br>tsc-3.2\src\sys\objects\pinit.c<br>Finalize 2<br>Initialize 3<br>
Options have not been enabled.<br>You might have forgotten to call PetscInitialize().<br><br>This application has requested the Runtime to terminate it in an unusual way.<br>Please contact the application's support team for more information.<br>
<br><br>Thanks,<br>Mengda<br><br>