Commit 226f0d4f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

RemapLink: changed pointer to vector.

parent 33eb2429
...@@ -403,10 +403,10 @@ static void ...@@ -403,10 +403,10 @@ static void
scaleGridboxArea(size_t gridsize, const double *restrict array1, size_t gridsize2, double *restrict array2, scaleGridboxArea(size_t gridsize, const double *restrict array1, size_t gridsize2, double *restrict array2,
const double *restrict grid2_area) const double *restrict grid2_area)
{ {
double array1sum = 0; double array1sum = 0.0;
for (size_t i = 0; i < gridsize; i++) array1sum += array1[i]; for (size_t i = 0; i < gridsize; i++) array1sum += array1[i];
double array2sum = 0; double array2sum = 0.0;
for (size_t i = 0; i < gridsize2; i++) array2sum += grid2_area[i]; for (size_t i = 0; i < gridsize2; i++) array2sum += grid2_area[i];
for (size_t i = 0; i < gridsize2; i++) array2[i] = grid2_area[i] / array2sum * array1sum; for (size_t i = 0; i < gridsize2; i++) array2[i] = grid2_area[i] / array2sum * array1sum;
......
#include "array.h" #include "array.h"
#include "dmemory.h"
#include "process_int.h" #include "process_int.h"
#include "cdo_wtime.h" #include "cdo_wtime.h"
#include "cdo_options.h" #include "cdo_options.h"
...@@ -25,20 +24,20 @@ remapFirstOrder(double *restrict dst_array, const RemapVars &rv, const double *r ...@@ -25,20 +24,20 @@ remapFirstOrder(double *restrict dst_array, const RemapVars &rv, const double *r
const auto &dst_add = rv.tgt_cell_add; const auto &dst_add = rv.tgt_cell_add;
const auto &src_add = rv.src_cell_add; const auto &src_add = rv.src_cell_add;
const auto &links = rv.links; const auto &links = rv.links;
long links_per_value = rv.links_per_value; const auto links_per_value = rv.links_per_value;
if (links.option) if (links.option)
{ {
#ifdef HAVE_OPENMP4 #ifdef HAVE_OPENMP4
#pragma omp parallel for simd default(none) shared(num_links, dst_array, dst_add) #pragma omp parallel for simd default(none) shared(num_links, dst_array, dst_add)
#endif #endif
for (size_t n = 0; n < num_links; ++n) dst_array[dst_add[n]] = 0.; for (size_t n = 0; n < num_links; ++n) dst_array[dst_add[n]] = 0.0;
for (size_t j = 0; j < links.num_blks; ++j) for (size_t j = 0; j < links.num_blks; ++j)
{ {
const size_t *restrict dst_addx = links.dst_add[j]; const auto &dst_addx = links.dst_add[j];
const size_t *restrict src_addx = links.src_add[j]; const auto &src_addx = links.src_add[j];
const size_t *restrict windex = links.w_index[j]; const auto &windex = links.w_index[j];
auto nlinks = links.num_links[j]; auto nlinks = links.num_links[j];
#ifdef HAVE_OPENMP4 #ifdef HAVE_OPENMP4
...@@ -52,7 +51,7 @@ remapFirstOrder(double *restrict dst_array, const RemapVars &rv, const double *r ...@@ -52,7 +51,7 @@ remapFirstOrder(double *restrict dst_array, const RemapVars &rv, const double *r
} }
else else
{ {
long lpv = links_per_value; const auto lpv = links_per_value;
if (lpv > 0) if (lpv > 0)
{ {
size_t nlinks = num_links / lpv; size_t nlinks = num_links / lpv;
...@@ -127,7 +126,7 @@ remapSecondOrder(double *restrict dst_array, const RemapVars &rv, const double * ...@@ -127,7 +126,7 @@ remapSecondOrder(double *restrict dst_array, const RemapVars &rv, const double *
#ifdef SX #ifdef SX
#pragma cdir nodep #pragma cdir nodep
#endif #endif
for (size_t n = 0; n < num_links; ++n) dst_array[dst_add[n]] = 0.; for (size_t n = 0; n < num_links; ++n) dst_array[dst_add[n]] = 0.0;
if (num_wts == 3) if (num_wts == 3)
{ {
...@@ -173,7 +172,7 @@ remap(double *restrict dst_array, double missval, size_t dst_size, const RemapVa ...@@ -173,7 +172,7 @@ remap(double *restrict dst_array, double missval, size_t dst_size, const RemapVa
*/ */
extern int timer_remap; extern int timer_remap;
double start = Options::cdoVerbose ? cdo_get_wtime() : 0; const auto start = Options::cdoVerbose ? cdo_get_wtime() : 0.0;
// Check the order of the interpolation // Check the order of the interpolation
...@@ -263,7 +262,7 @@ remap_laf(double *restrict dst_array, double missval, size_t dst_size, const Rem ...@@ -263,7 +262,7 @@ remap_laf(double *restrict dst_array, double missval, size_t dst_size, const Rem
if (num_links == 0) return; if (num_links == 0) return;
size_t max_cls = get_max_add(num_links, dst_size, dst_add); auto max_cls = get_max_add(num_links, dst_size, dst_add);
#ifdef _OPENMP #ifdef _OPENMP
Varray2D<double> src_cls2(Threading::ompNumThreads, Varray<double>(max_cls)); Varray2D<double> src_cls2(Threading::ompNumThreads, Varray<double>(max_cls));
...@@ -481,10 +480,6 @@ remapVarsInit(RemapMethod mapType, int remapOrder, RemapVars &rv) ...@@ -481,10 +480,6 @@ remapVarsInit(RemapMethod mapType, int remapOrder, RemapVars &rv)
rv.links.option = false; rv.links.option = false;
rv.links.max_links = 0; rv.links.max_links = 0;
rv.links.num_blks = 0; rv.links.num_blks = 0;
rv.links.num_links = nullptr;
rv.links.src_add = nullptr;
rv.links.dst_add = nullptr;
rv.links.w_index = nullptr;
} }
void void
...@@ -513,10 +508,9 @@ remapVarsResize(RemapVars &rv, size_t size) ...@@ -513,10 +508,9 @@ remapVarsResize(RemapVars &rv, size_t size)
void void
remapVarsReorder(RemapVars &rv) remapVarsReorder(RemapVars &rv)
{ {
size_t j, nval = 0, num_blks = 0; size_t nval = 0, num_blks = 0;
size_t n;
size_t num_links = rv.num_links; const auto num_links = rv.num_links;
printf("remapVarsReorder\n"); printf("remapVarsReorder\n");
printf(" num_links %zu\n", num_links); printf(" num_links %zu\n", num_links);
...@@ -524,7 +518,7 @@ remapVarsReorder(RemapVars &rv) ...@@ -524,7 +518,7 @@ remapVarsReorder(RemapVars &rv)
size_t lastval = -1; size_t lastval = -1;
size_t max_links = 0; size_t max_links = 0;
for (n = 0; n < num_links; n++) for (size_t n = 0; n < num_links; n++)
{ {
if (rv.tgt_cell_add[n] == lastval) if (rv.tgt_cell_add[n] == lastval)
nval++; nval++;
...@@ -544,26 +538,26 @@ remapVarsReorder(RemapVars &rv) ...@@ -544,26 +538,26 @@ remapVarsReorder(RemapVars &rv)
printf("num_links %zu max_links %zu num_blks %zu\n", rv.num_links, max_links, num_blks); printf("num_links %zu max_links %zu num_blks %zu\n", rv.num_links, max_links, num_blks);
rv.links.num_links = (size_t *) Malloc(num_blks * sizeof(size_t)); rv.links.num_links.resize(num_blks);
rv.links.dst_add = (size_t **) Malloc(num_blks * sizeof(size_t *)); rv.links.dst_add.resize(num_blks);
rv.links.src_add = (size_t **) Malloc(num_blks * sizeof(size_t *)); rv.links.src_add.resize(num_blks);
rv.links.w_index = (size_t **) Malloc(num_blks * sizeof(size_t *)); rv.links.w_index.resize(num_blks);
} }
for (j = 0; j < num_blks; j++) for (size_t j = 0; j < num_blks; j++)
{ {
rv.links.dst_add[j] = (size_t *) Malloc(max_links * sizeof(size_t)); rv.links.dst_add[j].resize(max_links);
rv.links.src_add[j] = (size_t *) Malloc(max_links * sizeof(size_t)); rv.links.src_add[j].resize(max_links);
rv.links.w_index[j] = (size_t *) Malloc(max_links * sizeof(size_t)); rv.links.w_index[j].resize(max_links);
} }
for (j = 0; j < num_blks; j++) for (size_t j = 0; j < num_blks; j++)
{ {
nval = 0; nval = 0;
lastval = -1; lastval = -1;
size_t nlinks = 0; size_t nlinks = 0;
for (n = 0; n < num_links; n++) for (size_t n = 0; n < num_links; n++)
{ {
if (rv.tgt_cell_add[n] == lastval) if (rv.tgt_cell_add[n] == lastval)
nval++; nval++;
...@@ -605,24 +599,24 @@ remapVarsFree(RemapVars &rv) ...@@ -605,24 +599,24 @@ remapVarsFree(RemapVars &rv)
if (rv.links.num_blks) if (rv.links.num_blks)
{ {
Free(rv.links.num_links); varrayFree(rv.links.num_links);
size_t num_blks = rv.links.num_blks; const auto num_blks = rv.links.num_blks;
for (size_t i = 0; i < num_blks; ++i) for (size_t i = 0; i < num_blks; ++i)
{ {
Free(rv.links.src_add[i]); varrayFree(rv.links.src_add[i]);
Free(rv.links.dst_add[i]); varrayFree(rv.links.dst_add[i]);
Free(rv.links.w_index[i]); varrayFree(rv.links.w_index[i]);
} }
Free(rv.links.src_add); varrayFree(rv.links.src_add);
Free(rv.links.dst_add); varrayFree(rv.links.dst_add);
Free(rv.links.w_index); varrayFree(rv.links.w_index);
} }
} }
} }
else else
fprintf(stderr, "%s Warning: vars not initialized!\n", __func__); fprintf(stderr, "%s Warning: vars not initialized!\n", __func__);
} /* remapVarsFree */ } // remapVarsFree
void void
remapVarsCheckWeights(const RemapVars &rv) remapVarsCheckWeights(const RemapVars &rv)
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
#define REMAP_VARS_H #define REMAP_VARS_H
#include <cstdio> // size_t #include <cstdio> // size_t
#include <vector> #include <array>
class RemapGradients class RemapGradients
{ {
public: public:
std::vector<double> grad_lat; Varray<double> grad_lat;
std::vector<double> grad_lon; Varray<double> grad_lon;
std::vector<double> grad_latlon; Varray<double> grad_latlon;
void void
init(size_t size) init(size_t size)
...@@ -40,15 +40,15 @@ enum class NormOpt ...@@ -40,15 +40,15 @@ enum class NormOpt
FRACAREA FRACAREA
}; };
struct remaplink_t struct RemapLink
{ {
bool option; bool option;
size_t max_links; size_t max_links;
size_t num_blks; size_t num_blks;
size_t *num_links; Varray<size_t> num_links;
size_t **src_add; Varray2D<size_t> src_add;
size_t **dst_add; Varray2D<size_t> dst_add;
size_t **w_index; Varray2D<size_t> w_index;
}; };
struct RemapVars struct RemapVars
...@@ -67,7 +67,7 @@ struct RemapVars ...@@ -67,7 +67,7 @@ struct RemapVars
Varray<size_t> tgt_cell_add; // target grid address for each link Varray<size_t> tgt_cell_add; // target grid address for each link
Varray<double> wts; // map weights for each link [max_links*num_wts] Varray<double> wts; // map weights for each link [max_links*num_wts]
remaplink_t links; RemapLink links;
}; };
void remap(double *dst_array, double missval, size_t dst_size, const RemapVars &rv, const double *src_array, void remap(double *dst_array, double missval, size_t dst_size, const RemapVars &rv, const double *src_array,
......
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