Skip to content

Commit

Permalink
grid: Fix const warnings for icc and gcc -Wpedantic
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Aug 24, 2020
1 parent 0cf0ea7 commit b1360cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/grid/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS = -fopenmp -g -O3 -std=c99 -march=native -Wall -Wextra
CFLAGS = -fopenmp -g -O3 -std=c99 -march=native -Wall -Wextra -Wpedantic

all: grid_collocate_miniapp.x grid_collocate_unittest.x

Expand Down
35 changes: 21 additions & 14 deletions src/grid/grid_collocate_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,13 @@ static void grid_collocate_ortho(const int lp, const double zetp,
cmax = max(cmax, ub_cube[i]);
}

double pol[3][lp + 1][2 * cmax + 1];
double pol_mutable[3][lp + 1][2 * cmax + 1];
for (int i = 0; i < 3; i++) {
grid_fill_pol(dh[i][i], roffset[i], lb_cube[i], lp, cmax, zetp, pol[i]);
grid_fill_pol(dh[i][i], roffset[i], lb_cube[i], lp, cmax, zetp,
pol_mutable[i]);
}
const double(*pol)[lp + 1][2 * cmax + 1] =
(const double(*)[lp + 1][2 * cmax + 1]) pol_mutable;

// Enable to run a much simpler, but also slower implementation.
if (false) {
Expand All @@ -443,11 +446,12 @@ static void grid_collocate_ortho(const int lp, const double zetp,
npts_local, shift_local, grid);
} else {
// a mapping so that the ig corresponds to the right grid point
int map[3][2 * cmax + 1];
int map_mutable[3][2 * cmax + 1];
for (int i = 0; i < 3; i++) {
grid_fill_map(lb_cube[i], ub_cube[i], cubecenter[i], npts_global[i],
shift_local[i], cmax, map[i]);
shift_local[i], cmax, map_mutable[i]);
}
const int(*map)[2 * cmax + 1] = (const int(*)[2 * cmax + 1]) map_mutable;

grid_collocate_core(lp, cmax, coef_xyz, pol, map, lb_cube, dh, dh_inv,
disr_radius, npts_local, grid);
Expand Down Expand Up @@ -751,14 +755,15 @@ static void grid_collocate_internal(
const int lb_min_prep = max(lb_min + lb_min_diff, 0);
const int la_max_prep = la_max + la_max_diff;
const int lb_max_prep = lb_max + lb_max_diff;
const int lp = la_max_prep + lb_max_prep;

const int n1_prep = ncoset[la_max_prep];
const int n2_prep = ncoset[lb_max_prep];
double pab_prep[n2_prep][n1_prep];
memset(pab_prep, 0, n2_prep * n1_prep * sizeof(double));

double pab_prep_mutable[n2_prep][n1_prep];
memset(pab_prep_mutable, 0, n2_prep * n1_prep * sizeof(double));
grid_prepare_pab(func, o1, o2, la_max, la_min, lb_max, lb_min, zeta, zetb, n1,
n2, pab, n1_prep, n2_prep, pab_prep);
n2, pab, n1_prep, n2_prep, pab_prep_mutable);
const double(*pab_prep)[n1_prep] = (const double(*)[n1_prep])pab_prep_mutable;

// *** initialise the coefficient matrix, we transform the sum
//
Expand All @@ -774,9 +779,10 @@ static void grid_collocate_internal(
// (current implementation is l**7)
//

double alpha[3][lb_max_prep + 1][la_max_prep + 1]
[la_max_prep + lb_max_prep + 1];
grid_prepare_alpha(ra, rb, rp, la_max_prep, lb_max_prep, alpha);
double alpha_mutable[3][lb_max_prep + 1][la_max_prep + 1][lp + 1];
grid_prepare_alpha(ra, rb, rp, la_max_prep, lb_max_prep, alpha_mutable);
const double(*alpha)[lb_max_prep + 1][la_max_prep + 1][lp + 1] =
(const double(*)[lb_max_prep + 1][la_max_prep + 1][lp + 1]) alpha_mutable;

//
// compute P_{lxp,lyp,lzp} given P_{lxa,lya,lza,lxb,lyb,lzb} and
Expand All @@ -785,10 +791,11 @@ static void grid_collocate_internal(
// in collocate_fast.F
//

const int lp = la_max_prep + lb_max_prep;
double coef_xyz[lp + 1][lp + 1][lp + 1];
double coef_xyz_mutable[lp + 1][lp + 1][lp + 1];
grid_prepare_coef(la_max_prep, la_min_prep, lb_max_prep, lb_min_prep, lp,
prefactor, alpha, pab_prep, coef_xyz);
prefactor, alpha, pab_prep, coef_xyz_mutable);
const double(*coef_xyz)[lp + 1][lp + 1] =
(const double(*)[lp + 1][lp + 1]) coef_xyz_mutable;

if (orthorhombic && border_mask == 0) {
// Here we ignore bounds_owned and always collocate the entire cube,
Expand Down
32 changes: 19 additions & 13 deletions src/grid/grid_collocate_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,24 @@ static void create_dummy_basis_set(const int size, const int lmin,
const int lmax, const double zet,
grid_basis_set_t *basis_set) {

double sphi[size][size];
double sphi_mutable[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
sphi[i][j] = (i == j) ? 1.0 : 0.0; // identity matrix
sphi_mutable[i][j] = (i == j) ? 1.0 : 0.0; // identity matrix
}
}
const double(*sphi)[size] = (const double(*)[size])sphi_mutable;

const int npgf = size / ncoset[lmax];
assert(size == npgf * ncoset[lmax]);

const int first_sgf[1] = {1};

double zet_array[1][npgf];
double zet_array_mutable[1][npgf];
for (int i = 0; i < npgf; i++) {
zet_array[0][i] = zet;
zet_array_mutable[0][i] = zet;
}
const double(*zet_array)[npgf] = (const double(*)[npgf])zet_array_mutable;

grid_create_basis_set(/*nset=*/1,
/*nsgf=*/size,
Expand Down Expand Up @@ -267,7 +269,7 @@ static void create_dummy_task_list(
int iset_list[ntasks], jset_list[ntasks], ipgf_list[ntasks],
jpgf_list[ntasks];
int border_mask_list[ntasks], block_num_list[ntasks];
double radius_list[ntasks], rab_list[ntasks][3];
double radius_list[ntasks], rab_list_mutable[ntasks][3];
for (int i = 0; i < cycles; i++) {
level_list[i] = 1;
iatom_list[i] = 1;
Expand All @@ -279,10 +281,11 @@ static void create_dummy_task_list(
border_mask_list[i] = border_mask;
block_num_list[i] = i / cycles_per_block + 1;
radius_list[i] = radius;
rab_list[i][0] = rab[0];
rab_list[i][1] = rab[1];
rab_list[i][2] = rab[2];
rab_list_mutable[i][0] = rab[0];
rab_list_mutable[i][1] = rab[1];
rab_list_mutable[i][2] = rab[2];
}
const double(*rab_list)[3] = (const double(*)[3])rab_list_mutable;

double *blocks_buffer = NULL;

Expand Down Expand Up @@ -342,11 +345,13 @@ double grid_collocate_replay(const char *filename, const int cycles,
const double zetb = parse_double("zetb", fp);
const double rscale = parse_double("rscale", fp);

double dh[3][3], dh_inv[3][3], ra[3], rab[3];
parse_double3x3("dh", fp, dh);
parse_double3x3("dh_inv", fp, dh_inv);
double dh_mutable[3][3], dh_inv_mutable[3][3], ra[3], rab[3];
parse_double3x3("dh", fp, dh_mutable);
parse_double3x3("dh_inv", fp, dh_inv_mutable);
parse_double3("ra", fp, ra);
parse_double3("rab", fp, rab);
const double(*dh)[3] = (const double(*)[3])dh_mutable;
const double(*dh_inv)[3] = (const double(*)[3])dh_inv_mutable;

int npts_global[3], npts_local[3], shift_local[3], border_width[3];
parse_int3("npts_global", fp, npts_global);
Expand All @@ -360,14 +365,15 @@ double grid_collocate_replay(const char *filename, const int cycles,
const int n1 = parse_int("n1", fp);
const int n2 = parse_int("n2", fp);

double pab[n2][n1];
double pab_mutable[n2][n1];
char format[100];
for (int i = 0; i < n2; i++) {
for (int j = 0; j < n1; j++) {
sprintf(format, "%i %i %%le", i, j);
parse_next_line("pab", fp, format, 1, &pab[i][j]);
parse_next_line("pab", fp, format, 1, &pab_mutable[i][j]);
}
}
const double(*pab)[n1] = (const double(*)[n1])pab_mutable;

const int npts_local_total = npts_local[0] * npts_local[1] * npts_local[2];
const size_t sizeof_grid = sizeof(double) * npts_local_total;
Expand Down
2 changes: 1 addition & 1 deletion src/grid/grid_task_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ static void collocate_one_grid_level(
/*o2=*/jpgf * ncosetb,
/*n1=*/ncoa,
/*n2=*/ncob,
/*pab=*/(double(*)[ncoa])pab,
/*pab=*/(const double(*)[ncoa])pab,
/*grid=*/threadlocal_grid);
} // end of task loop

Expand Down

0 comments on commit b1360cd

Please sign in to comment.