pic_mpi_init Subroutine

public subroutine pic_mpi_init(requested_thread_level, provided_thread_level)

Initialize MPI environment with optional threading support

If no thread level is requested, uses MPI_THREAD_FUNNELED by default to allow OpenMP threading in compute_mbe_energy and similar functions.

Thread levels: MPI_THREAD_SINGLE: No threading support MPI_THREAD_FUNNELED: Only main thread makes MPI calls (good for OpenMP) MPI_THREAD_SERIALIZED: Multiple threads can make MPI calls, but not simultaneously MPI_THREAD_MULTIPLE: Full thread safety

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in), optional :: requested_thread_level
integer(kind=int32), intent(out), optional :: provided_thread_level

Calls

proc~~pic_mpi_init~2~~CallsGraph proc~pic_mpi_init~2 pic_mpi_init mpi_init_thread mpi_init_thread proc~pic_mpi_init~2->mpi_init_thread

Variables

Type Visibility Attributes Name Initial
integer(kind=int32), private :: ierr
integer(kind=int32), private :: provided
integer(kind=int32), private :: requested

Source Code

   subroutine pic_mpi_init(requested_thread_level, provided_thread_level)
      !! Initialize MPI environment with optional threading support
      !!
      !! If no thread level is requested, uses MPI_THREAD_FUNNELED by default
      !! to allow OpenMP threading in compute_mbe_energy and similar functions.
      !!
      !! Thread levels:
      !!   MPI_THREAD_SINGLE: No threading support
      !!   MPI_THREAD_FUNNELED: Only main thread makes MPI calls (good for OpenMP)
      !!   MPI_THREAD_SERIALIZED: Multiple threads can make MPI calls, but not simultaneously
      !!   MPI_THREAD_MULTIPLE: Full thread safety
      integer(int32), intent(in), optional :: requested_thread_level
      integer(int32), intent(out), optional :: provided_thread_level
      integer(int32) :: ierr, requested, provided

      ! Default to FUNNELED for OpenMP compatibility
      if (present(requested_thread_level)) then
         requested = requested_thread_level
      else
         requested = MPI_THREAD_FUNNELED
      end if

      call MPI_Init_thread(requested, provided, ierr)

      ! Return the provided level if requested
      if (present(provided_thread_level)) then
         provided_thread_level = provided
      end if

      ! Warn if we didn't get what we asked for
      if (provided < requested .and. requested /= MPI_THREAD_SINGLE) then
         if (requested == MPI_THREAD_FUNNELED) then
            write (*, '(a)') "Warning: MPI_THREAD_FUNNELED requested but not provided."
            write (*, '(a)') "OpenMP threading in compute functions may not work correctly."
         else if (requested == MPI_THREAD_SERIALIZED) then
            write (*, '(a)') "Warning: MPI_THREAD_SERIALIZED requested but not provided."
         else if (requested == MPI_THREAD_MULTIPLE) then
            write (*, '(a)') "Warning: MPI_THREAD_MULTIPLE requested but not provided."
         end if
      end if
   end subroutine pic_mpi_init