Skip to content

Commit

Permalink
Merge pull request #51 from terminationshock/support_int64_address_kind
Browse files Browse the repository at this point in the history
Pass int64 type to mpifx_win_allocate_shared
  • Loading branch information
bhourahine authored Oct 25, 2023
2 parents 5bcb24c + e4d4566 commit fa41668
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/mpifx_constants.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module mpifx_constants_module
public :: MPI_MODE_NOSTORE, MPI_MODE_NOPUT, MPI_MODE_NOPRECEDE, MPI_MODE_NOSUCCEED
public :: MPI_THREAD_SINGLE, MPI_THREAD_FUNNELED, MPI_THREAD_SERIALIZED, MPI_THREAD_MULTIPLE
public :: MPI_COMM_TYPE_SHARED
public :: MPIFX_UNHANDLED_ERROR, MPIFX_ASSERT_FAILED
public :: MPIFX_UNHANDLED_ERROR, MPIFX_ASSERT_FAILED, MPIFX_SIZE_T


!> Exit code for errors which were not caught due to missing optional arguments
Expand All @@ -19,6 +19,8 @@ module mpifx_constants_module
!> Exit code for failed assertions
integer, parameter :: MPIFX_ASSERT_FAILED = 2

integer, parameter :: MPIFX_SIZE_T = MPI_ADDRESS_KIND

end module mpifx_constants_module

!> \endcond
22 changes: 15 additions & 7 deletions lib/mpifx_win.fpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#:include 'mpifx.fypp'
#:set TYPES = NUMERIC_TYPES
#:set INT_TYPES = ['int32', 'int64']

!> Contains routined for MPI shared memory windows.
module mpifx_win_module
use mpifx_common_module
use mpifx_constants_module, only : MPIFX_SIZE_T
use iso_c_binding, only : c_ptr, c_f_pointer
implicit none
private
Expand All @@ -18,11 +20,15 @@ module mpifx_win_module
contains
!> Initializes an MPI shared memory window.
#:for TYPE in TYPES
generic :: allocate_shared => mpifx_win_allocate_shared_${TYPE_ABBREVS[TYPE]}$
#:for INT_TYPE in INT_TYPES
generic :: allocate_shared => mpifx_win_allocate_shared_${TYPE_ABBREVS[TYPE]}$_${INT_TYPE}$
#:endfor
#:endfor

#:for TYPE in TYPES
procedure, private :: mpifx_win_allocate_shared_${TYPE_ABBREVS[TYPE]}$
#:for INT_TYPE in INT_TYPES
procedure, private :: mpifx_win_allocate_shared_${TYPE_ABBREVS[TYPE]}$_${INT_TYPE}$
#:endfor
#:endfor

!> Locks a shared memory segment for remote access.
Expand All @@ -44,7 +50,7 @@ module mpifx_win_module

contains

#:def mpifx_win_allocate_shared_template(SUFFIX, TYPE)
#:def mpifx_win_allocate_shared_template(SUFFIX, TYPE, ADDRESS_KIND)

!> Initialized a window handle and returns a pointer to the address associated with a shared
!> memory segment.
Expand All @@ -64,9 +70,9 @@ contains
& local_length, local_pointer, error)
class(mpifx_win), intent(out) :: self
class(mpifx_comm), intent(in) :: mycomm
integer, intent(in) :: global_length
integer${ADDRESS_KIND}$, intent(in) :: global_length
${TYPE}$, pointer, intent(out) :: global_pointer(:)
integer, intent(in), optional :: local_length
integer${ADDRESS_KIND}$, intent(in), optional :: local_length
${TYPE}$, pointer, intent(out), optional :: local_pointer(:)
integer, intent(out), optional :: error

Expand Down Expand Up @@ -211,9 +217,11 @@ contains

#:for TYPE in TYPES
#:set FTYPE = FORTRAN_TYPES[TYPE]
#:set SUFFIX = TYPE_ABBREVS[TYPE]

$:mpifx_win_allocate_shared_template(SUFFIX, FTYPE)
#:for ADDRESS_KIND, INT_TYPE in zip(['', '(MPIFX_SIZE_T)'], INT_TYPES)
#:set SUFFIX = TYPE_ABBREVS[TYPE] + '_' + INT_TYPE
$:mpifx_win_allocate_shared_template(SUFFIX, FTYPE, ADDRESS_KIND)
#:endfor

#:endfor

Expand Down
11 changes: 10 additions & 1 deletion test/test_win_shared_mem.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ program test_win_shared_mem
type(mpifx_comm) :: globalcomm, nodecomm
type(mpifx_win) :: win
integer, parameter :: sample_value = 42, size_rank_0 = 7, size_rank_other = 4
integer :: global_length, local_length, rank, ii
integer(MPIFX_SIZE_T) :: global_length, local_length
integer :: global_length_int32, local_length_int32
integer :: rank, ii
integer, pointer :: global_pointer(:), local_pointer(:)

call mpifx_init()
Expand Down Expand Up @@ -77,6 +79,13 @@ program test_win_shared_mem
end if
end do

call win%free()

! Initialize again with int32 sizes
global_length_int32 = global_length
local_length_int32 = local_length
call win%allocate_shared(nodecomm, global_length_int32, global_pointer, local_length_int32, local_pointer)

call win%free()
call mpifx_finalize()

Expand Down

0 comments on commit fa41668

Please sign in to comment.