Skip to content

Commit

Permalink
grid: Move task dumping into reference backend
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Nov 5, 2020
1 parent db4da78 commit 5f04b44
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 256 deletions.
1 change: 0 additions & 1 deletion src/grid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ALL_HEADERS := $(shell find . -name "*.h")

ALL_OBJECTS := grid_collocate_replay.o \
grid_task_list.o \
grid_collocate.o \
common/grid_library.o \
common/grid_basis_set.o \
common/grid_sphere_cache.o \
Expand Down
4 changes: 2 additions & 2 deletions src/grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Currently, the following backends exist:

## The .task files

For debugging all collocations can be written to .task files. To enable this
feature edit the following line in [grid_collocate_cpu.c](grid_collocate_cpu.c):
For debugging all collocations by the reference backend can be written to .task
files. To enable this feature edit the following line in [grid_ref_collocate.c](ref/grid_ref_collocate.c):

```C
// Set this to true to write each task to a file.
Expand Down
70 changes: 36 additions & 34 deletions src/grid/grid_api.F
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ SUBROUTINE collocate_pgf_product(la_max, zeta, la_min, &
LOGICAL(KIND=C_BOOL) :: orthorhombic
REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: grid
INTERFACE
SUBROUTINE grid_collocate_pgf_product_c(orthorhombic, &
border_mask, func, &
la_max, la_min, lb_max, lb_min, &
zeta, zetb, rscale, dh, dh_inv, ra, rab, &
npts_global, npts_local, shift_local, border_width, &
radius, o1, o2, n1, n2, pab, &
grid) &
BIND(C, name="grid_collocate_pgf_product")
SUBROUTINE grid_ref_collocate_pgf_product_c(orthorhombic, &
border_mask, func, &
la_max, la_min, lb_max, lb_min, &
zeta, zetb, rscale, dh, dh_inv, ra, rab, &
npts_global, npts_local, shift_local, border_width, &
radius, o1, o2, n1, n2, pab, &
grid) &
BIND(C, name="grid_ref_collocate_pgf_product")
IMPORT :: C_PTR, C_INT, C_DOUBLE, C_BOOL
LOGICAL(KIND=C_BOOL), VALUE :: orthorhombic
INTEGER(KIND=C_INT), VALUE :: border_mask
Expand All @@ -164,7 +164,7 @@ SUBROUTINE grid_collocate_pgf_product_c(orthorhombic, &
INTEGER(KIND=C_INT), VALUE :: n2
TYPE(C_PTR), VALUE :: pab
TYPE(C_PTR), VALUE :: grid
END SUBROUTINE grid_collocate_pgf_product_c
END SUBROUTINE grid_ref_collocate_pgf_product_c
END INTERFACE

!TODO remove unused dummy arguments
Expand Down Expand Up @@ -204,31 +204,33 @@ END SUBROUTINE grid_collocate_pgf_product_c
CPASSERT(IS_CONTIGUOUS(grid))
#endif

CALL grid_collocate_pgf_product_c(orthorhombic=orthorhombic, &
border_mask=border_mask, &
func=ga_gb_function, &
la_max=la_max, &
la_min=la_min, &
lb_max=lb_max, &
lb_min=lb_min, &
zeta=zeta, &
zetb=zetb, &
rscale=scale, &
dh=C_LOC(rsgrid%desc%dh(1, 1)), &
dh_inv=C_LOC(rsgrid%desc%dh_inv(1, 1)), &
ra=C_LOC(ra(1)), &
rab=C_LOC(rab(1)), &
npts_global=C_LOC(npts_global(1)), &
npts_local=C_LOC(npts_local(1)), &
shift_local=C_LOC(shift_local(1)), &
border_width=C_LOC(border_width(1)), &
radius=radius, &
o1=o1, &
o2=o2, &
n1=SIZE(pab, 1), &
n2=SIZE(pab, 2), &
pab=C_LOC(pab(1, 1)), &
grid=C_LOC(grid(1, 1, 1)))
! For collocating single pgf products there is only the reference implementation.

CALL grid_ref_collocate_pgf_product_c(orthorhombic=orthorhombic, &
border_mask=border_mask, &
func=ga_gb_function, &
la_max=la_max, &
la_min=la_min, &
lb_max=lb_max, &
lb_min=lb_min, &
zeta=zeta, &
zetb=zetb, &
rscale=scale, &
dh=C_LOC(rsgrid%desc%dh(1, 1)), &
dh_inv=C_LOC(rsgrid%desc%dh_inv(1, 1)), &
ra=C_LOC(ra(1)), &
rab=C_LOC(rab(1)), &
npts_global=C_LOC(npts_global(1)), &
npts_local=C_LOC(npts_local(1)), &
shift_local=C_LOC(shift_local(1)), &
border_width=C_LOC(border_width(1)), &
radius=radius, &
o1=o1, &
o2=o2, &
n1=SIZE(pab, 1), &
n2=SIZE(pab, 2), &
pab=C_LOC(pab(1, 1)), &
grid=C_LOC(grid(1, 1, 1)))

END SUBROUTINE collocate_pgf_product

Expand Down
63 changes: 0 additions & 63 deletions src/grid/grid_collocate.c

This file was deleted.

58 changes: 0 additions & 58 deletions src/grid/grid_collocate.h

This file was deleted.

97 changes: 3 additions & 94 deletions src/grid/grid_collocate_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*----------------------------------------------------------------------------*/

// needed for struct timespec
#define _XOPEN_SOURCE 700 /* Enable POSIX 2008/13 */

#include <assert.h>
#include <fenv.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
Expand All @@ -20,100 +20,9 @@
#include <time.h>

#include "common/grid_common.h"
#include "grid_collocate.h"
#include "grid_collocate_replay.h"
#include "grid_task_list.h"

/*******************************************************************************
* \brief Writes the given arguments into a .task file.
* See grid_collocate_replay.h for details.
* \author Ole Schuett
******************************************************************************/
void grid_collocate_record(
const bool orthorhombic, const int border_mask, const int func,
const int la_max, const int la_min, const int lb_max, const int lb_min,
const double zeta, const double zetb, const double rscale,
const double dh[3][3], const double dh_inv[3][3], const double ra[3],
const double rab[3], const int npts_global[3], const int npts_local[3],
const int shift_local[3], const int border_width[3], const double radius,
const int o1, const int o2, const int n1, const int n2,
const double pab[n2][n1], const double *grid) {

static int counter = 1;
int my_number;

#pragma omp critical
my_number = counter++;

char filename[100];
snprintf(filename, sizeof(filename), "grid_collocate_%05i.task", my_number);

const int D = DECIMAL_DIG; // In C11 we could use DBL_DECIMAL_DIG.
FILE *fp = fopen(filename, "w+");
fprintf(fp, "#Grid collocate task v9\n");
fprintf(fp, "orthorhombic %i\n", orthorhombic);
fprintf(fp, "border_mask %i\n", border_mask);
fprintf(fp, "func %i\n", func);
fprintf(fp, "la_max %i\n", la_max);
fprintf(fp, "la_min %i\n", la_min);
fprintf(fp, "lb_max %i\n", lb_max);
fprintf(fp, "lb_min %i\n", lb_min);
fprintf(fp, "zeta %.*e\n", D, zeta);
fprintf(fp, "zetb %.*e\n", D, zetb);
fprintf(fp, "rscale %.*e\n", D, rscale);
for (int i = 0; i < 3; i++)
fprintf(fp, "dh %i %.*e %.*e %.*e\n", i, D, dh[i][0], D, dh[i][1], D,
dh[i][2]);
for (int i = 0; i < 3; i++)
fprintf(fp, "dh_inv %i %.*e %.*e %.*e\n", i, D, dh_inv[i][0], D,
dh_inv[i][1], D, dh_inv[i][2]);
fprintf(fp, "ra %.*e %.*e %.*e\n", D, ra[0], D, ra[1], D, ra[2]);
fprintf(fp, "rab %.*e %.*e %.*e\n", D, rab[0], D, rab[1], D, rab[2]);
fprintf(fp, "npts_global %i %i %i\n", npts_global[0], npts_global[1],
npts_global[2]);
fprintf(fp, "npts_local %i %i %i\n", npts_local[0], npts_local[1],
npts_local[2]);
fprintf(fp, "shift_local %i %i %i\n", shift_local[0], shift_local[1],
shift_local[2]);
fprintf(fp, "border_width %i %i %i\n", border_width[0], border_width[1],
border_width[2]);
fprintf(fp, "radius %.*e\n", D, radius);
fprintf(fp, "o1 %i\n", o1);
fprintf(fp, "o2 %i\n", o2);
fprintf(fp, "n1 %i\n", n1);
fprintf(fp, "n2 %i\n", n2);

for (int i = 0; i < n2; i++) {
for (int j = 0; j < n1; j++) {
fprintf(fp, "pab %i %i %.*e\n", i, j, D, pab[i][j]);
}
}

const int npts_local_total = npts_local[0] * npts_local[1] * npts_local[2];

int ngrid_nonzero = 0;
for (int i = 0; i < npts_local_total; i++) {
if (grid[i] != 0.0) {
ngrid_nonzero++;
}
}
fprintf(fp, "ngrid_nonzero %i\n", ngrid_nonzero);

for (int k = 0; k < npts_local[2]; k++) {
for (int j = 0; j < npts_local[1]; j++) {
for (int i = 0; i < npts_local[0]; i++) {
const double val =
grid[k * npts_local[1] * npts_local[0] + j * npts_local[0] + i];
if (val != 0.0) {
fprintf(fp, "grid %i %i %i %.*e\n", i, j, k, D, val);
}
}
}
}
fprintf(fp, "#THE_END\n");
fclose(fp);
printf("Wrote %s\n", filename);
}
#include "ref/grid_ref_collocate.h"

/*******************************************************************************
* \brief Reads next line from given filehandle and handles errors.
Expand Down Expand Up @@ -427,7 +336,7 @@ double grid_collocate_replay(const char *filename, const int cycles,

clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
for (int i = 0; i < cycles; i++) {
grid_collocate_pgf_product(
grid_ref_collocate_pgf_product(
orthorhombic, border_mask, func, la_max, la_min, lb_max, lb_min, zeta,
zetb, rscale, dh, dh_inv, ra, rab, npts_global, npts_local,
shift_local, border_width, radius, o1, o2, n1, n2, pab, grid_test);
Expand Down

0 comments on commit 5f04b44

Please sign in to comment.