Skip to content

Commit 42a3875

Browse files
committed
UVM and down sample
1 parent c933e72 commit 42a3875

23 files changed

+828
-195
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,12 @@ function(MFC_SETUP_TARGET)
506506
)
507507
endif()
508508
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
509+
# Frontier Unified Memory Support
510+
if (MFC_Unified)
511+
target_compile_options(${ARGS_TARGET}
512+
PRIVATE -DFRONTIER_UNIFIED)
513+
endif()
514+
509515
find_package(hipfort COMPONENTS hip CONFIG REQUIRED)
510516
target_link_libraries(${a_target} PRIVATE hipfort::hip hipfort::hipfort-amdgcn)
511517
endif()

src/common/m_helper.fpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module m_helper
3737
double_factorial, &
3838
factorial, &
3939
f_cut_on, &
40-
f_cut_off
40+
f_cut_off, &
41+
s_downsample_data
4142

4243
contains
4344

@@ -625,4 +626,49 @@ contains
625626
626627
end function f_gx
627628
629+
subroutine s_downsample_data(q_cons_vf, q_cons_temp, m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds)
630+
631+
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf, q_cons_temp
632+
633+
! Down sampling variables
634+
integer :: i, j, k, l
635+
integer :: ix, iy, iz, x_id, y_id, z_id
636+
integer, intent(inout) :: m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds
637+
638+
m_ds = INT((m+1)/3) - 1
639+
n_ds = INT((n+1)/3) - 1
640+
p_ds = INT((p+1)/3) - 1
641+
642+
m_glb_ds = INT((m_glb+1)/3) - 1
643+
n_glb_ds = INT((n_glb+1)/3) - 1
644+
p_glb_ds = INT((p_glb+1)/3) - 1
645+
646+
do i = 1, sys_size
647+
$:GPU_UPDATE(host='[q_cons_vf(i)%sf]')
648+
end do
649+
650+
do l = -1, p_ds+1
651+
do k = -1, n_ds+1
652+
do j = -1, m_ds+1
653+
x_id = 3*j + 1
654+
y_id = 3*k + 1
655+
z_id = 3*l + 1
656+
do i = 1, sys_size
657+
q_cons_temp(i)%sf(j,k,l) = 0
658+
659+
do iz = -1, 1
660+
do iy = -1, 1
661+
do ix = -1, 1
662+
q_cons_temp(i)%sf(j,k,l) = q_cons_temp(i)%sf(j,k,l) &
663+
+ (1._wp / 27._wp)*q_cons_vf(i)%sf(x_id+ix,y_id+iy,z_id+iz)
664+
end do
665+
end do
666+
end do
667+
end do
668+
end do
669+
end do
670+
end do
671+
672+
end subroutine s_downsample_data
673+
628674
end module m_helper

src/common/m_mpi_common.fpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,57 @@ contains
282282
283283
end subroutine s_initialize_mpi_data
284284
285+
!! @param q_cons_vf Conservative variables
286+
subroutine s_initialize_mpi_data_ds(q_cons_vf)
287+
288+
type(scalar_field), &
289+
dimension(sys_size), &
290+
intent(in) :: q_cons_vf
291+
292+
integer, dimension(num_dims) :: sizes_glb, sizes_loc
293+
integer, dimension(3) :: sf_start_idx
294+
295+
#ifdef MFC_MPI
296+
297+
! Generic loop iterator
298+
integer :: i, j, q, k, l, m_ds, n_ds, p_ds, ierr
299+
300+
sf_start_idx = (/0, 0, 0/)
301+
302+
#ifndef MFC_POST_PROCESS
303+
m_ds = INT((m+1)/3) - 1
304+
n_ds = INT((n+1)/3) - 1
305+
p_ds = INT((p+1)/3) - 1
306+
#else
307+
m_ds = m
308+
n_ds = n
309+
p_ds = p
310+
#endif
311+
312+
#ifdef MFC_POST_PROCESS
313+
do i = 1, sys_size
314+
MPI_IO_DATA%var(i)%sf => q_cons_vf(i)%sf(-1:m_ds+1, -1:n_ds+1, -1:p_ds+1)
315+
end do
316+
#endif
317+
! Define global(g) and local(l) sizes for flow variables
318+
sizes_loc(1) = m_ds + 3
319+
if (n > 0) then
320+
sizes_loc(2) = n_ds + 3
321+
if (p > 0) then
322+
sizes_loc(3) = p_ds + 3
323+
end if
324+
end if
325+
326+
! Define the view for each variable
327+
do i = 1, sys_size
328+
call MPI_TYPE_CREATE_SUBARRAY(num_dims, sizes_loc, sizes_loc, sf_start_idx, &
329+
MPI_ORDER_FORTRAN, mpi_p, MPI_IO_DATA%view(i), ierr)
330+
call MPI_TYPE_COMMIT(MPI_IO_DATA%view(i), ierr)
331+
end do
332+
#endif
333+
334+
end subroutine s_initialize_mpi_data_ds
335+
285336
impure subroutine s_mpi_gather_data(my_vector, counts, gathered_vector, root)
286337
287338
integer, intent(in) :: counts ! Array of vector lengths for each process

