Block-Structured AMR Software Framework
TimingStats.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017, UChicago Argonne, LLC
3  * All Rights Reserved
4  *
5  * Hardware/Hybrid Cosmology Code (HACC), Version 1.0
6  *
7  * Salman Habib, Adrian Pope, Hal Finkel, Nicholas Frontiere, Katrin Heitmann,
8  * Vitali Morozov, Jeffrey Emberson, Thomas Uram, Esteban Rangel
9  * (Argonne National Laboratory)
10  *
11  * David Daniel, Patricia Fasel, Chung-Hsing Hsu, Zarija Lukic, James Ahrens
12  * (Los Alamos National Laboratory)
13  *
14  * George Zagaris
15  * (Kitware)
16  *
17  * OPEN SOURCE LICENSE
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are met:
21  *
22  * 1. Redistributions of source code must retain the above copyright notice,
23  * this list of conditions and the following disclaimer. Software changes,
24  * modifications, or derivative works, should be noted with comments and
25  * the author and organization's name.
26  *
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  *
31  * 3. Neither the names of UChicago Argonne, LLC or the Department of Energy
32  * nor the names of its contributors may be used to endorse or promote
33  * products derived from this software without specific prior written
34  * permission.
35  *
36  * 4. The software and the end-user documentation included with the
37  * redistribution, if any, must include the following acknowledgment:
38  *
39  * "This product includes software produced by UChicago Argonne, LLC under
40  * Contract No. DE-AC02-06CH11357 with the Department of Energy."
41  *
42  * *****************************************************************************
43  * DISCLAIMER
44  * THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND. NEITHER THE
45  * UNITED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR
46  * UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY,
47  * EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE
48  * ACCURARY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, DATA, APPARATUS,
49  * PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
50  * PRIVATELY OWNED RIGHTS.
51  *
52  * *****************************************************************************
53  */
54 
55 #ifndef HACC_TIMINGSTATS_H
56 #define HACC_TIMINGSTATS_H
57 
58 #include <math.h>
59 
60 #include <mpi.h>
61 
62 #include "verbosity.h"
63 
64 // lightweight timing statistics from MPI_Wtime() calls
65 // C header only, no static variables
66 // prints maximum, average/mean, minimum, and stddev
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 inline
73 void printTimingStats(MPI_Comm comm, // comm for MPI_Allreduce()
74  const char *preamble, // text at beginning of line
75  double dt) // delta t in seconds
76 {
77  int myrank, nranks;
78  double max, min, sum, avg, var, stdev;
79 
80  MPI_Comm_rank(comm, &myrank);
81  MPI_Comm_size(comm, &nranks);
82 
83  MPI_Allreduce(&dt, &max, 1, MPI_DOUBLE, MPI_MAX, comm);
84  MPI_Allreduce(&dt, &min, 1, MPI_DOUBLE, MPI_MIN, comm);
85  MPI_Allreduce(&dt, &sum, 1, MPI_DOUBLE, MPI_SUM, comm);
86  avg = sum/nranks;
87 
88  dt -= avg;
89  dt *= dt;
90  MPI_Allreduce(&dt, &var, 1, MPI_DOUBLE, MPI_SUM, comm);
91  var *= 1.0/nranks;
92  stdev = sqrt(var);
93 
94  if(myrank==0 && verbosity() > 0) {
95  printf("%s max %.3es avg %.3es min %.3es dev %.3es\n",
96  preamble, max, avg, min, stdev);
97  }
98 
99  MPI_Barrier(comm);
100 
101  return;
102 }
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif // HACC_TIMINGSTATS_H
int MPI_Comm
Definition: AMReX_ccse-mpi.H:47
void printTimingStats(MPI_Comm comm, const char *preamble, double dt)
Definition: TimingStats.h:73
@ min
Definition: AMReX_ParallelReduce.H:18
@ max
Definition: AMReX_ParallelReduce.H:17
@ sum
Definition: AMReX_ParallelReduce.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373
int verbosity()
Definition: verbosity.cpp:4