17 #if (defined(NAMD_CUDA) || defined(NAMD_HIP)) && defined(NODEGROUP_FORCE_REGISTER) 19 void CudaGlobalMasterClient::initialize(
20 const std::vector<std::string>& arguments,
int deviceID, cudaStream_t stream) {
21 m_name = arguments[1];
22 m_device_id = deviceID;
23 const std::string msg =
"Creating CudaGlobalMasterClient " + m_name +
24 " on PE " + std::to_string(CkMyPe()) +
"\n";
36 CudaGlobalMasterClient::~CudaGlobalMasterClient() {
47 void CudaGlobalMasterClient::unsubscribe() {
48 auto master = m_master.lock();
50 master->removeClient(shared_from_this());
53 iout <<
iWARN <<
"Trying to remove client \"" << name()
54 <<
"\" which is not in the master";
58 void CudaGlobalMasterClient::subscribe(
59 std::shared_ptr<CudaGlobalMasterServer> master) {
60 auto tmp = m_master.lock();
65 master->addClient(shared_from_this());
69 int CudaGlobalMasterClient::updateFromTCLCommand(
const std::vector<std::string>& arguments) {
70 iout <<
iINFO <<
"Updating client " << name() <<
" with arguments:\n" <<
endi;
71 for (
size_t i = 0; i < arguments.size(); ++i) {
72 iout <<
iINFO <<
" arguments[" << i <<
"]: " << arguments[i] <<
'\n' <<
endi;
81 std::string CudaGlobalMasterClient::getTCLUpdateResult() {
85 bool CudaGlobalMasterClient::tclAvailable()
const {
93 void CudaGlobalMasterClient::finishReductions(
bool doEnergy,
bool doVirial,
95 if (doEnergy && hasEnergy()) {
98 if (useDefaultExtForceAndVirial()) {
99 if (getRequestedAtoms().size() == getRequestedForcedAtoms().size()) {
105 cudaCheck(cudaMemsetAsync(m_d_ExtForce, 0,
sizeof(
Vector), getStream()));
106 clientVirialAndExtForce(this->getPositions(), this->getAppliedForces(),
107 this->getRequestedAtoms().size(), m_d_ExtVirial,
108 m_d_ExtForce, getStream());
109 copy_DtoH(m_d_ExtVirial, m_h_virial, 1, getStream());
110 copy_DtoH(m_d_ExtForce, m_h_ExtForce, 1, getStream());
111 cudaCheck(cudaStreamSynchronize(getStream()));
118 iout <<
iWARN <<
"Virial is not available for CudaGlobalMasterClient \"" 119 << name() <<
"\" since the number of atoms requested (" 120 << std::to_string(getRequestedAtoms().size())
121 <<
") does not match the number of applied forces (" 122 << std::to_string(getRequestedForcedAtoms().size()) <<
")\n";
135 SimParameters* CudaGlobalMasterClient::getSimParameters()
const {
139 Molecule* CudaGlobalMasterClient::getMolecule()
const {
144 const Controller* CudaGlobalMasterClient::getController()
const {
148 ScriptTcl* CudaGlobalMasterClient::getScript() {
156 bool CudaGlobalMasterClient::replica_enabled()
const {
157 #if CMK_HAS_PARTITION 164 int CudaGlobalMasterClient::replica_index()
const {
165 return CmiMyPartition();
168 int CudaGlobalMasterClient::num_replicas()
const {
169 return CmiNumPartitions();
172 void replica_comm_barrier() {
176 int replica_comm_recv(
char* msg_data,
int buf_len,
int src_rep) {
179 CmiAssert(recvMsg != NULL);
180 int retval = recvMsg->
size;
181 if (buf_len >= retval) {
182 memcpy(msg_data,recvMsg->
data,retval);
190 int replica_comm_send(
char* msg_data,
int msg_len,
int dest_rep) {
197 CudaGlobalMasterClient::CudaGlobalMasterClient() {
198 NAMD_die(
"CudaGlobalMasterClient requires NAMD to be built with CUDA");
201 #endif // (defined(NAMD_CUDA) || defined(NAMD_HIP)) && defined(NODEGROUP_FORCE_REGISTER)
const Controller & getController() const
std::ostream & iINFO(std::ostream &s)
void deallocate_host(T **pp)
#define ADD_TENSOR_OBJECT(R, RL, D)
SimParameters * simParameters
void deallocate_device(T **pp)
void allocate_device(T **pp, const size_t len)
void replica_send(const char *sndbuf, int sendcount, int destPart, int destPE)
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
Molecule stores the structural information for the system.
void replica_recv(DataMessage **precvMsg, int srcPart, int srcPE)
void allocate_host(T **pp, const size_t len)
void NAMD_die(const char *err_msg)
void copy_DtoH(const T *d_array, T *h_array, const size_t array_len, cudaStream_t stream=0)
#define ADD_VECTOR_OBJECT(R, RL, D)