!===============================================================================
!
! comm_shmempi.F90 - MPI + shmem on Altix
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2005-2006 Hinnerk Stueben
!
! This file is part of BQCD -- Berlin Quantum ChromoDynamics program
!
! BQCD is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! BQCD is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with BQCD.  If not, see <http://www.gnu.org/licenses/>.
!
!-------------------------------------------------------------------------------
# include "defs.h"

!-------------------------------------------------------------------------------
subroutine comm_init()

  implicit none
  include 'mpif.h'
  integer  ierror

  call mpi_init(ierror)
end

!-------------------------------------------------------------------------------
subroutine comm_finalize()

  implicit none
  include 'mpif.h'
  integer  ierror

  call mpi_finalize(ierror)
end

!-------------------------------------------------------------------------------
subroutine comm_abort()

  implicit none
  include 'mpif.h'
  integer ierror

  call mpi_abort(MPI_COMM_WORLD, 1, ierror)
end

!-------------------------------------------------------------------------------
COMM_METHOD function comm_method()

#ifdef _OPENMP
  comm_method = "shmem/MPI + OpenMP"
#else
  comm_method = "shmem/MPI"
#endif
end

!-------------------------------------------------------------------------------
subroutine comm_basic_test()  ! print MPI-size, -rank, -procesor_name, and my_coord 
                               
  use module_function_decl
  implicit none
  include 'mpif.h'
  integer :: size, rank, ierr
  integer :: len_name
  integer :: coord(DIM)

  character(MPI_MAX_PROCESSOR_NAME) :: name

  call mpi_comm_size(MPI_COMM_WORLD, size, ierr)
  call mpi_comm_rank(MPI_COMM_WORLD, rank, ierr)
  call mpi_get_processor_name(name, len_name, ierr)

  ASSERT(rank == my_pe())

  call my_coord(coord)

  write(STDERR, "(2(a,i5),2a,a,4i4)") &
        "comm_basic_test(): MPI: size = ", size, &
        " rank = ", rank, &
        " name = ", name(1:len_name), &
        " my_coord = ", coord

end

!===============================================================================