src/common/m_variables_conversion.fpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ contains
392392
if (igr) then
393393
if (num_fluids == 1) then
394394
alpha_rho_K(1) = q_vf(contxb)%sf(k, l, r)
395-
alpha_K(1) = q_vf(advxb)%sf(k, l, r)
395+
alpha_K(1) = 1._wp
396396
else
397397
do i = 1, num_fluids - 1
398398
alpha_rho_K(i) = q_vf(i)%sf(k, l, r)
@@ -884,7 +884,7 @@ contains
884884
if (igr) then
885885
if (num_fluids == 1) then
886886
alpha_rho_K(1) = qK_cons_vf(contxb)%sf(j, k, l)
887-
alpha_K(1) = qK_cons_vf(advxb)%sf(j, k, l)
887+
alpha_K(1) = 1._wp
888888
else
889889
$:GPU_LOOP(parallelism='[seq]')
890890
do i = 1, num_fluids - 1
@@ -1223,10 +1223,12 @@ contains
12231223
call s_convert_to_mixture_variables(q_prim_vf, j, k, l, &
12241224
rho, gamma, pi_inf, qv, Re_K, G, fluid_pp(:)%G)
12251225

1226-
! Transferring the advection equation(s) variable(s)
1227-
do i = adv_idx%beg, adv_idx%end
1228-
q_cons_vf(i)%sf(j, k, l) = q_prim_vf(i)%sf(j, k, l)
1229-
end do
1226+
if (.not. igr .or. num_fluids > 1) then
1227+
! Transferring the advection equation(s) variable(s)
1228+
do i = adv_idx%beg, adv_idx%end
1229+
q_cons_vf(i)%sf(j, k, l) = q_prim_vf(i)%sf(j, k, l)
1230+
end do
1231+
end if
12301232

12311233
if (relativity) then
12321234

src/post_process/m_data_input.f90

Lines changed: 107 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ end subroutine s_read_abstract_data_files
5050
type(scalar_field), allocatable, dimension(:), public :: q_cons_vf !<
5151
!! Conservative variables
5252

53+
type(scalar_field), allocatable, dimension(:), public :: q_cons_temp
54+
5355
type(scalar_field), allocatable, dimension(:), public :: q_prim_vf !<
5456
!! Primitive variables
5557

@@ -340,6 +342,7 @@ impure subroutine s_read_parallel_data_files(t_step)
340342
integer(KIND=MPI_OFFSET_KIND) :: WP_MOK, var_MOK, str_MOK
341343
integer(KIND=MPI_OFFSET_KIND) :: NVARS_MOK
342344
integer(KIND=MPI_OFFSET_KIND) :: MOK
345+
real(wp) :: delx, dely, delz
343346

344347
character(LEN=path_len + 2*name_len) :: file_loc
345348
logical :: file_exist
@@ -352,17 +355,25 @@ impure subroutine s_read_parallel_data_files(t_step)
352355
allocate (y_cb_glb(-1:n_glb))
353356
allocate (z_cb_glb(-1:p_glb))
354357

