Skip to content

remove C MPI wrapper function for MPI_Comm_rank #55

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 31, 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
17 changes: 15 additions & 2 deletions src/mpi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,24 @@ subroutine MPI_Barrier_proc(comm, ierror)
end subroutine MPI_Barrier_proc

subroutine MPI_Comm_rank_proc(comm, rank, ierror)
use mpi_c_bindings, only: c_mpi_comm_rank
use iso_c_binding, only: c_int, c_ptr
use mpi_c_bindings, only: c_mpi_comm_rank, c_mpi_comm_f2c
integer, intent(in) :: comm
integer, intent(out) :: rank
integer, optional, intent(out) :: ierror
call c_mpi_comm_rank(comm, rank, ierror)
type(c_ptr) :: c_comm
integer(c_int) :: local_ierr

c_comm = c_mpi_comm_f2c(comm)
local_ierr = c_mpi_comm_rank(c_comm, rank)

if (present(ierror)) then
ierror = local_ierr
else
if (local_ierr /= MPI_SUCCESS) then
print *, "MPI_Comm_rank failed with error code: ", local_ierr
end if
end if
end subroutine

subroutine MPI_Comm_split_type_proc(comm, split_type, key, info, newcomm, ierror)
Expand Down
10 changes: 5 additions & 5 deletions src/mpi_c_bindings.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ function c_mpi_barrier(comm) bind(C, name="MPI_Barrier")
integer(c_int) :: c_mpi_barrier
end function c_mpi_barrier

subroutine c_mpi_comm_rank(comm, rank, ierror) bind(C, name="mpi_comm_rank_wrapper")
use iso_c_binding, only: c_int
integer(c_int), intent(in) :: comm
function c_mpi_comm_rank(comm, rank) bind(C, name="MPI_Comm_rank")
use iso_c_binding, only: c_int, c_ptr
type(c_ptr), value :: comm
integer(c_int), intent(out) :: rank
integer(c_int), optional, intent(out) :: ierror
end subroutine
integer(c_int) :: c_mpi_comm_rank
end function c_mpi_comm_rank

subroutine c_mpi_comm_split_type(comm, split_type, key, info, newcomm, ierror) bind(C, name="mpi_comm_split_type_wrapper")
use iso_c_binding, only: c_int
Expand Down
10 changes: 0 additions & 10 deletions src/mpi_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,6 @@ void mpi_allreduce_wrapper_int(const int *sendbuf, int *recvbuf, int *count,
}
}

// void mpi_barrier_wrapper(int *comm_f, int *ierror) {
// MPI_Comm comm = MPI_Comm_f2c(*comm_f);
// *ierror = MPI_Barrier(comm);
// }

void mpi_comm_rank_wrapper(int *comm_f, int *rank, int *ierror) {
MPI_Comm comm = get_c_comm_from_fortran(*comm_f);
*ierror = MPI_Comm_rank(comm, rank);
}

void mpi_comm_split_type_wrapper(int *comm_f, int *split_type, int *key,
int *info_f, int *newcomm_f, int *ierror) {
MPI_Comm comm = get_c_comm_from_fortran(*comm_f);
Expand Down