Loading...
Searching...
No Matches
RgpotPot.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#pragma once
13
15#include "eon/Potential.h"
17#include <cstdint>
18#include <memory>
19#include <string>
20
21class RGPotEngine;
22
28class RgpotPot final : public eonc::Potential {
29public:
30 explicit RgpotPot(const eonc::Parameters &p);
31 ~RgpotPot() override;
32
33 RgpotPot(const RgpotPot &) = delete;
34 RgpotPot &operator=(const RgpotPot &) = delete;
35
36 void force(long N, const double *R, const int *atomicNrs, double *F,
37 double *U, double *variance, const double *box) override;
38
39 [[nodiscard]] bool isThreadSafe() const noexcept override { return false; }
40
46 [[nodiscard]] bool supportsBatchEvaluation() const noexcept override;
47 void forceBatch(long nSystems, long nAtoms, const double *const *positions,
48 const int *const *atomicNrs, double *const *forces,
49 double *energies, double *variances,
50 const double *const *boxes) override;
54 void forceBatchOwned(long nSystems, long nAtoms,
55 const double *const *positions,
56 const int *const *atomicNrs, double *const *forces,
57 double *energies, double *variances,
58 const double *const *boxes, const long *owners) override;
60 [[nodiscard]] bool requiresIsolatedMoleculeLayout() const noexcept override {
61 return backend_ == "nwchemc" || isolatedMolecule_;
62 }
63 [[nodiscard]] const std::string &backend() const noexcept { return backend_; }
64 [[nodiscard]] bool engineAvailable() const;
67 [[nodiscard]] const eonc::CalculatorGroupUse &groupUse() const noexcept {
68 return use_;
69 }
70
71private:
72 // Under mpirun (an MPI build of rgpot with cpmdc) only world rank 0 runs
73 // eOn. It broadcasts each force request; the other ranks serve requests
74 // from the constructor until the driver sends a stop, then exit.
75 [[noreturn]] void serveWorker();
76 void computeSingle(long N, const double *R, const int *atomicNrs, double *F,
77 double *U, const double *box, int group);
78 void computeBatch(long nSystems, long nAtoms, const double *const *positions,
79 const int *const *atomicNrs, double *const *forces,
80 double *energies, const double *const *boxes,
81 const std::int64_t *owners, const std::int64_t *route);
82 void sendStop();
83 void stopAndDrop();
85 // Collective over every rank: each group's first rank shares its busy
86 // seconds and system count.
87 void exchangeGroupUse();
88 bool evaluate(long N, const double *R, const int *atomicNrs, double *F,
89 double *U, const double *box, std::string &error);
90
91 std::unique_ptr<RGPotEngine> impl_;
92 std::string backend_;
93 bool isolatedMolecule_{false};
94 bool driver_{true};
95 bool stopped_{false};
96 bool dropped_{false};
97 bool acked_{false};
98 // This rank's seconds inside engine calls and the systems it evaluated.
99 double busy_{0.0};
100 double systemsDone_{0.0};
102 // Driver only: which group evaluates which system.
103 std::unique_ptr<eonc::GroupSchedule> schedule_;
104};
Opaque rgpot-backed engine (nwchemc / cpmdc / metatomic / uma / xtb).
Definition RGPotEngine.h:57
RgpotPot(const RgpotPot &)=delete
RgpotPot(const eonc::Parameters &p)
Definition RgpotPot.cpp:19
const eonc::CalculatorGroupUse & groupUse() const noexcept
Calculator-group accounting on the driver.
Definition RgpotPot.h:67
bool engineAvailable() const
Definition RgpotPot.cpp:139
bool requiresIsolatedMoleculeLayout() const noexcept override
Molecular tasks retain Cartesian coordinates across storage-cell faces.
Definition RgpotPot.h:60
std::string backend_
Definition RgpotPot.h:92
std::unique_ptr< eonc::GroupSchedule > schedule_
Definition RgpotPot.h:103
std::unique_ptr< RGPotEngine > impl_
Definition RgpotPot.h:91
void forceBatchOwned(long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes, const long *owners) override
owners[j] is system j's identity (a NEB image, a ring bead): it names the orbitals the engine starts ...
Definition RgpotPot.cpp:436
double busy_
Definition RgpotPot.h:99
bool isolatedMolecule_
Definition RgpotPot.h:93
void forceBatch(long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes) override
Definition RgpotPot.cpp:427
bool stopped_
Definition RgpotPot.h:95
bool dropped_
Definition RgpotPot.h:96
void exchangeGroupUse()
Definition RgpotPot.cpp:163
const std::string & backend() const noexcept
Definition RgpotPot.h:63
bool acked_
Definition RgpotPot.h:97
double systemsDone_
Definition RgpotPot.h:100
bool isThreadSafe() const noexcept override
Whether this potential's force() can be called from multiple threads on the SAME instance.
Definition RgpotPot.h:39
bool driver_
Definition RgpotPot.h:94
~RgpotPot() override
Definition RgpotPot.cpp:129
RgpotPot & operator=(const RgpotPot &)=delete
void stopAndDrop()
Definition RgpotPot.cpp:177
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
Definition RgpotPot.cpp:385
bool evaluate(long N, const double *R, const int *atomicNrs, double *F, double *U, const double *box, std::string &error)
Definition RgpotPot.cpp:255
void computeBatch(long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, const double *const *boxes, const std::int64_t *owners, const std::int64_t *route)
Definition RgpotPot.cpp:282
void serveWorker()
Definition RgpotPot.cpp:322
bool supportsBatchEvaluation() const noexcept override
With cpmdc calculator groups ([RgpotPot] ranks_per_image), a batch is spread over the groups by eonc:...
Definition RgpotPot.cpp:419
eonc::CalculatorGroupUse use_
Definition RgpotPot.h:101
void sendStop()
Definition RgpotPot.cpp:153
void releaseWorkersAtExit()
Definition RgpotPot.cpp:204
void computeSingle(long N, const double *R, const int *atomicNrs, double *F, double *U, const double *box, int group)
Definition RgpotPot.cpp:266
How a job used its calculator groups: the seconds each group spent inside engine calls,...