NAMD
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
GlobalMasterIMD Class Reference

#include <GlobalMasterIMD.h>

Inheritance diagram for GlobalMasterIMD:
GlobalMaster

Public Member Functions

 GlobalMasterIMD ()
 
 ~GlobalMasterIMD ()
 
void send_energies (IMDEnergies *)
 
void send_fcoords (int, FloatVector *)
 
void send_velocities (int, FloatVector *)
 
void send_forces (int, FloatVector *)
 
void send_box (IMDBox *)
 
void send_time (IMDTime *)
 
- Public Member Functions inherited from GlobalMaster
void processData (AtomIDList::iterator a_i, AtomIDList::iterator a_e, PositionList::iterator p_i, PositionList::iterator g_i, PositionList::iterator g_e, BigRealList::iterator gm_i, BigRealList::iterator gm_e, ForceList::iterator gtf_i, ForceList::iterator gtf_e, IntList::iterator goi_i, IntList::iterator goi_e, BigRealList::iterator gov_i, BigRealList::iterator gov_e, AtomIDList::iterator last_atoms_forced_i, AtomIDList::iterator last_atoms_forced_e, ForceList::iterator last_forces_i, AtomIDList::iterator, AtomIDList::iterator, ForceList::iterator)
 
bool changedAtoms ()
 
const AtomIDListrequestedAtoms ()
 
bool changedForces ()
 
const AtomIDListforcedAtoms ()
 
const ForceListappliedForces ()
 
bool changedGroups ()
 
const ResizeArray< AtomIDList > & requestedGroups ()
 
const ForceListgroupForces ()
 
bool changedGridObjs ()
 
const IntListrequestedGridObjs ()
 
const BigRealListgridObjForces ()
 
bool requestedTotalForces ()
 
void clearChanged ()
 
virtual ~GlobalMaster ()
 
void check () const
 
void setLattice (const Lattice *lat)
 

Protected Member Functions

virtual void calculate ()
 
void imd_connection ()
 
void get_vmd_forces ()
 
- Protected Member Functions inherited from GlobalMaster
 GlobalMaster ()
 
AtomIDListmodifyRequestedAtoms ()
 
AtomIDListmodifyForcedAtoms ()
 
ForceListmodifyAppliedForces ()
 
ResizeArray< AtomIDList > & modifyRequestedGroups ()
 
ForceListmodifyGroupForces ()
 
IntListmodifyRequestedGridObjects ()
 
BigRealListmodifyGridObjForces ()
 
AtomIDList::const_iterator getAtomIdBegin ()
 
AtomIDList::const_iterator getAtomIdEnd ()
 
PositionList::const_iterator getAtomPositionBegin ()
 
PositionList::const_iterator getGroupPositionBegin ()
 
PositionList::const_iterator getGroupPositionEnd ()
 
ForceList::const_iterator getGroupTotalForceBegin ()
 
ForceList::const_iterator getGroupTotalForceEnd ()
 
IntList::const_iterator getGridObjIndexBegin ()
 
IntList::const_iterator getGridObjIndexEnd ()
 
BigRealList::const_iterator getGridObjValueBegin ()
 
BigRealList::const_iterator getGridObjValueEnd ()
 
AtomIDList::const_iterator getLastAtomsForcedBegin ()
 
AtomIDList::const_iterator getLastAtomsForcedEnd ()
 
ForceList::const_iterator getLastForcesBegin ()
 
AtomIDList::const_iterator getForceIdBegin ()
 
AtomIDList::const_iterator getForceIdEnd ()
 
ForceList::const_iterator getTotalForce ()
 
void requestTotalForce (bool yesno=true)
 
BigRealList::const_iterator getGroupMassBegin ()
 
BigRealList::const_iterator getGroupMassEnd ()
 
void addReductionEnergy (int reductionTag, BigReal energy)
 
SubmitReductiongetCurrentReduction ()
 
void submitReduction ()
 

Protected Attributes

int IMDversion
 
int IMDwait
 
int IMDignore
 
int IMDignoreForces
 
IMDSessionInfo IMDsendsettings
 
void * sock
 
ResizeArray< void * > clients
 
float * coordtmp
 
int coordtmpsize
 
float * veltmp
 
int veltmpsize
 
float * forcetmp
 
int forcetmpsize
 
int IMDv3TimeoutSeconds
 
- Protected Attributes inherited from GlobalMaster
bool totalForceRequested
 
const Latticelattice
 
AtomIDList::iterator atomIdBegin
 
AtomIDList::iterator atomIdEnd
 
PositionList::iterator atomPositionBegin
 
PositionList::iterator groupPositionBegin
 
PositionList::iterator groupPositionEnd
 
BigRealList::iterator groupMassBegin
 
BigRealList::iterator groupMassEnd
 
ForceList::iterator groupTotalForceBegin
 
ForceList::iterator groupTotalForceEnd
 
