38 namespace functionEntries
62 const Foam::word Foam::functionEntries::codeStream::codeTemplateC =
63 "codeStreamTemplate.C";
70 const dictionary& dict
73 const baseIOdictionary& d =
static_cast<const baseIOdictionary&
> 77 return const_cast<Time&
>(d.time()).libs();
81 bool Foam::functionEntries::codeStream::doingMasterOnlyReading
83 const dictionary& dict
86 const dictionary& topDict = dict.topDict();
88 if (isA<baseIOdictionary>(topDict))
90 const baseIOdictionary& d =
static_cast<const baseIOdictionary&
> 97 Pout<<
"codeStream : baseIOdictionary:" << dict.
name()
98 <<
" master-only-reading:" << d.global()
108 Pout<<
"codeStream : not a baseIOdictionary:" << dict.
name()
109 <<
" master-only-reading:" <<
false 119 Foam::functionEntries::codeStream::streamingFunctionType
120 Foam::functionEntries::codeStream::getFunction
122 const dictionary& parentDict,
123 const dictionary& codeDict
127 dynamicCodeContext context(codeDict, {
"code",
"codeInclude",
"localCode"});
131 std::string sha1Str(context.sha1().str(
true));
132 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
136 const fileName libPath = dynCode.libPath();
141 const dictionary& topDict = parentDict.topDict();
142 if (isA<baseIOdictionary>(topDict))
144 lib = libs(parentDict).findLibrary(libPath);
149 Info<<
"Using #codeStream with " << libPath <<
endl;
157 if (isA<baseIOdictionary>(topDict))
161 dlLibraryTable& dlLibs = libs(parentDict);
162 if (dlLibs.open(libPath,
false))
164 lib = dlLibs.findLibrary(libPath);
170 lib =
dlOpen(libPath,
false);
184 if (!dynCode.upToDate(context))
187 dynCode.reset(context);
190 dynCode.addCompileFile(codeTemplateC);
193 dynCode.setMakeOptions
197 +
"\n\nLIB_LIBS = \\\n" 202 if (!dynCode.copyOrCreateFiles(
true))
207 ) <<
"Failed writing files for" <<
nl 208 << dynCode.libRelPath() <<
nl 213 if (!dynCode.wmakeLibso())
218 ) <<
"Failed wmake " << dynCode.libRelPath() <<
nl 227 !doingMasterOnlyReading(topDict)
237 off_t masterSize = mySize;
243 <<
" have masterSize:" << masterSize
244 <<
" and localSize:" << mySize
249 if (mySize < masterSize)
253 Pout<<
"Local file " << libPath
254 <<
" not of same size (" << mySize
256 << masterSize <<
"). Waiting for " 258 <<
" seconds." <<
endl;
265 if (mySize < masterSize)
270 ) <<
"Cannot read (NFS mounted) library " <<
nl 273 <<
" detected size " << mySize
274 <<
" whereas master size is " << masterSize
276 <<
"If your case is not NFS mounted" 277 <<
" (so distributed) set fileModificationSkew" 286 <<
" after waiting: have masterSize:" << masterSize
287 <<
" and localSize:" << mySize
292 if (isA<baseIOdictionary>(topDict))
296 dlLibraryTable& dlLibs = libs(parentDict);
300 Pout<<
"Opening cached dictionary:" << libPath <<
endl;
303 if (!dlLibs.open(libPath,
false))
308 ) <<
"Failed loading library " << libPath <<
nl 309 <<
"Did you add all libraries to the 'libs' entry" 310 <<
" in system/controlDict?" 314 lib = dlLibs.findLibrary(libPath);
321 Pout<<
"Opening uncached dictionary:" << libPath <<
endl;
323 lib =
dlOpen(libPath,
true);
328 if (!doingMasterOnlyReading(topDict))
330 reduce(haveLib, andOp<bool>());
338 ) <<
"Failed loading library " << libPath
339 <<
" on some processors." 345 streamingFunctionType
function =
346 reinterpret_cast<streamingFunctionType
> 348 dlSym(lib, dynCode.codeName())
357 ) <<
"Failed looking up symbol " << dynCode.codeName()
375 <<
" in file " << parentDict.
name() <<
endl;
379 "functionEntries::codeStream::execute(..)",
385 dictionary codeDict(
"#codeStream", parentDict, is);
387 streamingFunctionType
function = getFunction(parentDict, codeDict);
391 (*function)(os, parentDict);
395 entry.
read(parentDict, resultStream);
408 <<
" in file " << parentDict.
name() <<
endl;
412 "functionEntries::codeStream::execute(..)",
418 dictionary codeDict(
"#codeStream", parentDict, is);
420 streamingFunctionType
function = getFunction(parentDict, codeDict);
424 (*function)(os, parentDict);
428 parentDict.
read(resultStream);
virtual const fileName & name() const
Return the name of the stream.
bool read(Istream &)
Read dictionary from Istream.
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.
label lineNumber() const
Return current stream line number.
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream)
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.
const fileName & name() const
Return the dictionary name.
A class for handling words, derived from string.
streamFormat format() const
Return current stream format.
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.
Input from memory buffer stream.
prefixOSstream Pout(cout, "Pout")
Macros for easy insertion into member function selection tables.
static float fileModificationSkew
virtual bool read(const dictionary &, Istream &)
Read tokens from the given stream.
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.
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.
Output to memory buffer stream.
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
defineTypeNameAndDebug(calcEntry, 0)