a problem with error of "An error occurred in MPI_Comm_rank after MPI was finalized"

Thomas Witkowski thomas.witkowski at tu-dresden.de
Mon Oct 12 01:34:49 CDT 2009


Put the functions PetscInitialize(...) and PetscFinalize() out of the 
function when using it in a loop. Both functions have to be called only 
once in your program.

Thomas

Yin Feng wrote:
> I put PETSc solver in one function and use another function to call that.
> This problem only appears when I put the function with PETSc solver in 
> a loop,
> it works well at first step, and reports error "An error occurred in 
> MPI_Comm_rank after MPI was finalized"
> at second time. The program is designed to support only one processor 
> like:
>
> Vec            x,b;
>
> Mat            A;
>
> KSP            ksp;
>
> PC             pc;
>
> PetscInt       i,j,col[N];
>
> PetscScalar    value[N];
>
> PetscScalar    val;
>
>
> PetscInitialize(PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL);
>
> VecCreate(PETSC_COMM_WORLD,&x);
>
> VecSetSizes(x,PETSC_DECIDE,N);
>
> VecSetFromOptions(x);
>
> VecDuplicate(x,&b);
>
> MatCreate(PETSC_COMM_WORLD,&A);
>
> MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
>
> MatSetFromOptions(A);
>
>         ........
>
>         ........
>
> KSPCreate(PETSC_COMM_WORLD,&ksp);
>
> KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);
>
> KSPGetPC(ksp,&pc);
>
>         ................
>         ...............
>
>        
>  KSPSetTolerances(ksp,tol,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);
>
>         KSPSetFromOptions(ksp);
>
>         KSPSolve(ksp,b,x);
>
>
>         VecDestroy(x);
>
>         VecDestroy(b);
>
>         MatDestroy(A);
>
>         KSPDestroy(ksp);
>
>         PetscFinalize();
>
>
> Any one has ideal about this? 
>
> The detailed error description is:
>
> An error occurred in MPI_Comm_rank
>
> *** after MPI was finalized
>
> *** MPI_ERRORS_ARE_FATAL (goodbye)
>
> Abort before MPI_INIT completed successfully; not able to guarantee 
> that all other processes were killed!
>
>
> Thank you so much in advance!
>



More information about the petsc-users mailing list