VCSBeam
Functions
performance.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "vcsbeam.h"
Include dependency graph for performance.c:

Functions

double now ()
 Gets the precise current time. More...
 
int get_stopwatch_idx (logger *log, const char *stopwatch_name)
 Finds the stopwatch with the given name. More...
 
int get_stopwatch_max_name_length (logger *log)
 Finds the maximum length of stopwatch names. More...
 
double calc_stopwatch_mean (logger_stopwatch *sw)
 Calculates the mean duration of a stopwatch's runs. More...
 
double calc_stopwatch_std (logger_stopwatch *sw)
 Calculates the standard devation of a stopwatch's runs. More...
 
void write_stopwatch_stats_str (logger *log, logger_stopwatch *sw, int pad_size)
 Prints a stopwatch's statisticss (mean and std). More...
 
logger * create_logger (FILE *fout, int world_rank)
 Creates a new logger object. More...
 
void destroy_logger (logger *log)
 Destroys a logger object. More...
 
void logger_add_stopwatch (logger *log, const char *stopwatch_name, const char *description)
 Adds a stopwatch to the logger object. More...
 
void logger_start_stopwatch (logger *log, const char *stopwatch_name, bool print_description)
 Starts a stopwatch. More...
 
void logger_stop_stopwatch (logger *log, const char *stopwatch_name)
 Stops a stopwatch. More...
 
void logger_timed_message (logger *log, const char *message)
 Prints a timestamped log message. More...
 
void logger_message (logger *log, const char *message)
 Prints a log message. More...
 
void logger_stopwatch_report_stats (logger *log, const char *stopwatch_name)
 Prints a stopwatch's statistics. More...
 
void logger_report_all_stats (logger *log)
 Prints all stopwatches' statistics. More...
 

Function Documentation

◆ calc_stopwatch_mean()

double calc_stopwatch_mean ( logger_stopwatch *  sw)

Calculates the mean duration of a stopwatch's runs.

Parameters
swA stopwatch object
Returns
The mean duration of the runs of sw

◆ calc_stopwatch_std()

double calc_stopwatch_std ( logger_stopwatch *  sw)

Calculates the standard devation of a stopwatch's runs.

Parameters
swA stopwatch object
Returns
The standard deviation of the runs of sw

◆ create_logger()

logger* create_logger ( FILE *  fout,
int  world_rank 
)

Creates a new logger object.

Parameters
foutThe file stream where to print logger messages
world_rankThe rank of the current MPI process
Returns
A pointer to a newly created logger object

If world_rank is a non-negative integer, the value of world_rank will be included in log messages. To avoid printing the rank, set world_rank to PERFORMANCE_NO_MPI.

◆ destroy_logger()

void destroy_logger ( logger *  log)

Destroys a logger object.

Parameters
logThe logger object to be destroyed and its memory freed.

◆ get_stopwatch_idx()

int get_stopwatch_idx ( logger *  log,
const char *  stopwatch_name 
)

Finds the stopwatch with the given name.

Parameters
logThe logger object to be searched
[in]stopwatch_nameThe string to be searched
Returns
The index into log→stopwatches where the stopwatch name matches stopwatch_name

◆ get_stopwatch_max_name_length()

int get_stopwatch_max_name_length ( logger *  log)

Finds the maximum length of stopwatch names.

Parameters
logA logger object with stopwatches
Returns
The length of the longest name in the stopwatches in log

◆ logger_add_stopwatch()

void logger_add_stopwatch ( logger *  log,
const char *  stopwatch_name,
const char *  description 
)

Adds a stopwatch to the logger object.

Parameters
logThe logger object to be added to
stopwatch_nameA string specifying the new stopwatch's name
descriptionA string specifying the new stopwatch's purpose

◆ logger_message()

void logger_message ( logger *  log,
const char *  message 
)

Prints a log message.

Parameters
logA logger object
messageThe message to be printed

The message is printed to log->fout, including a trailing newline character.

◆ logger_report_all_stats()

void logger_report_all_stats ( logger *  log)

Prints all stopwatches' statistics.

Parameters
logthe logger object whose stopwatches are to be reported

This function prints the statistics of all stopwatches which have been run at least once. The output is aligned, with each stopwatch name being padded by the same amount.

Example:

TO DO
Todo:
Fill in an example of stats output for logger_report_all_stats().

◆ logger_start_stopwatch()

void logger_start_stopwatch ( logger *  log,
const char *  stopwatch_name,
bool  print_description 
)

Starts a stopwatch.

Parameters
logThe logger object containing the stopwatch to be started
stopwatch_nameThe name of the stopwatch to be started
print_descriptionPrint a timed message with the stopwatch's description

If the stopwatch is already running, this has no effect.

◆ logger_stop_stopwatch()

void logger_stop_stopwatch ( logger *  log,
const char *  stopwatch_name 
)

Stops a stopwatch.

Parameters
logThe logger object containing the stopwatch to be stopped
stopwatch_nameThe name of the stopwatch to be stopped

If the stopwatch is already stopped, this has no effect.

◆ logger_stopwatch_report_stats()

void logger_stopwatch_report_stats ( logger *  log,
const char *  stopwatch_name 
)

Prints a stopwatch's statistics.

Parameters
logA logger object containing the stopwatch to be reported
stopwatch_nameThe name of the stopwatch to be reported

A wrapper for write_stopwatch_stats_str(), where pad_size is set to zero, and the statistics are only printed if there has been at least one run for the specified stopwatch.

◆ logger_timed_message()

void logger_timed_message ( logger *  log,
const char *  message 
)

Prints a timestamped log message.

Parameters
logA logger object
messageThe message to be printed

The message will be printed to the file stream log->fout.

If log->world_rank is non-negative, the format of the message is

[<timestamp>] [MPI:<world_rank>] <message>

Otherwise, the format is

[timestamp] <message>

◆ now()

double now ( )

Gets the precise current time.

Returns
The current time in seconds

◆ write_stopwatch_stats_str()

void write_stopwatch_stats_str ( logger *  log,
logger_stopwatch *  sw,
int  pad_size 
)

Prints a stopwatch's statisticss (mean and std).

Parameters
logA logger object
swThe stopwatch object whose statistics are to be printed
pad_sizeThe field width for the stopwatch name (for alignment purposes)

Setting pad_size = 0 is the same as setting it to the number of characters in the stopwatch's name.