Go to the documentation of this file.
40 namespace functionEntries
58 primitiveEntryIstream,
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))
149 lib = libs(parentDict).open(libPath,
false);
164 || (regIOobject::fileModificationSkew <= 0);
168 if (!dynCode.upToDate(context))
171 dynCode.
reset(context);
174 dynCode.addCompileFile(codeTemplateC);
177 dynCode.setMakeOptions
181 +
"\n\nLIB_LIBS = \\\n"
186 if (!dynCode.copyOrCreateFiles(
true))
189 <<
"Failed writing files for" <<
nl
190 << dynCode.libRelPath() <<
nl
195 if (!dynCode.wmakeLibso())
198 <<
"Failed wmake " << dynCode.libRelPath() <<
nl
207 !doingMasterOnlyReading(topDict)
208 && regIOobject::fileModificationSkew > 0
217 off_t masterSize = mySize;
218 Pstream::scatter(masterSize);
223 iter < regIOobject::maxFileModificationPolls;
228 <<
"on processor " << Pstream::myProcNo()
229 <<
"masterSize:" << masterSize
230 <<
" and localSize:" << mySize
233 if (mySize == masterSize)
237 else if (mySize > masterSize)
240 <<
"Excessive size when reading (NFS mounted) library "
241 <<
nl << libPath <<
nl
242 <<
"on processor " << Pstream::myProcNo()
243 <<
" detected size " << mySize
244 <<
" whereas master size is " << masterSize
246 <<
"If your case is NFS mounted increase"
247 <<
" fileModificationSkew or maxFileModificationPolls;"
248 <<
nl <<
"If your case is not NFS mounted"
249 <<
" (so distributed) set fileModificationSkew"
256 <<
"Local file " << libPath
257 <<
" not of same size (" << mySize
259 << masterSize <<
"). Waiting for "
260 << regIOobject::fileModificationSkew
261 <<
" seconds." <<
endl;
272 if (mySize != masterSize)
275 <<
"Cannot read (NFS mounted) library " <<
nl
277 <<
"on processor " << Pstream::myProcNo()
278 <<
" detected size " << mySize
279 <<
" whereas master size is " << masterSize
281 <<
"If your case is NFS mounted increase"
282 <<
" fileModificationSkew or maxFileModificationPolls;"
283 <<
nl <<
"If your case is not NFS mounted"
284 <<
" (so distributed) set fileModificationSkew"
290 <<
"on processor " << Pstream::myProcNo()
291 <<
" after waiting: have masterSize:" << masterSize
292 <<
" and localSize:" << mySize <<
endl;
295 if (isA<baseIOdictionary>(topDict))
299 <<
"Opening cached dictionary:" << libPath <<
endl;
301 lib = libs(parentDict).open(libPath,
false);
306 <<
"Failed loading library " << libPath <<
nl
307 <<
"Did you add all libraries to the 'libs' entry"
308 <<
" in system/controlDict?"
316 <<
"Opening uncached dictionary:" << libPath <<
endl;
323 if (!doingMasterOnlyReading(topDict))
331 <<
"Failed loading library " << libPath
332 <<
" on some processors."
338 streamingFunctionType
function =
339 reinterpret_cast<streamingFunctionType
>
348 <<
"Failed looking up symbol " << dynCode.codeName()
363 <<
"Using #codeStream at line " << is.
lineNumber()
364 <<
" in file " << parentDict.
name() <<
endl;
366 dynamicCode::checkSecurity
368 "functionEntries::codeStream::evaluate(..)",
373 dictionary codeDict(
"#codeStream", parentDict, is);
378 streamingFunctionType
function = getFunction(parentDict, codeDict);
379 (*function)(os, parentDict);
396 entry.read(parentDict, result);
409 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 specified on locations.
A table of dynamically loaded libraries.
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.
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).
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,...
reduce(hasMovingMesh, orOp< bool >())
dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
const string & options() const
Return the code-options.
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Input from string buffer, using a ISstream.
#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)