forked from ornladios/ADIOS2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fortran example using MPI and Kokkos
- Loading branch information
1 parent
519be77
commit 71ad750
Showing
4 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
examples/hello/bpStepsWriteReadKokkos/bpStepsWriteReadKokkos.F90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
program TestBPWriteReadHeatMap2D use mpi use adios2 | ||
|
||
implicit none | ||
|
||
integer(kind = 8)::sum_i1, | ||
sum_i2 type(adios2_adios)::adios type(adios2_io)::ioPut, ioGet type(adios2_engine)::bpWriter, | ||
bpReader type(adios2_variable), dimension(1)::var_g, | ||
var_gIn | ||
|
||
integer(kind = 2), | ||
dimension( | ||
:, | ||
:), | ||
allocatable ::g, &sel_g integer(kind = 8), | ||
dimension(2)::ishape, istart, icount integer(kind = 8), | ||
dimension(2)::sel_start, sel_count integer ::ierr, irank, isize, | ||
step_status integer ::in1, in2 integer ::i1, | ||
i2 | ||
|
||
call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, irank, ierr) call | ||
MPI_COMM_SIZE(MPI_COMM_WORLD, isize, ierr) | ||
|
||
in1 = 3 in2 = 4 icount = (/ in1, in2 /) istart = (/ 0, in2 *irank /) ishape = (/ in1, | ||
in2 *isize /) | ||
|
||
allocate(g(in1, in2)) do i2 = 1, | ||
in2 do i1 = 1, | ||
in1 g(i1, i2) = irank + i1 end do end do | ||
|
||
!Start adios2 Writer call adios2_init(adios, MPI_COMM_WORLD, ierr) call | ||
adios2_declare_io(ioPut, adios, 'WriteIO', ierr) | ||
|
||
call adios2_define_variable(var_g(1), ioPut, &'bpFloats', | ||
adios2_type_integer2, &2, ishape, istart, | ||
icount, &adios2_constant_dims, ierr) | ||
|
||
call | ||
adios2_open(bpWriter, ioPut, 'BPFortranKokkos.bp', adios2_mode_write, &ierr) | ||
|
||
call adios2_put(bpWriter, var_g(1), g, ierr) | ||
|
||
call adios2_close(bpWriter, ierr) | ||
|
||
if (allocated(g)) deallocate(g) | ||
|
||
!Start adios2 Reader in rank 0 if (irank == 0) then | ||
|
||
call adios2_declare_io(ioGet, adios, 'ReadIO', ierr) | ||
|
||
call adios2_open(bpReader, ioGet, 'BPFortranKokkos.bp', | ||
&adios2_mode_read, MPI_COMM_SELF, ierr) | ||
|
||
call | ||
adios2_begin_step(bpReader, adios2_step_mode_read, -1., &step_status, ierr) | ||
|
||
call adios2_inquire_variable(var_gIn(1), ioGet, &'bpFloats', ierr) | ||
|
||
sel_start = (/ 0, 0 /) sel_count = (/ ishape(1), ishape(2) /) | ||
|
||
allocate(sel_g(ishape(1), ishape(2))) sel_g = 0 | ||
|
||
call adios2_set_selection(var_gIn(1), 2, sel_start, sel_count, &ierr) call | ||
adios2_get(bpReader, var_gIn(1), sel_g, ierr) | ||
|
||
call adios2_end_step(bpReader, ierr) | ||
|
||
call adios2_close(bpReader, ierr) | ||
|
||
do i2 = 1, | ||
INT(sel_count(2), 4) do i1 = 1, | ||
INT(sel_count(1), 4) write(6, "(i8)", advance = "no") sel_g(i1, i2) end do write(6, *) end | ||
do | ||
|
||
if (allocated(sel_g)) deallocate(sel_g) | ||
|
||
end if | ||
|
||
call adios2_finalize(adios, ierr) call MPI_Finalize(ierr) | ||
|
||
end program TestBPWriteReadHeatMap2D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "flcl-cxx.hpp" | ||
#include <Kokkos_Core.hpp> | ||
|
||
using view_type = flcl::view_i32_2d_t; | ||
|
||
extern "C" { | ||
|
||
void c_init_view(view_type **v_x, int *val) | ||
{ | ||
using flcl::view_from_ndarray; | ||
|
||
view_type x = **v_x; | ||
int d_val = *val; | ||
Kokkos::parallel_for("initBuffer", x.extent(1), KOKKOS_LAMBDA(const size_t idy) { | ||
for (size_t idx = 0; idx < x.extent(0); idx++) | ||
x(idx, idy) = d_val + idx; | ||
}); | ||
Kokkos::fence(); | ||
|
||
return; | ||
} | ||
|
||
void c_print_view(view_type **v_x) | ||
{ | ||
using flcl::view_from_ndarray; | ||
|
||
view_type x = **v_x; | ||
|
||
Kokkos::parallel_for("printBuffer", 1, KOKKOS_LAMBDA(const size_t id) { | ||
for (size_t idx = 0; idx < x.extent(0); idx++) | ||
{ | ||
for (size_t idy = 0; idy < x.extent(1); idy++) | ||
Kokkos::printf("%d ", x(idx, idy)); | ||
Kokkos::printf("\n"); | ||
} | ||
}); | ||
Kokkos::fence(); | ||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module view_f_mod use, intrinsic ::iso_c_binding use, | ||
intrinsic ::iso_fortran_env | ||
|
||
use ::flcl_mod | ||
|
||
implicit none | ||
|
||
public | ||
|
||
interface subroutine f_init_view(x, val) & | ||
&bind(c, name = 'c_init_view') use, | ||
intrinsic ::iso_c_binding use ::flcl_mod type(c_ptr), intent(in)::x integer(c_int), | ||
intent(in)::val end subroutine f_init_view | ||
|
||
subroutine f_print_view(x) & | ||
&bind(c, name = 'c_print_view') use, | ||
intrinsic ::iso_c_binding use ::flcl_mod type(c_ptr), | ||
intent(in)::x end subroutine f_print_view end interface | ||
|
||
contains | ||
|
||
subroutine init_view(x, val) use, | ||
intrinsic ::iso_c_binding use ::flcl_mod implicit none type(view_i32_2d_t), | ||
intent(inout)::x integer(c_int), | ||
intent(in)::val | ||
|
||
call f_init_view(x % ptr(), val) | ||
|
||
end subroutine init_view | ||
|
||
subroutine print_view(x) use, | ||
intrinsic ::iso_c_binding use ::flcl_mod implicit none type(view_i32_2d_t), | ||
intent(in)::x | ||
|
||
call f_print_view(x % ptr()) | ||
|
||
end subroutine print_view | ||
|
||
end module view_f_mod |