Loading...
Searching...
No Matches
MPIPot Class Reference

#include <MPIPot.h>

Inheritance diagram for MPIPot:

Public Member Functions

 MPIPot (const eonc::Parameters &p)
 ~MPIPot ()
void initialize ()
void cleanMemory ()
void force (long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
bool isThreadSafe () const noexcept override
 MPI_COMM_WORLD sends are not safe from two threads unless the library was initialized with MPI_THREAD_MULTIPLE, which eOn does not require.
Public Member Functions inherited from eonc::Potential
 Potential (PotType a_ptype)
 Production default: construction-scope registry, else PotRegistry::get().
 Potential (PotType a_ptype, IPotRegistry &registry)
 Test seam: injected registry, no process-default get() counters.
 Potential (PotType a_ptype, const Parameters &p)
 Potential (const Parameters &a_params)
virtual ~Potential ()
void force (std::span< const double > positions, std::span< const int > atomicNrs, std::span< double > forces, double *energy, double *variance, std::span< const double > box)
 C++ call site: size-checked view over the raw FFI force().
virtual void setFixedMask (long nAtoms, const double *isFixed)
 Optional frozen-atom mask (nAtoms*3, 1.0 = fixed).
std::tuple< double, AtomMatrix > get_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual double finiteCutoff () const noexcept
 Finite interaction range in position length units.
virtual bool isSurrogate () const noexcept
 Whether this is a surrogate (GP) potential.
virtual bool requiresIsolatedMoleculeLayout () const noexcept
 True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
virtual unsigned layoutFlags () const noexcept
virtual bool isSharedInstanceThreadSafe () const noexcept
 Conservative gate for sharing one Potential instance across threads.
virtual bool needsPerImageInstance () const noexcept
 Whether NEB should create separate Potential instances per image for true parallel force evaluation.
virtual std::shared_ptr< Potential > clonePotential () const
 Independent instance that does not reload from disk.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual bool computesStress () const noexcept
 True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.
virtual Matrix3d cauchyStress () const
 Cauchy stress in eV/Angstrom^3.
virtual 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)
 Evaluate forces for N systems in a single call.
virtual 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)

Private Attributes

int potentialRank {0}
double poll_period {0.0}

Additional Inherited Members

Public Types inherited from eonc::Potential
enum class  PotLayout : unsigned { InProcess = 1u << 0 , NeedsWorkingDirectory = 1u << 1 , Subprocess = 1u << 2 }
 How the pot is executed. Combine with bitwise or. More...
Public Attributes inherited from eonc::Potential
std::atomic< size_t > forceCallCounter
Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

Definition at line 17 of file MPIPot.h.

Constructor & Destructor Documentation

◆ MPIPot()

MPIPot::MPIPot ( const eonc::Parameters & p)

Definition at line 35 of file MPIPot.cpp.

36 : eonc::Potential(p) {
39}
double poll_period
Definition MPIPot.h:32
int potentialRank
Definition MPIPot.h:31
const potential_options_t & potential_options() const

◆ ~MPIPot()

MPIPot::~MPIPot ( )

Definition at line 43 of file MPIPot.cpp.

43{ cleanMemory(); }
void cleanMemory()
Definition MPIPot.cpp:41

Member Function Documentation

◆ cleanMemory()

void MPIPot::cleanMemory ( )

Definition at line 41 of file MPIPot.cpp.

41{}

◆ force()

void MPIPot::force ( long N,
const double * R,
const int * atomicNrs,
double * F,
double * U,
double * variance,
const double * box )
overridevirtual

Implements eonc::Potential.

Definition at line 45 of file MPIPot.cpp.

