Go to the documentation of this file.
40 namespace functionEntries
58 primitiveEntryIstream,
76 return const_cast<Time&
>(d.
time()).libs();
87 if (isA<baseIOdictionary>(topDict))
95 <<
"codeStream : baseIOdictionary:" <<
dict.name()
102 <<
"codeStream : not a baseIOdictionary:" <<
dict.name()
103 <<
" master-only-reading:" << regIOobject::masterOnlyReading <<
endl;
106 return regIOobject::masterOnlyReading;
122 std::string sha1Str(context.
sha1().
str(
true));
123 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
127 const fileName libPath = dynCode.libPath();
134 if (isA<baseIOdictionary>(topDict))
136 lib = libs(parentDict).findLibrary(libPath);
144 <<
"Using #codeStream with " << libPath <<
endl;
146 if (isA<baseIOdictionary>(topDict))
151 if (dlLibs.
open(libPath,
false))
159 lib =
dlOpen(libPath,
false);
169 || (regIOobject::fileModificationSkew <= 0);
173 if (!dynCode.upToDate(context))
176 dynCode.
reset(context);
179 dynCode.addCompileFile(codeTemplateC);
182 dynCode.setMakeOptions
186 +
"\n\nLIB_LIBS = \\\n"
191 if (!dynCode.copyOrCreateFiles(
true))
194 <<
"Failed writing files for" <<
nl
195 << dynCode.libRelPath() <<
nl
200 if (!dynCode.wmakeLibso())
203 <<
"Failed wmake " << dynCode.libRelPath() <<
nl
212 !doingMasterOnlyReading(topDict)
213 && regIOobject::fileModificationSkew > 0
222 off_t masterSize = mySize;
223 Pstream::scatter(masterSize);
228 iter < regIOobject::maxFileModificationPolls;
233 <<
"on processor " << Pstream::myProcNo()
234 <<
"masterSize:" << masterSize
235 <<
" and localSize:" << mySize
238 if (mySize == masterSize)
242 else if (mySize > masterSize)
245 <<
"Excessive size when reading (NFS mounted) library "
246 <<
nl << libPath <<
nl
247 <<
"on processor " << Pstream::myProcNo()
248 <<
" detected size " << mySize
249 <<
" whereas master size is " << masterSize
251 <<
"If your case is NFS mounted increase"
252 <<
" fileModificationSkew or maxFileModificationPolls;"
253 <<
nl <<
"If your case is not NFS mounted"
254 <<
" (so distributed) set fileModificationSkew"
261 <<
"Local file " << libPath
262 <<
" not of same size (" << mySize
264 << masterSize <<
"). Waiting for "
265 << regIOobject::fileModificationSkew
266 <<
" seconds." <<
endl;
277 if (mySize != masterSize)
280 <<
"Cannot read (NFS mounted) library " <<
nl
282 <<
"on processor " << Pstream::myProcNo()
283 <<
" detected size " << mySize
284 <<
" whereas master size is " << masterSize
286 <<
"If your case is NFS mounted increase"
287 <<
" fileModificationSkew or maxFileModificationPolls;"
288 <<
nl <<
"If your case is not NFS mounted"
289 <<
" (so distributed) set fileModificationSkew"
295 <<
"on processor " << Pstream::myProcNo()
296 <<
" after waiting: have masterSize:" << masterSize
297 <<
" and localSize:" << mySize <<
endl;
300 if (isA<baseIOdictionary>(topDict))
307 <<
"Opening cached dictionary:" << libPath <<
endl;
309 if (!dlLibs.
open(libPath,
false))
312 <<
"Failed loading library " << libPath <<
nl
313 <<
"Did you add all libraries to the 'libs' entry"
314 <<
" in system/controlDict?"
324 <<
"Opening uncached dictionary:" << libPath <<
endl;
326 lib =
dlOpen(libPath,
true);
331 if (!doingMasterOnlyReading(topDict))
339 <<
"Failed loading library " << libPath
340 <<
" on some processors."
346 streamingFunctionType
function =
347 reinterpret_cast<streamingFunctionType
>
349 dlSym(lib, dynCode.codeName())
356 <<
"Failed looking up symbol " << dynCode.codeName()
371 <<
"Using #codeStream at line " << is.
lineNumber()
372 <<
" in file " << parentDict.
name() <<
endl;
374 dynamicCode::checkSecurity
376 "functionEntries::codeStream::evaluate(..)",
381 dictionary codeDict(
"#codeStream", parentDict, is);
386 streamingFunctionType
function = getFunction(parentDict, codeDict);
387 (*function)(os, parentDict);
404 entry.read(parentDict, result);
417 parentDict.
read(result);
const string & libs() const
Return the code-libs.
A keyword and a list of tokens is an 'entry'.
void reset()
Clear all bits but do not adjust the addressable size.
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specifed on locations.
A table of dynamically loaded libraries.
void * findLibrary(const fileName &libName)
Find the handle of the named library.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
A class for handling file names.
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 string evaluate(const dictionary &parentDict, Istream &is)
Evaluate dynamically compiled code, returning result as string.
Encapsulation of dynamic code dictionaries.
defineTypeNameAndDebug(codeStream, 0)
streamFormat format() const noexcept
Get the current stream format.
Input/output from string buffers.
static bool execute(const dictionary &parentDict, primitiveEntry &entry, Istream &is)
Execute in a primitiveEntry context.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A class for handling character strings derived from std::string.
const Time & time() const
Return time.
static streamingFunctionType getFunction(const dictionary &parentDict, const dictionary &codeDict)
Construct, compile, load and return streaming function.
void(* streamingFunctionType)(Ostream &, const dictionary &)
Interpreter function type.
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).
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
static dlLibraryTable & libs(const dictionary &dict)
Helper function: access to dlLibraryTable of Time.
bool globalObject() const
Is object same for all processors?
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
Macros for easy insertion into member function selection tables.
const dictionary & topDict() const
Return the top of the tree.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const string & options() const
Return the code-options.
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Input from string buffer, using a ISstream.
bool open(bool verbose=true)
#define DebugPout
Report an information message using Foam::Pout.
bool read(Istream &is)
Read dictionary from Istream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static bool doingMasterOnlyReading(const dictionary &dict)
Helper: access IOobject for master-only-reading functionality.
Output to string buffer, using a OSstream.
label lineNumber() const
Const access to the current stream line number.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const SHA1 & sha1() const
Return SHA1 calculated from options, libs, include, code.
unsigned int sleep(const unsigned int sec)
Sleep for the specified number of seconds.
void * dlOpen(const fileName &libName, const bool check=true)
Open a shared library and return handle to library.
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)