37 namespace functionEntries
60 const Foam::word Foam::functionEntries::codeStream::codeTemplateC =
61 "codeStreamTemplate.C";
66 bool Foam::functionEntries::codeStream::masterOnlyRead
68 const dictionary& dict
71 const dictionary& topDict = dict.topDict();
75 Pout<<
"codeStream : dictionary:" << dict.
name()
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,
324 Info<<
"Using #codeStream at line " << is.lineNumber()
325 <<
" in file " << parentDict.name() <<
endl;
329 "functionEntries::codeStream::execute(..)",
335 const dictionary codeDict(
"#codeStream", parentDict, is);
337 const streamingFunctionType
function = getFunction(parentDict, codeDict);
340 OStringStream os(is.format());
341 (*function)(os, parentDict);
356 return insert(parentDict, run(parentDict, is));
367 return insert(parentDict, thisEntry, run(parentDict, is));
virtual const fileName & name() const
Return the name of the stream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool master(const label communicator=0)
Am I the master process.
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream)
dlLibraryTable libs
Table of loaded dynamic libraries.
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling words, derived from string.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static bool execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
prefixOSstream Pout(cout, "Pout")
void * findLibrary(const fileName &libName)
Find the handle of the named library.
Macros for easy insertion into member function selection tables.
static float fileModificationSkew
off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return size of file.
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
A class for handling character strings derived from std::string.
unsigned int sleep(const unsigned int)
Sleep for the specified number of seconds.
void * dlOpen(const fileName &lib, const bool check=true)
Open a shared library. Return handle to library. Print error message.
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
defineTypeNameAndDebug(calcEntry, 0)