Feel++ 0.111.0-preview.14
Finite Element Embedded Library in C++
Feel::Environment Class Reference

Initialize, finalize, and query the Feel++ environment. More...

+ Inheritance diagram for Feel::Environment:
+ Collaboration diagram for Feel::Environment:

Static Public Member Functions

template<typename Observer >
static void addDeleteObserver (Observer const &obs)
 
template<typename Observer >
static void addDeleteObserver (std::shared_ptr< Observer > const &obs)
 
static void addTimer (std::string const &msg, std::pair< double, int > const &t, std::string const &uiname)
 Return the timerstable pointer. More...
 
static void clearSomeMemory ()
 
static std::string expand (std::string const &expr)
 expand feel++ pathes in a string More...
 
static std::string findFileRemotely (std::string const &fname, std::string const &subdir="")
 try find remotely the file fname More...
 
static MemoryUsage logMemoryUsage (std::string const &message)
 print resident memory usage as well as PETSc malloc usage in log file More...
 
static int logVerbosityLevel ()
 get variables_map from options_description desc More...
 
template<typename ... Ts>
static std::pair< std::string, po::variable_value > option (Ts &&... v)
 
static void saveTimers (bool save)
 display and save timers
 
static void saveTimersMD (std::ostream &os)
 
static FEELPP_DEPRECATED const fs::path & scratchDirectory ()
 
static FEELPP_DEPRECATED void setLogs (std::string const &prefix)
 set log files More...
 
static void setLogVerbosityLevel (int logVerbosity)
 set the verbosity level of the VLOG macro
 
static void startLogging (std::string decorate)
 start logging. More...
 
static void stopLogging (bool remove=false)
 stop logging in Feel++. More...
 
template<typename ... Ts>
static po::variable_value vm (Ts &&... v)
 
- Static Public Member Functions inherited from Feel::JournalManager
static void setJournalFilename (const std::string &name)
 Setters. More...
 
static void setJournalAutoMode (bool b)
 Set the journal mode. More...
 
static void setJournalEnable (bool m)
 Activate or deactivate the journal.
 
static const std::string & journalFilename ()
 Getters. More...
 
static nl::json & journalData ()
 
static const bool journalAutoMode ()
 Get the current journal mode status. More...
 
static const bool journalEnabled ()
 Get the journal status. More...
 
static const uint32_type journalCurrentCheckpoint ()
 Get the current checkpoint counter. More...
 
static decltype(auto) journalSignal ()
 Get the journal underlying static signal. More...
 
static notify_type const & journalPull ()
 Journal gather/save. More...
 
static void journalSave (std::string const &filename="")
 Save the global property tree into a json file.
 
static void journalCheckpoint (bool save=true, const std::string &filename="")
 Generate a checkpoint. More...
 
static void journalFinalize ()
 Create the journal.
 
static void journalSetDBName (const std::string &dbname="feelpp")
 Setters. More...
 
static void journalSetDBHost (const std::string &host="localhost")
 Set the mongodb host.
 
static void journalSetDBUsername (const std::string &user="")
 Set the mongodb user name.
 
static void journalSetDBPassword (const std::string &password="")
 Set the mongodb user password.
 
static void journalSetDBPort (const std::string &port="27017")
 Set the mongodb port.
 
static void journalSetDBAuthsrc (const std::string &authsrc="admin")
 Set the collection used to authenticate.
 
static void journalSetDBCollection (const std::string &dbname="journal")
 Set mongodb collection to use for the journal.
 
static void journalDBConfig (const MongoConfig &mc)
 Set mongodb collection to use for the journal.
 

Typedefs

typedef WorldComm worldcomm_type
 
typedef std::shared_ptr< WorldComm > worldcomm_ptrtype
 

