45 void* Foam::codedBase::loadLibrary
47 const fileName& libPath,
48 const string& globalFuncName,
49 const dictionary& contextDict
67 loaderFunctionType
function =
68 reinterpret_cast<loaderFunctionType
> 70 dlSym(lib, globalFuncName)
82 ) <<
"Failed looking up symbol " << globalFuncName
91 ) <<
"Failed looking up symbol " << globalFuncName <<
nl 100 ) <<
"Failed unloading library " 113 void Foam::codedBase::unloadLibrary
115 const fileName& libPath,
116 const string& globalFuncName,
117 const dictionary& contextDict
137 loaderFunctionType
function =
138 reinterpret_cast<loaderFunctionType
> 140 dlSym(lib, globalFuncName)
152 ) <<
"Failed looking up symbol " << globalFuncName <<
nl 162 ) <<
"Failed unloading library " << libPath
172 return this->
type() +
" " + codeName();
176 void Foam::codedBase::createLibrary
192 dynCode.
reset(context);
194 this->prepare(dynCode, context);
201 ) <<
"Failed writing files for" <<
nl 229 off_t masterSize = mySize;
235 <<
" have masterSize:" << masterSize
236 <<
" and localSize:" << mySize
241 if (mySize < masterSize)
245 Pout<<
"Local file " << libPath
246 <<
" not of same size (" << mySize
248 << masterSize <<
"). Waiting for " 250 <<
" seconds." <<
endl;
257 if (mySize < masterSize)
262 ) <<
"Cannot read (NFS mounted) library " <<
nl 265 <<
" detected size " << mySize
266 <<
" whereas master size is " << masterSize
268 <<
"If your case is not NFS mounted" 269 <<
" (so distributed) set fileModificationSkew" 278 <<
" after waiting: have masterSize:" << masterSize
279 <<
" and localSize:" << mySize
295 "codedBase::updateLibrary()",
305 name + context.
sha1().
str(
true),
317 Info<<
"Using dynamicCode for " << this->description().c_str()
323 this->clearRedirect();
334 if (!loadLibrary(libPath, dynCode.
codeName(), context.
dict()))
336 createLibrary(dynCode, context);
338 if (!loadLibrary(libPath, dynCode.
codeName(), context.
dict()))
346 oldLibPath_ = libPath;
370 codeName_(name.replaceAll(
"-",
"_")),
377 codeName_(dict.
lookup(
"name")),
384 codeName_(cb.codeName_),
399 return baseTypeName +
"Template.C";
405 return baseTypeName +
"Template.H";
417 codeAndBuildKeys.
append(
"codeOptions");
418 codeAndBuildKeys.
append(
"codeLibs");
420 forAll(codeAndBuildKeys, i)
A class for handling verbatimStrings, derived from string.
#define forAll(list, i)
Loop across all elements in list.
word codeTemplateH(const word &baseTypeName) const
virtual Ostream & write(const char)=0
Write character.
A class for handling file names.
Inter-processor communication reduction functions.
const SHA1Digest & sha1() const
Return SHA1 digest calculated from include, options, code.
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
void reset(const dynamicCodeContext &)
Clear files and reset variables to specified context.
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...
const word & codeName() const
Return the code-name.
word codeTemplateC(const word &baseTypeName) const
virtual const dictionary & codeDict() const
Get the dictionary to initialise the codeContext.
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.
virtual const word & codeName() const
Name of the dynamically generated CodedType.
const dictionary & dict() const
Return the parent dictionary context.
dlLibraryTable libs
Table of loaded dynamic libraries.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
virtual wordList codeKeys() const =0
Get the keywords associated with source code.
stressControl lookup("compactNormalStress") >> compactNormalStress
const fileName & name() const
Return the dictionary name.
fileName libRelPath() const
Library path for specified code name relative to $FOAM_CASE.
A class for handling words, derived from string.
void append(const T &)
Append an element at the end of the list.
Base class for function objects and boundary conditions using dynamic code.
virtual void writeCode(Ostream &os) const
bool wmakeLibso() const
Compile a libso.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
fileName libPath() const
Library path for specified code name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
bool close(const fileName &name, const bool verbose=true)
Close the named library, optionally with warnings if problems occur.
bool upToDate(const dynamicCodeContext &context) const
Verify if the copied code is up-to-date, based on Make/SHA1Digest.
codedBase()
Construct null.
bool copyOrCreateFiles(const bool verbose=false) const
Copy/create files prior to compilation.
defineTypeNameAndDebug(combustionModel, 0)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
static word libraryBaseName(const fileName &libPath)
Return the library basename without leading 'lib' or trailing '.so'.
void updateLibrary() const
Update library as required.
word name(const complex &)
Return a string representation of a complex.
Tools for handling dynamic code compilation.
Encapsulation of dynamic code dictionaries.
#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.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
static float fileModificationSkew
std::string str(const bool prefixed=false) const
Return (40-byte) text representation, optionally with '_' prefix.
off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return size of file.
virtual string description() const
Return a description (type + name) for the output.
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.
virtual ~codedBase()
Destructor.
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
bool dlSymFound(void *handle, const std::string &symbol)
Report if symbol in a dlopened library could be found.
label startLineNumber() const
Return line number of first token in dictionary.