@@ -71,6 +71,10 @@ module mpi
7171 module procedure MPI_Comm_dup_proc
7272 end interface MPI_Comm_dup
7373
74+ interface MPi_Comm_free
75+ module procedure MPI_Comm_free_proc
76+ end interface MPI_Comm_free
77+
7478 interface MPI_Bcast
7579 module procedure MPI_Bcast_int_scalar
7680 module procedure MPI_Bcast_real_2D
@@ -435,7 +439,29 @@ subroutine MPI_Comm_dup_proc(comm, newcomm, ierror)
435439 print * , " MPI_Comm_dup failed with error code: " , local_ierr
436440 end if
437441 end if
438- end subroutine
442+ end subroutine MPI_Comm_dup_proc
443+
444+ subroutine MPI_Comm_free_proc (comm , ierror )
445+ use mpi_c_bindings, only: c_mpi_comm_free, c_mpi_comm_f2c
446+ integer , intent (inout ) :: comm
447+ integer , optional , intent (out ) :: ierror
448+ integer (kind= MPI_HANDLE_KIND) :: c_comm
449+ integer :: local_ierr
450+
451+ c_comm = handle_mpi_comm_f2c(comm)
452+ local_ierr = c_mpi_comm_free(c_comm)
453+ comm = handle_mpi_comm_c2f(c_comm)
454+
455+ if (present (ierror)) then
456+ ierror = local_ierr
457+ else
458+ if (local_ierr /= MPI_SUCCESS) then
459+ print * , " MPI_Comm_free failed with error code: " , local_ierr
460+ end if
461+ end if
462+
463+ comm = MPI_COMM_NULL ! Set to null after freeing
464+ end subroutine MPI_Comm_free_proc
439465
440466 subroutine MPI_Bcast_int_scalar (buffer , count , datatype , root , comm , ierror )
441467 use mpi_c_bindings, only: c_mpi_bcast
0 commit comments