355-
! Read in cell boundary locations in x-direction
356-
file_loc = trim(case_dir)//'/restart_data'//trim(mpiiofs)//'x_cb.dat'
357-
inquire (FILE=trim(file_loc), EXIST=file_exist)
358-
359-
if (file_exist) then
360-
data_size = m_glb + 2
361-
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
362-
call MPI_FILE_READ(ifile, x_cb_glb, data_size, mpi_p, status, ierr)
363-
call MPI_FILE_CLOSE(ifile, ierr)
358+
if(down_sample) then
359+
delx = (x_domain%end - x_domain%beg)/real(m_glb + 1, wp)
360+
do i = 0, m_glb
361+
x_cb_glb(i - 1) = x_domain%beg + delx*real(i, wp)
362+
end do
363+
x_cb_glb(m_glb) = x_domain%end
364364
else
365-
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
365+
! Read in cell boundary locations in x-direction
366+
file_loc = trim(case_dir)//'/restart_data'//trim(mpiiofs)//'x_cb.dat'
367+
inquire (FILE=trim(file_loc), EXIST=file_exist)
368+
369+
if (file_exist) then
370+
data_size = m_glb + 2
371+
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
372+
call MPI_FILE_READ(ifile, x_cb_glb, data_size, mpi_p, status, ierr)
373+
call MPI_FILE_CLOSE(ifile, ierr)
374+
else
375+
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
376+
end if
366377
end if
367378

368379
! Assigning local cell boundary locations
@@ -373,17 +384,25 @@ impure subroutine s_read_parallel_data_files(t_step)
373384
x_cc(0:m) = x_cb(-1:m - 1) + dx(0:m)/2._wp
374385

375386
if (n > 0) then
376-
! Read in cell boundary locations in y-direction
377-
file_loc = trim(case_dir)//'/restart_data'//trim(mpiiofs)//'y_cb.dat'
378-
inquire (FILE=trim(file_loc), EXIST=file_exist)
379-
380-
if (file_exist) then
381-
data_size = n_glb + 2
382-
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
383-
call MPI_FILE_READ(ifile, y_cb_glb, data_size, mpi_p, status, ierr)
384-
call MPI_FILE_CLOSE(ifile, ierr)
387+
if(down_sample) then
388+
dely = (y_domain%end - y_domain%beg)/real(n_glb + 1, wp)
389+
do i = 0, n_glb
390+
y_cb_glb(i - 1) = y_domain%beg + dely*real(i, wp)
391+
end do
392+
y_cb_glb(n_glb) = y_domain%end
385393
else
386-
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
394+
! Read in cell boundary locations in y-direction
395+
file_loc = trim(case_dir)//'/restart_data'//trim(mpiiofs)//'y_cb.dat'
396+
inquire (FILE=trim(file_loc), EXIST=file_exist)
397+
398+
if (file_exist) then
399+
data_size = n_glb + 2
400+
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
401+
call MPI_FILE_READ(ifile, y_cb_glb, data_size, mpi_p, status, ierr)
402+
call MPI_FILE_CLOSE(ifile, ierr)
403+
else
404+
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
405+
end if
387406
end if
388407

389408
! Assigning local cell boundary locations
@@ -394,17 +413,25 @@ impure subroutine s_read_parallel_data_files(t_step)
394413
y_cc(0:n) = y_cb(-1:n - 1) + dy(0:n)/2._wp
395414

396415
if (p > 0) then
397-
! Read in cell boundary locations in z-direction
398-
file_loc = trim(case_dir)//'/restart_data'//trim(mpiiofs)//'z_cb.dat'
399-
inquire (FILE=trim(file_loc), EXIST=file_exist)
400-
401-
if (file_exist) then
402-
data_size = p_glb + 2
403-
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
404-
call MPI_FILE_READ(ifile, z_cb_glb, data_size, mpi_p, status, ierr)
405-
call MPI_FILE_CLOSE(ifile, ierr)
416+
if(down_sample) then
417+
delz = (z_domain%end - z_domain%beg)/real(p_glb + 1, wp)
418+
do i = 0, p_glb
419+
z_cb_glb(i - 1) = z_domain%beg + delz*real(i, wp)
420+
end do
421+
z_cb_glb(p_glb) = z_domain%end
406422
else
407-
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
423+
! Read in cell boundary locations in z-direction
424+
file_loc = trim(case_dir)//'/restart_data'//trim(mpiiofs)//'z_cb.dat'
425+
inquire (FILE=trim(file_loc), EXIST=file_exist)
426+
427+
if (file_exist) then
428+
data_size = p_glb + 2
429+
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
430+
call MPI_FILE_READ(ifile, z_cb_glb, data_size, mpi_p, status, ierr)
431+
call MPI_FILE_CLOSE(ifile, ierr)
432+
else
433+
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
434+
end if
408435
end if
409436