46 {
47 if (variance != nullptr) {
48 *variance = 0.0;
49 }
50 // The peer receives the working directory as 1024 MPI_INT character
51 // codes, NUL terminated; the buffer element type must match MPI_INT.
52 std::array<int, 1024> icwd{};
53 const std::string cwd = std::filesystem::current_path().string();
54 if (cwd.size() >= icwd.size()) {
55 throw std::runtime_error(
56 "working directory path exceeds the MPI potential buffer");
57 }
58 for (std::size_t i = 0; i < cwd.size(); ++i) {
59 icwd[i] = static_cast<int>(static_cast<unsigned char>(cwd[i]));
60 }
61 int pbc = 1;
62 int failed = 0;
63 const int intn = static_cast<int>(N);
64 mpi_check(MPI_Send(&intn, 1, MPI_INT, potentialRank, 0, MPI_COMM_WORLD),
65 "MPI_Send atom count");
66 mpi_check(
67 MPI_Send(atomicNrs, intn, MPI_INT, potentialRank, 0, MPI_COMM_WORLD),
68 "MPI_Send atomic numbers");
69 mpi_check(MPI_Send(R, 3 * intn, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD),
70 "MPI_Send positions");
71 mpi_check(MPI_Send(box, 9, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD),
72 "MPI_Send cell");
73 mpi_check(MPI_Send(&pbc, 1, MPI_INT, potentialRank, 0, MPI_COMM_WORLD),
74 "MPI_Send pbc");
75 mpi_check(MPI_Send(icwd.data(), static_cast<int>(icwd.size()), MPI_INT,
76 potentialRank, 0, MPI_COMM_WORLD),
77 "MPI_Send working directory");
78
79 if (poll_period > 0.0) {
80 int eon_flag = 0;
81 // poll_period is in seconds (mpi_poll_period, default 0.25).
82 const auto usec = static_cast<std::uint64_t>(poll_period * 1000000.0);
83 mpi_check(MPI_Iprobe(potentialRank, 0, MPI_COMM_WORLD, &eon_flag,
84 MPI_STATUS_IGNORE),
85 "MPI_Iprobe");
86 while (!eon_flag) {
87 if (usec > 0) {
88 std::this_thread::sleep_for(std::chrono::microseconds(usec));
89 }
90 mpi_check(MPI_Iprobe(potentialRank, 0, MPI_COMM_WORLD, &eon_flag,
91 MPI_STATUS_IGNORE),
92 "MPI_Iprobe");
93 }
94 }
95
96 mpi_check(MPI_Recv(&failed, 1, MPI_INT, potentialRank, 0, MPI_COMM_WORLD,
97 MPI_STATUS_IGNORE),
98 "MPI_Recv status");
99 if (failed == 1) {
100 throw std::runtime_error("MPI potential reported a failed evaluation");
101 }
102
103 mpi_check(MPI_Recv(U, 1, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD,
104 MPI_STATUS_IGNORE),
105 "MPI_Recv energy");
106 mpi_check(MPI_Recv(F, 3 * intn, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD,
107 MPI_STATUS_IGNORE),
108 "MPI_Recv forces");
109}

◆ initialize()

void MPIPot::initialize ( )
inline

Definition at line 22 of file MPIPot.h.

22{};

◆ isThreadSafe()

bool MPIPot::isThreadSafe ( ) const
inlinenodiscardoverridevirtualnoexcept

MPI_COMM_WORLD sends are not safe from two threads unless the library was initialized with MPI_THREAD_MULTIPLE, which eOn does not require.

Reimplemented from eonc::Potential.

Definition at line 28 of file MPIPot.h.

28{ return false; }

Member Data Documentation

◆ poll_period

double MPIPot::poll_period {0.0}
private

Definition at line 32 of file MPIPot.h.

32{0.0};

◆ potentialRank

int MPIPot::potentialRank {0}
private

Definition at line 31 of file MPIPot.h.

31{0};

The documentation for this class was generated from the following files:
  • /home/runner/work/eOn/eOn/include/eon/potentials/MPIPot/MPIPot.h
  • /home/runner/work/eOn/eOn/client/potentials/MPIPot/MPIPot.cpp