1!
2! Copyright (C) by Argonne National Laboratory
3!     See COPYRIGHT in top-level directory
4!
5
6subroutine MPI_Win_set_errhandler_f08(win, errhandler, ierror)
7    use, intrinsic :: iso_c_binding, only : c_int
8    use :: mpi_f08, only : MPI_Win, MPI_Errhandler
9    use :: mpi_c_interface, only : c_Win, c_Errhandler
10    use :: mpi_c_interface, only : MPIR_Win_set_errhandler_c
11
12    implicit none
13
14    type(MPI_Win), intent(in) :: win
15    type(MPI_Errhandler), intent(in) :: errhandler
16    integer, optional, intent(out) :: ierror
17
18    integer(c_Win) :: win_c
19    integer(c_Errhandler) :: errhandler_c
20    integer(c_int) :: ierror_c
21
22    if (c_int == kind(0)) then
23        ierror_c = MPIR_Win_set_errhandler_c(win%MPI_VAL, errhandler%MPI_VAL)
24    else
25        win_c = win%MPI_VAL
26        errhandler_c = errhandler%MPI_VAL
27        ierror_c = MPIR_Win_set_errhandler_c(win_c, errhandler_c)
28    end if
29
30    if (present(ierror)) ierror = ierror_c
31
32end subroutine MPI_Win_set_errhandler_f08
33