21static void print_func(
const char *msg,
int msglen,
int output_unit) {
23 if (output_unit == 0) {
32static int run_test(
const char cp2k_root_dir[],
const char task_file[]) {
33 if (strlen(cp2k_root_dir) > 512) {
34 fprintf(stderr,
"Error: cp2k_root_dir too long.\n");
39 strcpy(filename, cp2k_root_dir);
40 if (filename[strlen(filename) - 1] !=
'/') {
41 strcat(filename,
"/");
44 strcat(filename,
"src/grid/sample_tasks/");
45 strcat(filename, task_file);
47 const double tolerance = 1e-12;
49 for (
int icol = 0; icol < 2; icol++) {
50 for (
int ibatch = 0; ibatch < 2; ibatch++) {
52 grid_replay(filename, 1, icol == 1, ibatch == 1, 1, tolerance);
54 printf(
"Max diff too high, test failed.\n\n");
62int main(
int argc,
char *argv[]) {
66 printf(
"Usage: grid_unittest.x <cp2k-root-dir>\n");
75 errors +=
run_test(argv[1],
"ortho_density_l0000.task");
76 errors +=
run_test(argv[1],
"ortho_density_l0122.task");
77 errors +=
run_test(argv[1],
"ortho_density_l2200.task");
78 errors +=
run_test(argv[1],
"ortho_density_l3300.task");
79 errors +=
run_test(argv[1],
"ortho_density_l3333.task");
80 errors +=
run_test(argv[1],
"ortho_density_l0505.task");
81 errors +=
run_test(argv[1],
"ortho_non_periodic.task");
82 errors +=
run_test(argv[1],
"ortho_tau.task");
83 errors +=
run_test(argv[1],
"general_density.task");
84 errors +=
run_test(argv[1],
"general_tau.task");
85 errors +=
run_test(argv[1],
"general_subpatch0.task");
86 errors +=
run_test(argv[1],
"general_subpatch16.task");
87 errors +=
run_test(argv[1],
"general_overflow.task");
93 printf(
"\nAll tests have passed :-)\n");
96 printf(
"\nFound %i errors :-(\n", errors);
void cp_mpi_init(int *argc, char ***argv)
Initialize MPI with MPI_THREAD_MULTIPLE or attach to an active MPI.
void cp_mpi_finalize(void)
Detach from MPI and finalize it only if cp_mpi_init initialized it.
static void print_func(const char *msg, int msglen, int output_unit)
Wrapper for printf, passed to dbm_library_print_stats.
void grid_library_finalize(void)
Finalizes the grid library.
void grid_library_init(void)
Initializes the grid library.
void grid_library_print_stats(const int fortran_comm, void(*print_func)(const char *, int, int), const int output_unit)
Prints statistics gathered by 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....
static void print_func(const char *msg, int msglen, 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.
int main()
Unit test of the C-interface provided via libcp2k.h.
void offload_set_chosen_device(int device_id)
Selects the chosen device to be used.
void offload_mempool_stats_print(int fortran_comm, void(*print_func)(const char *, int, int), int output_unit)
Print allocation statistics..