diff --git a/src/DAMASK_spectral.f90 b/src/DAMASK_spectral.f90 index 87b00f12e..fe7d78621 100755 --- a/src/DAMASK_spectral.f90 +++ b/src/DAMASK_spectral.f90 @@ -831,6 +831,8 @@ subroutine quit(stop_id) call PETScFinalize(ierr) if (ierr /= 0) write(6,'(a)') ' Error in PETScFinalize' #ifdef _OPENMP + ! If openMP is enabled, MPI is initialized before and independently of PETSc. Hence, also + ! take care of the finalization call MPI_finalize(error) if (error /= 0) write(6,'(a)') ' Error in MPI_finalize' #endif diff --git a/src/spectral_interface.f90 b/src/spectral_interface.f90 index 3c8489d04..25421cc78 100644 --- a/src/spectral_interface.f90 +++ b/src/spectral_interface.f90 @@ -82,8 +82,10 @@ subroutine DAMASK_interface_init() !-------------------------------------------------------------------------------------------------- ! PETSc Init -#ifdef _OPENMP - call MPI_Init_Thread(MPI_THREAD_FUNNELED,threadLevel,ierr);CHKERRQ(ierr) ! in case of OpenMP, don't rely on PETScInitialize doing MPI init +#ifdef _OPENM + ! If openMP is enabled, check if the MPI libary supports it and initialize accordingly. + ! Otherwise, the first call to PETSc will do the initialization. + call MPI_Init_Thread(MPI_THREAD_FUNNELED,threadLevel,ierr);CHKERRQ(ierr) if (threadLevel