12 #include "../offload/offload_library.h"
17 #if defined(__parallel)
36 printf(
"%s", message);
43 static int run_test(
const char cp2k_root_dir[],
const char task_file[]) {
44 if (strlen(cp2k_root_dir) > 512) {
45 fprintf(stderr,
"Error: cp2k_root_dir too long.\n");
50 strcpy(filename, cp2k_root_dir);
51 if (filename[strlen(filename) - 1] !=
'/') {
52 strcat(filename,
"/");
55 strcat(filename,
"src/grid/sample_tasks/");
56 strcat(filename, task_file);
58 const double tolerance = 1e-12;
60 for (
int icol = 0; icol < 2; icol++) {
61 for (
int ibatch = 0; ibatch < 2; ibatch++) {
63 grid_replay(filename, 1, icol == 1, ibatch == 1, 1, tolerance);
65 printf(
"Max diff too high, test failed.\n\n");
73 int main(
int argc,
char *argv[]) {
74 #if defined(__parallel)
75 MPI_Init(&argc, &argv);
79 printf(
"Usage: grid_unittest.x <cp2k-root-dir>\n");
87 errors +=
run_test(argv[1],
"ortho_density_l0000.task");
88 errors +=
run_test(argv[1],
"ortho_density_l0122.task");
89 errors +=
run_test(argv[1],
"ortho_density_l2200.task");
90 errors +=
run_test(argv[1],
"ortho_density_l3300.task");
91 errors +=
run_test(argv[1],
"ortho_density_l3333.task");
92 errors +=
run_test(argv[1],
"ortho_density_l0505.task");
93 errors +=
run_test(argv[1],
"ortho_non_periodic.task");
94 errors +=
run_test(argv[1],
"ortho_tau.task");
95 errors +=
run_test(argv[1],
"general_density.task");
96 errors +=
run_test(argv[1],
"general_tau.task");
97 errors +=
run_test(argv[1],
"general_subpatch0.task");
98 errors +=
run_test(argv[1],
"general_subpatch16.task");
99 errors +=
run_test(argv[1],
"general_overflow.task");
105 printf(
"\nAll tests have passed :-)\n");
107 printf(
"\nFound %i errors :-(\n", errors);
110 #if defined(__parallel)
void grid_library_finalize(void)
Finalizes the grid library.
void grid_library_print_stats(void(*mpi_sum_func)(long *, int), const int mpi_comm, void(*print_func)(char *, int), const int output_unit)
Prints statistics gathered by the grid library.
void grid_library_init(void)
Initializes the grid library.
bool grid_replay(const char *filename, const int cycles, const bool collocate, const bool batch, const int cycles_per_block, const double tolerance)
Reads a .task file, collocates/integrates it, and compares results. See grid_replay....
int main(int argc, char *argv[])
static void print_func(char *message, int output_unit)
Wrapper for printf, passed to grid_library_print_stats.
static int run_test(const char cp2k_root_dir[], const char task_file[])
Unit test for the grid code.
static void mpi_sum_func(long *number, int mpi_comm)
Standin for mpi_sum, passed to grid_library_print_stats.
subroutine, public offload_set_chosen_device(device_id)
Selects the chosen device to be used.