47 if (!isalpha(result[0]))
50 <<
"Cannot construct code name from function name \"" <<
name
51 <<
"\" as the first character is not alphabetic"
57 const bool valid = isalnum(result[i]) || result[i] ==
'_';
69 void* Foam::codedBase::loadLibrary
71 const fileName& libPath,
72 const string& globalFuncName,
73 const dictionary& contextDict
91 const loaderFunctionType
function =
92 reinterpret_cast<loaderFunctionType
>
94 dlSym(lib, globalFuncName)
106 ) <<
"Failed looking up symbol " << globalFuncName
115 ) <<
"Failed looking up symbol " << globalFuncName <<
nl
124 ) <<
"Failed unloading library "
137 void Foam::codedBase::unloadLibrary
139 const fileName& libPath,
140 const string& globalFuncName,
141 const dictionary& contextDict
161 const loaderFunctionType
function =
162 reinterpret_cast<loaderFunctionType
>
164 dlSym(lib, globalFuncName)
176 ) <<
"Failed looking up symbol " << globalFuncName <<
nl
186 ) <<
"Failed unloading library " << libPath
197 const word& codeDictVar,
198 const dictionary&
dict
201 verbatimString codeString;
223 void Foam::codedBase::createLibrary
225 const dictionary&
dict,
226 dynamicCode& dynCode,
227 const dynamicCodeContext& context
237 if (!dynCode.upToDate(context))
240 dynCode.reset(context);
242 this->prepare(dynCode, context);
244 if (!dynCode.copyOrCreateFiles(
true))
249 ) <<
"Failed writing files for" <<
nl
250 << dynCode.libRelPath() <<
nl
255 if (!dynCode.wmakeLibso())
260 ) <<
"Failed wmake " << dynCode.libRelPath() <<
nl
274 const fileName libPath = dynCode.libPath();
277 off_t masterSize = mySize;
283 <<
" have masterSize:" << masterSize
284 <<
" and localSize:" << mySize
288 if (mySize < masterSize)
292 Pout<<
"Local file " << libPath
293 <<
" not of same size (" << mySize
295 << masterSize <<
"). Waiting for "
297 <<
" seconds." <<
endl;
304 if (mySize < masterSize)
309 ) <<
"Cannot read (NFS mounted) library " <<
nl
312 <<
" detected size " << mySize
313 <<
" whereas master size is " << masterSize
315 <<
"If your case is not NFS mounted"
316 <<
" (so distributed) set fileModificationSkew"
325 <<
" after waiting: have masterSize:" << masterSize
326 <<
" and localSize:" << mySize
343 codeName_(codeName(
name)),
344 codeContext_(
dict, codeKeys, codeDictVars)
361 codeName_(cb.codeName_),
362 codeContext_(cb.codeContext_)
382 return this->
type() +
" " + codeName();
388 return baseTypeName +
"Template.C";
394 return baseTypeName +
"Template.H";
404 "codedBase::updateLibrary()",
412 name + codeContext_.sha1().str(
true),
424 Info<<
"Using dynamicCode for " << this->description().c_str()
439 createLibrary(
dict, dynCode, codeContext_);
449 oldLibPath_ = libPath;
457 codeContext_.read(
dict);
463 if (codeName().size())
468 codeContext_.write(os);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
graph_traits< Graph >::vertices_size_type size_type
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
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
void read(const dictionary &dict)
Read the dictionary and update the code.
const word & codeName() const
Name of the dynamically generated CodedType.
void write(Ostream &os) const
Write the code for restart.
codedBase(const word &name, const dictionary &dict, const wordList &codeKeys, const wordList &codeDictVars)
Construct from name and dictionary.
word codeTemplateH(const word &baseTypeName) const
virtual ~codedBase()
Destructor.
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
string description() const
Return a description (type + name) for the output.
const fileName & name() const
Return the dictionary name.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
T lookupOrDefault(const word &, const T &, const bool writeDefault=writeOptionalEntries > 0) const
Find and return a T, if not found return the given default.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
virtual 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.
Tools for handling dynamic code compilation.
const word & codeName() const
Return the code-name.
fileName libPath() const
Library path for specified code name.
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.
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.
static const verbatimString null
An empty verbatimString.
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)
string & inplaceExpandCodeString(string &, const dictionary &dict, const word &dictVar="dict", const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
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.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
defineTypeNameAndDebug(combustionModel, 0)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
prefixOSstream Pout(cout, "Pout")
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
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.