#include <DynamicList.h>
Public Member Functions | |
DynamicList () | |
Constructor. More... | |
void | activate (const unsigned ii) |
Make something active. More... | |
void | activateAll () |
Make everything in the list active. More... | |
void | addIndexToList (const T &ii) |
Add something to the active list. More... | |
void | clear () |
Clear the list. More... | |
void | completeUpdate () |
This can be called on once update is complete. More... | |
void | createIndexListFromVector (const std::vector< T > &myind) |
Create the list from a vector. More... | |
void | deactivate (const T &t) |
Make a particular element inactive. More... | |
void | deactivateAll () |
Make everything in the list inactive. More... | |
void | emptyActiveMembers () |
Empty the list of active members. More... | |
unsigned | fullSize () const |
Return the total number of elements in the list. More... | |
int | getIndexOfElement (const T &t) const |
Find the index of in the list which has value t. More... | |
unsigned | getNumberActive () const |
Return the number of elements that are currently active. More... | |
bool | isActive (const unsigned &) const |
Find out if a member is active. More... | |
void | mpi_gatherActiveMembers (Communicator &comm) |
Do updateActiveMembers for a loop that has been distributed over multiple nodes. More... | |
T | operator() (const unsigned &i) const |
An operator that returns the element from the full list (used in neighbour lists) More... | |
T | operator[] (const unsigned &i) const |
An operator that returns the element from the current active list. More... | |
void | putIndexInActiveArray (const unsigned &ii) |
This can be used for a fast version of updateActiveMembers in which only a subset of the indexes are checked. More... | |
std::vector< T > | retrieveActiveList () |
Retriee the list of active objects. More... | |
void | setupMPICommunication (Communicator &comm) |
Setup MPI communication if things are activated/deactivated on different nodes. More... | |
void | sortActiveList () |
This sorts the elements in the active list. More... | |
void | updateActiveMembers () |
Get the list of active members. More... | |
bool | updateComplete () const |
This tells one if an update has been completed. More... | |
Private Attributes | |
std::vector< unsigned > | active |
This is the list of active members. More... | |
std::vector< T > | all |
This is the list of all the relevant members. More... | |
bool | allWereActivated |
These are flags that are used internally to ensure that dynamic lists are being used properly. More... | |
bool | allWereDeactivated |
unsigned | nactive |
The current number of active members. More... | |
unsigned | nprocessors |
the number of processors the jobs in the Dynamic list are distributed across More... | |
std::vector< unsigned > | onoff |
This tells us what members of all are on/off at any given time. More... | |
unsigned | rank |
The rank of the node we are on. More... | |
Friends | |
template<typename U > | |
void | mpi_gatherActiveMembers (Communicator &, std::vector< DynamicList< U > > &) |
This gathers data split across nodes list of Dynamic lists. More... | |
A class for storing a list that changes which members are active as a function of time. It also contains friends method that allows you to link two dynamic lists so that you can request stuff from list2 in list1 A PLMD::DynamicList can be used to change what elements in a list should be looped over at any given time. This class is, for the most part, used in tandem with PLMD::NeighbourList. For complex reasons related to the PLMD::MultiColvar object the dynamic list class is separate from PLMD::NeighbourList. This is no bad thing though as there may be occasions where one needs to change the elements currently involved in a calculation using some non neighbour list based method. To be clear though PLMD::NeighbourList will look after everything connected with PLMD::DynamicList other than the initial setup of PLMD::DynamicList and the loops over the active elements of the list.
The essence of a dynamic list is as follows. Consider the following loop:
std::vector<something> aa; for(unsigned i=0;i<aa.size();++i){ aa[i].doSomething(); }
This takes all the members in aa and does something or other to them - simple. Now it may well be that the precise set of things from aa that you want to do in any given time or place is not always the same. We can thus use dynamic lists to control what particular things are done are done at a given time. That is to say we can use PLMD::DynamicList to specify a subset of things from aa to do at a given time. This is done by:
DynamicList list; std::vector<something> aa; unsigned kk; for(unsigned i=0;i<list.getNumberActive();++i){ kk=list[i]; aa[kk].doSomething(); }
where we somewhere set up the list and make some decisions (in PLMD::NeighbourList for example) as to what elements from aa are currently active.
Setting up a dynamic list is a matter of declaring it and passing a set of indices to it. For the example above with aa one can do this using:
DynamicList list; for(unsigned i=0;i<aa.size();++i) list.addIndexToList( i );
Doing this creates the list of all members.
To cycle over the full set of members in the list one should do:
for(unsigned i=0;i<list.fullSize();++i){ kk=list(i); aa[kk].doSomething(); }
If the DynamicList was set up as per the example above then this code is equivalent to:
for(unsigned i=0;i<aa.size();++i){ aa[i].doSomething(); }
The important business comes when we start activating and deactivating members. When we create a dynamic list none of the members are active for business. Hence, getNumberActive() returns 0. There are four routines that we can use to change this situation.
activateAll() | make all members active |
activate(i) | make the ith element of the list active (in the example above this mean we doSomething() for element i of aa) |
deactivateAll() | make all members inactive |
deactivate(i) | make th ith element of the list active (in the example above this mean we dont doSomething() for element i of aa) |
Once you have activated and deactivated members to your hearts content you can then update the dynamic list using PLMD::DynamicList::updateActiveMembers(). Once this is done you can loop over only the members you have specifically made active using:
DynamicList list; for(unsigned i=0;i<list.getNumberActive();++i){ kk=list[i]; aa[kk].doSomething(); }
as was described above.
If your loop is distributed over processesors you can still use dynamic lists to activate and deactivate members. When running with mpi however you must call PLMD::DynamicList::setupMPICommunication during initialization. To gather the members that have been activated/deactivated during the running of all the processes on all the nodes you must call PLMD::DynamicList::mpi_gatherActiveMembers in place of PLMD::DynamicList::updateActiveMembers.
When using dynamic_lists we strongly recommend that you first compile without the -DNDEBUG flag. When this flag is not present many checks are performed inside the dynamic list class, which will help you ensure that the dynamic list is used correctly.
|
inline |
Constructor.
void PLMD::DynamicList< T >::activate | ( | const unsigned | ii | ) |
Make something active.
void PLMD::DynamicList< T >::activateAll |
Make everything in the list active.
void PLMD::DynamicList< T >::addIndexToList | ( | const T & | ii | ) |
Add something to the active list.
void PLMD::DynamicList< T >::clear |
Clear the list.
void PLMD::DynamicList< T >::completeUpdate |
This can be called on once update is complete.
void PLMD::DynamicList< T >::createIndexListFromVector | ( | const std::vector< T > & | myind | ) |
Create the list from a vector.
void PLMD::DynamicList< T >::deactivate | ( | const T & | t | ) |
Make a particular element inactive.
void PLMD::DynamicList< T >::deactivateAll |
Make everything in the list inactive.
void PLMD::DynamicList< T >::emptyActiveMembers |
Empty the list of active members.
unsigned PLMD::DynamicList< T >::fullSize |
Return the total number of elements in the list.
int PLMD::DynamicList< T >::getIndexOfElement | ( | const T & | t | ) | const |
Find the index of in the list which has value t.
unsigned PLMD::DynamicList< T >::getNumberActive |
Return the number of elements that are currently active.
bool PLMD::DynamicList< T >::isActive | ( | const unsigned & | i | ) | const |
Find out if a member is active.
void PLMD::DynamicList< T >::mpi_gatherActiveMembers | ( | Communicator & | comm | ) |
Do updateActiveMembers for a loop that has been distributed over multiple nodes.
|
inline |
An operator that returns the element from the full list (used in neighbour lists)
|
inline |
An operator that returns the element from the current active list.
void PLMD::DynamicList< T >::putIndexInActiveArray | ( | const unsigned & | ii | ) |
This can be used for a fast version of updateActiveMembers in which only a subset of the indexes are checked.
std::vector< T > PLMD::DynamicList< T >::retrieveActiveList |
Retriee the list of active objects.
void PLMD::DynamicList< T >::setupMPICommunication | ( | Communicator & | comm | ) |
Setup MPI communication if things are activated/deactivated on different nodes.
void PLMD::DynamicList< T >::sortActiveList |
This sorts the elements in the active list.
void PLMD::DynamicList< T >::updateActiveMembers |
Get the list of active members.
bool PLMD::DynamicList< T >::updateComplete |
This tells one if an update has been completed.
|
friend |
This gathers data split across nodes list of Dynamic lists.
|
private |
This is the list of active members.
|
private |
This is the list of all the relevant members.
|
private |
These are flags that are used internally to ensure that dynamic lists are being used properly.
|
private |
|
private |
The current number of active members.
|
private |
the number of processors the jobs in the Dynamic list are distributed across
|
private |
This tells us what members of all are on/off at any given time.
|
private |
The rank of the node we are on.
Hosted by GitHub | 1.8.17 |