Constructors, destructor

 Environment ()
 Initialize the Feel environment. More...
 
 Environment (int &argc, char **&argv)
 Initialize the Feel environment. More...
 
 Environment (int argc, char **argv, mpi::threading::level lvl, po::options_description const &desc, po::options_description const &desc_lib, AboutData const &about, Repository::Config const &config)
 Construct a new Environment object. More...
 
 Environment (NA::arguments< typename na::argc::template required_as_t< int >, typename na::argv::template required_as_t< char ** >, typename na::threading::template required_as_t< mpi::threading::level >, typename na::desc::template required_as_t< po::options_description const & >, typename na::desc_lib::template required_as_t< po::options_description const & >, typename na::about::template required_as_t< AboutData const & >, typename na::config::template required_as_t< Repository::Config const & > > &&args)
 
template<typename ... Ts, typename = typename std::enable_if_t< sizeof...(Ts) != 0 && ( NA::is_named_argument_v<Ts> && ...) >>
 Environment (Ts &&... v)
 
 ~Environment () override
 Shuts down the Feel environment. More...
 

Accessors

static bool initialized ()
 Determine if the MPI environment has already been initialized. More...
 
static bool finalized ()
 Determine if the MPI environment has already been finalized. More...
 
static bool aborted ()
 Determine if the MPI environment has already been aborted. More...
 
static std::shared_ptr< WorldComm > const & worldCommPtr ()
 
static WorldComm & worldComm ()
 return the worldcomm (static)
 
static WorldComm & worldCommSeq ()
 
static worldcomm_ptr_t & worldCommSeqPtr ()
 
static worldscomm_ptr_t & worldsComm (int n)
 return n sub world communicators
 
static worldscomm_ptr_t & worldsCommSeq (int n)
 
static worldscomm_ptr_t & worldsCommGroupBySubspace (int n)
 
static worldcomm_t & masterWorldComm (int n)
 return master world comm associated with a color map of size n
 
static int numberOfProcessors ()
 return number of processors
 
static rank_type rank ()
 return the rank in global mpi communicator
 
static rank_type masterRank ()
 return master rank in mpi communicator
 
static mpi::threading::level threadLevel ()
 get the thread level that could be set The thread level resquested to mpi may not be supported. More...
 
static bool isMainThread ()
 Are we in the main thread? this function may be useful e.g. More...
 
static void abort (int errcode)
 Abort all MPI processes. More...
 
static bool isSequential ()
 
static bool isParallel ()
 
static bool isMasterRank ()
 rank 0 process is considered the master process More...
 
static std::string logMpiMode ()
 
static bool shouldLog ()
 
static po::command_line_parser const & commandLineParser ()
 
static std::vector< std::tuple< std::string, std::istringstream > > & configFiles ()
 
static void setConfigFiles (std::vector< std::string > const &filenames)
 Set the Configuration from a list of files. More...
 
static void setConfigFile (std::string const &filename)
 Set the Configuration from a File. More...
 
static po::variables_map const & vm ()
 return variables_map
 
template<typename T >
static void setOptionValue (std::string s, T val)
 
static AboutData const & about ()
 
static void olLoadInGmsh (std::string filename)
 Adds a file to automatically load in Gmsh with Onelab.
 
static po::options_description const & optionsDescription ()
 return options description data structure
 
static po::options_description const & optionsDescriptionApplication ()
 return options description data structure
 
static po::options_description const & optionsDescriptionLibrary ()
 return the options description for the Feel++ library
 
static void addOptions (po::options_description const &desc)
 Lazily register and parse options owned by an instantiated component. More...
 

Mutators

static Repository & repository ()
 get the repository info More...
 
static bool repositoryConfigured ()
 check if repository is configured More...
 
static void setWorldComm (WorldComm &worldcomm)
 set the static worldcomm
 

directories

template<typename ... Ts>
static void changeRepository (Ts &&... v)
 
static fs::path const & rootRepository ()
 
static std::string findFile (std::string const &filename, std::vector< std::string > paths={})
 Find a file. More...
 
static std::vector< std::string > geoPathList ()
 
static std::string localGeoRepository ()
 
static boost::tuple< std::string, bool > systemGeoRepository ()
 
static std::string localConfigRepository ()
 
static boost::tuple< std::string, bool > systemConfigRepository ()
 
