eOn client
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
LAMMPSPot.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
// serves as an interface between LAMMPS potentials maintained by SANDIA
13
14
#pragma once
15
16
#include "
eon/Parameters.h
"
17
#include "
eon/Potential.h
"
18
19
#include <mutex>
20
21
class
LAMMPSPot
:
public
Potential
{
22
23
public
:
24
[[nodiscard]]
bool
needsPerImageInstance
() const noexcept
override
{
25
return
true
;
26
}
27
LAMMPSPot
(
const
Parameters
&p);
28
~LAMMPSPot
();
29
void
cleanMemory
();
30
void
force
(
long
N,
const
double
*R,
const
int
*atomicNrs,
double
*F,
31
double
*U,
double
*variance,
const
double
*box)
override
;
32
33
private
:
34
int
lammpsThr
{0};
35
#ifdef EONMPI
36
MPI_Comm mpiComm;
37
#endif
38
long
numberOfAtoms
{0};
39
double
oldBox
[9]{};
40
void
*
LAMMPSObj
{
nullptr
};
41
void
makeNewLAMMPS
(
long
N,
const
double
*R,
const
int
*atomicNrs,
42
const
double
*box);
43
bool
realunits
{
false
};
44
45
#if !defined(EONMPI) && !defined(IS_WINDOWS)
46
// Process-per-image evaluation. NEB drives intermediate images on separate
47
// std::threads; if each thread opened LAMMPS in this process they would all
48
// share one MPI_COMM_WORLD and their concurrent reduction collectives would
49
// collide (heap corruption / MPI_ERR_OP). Instead each LAMMPSPot forks a
50
// dedicated worker process that owns its LAMMPS instance, so every image runs
51
// in its own process with its own MPI_COMM_WORLD and true parallelism.
52
// Not available on Windows (no fork/pipe).
53
// Respawns allowed after a worker times out, dies, or reports an error.
54
// A single transient failure must not poison the job: every later
55
// evaluation would return the impassable wall, no minimisation could ever
56
// meet its force criterion, and the search would be discarded as a minimum
57
// that failed to converge. Respawning is safe now that the teardown is
58
// bounded rather than waiting on a wedged child forever. The budget is
59
// finite so a worker that cannot be revived still ends the search instead
60
// of looping.
61
int
workerRespawnsLeft
{3};
62
// Serialises the request/response exchange with the worker. eOn minimises
63
// the two endpoints of a saddle concurrently, and when both share this
64
// instance the two threads interleave writes and reads on the same pipe.
65
// The protocol is a bare byte stream with no framing, so an interleaved
66
// exchange is read as corrupt: the worker reports an evaluation error, the
67
// next send finds a closed pipe, and the worker dies, all within the first
68
// three force calls of the minimisation. Uncontended when instances really
69
// are per-image.
70
std::mutex
workerMutex
;
71
int
workerPid
{-1};
72
int
reqFd
{-1};
// parent writes requests here (child stdin side)
73
int
resFd
{-1};
// parent reads results here (child stdout side)
74
bool
workerSpawned
{
false
};
75
76
// Fork the worker child on first use; child enters runWorkerLoop().
77
void
ensureWorker
();
78
// Child main loop: read requests, evaluate, write results; never returns.
79
[[noreturn]]
void
runWorkerLoop
();
80
void
stopWorker
();
81
#endif
82
// In-process LAMMPS force evaluation (used directly on Windows/MPI, and
83
// inside the worker child on POSIX).
84
void
forceLocal
(
long
N,
const
double
*R,
const
int
*atomicNrs,
double
*F,
85
double
*U,
const
double
*box);
86
};
Parameters.h
Potential.h
LAMMPSPot::oldBox
double oldBox[9]
Definition
LAMMPSPot.h:39
LAMMPSPot::reqFd
int reqFd
Definition
LAMMPSPot.h:72
LAMMPSPot::workerPid
int workerPid
Definition
LAMMPSPot.h:71
LAMMPSPot::makeNewLAMMPS
void makeNewLAMMPS(long N, const double *R, const int *atomicNrs, const double *box)
Definition
LAMMPSPot.cpp:453
LAMMPSPot::LAMMPSPot
LAMMPSPot(const Parameters &p)
Definition
LAMMPSPot.cpp:40
LAMMPSPot::lammpsThr
int lammpsThr
Definition
LAMMPSPot.h:34
LAMMPSPot::~LAMMPSPot
~LAMMPSPot()
Definition
LAMMPSPot.cpp:61
LAMMPSPot::workerSpawned
bool workerSpawned
Definition
LAMMPSPot.h:74
LAMMPSPot::cleanMemory
void cleanMemory()
Definition
LAMMPSPot.cpp:63
LAMMPSPot::workerRespawnsLeft
int workerRespawnsLeft
Definition
LAMMPSPot.h:61
LAMMPSPot::realunits
bool realunits
Definition
LAMMPSPot.h:43
LAMMPSPot::stopWorker
void stopWorker()
Definition
LAMMPSPot.cpp:232
LAMMPSPot::LAMMPSObj
void * LAMMPSObj
Definition
LAMMPSPot.h:40
LAMMPSPot::needsPerImageInstance
bool needsPerImageInstance() const noexcept override
Whether NEB should create separate Potential instances per image for true parallel force evaluation.
Definition
LAMMPSPot.h:24
LAMMPSPot::ensureWorker
void ensureWorker()
Definition
LAMMPSPot.cpp:140
LAMMPSPot::runWorkerLoop
void runWorkerLoop()
Definition
LAMMPSPot.cpp:192
LAMMPSPot::numberOfAtoms
long numberOfAtoms
Definition
LAMMPSPot.h:38
LAMMPSPot::force
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
Definition
LAMMPSPot.cpp:273
LAMMPSPot::forceLocal
void forceLocal(long N, const double *R, const int *atomicNrs, double *F, double *U, const double *box)
Definition
LAMMPSPot.cpp:388
LAMMPSPot::workerMutex
std::mutex workerMutex
Definition
LAMMPSPot.h:70
LAMMPSPot::resFd
int resFd
Definition
LAMMPSPot.h:73
eonc::Parameters
Definition
Parameters.h:28
eonc::Potential::Potential
Potential(PotType a_ptype)
Definition
Potential.h:35
include
eon
potentials
LAMMPS
LAMMPSPot.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf