Loading...
Searching...
No Matches
eonc::GroupSchedule Class Reference

Which calculator group evaluates which system. More...

#include <GroupSchedule.h>

Public Member Functions

 GroupSchedule (int groups)
int groups () const noexcept
int defaultHome (std::int64_t key, long position) const
 The home of a key never seen: key mod G for a key of zero or more, the batch position mod G otherwise.
std::vector< int > assign (const std::vector< std::int64_t > &keys)
 Groups for a batch of systems with these keys.
void record (std::int64_t key, const double *positions, long n3, const double *cell=nullptr)
 Remember the geometry a key was last evaluated at.
int nearest (const double *positions, long n3, const double *cell=nullptr) const
 The group for a single request: the home of the recorded geometry nearest to positions (root-mean-square over coordinates), group 0 when nothing of this size is recorded.
void settle (std::int64_t key, int group)
 A single request's group becomes the home of the single-request key.

Private Member Functions

int homeOf (std::int64_t key, long position) const

Private Attributes

int groups_
std::map< std::int64_t, int > home_
std::map< std::int64_t, std::vector< double > > last_
std::map< std::int64_t, std::vector< double > > cells_

Detailed Description

Which calculator group evaluates which system.

A group keeps the converged orbitals of every system it evaluated, under the system's key (a NEB image, a ring bead). Sending a key back to the group that holds its orbitals is what makes the next SCF warm, so a key stays on its home group. A batch caps each group at ceil(M / G) systems: a key whose home group is full moves to the least-loaded group, which becomes its home, because one extra evaluation on a full group costs a whole SCF while a move costs the difference between a warm and a cooler start. A single request goes to the group that last evaluated the geometry nearest to it.

Every decision is made on the driver and sent to the other ranks, so the state here lives on the driver only.

Definition at line 39 of file GroupSchedule.h.

Constructor & Destructor Documentation

◆ GroupSchedule()

eonc::GroupSchedule::GroupSchedule ( int groups)
inlineexplicit

Definition at line 41 of file GroupSchedule.h.

41: groups_{std::max(groups, 1)} {}
int groups() const noexcept

Member Function Documentation

◆ assign()

std::vector< int > eonc::GroupSchedule::assign ( const std::vector< std::int64_t > & keys)
inlinenodiscard

Groups for a batch of systems with these keys.

Definition at line 53 of file GroupSchedule.h.

53 {
54 const long m = static_cast<long>(keys.size());
55 const long cap = (m + groups_ - 1) / groups_;
56 std::vector<long> load(static_cast<size_t>(groups_), 0);
57 std::vector<int> route(static_cast<size_t>(m), -1);
58 for (long j = 0; j < m; ++j) {
59 const int home = homeOf(keys[static_cast<size_t>(j)], j);
60 if (load[static_cast<size_t>(home)] < cap) {
61 route[static_cast<size_t>(j)] = home;
62 ++load[static_cast<size_t>(home)];
63 }
64 }
65 for (long j = 0; j < m; ++j) {
66 if (route[static_cast<size_t>(j)] >= 0)
67 continue;
68 const auto least = std::min_element(load.begin(), load.end());
69 const int g = static_cast<int>(least - load.begin());
70 route[static_cast<size_t>(j)] = g;
71 ++*least;
72 }
73 for (long j = 0; j < m; ++j)
74 home_[keys[static_cast<size_t>(j)]] = route[static_cast<size_t>(j)];
75 return route;
76 }
int homeOf(std::int64_t key, long position) const
std::map< std::int64_t, int > home_

◆ defaultHome()

int eonc::GroupSchedule::defaultHome ( std::int64_t key,
long position ) const
inlinenodiscard

The home of a key never seen: key mod G for a key of zero or more, the batch position mod G otherwise.

Definition at line 47 of file GroupSchedule.h.

47 {
48 const std::int64_t base = key >= 0 ? key : position;
49 return static_cast<int>(((base % groups_) + groups_) % groups_);
50 }

◆ groups()

int eonc::GroupSchedule::groups ( ) const
inlinenodiscardnoexcept

Definition at line 43 of file GroupSchedule.h.

43{ return groups_; }

◆ homeOf()

int eonc::GroupSchedule::homeOf ( std::int64_t key,
long position ) const
inlinenodiscardprivate

Definition at line 128 of file GroupSchedule.h.

128 {
129 const auto it = home_.find(key);
130 return it != home_.end() ? it->second : defaultHome(key, position);
131 }
int defaultHome(std::int64_t key, long position) const
The home of a key never seen: key mod G for a key of zero or more, the batch position mod G otherwise...

◆ nearest()

int eonc::GroupSchedule::nearest ( const double * positions,
long n3,
const double * cell = nullptr ) const
inlinenodiscard

The group for a single request: the home of the recorded geometry nearest to positions (root-mean-square over coordinates), group 0 when nothing of this size is recorded.

Definition at line 92 of file GroupSchedule.h.

93 {
94 double best = std::numeric_limits<double>::infinity();
95 int group = 0;
96 for (const auto &[key, stored] : last_) {
97 if (static_cast<long>(stored.size()) != n3)
98 continue;
99 const auto recordedCell = cells_.find(key);
100 if (cell && recordedCell != cells_.end() &&
101 !std::equal(recordedCell->second.begin(), recordedCell->second.end(),
102 cell))
103 continue;
104 std::vector<double> differences(static_cast<size_t>(n3));
105 for (long i = 0; i < n3; ++i) {
106 differences[static_cast<size_t>(i)] =
107 stored[static_cast<size_t>(i)] - positions[i];
108 }
109 if (cell &&
110 std::any_of(cell, cell + 9, [](double x) { return x != 0.0; }))
111 pbc::closestDisplacements(differences.data(), differences.size(), cell);
112 double d2 = 0.0;
113 for (double d : differences)
114 d2 += d * d;
115 const auto home = home_.find(key);
116 if (d2 < best && home != home_.end()) {
117 best = d2;
118 group = home->second;
119 }
120 }
121 return group;
122 }
std::map< std::int64_t, std::vector< double > > cells_
std::map< std::int64_t, std::vector< double > > last_
void closestDisplacements(double *data, size_t coordinates, const double *rowMajorCell)

◆ record()

void eonc::GroupSchedule::record ( std::int64_t key,
const double * positions,
long n3,
const double * cell = nullptr )
inline

Remember the geometry a key was last evaluated at.

Definition at line 79 of file GroupSchedule.h.

80 {
81 auto &stored = last_[key];
82 stored.assign(positions, positions + n3);
83 if (cell)
84 cells_[key].assign(cell, cell + 9);
85 else
86 cells_.erase(key);
87 }

◆ settle()

void eonc::GroupSchedule::settle ( std::int64_t key,
int group )
inline

A single request's group becomes the home of the single-request key.

Definition at line 125 of file GroupSchedule.h.

125{ home_[key] = group; }

Member Data Documentation

◆ cells_

std::map<std::int64_t, std::vector<double> > eonc::GroupSchedule::cells_
private

Definition at line 136 of file GroupSchedule.h.

◆ groups_

int eonc::GroupSchedule::groups_
private

Definition at line 133 of file GroupSchedule.h.

◆ home_

std::map<std::int64_t, int> eonc::GroupSchedule::home_
private

Definition at line 134 of file GroupSchedule.h.

◆ last_

std::map<std::int64_t, std::vector<double> > eonc::GroupSchedule::last_
private

Definition at line 135 of file GroupSchedule.h.


The documentation for this class was generated from the following file: