49 if (!isalpha(result[0]))
52 <<
"Cannot construct code name from function name \"" <<
name
53 <<
"\" as the first character is not alphabetic"
59 const bool valid = isalnum(result[i]) || result[i] ==
'_';
71 void* Foam::codedBase::loadLibrary
73 const fileName& libPath,
74 const string& globalFuncName,
75 const dictionary& contextDict
93 loaderFunctionType
function =
94 reinterpret_cast<loaderFunctionType
>
96 dlSym(lib, globalFuncName)
108 ) <<
"Failed looking up symbol " << globalFuncName
117 ) <<
"Failed looking up symbol " << globalFuncName <<
nl
126 ) <<
"Failed unloading library "
139 void Foam::codedBase::unloadLibrary
141 const fileName& libPath,
142 const string& globalFuncName,
143 const dictionary& contextDict
163 loaderFunctionType
function =
164 reinterpret_cast<loaderFunctionType
>
166 dlSym(lib, globalFuncName)
178 ) <<
"Failed looking up symbol " << globalFuncName <<
nl
188 ) <<
"Failed unloading library " << libPath
198 return this->
type() +
" " + codeName();
202 void Foam::codedBase::createLibrary
218 dynCode.
reset(context);
220 this->prepare(dynCode, context);
227 ) <<
"Failed writing files for" <<
nl
252 const fileName libPath = dynCode.
libPath();
255 off_t masterSize = mySize;
261 <<
" have masterSize:" << masterSize
262 <<
" and localSize:" << mySize
267 if (mySize < masterSize)
271 Pout<<
"Local file " << libPath
272 <<
" not of same size (" << mySize
274 << masterSize <<
"). Waiting for "
276 <<
" seconds." <<
endl;
283 if (mySize < masterSize)
288 ) <<
"Cannot read (NFS mounted) library " <<
nl
291 <<
" detected size " << mySize
292 <<
" whereas master size is " << masterSize
294 <<
"If your case is not NFS mounted"
295 <<
" (so distributed) set fileModificationSkew"
304 <<
" after waiting: have masterSize:" << masterSize
305 <<
" and localSize:" << mySize
321 "codedBase::updateLibrary()",
343 Info<<
"Using dynamicCode for " << this->description().c_str()
349 this->clearRedirect();
360 if (!loadLibrary(libPath, dynCode.
codeName(), context.
dict()))
362 createLibrary(dynCode, context);
364 if (!loadLibrary(libPath, dynCode.
codeName(), context.
dict()))
372 oldLibPath_ = libPath;
396 codeName_(codeName(
name)),
403 codeName_(codeName(
dict.lookup(
"name"))),
410 codeName_(cb.codeName_),
425 return baseTypeName +
"Template.C";
431 return baseTypeName +
"Template.H";
437 if (codeName().size())
442 wordList codeAndBuildKeys(codeKeys());
443 codeAndBuildKeys.
append(
"codeOptions");
444 codeAndBuildKeys.
append(
"codeLibs");
446 forAll(codeAndBuildKeys, i)
448 if (codeDict().
found(codeAndBuildKeys[i]))
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Inter-processor communication reduction functions.
graph_traits< Graph >::vertices_size_type size_type
#define forAll(list, i)
Loop across all elements in list.
void append(const T &)
Append an element at the end of the list.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & write(const char)=0
Write character.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
std::string str(const bool prefixed=false) const
Return (40-byte) text representation, optionally with '_' prefix.
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)
Base class for function objects and boundary conditions using dynamic code.
word codeTemplateC(const word &baseTypeName) const
virtual void writeCode(Ostream &os) const
virtual const word & codeName() const
Name of the dynamically generated CodedType.
word codeTemplateH(const word &baseTypeName) const
virtual ~codedBase()
Destructor.
codedBase()
Construct null.
virtual const dictionary & codeDict() const
Get the dictionary to initialise the codeContext.
void updateLibrary() const
Update library as required.
virtual string description() const
Return a description (type + name) for the output.
const fileName & name() const
Return the dictionary name.
A list of keyword definitions, which are a keyword followed by any number of values (e....
label startLineNumber() const
Return line number of first token in dictionary.
bool close(const fileName &name, const bool verbose=true)
Close the named library, optionally with warnings if problems occur.
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.
Encapsulation of dynamic code dictionaries.
const dictionary & dict() const
Return the parent dictionary context.
const SHA1Digest & sha1() const
Return SHA1 digest calculated from include, options, code.
Tools for handling dynamic code compilation.
const word & codeName() const
Return the code-name.
bool copyOrCreateFiles(const bool verbose=false) const
Copy/create files prior to compilation.
fileName libPath() const
Library path for specified code name.
void reset(const dynamicCodeContext &)
Clear files and reset variables to specified context.
fileName libRelPath() const
Library path for specified code name relative to $FOAM_CASE.
static word libraryBaseName(const fileName &libPath)
Return the library basename without leading 'lib' or trailing '.so'.
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
bool upToDate(const dynamicCodeContext &context) const
Verify if the copied code is up-to-date, based on Make/SHA1Digest.
bool wmakeLibso() const
Compile a libso.
A class for handling file names.
static float fileModificationSkew
A class for handling character strings derived from std::string.
A class for handling verbatimStrings, derived from string.
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool valid(const PtrList< ModelType > &l)
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.
bool dlSymFound(void *handle, const std::string &symbol)
Report if symbol in a dlopened library could be found.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout, "Pout")
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
unsigned int sleep(const unsigned int)
Sleep for the specified number of seconds.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.