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
Add support for scalar product operator #67
Changes from all commits
9129656
11608d4
ce7b3f8
030f382
ed12712
ce9289f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,27 @@ attributes(global) subroutine axpby(n, alpha, x, beta, y) | |
|
||
end subroutine axpby | ||
|
||
attributes(global) subroutine scalar_product(s, x, y, n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caller needs to understand this is pencil sum to set correct n_threads/blocks. This should be documented here. |
||
implicit none | ||
|
||
real(dp), device, intent(inout) :: s | ||
real(dp), device, intent(in), dimension(:, :, :) :: x, y | ||
integer, value, intent(in) :: n | ||
|
||
real(dp) :: s_pncl !! pencil sum | ||
integer :: i, j, b, ierr | ||
|
||
i = threadIdx%x | ||
b = blockIdx%x | ||
|
||
s_pncl = 0._dp | ||
do j = 1, n | ||
s_pncl = s_pncl + x(i, j, b)*y(i, j, b) | ||
end do | ||
ierr = atomicadd(s, s_pncl) | ||
|
||
end subroutine scalar_product | ||
|
||
attributes(global) subroutine buffer_copy(u_send_s, u_send_e, u, n, n_halo) | ||
implicit none | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -30,8 +30,9 @@ module m_omp_backend | |||||||
procedure :: sum_yintox => sum_yintox_omp | ||||||||
procedure :: sum_zintox => sum_zintox_omp | ||||||||
procedure :: vecadd => vecadd_omp | ||||||||
procedure :: set_fields => set_fields_omp | ||||||||
procedure :: get_fields => get_fields_omp | ||||||||
procedure :: scalar_product => scalar_product_omp | ||||||||
procedure :: set_field => set_field_omp | ||||||||
procedure :: get_field => get_field_omp | ||||||||
procedure :: transeq_omp_dist | ||||||||
end type omp_backend_t | ||||||||
|
||||||||
|
@@ -304,6 +305,16 @@ subroutine vecadd_omp(self, a, x, b, y) | |||||||
|
||||||||
end subroutine vecadd_omp | ||||||||
|
||||||||
real(dp) function scalar_product_omp(self, x, y) result(s) | ||||||||
implicit none | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
class(omp_backend_t) :: self | ||||||||
class(field_t), intent(in) :: x, y | ||||||||
|
||||||||
s = 0._dp | ||||||||
|
||||||||
end function scalar_product_omp | ||||||||
|
||||||||
subroutine copy_into_buffers(u_send_s, u_send_e, u, n, n_blocks) | ||||||||
implicit none | ||||||||
|
||||||||
|
@@ -329,31 +340,27 @@ subroutine copy_into_buffers(u_send_s, u_send_e, u, n, n_blocks) | |||||||
|
||||||||
end subroutine copy_into_buffers | ||||||||
|
||||||||
subroutine set_fields_omp(self, u, v, w, u_in, v_in, w_in) | ||||||||
subroutine set_field_omp(self, f, arr) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear argument names. Perhaps |
||||||||
implicit none | ||||||||
|
||||||||
class(omp_backend_t) :: self | ||||||||
class(field_t), intent(inout) :: u, v, w | ||||||||
real(dp), dimension(:, :, :), intent(in) :: u_in, v_in, w_in | ||||||||
class(field_t), intent(inout) :: f | ||||||||
real(dp), dimension(:, :, :), intent(in) :: arr | ||||||||
|
||||||||
u%data = u_in | ||||||||
v%data = v_in | ||||||||
w%data = w_in | ||||||||
f%data = arr | ||||||||
|
||||||||
end subroutine set_fields_omp | ||||||||
end subroutine set_field_omp | ||||||||
|
||||||||
subroutine get_fields_omp(self, u_out, v_out, w_out, u, v, w) | ||||||||
subroutine get_field_omp(self, arr, f) | ||||||||
implicit none | ||||||||
|
||||||||
class(omp_backend_t) :: self | ||||||||
real(dp), dimension(:, :, :), intent(out) :: u_out, v_out, w_out | ||||||||
class(field_t), intent(in) :: u, v, w | ||||||||
real(dp), dimension(:, :, :), intent(out) :: arr | ||||||||
class(field_t), intent(in) :: f | ||||||||
|
||||||||
u_out = u%data | ||||||||
v_out = v%data | ||||||||
w_out = w%data | ||||||||
arr = f%data | ||||||||
|
||||||||
end subroutine get_fields_omp | ||||||||
end subroutine get_field_omp | ||||||||
|
||||||||
end module m_omp_backend | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're thinking about mixed/reduced precision, should the precision passed to MPI derive from the actual data type? Not sure what the typical way to do this is in MPI codes. @pbartholomew08, @Nanoseb?