Commit 7a84dba9 authored by POLCHER Jan's avatar POLCHER Jan 🚴🏾
Browse files

Optimized memory management. In nearly all cases the dimensions used for...

Optimized memory management. In nearly all cases the dimensions used for variables in routing_reg.f90 are now passed in argument.
This change has shown a bug in killbas which still needs to be solved.
parent 0a9e8068
This diff is collapsed.
This diff is collapsed.
......@@ -262,15 +262,23 @@ class HydroOverlap :
trip_tmp[np.isnan(trip_tmp)] = undef_int
basins_tmp[np.isnan(trip_tmp)] = undef_int
#
# Compute nbxmax
#
ijdim=[]
for ib in range(nbpt) :
ijdim.append(max(max(sub_index[ib,:,0])-min(sub_index[ib,:,0])+1,max(sub_index[ib,:,1])-min(sub_index[ib,:,1])+1))
ijdimmax = max(ijdim)
#
# Go to the call of the FORTRAN interface
#
print("GETHYDROGRID : nbpt = ", nbpt, nbvmax)
print("GETHYDROGRID : nbvmax = ", nbvmax)
print("GETHYDROGRID : nbxmax = ", nbxmax)
#
self.nbi, self.nbj, self.area_bx, self.trip_bx, self.basin_bx, self.topoind_bx, self.fac_bx, self.hierarchy_bx, \
self.orog_bx, self.floodp_bx, \
self.lon_bx, self.lat_bx, self.lshead_bx = \
routing_interface.gethydrogrid(nbxmax, sub_pts, sub_index, sub_area, \
routing_interface.gethydrogrid(ijdimmax, sub_pts, sub_index, sub_area, \
hydrodata.basinsmax, hydrodata.topoindmin, sub_lon, sub_lat, trip_tmp, basins_tmp, topoind_tmp, fac_tmp,\
hierarchy_tmp, orog_tmp, floodp_tmp)
#
......@@ -296,15 +304,14 @@ class HydroSuper :
#
# nb_htu can be adjusted with self.nwbas
# nb_htu can be lowered with a larger maxpercent (routing_reg.f90)
nb_htu = 600
nb_htu = nbvmax
nbv = nbvmax
#
# Call findbasins
#
nb_basin, basin_inbxid, basin_outlet, basin_outtp, self.basin_sz, basin_bxout, basin_bbout, self.basin_pts, basin_lshead, coast_pts = \
routing_interface.findbasins(nbpt = self.nbpt, nb_htu = nb_htu, nbv = nbv, nbi = hydrooverlap.nbi, nbj = hydrooverlap.nbj, \
trip_bx = hydrooverlap.trip_bx, \
routing_interface.findbasins(nbpt = self.nbpt, nb_htu = self.nbhtuext, nbv = nbv, nbi = hydrooverlap.nbi, \
nbj = hydrooverlap.nbj, trip_bx = hydrooverlap.trip_bx, \
basin_bx = hydrooverlap.basin_bx, fac_bx = hydrooverlap.fac_bx, \
hierarchy_bx = hydrooverlap.hierarchy_bx, \
topoind_bx = hydrooverlap.topoind_bx, lshead_bx = hydrooverlap.lshead_bx, \
......@@ -313,7 +320,13 @@ class HydroSuper :
# Adjust nwbas to the maximum found over the domain
#
self.nwbas = part.domainmax(np.max(nb_basin))
# Set the number of inflows per basin. For the moment twice the maximum number of basins.
self.inflowmax = self.nwbas*2
print("Maximum number of basin created : {0}".format(self.nwbas))
ijdim=[]
for i in range(self.nbpt) :
ijdim.append(max(hydrooverlap.area_bx[i,:,:].shape))
self.ijdimmax = max(ijdim)
#
# Call Globalize
#
......@@ -321,12 +334,13 @@ class HydroSuper :
lon_bx_tmp[np.isnan(lon_bx_tmp)] = undef_int
lat_bx_tmp = hydrooverlap.lat_bx
lat_bx_tmp[np.isnan(lat_bx_tmp)] = undef_int
#
self.basin_count, self.basin_notrun, self.basin_area, self.basin_cg, self.basin_hierarchy, \
self.basin_orog, self.basin_floodp, self.basin_fac, self.basin_topoind, \
self.basin_id, self.basin_outcoor, self.basin_type, self.basin_flowdir, \
self.basin_lshead, self.outflow_grid, self.outflow_basin, self.nbcoastal, self.coastal_basin = \
routing_interface.globalize(nbpt = self.nbpt, nb_htu = nb_htu,nbv = nbv, area_bx = hydrooverlap.area_bx, lon_bx = lon_bx_tmp, \
lat_bx = lat_bx_tmp, trip_bx = hydrooverlap.trip_bx, \
routing_interface.globalize(nbpt = self.nbpt, nb_htu = self.nbhtuext, nbv = nbv, ijdimmax = self.ijdimmax, \
area_bx = hydrooverlap.area_bx, lon_bx = lon_bx_tmp, lat_bx = lat_bx_tmp, trip_bx = hydrooverlap.trip_bx, \
hierarchy_bx = hydrooverlap.hierarchy_bx, orog_bx = hydrooverlap.orog_bx, floodp_bx = hydrooverlap.floodp_bx,\
fac_bx = hydrooverlap.fac_bx, topoind_bx = hydrooverlap.topoind_bx, min_topoind = hydrodata.topoindmin, \
nb_basin = nb_basin, basin_inbxid = basin_inbxid, basin_outlet = basin_outlet, basin_outtp = basin_outtp, \
......@@ -343,11 +357,15 @@ class HydroSuper :
# Call the linkup routine in routing_reg.
#
print("Invented basins =", hydrodata.basinsmax)
self.inflow_number,self.inflow_grid,self.inflow_basin = routing_interface.linkup(nbxmax, self.basin_count, self.basin_area, self.basin_id, \
self.basin_flowdir, self.basin_lshead, self.basin_hierarchy, \
self.basin_fac, self.outflow_grid, self.outflow_basin, \
self.nbcoastal, self.coastal_basin, float(hydrodata.basinsmax))
self.inflow_number,self.inflow_grid,self.inflow_basin = \
routing_interface.linkup(self.ijdimmax, self.inflowmax, self.basin_count, self.basin_area, \
self.basin_id, self.basin_flowdir, self.basin_lshead, self.basin_hierarchy, \
self.basin_fac, self.outflow_grid, self.outflow_basin, \
self.nbcoastal, self.coastal_basin, float(hydrodata.basinsmax))
self.nbxmax_in = self.inflow_number.shape[1]
#
#
#
return
#
......@@ -415,8 +433,10 @@ class HydroSuper :
#
def killbas(self, tokill, totakeover, numops):
ops = tokill.shape[1]
routing_interface.killbas(nbpt = self.nbpt, nbxmax_in = self.nbxmax_in, \
#
nbxmax_tmp = self.inflow_grid.shape[2]
#
routing_interface.killbas(nbpt = self.nbpt, inflowmax = nbxmax_tmp, \
nbasmax = self.nbasmax, nwbas = self.nwbas, ops = ops, tokill = tokill,\
totakeover = totakeover, numops = numops, basin_count = self.basin_count,\
basin_area = self.basin_area, basin_orog = self.basin_orog, basin_floodp = self.basin_floodp, \
......@@ -551,12 +571,13 @@ class HydroGraph :
self.nbasmax = nbasmax
self.nbpt = hydrosuper.basin_count.shape[0]
nwbas = hydrosuper.basin_topoind.shape[1]
nbxmax_in = hydrosuper.inflow_grid.shape[1]
nbxmax_in = hydrosuper.inflow_grid.shape[2]
#
#
self.routing_area, self.routing_orog, self.routing_floodp, self.routing_cg, self.topo_resid, self.route_nbbasin,\
self.route_togrid, self.route_tobasin, self.route_nbintobas, self.global_basinid, \
self.route_outlet, self.route_type, self.origin_nbintobas, self.routing_fetch = \
routing_interface.finish_truncate(nbpt = self.nbpt, nbxmax_in = nbxmax_in, nbasmax = nbasmax, nwbas = nwbas, \
routing_interface.finish_truncate(nbpt = self.nbpt, inflowmax = nbxmax_in, nbasmax = nbasmax, nwbas = nwbas, \
num_largest = hydrosuper.num_largest, gridarea = modelgrid.area, \
cfrac = modelgrid.contfrac, basin_count = hydrosuper.basin_count, \
basin_notrun = hydrosuper.basin_notrun, basin_area = hydrosuper.basin_area, \
......@@ -579,12 +600,10 @@ class HydroGraph :
# Inflows
self.max_inflow = part.domainmax(np.max(hydrosuper.inflow_number))
gingrid = part.l2glandindex( hydrosuper.inflow_grid[:,:,:self.max_inflow])
self.route_innum, self.route_ingrid, self.route_inbasin = routing_interface.finish_inflows(nbpt = self.nbpt, nbxmax_in = nbxmax_in, \
nbasmax = nbasmax, inf_max = self.max_inflow, \
basin_count = hydrosuper.basin_count, \
inflow_number = hydrosuper.inflow_number, \
inflow_grid = gingrid, \
inflow_basin = hydrosuper.inflow_basin[:,:,:self.max_inflow])
self.route_innum, self.route_ingrid, self.route_inbasin = \
routing_interface.finish_inflows(nbpt = self.nbpt, nwbas = nwbas, nbasmax = nbasmax, inf_max = self.max_inflow, \
basin_count = hydrosuper.basin_count, inflow_number = hydrosuper.inflow_number, \
inflow_grid = gingrid, inflow_basin = hydrosuper.inflow_basin[:,:,:self.max_inflow])
return
#
......
......@@ -19,6 +19,19 @@ source ../../Environment
#
/bin/rm -f DocumentationInterface *graph.nc *.txt
#
# If weights file does not exist, then compute it quickly
#
if [ ! -e Weights.nc ] ; then
mpirun -n ${NSLOTS} python ../../WeightsOnly.py
if [ $? -gt 0 ] ; then
exit
else
echo "============================================="
echo "= Weight calculations successful ="
echo "============================================="
fi
fi
#
# Run the Python code to generate the HTUs and write them into a netCDF file.
#
mpirun -n ${NSLOTS} python ../../RoutingPreProc.py
......
......@@ -3,10 +3,10 @@
#PBS -N BuildHTUs_IP
#
#PBS -j oe
#PBS -l nodes=1:ppn=48
#PBS -l nodes=1:ppn=64
#PBS -l walltime=12:00:00
#PBS -l mem=160gb
#PBS -l vmem=160gb
#PBS -l mem=240gb
#PBS -l vmem=240gb
#
cd ${PBS_O_WORKDIR}
export NSLOTS=$(($PBS_NUM_NODES*$PBS_NUM_PPN))
......@@ -20,6 +20,7 @@ source ../../Environment
/bin/rm -f DocumentationInterface *graph.nc *.txt
#
# Run the Python code to generate the HTUs and write them into a netCDF file.
# It will also generate the weights if needed.
#
mpirun -n ${NSLOTS} python ../../RoutingPreProc.py
if [ $? -gt 0 ] ; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment