@@ -71,6 +71,10 @@ module mpi
71
71
module procedure MPI_Comm_dup_proc
72
72
end interface MPI_Comm_dup
73
73
74
+ interface MPi_Comm_free
75
+ module procedure MPI_Comm_free_proc
76
+ end interface MPI_Comm_free
77
+
74
78
interface MPI_Bcast
75
79
module procedure MPI_Bcast_int_scalar
76
80
module procedure MPI_Bcast_real_2D
@@ -435,7 +439,29 @@ subroutine MPI_Comm_dup_proc(comm, newcomm, ierror)
435
439
print * , " MPI_Comm_dup failed with error code: " , local_ierr
436
440
end if
437
441
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
439
465
440
466
subroutine MPI_Bcast_int_scalar (buffer , count , datatype , root , comm , ierror )
441
467
use mpi_c_bindings, only: c_mpi_bcast
0 commit comments