38 namespace functionEntries
62 const Foam::word Foam::functionEntries::codeStream::codeTemplateC =
63 "codeStreamTemplate.C";
70 const dictionary& dict
77 bool Foam::functionEntries::codeStream::doingMasterOnlyReading
79 const dictionary& dict
82 const dictionary& topDict = dict.topDict();
84 if (isA<baseIOdictionary>(topDict))
86 const baseIOdictionary& d =
static_cast<const baseIOdictionary&
> 93 Pout<<
"codeStream : baseIOdictionary:" << dict.
name()
94 <<
" master-only-reading:" << d.global()
104 Pout<<
"codeStream : not a baseIOdictionary:" << dict.
name()
105 <<
" master-only-reading:" <<
false 115 Foam::functionEntries::codeStream::streamingFunctionType
116 Foam::functionEntries::codeStream::getFunction
118 const dictionary& parentDict,
119 const dictionary& codeDict
123 dynamicCodeContext context(codeDict, {
"code",
"codeInclude",
"localCode"});
127 std::string sha1Str(context.sha1().str(
true));
128 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
132 const fileName libPath = dynCode.libPath();
137 const dictionary& topDict = parentDict.topDict();
138 if (isA<baseIOdictionary>(topDict))
145 Info<<
"Using #codeStream with " << libPath <<
endl;
153 if (isA<baseIOdictionary>(topDict))
157 dlLibraryTable& dlLibs =
libs(parentDict);
158 if (dlLibs.open(libPath,
false))
160 lib = dlLibs.findLibrary(libPath);
166 lib =
dlOpen(libPath,
false);
180 if (!dynCode.upToDate(context))
183 dynCode.reset(context);
186 dynCode.addCompileFile(codeTemplateC);
189 dynCode.setMakeOptions
193 +
"\n\nLIB_LIBS = \\\n" 198 if (!dynCode.copyOrCreateFiles(
true))
203 ) <<
"Failed writing files for" <<
nl 204 << dynCode.libRelPath() <<
nl 209 if (!dynCode.wmakeLibso())
214 ) <<
"Failed wmake " << dynCode.libRelPath() <<
nl 223 !doingMasterOnlyReading(topDict)
233 off_t masterSize = mySize;
239 <<
" have masterSize:" << masterSize
240 <<
" and localSize:" << mySize
245 if (mySize < masterSize)
249 Pout<<
"Local file " << libPath
250 <<
" not of same size (" << mySize
252 << masterSize <<
"). Waiting for " 254 <<
" seconds." <<
endl;
261 if (mySize < masterSize)
266 ) <<
"Cannot read (NFS mounted) library " <<
nl 269 <<
" detected size " << mySize
270 <<
" whereas master size is " << masterSize
272 <<
"If your case is not NFS mounted" 273 <<
" (so distributed) set fileModificationSkew" 282 <<
" after waiting: have masterSize:" << masterSize
283 <<
" and localSize:" << mySize
288 if (isA<baseIOdictionary>(topDict))
292 dlLibraryTable& dlLibs =
libs(parentDict);
296 Pout<<
"Opening cached dictionary:" << libPath <<
endl;
299 if (!dlLibs.open(libPath,
false))
304 ) <<
"Failed loading library " << libPath <<
nl 305 <<
"Did you add all libraries to the 'libs' entry" 306 <<
" in system/controlDict?" 310 lib = dlLibs.findLibrary(libPath);
317 Pout<<
"Opening uncached dictionary:" << libPath <<
endl;
319 lib =
dlOpen(libPath,
true);
324 if (!doingMasterOnlyReading(topDict))
326 reduce(haveLib, andOp<bool>());
334 ) <<
"Failed loading library " << libPath
335 <<
" on some processors." 341 streamingFunctionType
function =
342 reinterpret_cast<streamingFunctionType
> 344 dlSym(lib, dynCode.codeName())
353 ) <<
"Failed looking up symbol " << dynCode.codeName()
363 const dictionary& parentDict,
367 Info<<
"Using #codeStream at line " << is.lineNumber()
368 <<
" in file " << parentDict.name() <<
endl;
372 "functionEntries::codeStream::execute(..)",
378 dictionary codeDict(
"#codeStream", parentDict, is);
380 streamingFunctionType
function = getFunction(parentDict, codeDict);
383 OStringStream os(is.format());
384 (*function)(os, parentDict);
399 return insert(parentDict, run(parentDict, is));
410 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.
A class for handling words, derived from string.
A table of dynamically loaded libraries.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
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)