131 void* Foam::codedBase::loadLibrary
133 const fileName& libPath,
134 const std::string& funcName,
135 const dynamicCodeContext& context
140 void* handle = libs().open(libPath,
false);
152 const bool ok = libs().loadHook(handle, funcName,
false);
157 <<
"Failed symbol lookup " << funcName.c_str() <<
nl 158 <<
"from " << libPath <<
nl 162 if (!libs().close(libPath,
false))
165 <<
"Failed unloading library " << libPath <<
nl 174 void Foam::codedBase::unloadLibrary
176 const fileName& libPath,
177 const std::string& funcName,
178 const dynamicCodeContext& context
181 void* handle = libs().open(libPath,
false);
191 const bool ok = libs().unloadHook(handle, funcName,
false);
196 <<
"Failed looking up symbol " << funcName <<
nl 197 <<
"from " << libPath <<
nl;
200 if (!libs().close(libPath,
false))
203 <<
"Failed unloading library " << libPath <<
nl 209 void Foam::codedBase::createLibrary
211 dynamicCode& dynCode,
212 const dynamicCodeContext& context
222 if (!dynCode.upToDate(context))
225 dynCode.reset(context);
227 this->prepare(dynCode, context);
229 if (!dynCode.copyOrCreateFiles(
true))
232 <<
"Failed writing files for" <<
nl 233 << dynCode.libRelPath() <<
nl 238 if (!dynCode.wmakeLibso())
241 <<
"Failed wmake " << dynCode.libRelPath() <<
nl 255 const fileName libPath = dynCode.libPath();
258 off_t masterSize = mySize;
270 <<
" have masterSize:" << masterSize
271 <<
" and localSize:" << mySize
274 if (mySize == masterSize)
278 else if (mySize > masterSize)
281 <<
"Excessive size when reading (NFS mounted) library " 282 <<
nl << libPath <<
nl 284 <<
" detected size " << mySize
285 <<
" whereas master size is " << masterSize
287 <<
"If your case is NFS mounted increase" 288 <<
" fileModificationSkew or maxFileModificationPolls;" 289 <<
nl <<
"If your case is not NFS mounted" 290 <<
" (so distributed) set fileModificationSkew" 297 <<
"Local file " << libPath
298 <<
" not of same size (" << mySize
300 << masterSize <<
"). Waiting for " 302 <<
" seconds." <<
endl;
313 if (mySize != masterSize)
316 <<
"Cannot read (NFS mounted) library " <<
nl 319 <<
" detected size " << mySize
320 <<
" whereas master size is " << masterSize
322 <<
"If your case is NFS mounted increase" 323 <<
" fileModificationSkew or maxFileModificationPolls;" 324 <<
nl <<
"If your case is not NFS mounted" 325 <<
" (so distributed) set fileModificationSkew" 332 <<
" after waiting: have masterSize:" << masterSize
333 <<
" and localSize:" << mySize <<
endl;
350 context_.append(str);
362 "codedBase::updateLibrary()",
374 const fileName libPath = dynCode.libPath();
378 if (libs().findLibrary(libPath))
384 <<
"Using dynamicCode for " << this->description().c_str()
390 this->clearRedirect();
401 if (!loadLibrary(libPath, dynCode.codeName(), context))
403 createLibrary(dynCode, context);
405 loadLibrary(libPath, dynCode.codeName(), context);
409 oldLibPath_ = libPath;
425 if (context_.valid())
427 updateLibrary(
name, context_);
431 updateLibrary(
name, dynamicCodeContext(this->codeDict()));
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
A class for handling file names.
Inter-processor communication reduction functions.
std::string str(const bool prefixed=false) const
The digest (40-byte) text representation, optionally with '_' prefix.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
errorManipArg< error, int > exit(error &err, const int errNo=1)
static float fileModificationSkew
Time skew (seconds) for file modification checks.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
const word dictName("faMeshDefinition")
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
bool store()
Register object with its registry and transfer ownership to the registry.
static void reduceOr(bool &value, const label communicator=worldComm)
Logical (or) reduction (cf. MPI AllReduce)
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Ignore writing from objectRegistry::writeObject()
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
void append(const std::string &str)
Add content to SHA1 hashing.
const fileName & name() const noexcept
The dictionary name.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all processes in communicator.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
const dictionary & dict() const noexcept
Return the parent dictionary context.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
static word basename(const fileName &libPath)
Library basename without leading 'lib' or trailing '.so'.
A class for handling words, derived from Foam::string.
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
const Time & time() const noexcept
Return time registry.
Reading required, file watched for runTime modification.
const word & system() const noexcept
Return system name.
static int maxFileModificationPolls
Max number of times to poll for file modification changes.
unsigned int sleep(const unsigned int sec)
Sleep for the specified number of seconds.
void setCodeContext(const dictionary &dict)
Set code context from a dictionary.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
static void writeEntryIfPresent(Ostream &os, const dictionary &dict, const word &key)
Tools for handling dynamic code compilation.
Encapsulation of dynamic code dictionaries.
void updateLibrary(const word &name, const dynamicCodeContext &context) const
Update library as required, using the given context.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
static bool master(const label communicator=worldComm)
Am I the master rank.
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
#define DebugPout
Report an information message using Foam::Pout.
virtual bool isDict() const noexcept
Return true if this entry is a dictionary.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Registry of regIOobjects.
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specified on locations.
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
Defines the attributes of an object for which implicit objectRegistry management is supported...
static void writeCodeDict(Ostream &os, const dictionary &dict)
Write code-dictionary contents.
label startLineNumber() const
Return line number of first token in dictionary.
virtual const dictionary & codeDict() const =0
A keyword and a list of tokens is an 'entry'.
const SHA1 & sha1() const noexcept
The SHA1 calculated from options, libs, include, code, etc.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...