Go to the documentation of this file.
54 static inline void writeEntryIfPresent
57 const dictionary&
dict,
69 os.writeEntry(key, toks[0]);
82 writeEntryIfPresent(os,
dict,
"codeInclude");
83 writeEntryIfPresent(os,
dict,
"localCode");
84 writeEntryIfPresent(os,
dict,
"code");
85 writeEntryIfPresent(os,
dict,
"codeOptions");
86 writeEntryIfPresent(os,
dict,
"codeLibs");
92 void* Foam::codedBase::loadLibrary
95 const std::string& funcName,
103 !libPath.empty() && libs().open(libPath,
false)
104 ? libs().findLibrary(libPath)
118 void* rawSymbol =
dlSymFind(handle, funcName);
122 loaderType fun =
reinterpret_cast<loaderType
>(rawSymbol);
131 <<
"Failed symbol lookup " << funcName.c_str() <<
nl
132 <<
"from " << libPath <<
nl
139 <<
"Failed symbol lookup " << funcName.c_str() <<
nl
140 <<
"from " << libPath <<
nl
144 if (!libs().close(libPath,
false))
147 <<
"Failed unloading library " << libPath <<
nl
156 void Foam::codedBase::unloadLibrary
158 const fileName& libPath,
159 const std::string& funcName,
160 const dynamicCodeContext& context
165 !libPath.empty() && libs().open(libPath,
false)
166 ? libs().findLibrary(libPath)
178 void* rawSymbol =
dlSymFind(handle, funcName);
182 loaderType fun =
reinterpret_cast<loaderType
>(rawSymbol);
191 <<
"Failed symbol lookup " << funcName.c_str() <<
nl
192 <<
"from " << libPath <<
nl
197 if (!libs().close(libPath,
false))
200 <<
"Failed unloading library " << libPath <<
nl
206 void Foam::codedBase::createLibrary
208 dynamicCode& dynCode,
209 const dynamicCodeContext& context
219 if (!dynCode.upToDate(context))
222 dynCode.reset(context);
224 this->prepare(dynCode, context);
226 if (!dynCode.copyOrCreateFiles(
true))
229 <<
"Failed writing files for" <<
nl
230 << dynCode.libRelPath() <<
nl
235 if (!dynCode.wmakeLibso())
238 <<
"Failed wmake " << dynCode.libRelPath() <<
nl
252 const fileName libPath = dynCode.libPath();
255 off_t masterSize = mySize;
267 <<
" have masterSize:" << masterSize
268 <<
" and localSize:" << mySize
271 if (mySize == masterSize)
275 else if (mySize > masterSize)
278 <<
"Excessive size when reading (NFS mounted) library "
279 <<
nl << libPath <<
nl
281 <<
" detected size " << mySize
282 <<
" whereas master size is " << masterSize
284 <<
"If your case is NFS mounted increase"
285 <<
" fileModificationSkew or maxFileModificationPolls;"
286 <<
nl <<
"If your case is not NFS mounted"
287 <<
" (so distributed) set fileModificationSkew"
294 <<
"Local file " << libPath
295 <<
" not of same size (" << mySize
297 << masterSize <<
"). Waiting for "
299 <<
" seconds." <<
endl;
310 if (mySize != masterSize)
313 <<
"Cannot read (NFS mounted) library " <<
nl
316 <<
" detected size " << mySize
317 <<
" whereas master size is " << masterSize
319 <<
"If your case is NFS mounted increase"
320 <<
" fileModificationSkew or maxFileModificationPolls;"
321 <<
nl <<
"If your case is not NFS mounted"
322 <<
" (so distributed) set fileModificationSkew"
329 <<
" after waiting: have masterSize:" << masterSize
330 <<
" and localSize:" << mySize <<
endl;
340 context_.setCodeContext(
dict);
346 context_.append(str);
358 "codedBase::updateLibrary()",
370 const fileName libPath = dynCode.libPath();
374 if (libs().findLibrary(libPath))
380 <<
"Using dynamicCode for " << this->description().c_str()
386 this->clearRedirect();
397 if (!loadLibrary(libPath, dynCode.codeName(), context))
399 createLibrary(dynCode, context);
401 loadLibrary(libPath, dynCode.codeName(), context);
405 oldLibPath_ = libPath;
421 if (context_.valid())
423 updateLibrary(
name, context_);
void append(const std::string &str)
Add content to SHA1 hashing.
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specified on locations.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling words, derived from Foam::string.
A class for handling file names.
static void writeCodeDict(Ostream &os, const dictionary &dict)
Write code-dictionary contents.
std::string str(const bool prefixed=false) const
The digest (40-byte) text representation, optionally with '_' prefix.
Tools for handling dynamic code compilation.
const dictionary & dict() const
Return the parent dictionary context.
static float fileModificationSkew
Encapsulation of dynamic code dictionaries.
static int maxFileModificationPolls
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void setCodeContext(const dictionary &dict)
Set code context from a dictionary.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
const fileName & name() const
The dictionary name.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
void * dlSymFind(void *handle, const std::string &symbol, bool required=false)
Look for symbol in a dlopened library.
word name(const complex &c)
Return string representation of complex.
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
label startLineNumber() const
Return line number of first token in dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Inter-processor communication reduction functions.
#define DebugPout
Report an information message using Foam::Pout.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< token > tokenList
List of tokens, used for a IOdictionary entry.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static bool master(const label communicator=0)
Am I the master process.
static word libraryBaseName(const fileName &libPath)
Return the library basename without leading 'lib' or trailing '.so'.
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
const SHA1 & sha1() const
Return SHA1 calculated from options, libs, include, code.
void updateLibrary(const word &name, const dynamicCodeContext &context) const
Update library as required, using the given context.
defineTypeNameAndDebug(combustionModel, 0)
unsigned int sleep(const unsigned int sec)
Sleep for the specified number of seconds.