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