(git:f56c6e3)
Loading...
Searching...
No Matches
grid_miniapp.c
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7#include "../offload/offload_library.h"
8#include "../offload/offload_mempool.h"
10#include "grid_replay.h"
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16/*******************************************************************************
17 * \brief Wrapper for printf, passed to grid_library_print_stats.
18 * \author Ole Schuett
19 ******************************************************************************/
20static void print_func(const char *msg, int msglen, int output_unit) {
21 (void)msglen; // mark used
22 if (output_unit == 0) { // i.e. my_rank == 0
23 printf("%s", msg);
24 }
25}
26
27/*******************************************************************************
28 * \brief Stand-alone miniapp for running .task files.
29 * \author Ole Schuett
30 ******************************************************************************/
31int main(int argc, char *argv[]) {
32 // Parsing of optional args.
33 int iarg = 1;
34 int nrequired_args = 2;
35
36 bool collocate = true;
37 if (iarg < argc && strcmp(argv[iarg], "--integrate") == 0) {
38 iarg++;
39 collocate = false;
40 }
41
42 bool batch = false;
43 if (iarg < argc && strcmp(argv[iarg], "--batch") == 0) {
44 iarg++;
45 batch = true;
46 nrequired_args++;
47 }
48
49 // All optional args have been parsed.
50 if (argc - iarg != nrequired_args) {
51 fprintf(stderr, "Usage: grid_miniapp.x [--integrate] [--batch "
52 "<cycles-per-block>] <cycles> <task-file>\n");
53 return 1;
54 }
55
56 int cycles_per_block = 1;
57 if (batch && sscanf(argv[iarg++], "%i", &cycles_per_block) != 1) {
58 fprintf(stderr, "Error: Could not parse cycles per block.\n");
59 return 1;
60 }
61
62 int cycles;
63 if (sscanf(argv[iarg++], "%i", &cycles) != 1) {
64 fprintf(stderr, "Error: Could not parse cycles.\n");
65 return 1;
66 }
67
68 offload_set_chosen_device(0);
70
71 const double tolerance = 1e-12 * cycles;
72 const bool success = grid_replay(argv[iarg++], cycles, collocate, batch,
73 cycles_per_block, tolerance);
74
75 if (success) {
76 grid_library_print_stats(0 /*fortran_comm*/, &print_func, 0 /*rank*/);
77 offload_mempool_stats_print(0 /*fortran_comm*/, &print_func, 0 /*rank*/);
79 } else {
80 fprintf(stderr, "Error: Maximal difference is too large.\n");
82 return 2;
83 }
84
85 return 0;
86}
87
88// EOF
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.
static void print_func(const char *msg, int msglen, int output_unit)
Wrapper for printf, passed to grid_library_print_stats.
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()
Unit test of the C-interface provided via libcp2k.h.