Skip to content

Commit e5a3d7c

Browse files
committed
Apply code review
1 parent 81c2d04 commit e5a3d7c

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/mpi.f90

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ integer(kind=MPI_HANDLE_KIND) function handle_mpi_comm_f2c(comm_f) result(c_comm
185185
end if
186186
end function handle_mpi_comm_f2c
187187

188+
integer(kind=MPI_HANDLE_KIND) function handle_mpi_comm_c2f(comm_c) result(f_comm)
189+
use mpi_c_bindings, only: c_mpi_comm_c2f, c_mpi_comm_null
190+
integer(kind=mpi_handle_kind), intent(in) :: comm_c
191+
if (comm_c == c_mpi_comm_null) then
192+
f_comm = MPI_COMM_NULL
193+
else
194+
f_comm = c_mpi_comm_c2f(comm_c)
195+
end if
196+
end function handle_mpi_comm_c2f
197+
188198
integer(kind=MPI_HANDLE_KIND) function handle_mpi_info_f2c(info_f) result(c_info)
189199
use mpi_c_bindings, only: c_mpi_info_f2c, c_mpi_info_null
190200
integer, intent(in) :: info_f
@@ -396,11 +406,7 @@ subroutine MPI_Comm_create_proc(comm, group, newcomm, ierror)
396406
c_group = c_mpi_group_f2c(group)
397407
local_ierr = c_mpi_comm_create(c_comm, c_group, c_newcomm)
398408

399-
if (c_newcomm == c_mpi_comm_null) then
400-
newcomm = MPI_COMM_NULL
401-
else
402-
newcomm = c_mpi_comm_c2f(c_newcomm)
403-
end if
409+
newcomm = handle_mpi_comm_c2f(c_newcomm)
404410

405411
if (present(ierror)) then
406412
ierror = local_ierr

src/mpi_constants.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@ MPI_Status* c_MPI_STATUSES_IGNORE = MPI_STATUSES_IGNORE;
44

55
MPI_Info c_MPI_INFO_NULL = MPI_INFO_NULL;
66

7-
MPI_Comm c_MPI_COMM_WORLD = MPI_COMM_WORLD;
7+
void* c_MPI_IN_PLACE = MPI_IN_PLACE;
8+
9+
// DataType Declarations
810

911
MPI_Datatype c_MPI_DOUBLE = MPI_DOUBLE;
1012

1113
MPI_Datatype c_MPI_FLOAT = MPI_FLOAT;
1214

1315
MPI_Datatype c_MPI_INT = MPI_INT;
1416

15-
void* c_MPI_IN_PLACE = MPI_IN_PLACE;
17+
MPI_Datatype c_MPI_LOGICAL = MPI_LOGICAL;
18+
19+
MPI_Datatype c_MPI_CHARACTER = MPI_CHARACTER;
20+
21+
MPI_Datatype c_MPI_REAL = MPI_REAL;
22+
23+
// Operation Declarations
1624

1725
MPI_Op c_MPI_SUM = MPI_SUM;
1826

1927
MPI_Op c_MPI_MAX = MPI_MAX;
2028

21-
MPI_Datatype c_MPI_LOGICAL = MPI_LOGICAL;
22-
23-
MPI_Datatype c_MPI_CHARACTER = MPI_CHARACTER;
29+
// Communicators Declarations
2430

25-
MPI_Datatype c_MPI_REAL = MPI_REAL;
31+
MPI_Comm c_MPI_COMM_NULL = MPI_COMM_NULL;
2632

27-
MPI_Comm c_MPI_COMM_NULL = MPI_COMM_NULL;
33+
MPI_Comm c_MPI_COMM_WORLD = MPI_COMM_WORLD;

tests/comm_create_1.f90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ program minimal_mre_range
22
use mpi
33
implicit none
44

5-
integer :: ierr, rank, size
5+
integer :: ierr, rank, new_rank, size
66
integer :: group_world, group_range, new_comm
77
integer, dimension(1,3) :: range ! 1D array to define a single range
88
integer :: i
@@ -28,7 +28,9 @@ program minimal_mre_range
2828

2929
! Print participation
3030
if (new_comm /= MPI_COMM_NULL) then
31-
print *, 'Rank', rank, 'is in the new communicator.'
31+
call MPI_COMM_RANK(new_comm, new_rank, ierr)
32+
if (ierr /= MPI_SUCCESS) error stop "MPI_COMM_RANK on new_comm failed"
33+
print *, 'Global rank', rank, 'is in new_comm with local rank', new_rank
3234
else
3335
print *, 'Rank', rank, 'is NOT in the new communicator.'
3436
end if

0 commit comments

Comments
 (0)