Finalise 1 library if it hasn't been finalised already
subroutine finish_mp
#ifdef MPI
# ifdef SHMEM
use shm_mpi3, only : shm_clean
# endif
implicit none
integer :: ierror
logical :: fin
# ifdef SHMEM
call shm_clean
# endif
call mpi_finalized (fin, ierror)
if(.not.fin) call mpi_finalize (ierror)
#endif
mp_initialized = .false.
end subroutine finish_mp