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
226 const fileName libPath = dynCode.
libPath();
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()",
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";
411 if (codeName().size())
416 wordList codeAndBuildKeys(codeKeys());
417 codeAndBuildKeys.
append(
"codeOptions");
418 codeAndBuildKeys.
append(
"codeLibs");
420 forAll(codeAndBuildKeys, i)
422 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.
#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.
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)
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.
word name(const complex &)
Return a string representation of a complex.
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.