static std::string appRepository ()
 the application directory, application results are stored there the directory is controlled by changeRepository
 
static std::string appRepositoryWithoutNumProc ()
 the application directory without np, application results are stored there the directory is controlled by changeRepository
 
static std::string exprRepository ()
 the expressions repository is typically a sub-directory of the appRepository() that contains the expressions generated using Ginac
 
static std::string logsRepository ()
 the logfiles repository is a subdirectory of the appRepository containing the logfiles
 
static std::string exportsRepository ()
 the exports repository is a subdirectory of the appRepository containing the results exported during the application execution
 
static std::string downloadsRepository ()
 the downloads repository is a subdirectory of the appRepository containing the files downloaded during the application execution
 
static uuids::uuid randomUUID (bool parallel=true)
 Generate a random UUID. More...
 
static uuids::uuid nameUUID (uuids::uuid const &dns_namespace_uuid, std::string const &name)
 Generate a UUID from a namespace UUID and a name.
 

Additional Inherited Members

- Public Types inherited from Feel::JournalManager
using notify_type = nl::json
 
- Public Member Functions inherited from Feel::JournalManager
 JournalManager ()
 Constructor. More...
 
virtual ~JournalManager ()=default
 Destructor.
 

Detailed Description

Initialize, finalize, and query the Feel++ environment.

The Environment class is used to initialize, finalize, and query the Feel++ environment. It will typically be used in the main() function of a program, which will create a single instance of Environment initialized with the arguments passed to the program:

int main(int argc, char* argv[])
{
using namespace Feel;
Environment env(argc, argv);
}
Environment()
Initialize the Feel environment.
Definition: environment.cpp:298
-*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-w...
Definition: about.cpp:37

or more commonly

int main(int argc, char* argv[])
{
using namespace Feel;
po::options_description myoptions( "Laplacian options" );
myoptions.add_options()
( "mu", po::value<double>()->default_value( 1.0 ), "coeff" );
Environment env( _argc=argc, _argv=argv,
_desc=myoptions,
_about=about(_name="myapp",
_author="Feel++ Consortium",
_email="feelpp-devel@feelpp.org"));
}

The instance of Environment will initialize Feel++ (by calling MPI, PETSc, SLEPc or Logging initialization routines) in its constructor and finalize in its destructor.

Author
Christophe Prud'homme
See also
Application

Constructor & Destructor Documentation

◆ Environment() [1/3]

Feel::Environment::Environment ( )

Initialize the Feel environment.

Default constructor.

If the Feel environment has not already been initialized, initializes Feel

◆ Environment() [2/3]

Feel::Environment::Environment ( int &  argc,
char **&  argv 
)

Initialize the Feel environment.

Constructor.

If the Feel environment has not already been initialized, initializes Feel

Parameters
argcThe number of arguments provided in argv, as passed into the program's main function.
argvThe array of argument strings passed to the program via main.

◆ Environment() [3/3]

Feel::Environment::Environment ( int  argc,
char **  argv,
mpi::threading::level  lvl,
po::options_description const &  desc,
po::options_description const &  desc_lib,
AboutData const &  about,
Repository::Config const &  config 
)

Construct a new Environment object.

Parameters
argcnumber of command line aguments
argvcommand line aguments
lvllevel of threading in MPI
desccommand line options for application
desc_libcommand line options for library
aboutabout data structure
configconfiguration of the repository of the resut&lts

◆ ~Environment()

Feel::Environment::~Environment ( )
override

Shuts down the Feel environment.

If this Environment object was used to initialize the Feel environment, and the Feel environment has not already been shut down (finalized), this destructor will shut down the Feel environment.

References Feel::Table::add_row(), Feel::AboutData::appName(), Feel::Table::format(), and saveTimers().

Member Function Documentation

◆ abort()

void Feel::Environment::abort ( int  errcode)
static

Abort all MPI processes.

Aborts all MPI processes and returns to the environment. The precise behavior will be defined by the underlying MPI implementation. This is equivalent to a call to MPI_Abort with MPI_COMM_WORLD.

