Skip to content

Commit

Permalink
Merge pull request #87 from Nanoseb/fix-reordering-parallel
Browse files Browse the repository at this point in the history
Fix reordering in parallel
  • Loading branch information
Nanoseb committed May 14, 2024
2 parents 8024542 + 0940d01 commit 83bef11
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/omp/backend.f90
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,22 @@ subroutine reorder_omp(self, u_, u, direction)
select case (direction)
case (RDR_X2Y)
ndir_loc = self%xdirps%n
ndir_groups = self%xdirps%n_blocks
ndir_groups = self%allocator%xdims_padded(3)
case (RDR_X2Z)
ndir_loc = self%xdirps%n
ndir_groups = self%xdirps%n_blocks
ndir_groups = self%allocator%xdims_padded(3)
case (RDR_Y2X)
ndir_loc = self%ydirps%n
ndir_groups = self%ydirps%n_blocks
ndir_groups = self%allocator%ydims_padded(3)
case (RDR_Y2Z)
ndir_loc = self%ydirps%n
ndir_groups = self%ydirps%n_blocks
ndir_groups = self%allocator%ydims_padded(3)
case (RDR_Z2X)
ndir_loc = self%zdirps%n
ndir_groups = self%zdirps%n_blocks
ndir_groups = self%allocator%zdims_padded(3)
case (RDR_Z2Y)
ndir_loc = self%zdirps%n
ndir_groups = self%zdirps%n_blocks
ndir_groups = self%allocator%zdims_padded(3)
case default
ndir_loc = 0
ndir_groups = 0
Expand All @@ -346,8 +346,8 @@ subroutine reorder_omp(self, u_, u, direction)
do i = 1, SZ
call get_index_reordering( &
out_i, out_j, out_k, i, j, k, direction, &
SZ, self%xdirps%n, self%ydirps%n, self%zdirps%n &
)
SZ, self%allocator%xdims_padded(2), &
self%allocator%ydims_padded(2), self%allocator%zdims_padded(2))
u_%data(out_i, out_j, out_k) = u%data(i, j, k)
end do
end do
Expand Down
34 changes: 17 additions & 17 deletions src/ordering.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,63 @@ module m_ordering
!!

pure subroutine get_index_ijk(i, j, k, dir_i, dir_j, dir_k, dir, &
SZ, nx_loc, ny_loc, nz_loc)
SZ, nx_padded, ny_padded, nz_padded)
!! Get cartesian index from application storage directional one
integer, intent(out) :: i, j, k ! cartesian indices
integer, intent(in) :: dir_i, dir_j, dir_k ! application storage indices
integer, intent(in) :: dir ! direction of the applicatino storage indices
integer, intent(in) :: SZ, nx_loc, ny_loc, nz_loc ! dimensions of the block
integer, intent(in) :: SZ, nx_padded, ny_padded, nz_padded ! dimensions of the block

select case (dir)
case (DIR_X)
i = dir_j
j = mod(dir_k - 1, ny_loc/SZ)*SZ + dir_i
k = 1 + (dir_k - 1)/(ny_loc/SZ)
j = mod(dir_k - 1, ny_padded/SZ)*SZ + dir_i
k = 1 + (dir_k - 1)/(ny_padded/SZ)
case (DIR_Y)
i = mod(dir_k - 1, nx_loc/SZ)*SZ + dir_i
i = mod(dir_k - 1, nx_padded/SZ)*SZ + dir_i
j = dir_j
k = 1 + (dir_k - 1)/(nx_loc/SZ)
k = 1 + (dir_k - 1)/(nx_padded/SZ)
case (DIR_Z)
i = mod(dir_k - 1, nx_loc/SZ)*SZ + dir_i
j = 1 + (dir_k - 1)/(nx_loc/SZ)
i = mod(dir_k - 1, nx_padded/SZ)*SZ + dir_i
j = 1 + (dir_k - 1)/(nx_padded/SZ)
k = dir_j
end select

end subroutine get_index_ijk

pure subroutine get_index_dir(dir_i, dir_j, dir_k, i, j, k, dir, &
SZ, nx_loc, ny_loc, nz_loc)
SZ, nx_padded, ny_padded, nz_padded)
!! Get application storage directional index from cartesian index
integer, intent(out) :: dir_i, dir_j, dir_k ! application storage indices
integer, intent(in) :: i, j, k ! cartesian indices
integer, intent(in) :: dir ! direction of the application storage indices
integer, intent(in) :: SZ, nx_loc, ny_loc, nz_loc ! dimensions of the block
integer, intent(in) :: SZ, nx_padded, ny_padded, nz_padded ! dimensions of the block

