add plugin clear command to unload all loaded plugins

This commit is contained in:
Axel Kohlmeyer
2021-03-13 12:40:04 -05:00
parent 79d438e090
commit 88760fa648
5 changed files with 28 additions and 7 deletions

View File

@ -10,7 +10,7 @@ Syntax
plugin command args
* command = *load* or *unload* or *list*
* command = *load* or *unload* or *list* or *clear*
* args = list of arguments for a particular plugin command
.. parsed-literal::
@ -19,6 +19,7 @@ Syntax
*unload* style name = unload plugin *name* of style *style*
*style* = *pair* or *fix* or *command*
*list* = print a list of currently loaded plugins
*clear* = unload all currently loaded plugins
Examples
""""""""
@ -29,6 +30,7 @@ Examples
plugin unload pair morse2/omp
plugin unload command hello
plugin list
plugin clear
Description
"""""""""""
@ -52,21 +54,25 @@ that style instance will be deleted.
The *list* command will print a list of the loaded plugins and their
styles and names.
The *clear* command will unload all currently loaded plugins.
Restrictions
""""""""""""
Plugins are currently not available on Windows.
Plugins are not available on Windows.
For the loading of plugins to work, the LAMMPS library must be
:ref:`compiled as a shared library <library>`.
For the loading of plugins to work the LAMMPS library must be
:ref:`compiled as a shared library <library>`. If plugins
access functions or classes from a package, LAMMPS must have
been compiled with that package included.
Plugins are dependent on the LAMMPS binary interface (ABI)
and particularly the MPI library used. So they are not guaranteed
to work when the plugin was compiled with a different MPI library
or different compilation settings or a different LAMMPS version.
If there is a mismatch the *plugin* command may fail to load the
plugin(s) or data corruption or crashes may happen.
There are no checks, so if there is a mismatch the plugin object
will either not load or data corruption and crashes may happen.
Related commands

View File

@ -1110,6 +1110,8 @@ void Input::plugin()
} else if (cmd == "unload") {
if (narg != 3) error->all(FLERR,"Illegal plugin unload command");
plugin_unload(arg[1],arg[2],lmp);
} else if (cmd == "clear") {
plugin_clear(lmp);
} else if (cmd == "list") {
if (comm->me == 0) {
int num = plugin_get_num_plugins();

View File

@ -238,6 +238,18 @@ namespace LAMMPS_NS
}
}
/* --------------------------------------------------------------------
unload all loaded plugins
-------------------------------------------------------------------- */
void plugin_clear(LAMMPS *lmp)
{
while (pluginlist.size() > 0) {
auto p = pluginlist.begin();
plugin_unload(p->style,p->name,lmp);
}
}
/* --------------------------------------------------------------------
remove plugin of given name and style from internal lists
-------------------------------------------------------------------- */

View File

@ -25,6 +25,7 @@ namespace LAMMPS_NS
void plugin_unload(const char *, const char *, LAMMPS *);
void plugin_erase(const char *, const char *);
void plugin_clear(LAMMPS *);
int plugin_get_num_plugins();
int plugin_find(const char *, const char *);

View File

@ -350,7 +350,7 @@ static char *variable_expand_generator(const char *text, int state)
static char *plugin_generator(const char *text, int state)
{
const char *subcmd[] = {"load", "unload", "list", NULL};
const char *subcmd[] = {"load", "unload", "list", "clear", NULL};
const char *sub;
static std::size_t idx, len;
if (!state) idx = 0;