IntList::iterator gridObjIndexBegin
 
IntList::iterator gridObjIndexEnd
 
BigRealList::iterator gridObjValueBegin
 
BigRealList::iterator gridObjValueEnd
 
AtomIDList::iterator lastAtomsForcedBegin
 
ForceList::iterator lastForcesBegin
 
AtomIDList::iterator lastAtomsForcedEnd
 
AtomIDList::iterator forceIdBegin
 
AtomIDList::iterator forceIdEnd
 
ForceList::iterator totalForceBegin
 
bool reqAtomsChanged
 
AtomIDList reqAtoms
 
bool appForcesChanged
 
AtomIDList fAtoms
 
ForceList appForces
 
bool reqGroupsChanged
 
ResizeArray< AtomIDListreqGroups
 
ForceList grpForces
 
bool reqGridObjsChanged
 
IntList reqGridObjs
 
BigRealList gridobjForces
 
SubmitReductionreductionGpuResident
 
SubmitReductionreduction
 

Friends

class IMDOutput
 

Additional Inherited Members

- Public Attributes inherited from GlobalMaster
int step
 
int globalMasterStep
 
int old_num_groups_requested
 

Detailed Description

Definition at line 17 of file GlobalMasterIMD.h.

Constructor & Destructor Documentation

◆ GlobalMasterIMD()

GlobalMasterIMD::GlobalMasterIMD ( )
Note
In case of (IMDignore || IMDignoreForces), the GlobalMasterIMD object is not a client of GlobalMasterServer, and GlobalMasterIMD->calculate() will be only called from IMDOutput::gather_*, and the subsequent GlobalMaster::submitReduction() won't be called. Moreover, GlobalMasterIMD->calculate() is called in a multiple time stepping manner, so GlobalMaster::submitReduction() cannot be used in GlobalMasterIMD->calculate() in case of (IMDignore || IMDignoreForces). To workaround the issue, we have to delete the reduction object, which should be safe since GlobalMasterIMD doesn't use GlobalMaster::addReductionEnergy().

Definition at line 56 of file GlobalMasterIMD.C.

References coordtmp, coordtmpsize, DebugM, endi(), find_free_port(), forcetmp, forcetmpsize, iINFO(), Node::imd, IMDignore, SimParameters::IMDignore, IMDignoreForces, SimParameters::IMDignoreForces, SimParameters::IMDport, IMDsendsettings, SimParameters::IMDsendsettings, IMDv3TimeoutSeconds, IMDversion, SimParameters::IMDversion, IMDwait, SimParameters::IMDwait, iout, iWARN(), NAMD_die(), Node::Object(), GlobalMaster::reduction, GlobalMaster::reductionGpuResident, GlobalMaster::requestedGroups(), Node::simParameters, sock, IMDOutput::use_imd(), veltmp, veltmpsize, vmdsock_create(), vmdsock_destroy(), vmdsock_init(), and vmdsock_listen().

56  {
57  DebugM(3,"Constructing\n");
59  int port = simparams->IMDport;
60  IMDversion = simparams->IMDversion;
61  IMDwait = simparams->IMDwait;
62  IMDignore = simparams->IMDignore;
63  IMDignoreForces = simparams->IMDignoreForces;
64  IMDsendsettings = simparams->IMDsendsettings;
65  coordtmp = NULL;
66  coordtmpsize = 0;
67  veltmp = NULL;
68  veltmpsize = 0;
69  forcetmp = NULL;
70  forcetmpsize = 0;
71 
72  if ( vmdsock_init() ) {
73  NAMD_die("Unable to initialize socket interface for IMD.\n");
74  }
75  sock = vmdsock_create();
76  int newport = find_free_port(sock, port);
77  if (newport != port) {
78  iout << iWARN << "Interactive MD failed to bind to port "
79  << port << ".\n" << endi;
80  }
81  if (newport < 0) {
83  NAMD_die("Interactive MD failed to find free port.\n");
84  }
86  iout << iINFO << "Interactive MD listening on port "
87  << newport << ".\n" << endi;
88  DebugM(2,"Done constructing ("<<requestedGroups().size()<<" initial groups)\n");
89 
101  if (IMDignore || IMDignoreForces) {
102  if (reduction) {
103  delete reduction;
104  reduction = nullptr;
105  }
106 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
107  if (reductionGpuResident) {
108  delete reductionGpuResident;
109  reductionGpuResident = nullptr;
110  }
111 #endif
112  }
113  Node::Object()->imd->use_imd(this);
114 
115  IMDv3TimeoutSeconds = 60;
116 }
static Node * Object()
Definition: Node.h:86
void * vmdsock_create(void)
Definition: vmdsock.C:76
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
static int find_free_port(void *sock, int defport)
IMDOutput * imd
Definition: Node.h:186
SimParameters * simParameters
Definition: Node.h:181
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
const ResizeArray< AtomIDList > & requestedGroups()
Definition: GlobalMaster.C:190
int vmdsock_init(void)
Definition: vmdsock.C:52
SubmitReduction * reductionGpuResident
Definition: GlobalMaster.h:196
SubmitReduction * reduction
Definition: GlobalMaster.h:198
int vmdsock_listen(void *v)
Definition: vmdsock.C:123
void NAMD_die(const char *err_msg)
Definition: common.C:147
IMDSessionInfo IMDsendsettings
void vmdsock_destroy(void *v)
Definition: vmdsock.C:164
IMDSessionInfo IMDsendsettings
void use_imd(GlobalMasterIMD *)
Definition: IMDOutput.C:28

◆ ~GlobalMasterIMD()

GlobalMasterIMD::~GlobalMasterIMD ( )

Definition at line 118 of file GlobalMasterIMD.C.

References clients, coordtmp, forcetmp, ResizeArray< Elem >::size(), sock, veltmp, and vmdsock_destroy().

118  {
119  if (sock)
121  for (int i=0; i<clients.size(); i++)
123  if (coordtmp) delete [] coordtmp;
124  if (veltmp) delete[] veltmp;
125  if (forcetmp) delete[] forcetmp;
126 }
int size(void) const
Definition: ResizeArray.h:131
ResizeArray< void * > clients
void vmdsock_destroy(void *v)
Definition: vmdsock.C:164

Member Function Documentation

◆ calculate()

void GlobalMasterIMD::calculate ( )
protectedvirtual

Reimplemented from GlobalMaster.

Definition at line 179 of file GlobalMasterIMD.C.

References clients, DebugM, vmdforce::force, get_vmd_forces(), imd_connection(), IMDignore, IMDignoreForces, IMDv2, IMDversion, IMDwait, vmdforce::index, ResizeArray< Elem >::item(), GlobalMaster::modifyAppliedForces(), GlobalMaster::modifyForcedAtoms(), GlobalMaster::modifyGroupForces(), ResizeArray< Elem >::resize(), ResizeArray< Elem >::size(), and vmdforces.

Referenced by IMDOutput::gather_coordinates(), IMDOutput::gather_forces(), and IMDOutput::gather_velocities().

179  {
180  if ((IMDversion == IMDversion_t::IMDv2) ||
181  (IMDwait && !clients.size())) {
182  // Check for incoming connections
183  imd_connection();
184  }
185 
187  /* clear out the requested forces first! */
188  if (!IMDignore && !IMDignoreForces) {
192  }
193 
194  // Assume for now that the only thing we get from VMD is a set of forces.
195  // Later we'll want to look for and implement more sophisticated control
196  // parameters. ie have a specified protocol
197 
198  // Check/get new forces from VMD
199  get_vmd_forces();
200 
201  // Right now I don't check to see if any new forces were obtained.
202  // An optimization would be cache the results message. However, there
203  // would still be copying since it looks like the messages get deleted
204  // by the receiver.
205 
206  /* set our arrays to be big enough to hold all of the forces */
207  int num = vmdforces.size();
208 
209  DebugM(2,"Setting " << num << " forces.\n");
210 
211  if (!IMDignore && !IMDignoreForces) {
212  modifyForcedAtoms().resize(num);
214 
215  int i;
217  for ( i = 0; i < num; ++i, ++v_i) {
218  modifyForcedAtoms().item(i) = v_i->index;
219  modifyAppliedForces().item(i) = v_i->force;
220  }
221  }
222  }
223 }
ForceList & modifyAppliedForces()
Definition: GlobalMaster.C:203
Vector force
int size(void) const
Definition: ResizeArray.h:131
#define DebugM(x, y)
Definition: Debug.h:75
void resize(int i)
Definition: ResizeArray.h:84
AtomIDList & modifyForcedAtoms()
Definition: GlobalMaster.C:198
ForceList & modifyGroupForces()
Definition: GlobalMaster.C:208
Elem & item(int i)
Definition: ResizeArray.h:119
ResizeArray< void * > clients
static UniqueSortedArray< vmdforce > vmdforces
Definition: common.h:275

◆ get_vmd_forces()

void GlobalMasterIMD::get_vmd_forces ( )
protected

Definition at line 225 of file GlobalMasterIMD.C.

References clients, ResizeArray< Elem >::del(), endi(), vmdforce::force, iINFO(), Node::imd, imd_connection(), IMD_DISCONNECT, IMD_ENERGIES, IMD_FCOORDS, IMD_IOERROR, IMD_KILL, IMD_MDCOMM, IMD_PAUSE, imd_recv_energies(), imd_recv_fcoords(), imd_recv_header(), imd_recv_mdcomm(), IMD_RESUME, IMD_TRATE, IMD_WAIT, IMDignore, IMDignoreForces, IMDv2, IMDv3, IMDversion, IMDwait, SimParameters::IMDwait, vmdforce::index, iout, iWARN(), NAMD_quit(), Node::Object(), IMDOutput::set_transrate(), Node::simParameters, ResizeArray< Elem >::size(), vmdforces, vmdsock_destroy(), vmdsock_selread(), Vector::x, Vector::y, and Vector::z.

Referenced by calculate(), and IMDOutput::get_imd_packet().

225  {
226  IMDType type;
227  int32 length;
228  int32 *vmd_atoms;
229  float *vmd_forces;
230  int paused = 0;
231  int warned = 0;
232  vmdforce *vtest, vnew;
233 
234  // Loop through each socket one at a time. By doing this, rather than
235  // polling all sockets at once, NAMD only has to keep up with one IMD
236  // connection; if it tried to read from all of them, it could more easily
237  // fall behind and never finish draining all the sockets.
238  // It would be better to have a system where VMD couldn't DOS NAMD by
239  // spamming it with messages, but in practice NAMD is able to keep up with
240  // VMD's send rate.
241  for (int i_client=0; i_client<clients.size(); i_client++) {
242  void *clientsock = clients[i_client];
243  while (vmdsock_selread(clientsock,0) > 0 || paused) { // Drain the socket
244  type = imd_recv_header(clientsock, &length);
245  switch (type) {
246  case IMD_MDCOMM:
247  // Expect the msglength to give number of indicies, and the data
248  // message to consist of first the indicies, then the coordinates
249  // in xyz1 xyz2... format.
250  vmd_atoms = new int32[length];
251  vmd_forces = new float[3*length];
252  if (imd_recv_mdcomm(clientsock, length, vmd_atoms, vmd_forces)) {
253  iout << iWARN <<
254  "Error reading IMD forces, killing connection\n" << endi;
255  goto vmdDestroySocket;
256  }
258  iout << iWARN << "Ignoring IMD forces as receiving forces is not supported in IMDv3 as of now\n" << endi;
259  }
260  else if (IMDignore || IMDignoreForces) {
261  if ( ! warned ) {
262  warned = 1;
263  char option[16];
264  if (IMDignore) strcpy(option, "IMDignore");
265  else strcpy(option, "IMDignoreForces");
266  iout << iWARN << "Ignoring IMD forces due to " << option << "\n" << endi;
267  }
268  } else {
269  for (int i=0; i<length; i++) {
270  vnew.index = vmd_atoms[i];
271  if ( (vtest=vmdforces.find(vnew)) != NULL) {
272  // find was successful, so overwrite the old force values
273  if (vmd_forces[3*i] != 0.0f || vmd_forces[3*i+1] != 0.0f
274  || vmd_forces[3*i+2] != 0.0f) {
275  vtest->force.x = vmd_forces[3*i];
276  vtest->force.y = vmd_forces[3*i+1];
277  vtest->force.z = vmd_forces[3*i+2];
278  } else {
279  // or delete it from the list if the new force is ZERO
280  vmdforces.del(vnew);
281  }
282  }
283  else {
284  // Create a new entry in the table if the new force isn't ZERO
285  if (vmd_forces[3*i] != 0.0f || vmd_forces[3*i+1] != 0.0f
286  || vmd_forces[3*i+2] != 0.0f) {
287  vnew.force.x = vmd_forces[3*i];
288  vnew.force.y = vmd_forces[3*i+1];
289  vnew.force.z = vmd_forces[3*i+2];
290  vmdforces.add(vnew);
291  }
292  }
293  }
294  }
295  delete [] vmd_atoms;
296  delete [] vmd_forces;
297  break;
298  case IMD_TRATE:
299  iout << iINFO << "Setting transfer rate to " << length<<'\n'<<endi;
300  Node::Object()->imd->set_transrate(length);
301  break;
302  case IMD_PAUSE:
303  if (IMDignore) {
304  iout << iWARN << "Ignoring IMD pause due to IMDignore\n" << endi;
305  break;
306  }
308  if ( paused ) {
309  iout << iINFO << "Resuming IMD\n" << endi;
311  }
312  paused = ! paused;
313  if ( paused ) {
314  iout << iINFO << "Pausing IMD\n" << endi;
315  IMDwait = 1;
316  }
317  } else if (IMDversion == IMDversion_t::IMDv3) {
318  if ( paused ) {
319  iout << iINFO << "Already paused\n" << endi;
320  }
321  if ( ! paused ) {
322  iout << iINFO << "Pausing IMD\n" << endi;
323  paused = ! paused;
324  }
325  }
326  break;
327  case IMD_RESUME:
329  if ( paused ) {
330  iout << iINFO << "Resuming IMD\n" << endi;
331  }
332  paused = ! paused;
333  }
334  break;
335  case IMD_IOERROR:
336  iout << iWARN << "IMD connection lost\n" << endi;
337  case IMD_DISCONNECT:
338  iout << iINFO << "IMD connection detached\n" << endi;
339  vmdDestroySocket:
340  vmdsock_destroy(clientsock);
341  clients.del(i_client);
342  // Adjust index to account for the deleted client
343  i_client--;
344  // Remove any paused state before moving onto next client
345  if ( paused ) paused = ! paused;
346  // Enable the MD to continue after detach if IMD is v2
348  if (IMDwait && !clients.size()) imd_connection();
349  goto vmdEnd;
350  case IMD_KILL:
351  if (IMDignore) {
352  iout << iWARN << "Ignoring IMD kill due to IMDignore\n" << endi;
353  break;
354  }
355  NAMD_quit("Received IMD kill from client\n");
356  break;
357  case IMD_ENERGIES:
358  IMDEnergies junk;
359  imd_recv_energies(clientsock, &junk);
360  break;
361  case IMD_FCOORDS:
362  vmd_forces = new float[3*length];
363  imd_recv_fcoords(clientsock, length, vmd_forces);
364  delete [] vmd_forces;
365  break;
366  case IMD_WAIT:
368  IMDwait = length;
369  iout << iINFO << "IMD set to " << (IMDwait ? "wait" : "not wait") << " for incoming connection" << '\n' << endi;
370  }
371  break;
372  default: ;
373  }
374  }
375  vmdEnd: ;
376  }
377 }
static Node * Object()
Definition: Node.h:86
Definition: imd.h:33
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
Vector force
int vmdsock_selread(void *v, int sec)
Definition: vmdsock.C:177
int size(void) const
Definition: ResizeArray.h:131
Definition: common.h:275
void NAMD_quit(const char *err_msg)
Definition: common.C:125
IMDOutput * imd
Definition: Node.h:186
SimParameters * simParameters
Definition: Node.h:181
int32_t int32
Definition: common.h:38
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
Definition: imd.h:22
#define iout
Definition: InfoStream.h:51
IMDType
Definition: imd.h:15
int imd_recv_fcoords(void *s, int32 n, float *coords)
Definition: imd.C:298
int imd_recv_mdcomm(void *s, int32 n, int32 *indices, float *forces)
Definition: imd.C:287
BigReal x
Definition: Vector.h:74
Definition: imd.h:24
ResizeArray< void * > clients
static UniqueSortedArray< vmdforce > vmdforces
void vmdsock_destroy(void *v)
Definition: vmdsock.C:164
BigReal y
Definition: Vector.h:74
void del(int index, int num=1)
Definition: ResizeArray.h:108
Definition: imd.h:23
int imd_recv_energies(void *s, IMDEnergies *energies)
Definition: imd.C:293
Definition: common.h:275
Definition: imd.h:28
Definition: imd.h:21
IMDType imd_recv_header(void *s, int32 *length)
Definition: imd.C:276
void set_transrate(int newrate)
Definition: IMDOutput.h:42

