CEPS
|
Regroups useful input/output methods and string operations. More...
Data Structures | |
class | map |
ceps::map object acts like std::map but with additional methods (print and contains) More... | |
struct | KeyGen |
Key translator, basically translate used map key to string if it's possible. More... | |
struct | KeyGen< std::string > |
Specialization of key translator for string type : just upper and trim spaces. More... | |
struct | MapPrinter |
Structure tool to print a map defined by two templates. More... | |
struct | MapPrinter< std::string, OBJECT_T > |
Specialization of the structure tool to print print a map with KEY_T = std::string. More... | |
struct | MapPrinter< std::string, std::string > |
Explicit specialization for map with KEY_T = OBJECT_T = std::string. More... | |
struct | RangeAdapter |
Use std::pair of iterator returned by equal_range as iterator with a begin() and end() method. More... | |
struct | type_separator |
Type separator with variadic template : if variadic gets tuple if unique type gets just a normal type. More... | |
struct | type_separator< T > |
Specialization of type separator with a unique type. More... | |
struct | is_tuple |
Get if the template is a tuple : std::false_type. More... | |
struct | is_tuple< std::tuple< T... > > |
Get if the template is a tuple : std::true_type. More... | |
struct | function |
function caller : abstract base, only contains an variadic operator() More... | |
struct | function< _Res(_Args...)> |
function caller : abstract base, only contains a variadic operator() More... | |
struct | char_holder |
Store with static way a char, can be used as template with the correct use. More... | |
Typedefs | |
template<typename _Arg , typename _Res > | |
using | unary_function = function< _Res(_Arg)> |
Unary function. More... | |
template<typename _Arg1 , typename _Arg2 , typename _Res > | |
using | binary_function = function< _Res(_Arg1, _Arg2)> |
Binary function. More... | |
template<typename _Arg1 , typename _Arg2 , typename _Arg3 , typename _Res > | |
using | ternary_function = function< _Res(_Arg1, _Arg2, _Arg3)> |
Ternary function. More... | |
using | timespace_function = binary_function< real_t, std::array< real_t, 3 >, real_t > |
Function definition, support f(t, x) struct. More... | |
using | sol_function = unary_function< real_t, real_t > |
Function definition, support f(u) struct. More... | |
Functions | |
string | getDir (const string &s) |
string | getBaseName (const string &s) |
Extracts the base of a file name, without path, nor extension. Ex: getBaseName ("/path/to/myfile.dat") returns myfile Ex: getBaseName ("./path.with.dots//farboo") returns farboo . More... | |
string | getFileName (const string &s) |
string | getExtension (const string &s) |
bool | fileExists (const string &fileName, const string &directory) |
void | splitString (const string &s, std::vector< string > &elements, char delimiter) |
Splits a string using given delimiter. More... | |
void | splitString (const string &s, std::vector< string > &words, string delims) |
std::vector< std::string > | cleanup (const std::vector< std::string > &vec) |
Clean a vector of string, remove empty and " " string. More... | |
string | trim (const string &s) |
string | removeSpaces (const string &s) |
string | toUpper (const string &s) |
string | toLower (const string &s) |
bool | isPathInOneWord (const string &s) |
std::string | toKey (const std::string &s) |
Transform to key type a std::string, upper case and no spaces. More... | |
bool | toBool (const std::string &s) |
Cast string to bool. More... | |
real_t | toReal (const std::string &s) |
Cast string to real_t. More... | |
int_t | toInt (const std::string &s) |
Cast string to int_t. More... | |
uint_t | toUInt (const std::string &s) |
Cast string to uint_t. More... | |
bool | starts_with (const std::string &str, const std::string &comp) |
Check if the string 'str' starts with 'comp'. More... | |
bool | ends_with (const std::string &str, const std::string &comp) |
Check if the string 'str' ends with 'comp'. More... | |
ceps::map< std::vector< std::string >, std::string > | extractParam (std::string params, std::set< std::string > tags) |
Builds a map of keywords and parameter words according to tags. More... | |
void | splitString (const string &s, std::vector< string > &elements, std::string delimiters=std::string(" \t")) |
Splits a string using mulitple delimiters in a single string. More... | |
uint_t | initialize (int_t argc, char *argv[]) |
Initializes parallel environment. More... | |
void | finalize () |
Finalizes parallel environment. More... | |
uint_t | getRank () |
Returns current processor rank. More... | |
uint_t | getGridSize () |
Returns the number of process on the computing grid. More... | |
bool | isMaster () |
Is calling process the master ? More... | |
bool | isLast () |
Is calling process last in computing grid ? More... | |
bool | isParallel () |
Is there more than 1 process currently working ? More... | |
void | barrier () |
Explicit barrier: wait for all processors before continuing. More... | |
void | beginSequential () |
Begins a sequential block. More... | |
void | endSequential () |
End a sequential block. More... | |
MPI_Comm | getCommunicator () |
Get the communicator. More... | |
template<typename T > | |
int | allGatherv (const std::vector< T > &localTab, int localSize, std::vector< T > &globalTab) |
Gather all the local orig vector in the global dest vector. More... | |
int | allGatherv (const std::unordered_map< uint_t, uint_t > &orig, std::unordered_map< uint_t, uint_t > &dest) |
gather all the local orig hashtable in the global dest hastable More... | |
void | sendRecvWithMatrix (const Eigen::Matrix< uint_t, Eigen::Dynamic, Eigen::Dynamic > &commMat, std::vector< std::vector< uint_t >> &sendBuffers, std::vector< std::vector< uint_t >> &recvBuffers) |
Pair to pair communication (using matrix) More... | |
real_t | tick () |
Returns wall time in seconds on calling processor. More... | |
real_t | tock (real_t time) |
Returns elapsed time in seconds between given time and wall time. More... | |
template<typename I > | |
RangeAdapter< I > | asRange (const std::pair< I, I > &p) |
Use std::pair of iterators returned by equal_range as iterator with a begin() and end() method. More... | |
template<class T > | |
int_t | argVector (const std::vector< T > &v, const T &item) |
Tests occurence of item in a vector, for the sake of readability. More... | |
template<class T > | |
bool | hasOccurence (const std::vector< T > &v, const T &item) |
More readable test than argVector!=-1. More... | |
template<class T1 , class T2 > | |
bool | hasKey (const std::map< T1, T2 > &m, const T1 &item) |
More readable than foo.find() != foo.end() More... | |
template<class T1 , class T2 > | |
bool | hasKey (const std::unordered_map< T1, T2 > &m, const T1 &item) |
More readable than foo.find() != foo.end() More... | |
template<class T > | |
bool | hasOccurence (const std::set< T > &s, const T &item) |
More readable than foo.find() != foo.end() More... | |
template<typename T > | |
void | destroy_object (T &) |
Destroy[delete] any type. More... | |
template<typename T > | |
void | destroy_object (T *&obj) |
Specialization if is_pointer : Destroy[delete] any type. More... | |
Regroups useful input/output methods and string operations.
A namespace for all utility methods.
Namespace for Map and related object, internal structures.
using ceps::binary_function = typedef function<_Res(_Arg1, _Arg2)> |
Binary function.
_Arg1 | type of argument 1 |
_Arg2 | type of argument 2 |
_Res | type of result |
using ceps::sol_function = typedef unary_function<real_t, real_t> |
Function definition, support f(u) struct.
using ceps::ternary_function = typedef function<_Res(_Arg1, _Arg2, _Arg3)> |
Ternary function.
_Arg1 | type of argument 1 |
_Arg2 | type of argument 2 |
_Res | type of result |
using ceps::timespace_function = typedef binary_function<real_t, std::array<real_t, 3>, real_t> |
Function definition, support f(t, x) struct.
using ceps::unary_function = typedef function<_Res(_Arg)> |
Unary function.
_Arg1 | type of argument 1 |
_Arg2 | type of argument 2 |
_Res | type of result |
int ceps::allGatherv | ( | const std::unordered_map< uint_t, uint_t > & | orig, |
std::unordered_map< uint_t, uint_t > & | dest | ||
) |
gather all the local orig hashtable in the global dest hastable
[out] | dest | global hastable |
[in] | orig | local hashtable |
int ceps::allGatherv | ( | const std::vector< T > & | localTab, |
int | localSize, | ||
std::vector< T > & | globalTab | ||
) |
Gather all the local orig vector in the global dest vector.
[in] | localTab | local vector to put in the global vector |
[in] | localSize | number of local elements we want to put in the global Tab |
[out] | globalTab | global output vector gather all the local vectors |
int_t ceps::argVector | ( | const std::vector< T > & | v, |
const T & | item | ||
) |
Tests occurence of item
in a vector, for the sake of readability.
item
is not found. Otherwise, index in vector. RangeAdapter<I> ceps::asRange | ( | const std::pair< I, I > & | p | ) |
Use std::pair of iterators returned by equal_range as iterator with a begin() and end() method.
void ceps::barrier | ( | ) |
Explicit barrier: wait for all processors before continuing.
void ceps::beginSequential | ( | ) |
Begins a sequential block.
All the instructions between the beginning and the end of a sequential block will be run by each process one after the other. The hand is given to process 0, then process 1 etc. Users should be careful when using beginSequential and endSequential: every call to beginSequential must be coupled with a call to endSequential. Invalid use of these methods will create deadlocks.
std::vector< std::string > ceps::cleanup | ( | const std::vector< std::string > & | vec | ) |
Clean a vector of string, remove empty and " " string.
[in] | vec | the vector of string to clean |
void ceps::destroy_object | ( | T & | ) |
Destroy[delete] any type.
T |
void ceps::destroy_object | ( | T *& | obj | ) |
Specialization if is_pointer : Destroy[delete] any type.
T |
obj |
bool ceps::ends_with | ( | const std::string & | str, |
const std::string & | comp | ||
) |
Check if the string 'str' ends with 'comp'.
void ceps::endSequential | ( | ) |
End a sequential block.
All the instructions between the beginning and the end of a sequential block will be run by each process one after the other. The hand is given to process 0, then process 1 etc.
ceps::map< std::vector< std::string >, std::string > ceps::extractParam | ( | std::string | params, |
std::set< std::string > | tags | ||
) |
Builds a map of keywords and parameter words according to tags.
if splitted string vec is {"FOO","1","2","BAR","toto"} extractParam(vec,{"FOO","BAR"}) returns {"BAR":"toto","FOO":{"1","2"}}
params | input string |
tags | tag to search to look up |
bool ceps::fileExists | ( | const string & | fileName, |
const string & | directory | ||
) |
Returns true if the given file is in the specified directory
[in] | fileName | the file |
[in] | directory | absolute path to the directory |
void ceps::finalize | ( | ) |
Finalizes parallel environment.
As with ceps::initialize(), implementation differs whether PETSc is used or not.
string ceps::getBaseName | ( | const string & | s | ) |
Extracts the base of a file name, without path, nor extension. Ex: getBaseName
("/path/to/myfile.dat") returns myfile
Ex: getBaseName
("./path.with.dots//farboo") returns farboo
.
[in] | s | file name |
MPI_Comm ceps::getCommunicator | ( | ) |
Get the communicator.
string ceps::getDir | ( | const string & | s | ) |
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file.txt" returns "/home/someone/"
s | the string, usually the absolute path to a file |
string ceps::getExtension | ( | const string & | s | ) |
Returns the extension of a file, if any.
s | the file name |
string ceps::getFileName | ( | const string & | s | ) |
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone/file.txt" returns "file.txt"
s | the string, usually the absolute path to a file |
uint_t ceps::getGridSize | ( | ) |
Returns the number of process on the computing grid.
uint_t ceps::getRank | ( | ) |
Returns current processor rank.
bool ceps::hasKey | ( | const std::map< T1, T2 > & | m, |
const T1 & | item | ||
) |
More readable than foo.find() != foo.end()
bool ceps::hasKey | ( | const std::unordered_map< T1, T2 > & | m, |
const T1 & | item | ||
) |
More readable than foo.find() != foo.end()
bool ceps::hasOccurence | ( | const std::set< T > & | s, |
const T & | item | ||
) |
More readable than foo.find() != foo.end()
bool ceps::hasOccurence | ( | const std::vector< T > & | v, |
const T & | item | ||
) |
More readable test than argVector!=-1.
Initializes parallel environment.
If PETSc is used then the PETSc method PetscTools::PetscInitialize(...) is used. Else, use default MPI initialization method. Also parses command line arguments.
[in] | argc | number of arguments |
[in] | argv | program arguments |
bool ceps::isLast | ( | ) |
Is calling process last in computing grid ?
bool ceps::isMaster | ( | ) |
Is calling process the master ?
bool ceps::isParallel | ( | ) |
Is there more than 1 process currently working ?
bool ceps::isPathInOneWord | ( | const string & | s | ) |
Checks if given path is in one word (it may not exist yet)
string ceps::removeSpaces | ( | const string & | s | ) |
Removes spaces and tabs from given string
[in] | s | string to clean |
void ceps::sendRecvWithMatrix | ( | const Eigen::Matrix< uint_t, Eigen::Dynamic, Eigen::Dynamic > & | commMat, |
std::vector< std::vector< uint_t >> & | sendBuffers, | ||
std::vector< std::vector< uint_t >> & | recvBuffers | ||
) |
Pair to pair communication (using matrix)
[in] | commMat | commMat(i,j) indicate the size of the vector to send from process i to process j |
[in] | sendBuffers | vector of vector of buffers to send |
[out] | recvBuffers | vector of vector FIXME find the size limit of communications. ~5M uint_ts on mac OS CI machine |
void ceps::splitString | ( | const string & | s, |
std::vector< string > & | elements, | ||
char | delimiter | ||
) |
Splits a string using given delimiter.
[in] | s | string to split |
[in,out] | elements | vector that will hold the results. The vector is not cleaned before use. |
[in] | delimiter | delimiter to use |
void ceps::splitString | ( | const string & | s, |
std::vector< string > & | elements, | ||
std::string | delimiters = std::string(" \t") |
||
) |
Splits a string using mulitple delimiters in a single string.
Warning: this does not consider the whole argument as being a separator, but each of its character to act as one. Each created substring will be trimmed from white spaces. Beginning and trailing empty fields are still added to the result vector. Example: splitString
(" ,: far ,,boo:,",v,",:") will add to v
the strings ""
,"","far","","boo","",""
[in] | s | string to split |
[in,out] | elements | vector that will hold the results. The vector is not cleaned before use. |
[in] | delimiters | delimiters to use |
void ceps::splitString | ( | const string & | s, |
std::vector< string > & | words, | ||
string | delims | ||
) |
bool ceps::starts_with | ( | const std::string & | str, |
const std::string & | comp | ||
) |
Check if the string 'str' starts with 'comp'.
|
inline |
Returns wall time in seconds on calling processor.
bool ceps::toBool | ( | const std::string & | s | ) |
Cast string to bool.
s | std::string to parse |
Returns elapsed time in seconds between given time and wall time.
time | start time |
int_t ceps::toInt | ( | const std::string & | s | ) |
Cast string to int_t.
s | std::string to parse |
std::string ceps::toKey | ( | const std::string & | s | ) |
Transform to key type a std::string, upper case and no spaces.
[in] | s | std::string to parse |
string ceps::toLower | ( | const string & | s | ) |
Switches all characters to lower case
[in] | s | string to parse |
real_t ceps::toReal | ( | const std::string & | s | ) |
Cast string to real_t.
s | std::string to parse |
uint_t ceps::toUInt | ( | const std::string & | s | ) |
Cast string to uint_t.
s | std::string to parse |
string ceps::toUpper | ( | const string & | s | ) |
Switches all characters to upper case
[in] | s | string to parse |
string ceps::trim | ( | const string & | s | ) |
Removes trailing and preceeding spaces from given string
[in] | s | string to clean |