select case (dir)
case (DIR_X)
dir_i = mod(j - 1, SZ) + 1
dir_j = i
dir_k = (ny_loc/SZ)*(k - 1) + 1 + (j - 1)/SZ
dir_k = (ny_padded/SZ)*(k - 1) + 1 + (j - 1)/SZ
case (DIR_Y)
dir_i = mod(i - 1, SZ) + 1
dir_j = j
dir_k = (nx_loc/SZ)*(k - 1) + 1 + (i - 1)/SZ
dir_k = (nx_padded/SZ)*(k - 1) + 1 + (i - 1)/SZ
case (DIR_Z)
dir_i = mod(i - 1, SZ) + 1
dir_j = k
dir_k = (nx_loc/SZ)*(j - 1) + 1 + (i - 1)/SZ
dir_k = (nx_padded/SZ)*(j - 1) + 1 + (i - 1)/SZ
end select

end subroutine get_index_dir

pure subroutine get_index_reordering(out_i, out_j, out_k, in_i, in_j, in_k, &
reorder_dir, SZ, nx_loc, ny_loc, nz_loc)
reorder_dir, SZ, nx_padded, ny_padded, nz_padded)
!! Converts a set of application storage directional index to an other direction.
!! The two directions are defined by the reorder_dir variable, RDR_X2Y will go from storage in X to Y etc.
integer, intent(out) :: out_i, out_j, out_k ! new indices in the application storage
integer, intent(in) :: in_i, in_j, in_k ! original indices
integer, intent(in) :: reorder_dir
integer, intent(in) :: SZ, nx_loc, ny_loc, nz_loc ! dimensions of the block
integer, intent(in) :: SZ, nx_padded, ny_padded, nz_padded ! dimensions of the block
integer :: i, j, k ! Intermediary cartesian indices
integer :: dir_in, dir_out

Expand All @@ -93,9 +93,9 @@ pure subroutine get_index_reordering(out_i, out_j, out_k, in_i, in_j, in_k, &
end select

call get_index_ijk(i, j, k, in_i, in_j, in_k, dir_in, &
SZ, nx_loc, ny_loc, nz_loc)
SZ, nx_padded, ny_padded, nz_padded)
call get_index_dir(out_i, out_j, out_k, i, j, k, dir_out, &
SZ, nx_loc, ny_loc, nz_loc)
SZ, nx_padded, ny_padded, nz_padded)

end subroutine get_index_reordering

Expand Down
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CTEST_NPROCS "4" CACHE STRING "number of process used in tests")

function(define_test testfile np backend)
get_filename_component(test_name ${testfile} NAME_WE)
string(CONCAT test_name ${test_name} _ ${backend})
string(CONCAT test_name ${test_name} _ ${backend} _ ${np})

add_executable(${test_name} ${testfile})

Expand All @@ -26,6 +26,8 @@ endfunction()

define_test(test_allocator.f90 1 omp)
define_test(test_reordering.f90 1 omp)
define_test(test_reordering.f90 2 omp)
define_test(test_reordering.f90 4 omp)
define_test(omp/test_omp_tridiag.f90 ${CMAKE_CTEST_NPROCS} omp)
define_test(omp/test_omp_transeq.f90 ${CMAKE_CTEST_NPROCS} omp)
define_test(omp/test_omp_dist_transeq.f90 ${CMAKE_CTEST_NPROCS} omp)
Expand Down
15 changes: 11 additions & 4 deletions tests/test_reordering.f90
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ program test_reorder
do j = 1, ydirps%n
do i = 1, xdirps%n
call test_index_reversing(pass_X, i, j, k, DIR_X, &
SZ, xdirps%n, ydirps%n, zdirps%n)
SZ, allocator%xdims_padded(2), &
allocator%ydims_padded(2), &
allocator%zdims_padded(2))
call test_index_reversing(pass_Y, i, j, k, DIR_Y, &
SZ, xdirps%n, ydirps%n, zdirps%n)
SZ, allocator%xdims_padded(2), &
allocator%ydims_padded(2), &
allocator%zdims_padded(2))
call test_index_reversing(pass_Z, i, j, k, DIR_Z, &
SZ, xdirps%n, ydirps%n, zdirps%n)
SZ, allocator%xdims_padded(2), &
allocator%ydims_padded(2), &
allocator%zdims_padded(2))
end do
end do
end do
Expand Down Expand Up @@ -215,7 +221,8 @@ subroutine check_reorder(allpass, a, b, message)
write (stderr, '(a)') message
end if
#else
if (norm2(a%data - b%data) > tol) then
if (norm2(a%data(1:SZ, 1:globs%nx_loc, 1:globs%n_groups_x) - &
b%data(1:SZ, 1:globs%nx_loc, 1:globs%n_groups_x)) > tol) then
allpass = .false.
write (stderr, '(a)') message
end if
Expand Down

0 comments on commit 83bef11

Please sign in to comment.