Skip to content

refactor: move MPI_Finalize C wrapper to pure Fortran #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/mpi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ subroutine MPI_Finalize_proc(ierr)
use mpi_c_bindings, only: c_mpi_finalize
use iso_c_binding, only: c_int
integer, optional, intent(out) :: ierr
integer :: local_ierr
integer(c_int) :: local_ierr

!> assigns the status code to integer of kind 'c_int'
local_ierr = c_mpi_finalize()
if (present(ierr)) then
call c_mpi_finalize(ierr)
else
call c_mpi_finalize(local_ierr)
if (local_ierr /= 0) then
print *, "MPI_Finalize failed with error code: ", local_ierr
end if
!> we need to cast it to a Fortran integer, hence the use of 'int'
ierr = int(local_ierr)
else if (local_ierr /= 0) then
print *, "MPI_Finalize failed with error code: ", int(local_ierr)
end if
end subroutine

Expand Down
5 changes: 2 additions & 3 deletions src/mpi_c_bindings.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ subroutine c_mpi_init_thread(required, provided, ierr) bind(C, name="mpi_init_th
integer(c_int), intent(out) :: ierr
end subroutine c_mpi_init_thread

subroutine c_mpi_finalize(ierr) bind(C, name="mpi_finalize_wrapper")
integer(c_int) function c_mpi_finalize() bind(C, name="MPI_Finalize")
use iso_c_binding, only : c_int
integer(c_int), intent(out) :: ierr
end subroutine c_mpi_finalize
end function c_mpi_finalize

subroutine c_mpi_comm_size(comm, size, ierr) bind(C, name="mpi_comm_size_wrapper")
use iso_c_binding, only: c_int
Expand Down
4 changes: 0 additions & 4 deletions src/mpi_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ void mpi_init_thread_wrapper(int *required, int *provided, int *ierr) {
*ierr = MPI_Init_thread(&argc, &argv, thread_support, provided);
}

void mpi_finalize_wrapper(int *ierr) {
*ierr = MPI_Finalize();
}

void mpi_comm_size_wrapper(int *comm_f, int *size, int *ierr) {
MPI_Comm comm = MPI_Comm_f2c(*comm_f);
*ierr = MPI_Comm_size(comm, size);
Expand Down