38 namespace functionEntries
62 "codeStreamTemplate.C";
67 bool Foam::functionEntries::codeStream::masterOnlyRead
69 const dictionary&
dict
77 <<
" master-only-reading:" << topDict.global()
81 return topDict.global();
85 Foam::functionEntries::codeStream::streamingFunctionType
86 Foam::functionEntries::codeStream::getFunction
88 const dictionary& parentDict,
89 const dictionary& codeDict
93 const dynamicCodeContext context
96 {
"code",
"codeInclude",
"localCode"},
102 const std::string sha1Str(context.sha1().str(
true));
103 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
107 const fileName libPath = dynCode.libPath();
114 Info<<
"Using #codeStream with " << libPath <<
endl;
130 lib =
dlOpen(libPath,
false);
143 if (!dynCode.upToDate(context))
146 dynCode.reset(context);
149 dynCode.addCompileFile(codeTemplateC);
152 dynCode.setMakeOptions
156 +
"\n\nLIB_LIBS = \\\n"
161 if (!dynCode.copyOrCreateFiles(
true))
166 ) <<
"Failed writing files for" <<
nl
167 << dynCode.libRelPath() <<
nl
172 if (!dynCode.wmakeLibso())
177 ) <<
"Failed wmake " << dynCode.libRelPath() <<
nl
185 !masterOnlyRead(parentDict)
195 off_t masterSize = mySize;
201 <<
" have masterSize:" << masterSize
202 <<
" and localSize:" << mySize
207 if (mySize < masterSize)
211 Pout<<
"Local file " << libPath
212 <<
" not of same size (" << mySize
214 << masterSize <<
"). Waiting for "
216 <<
" seconds." <<
endl;
223 if (mySize < masterSize)
228 ) <<
"Cannot read (NFS mounted) library " <<
nl
231 <<
" detected size " << mySize
232 <<
" whereas master size is " << masterSize
234 <<
"If your case is not NFS mounted"
235 <<
" (so distributed) set fileModificationSkew"
244 <<
" after waiting: have masterSize:" << masterSize
245 <<
" and localSize:" << mySize
254 Pout<<
"Opening cached dictionary:" << libPath <<
endl;
264 Pout<<
"Opening uncached dictionary:" << libPath <<
endl;
267 lib =
dlOpen(libPath,
true);
276 ) <<
"Failed loading library " << libPath <<
nl
277 <<
"Did you add all libraries to the 'libs' entry"
278 <<
" in system/controlDict?"
283 if (!masterOnlyRead(parentDict))
285 reduce(haveLib, andOp<bool>());
293 ) <<
"Failed loading library " << libPath
294 <<
" on some processors."
300 const streamingFunctionType
function =
301 reinterpret_cast<streamingFunctionType
>
303 dlSym(lib, dynCode.codeName())
312 ) <<
"Failed looking up symbol " << dynCode.codeName()
322 const dictionary& parentDict,
328 Info<<
"Using #codeStream at line " << is.lineNumber()
329 <<
" in file " << parentDict.name() <<
endl;
334 "functionEntries::codeStream::execute(..)",
340 const dictionary codeDict(
"#codeStream", parentDict, is);
342 const streamingFunctionType
function = getFunction(parentDict, codeDict);
345 OStringStream os(is.format());
346 (*function)(os, parentDict);
361 return insert(parentDict, run(parentDict, is));
372 return insert(parentDict, thisEntry, run(parentDict, is));
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Inter-processor communication reduction functions.
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.
static const word null
An empty word.
#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.