From f369a16d4bdf895d42a91ffaee3e5fc922731527 Mon Sep 17 00:00:00 2001 From: ignis Date: Sun, 7 Jul 2019 21:40:37 +0900 Subject: [PATCH] - rename export file - enable export save - improve term comment with lval name - add export offset array - pass file index to calculation subroutine - bugfix: - get array name after allocation - multiply offset by 8 to be size in Byte --- code/code_gen/post.py | 31 ++++---- code/code_gen/resources/m_template.py | 6 +- code/code_gen/terms.input | 4 +- code/m_parameters.f90 | 4 + code/m_terms.f90 | 108 +++++++++++++++++++++----- code/post.f90 | 8 +- 6 files changed, 120 insertions(+), 41 deletions(-) diff --git a/code/code_gen/post.py b/code/code_gen/post.py index 526757c..5ed3939 100644 --- a/code/code_gen/post.py +++ b/code/code_gen/post.py @@ -236,7 +236,7 @@ real*8, allocatable, dimension(:,:,:) :: {field_name}_export_array fmt_init=''' ! init call MPI_INFO_CREATE({field_name}_info, mpi_err) -call MPI_FILE_OPEN(MPI_COMM_TASK,'{field_name}-export.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,{field_name}_info,{field_name}_fh,mpi_err) +call MPI_FILE_OPEN(MPI_COMM_TASK,'export-{field_name}.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,{field_name}_info,{field_name}_fh,mpi_err) allocate({field_name}_export_array({xs}:{xe},{ys}:{ye},{zs}:{ze}), stat=ierr) ; {field_name}_export_array = 0. ''' @@ -249,18 +249,18 @@ deallocate({field_name}_export_array) fmt_calc=''' ! copy to array for export -! do k = 1, nzp -! do j = 1, nyp -! do i = {x_start}, {x_end} -! {field_name}_export_array(i,j,k) = {work_array}(i,j,k) -! end do -! end do -! end do +do k = {zs}, {ze} +do j = {ys}, {ye} +do i = {xs}, {xe} +{field_name}_export_array(i,j,k) = {work_array}(i,j,k) +end do +end do +end do ! write to file -! count = ({xe} - {xs} + 1) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) -! offset = {itime} * count -! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count, MPI_REAL8, mpi_status, mpi_err) +count = ({xe} - {xs} + 1) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) +offset = export_offset(fidx) * count * 8 +call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count, MPI_REAL8, mpi_status, mpi_err) ''' def __init__ (self, name, attr, parent): @@ -281,9 +281,10 @@ deallocate({field_name}_export_array) self.params.setdefault("field_name", self.name) + def code (self): - # argument time index, file id, array - return FieldExporter.fmt_calc # real_array_loop.format((self.array, rhs), self.comment) + self.params["work_array"] = self.parent.array + return FieldExporter.fmt_calc.format(**self.params) def code_decl (self): return FieldExporter.fmt_decl.format(**self.params) @@ -304,7 +305,7 @@ class Field (FieldBase): self.attr = attr self.exp = exp self.fluc, self.dep, self.derivs = ExpInspector.inspect(exp) - self.comment = ExpToCode(self.fdict).transform(self.exp) + self.comment = self.name + " = " + ExpToCode(self.fdict).transform(self.exp) self.exporter = None try: @@ -337,6 +338,7 @@ end do rhs = ExpToCode(self.fdict).transform(self.exp) calculation_code = real_array_loop.format((self.array, rhs), self.comment) + export_code = ( self.exporter.code() if self.export_on() else "") return calculation_code + export_code @@ -363,6 +365,7 @@ class FluctuationField (FieldBase): if self.field.is_fluctuation(): self.comment = self.comment.format(self.w) + self.comment = self.name + " = " + self.comment def code (self, alloc=None): real_array_loop = """ diff --git a/code/code_gen/resources/m_template.py b/code/code_gen/resources/m_template.py index 7f9fd01..18745d9 100644 --- a/code/code_gen/resources/m_template.py +++ b/code/code_gen/resources/m_template.py @@ -27,8 +27,9 @@ subroutine m_{0[module_name]}_finalize end subroutine m_{0[module_name]}_finalize -subroutine m_{0[module_name]}_calculate_pass1 +subroutine m_{0[module_name]}_calculate_pass1(fidx) +integer :: fidx integer :: i, j, k {0[module_pass1]} @@ -48,8 +49,9 @@ denum=real(nfiles*nyp*nzp) end subroutine m_{0[module_name]}_average_pass1 -subroutine m_{0[module_name]}_calculate_pass2 +subroutine m_{0[module_name]}_calculate_pass2(fidx) +integer :: fidx integer :: i, j, k {0[module_pass2]} diff --git a/code/code_gen/terms.input b/code/code_gen/terms.input index 277294e..034c427 100644 --- a/code/code_gen/terms.input +++ b/code/code_gen/terms.input @@ -2,9 +2,9 @@ # field_name (arg_name=arg (, pair)* ) = expression -c = 1.0 - y +c (export=true, xs=176, xe=400) = 1.0 - y -fsd () = sqrt (sqr(ddx(c)) + sqr(ddy(c)) + sqr(ddz(c))) +fsd (export=true, xs=176, xe=400) = sqrt (sqr(ddx(c)) + sqr(ddy(c)) + sqr(ddz(c))) nx = - ddx(c) / fsd ny = - ddy(c) / fsd diff --git a/code/m_parameters.f90 b/code/m_parameters.f90 index 85d1cf4..511af47 100644 --- a/code/m_parameters.f90 +++ b/code/m_parameters.f90 @@ -28,6 +28,8 @@ module m_parameters integer, allocatable :: file_dist(:) + integer, allocatable :: export_offset(:) + real, parameter :: pi=3.14159265358979323846 real, parameter :: me=1.00e-20 @@ -128,6 +130,7 @@ subroutine read_intro allocate (file_dist(startnum:endnum), stat=ierr) + allocate (export_offset(startnum:endnum), stat=ierr) file_count = 0 @@ -136,6 +139,7 @@ subroutine read_intro IF ( .not. to_omit(i) ) THEN file_dist(i) = mod(file_count, numprocs) + export_offset(i) = file_count file_count = file_count + 1 diff --git a/code/m_terms.f90 b/code/m_terms.f90 index 05a6c8d..8c14dab 100644 --- a/code/m_terms.f90 +++ b/code/m_terms.f90 @@ -24,6 +24,22 @@ integer(kind=MPI_INTEGER_KIND) :: divn_info ! - buffer real*8, allocatable, dimension(:,:,:) :: divn_export_array + +! - file_handles and mpi_infos +integer(kind=MPI_INTEGER_KIND) :: c_fh +integer(kind=MPI_INTEGER_KIND) :: c_info + +! - buffer +real*8, allocatable, dimension(:,:,:) :: c_export_array + + +! - file_handles and mpi_infos +integer(kind=MPI_INTEGER_KIND) :: fsd_fh +integer(kind=MPI_INTEGER_KIND) :: fsd_info + +! - buffer +real*8, allocatable, dimension(:,:,:) :: fsd_export_array + real*8, allocatable, dimension(:,:,:) :: xyzbuffer0 real*8, allocatable, dimension(:,:,:) :: xyzbuffer1 real*8, allocatable, dimension(:,:,:) :: xyzbuffer2 @@ -42,9 +58,21 @@ allocate(avg_divn(nxp), stat=ierr) ; avg_divn = 0. ! init call MPI_INFO_CREATE(divn_info, mpi_err) -call MPI_FILE_OPEN(MPI_COMM_TASK,'divn-export.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,divn_info,divn_fh,mpi_err) +call MPI_FILE_OPEN(MPI_COMM_TASK,'export-divn.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,divn_info,divn_fh,mpi_err) allocate(divn_export_array(176:400,1:nyp,1:nzp), stat=ierr) ; divn_export_array = 0. + +! init +call MPI_INFO_CREATE(c_info, mpi_err) +call MPI_FILE_OPEN(MPI_COMM_TASK,'export-c.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,c_info,c_fh,mpi_err) +allocate(c_export_array(176:400,1:nyp,1:nzp), stat=ierr) ; c_export_array = 0. + + +! init +call MPI_INFO_CREATE(fsd_info, mpi_err) +call MPI_FILE_OPEN(MPI_COMM_TASK,'export-fsd.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,fsd_info,fsd_fh,mpi_err) +allocate(fsd_export_array(176:400,1:nyp,1:nzp), stat=ierr) ; fsd_export_array = 0. + allocate(xyzbuffer0(nxp,nyp,nzp), stat=ierr) ; xyzbuffer0 = 0. allocate(xyzbuffer1(nxp,nyp,nzp), stat=ierr) ; xyzbuffer1 = 0. allocate(xyzbuffer2(nxp,nyp,nzp), stat=ierr) ; xyzbuffer2 = 0. @@ -65,6 +93,18 @@ call MPI_FILE_CLOSE(divn_fh, mpi_err) call MPI_INFO_FREE(divn_info, mpi_err) deallocate(divn_export_array) + +! finalize +call MPI_FILE_CLOSE(c_fh, mpi_err) +call MPI_INFO_FREE(c_info, mpi_err) +deallocate(c_export_array) + + +! finalize +call MPI_FILE_CLOSE(fsd_fh, mpi_err) +call MPI_INFO_FREE(fsd_info, mpi_err) +deallocate(fsd_export_array) + deallocate(xyzbuffer0) deallocate(xyzbuffer1) deallocate(xyzbuffer2) @@ -74,12 +114,13 @@ deallocate(xyzbuffer4) end subroutine m_terms_finalize -subroutine m_terms_calculate_pass1 +subroutine m_terms_calculate_pass1(fidx) +integer :: fidx integer :: i, j, k -! ( 1.0 - y(i,j,k) ) +! c = ( 1.0 - y(i,j,k) ) do k = 1, nzp do j = 1, nyp do i = 1, nxp @@ -88,6 +129,20 @@ end do end do end do +! copy to array for export +do k = 1, nzp +do j = 1, nyp +do i = 176, 400 +c_export_array(i,j,k) = xyzbuffer3(i,j,k) +end do +end do +end do + +! write to file +count = (400 - 176 + 1) * (nyp - 1 + 1) * (nzp - 1 + 1) +offset = export_offset(fidx) * count * 8 +call MPI_FILE_WRITE_AT(c_fh, offset, c_export_array, count, MPI_REAL8, mpi_status, mpi_err) + do k = 1, nzp do j = 1, nyp @@ -101,7 +156,7 @@ call ddx ( xyzbuffer2, xyzbuffer3 ) call ddy ( xyzbuffer1, xyzbuffer3 ) call ddz ( xyzbuffer0, xyzbuffer3 ) -! ( sqrt ( ( ( ((ddx_c(i,j,k))*(ddx_c(i,j,k))) + ((ddy_c(i,j,k))*(ddy_c(i,j,k))) ) + ((ddz_c(i,j,k))*(ddz_c(i,j,k))) ) ) ) +! fsd = ( sqrt ( ( ( ((ddx_c(i,j,k))*(ddx_c(i,j,k))) + ((ddy_c(i,j,k))*(ddy_c(i,j,k))) ) + ((ddz_c(i,j,k))*(ddz_c(i,j,k))) ) ) ) do k = 1, nzp do j = 1, nyp do i = 1, nxp @@ -110,6 +165,20 @@ end do end do end do +! copy to array for export +do k = 1, nzp +do j = 1, nyp +do i = 176, 400 +fsd_export_array(i,j,k) = xyzbuffer3(i,j,k) +end do +end do +end do + +! write to file +count = (400 - 176 + 1) * (nyp - 1 + 1) * (nzp - 1 + 1) +offset = export_offset(fidx) * count * 8 +call MPI_FILE_WRITE_AT(fsd_fh, offset, fsd_export_array, count, MPI_REAL8, mpi_status, mpi_err) + do k = 1, nzp do j = 1, nyp @@ -120,7 +189,7 @@ end do end do -! ( ( - ddx_c(i,j,k) ) / fsd(i,j,k) ) +! nx = ( ( - ddx_c(i,j,k) ) / fsd(i,j,k) ) do k = 1, nzp do j = 1, nyp do i = 1, nxp @@ -131,7 +200,7 @@ end do call ddx ( xyzbuffer2, xyzbuffer4 ) -! ( ( - ddy_c(i,j,k) ) / fsd(i,j,k) ) +! ny = ( ( - ddy_c(i,j,k) ) / fsd(i,j,k) ) do k = 1, nzp do j = 1, nyp do i = 1, nxp @@ -141,7 +210,7 @@ end do end do -! ( ( - ddz_c(i,j,k) ) / fsd(i,j,k) ) +! nz = ( ( - ddz_c(i,j,k) ) / fsd(i,j,k) ) do k = 1, nzp do j = 1, nyp do i = 1, nxp @@ -153,7 +222,7 @@ end do call ddy ( xyzbuffer3, xyzbuffer4 ) call ddz ( xyzbuffer0, xyzbuffer1 ) -! ( ( ddx_nx(i,j,k) + ddy_ny(i,j,k) ) + ddz_nz(i,j,k) ) +! divn = ( ( ddx_nx(i,j,k) + ddy_ny(i,j,k) ) + ddz_nz(i,j,k) ) do k = 1, nzp do j = 1, nyp do i = 1, nxp @@ -163,18 +232,18 @@ end do end do ! copy to array for export -! do k = 1, nzp -! do j = 1, nyp -! do i = {x_start}, {x_end} -! {field_name}_export_array(i,j,k) = {work_array}(i,j,k) -! end do -! end do -! end do +do k = 1, nzp +do j = 1, nyp +do i = 176, 400 +divn_export_array(i,j,k) = xyzbuffer4(i,j,k) +end do +end do +end do ! write to file -! count = ({xe} - {xs} + 1) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) -! offset = {itime} * count -! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count, MPI_REAL8, mpi_status, mpi_err) +count = (400 - 176 + 1) * (nyp - 1 + 1) * (nzp - 1 + 1) +offset = export_offset(fidx) * count * 8 +call MPI_FILE_WRITE_AT(divn_fh, offset, divn_export_array, count, MPI_REAL8, mpi_status, mpi_err) do k = 1, nzp @@ -215,8 +284,9 @@ avg_fsd = avg_fsd / denum end subroutine m_terms_average_pass1 -subroutine m_terms_calculate_pass2 +subroutine m_terms_calculate_pass2(fidx) +integer :: fidx integer :: i, j, k diff --git a/code/post.f90 b/code/post.f90 index 546cb8f..ac7db76 100644 --- a/code/post.f90 +++ b/code/post.f90 @@ -46,7 +46,7 @@ CALL READ_FILE(fread) - CALL m_terms_calculate_pass1 + CALL m_terms_calculate_pass1(fread) END IF @@ -77,7 +77,7 @@ CALL READ_FILE(fread) - CALL m_terms_calculate_pass2 + CALL m_terms_calculate_pass2(fread) ENDIF @@ -163,7 +163,7 @@ CALL READ_FILE(fread) - CALL m_terms_calculate_pass1 + CALL m_terms_calculate_pass1(fread) end do fetchloop1 @@ -223,7 +223,7 @@ CALL READ_FILE(fread) - CALL m_terms_calculate_pass2 + CALL m_terms_calculate_pass2(fread) end do fetchloop2