Parameters
errcodeThe error code to return to the environment.
Returns
Will not return.

◆ aborted()

bool Feel::Environment::aborted ( )
static

Determine if the MPI environment has already been aborted.

this occurs if MPI_Abort has been called

Returns
true if the Feel++ nvironment has been aborted.

◆ addOptions()

void Feel::Environment::addOptions ( po::options_description const &  desc)
static

Lazily register and parse options owned by an instantiated component.

Re-registering the same complete option description is idempotent. Partial overlap is rejected because it usually indicates inconsistent component prefixes or option definitions.

Parameters
desccomponent-specific option description

◆ addTimer()

void Feel::Environment::addTimer ( std::string const &  msg,
std::pair< double, int > const &  t,
std::string const &  uiname = "" 
)
static

Return the timerstable pointer.

add timer to a map of timers that can be shown using displayTimers()

◆ expand()

std::string Feel::Environment::expand ( std::string const &  expr)
static

expand feel++ pathes in a string

Feel++ defines some paths

  • top_srcdir : top source directory from which feel++ was compiled
  • top_builddir : top build directory in which feel++ was compiled
  • repository : repository for the results (default: $HOME/feel)
  • datadir : repository for data like meshes ($top_srcdir/data)
  • exprdbdir : top level directory of ginac expression ($repository/exprDB)
  • home : $HOME directory The paths can be used in filename string and expanded using this function by prefixing them by $
    std::string topsrcdir = Environment::expand( "$top_srcdir");
    std::string topbuilddir = Environment::expand( "$top_builddir");
    static std::string expand(std::string const &expr)
    expand feel++ pathes in a string
    Definition: environment.cpp:2856
    They can be used in config files or in the command line
    feelpp_qs_laplacian --gmsh.filename=\$home/mesh.geo
Parameters
exprstring where paths might be expanded
Returns
the expansion of the feel++ paths defined in string expr

◆ finalized()

bool Feel::Environment::finalized ( )
static

Determine if the MPI environment has already been finalized.

The routine is equivalent to a call to MPI_Finalized.

Returns
true if the MPI environment has been finalized.

◆ findFile()

std::string Feel::Environment::findFile ( std::string const &  filename,
std::vector< std::string >  paths = {} 
)
static

Find a file.

The lookup is as follows:

  • look into current path
  • look into paths that went through changeRepository(), it means that we look for example into the path from which the executable was run If the file has an extension .geo or .msh, try also to
  • look into localGeoRepository() which is usually $HOME/feel/geo
  • look into systemGeoRepository() which is usually $FEELPP_DIR/share/feel/geo If filename is not found, then the empty string is returned.
    Returns
    the string containing the filename path

◆ findFileRemotely()

std::string Feel::Environment::findFileRemotely ( std::string const &  fname,
std::string const &  subdir = "" 
)
static

try find remotely the file fname

Parameters
fnamefilename
subdirubdirectory to store the file that may be downloaded
Returns
the filename

◆ geoPathList()

std::vector< std::string > Feel::Environment::geoPathList ( )
static
Returns
the list of paths where Feel++ looks into to find a Gmsh Geo file

◆ initialized()

bool Feel::Environment::initialized ( )
static

Determine if the MPI environment has already been initialized.

This routine is equivalent to a call to MPI_Initialized.

Returns
true if the MPI environment has been initialized.

◆ isMainThread()

bool Feel::Environment::isMainThread ( )
static

Are we in the main thread? this function may be useful e.g.

in funneled level

◆ isMasterRank()

static bool Feel::Environment::isMasterRank ( )
static

rank 0 process is considered the master process

the master process can then for example print information in the console or in some files

◆ isParallel()

static bool Feel::Environment::isParallel ( )
static
Returns
true if the environment is not sequential, that is if the number of process is greater than 1

◆ isSequential()

static bool Feel::Environment::isSequential ( )
static
Returns
true if number of process is 1, hence the environment is sequential

◆ localConfigRepository()

std::string Feel::Environment::localConfigRepository ( )
static
Returns
the local config files repository (default: $HOME/feel/config)