◆ imd_connection()

void GlobalMasterIMD::imd_connection ( )
protected

Definition at line 152 of file GlobalMasterIMD.C.

References ResizeArray< Elem >::add(), clients, endi(), iINFO(), IMDsendsettings, IMDversion, IMDwait, iout, iWARN(), my_imd_connect(), ResizeArray< Elem >::size(), sock, vmdsock_accept(), vmdsock_destroy(), and vmdsock_selread().

Referenced by calculate(), IMDOutput::get_imd_packet(), and get_vmd_forces().

152  {
153  // check for incoming connection
154  do {
155  int rc;
156  if (IMDwait && !clients.size()) {
157  iout << iINFO << "INTERACTIVE MD AWAITING CONNECTION\n" << endi;
158  do { rc = vmdsock_selread(sock, 3600); } while (rc <= 0);
159  } else {
160  rc = vmdsock_selread(sock, 0);
161  }
162  if (rc > 0) {
163  void *clientsock = vmdsock_accept(sock);
164  if (!clientsock) {
165  iout << iWARN << "IMD socket accept failed\n" << endi;
166  } else {
167  if (!my_imd_connect(clientsock, IMDversion, &IMDsendsettings)) {
168  iout << iWARN << "IMD connection failed\n" << endi;
169  vmdsock_destroy(clientsock);
170  } else {
171  iout << iINFO << "IMD connection opened\n" <<endi;
172  clients.add(clientsock);
173  }
174  }
175  }
176  } while (IMDwait && !clients.size());
177 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int vmdsock_selread(void *v, int sec)
Definition: vmdsock.C:177
int size(void) const
Definition: ResizeArray.h:131
static int my_imd_connect(void *s, const int IMDversion, const IMDSessionInfo *sessionInfo)
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
int add(const Elem &elem)
Definition: ResizeArray.h:101
ResizeArray< void * > clients
void vmdsock_destroy(void *v)
Definition: vmdsock.C:164
IMDSessionInfo IMDsendsettings
void * vmdsock_accept(void *v)
Definition: vmdsock.C:128

◆ send_box()

void GlobalMasterIMD::send_box ( IMDBox box)

Definition at line 507 of file GlobalMasterIMD.C.

References clients, imd_send_box(), IMDv3TimeoutSeconds, NAMD_die(), ResizeArray< Elem >::size(), and vmdsock_selwrite().

Referenced by IMDOutput::gather_box().

507  {
508  for (int i=0; i<clients.size(); i++) {
509  void *clientsock = clients[i];
510  /*
511  * Only IMDv3 may require the box.
512  */
513  if (!clientsock) continue;
514  else if (!vmdsock_selwrite(clientsock, IMDv3TimeoutSeconds)) {
515  const std::string error =
516  std::string{"IMDv3: GlobalMasterIMD::send_box socket timeout in "} +
517  std::to_string(IMDv3TimeoutSeconds) + "\n";
518  NAMD_die(error.c_str());
519  }
520  imd_send_box(clientsock, box);
521  }
522 }
int vmdsock_selwrite(void *v, int sec)
Definition: vmdsock.C:194
int size(void) const
Definition: ResizeArray.h:131
int imd_send_box(void *s, const IMDBox *box)
Definition: imd.C:222
void NAMD_die(const char *err_msg)
Definition: common.C:147
ResizeArray< void * > clients

◆ send_energies()

void GlobalMasterIMD::send_energies ( IMDEnergies energies)

Definition at line 379 of file GlobalMasterIMD.C.

References clients, imd_send_energies(), IMDv2, IMDv3, IMDv3TimeoutSeconds, SimParameters::IMDversion, NAMD_die(), Node::Object(), Node::simParameters, ResizeArray< Elem >::size(), and vmdsock_selwrite().

Referenced by IMDOutput::gather_energies().

379  {
380  const SimParameters *simparams = Node::Object()->simParameters;
381  for (int i=0; i<clients.size(); i++) {
382  void *clientsock = clients[i];
383  if (simparams->IMDversion == IMDversion_t::IMDv2) {
384  if (!clientsock || !vmdsock_selwrite(clientsock,0)) continue;
385  } else if (simparams->IMDversion == IMDversion_t::IMDv3) {
386  /* NOTE (from Lawson Woods):
387  * If vmdsock_selwrite returns 0, indicating that the socket
388  * isn't immediately available (within 0 seconds), the above
389  * IMDv2 code just doesn't send the packet.
390  * But in IMDv3, packets aren't skippable, the simulation
391  * engine has to wait until the socket is ready.
392  */
393  if (!clientsock) continue;
394  else if (!vmdsock_selwrite(clientsock, IMDv3TimeoutSeconds)) {
395  const std::string error =
396  std::string{"IMDv3: GlobalMasterIMD::send_energies socket timeout in "} +
397  std::to_string(IMDv3TimeoutSeconds) + "\n";
398  NAMD_die(error.c_str());
399  }
400  }
401  imd_send_energies(clientsock, energies);
402  }
403 }
static Node * Object()
Definition: Node.h:86
int vmdsock_selwrite(void *v, int sec)
Definition: vmdsock.C:194
int size(void) const
Definition: ResizeArray.h:131
Definition: common.h:275
int imd_send_energies(void *s, const IMDEnergies *energies)
Definition: imd.C:182
SimParameters * simParameters
Definition: Node.h:181
void NAMD_die(const char *err_msg)
Definition: common.C:147
ResizeArray< void * > clients
Definition: common.h:275

◆ send_fcoords()

void GlobalMasterIMD::send_fcoords ( int  N,
FloatVector coords 
)

Definition at line 405 of file GlobalMasterIMD.C.

References clients, coords, coordtmp, coordtmpsize, imd_send_fcoords(), IMDv2, IMDv3, IMDv3TimeoutSeconds, SimParameters::IMDversion, NAMD_die(), Node::Object(), Node::simParameters, ResizeArray< Elem >::size(), and vmdsock_selwrite().

Referenced by IMDOutput::gather_coordinates().

405  {
406  const SimParameters *simparams = Node::Object()->simParameters;
407  for (int i=0; i<clients.size(); i++) {
408  void *clientsock = clients[i];
409  if (simparams->IMDversion == IMDversion_t::IMDv2) {
410  if (!clientsock || !vmdsock_selwrite(clientsock,0)) continue;
411  } else if (simparams->IMDversion == IMDversion_t::IMDv3) {
412  /* NOTE (from Lawson Woods):
413  * If vmdsock_selwrite returns 0, indicating that the socket
414  * isn't immediately available (within 0 seconds), the above
415  * IMDv2 code just doesn't send the packet.
416  * But in IMDv3, packets aren't skippable, the simulation
417  * engine has to wait until the socket is ready.
418  */
419  if (!clientsock) continue;
420  else if (!vmdsock_selwrite(clientsock, IMDv3TimeoutSeconds)) {
421  const std::string error =
422  std::string{"IMDv3: GlobalMasterIMD::send_fcoords socket timeout in "} +
423  std::to_string(IMDv3TimeoutSeconds) + "\n";
424  NAMD_die(error.c_str());
425  }
426  }
427  if (sizeof(FloatVector) == 3*sizeof(float)) {
428  imd_send_fcoords(clientsock, N, (float *)coords);
429  } else {
430  if (coordtmpsize < N) {
431  if (coordtmp) delete [] coordtmp;
432  coordtmp = new float[3*N];
433  coordtmpsize = N;
434  }
435  for (int i=0; i<N; i++) {
436  coordtmp[3*i] = coords[i].x;
437  coordtmp[3*i+1] = coords[i].y;
438  coordtmp[3*i+2] = coords[i].z;
439  }
440  imd_send_fcoords(clientsock, N, coordtmp);
441  }
442  }
443 }
static Node * Object()
Definition: Node.h:86
int vmdsock_selwrite(void *v, int sec)
Definition: vmdsock.C:194
int size(void) const
Definition: ResizeArray.h:131
Definition: common.h:275
SimParameters * simParameters
Definition: Node.h:181
int imd_send_fcoords(void *s, int32 n, const float *coords)
Definition: imd.C:192
void NAMD_die(const char *err_msg)
Definition: common.C:147
ResizeArray< void * > clients
Definition: common.h:275
static float * coords
Definition: ScriptTcl.C:67

◆ send_forces()

void GlobalMasterIMD::send_forces ( int  N,
FloatVector forces 
)

Definition at line 476 of file GlobalMasterIMD.C.

References clients, forcetmp, forcetmpsize, imd_send_forces(), IMDv3TimeoutSeconds, NAMD_die(), ResizeArray< Elem >::size(), vmdsock_selwrite(), FloatVector::x, FloatVector::y, and FloatVector::z.

Referenced by IMDOutput::gather_forces().

476  {
477  for (int i=0; i<clients.size(); i++) {
478  void *clientsock = clients[i];
479  /*
480  * Only IMDv3 may require the forces.
481  */
482  if (!clientsock) continue;
483  else if (!vmdsock_selwrite(clientsock, IMDv3TimeoutSeconds)) {
484  const std::string error =
485  std::string{"IMDv3: GlobalMasterIMD::send_forces socket timeout in "} +
486  std::to_string(IMDv3TimeoutSeconds) + "\n";
487  NAMD_die(error.c_str());
488  }
489  if (sizeof(FloatVector) == 3*sizeof(float)) {
490  imd_send_forces(clientsock, N, (float *)forces);
491  } else {
492  if (forcetmpsize < N) {
493  if (forcetmp) delete [] forcetmp;
494  forcetmp = new float[3*N];
495  forcetmpsize = N;
496  }
497  for (int i=0; i<N; i++) {
498  forcetmp[3*i] = forces[i].x;
499  forcetmp[3*i+1] = forces[i].y;
500  forcetmp[3*i+2] = forces[i].z;
501  }
502  imd_send_forces(clientsock, N, forcetmp);
503  }
504  }
505 }
int vmdsock_selwrite(void *v, int sec)
Definition: vmdsock.C:194
int size(void) const
Definition: ResizeArray.h:131
float y
Definition: Vector.h:26
float x
Definition: Vector.h:26
float z
Definition: Vector.h:26
int imd_send_forces(void *s, int32 n, const float *forces)
Definition: imd.C:212
void NAMD_die(const char *err_msg)
Definition: common.C:147
ResizeArray< void * > clients

◆ send_time()

void GlobalMasterIMD::send_time ( IMDTime time)

Definition at line 524 of file GlobalMasterIMD.C.

References clients, imd_send_time(), IMDv3TimeoutSeconds, NAMD_die(), ResizeArray< Elem >::size(), and vmdsock_selwrite().

Referenced by IMDOutput::gather_time().

524  {
525  for (int i=0; i<clients.size(); i++) {
526  void *clientsock = clients[i];
527  /*
528  * Only IMDv3 may require the time.
529  */
530  if (!clientsock) continue;
531  else if (!vmdsock_selwrite(clientsock, IMDv3TimeoutSeconds)) {
532  const std::string error =
533  std::string{"IMDv3: GlobalMasterIMD::send_time socket timeout in "} +
534  std::to_string(IMDv3TimeoutSeconds) + "\n";
535  NAMD_die(error.c_str());
536  }
537  imd_send_time(clientsock, time);
538  }
539 }
int vmdsock_selwrite(void *v, int sec)
Definition: vmdsock.C:194
int size(void) const
Definition: ResizeArray.h:131
int imd_send_time(void *s, const IMDTime *time)
Definition: imd.C:232
void NAMD_die(const char *err_msg)
Definition: common.C:147
ResizeArray< void * > clients

◆ send_velocities()

void GlobalMasterIMD::send_velocities ( int  N,
FloatVector velocities 
)

Definition at line 445 of file GlobalMasterIMD.C.

References clients, imd_send_velocities(), IMDv3TimeoutSeconds, NAMD_die(), ResizeArray< Elem >::size(), veltmp, veltmpsize, vmdsock_selwrite(), FloatVector::x, FloatVector::y, and FloatVector::z.

Referenced by IMDOutput::gather_velocities().

445  {
446  for (int i=0; i<clients.size(); i++) {
447  void *clientsock = clients[i];
448  /*
449  * Only IMDv3 may require the velocities.
450  */
451  if (!clientsock) continue;
452  else if (!vmdsock_selwrite(clientsock, IMDv3TimeoutSeconds)) {
453  const std::string error =
454  std::string{"IMDv3: GlobalMasterIMD::send_velocities socket timeout in "} +
455  std::to_string(IMDv3TimeoutSeconds) + "\n";
456  NAMD_die(error.c_str());
457  }
458  if (sizeof(FloatVector) == 3*sizeof(float)) {
459  imd_send_velocities(clientsock, N, (float *)velocities);
460  } else {
461  if (veltmpsize < N) {
462  if (veltmp) delete [] veltmp;
463  veltmp = new float[3*N];
464  veltmpsize = N;
465  }
466  for (int i=0; i<N; i++) {
467  veltmp[3*i] = velocities[i].x;
468  veltmp[3*i+1] = velocities[i].y;
469  veltmp[3*i+2] = velocities[i].z;
470  }
471  imd_send_velocities(clientsock, N, veltmp);
472  }
473  }
474 }
int vmdsock_selwrite(void *v, int sec)
Definition: vmdsock.C:194
int size(void) const
Definition: ResizeArray.h:131
float y
Definition: Vector.h:26
float x
Definition: Vector.h:26
float z
Definition: Vector.h:26
void NAMD_die(const char *err_msg)
Definition: common.C:147
ResizeArray< void * > clients
int imd_send_velocities(void *s, int32 n, const float *vels)
Definition: imd.C:202

Friends And Related Function Documentation

◆ IMDOutput

friend class IMDOutput
friend

Definition at line 34 of file GlobalMasterIMD.h.

Member Data Documentation

◆ clients

ResizeArray<void *> GlobalMasterIMD::clients
protected

◆ coordtmp

float* GlobalMasterIMD::coordtmp
protected

Definition at line 69 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), send_fcoords(), and ~GlobalMasterIMD().

