CEPS
Data Structures | Typedefs | Functions
ceps Namespace Reference

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...
 

Detailed Description

Regroups useful input/output methods and string operations.

A namespace for all utility methods.

Namespace for Map and related object, internal structures.

Typedef Documentation

◆ binary_function

template<typename _Arg1 , typename _Arg2 , typename _Res >
using ceps::binary_function = typedef function<_Res(_Arg1, _Arg2)>

Binary function.

Template Parameters
_Arg1type of argument 1
_Arg2type of argument 2
_Restype of result

◆ sol_function

Function definition, support f(u) struct.

◆ ternary_function

template<typename _Arg1 , typename _Arg2 , typename _Arg3 , typename _Res >
using ceps::ternary_function = typedef function<_Res(_Arg1, _Arg2, _Arg3)>

Ternary function.

Template Parameters
_Arg1type of argument 1
_Arg2type of argument 2
_Restype of result

◆ timespace_function

using ceps::timespace_function = typedef binary_function<real_t, std::array<real_t, 3>, real_t>

Function definition, support f(t, x) struct.

◆ unary_function

template<typename _Arg , typename _Res >
using ceps::unary_function = typedef function<_Res(_Arg)>

Unary function.

Template Parameters
_Arg1type of argument 1
_Arg2type of argument 2
_Restype of result

Function Documentation

◆ allGatherv() [1/2]

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

Parameters
[out]destglobal hastable
[in]origlocal hashtable
Returns
MPI_SUCCES if success

◆ allGatherv() [2/2]

template<typename T >
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.

Parameters
[in]localTablocal vector to put in the global vector
[in]localSizenumber of local elements we want to put in the global Tab
[out]globalTabglobal output vector gather all the local vectors
Returns
MPI_SUCCES if success

◆ argVector()

template<class T >
int_t ceps::argVector ( const std::vector< T > &  v,
const T &  item 
)

Tests occurence of item in a vector, for the sake of readability.

Returns
-1 if item is not found. Otherwise, index in vector.

◆ asRange()

template<typename I >
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.

◆ barrier()

void ceps::barrier ( )

Explicit barrier: wait for all processors before continuing.

◆ beginSequential()

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.

◆ cleanup()

std::vector< std::string > ceps::cleanup ( const std::vector< std::string > &  vec)

Clean a vector of string, remove empty and " " string.

Parameters
[in]vecthe vector of string to clean
Returns
std::vector<std::string> the vector of string after clean

◆ destroy_object() [1/2]

template<typename T >
void ceps::destroy_object ( T &  )

Destroy[delete] any type.

Template Parameters
T

◆ destroy_object() [2/2]

template<typename T >
void ceps::destroy_object ( T *&  obj)

Specialization if is_pointer : Destroy[delete] any type.

Template Parameters
T
Parameters
obj

◆ ends_with()

bool ceps::ends_with ( const std::string &  str,
const std::string &  comp 
)

Check if the string 'str' ends with 'comp'.

◆ endSequential()

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.

◆ extractParam()

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"}} 
Parameters
paramsinput string
tagstag to search to look up

◆ fileExists()

bool ceps::fileExists ( const string &  fileName,
const string &  directory 
)

Returns true if the given file is in the specified directory

Parameters
[in]fileNamethe file
[in]directoryabsolute path to the directory
Returns
true if file exists

◆ finalize()

void ceps::finalize ( )

Finalizes parallel environment.

As with ceps::initialize(), implementation differs whether PETSc is used or not.

◆ getBaseName()

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.

Parameters
[in]sfile name
Returns
base name

◆ getCommunicator()

MPI_Comm ceps::getCommunicator ( )

Get the communicator.

◆ getDir()

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/"

Parameters
sthe string, usually the absolute path to a file
Returns
the path to the directory

◆ getExtension()

string ceps::getExtension ( const string &  s)

Returns the extension of a file, if any.

Parameters
sthe file name
Returns
the file extension

◆ getFileName()

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"

Parameters
sthe string, usually the absolute path to a file
Returns
the file name

◆ getGridSize()

uint_t ceps::getGridSize ( )

Returns the number of process on the computing grid.

◆ getRank()

uint_t ceps::getRank ( )

Returns current processor rank.

◆ hasKey() [1/2]

template<class T1 , class T2 >
bool ceps::hasKey ( const std::map< T1, T2 > &  m,
const T1 &  item 
)

More readable than foo.find() != foo.end()

◆ hasKey() [2/2]

template<class T1 , class T2 >
bool ceps::hasKey ( const std::unordered_map< T1, T2 > &  m,
const T1 &  item 
)

More readable than foo.find() != foo.end()

◆ hasOccurence() [1/2]

template<class T >
bool ceps::hasOccurence ( const std::set< T > &  s,
const T &  item 
)

More readable than foo.find() != foo.end()

◆ hasOccurence() [2/2]

template<class T >
bool ceps::hasOccurence ( const std::vector< T > &  v,
const T &  item 
)

More readable test than argVector!=-1.

◆ initialize()

uint_t ceps::initialize ( int_t  argc,
char *  argv[] 
)

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.

Parameters
[in]argcnumber of arguments
[in]argvprogram arguments
Returns
non-zero value on failure.

◆ isLast()

bool ceps::isLast ( )

Is calling process last in computing grid ?

◆ isMaster()

bool ceps::isMaster ( )

Is calling process the master ?

◆ isParallel()

bool ceps::isParallel ( )

Is there more than 1 process currently working ?

◆ isPathInOneWord()

bool ceps::isPathInOneWord ( const string &  s)

Checks if given path is in one word (it may not exist yet)

◆ removeSpaces()

string ceps::removeSpaces ( const string &  s)

Removes spaces and tabs from given string

Parameters
[in]sstring to clean
Returns
cleaned string

◆ sendRecvWithMatrix()

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)

Parameters
[in]commMatcommMat(i,j) indicate the size of the vector to send from process i to process j
[in]sendBuffersvector of vector of buffers to send
[out]recvBuffersvector of vector FIXME find the size limit of communications. ~5M uint_ts on mac OS CI machine

◆ splitString() [1/3]

void ceps::splitString ( const string &  s,
std::vector< string > &  elements,
char  delimiter 
)

Splits a string using given delimiter.

Parameters
[in]sstring to split
[in,out]elementsvector that will hold the results. The vector is not cleaned before use.
[in]delimiterdelimiter to use

◆ splitString() [2/3]

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","",""

Parameters
[in]sstring to split
[in,out]elementsvector that will hold the results. The vector is not cleaned before use.
[in]delimitersdelimiters to use

◆ splitString() [3/3]

void ceps::splitString ( const string &  s,
std::vector< string > &  words,
string  delims 
)

◆ starts_with()

bool ceps::starts_with ( const std::string &  str,
const std::string &  comp 
)

Check if the string 'str' starts with 'comp'.

◆ tick()

real_t ceps::tick ( )
inline

Returns wall time in seconds on calling processor.

◆ toBool()

bool ceps::toBool ( const std::string &  s)

Cast string to bool.

Parameters
sstd::string to parse
Returns
bool the value

◆ tock()

real_t ceps::tock ( real_t  time)
inline

Returns elapsed time in seconds between given time and wall time.

Parameters
timestart time
Returns
elapsed time

◆ toInt()

int_t ceps::toInt ( const std::string &  s)

Cast string to int_t.

Parameters
sstd::string to parse
Returns
int_t the value

◆ toKey()

std::string ceps::toKey ( const std::string &  s)

Transform to key type a std::string, upper case and no spaces.

Parameters
[in]sstd::string to parse
Returns
a std::string

◆ toLower()

string ceps::toLower ( const string &  s)

Switches all characters to lower case

Parameters
[in]sstring to parse
Returns
a string

◆ toReal()

real_t ceps::toReal ( const std::string &  s)

Cast string to real_t.

Parameters
sstd::string to parse
Returns
real_t the value

◆ toUInt()

uint_t ceps::toUInt ( const std::string &  s)

Cast string to uint_t.

Parameters
sstd::string to parse
Returns
uint_t the value

◆ toUpper()

string ceps::toUpper ( const string &  s)

Switches all characters to upper case

Parameters
[in]sstring to parse
Returns
A STRING

◆ trim()

string ceps::trim ( const string &  s)

Removes trailing and preceeding spaces from given string

Parameters
[in]sstring to clean
Returns
cleaned string