◆ localGeoRepository()

std::string Feel::Environment::localGeoRepository ( )
static
Returns
the local geo files repository (default: $HOME/feel/geo)

◆ logMemoryUsage()

MemoryUsage Feel::Environment::logMemoryUsage ( std::string const &  message)
static

print resident memory usage as well as PETSc malloc usage in log file

Parameters
messagemessage to print to identity the associated memory operation

Referenced by Feel::PsLogger::log().

◆ logVerbosityLevel()

static int Feel::Environment::logVerbosityLevel ( )
static

get variables_map from options_description desc

get the log verbosity level

◆ randomUUID()

uuids::uuid Feel::Environment::randomUUID ( bool  parallel = true)
static

Generate a random UUID.

the UUID is very very very very likely to be unique as it is encoded into 128 bits

Parameters
parallelif true generate the same uuid for all MPI process, if false it will be different

◆ repository()

static Repository & Feel::Environment::repository ( )
static

get the repository info

Returns
Repository&

◆ repositoryConfigured()

static bool Feel::Environment::repositoryConfigured ( )
static

check if repository is configured

Returns
true if repository is configured, false otherwise

◆ rootRepository()

fs::path const & Feel::Environment::rootRepository ( )
static
Returns
the root repository (default: $HOME/feel)

Referenced by Feel::Application::rootRepository().

◆ scratchDirectory()

static FEELPP_DEPRECATED const fs::path & Feel::Environment::scratchDirectory ( )
static
Returns
the scratch directory

◆ setConfigFile()

void Feel::Environment::setConfigFile ( std::string const &  filename)
static

Set the Configuration from a File.

Parameters
filenamefilename of the config file

◆ setConfigFiles()

void Feel::Environment::setConfigFiles ( std::vector< std::string > const &  filenames)
static

Set the Configuration from a list of files.

Parameters
filenameslist of config files

◆ setLogs()

void Feel::Environment::setLogs ( std::string const &  prefix)
static

set log files

Parameters
prefixprefix for log filenames

◆ startLogging()

void Feel::Environment::startLogging ( std::string  decorate)
static

start logging.

LOG(INFO) << "Feel++ uses logging";
static void stopLogging(bool remove=false)
stop logging in Feel++.
Definition: environment.cpp:2451
static void startLogging(std::string decorate)
start logging.
Definition: environment.cpp:2302

References Feel::rank().

◆ stopLogging()

void Feel::Environment::stopLogging ( bool  remove = false)
static

stop logging in Feel++.

This function safely shuts down Google's logging system and optionally removes log files. It is MPI-safe and can be called before MPI init, during MPI execution, or after MPI finalization.

Parameters
removedeletes the log directory and all its content
LOG(INFO) << "Feel++ uses logging";
LOG(INFO) << "Feel++ uses logging";
Environment::stopLogging( true ); // delete the `logs` subdirectory of the current path
Note
When called after MPI finalization (e.g., after PetscFinalize/SlepcFinalize), log cleanup will happen on all ranks to avoid MPI-after-finalize errors.

◆ systemConfigRepository()

boost::tuple< std::string, bool > Feel::Environment::systemConfigRepository ( )
static
Returns
a tuple : the system config files repository (default: /usr/share/feel/config or /usr/local/share/feel/config) and true or false whether the directory exists or not

◆ systemGeoRepository()

boost::tuple< std::string, bool > Feel::Environment::systemGeoRepository ( )
static
Returns
a tuple : the system geo files repository (default: /usr/share/feel/geo or /usr/local/share/feel/geo) and true or false whether the directory exists or not

◆ threadLevel()

mpi::threading::level Feel::Environment::threadLevel ( )
static

get the thread level that could be set The thread level resquested to mpi may not be supported.

This function returns the maximum level of thread support that could be setup

Returns
the maximum thread level supported with respect to the initialization request

◆ worldCommPtr()

static std::shared_ptr< WorldComm > const & Feel::Environment::worldCommPtr ( )
static
Returns
the shared_ptr WorldComm