Refactor: replace static colvarmodule with class member#886
Refactor: replace static colvarmodule with class member#886giacomofiorin merged 24 commits intomasterfrom
Conversation
|
A lot of progress towards the goal. Some classes got access to a The main hurdle that remains is the scripts, which rely heavily on the static As a first step, we could keep a static, global |
|
This is great progress already! :-) For Tcl, we could maybe use That would only work for Tcl, but that's also where you would need it. LAMMPS scripting commands are associated to a |
|
My main concern is, all Colvars functionality relies on there being a single instance of the module. Removing static pointers would also require adding a different kind of check that there is only one |
Why does all functionality rely on being a single instance? |
Mostly for I/O: if multiple instances were allowed, each would need its own set of input and output files. |
But this is what the derived classes of |
|
In practice, the main application I've had in mind so far would be associating one colvarmodule instance with one molecule in VMD, although that would need more work because 1) VMD has a single Tcl interpreter, and 2) so far we have single proxy object - so we'd have to choose between duplicating the proxy object as well, or let a single proxy switch between molecules. Given the current architecture, I think one proxy per molecule would be simpler. Thanks to Giacomo's suggestion with You may have more ideas for using multiple instances: I'm interested. |
|
To answer @giacomofiorin 's remark about relying on there being a single instance: my goal here is that several instances could exist and that all calls are addressed to the right objects. One point to be worked out is whether they attach to the same or different proxy objects. For now, I am working under the assumption of a proxy object talking to a single colvarmodule instance. |
|
Making these changes, I find that the scripting functionality would be better located in the colvarmodule class than colvarproxy. The colvarscript object is now created and used only by the module, and the proxy is just an extra level of indirection. |
|
I had to re-introduce a patch to ScriptTcl.C to pass the correct colvarscript pointer in the NAMD-defined version of the cv command. Incompatible (non-patched) NAMD will pass a wrong pointer, so I added a validation function to colvarscript to detect that and print a helpful error message. |
cf9ec7c to
ad7df73
Compare
e6f7cfe to
46122d2
Compare
|
I think the last issue in Gromacs is fixed. Note that at present, in shared-memory settings, only one thread has a pointer to the colvarmodule object, but in principle, it could be broadcast or made static so all threads can access it if that was useful. |
|
Since this is very conflict-prone, I propose to rebase only when ready to merge. |
giacomofiorin
left a comment
There was a problem hiding this comment.
I haven't looked at the entire diff, which is large, but everything I have seen looks okay. Basically, every class now needs an extra parameter, but this is a necessary evil to remove the static colvarmodule pointer.
Another necessary evil are the "*_static" functions, which would have to be removed in the next iteration.
387dd11 to
4cc0ef3
Compare
Agreed! I realized that completing this job would be too far-reaching for a single PR, as several class hierarchies would have had to be reworked. For the classes that I didn't want to overhaul right now, I added these functions that behave just like in the current master branch, but are clearly named as using the deprecated coding pattern. This way we can move forward with the rest of development and take the time to finish the transition. |
469aec1 to
06ab938
Compare
for which there is no short-term solution
Note: renaming .diff to .patch to avoid falling under .gitignore
about diamond inheritance
thread in Gromacs
257883f to
33932d0
Compare
In a first stage, just trying to keep functionality intact, removing all static member data from class
colvarmodule.First approach: make a colvarmodule pointer a member of colvarparse, because the big classes inherit from it.
Now a number of lightweight classes (in colvartypes) or sub-classes don't have access to the pointer yet. Alternatives are to extend them with a pointer, or remove the functionality that needs it (mostly
loganderrorcalls).EDIT: because this is so far-reaching, I am turning it into a partial implementation that can be merged in finite time, leaving some of the classes to be modified later.
Namely:
colvarbias classes have been handles thanks to virtual inheritance: only the colvarbias base class constructor sets the cvmodule pointer, as passed on by the final classes. Intermediate classes don't have to worry about it.
Final status: the remaining uses of the static pointer can be tracked by looking for calls to
cvm::main(). There are new functionslog_staticanderror_staticthat make use of the static pointer only if available, and have fallbacks if not. All of these can be phased out in later PRs.