FEI Version of the Day
fei_test_utils Namespace Reference


std::string construct_filename (int argc, char **argv)
int initialize_mpi (int argc, char **argv, int &localProc, int &numProcs)
bool bool_arg (const char *flag, int argc, char **argv, bool default_result)
std::string get_arg_value (const char *flag, int argc, char **argv)
void broadcast_string (MPI_Comm comm, int root, std::string &strg)
void read_file_lines_into_strings (const char *filename, std::vector< std::string > &file_contents)
int get_filename_and_read_input (int argc, char **argv, MPI_Comm comm, int localProc, std::vector< std::string > &stdstrings)
void read_input_file (const char *filename, MPI_Comm comm, std::vector< std::string > &file_contents)
double get_file_benchmark (const char *filename, const char *testname)
bool within_percentage_margin (double value1, double value2, unsigned margin)

Detailed Description

The fei_test_utils namespace contains general test-utility functions.

Function Documentation

std::string fei_test_utils::construct_filename ( int  argc,
char **  argv 

Look through argv for a '-i' argument which names an input file, and a '-d' argument which names the directory in which the input file is to be found. If the '-i' argument is present but the '-d' argument is not present, then the path to the input file will be assumed to be ".".

Definition at line 26 of file fei_test_utils.cpp.

int fei_test_utils::initialize_mpi ( int  argc,
char **  argv,
int &  localProc,
int &  numProcs 

If the macro FEI_SER is not defined, call MPI_Init and then call MPI_Comm_rank to set localProc and MPI_Comm_size to set numProcs.

If the macro FEI_SER is defined, then simply set localProc = 0 and set numProcs = 1.

Definition at line 65 of file fei_test_utils.cpp.

bool fei_test_utils::bool_arg ( const char *  flag,
int  argc,
char **  argv,
bool  default_result = false 

If flag is in the specified command-line arguments, and it is accompanied by either "yes" or "true" (case insensitive), then return true. If it is accompanied by "no" or "false", return false. If flag is not in the specified command-line arguments, return false unless the optional parameter 'default_result' is set to true.

(e.g., return true if some argv[i] == flag and argv[i+1] == "yes".)

Definition at line 78 of file fei_test_utils.cpp.

std::string fei_test_utils::get_arg_value ( const char *  flag,
int  argc,
char **  argv 

Return argument string corresponding to flag from the command-line arguments. Example: if command-line arguments include some argv[i]="-d" and argv[i+1] = "path", and this function is called with flag=="-d", then the returned string value will be "path".

Definition at line 103 of file fei_test_utils.cpp.

void fei_test_utils::broadcast_string ( MPI_Comm  comm,
int  root,
std::string &  strg 

Broadcast string from 'root' processor so that on exit, the string has the same contents on all processors. Does nothing if num-procs==1 or if the compile-time macro FEI_SER is defined.

Definition at line 118 of file fei_test_utils.cpp.

void fei_test_utils::read_file_lines_into_strings ( const char *  filename,
std::vector< std::string > &  file_contents 

read contents of file line by line into a vector of strings. This is a purely serial operation.

Definition at line 150 of file fei_test_utils.cpp.

int fei_test_utils::get_filename_and_read_input ( int  argc,
char **  argv,
MPI_Comm  comm,
int  localProc,
std::vector< std::string > &  stdstrings 

Check command-line arguments for an input-file specified by '-i', and optionally a path specified by '-d', and then read the contents of the input-file into the user-provided parameter-strings.

Filename is constructed on proc 0, file is read on proc 0, and contents are returned on all processors.

Definition at line 174 of file fei_test_utils.cpp.

void fei_test_utils::read_input_file ( const char *  filename,
MPI_Comm  comm,
std::vector< std::string > &  file_contents 

This function reads the contents of filename on processor 0, and broadcasts those contents (strings) to all processors. All processors return the file contents in the file_contents argument.

If the file is not found, or can't be opened, an std::runtime_error will be thrown.

Definition at line 194 of file fei_test_utils.cpp.

double fei_test_utils::get_file_benchmark ( const char *  filename,
const char *  testname 

Given a file-name and test-name, return the named benchmark value.

If anything goes wrong, such as the file can't be read, or the specified testname doesn't appear in the file, throw an std::runtime_error.

Definition at line 243 of file fei_test_utils.cpp.

bool fei_test_utils::within_percentage_margin ( double  value1,
double  value2,
unsigned  margin 

Given two values determine whether the values are within 'margin' percentage points of each other. i.e., return true if 100*abs(value1 - value2)/max(abs(value1),abs(value2)) <= margin

Note: if max(abs(value1),abs(value2)) < 1.e-14, return true

Definition at line 260 of file fei_test_utils.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends