NAMD
CudaGlobalMasterClient.h
Go to the documentation of this file.
1 #ifndef CUDAGLOBALMASTERCLIENT_H
2 #define CUDAGLOBALMASTERCLIENT_H
3 
4 #include "CudaUtils.h"
5 #include "NamdTypes.h"
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
11 class Lattice;
12 class NodeReduction;
13 class Molecule;
14 class SimParameters;
15 class Controller;
16 
22  : public std::enable_shared_from_this<CudaGlobalMasterClient> {
23 #if defined(NAMD_CUDA) && defined(NODEGROUP_FORCE_REGISTER)
24 public:
33  virtual ~CudaGlobalMasterClient();
40  virtual void initialize(
41  const std::vector<std::string>& arguments,
42  int deviceID, cudaStream_t stream);
47  virtual void setStep(int64_t step) { m_step = step; }
52  void setMaster(std::shared_ptr<CudaGlobalMasterServer> master) {
53  m_master = master;
54  }
59  void subscribe(std::shared_ptr<CudaGlobalMasterServer> master);
63  void unsubscribe();
67  std::string name() { return m_name; }
71  virtual void calculate() {}
78  virtual bool requestedAtomsChanged() = 0;
85  virtual bool requestedTotalForcesAtomsChanged() = 0;
92  virtual bool requestedForcedAtomsChanged() = 0;
100  virtual bool requestUpdateAtomPositions() = 0;
108  virtual bool requestUpdateAtomTotalForces() = 0;
116  virtual bool requestUpdateForcedAtoms() = 0;
125  virtual bool requestUpdateMasses() = 0;
135  virtual bool requestUpdateCharges() = 0;
140  virtual bool requestUpdateLattice() = 0;
150  virtual bool requestUpdateTransforms() { return false; }
159  virtual bool requestUpdateVelocities() { return false; }
175  virtual double *getAppliedForces() const = 0;
191  virtual double *getPositions() = 0;
207  virtual float *getMasses() = 0;
223  virtual float *getCharges() = 0;
239  virtual double *getTotalForces() = 0;
254  virtual double *getLattice() = 0;
272  virtual char *getTransforms() { return nullptr; }
288  virtual double *getVelocities() { return nullptr; }
294  virtual std::string updateFromTCLCommand(const std::vector<std::string>& arguments);
306  void finishReductions(bool doEnergy, bool doVirial, NodeReduction *reduction);
311  virtual const std::vector<AtomID> &getRequestedAtoms() const = 0;
315  virtual const std::vector<AtomID> &getRequestedTotalForcesAtoms() const = 0;
320  virtual const std::vector<AtomID> &getRequestedForcedAtoms() const = 0;
321 
322 protected:
326  virtual cudaStream_t getStream() = 0;
330  virtual bool hasEnergy() const { return true; }
335  virtual double getEnergy() const { return 0; }
339  virtual bool hasVirial() const { return false; }
344  virtual cudaTensor getVirial() const { return cudaTensor{0}; };
352  virtual bool hasExtForce() const { return false; }
357  virtual Vector getExtForce() const { return Vector{0}; };
363  virtual bool useDefaultExtForceAndVirial() const { return true; };
367  SimParameters* getSimParameters() const;
371  Molecule* getMolecule() const;
375  const Controller* getController() const;
376 
377  // APIs for future use for replica exchange
378  bool replica_enabled() const;
379  int replica_index() const;
380  int num_replicas() const;
381  void replica_comm_barrier();
382  int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
383  int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
384 
385 protected:
386  std::weak_ptr<CudaGlobalMasterServer> m_master;
387  std::string m_name;
388  int m_device_id;
389  int64_t m_step;
390  cudaTensor *m_d_ExtVirial;
391  Vector *m_d_ExtForce;
392 #else
393 public:
394  CudaGlobalMasterClient(std::string name, int deviceID);
395 #endif // defined(NAMD_CUDA) && defined(NODEGROUP_FORCE_REGISTER)
396 };
397 
398 #endif // CUDAGLOBALMASTERCLIENT_H
Definition: Vector.h:72
A class for performing calculations on specific atoms selected by atom serial numbers.
Molecule stores the structural information for the system.
Definition: Molecule.h:175
CudaGlobalMasterClient(std::string name, int deviceID)
A class for copying atom information from SequencerCUDA to CudaGlobalMasterClient.