410437
! Assigning local cell boundary locations
@@ -459,7 +486,42 @@ impure subroutine s_read_parallel_conservative_data(t_step, m_MOK, n_MOK, p_MOK,
459486
if (file_exist) then
460487
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
461488

462-
call s_setup_mpi_io_params(data_size, m_MOK, n_MOK, p_MOK, WP_MOK, MOK, str_MOK, NVARS_MOK)
489+
if(down_sample) then
490+
call s_initialize_mpi_data_ds(q_cons_temp)
491+
else
492+
! Initialize MPI data I/O
493+
if (ib) then
494+
call s_initialize_mpi_data(q_cons_vf, ib_markers)
495+
else
496+
call s_initialize_mpi_data(q_cons_vf)
497+
end if
498+
end if
499+
500+
if(down_sample) then
501+
! Size of local arrays
502+
data_size = (m + 3)*(n + 3)*(p + 3)
503+
504+
! Resize some integers so MPI can read even the biggest file
505+
m_MOK = int(m_glb + 1, MPI_OFFSET_KIND)
506+
n_MOK = int(n_glb + 1, MPI_OFFSET_KIND)
507+
p_MOK = int(p_glb + 1, MPI_OFFSET_KIND)
508+
WP_MOK = int(8._wp, MPI_OFFSET_KIND)
509+
MOK = int(1._wp, MPI_OFFSET_KIND)
510+
str_MOK = int(name_len, MPI_OFFSET_KIND)
511+
NVARS_MOK = int(sys_size, MPI_OFFSET_KIND)
512+
else
513+
! Size of local arrays
514+
data_size = (m + 1)*(n + 1)*(p + 1)
515+
516+
! Resize some integers so MPI can read even the biggest file
517+
m_MOK = int(m_glb + 1, MPI_OFFSET_KIND)
518+
n_MOK = int(n_glb + 1, MPI_OFFSET_KIND)
519+
p_MOK = int(p_glb + 1, MPI_OFFSET_KIND)
520+
WP_MOK = int(8._wp, MPI_OFFSET_KIND)
521+
MOK = int(1._wp, MPI_OFFSET_KIND)
522+
str_MOK = int(name_len, MPI_OFFSET_KIND)
523+
NVARS_MOK = int(sys_size, MPI_OFFSET_KIND)
524+
end if
463525

464526
! Read the data for each variable
465527
if (bubbles_euler .or. elasticity .or. mhd) then
@@ -479,6 +541,12 @@ impure subroutine s_read_parallel_conservative_data(t_step, m_MOK, n_MOK, p_MOK,
479541
call s_mpi_barrier()
480542
call MPI_FILE_CLOSE(ifile, ierr)
481543

544+
if(down_sample) then
545+
do i = 1, sys_size
546+
q_cons_vf(i)%sf(0:m,0:n,0:p) = q_cons_temp(i)%sf(0:m,0:n,0:p)
547+
end do
548+
end if
549+
482550
call s_read_ib_data_files(trim(case_dir)//'/restart_data'//trim(mpiiofs))
483551
else
484552
call s_mpi_abort('File '//trim(file_loc)//' is missing. Exiting.')
@@ -529,6 +597,7 @@ impure subroutine s_initialize_data_input_module
529597
! the simulation
530598
allocate (q_cons_vf(1:sys_size))
531599
allocate (q_prim_vf(1:sys_size))
600+
allocate (q_cons_temp(1:sys_size))
532601

533602
! Allocating the parts of the conservative and primitive variables
534603
! that do require the direct knowledge of the dimensionality of
@@ -539,6 +608,9 @@ impure subroutine s_initialize_data_input_module
539608
! Simulation is 3D
540609
if (p > 0) then
541610
call s_allocate_field_arrays(-buff_size, m + buff_size, n + buff_size, p + buff_size)
611+
if(down_sample) then
612+
allocate(q_cons_temp(i)%sf(-1:m+1,-1:n+1,-1:p+1))
613+
end if
542614
else
543615
! Simulation is 2D
544616
call s_allocate_field_arrays(-buff_size, m + buff_size, n + buff_size, 0)
@@ -579,10 +651,14 @@ impure subroutine s_finalize_data_input_module
579651
do i = 1, sys_size
580652
deallocate (q_cons_vf(i)%sf)
581653
deallocate (q_prim_vf(i)%sf)
654+
if (down_sample) then
655+
deallocate (q_cons_temp(i)%sf)
656+
end if
582657
end do
583658

584659
deallocate (q_cons_vf)
585660
deallocate (q_prim_vf)
661+
deallocate (q_cons_temp)
586662

587663
if (ib) then
588664
deallocate (ib_markers%sf)

0 commit comments

Comments
 (0)