(git:ccc2433)
grid_miniapp.c
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* CP2K: A general program to perform molecular dynamics simulations */
3 /* Copyright 2000-2024 CP2K developers group <https://cp2k.org> */
4 /* */
5 /* SPDX-License-Identifier: BSD-3-Clause */
6 /*----------------------------------------------------------------------------*/
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "../offload/offload_library.h"
13 #include "common/grid_library.h"
14 #include "grid_replay.h"
15 
16 void mpi_sum_func(long *number, int mpi_comm) {
17  *number += 0; // Nothing todo without MPI, pretend arguments are used anyways.
18  mpi_comm += 0;
19 }
20 
21 void print_func(char *message, int output_unit) {
22  output_unit += 0; // Pretend argument is used.
23  printf("%s", message);
24 }
25 
26 /*******************************************************************************
27  * \brief Stand-alone miniapp for running .task files.
28  * \author Ole Schuett
29  ******************************************************************************/
30 int main(int argc, char *argv[]) {
31  // Parsing of optional args.
32  int iarg = 1;
33  int nrequired_args = 2;
34 
35  bool collocate = true;
36  if (iarg < argc && strcmp(argv[iarg], "--integrate") == 0) {
37  iarg++;
38  collocate = false;
39  }
40 
41  bool batch = false;
42  if (iarg < argc && strcmp(argv[iarg], "--batch") == 0) {
43  iarg++;
44  batch = true;
45  nrequired_args++;
46  }
47 
48  // All optional args have been parsed.
49  if (argc - iarg != nrequired_args) {
50  fprintf(stderr, "Usage: grid_miniapp.x [--integrate] [--batch "
51  "<cycles-per-block>] <cycles> <task-file>\n");
52  return 1;
53  }
54 
55  int cycles_per_block = 1;
56  if (batch && sscanf(argv[iarg++], "%i", &cycles_per_block) != 1) {
57  fprintf(stderr, "Error: Could not parse cycles per block.\n");
58  return 1;
59  }
60 
61  int cycles;
62  if (sscanf(argv[iarg++], "%i", &cycles) != 1) {
63  fprintf(stderr, "Error: Could not parse cycles.\n");
64  return 1;
65  }
66 
69 
70  const double tolerance = 1e-12 * cycles;
71  const bool success = grid_replay(argv[iarg++], cycles, collocate, batch,
72  cycles_per_block, tolerance);
73 
76 
77  if (!success) {
78  fprintf(stderr, "Error: Maximal difference is too large.\n");
79  return 2;
80  }
81 
82  return 0;
83 }
84 
85 // EOF
void grid_library_finalize(void)
Finalizes the grid library.
Definition: grid_library.c:83
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.
Definition: grid_library.c:155
void grid_library_init(void)
Initializes the grid library.
Definition: grid_library.c:49
int main(int argc, char *argv[])
Stand-alone miniapp for running .task files.
Definition: grid_miniapp.c:30
void mpi_sum_func(long *number, int mpi_comm)
Definition: grid_miniapp.c:16
void print_func(char *message, int output_unit)
Definition: grid_miniapp.c:21
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....
Definition: grid_replay.c:222
subroutine, public offload_set_chosen_device(device_id)
Selects the chosen device to be used.
Definition: offload_api.F:132