comm_setup Subroutine

public subroutine comm_setup()

Arguments

None

Source Code

   subroutine comm_setup()
      ! internal
      character(len=*), parameter :: this_procedure = 'comm_setup'
      character(len=128) :: msg
#ifdef MPI
      integer :: ierr, nid, comm_size
      logical :: mpi_is_initialized
      ! check if MPI has already been initialized and if not, initialize
      call MPI_Initialized(mpi_is_initialized, ierr)
      if (.not. mpi_is_initialized) then
         call logger%log_message('Set up parallel run with MPI.', this_module, this_procedure)
         call MPI_Init(ierr)
         if (ierr /= MPI_SUCCESS) call stop_error("Error initializing MPI", this_module, this_procedure)
      else
         call logger%log_message('MPI already initialized.', this_module, this_procedure)
      end if
      call MPI_Comm_rank(MPI_COMM_WORLD, nid, ierr); call set_rank(nid)
      call MPI_Comm_size(MPI_COMM_WORLD, comm_size, ierr); call set_comm_size(comm_size)
      write (msg, '(A,I0,A,I0)') 'IO rank = ', nid, ', comm_size = ', comm_size
      call logger%log_message(trim(msg), this_module, this_procedure)
#else
      write (msg, '(A)') 'Setup serial run'
      call set_rank(0)
      call set_comm_size(1)
      call logger%log_message(trim(msg), this_module, this_procedure)
#endif
      return
   end subroutine comm_setup