◆ coordtmpsize

int GlobalMasterIMD::coordtmpsize
protected

Definition at line 70 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), and send_fcoords().

◆ forcetmp

float* GlobalMasterIMD::forcetmp
protected

Definition at line 75 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), send_forces(), and ~GlobalMasterIMD().

◆ forcetmpsize

int GlobalMasterIMD::forcetmpsize
protected

Definition at line 76 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), and send_forces().

◆ IMDignore

int GlobalMasterIMD::IMDignore
protected

Definition at line 54 of file GlobalMasterIMD.h.

Referenced by calculate(), get_vmd_forces(), GlobalMasterIMD(), and IMDOutput::use_imd().

◆ IMDignoreForces

int GlobalMasterIMD::IMDignoreForces
protected

Definition at line 57 of file GlobalMasterIMD.h.

Referenced by calculate(), get_vmd_forces(), GlobalMasterIMD(), and IMDOutput::use_imd().

◆ IMDsendsettings

IMDSessionInfo GlobalMasterIMD::IMDsendsettings
protected

Definition at line 60 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), and imd_connection().

◆ IMDv3TimeoutSeconds

int GlobalMasterIMD::IMDv3TimeoutSeconds
protected

◆ IMDversion

int GlobalMasterIMD::IMDversion
protected

Definition at line 48 of file GlobalMasterIMD.h.

Referenced by calculate(), get_vmd_forces(), GlobalMasterIMD(), and imd_connection().

◆ IMDwait

int GlobalMasterIMD::IMDwait
protected

Definition at line 51 of file GlobalMasterIMD.h.

Referenced by calculate(), get_vmd_forces(), GlobalMasterIMD(), and imd_connection().

◆ sock

void* GlobalMasterIMD::sock
protected

Definition at line 63 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), imd_connection(), and ~GlobalMasterIMD().

◆ veltmp

float* GlobalMasterIMD::veltmp
protected

Definition at line 72 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), send_velocities(), and ~GlobalMasterIMD().

◆ veltmpsize

int GlobalMasterIMD::veltmpsize
protected

Definition at line 73 of file GlobalMasterIMD.h.

Referenced by GlobalMasterIMD(), and send_velocities().


The documentation for this class was generated from the following files: