exporter code injection mech
This commit is contained in:
parent
bd81bea8be
commit
5551782ecd
2 changed files with 63 additions and 16 deletions
|
|
@ -251,13 +251,13 @@ class FieldExporter (object):
|
||||||
|
|
||||||
fmt_calc='''
|
fmt_calc='''
|
||||||
! copy to array for export
|
! copy to array for export
|
||||||
do k = 1, nzp
|
! do k = 1, nzp
|
||||||
do j = 1, nyp
|
! do j = 1, nyp
|
||||||
do i = {}, {}
|
! do i = {}, {}
|
||||||
{}(i,j,k) = {}(i,j,k)
|
! {}(i,j,k) = {}(i,j,k)
|
||||||
end do
|
! end do
|
||||||
end do
|
! end do
|
||||||
end do
|
! end do
|
||||||
|
|
||||||
! after calculate
|
! after calculate
|
||||||
! count = {x1-x0+1} * ny * nz
|
! count = {x1-x0+1} * ny * nz
|
||||||
|
|
@ -271,21 +271,21 @@ end do
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.x0 = attr["x0"]
|
self.x0 = attr["x0"]
|
||||||
self.x1 = attr["x1"]
|
self.x1 = attr["x1"]
|
||||||
self.xslice = "{}:{},ny,nz".format(x0, x1)
|
self.xslice = "{}:{},ny,nz".format(self.x0, self.x1)
|
||||||
|
|
||||||
|
|
||||||
def code (self):
|
def code (self):
|
||||||
# argument time index, file id, array
|
# argument time index, file id, array
|
||||||
return # real_array_loop.format((self.array, rhs), self.comment)
|
return FieldExporter.fmt_calc # real_array_loop.format((self.array, rhs), self.comment)
|
||||||
|
|
||||||
def code_decl (self):
|
def code_decl (self):
|
||||||
return # real_array_decl.format(self.name, self.dim)
|
return FieldExporter.fmt_decl # real_array_decl.format(self.name, self.dim)
|
||||||
|
|
||||||
def code_alloc (self):
|
def code_alloc (self):
|
||||||
return # real_array_alloc.format(self.name, self.shape)
|
return FieldExporter.fmt_init # real_array_alloc.format(self.name, self.shape)
|
||||||
|
|
||||||
def code_free (self):
|
def code_free (self):
|
||||||
return # real_array_free.format(self.name)
|
return FieldExporter.fmt_final # real_array_free.format(self.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -299,12 +299,22 @@ class Field (FieldBase):
|
||||||
self.fluc, self.dep, self.derivs = ExpInspector.inspect(exp)
|
self.fluc, self.dep, self.derivs = ExpInspector.inspect(exp)
|
||||||
self.comment = ExpToCode(self.fdict).transform(self.exp)
|
self.comment = ExpToCode(self.fdict).transform(self.exp)
|
||||||
|
|
||||||
|
self.exporter = None
|
||||||
|
try:
|
||||||
|
if self.attr["export"]:
|
||||||
|
self.exporter = FieldExporter(self.name, self.attr, self)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
'''
|
'''
|
||||||
for a in self.dep:
|
for a in self.dep:
|
||||||
if a not in self.fdict:
|
if a not in self.fdict:
|
||||||
raise StandardError(a + " is not defined")
|
raise StandardError(a + " is not defined")
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def export_on (self):
|
||||||
|
return self.exporter is not None
|
||||||
|
|
||||||
def code (self, alloc=None):
|
def code (self, alloc=None):
|
||||||
real_array_loop = """
|
real_array_loop = """
|
||||||
! {1}
|
! {1}
|
||||||
|
|
@ -319,7 +329,10 @@ end do
|
||||||
self.array = alloc[self.name] if alloc else self.name
|
self.array = alloc[self.name] if alloc else self.name
|
||||||
|
|
||||||
rhs = ExpToCode(self.fdict).transform(self.exp)
|
rhs = ExpToCode(self.fdict).transform(self.exp)
|
||||||
return real_array_loop.format((self.array, rhs), self.comment)
|
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
|
||||||
|
|
||||||
|
|
||||||
class FluctuationField (FieldBase):
|
class FluctuationField (FieldBase):
|
||||||
|
|
@ -824,9 +837,9 @@ close (200)
|
||||||
|
|
||||||
md = {}
|
md = {}
|
||||||
md["module_name"] = "terms"
|
md["module_name"] = "terms"
|
||||||
md["module_data"] = "\n".join((declf, declh, declavg, declarr))
|
md["module_data"] = "\n".join((declf, declh, declavg, decl_export, declarr))
|
||||||
md["module_init"] = "\n".join((allocavg, allocarr))
|
md["module_init"] = "\n".join((allocavg, alloc_export, allocarr))
|
||||||
md["module_finalize"] = "\n".join((freeavg, freearr))
|
md["module_finalize"] = "\n".join((freeavg, free_export, freearr))
|
||||||
md["module_pass1"] = sub_calc1
|
md["module_pass1"] = sub_calc1
|
||||||
md["module_pass1_avg"] = sub_avg1
|
md["module_pass1_avg"] = sub_avg1
|
||||||
md["module_pass2"] = sub_calc2
|
md["module_pass2"] = sub_calc2
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,14 @@ character (len = *), parameter :: output_header="x avg_c avg_divn avg_fsd"
|
||||||
real*8, allocatable, dimension(:) :: avg_c
|
real*8, allocatable, dimension(:) :: avg_c
|
||||||
real*8, allocatable, dimension(:) :: avg_fsd
|
real*8, allocatable, dimension(:) :: avg_fsd
|
||||||
real*8, allocatable, dimension(:) :: avg_divn
|
real*8, allocatable, dimension(:) :: avg_divn
|
||||||
|
|
||||||
|
! - file_handles and mpi_infos
|
||||||
|
! integer(kind=MPI_INTEGER_KIND) :: {field_name}_fh
|
||||||
|
! integer(kind=MPI_INTEGER_KIND) :: {field_name}_info
|
||||||
|
|
||||||
|
! - buffer
|
||||||
|
! real*8, allocatable, dimension(:,:,:) :: {field_name}_export_array
|
||||||
|
|
||||||
real*8, allocatable, dimension(:,:,:) :: xyzbuffer0
|
real*8, allocatable, dimension(:,:,:) :: xyzbuffer0
|
||||||
real*8, allocatable, dimension(:,:,:) :: xyzbuffer1
|
real*8, allocatable, dimension(:,:,:) :: xyzbuffer1
|
||||||
real*8, allocatable, dimension(:,:,:) :: xyzbuffer2
|
real*8, allocatable, dimension(:,:,:) :: xyzbuffer2
|
||||||
|
|
@ -27,6 +35,12 @@ integer :: ierr
|
||||||
allocate(avg_c(nxp), stat=ierr) ; avg_c = 0.
|
allocate(avg_c(nxp), stat=ierr) ; avg_c = 0.
|
||||||
allocate(avg_fsd(nxp), stat=ierr) ; avg_fsd = 0.
|
allocate(avg_fsd(nxp), stat=ierr) ; avg_fsd = 0.
|
||||||
allocate(avg_divn(nxp), stat=ierr) ; avg_divn = 0.
|
allocate(avg_divn(nxp), stat=ierr) ; avg_divn = 0.
|
||||||
|
|
||||||
|
! init
|
||||||
|
! call MPI_INFO_CREATE({field_name}_info, mpi_err)
|
||||||
|
! call MPI_FILE_OPEN(MPI_COMM_TASK,{field_name}_fname,MPI_MODE_WRONLY+MPI_MODE_CREATE,{field_name}_info,{field_name}_fh,mpi_err)
|
||||||
|
! allocate({field_name}_export_array({1}), stat=ierr) ; {field_name}_export_array = 0.
|
||||||
|
|
||||||
allocate(xyzbuffer0(nxp,nyp,nzp), stat=ierr) ; xyzbuffer0 = 0.
|
allocate(xyzbuffer0(nxp,nyp,nzp), stat=ierr) ; xyzbuffer0 = 0.
|
||||||
allocate(xyzbuffer1(nxp,nyp,nzp), stat=ierr) ; xyzbuffer1 = 0.
|
allocate(xyzbuffer1(nxp,nyp,nzp), stat=ierr) ; xyzbuffer1 = 0.
|
||||||
allocate(xyzbuffer2(nxp,nyp,nzp), stat=ierr) ; xyzbuffer2 = 0.
|
allocate(xyzbuffer2(nxp,nyp,nzp), stat=ierr) ; xyzbuffer2 = 0.
|
||||||
|
|
@ -41,6 +55,12 @@ subroutine m_terms_finalize
|
||||||
deallocate(avg_c)
|
deallocate(avg_c)
|
||||||
deallocate(avg_fsd)
|
deallocate(avg_fsd)
|
||||||
deallocate(avg_divn)
|
deallocate(avg_divn)
|
||||||
|
|
||||||
|
! finalize
|
||||||
|
! call MPI_FILE_CLOSE({field_name}_fh, mpi_err)
|
||||||
|
! call MPI_INFO_FREE({field_name}_info, mpi_err)
|
||||||
|
! deallocate({field_name}_export_array)
|
||||||
|
|
||||||
deallocate(xyzbuffer0)
|
deallocate(xyzbuffer0)
|
||||||
deallocate(xyzbuffer1)
|
deallocate(xyzbuffer1)
|
||||||
deallocate(xyzbuffer2)
|
deallocate(xyzbuffer2)
|
||||||
|
|
@ -138,6 +158,20 @@ end do
|
||||||
end do
|
end do
|
||||||
end do
|
end do
|
||||||
|
|
||||||
|
! copy to array for export
|
||||||
|
! do k = 1, nzp
|
||||||
|
! do j = 1, nyp
|
||||||
|
! do i = {}, {}
|
||||||
|
! {}(i,j,k) = {}(i,j,k)
|
||||||
|
! end do
|
||||||
|
! end do
|
||||||
|
! end do
|
||||||
|
|
||||||
|
! after calculate
|
||||||
|
! count = {x1-x0+1} * ny * nz
|
||||||
|
! offset = time_count * count
|
||||||
|
! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_buffer, count, MPI_REAL8, mpi_status, mpi_err)
|
||||||
|
|
||||||
|
|
||||||
do k = 1, nzp
|
do k = 1, nzp
|
||||||
do j = 1, nyp
|
do j = 1, nyp
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue