11 #if defined(NAMD_CUDA) && defined(NODEGROUP_FORCE_REGISTER) 13 void CudaGlobalMasterClient::initialize(
14 const std::vector<std::string>& arguments,
int deviceID, cudaStream_t stream) {
15 m_name = arguments[1];
16 m_device_id = deviceID;
17 const std::string msg =
"Creating CudaGlobalMasterClient " + m_name +
18 " on PE " + std::to_string(CkMyPe()) +
"\n";
28 CudaGlobalMasterClient::~CudaGlobalMasterClient() {
35 void CudaGlobalMasterClient::unsubscribe() {
36 auto master = m_master.lock();
38 master->removeClient(shared_from_this());
41 iout <<
iWARN <<
"Trying to remove client \"" << name()
42 <<
"\" which is not in the master";
46 void CudaGlobalMasterClient::subscribe(
47 std::shared_ptr<CudaGlobalMasterServer> master) {
48 auto tmp = m_master.lock();
53 master->addClient(shared_from_this());
57 std::string CudaGlobalMasterClient::updateFromTCLCommand(
const std::vector<std::string>& arguments) {
58 iout <<
iINFO <<
"Updating client " << name() <<
" with arguments:\n" <<
endi;
59 for (
size_t i = 0; i < arguments.size(); ++i) {
60 iout <<
iINFO <<
" arguments[" << i <<
"]: " << arguments[i] <<
'\n' <<
endi;
65 void CudaGlobalMasterClient::finishReductions(
bool doEnergy,
bool doVirial,
67 if (doEnergy && hasEnergy()) {
68 #ifdef NODEGROUP_FORCE_REGISTER 72 if (useDefaultExtForceAndVirial()) {
73 if (getRequestedAtoms().size() == getRequestedForcedAtoms().size()) {
79 cudaCheck(cudaMemsetAsync(m_d_ExtForce, 0,
sizeof(
Vector), getStream()));
80 clientVirialAndExtForce(this->getPositions(), this->getAppliedForces(),
81 this->getRequestedAtoms().size(), m_d_ExtVirial,
82 m_d_ExtForce, getStream());
85 copy_DtoH(m_d_ExtVirial, &h_virial, 1, getStream());
86 copy_DtoH(m_d_ExtForce, &extForce, 1, getStream());
87 cudaCheck(cudaStreamSynchronize(getStream()));
88 #ifdef NODEGROUP_FORCE_REGISTER 96 iout <<
iWARN <<
"Virial is not available for CudaGlobalMasterClient \"" 97 << name() <<
"\" since the number of atoms requested (" 98 << std::to_string(getRequestedAtoms().size())
99 <<
") does not match the number of applied forces (" 100 << std::to_string(getRequestedForcedAtoms().size()) <<
")\n";
104 #ifdef NODEGROUP_FORCE_REGISTER 115 SimParameters* CudaGlobalMasterClient::getSimParameters()
const {
119 Molecule* CudaGlobalMasterClient::getMolecule()
const {
123 const Controller* CudaGlobalMasterClient::getController()
const {
127 bool CudaGlobalMasterClient::replica_enabled()
const {
128 #if CMK_HAS_PARTITION 135 int CudaGlobalMasterClient::replica_index()
const {
136 return CmiMyPartition();
139 int CudaGlobalMasterClient::num_replicas()
const {
140 return CmiNumPartitions();
143 void replica_comm_barrier() {
147 int replica_comm_recv(
char* msg_data,
int buf_len,
int src_rep) {
150 CmiAssert(recvMsg != NULL);
151 int retval = recvMsg->
size;
152 if (buf_len >= retval) {
153 memcpy(msg_data,recvMsg->
data,retval);
161 int replica_comm_send(
char* msg_data,
int msg_len,
int dest_rep) {
169 NAMD_die(
"CudaGlobalMasterClient requires NAMD to be built with CUDA");
172 #endif // defined(NAMD_CUDA) && defined(NODEGROUP_FORCE_REGISTER)
const Controller & getController() const
std::ostream & iINFO(std::ostream &s)
#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)
ReductionValue & item(int index)
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)
CudaGlobalMasterClient(std::string name, int deviceID)