37 namespace functionEntries
61 "codeStreamTemplate.C";
66 bool Foam::functionEntries::codeStream::masterOnlyRead
68 const dictionary&
dict
76 <<
" master-only-reading:" << topDict.global()
80 return topDict.global();
84 Foam::functionEntries::codeStream::streamingFunctionType
85 Foam::functionEntries::codeStream::getFunction
87 const dictionary& parentDict,
88 const dictionary& codeDict
92 const dynamicCodeContext context
95 {
"code",
"codeInclude",
"localCode"}
100 const std::string sha1Str(context.sha1().str(
true));
101 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
105 const fileName libPath = dynCode.libPath();
112 Info<<
"Using #codeStream with " << libPath <<
endl;
128 lib =
dlOpen(libPath,
false);
141 if (!dynCode.upToDate(context))
144 dynCode.reset(context);
147 dynCode.addCompileFile(codeTemplateC);
150 dynCode.setMakeOptions
154 +
"\n\nLIB_LIBS = \\\n"
159 if (!dynCode.copyOrCreateFiles(
true))
164 ) <<
"Failed writing files for" <<
nl
165 << dynCode.libRelPath() <<
nl
170 if (!dynCode.wmakeLibso())
175 ) <<
"Failed wmake " << dynCode.libRelPath() <<
nl
183 !masterOnlyRead(parentDict)
193 off_t masterSize = mySize;
199 <<
" have masterSize:" << masterSize
200 <<
" and localSize:" << mySize
205 if (mySize < masterSize)
209 Pout<<
"Local file " << libPath
210 <<
" not of same size (" << mySize
212 << masterSize <<
"). Waiting for "
214 <<
" seconds." <<
endl;
221 if (mySize < masterSize)
226 ) <<
"Cannot read (NFS mounted) library " <<
nl
229 <<
" detected size " << mySize
230 <<
" whereas master size is " << masterSize
232 <<
"If your case is not NFS mounted"
233 <<
" (so distributed) set fileModificationSkew"
242 <<
" after waiting: have masterSize:" << masterSize
243 <<
" and localSize:" << mySize
252 Pout<<
"Opening cached dictionary:" << libPath <<
endl;
262 Pout<<
"Opening uncached dictionary:" << libPath <<
endl;
265 lib =
dlOpen(libPath,
true);
274 ) <<
"Failed loading library " << libPath <<
nl
275 <<
"Did you add all libraries to the 'libs' entry"
276 <<
" in system/controlDict?"
281 if (!masterOnlyRead(parentDict))
283 reduce(haveLib, andOp<bool>());
291 ) <<
"Failed loading library " << libPath
292 <<
" on some processors."
298 const streamingFunctionType
function =
299 reinterpret_cast<streamingFunctionType
>
301 dlSym(lib, dynCode.codeName())
310 ) <<
"Failed looking up symbol " << dynCode.codeName()
320 const dictionary& parentDict,
326 Info<<
"Using #codeStream at line " << is.lineNumber()
327 <<
" in file " << parentDict.name() <<
endl;
332 "functionEntries::codeStream::execute(..)",
338 const dictionary codeDict(
"#codeStream", parentDict, is);
340 const streamingFunctionType
function = getFunction(parentDict, codeDict);
343 OStringStream os(is.format());
344 (*function)(os, parentDict);
359 return insert(parentDict, run(parentDict, is));
370 return insert(parentDict, thisEntry, run(parentDict, is));
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into member function selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
static bool master(const label communicator=0)
Am I the master process.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
const fileName & name() const
Return the dictionary name.
A list of keyword definitions, which are a keyword followed by any number of values (e....
const dictionary & topDict() const
Return the top of the tree.
void * findLibrary(const fileName &libName)
Find the handle of the named library.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
Dictionary entry that contains C++ OpenFOAM code that is compiled to generate the entry itself....
static bool execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
static const word codeTemplateC
Name of the C code template to be used.
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
const dictionary & dict() const
This entry is not a dictionary,.
static float fileModificationSkew
A class for handling character strings derived from std::string.
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
defineTypeNameAndDebug(includeFvConstraintEntry, 0)
addToMemberFunctionSelectionTable(functionEntry, includeFvConstraintEntry, execute, dictionaryIstream)
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dlLibraryTable libs
Table of loaded dynamic libraries.
off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return size of file.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void * dlOpen(const fileName &lib, const bool check=true)
Open a shared library. Return handle to library. Print error message.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
prefixOSstream Pout(cout, "Pout")
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
unsigned int sleep(const unsigned int)
Sleep for the specified number of seconds.