Commit 66addef1 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

remapbic: optimize memory handling

parent d832cfab
...@@ -105,6 +105,9 @@ void scrip_remap_bicubic_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, r ...@@ -105,6 +105,9 @@ void scrip_remap_bicubic_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid, r
long tgt_grid_size = tgt_grid->size; long tgt_grid_size = tgt_grid->size;
weightlinks4_t *weightlinks = (weightlinks4_t *) Malloc(tgt_grid_size*sizeof(weightlinks4_t)); weightlinks4_t *weightlinks = (weightlinks4_t *) Malloc(tgt_grid_size*sizeof(weightlinks4_t));
weightlinks[0].addweights = (addweight4_t *) Malloc(4*tgt_grid_size*sizeof(addweight4_t));
for ( unsigned tgt_cell_add = 1; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
weightlinks[tgt_cell_add].addweights = weightlinks[0].addweights + 4*tgt_cell_add;
/* Loop over destination grid */ /* Loop over destination grid */
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
int find_ij_weights(double plon, double plat, double* restrict src_lats, double* restrict src_lons, double *ig, double *jg) int find_ij_weights(double plon, double plat, double *restrict src_lats, double *restrict src_lons, double *ig, double *jg)
{ {
int lfound = 0; int lfound = 0;
long iter; /* iteration counters */ long iter; /* iteration counters */
...@@ -79,7 +79,7 @@ int find_ij_weights(double plon, double plat, double* restrict src_lats, double* ...@@ -79,7 +79,7 @@ int find_ij_weights(double plon, double plat, double* restrict src_lats, double*
if ( iter < remap_max_iter ) lfound = 1; if ( iter < remap_max_iter ) lfound = 1;
return (lfound); return lfound;
} }
static static
...@@ -104,7 +104,7 @@ int num_src_points(const int* restrict mask, const int src_add[4], double src_la ...@@ -104,7 +104,7 @@ int num_src_points(const int* restrict mask, const int src_add[4], double src_la
src_lats[n] = 0.; src_lats[n] = 0.;
} }
return (icount); return icount;
} }
static static
...@@ -146,7 +146,7 @@ void bilinear_warning(double plon, double plat, double iw, double jw, int* src_a ...@@ -146,7 +146,7 @@ void bilinear_warning(double plon, double plat, double iw, double jw, int* src_a
} }
static static
void bilinear_remap(double* restrict tgt_point, const double* restrict src_array, const double wgts[4], const int src_add[4]) void bilinear_remap(double* restrict tgt_point, const double *restrict src_array, const double wgts[4], const int src_add[4])
{ {
// *tgt_point = 0.; // *tgt_point = 0.;
// for ( int n = 0; n < 4; ++n ) *tgt_point += src_array[src_add[n]]*wgts[n]; // for ( int n = 0; n < 4; ++n ) *tgt_point += src_array[src_add[n]]*wgts[n];
......
...@@ -149,7 +149,8 @@ void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4 ...@@ -149,7 +149,8 @@ void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4
if ( num_weights ) if ( num_weights )
{ {
addweight4_t *addweights = (addweight4_t *) Malloc(num_weights*sizeof(addweight4_t)); addweight4_t *addweights = weightlinks[cell_add].addweights;
for ( unsigned n = 0; n < num_weights; ++n ) for ( unsigned n = 0; n < num_weights; ++n )
{ {
addweights[n].add = srch_add[n]; addweights[n].add = srch_add[n];
...@@ -159,7 +160,6 @@ void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4 ...@@ -159,7 +160,6 @@ void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4
sort_addweights4(num_weights, addweights); sort_addweights4(num_weights, addweights);
weightlinks[cell_add].addweights = addweights;
weightlinks[cell_add].nlinks = num_weights; weightlinks[cell_add].nlinks = num_weights;
} }
} }
...@@ -265,12 +265,9 @@ void weightlinks2remaplinks4(unsigned tgt_grid_size, weightlinks4_t *weightlinks ...@@ -265,12 +265,9 @@ void weightlinks2remaplinks4(unsigned tgt_grid_size, weightlinks4_t *weightlinks
for ( unsigned k = 0; k < 4; ++k ) for ( unsigned k = 0; k < 4; ++k )
wts[(offset+ilink)*4+k] = addweights[ilink].weight[k]; wts[(offset+ilink)*4+k] = addweights[ilink].weight[k];
} }
#ifdef _OPENMP
free(addweights);
#else
Free(addweights);
#endif
} }
} }
Free(weightlinks[0].addweights);
} }
} }
Supports Markdown
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