GRVY-0.38.0
Performance Timing Example using C API

An illustrative code example in C using the performance timer API is shown below (and is also available in the examples directory from a top-level install). This example illustrates basic timer usage (including the use of nested timers).

//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
//
// libGRVY - a utility library for scientific computing.
//
// Copyright (C) 2008-2013,2018-2022 The PECOS Development Team
// Additional Copyright (C) 2018 individual authors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301 USA
//
//-----------------------------------------------------------------------el-
//
// Simple example illustrating performance timing via libGRVY.
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
#include<stdio.h>
#include<unistd.h>
#include<grvy.h>
#include<sys/time.h>
#include<time.h>
const double Foo_Sleep = 0.3 * 1.e6;
const double Bar_Sleep = 0.05 * 1.e6;
const double Boo_Sleep = 0.1167 * 1.e6;
const int Max_Iters = 10;
void foo();
void bar();
void boo();
int main()
{
int i,itest;
const int num_repeat = 2;
/* Initialize the timing library - the global timer will be
initialized with this call */
grvy_timer_init("GRVY Example Timing");
/* Outer Test Loop */
for(itest=0;itest<num_repeat;itest++)
{
/* Reset the timer to mearure performance timing for each test
loop iteration */
if(itest > 0)
/* Define the beginning of the overall code portion to be monitored */
grvy_timer_begin("Main Program");
/* Primary Iteration Work Loop */
for(i=0;i<Max_Iters;i++)
{
printf("Main iteration loop = %i\n",i);
foo();
}
/* Finalize the main program timer */
grvy_timer_end("Main Program");
/* Print performance summary to stdout */
}
/* Query timers directly - results should match those
shown in grvy_timer_summarize() routine */
printf("Querying global timer elapsed time:\n");
printf("\tElapsed global time = %10.5e secs\n",grvy_timer_elapsed_global());
printf("\nQuerying individual timers (exclusive values):\n");
printf("\tfoo: %10.5e secs\n",grvy_timer_elapsedseconds("foo"));
printf("\tbar: %10.5e secs\n",grvy_timer_elapsedseconds("bar"));
printf("\tboo: %10.5e secs\n",grvy_timer_elapsedseconds("boo"));
printf("\nQuerying individual stats for timer \"bar\" (exclusive values)\n");
printf("\tbar ( count): %i\n",grvy_timer_stats_count ("bar"));
printf("\tbar ( mean): %e\n",grvy_timer_stats_mean ("bar"));
printf("\tbar (variance): %e\n",grvy_timer_stats_variance("bar"));
printf("\tbar ( min): %e\n",grvy_timer_stats_min ("bar"));
printf("\tbar ( max): %e\n",grvy_timer_stats_max ("bar"));
/* The above provides exclusive timing statistics, but you can also
query inclusive measurements as well */
printf("\nQuerying individual timers (inclusive values):\n");
printf("\tfoo: %10.5e secs\n",grvy_timer_elapsedseconds_inc("foo"));
printf("\tbar: %10.5e secs\n",grvy_timer_elapsedseconds_inc("bar"));
printf("\tboo: %10.5e secs\n",grvy_timer_elapsedseconds_inc("boo"));
printf("\nQuerying individual stats for timer \"foo\" (inclusive values)\n");
printf("\tbar ( mean): %e\n",grvy_timer_stats_mean_inc ("foo"));
printf("\tbar (variance): %e\n",grvy_timer_stats_variance_inc("foo"));
printf("\tbar ( min): %e\n",grvy_timer_stats_min_inc ("foo"));
printf("\tbar ( max): %e\n",grvy_timer_stats_max_inc ("foo"));
/* save measured timing to historical performance DB (required
optional HDF library linkage) */
const int num_procs = 1;
grvy_timer_save_hist("C-Example1","My clever comment",num_procs,"hist.h5");
return 0;
}
void foo()
{
/* Mark the beginning of new timer */
usleep(Foo_Sleep);
bar();
/* Mark the end of the timer */
return;
}
void bar()
{
/* Mark the beginning of new timer (use macro for function name) */
grvy_timer_begin(__func__);
usleep(Bar_Sleep);
boo();
/* Mark the end of the timer */
grvy_timer_end(__func__);
return;
}
void boo()
{
/* Mark the beginning of new timer */
grvy_timer_begin(__func__);
usleep(Boo_Sleep);
/* Mark the end of the timer */
grvy_timer_end(__func__);
return;
}
grvy_timer_save_hist
int grvy_timer_save_hist(const char *experiment_name, const char *comment, int num_procs, const char *filename)
Save current libGRVY timing results to HDF file for logging.
grvy_timer_stats_min
double grvy_timer_stats_min(const char *id)
Returns the minimum (exclusive) measured timing (in seconds) for defined timer id.
grvy_timer_finalize
void grvy_timer_finalize()
Finalize global timing process - stops the active global timer.
grvy_timer_elapsedseconds_inc
double grvy_timer_elapsedseconds_inc(const char *id)
Returns total (inclusive) elapsed time (in seconds) for defined timer id.
grvy_timer_begin
void grvy_timer_begin(const char *id)
Identify beginning of code section to time with unique id string.
grvy_timer_stats_count
int grvy_timer_stats_count(const char *id)
Returns the total number of timer calls for defined timer id.
grvy_timer_init
void grvy_timer_init(const char *description)
Initialize timer library with a description string which initiates the global timing process (the des...
grvy_timer_summarize
void grvy_timer_summarize()
Print a concise summary of all defined timers to stdout. This routine shows the relative runtime perc...
grvy_timer_elapsedseconds
double grvy_timer_elapsedseconds(const char *id)
Returns total (exclusive) elapsed time (in seconds) for defined timer id.
grvy_timer_stats_min_inc
double grvy_timer_stats_min_inc(const char *id)
Returns the minimum (inclusive) measured timing (in seconds) for defined timer id.
grvy_timer_stats_max_inc
double grvy_timer_stats_max_inc(const char *id)
Returns the largest (inclusive) measured timing (in seconds) for defined timer id.
grvy_timer_stats_mean_inc
double grvy_timer_stats_mean_inc(const char *id)
Returns the mean (inclusive) value (in seconds) for defined timer id.
grvy_timer_reset
void grvy_timer_reset()
Resets all actively defined timers (accumulated time and calling statistics are reinitialized).
grvy_timer_end
void grvy_timer_end(const char *id)
Identify end of code section to time with a matching id string.
grvy_timer_stats_variance_inc
double grvy_timer_stats_variance_inc(const char *id)
Returns the variance (inclusive) for defined timer id.
grvy.h
grvy_timer_elapsed_global
double grvy_timer_elapsed_global()
Returns total elapsed time (in seconds) for the global timer.
grvy_timer_stats_mean
double grvy_timer_stats_mean(const char *id)
Returns the mean (exclusive) value (in seconds) for defined timer id.
grvy_timer_stats_variance
double grvy_timer_stats_variance(const char *id)
Returns the variance (exclusive) for defined timer id.
grvy_timer_stats_max
double grvy_timer_stats_max(const char *id)
Returns the largest (exclusive) measured timing (in seconds) for defined timer id.

Generated on Wed Jul 12 2023 16:53:23 for GRVY-0.38.0 by  doxygen 1.8.17