ls1-MarDyn
ls1-MarDyn molecular dynamics code
MoleculeIdPool.h
1#ifndef SRC_MOLECULES_MOLECULEIDPOOL_H_
2#define SRC_MOLECULES_MOLECULEIDPOOL_H_
3
4#include "utils/mardyn_assert.h"
5
15 /* Local pool range is implemented by subdividing the total range of IDs into
16 * numProcesses blocks of poolSize / numProcesses size assigning them consecutively
17 * to the processes. */
18public:
19 MoleculeIdPool(unsigned long poolsize, int numProcs, int myProcRank) :
20 _poolSize(poolsize), _numProcesses(numProcs), _myProcRank(myProcRank), _moleculesFromThisProcess(0) {}
21
23 unsigned long getNewMoleculeId() {
24 mardyn_assert(_moleculesFromThisProcess < localIdRangeSize());
25 return myIDoffset() + _moleculesFromThisProcess++;
26 }
28 int getOwnerRank(unsigned long id) {
29 return id / localIdRangeSize();
30 }
32 unsigned long localIdRangeSize(){
33 static unsigned long localIdRangeSize = _poolSize / _numProcesses;
34 return localIdRangeSize;
35 }
36
37private:
38 unsigned long myIDoffset() {
39 static unsigned long myIDoffset = localIdRangeSize() * _myProcRank;
40 return myIDoffset;
41 }
42
43 unsigned long _poolSize;
44 int _numProcesses;
45 int _myProcRank;
46 unsigned long _moleculesFromThisProcess;
47};
48
49#endif // SRC_MOLECULES_MOLECULEIDPOOL_H_
The MoleculeIdPool manages molecule ID handling.
Definition: MoleculeIdPool.h:14
int getOwnerRank(unsigned long id)
Definition: MoleculeIdPool.h:28
unsigned long localIdRangeSize()
Definition: MoleculeIdPool.h:32
unsigned long getNewMoleculeId()
Definition: MoleculeIdPool.h:23