mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: minor code cleanup for codeStream/codedFixedValueFvPatchScalarField
This commit is contained in:
@ -98,21 +98,20 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
// see if library is loaded
|
// see if library is loaded
|
||||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||||
|
|
||||||
bool reuseLib = false;
|
|
||||||
|
|
||||||
// nothing loaded
|
// nothing loaded
|
||||||
// avoid compilation if possible by loading an existing library
|
// avoid compilation if possible by loading an existing library
|
||||||
if (!lib && dlLibraryTable::open(libPath, false))
|
if (!lib && dlLibraryTable::open(libPath, false))
|
||||||
{
|
{
|
||||||
lib = dlLibraryTable::findLibrary(libPath);
|
lib = dlLibraryTable::findLibrary(libPath);
|
||||||
reuseLib = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create library if required
|
// create library if required
|
||||||
if (!lib)
|
if (!lib)
|
||||||
{
|
{
|
||||||
if (Pstream::master())
|
bool create = Pstream::master();
|
||||||
|
|
||||||
|
if (create)
|
||||||
{
|
{
|
||||||
if (!dynCode.upToDate(context))
|
if (!dynCode.upToDate(context))
|
||||||
{
|
{
|
||||||
@ -137,7 +136,7 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
"functionEntries::codeStream::execute(..)",
|
"functionEntries::codeStream::execute(..)",
|
||||||
parentDict
|
parentDict
|
||||||
) << "Failed writing files for" << nl
|
) << "Failed writing files for" << nl
|
||||||
<< dynCode.libPath() << nl
|
<< dynCode.libRelPath() << nl
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,14 +147,13 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
(
|
(
|
||||||
"functionEntries::codeStream::execute(..)",
|
"functionEntries::codeStream::execute(..)",
|
||||||
parentDict
|
parentDict
|
||||||
) << "Failed wmake " << libPath
|
) << "Failed wmake " << dynCode.libRelPath() << nl
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// all processes must wait for compile
|
// all processes must wait for compile to finish
|
||||||
bool waiting = true;
|
reduce(create, orOp<bool>());
|
||||||
reduce(waiting, orOp<bool>());
|
|
||||||
|
|
||||||
if (!dlLibraryTable::open(libPath, false))
|
if (!dlLibraryTable::open(libPath, false))
|
||||||
{
|
{
|
||||||
@ -163,21 +161,17 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
(
|
(
|
||||||
"functionEntries::codeStream::execute(..)",
|
"functionEntries::codeStream::execute(..)",
|
||||||
parentDict
|
parentDict
|
||||||
) << "Failed loading library " << libPath
|
) << "Failed loading library " << libPath << nl
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
lib = dlLibraryTable::findLibrary(libPath);
|
lib = dlLibraryTable::findLibrary(libPath);
|
||||||
}
|
}
|
||||||
else if (reuseLib)
|
|
||||||
{
|
|
||||||
Info<< "Reusing library in " << libPath << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Find the function handle in the library
|
// Find the function handle in the library
|
||||||
void (*function)(Ostream&, const dictionary&);
|
streamingFunctionType function =
|
||||||
function = reinterpret_cast<void(*)(Ostream&, const dictionary&)>
|
reinterpret_cast<streamingFunctionType>
|
||||||
(
|
(
|
||||||
dlSym(lib, dynCode.codeName())
|
dlSym(lib, dynCode.codeName())
|
||||||
);
|
);
|
||||||
|
|||||||
@ -109,6 +109,11 @@ class codeStream
|
|||||||
:
|
:
|
||||||
public functionEntry
|
public functionEntry
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//- Interpreter function type
|
||||||
|
typedef void (*streamingFunctionType)(Ostream&, const dictionary&);
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
|
|||||||
@ -47,32 +47,6 @@ const Foam::word Foam::codedFixedValueFvPatchScalarField::codeTemplateH
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
Foam::string Foam::codedFixedValueFvPatchScalarField::libraryGlobalName
|
|
||||||
(
|
|
||||||
const fileName& libPath
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// global function name (SHA1-encoded)
|
|
||||||
// that can be used for version control and/or explicit loading/unloading
|
|
||||||
string globalFuncName = libPath.name();
|
|
||||||
|
|
||||||
// remove ".so" extension
|
|
||||||
string::size_type dot = globalFuncName.find('.');
|
|
||||||
if (dot != string::npos)
|
|
||||||
{
|
|
||||||
globalFuncName.resize(dot);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove leading 'lib' from name
|
|
||||||
globalFuncName.erase(0, 3);
|
|
||||||
|
|
||||||
return globalFuncName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
||||||
(
|
(
|
||||||
const fileName& libPath,
|
const fileName& libPath,
|
||||||
@ -82,20 +56,17 @@ void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
|||||||
{
|
{
|
||||||
void* lib = 0;
|
void* lib = 0;
|
||||||
|
|
||||||
// global function name (SHA1-encoded)
|
|
||||||
// that can be used for version control and/or explicit loading/unloading
|
|
||||||
|
|
||||||
// avoid compilation by loading an existing library
|
// avoid compilation by loading an existing library
|
||||||
if (dlLibraryTable::open(libPath, false))
|
if (!libPath.empty() && dlLibraryTable::open(libPath, false))
|
||||||
{
|
{
|
||||||
lib = dlLibraryTable::findLibrary(libPath);
|
lib = dlLibraryTable::findLibrary(libPath);
|
||||||
|
|
||||||
// verify the loaded version and unload if needed
|
// verify the loaded version and unload if needed
|
||||||
if (lib)
|
if (lib)
|
||||||
{
|
{
|
||||||
|
// provision for manual execution of code after loading
|
||||||
if (dlSymFound(lib, globalFuncName))
|
if (dlSymFound(lib, globalFuncName))
|
||||||
{
|
{
|
||||||
// Find the function handle in the library
|
|
||||||
loaderFunctionType function =
|
loaderFunctionType function =
|
||||||
reinterpret_cast<loaderFunctionType>
|
reinterpret_cast<loaderFunctionType>
|
||||||
(
|
(
|
||||||
@ -104,8 +75,7 @@ void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
|||||||
|
|
||||||
if (function)
|
if (function)
|
||||||
{
|
{
|
||||||
// force load
|
(*function)(true); // force load
|
||||||
(*function)(true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -152,7 +122,12 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
|||||||
const dictionary& contextDict
|
const dictionary& contextDict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
void* lib = 0;
|
||||||
|
|
||||||
|
if (!libPath.empty())
|
||||||
|
{
|
||||||
|
lib = dlLibraryTable::findLibrary(libPath);
|
||||||
|
}
|
||||||
|
|
||||||
if (!lib)
|
if (!lib)
|
||||||
{
|
{
|
||||||
@ -162,7 +137,6 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
|||||||
// provision for manual execution of code before unloading
|
// provision for manual execution of code before unloading
|
||||||
if (dlSymFound(lib, globalFuncName))
|
if (dlSymFound(lib, globalFuncName))
|
||||||
{
|
{
|
||||||
// Find the function handle in the library
|
|
||||||
loaderFunctionType function =
|
loaderFunctionType function =
|
||||||
reinterpret_cast<loaderFunctionType>
|
reinterpret_cast<loaderFunctionType>
|
||||||
(
|
(
|
||||||
@ -171,8 +145,7 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
|||||||
|
|
||||||
if (function)
|
if (function)
|
||||||
{
|
{
|
||||||
// force unload
|
(*function)(false); // force unload
|
||||||
(*function)(false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -181,8 +154,7 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
|||||||
"codedFixedValueFvPatchScalarField::unloadLibrary()",
|
"codedFixedValueFvPatchScalarField::unloadLibrary()",
|
||||||
contextDict
|
contextDict
|
||||||
) << "Failed looking up symbol " << globalFuncName << nl
|
) << "Failed looking up symbol " << globalFuncName << nl
|
||||||
<< "from " << libPath
|
<< "from " << libPath << exit(FatalIOError);
|
||||||
<< exit(FatalIOError);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,9 +204,13 @@ void Foam::codedFixedValueFvPatchScalarField::createLibrary
|
|||||||
dynamicCode& dynCode,
|
dynamicCode& dynCode,
|
||||||
const dynamicCodeContext& context
|
const dynamicCodeContext& context
|
||||||
) const
|
) const
|
||||||
|
{
|
||||||
|
bool create = Pstream::master();
|
||||||
|
|
||||||
|
if (create)
|
||||||
{
|
{
|
||||||
// Write files for new library
|
// Write files for new library
|
||||||
if (Pstream::master() && !dynCode.upToDate(context))
|
if (!dynCode.upToDate(context))
|
||||||
{
|
{
|
||||||
// filter with this context
|
// filter with this context
|
||||||
dynCode.reset(context);
|
dynCode.reset(context);
|
||||||
@ -266,13 +242,28 @@ void Foam::codedFixedValueFvPatchScalarField::createLibrary
|
|||||||
{
|
{
|
||||||
FatalIOErrorIn
|
FatalIOErrorIn
|
||||||
(
|
(
|
||||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
"codedFixedValueFvPatchScalarField::createLibrary(..)",
|
||||||
context.dict()
|
context.dict()
|
||||||
) << "Failed writing files for" << nl
|
) << "Failed writing files for" << nl
|
||||||
<< dynCode.libPath() << nl
|
<< dynCode.libRelPath() << nl
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dynCode.wmakeLibso())
|
||||||
|
{
|
||||||
|
FatalIOErrorIn
|
||||||
|
(
|
||||||
|
"codedFixedValueFvPatchScalarField::createLibrary(..)",
|
||||||
|
context.dict()
|
||||||
|
) << "Failed wmake " << dynCode.libRelPath() << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// all processes must wait for compile to finish
|
||||||
|
reduce(create, orOp<bool>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -294,7 +285,6 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() const
|
|||||||
|
|
||||||
dynamicCodeContext context(codeDict);
|
dynamicCodeContext context(codeDict);
|
||||||
|
|
||||||
|
|
||||||
// codeName: redirectType + _<sha1>
|
// codeName: redirectType + _<sha1>
|
||||||
// codeDir : redirectType
|
// codeDir : redirectType
|
||||||
dynamicCode dynCode
|
dynamicCode dynCode
|
||||||
@ -305,77 +295,33 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() const
|
|||||||
const fileName libPath = dynCode.libPath();
|
const fileName libPath = dynCode.libPath();
|
||||||
|
|
||||||
|
|
||||||
// see if library is loaded
|
// the correct library was already loaded => we are done
|
||||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
if (dlLibraryTable::findLibrary(libPath))
|
||||||
|
|
||||||
// library not loaded, and also need to unload old version
|
|
||||||
if (!lib && !oldLibPath_.empty())
|
|
||||||
{
|
|
||||||
// unload code
|
|
||||||
// Remove instantiation of fvPatchField provided by library
|
|
||||||
redirectPatchFieldPtr_.clear();
|
|
||||||
|
|
||||||
unloadLibrary
|
|
||||||
(
|
|
||||||
oldLibPath_,
|
|
||||||
libraryGlobalName(oldLibPath_),
|
|
||||||
context.dict()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// retain for future reference
|
|
||||||
oldLibPath_ = libPath;
|
|
||||||
|
|
||||||
bool waiting = false;
|
|
||||||
|
|
||||||
if (lib)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove instantiation of fvPatchField provided by library
|
// remove instantiation of fvPatchField provided by library
|
||||||
redirectPatchFieldPtr_.clear();
|
redirectPatchFieldPtr_.clear();
|
||||||
|
|
||||||
// avoid compilation by loading an existing library
|
// may need to unload old library
|
||||||
lib = loadLibrary
|
unloadLibrary
|
||||||
(
|
(
|
||||||
libPath,
|
oldLibPath_,
|
||||||
dynCode.codeName(),
|
dynamicCode::libraryBaseName(oldLibPath_),
|
||||||
context.dict()
|
context.dict()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// try loading an existing library (avoid compilation when possible)
|
||||||
// really do need to create library
|
if (!loadLibrary(libPath, dynCode.codeName(), context.dict()))
|
||||||
if (!lib)
|
|
||||||
{
|
|
||||||
if (Pstream::master())
|
|
||||||
{
|
{
|
||||||
createLibrary(dynCode, context);
|
createLibrary(dynCode, context);
|
||||||
|
|
||||||
if (!dynCode.wmakeLibso())
|
loadLibrary(libPath, dynCode.codeName(), context.dict());
|
||||||
{
|
|
||||||
FatalIOErrorIn
|
|
||||||
(
|
|
||||||
"codedFixedValueFvPatchScalarField::updateLibrary()",
|
|
||||||
context.dict()
|
|
||||||
) << "Failed wmake " << libPath
|
|
||||||
<< exit(FatalIOError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// all processes must wait for compile
|
// retain for future reference
|
||||||
waiting = true;
|
oldLibPath_ = libPath;
|
||||||
reduce(waiting, orOp<bool>());
|
|
||||||
|
|
||||||
// load newly compiled libray
|
|
||||||
lib = loadLibrary
|
|
||||||
(
|
|
||||||
libPath,
|
|
||||||
dynCode.codeName(),
|
|
||||||
context.dict()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -114,13 +114,11 @@ class codedFixedValueFvPatchScalarField
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
// Generic library management pieces
|
const IOdictionary& dict() const;
|
||||||
|
|
||||||
//- Global loader/unloader function type
|
//- Global loader/unloader function type
|
||||||
typedef void (*loaderFunctionType)(bool);
|
typedef void (*loaderFunctionType)(bool);
|
||||||
|
|
||||||
static string libraryGlobalName(const fileName& libPath);
|
|
||||||
|
|
||||||
static void* loadLibrary
|
static void* loadLibrary
|
||||||
(
|
(
|
||||||
const fileName& libPath,
|
const fileName& libPath,
|
||||||
@ -136,13 +134,12 @@ class codedFixedValueFvPatchScalarField
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const IOdictionary& dict() const;
|
|
||||||
|
|
||||||
void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
|
void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
|
||||||
|
|
||||||
//- Update library as required
|
//- Update library as required
|
||||||
void updateLibrary() const;
|
void updateLibrary() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Static data members
|
// Static data members
|
||||||
|
|||||||
Reference in New Issue
Block a user