38 namespace functionEntries
62 const Foam::word Foam::functionEntries::codeStream::codeTemplateC
63 =
"codeStreamTemplate.C";
70 const dictionary& dict
73 const IOdictionary& d =
static_cast<const IOdictionary&
>(dict.topDict());
74 return const_cast<Time&
>(d.time()).libs();
78 Foam::functionEntries::codeStream::streamingFunctionType
79 Foam::functionEntries::codeStream::getFunction
81 const dictionary& parentDict,
82 const dictionary& codeDict
86 dynamicCodeContext context(codeDict);
90 std::string sha1Str(context.sha1().str(
true));
91 dynamicCode dynCode(
"codeStream" + sha1Str, sha1Str);
95 const fileName libPath = dynCode.libPath();
99 if (isA<IOdictionary>(parentDict.topDict()))
101 lib = libs(parentDict).findLibrary(libPath);
106 Info<<
"Using #codeStream with " << libPath <<
endl;
114 if (isA<IOdictionary>(parentDict.topDict()))
118 dlLibraryTable& dlLibs = libs(parentDict);
119 if (dlLibs.open(libPath,
false))
121 lib = dlLibs.findLibrary(libPath);
127 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 194 off_t masterSize = mySize;
200 <<
" have masterSize:" << masterSize
201 <<
" and localSize:" << mySize
206 if (mySize < masterSize)
210 Pout<<
"Local file " << libPath
211 <<
" not of same size (" << mySize
213 << masterSize <<
"). Waiting for " 215 <<
" seconds." <<
endl;
222 if (mySize < masterSize)
227 ) <<
"Cannot read (NFS mounted) library " <<
nl 230 <<
" detected size " << mySize
231 <<
" whereas master size is " << masterSize
233 <<
"If your case is not NFS mounted" 234 <<
" (so distributed) set fileModificationSkew" 243 <<
" after waiting: have masterSize:" << masterSize
244 <<
" and localSize:" << mySize
249 if (isA<IOdictionary>(parentDict.topDict()))
253 dlLibraryTable& dlLibs = libs(parentDict);
257 Pout<<
"Opening cached dictionary:" << libPath <<
endl;
260 if (!dlLibs.open(libPath,
false))
265 ) <<
"Failed loading library " << libPath <<
nl 266 <<
"Did you add all libraries to the 'libs' entry" 267 <<
" in system/controlDict?" 271 lib = dlLibs.findLibrary(libPath);
278 Pout<<
"Opening uncached dictionary:" << libPath <<
endl;
280 lib =
dlOpen(libPath,
true);
287 reduce(haveLib, andOp<bool>());
295 ) <<
"Failed loading library " << libPath
296 <<
" on some processors." 302 streamingFunctionType
function =
303 reinterpret_cast<streamingFunctionType
> 305 dlSym(lib, dynCode.codeName())
314 ) <<
"Failed looking up symbol " << dynCode.codeName()
332 <<
" in file " << parentDict.
name() <<
endl;
336 "functionEntries::codeStream::execute(..)",
342 dictionary codeDict(
"#codeStream", parentDict, is);
344 streamingFunctionType
function = getFunction(parentDict, codeDict);
348 (*function)(os, parentDict);
352 entry.
read(parentDict, resultStream);
365 <<
" in file " << parentDict.
name() <<
endl;
369 "functionEntries::codeStream::execute(..)",
375 dictionary codeDict(
"#codeStream", parentDict, is);
377 streamingFunctionType
function = getFunction(parentDict, codeDict);
381 (*function)(os, parentDict);
385 parentDict.
read(resultStream);
bool read(Istream &)
Read dictionary from Istream.
streamFormat format() const
Return current stream format.
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.
const fileName & name() const
Return the dictionary name.
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.
A class for handling words, derived from string.
A table of dynamically loaded libraries.
off_t fileSize(const fileName &)
Return size of file.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
prefixOSstream Pout(cout,"Pout")
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static bool masterOnlyReading
To flag master-only reading of objects.
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.
label lineNumber() const
Return current stream line number.
static int fileModificationSkew
Macros for easy insertion into member function selection tables.
virtual bool read(const dictionary &, Istream &)
Read tokens from the given stream.
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)