38 namespace functionEntries
63 {
"code",
"codeInclude",
"localCode"}
68 {
"dict", word::null, word::null}
72 "codeStreamTemplate.C";
77 bool Foam::functionEntries::codeStream::masterOnlyRead
79 const dictionary&
dict
87 <<
" master-only-reading:" << topDict.global()
95 Foam::functionEntries::codeStream::streamingFunctionType
96 Foam::functionEntries::codeStream::getFunction
98 const dictionary& contextDict,
99 const dictionary& codeDict
103 const dynamicCodeContext context
113 const std::string sha1Str(context.sha1().str(
true));
114 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
118 const fileName libPath = dynCode.libPath();
125 Info<<
"Using #codeStream with " << libPath <<
endl;
141 lib =
dlOpen(libPath,
false);
154 if (!dynCode.upToDate(context))
157 dynCode.reset(context);
160 dynCode.addCompileFile(codeTemplateC);
163 dynCode.setMakeOptions
167 +
"\n\nLIB_LIBS = \\\n"
172 if (!dynCode.copyOrCreateFiles(
true))
177 ) <<
"Failed writing files for" <<
nl
178 << dynCode.libRelPath() <<
nl
183 if (!dynCode.wmakeLibso())
188 ) <<
"Failed wmake " << dynCode.libRelPath() <<
nl
196 !masterOnlyRead(contextDict)
206 off_t masterSize = mySize;
212 <<
" have masterSize:" << masterSize
213 <<
" and localSize:" << mySize
218 if (mySize < masterSize)
222 Pout<<
"Local file " << libPath
223 <<
" not of same size (" << mySize
225 << masterSize <<
"). Waiting for "
227 <<
" seconds." <<
endl;
234 if (mySize < masterSize)
239 ) <<
"Cannot read (NFS mounted) library " <<
nl
242 <<
" detected size " << mySize
243 <<
" whereas master size is " << masterSize
245 <<
"If your case is not NFS mounted"
246 <<
" (so distributed) set fileModificationSkew"
255 <<
" after waiting: have masterSize:" << masterSize
256 <<
" and localSize:" << mySize
265 Pout<<
"Opening cached dictionary:" << libPath <<
endl;
275 Pout<<
"Opening uncached dictionary:" << libPath <<
endl;
278 lib =
dlOpen(libPath,
true);
287 ) <<
"Failed loading library " << libPath <<
nl
288 <<
"Did you add all libraries to the 'libs' entry"
289 <<
" in system/controlDict?"
294 if (!masterOnlyRead(contextDict))
296 reduce(haveLib, andOp<bool>());
304 ) <<
"Failed loading library " << libPath
305 <<
" on some processors."
311 const streamingFunctionType
function =
312 reinterpret_cast<streamingFunctionType
>
314 dlSym(lib, dynCode.codeName())
323 ) <<
"Failed looking up symbol " << dynCode.codeName()
333 const dictionary& contextDict,
339 Info<<
"Using #codeStream at line " << is.lineNumber()
340 <<
" in file " << contextDict.name() <<
endl;
345 "functionEntries::codeStream::execute(..)",
351 const dictionary codeDict(
"#codeStream", contextDict, is);
353 const streamingFunctionType
function = getFunction(contextDict, codeDict);
356 OStringStream os(is.format());
357 (*function)(os, contextDict);
372 return insert(contextDict, run(contextDict, is));
383 return insert(contextDict, thisEntry, run(contextDict, 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.
bool global() const
Return global state.
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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 const wordList codeKeys
Keywords associated with source code.
static const word codeTemplateC
Name of the C code template to be used.
static const wordList codeDictVars
Name of the dictionary variables in the source code.
static bool execute(dictionary &contextDict, Istream &)
Execute the functionEntry in a sub-dict context.
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.