NAMD
Classes | Macros | Functions
DataExchanger.h File Reference
#include "charm++.h"
#include "main.h"
#include "DataExchanger.decl.h"

Go to the source code of this file.

Classes

class  DataMessage
 
class  ReplicaDcdInitMsg
 
class  ReplicaDcdDataMsg
 
class  ReplicaDcdAckMsg
 
class  DataExchanger
 

Macros

#define CPROXY_DE(x)   ((CProxy_DataExchanger)(x))
 

Functions

 CpvExtern (int, breakScheduler)
 
 CpvExtern (int, inEval)
 
void packSend (int dest, int partition, const char *data, int size, int handler, int code=0)
 
void sendReplicaDcdInit (int dstPart, ReplicaDcdInitMsg *msg, int msgsize)
 
void sendReplicaDcdData (int dstPart, ReplicaDcdDataMsg *msg, int msgsize)
 
void sendReplicaDcdAck (int dstPart, ReplicaDcdAckMsg *msg)
 
void recvReplicaDcdInit (ReplicaDcdInitMsg *msg)
 
void recvReplicaDcdData (ReplicaDcdDataMsg *msg)
 
void recvReplicaDcdAck (ReplicaDcdAckMsg *msg)
 
void recvData (DataMessage *dmsg)
 
void recvAck (DataMessage *dmsg)
 
void replica_send (const char *sndbuf, int sendcount, int destPart, int destPE)
 
void replica_sendRecv (const char *sndbuf, int sendcount, int destPart, int destPE, DataMessage **precvMsg, int srcPart, int srcPE)
 
void replica_recv (DataMessage **precvMsg, int srcPart, int srcPE)
 
void replica_barrier ()
 
void replica_bcast (char *buf, int count, int root=0)
 
void replica_min_double (double *dat, int count)
 
void replica_eval (const char *cmdbuf, int targPart, int targPE, DataMessage **precvMsg)
 

Macro Definition Documentation

#define CPROXY_DE (   x)    ((CProxy_DataExchanger)(x))

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 14 of file DataExchanger.h.

Referenced by recvAck(), recvBcast(), recvData(), recvEvalCommand(), recvEvalResult(), recvRed(), replica_barrier(), replica_eval(), replica_recv(), replica_send(), and replica_sendRecv().

Function Documentation

CpvExtern ( int  ,
breakScheduler   
)
CpvExtern ( int  ,
inEval   
)
void packSend ( int  dest,
int  partition,
const char *  data,
int  size,
int  handler,
int  code = 0 
)

Definition at line 34 of file DataExchanger.C.

References DataMessage::setMessage().

Referenced by replica_send().

34  {
35  int msgsize = sizeof(DataMessage) + size;
36  DataMessage *dmsg = (DataMessage *)CmiAlloc(msgsize);
37  dmsg->setMessage(data,CkMyPe(),CmiMyPartition(),size,handler,code);
38 #if CMK_HAS_PARTITION
39  CmiInterSyncSendAndFree(dst,dstPart,msgsize,(char*)dmsg);
40 #else
41  CmiSyncSendAndFree(dst,msgsize,(char*)dmsg);
42 #endif
43  }
void setMessage(const char *_data, int _src, int _srcPart, int _size, int _handler, int _code)
Definition: DataExchanger.h:25
void recvAck ( DataMessage dmsg)

Definition at line 99 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

99  {
100  if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvAck!");
101  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_ack();
102  CmiFree(dmsg);
103  }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
void recvData ( DataMessage dmsg)

Definition at line 93 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

93  {
94  Pointer msg(dmsg);
95  if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvData!");
96  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_data(msg);
97  }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
Definition: Pointer.h:4
void recvReplicaDcdAck ( ReplicaDcdAckMsg msg)

Definition at line 87 of file DataExchanger.C.

References CollectionMaster::Object(), and CollectionMaster::unblockPositions().

Referenced by initializeReplicaConverseHandlers().

87  {
88  CmiFree(msg);
90  CkpvAccess(_qd)->process();
91  }
static CollectionMaster * Object()
void recvReplicaDcdData ( ReplicaDcdDataMsg msg)

Definition at line 82 of file DataExchanger.C.

References Node::Object(), Node::output, and Output::recvReplicaDcdData().

Referenced by initializeReplicaConverseHandlers().

82  {
84  CmiFree(msg);
85  }
static Node * Object()
Definition: Node.h:86
Output * output
Definition: Node.h:182
void recvReplicaDcdData(ReplicaDcdDataMsg *msg)
Definition: Output.C:700
void recvReplicaDcdInit ( ReplicaDcdInitMsg msg)

Definition at line 77 of file DataExchanger.C.

References Node::Object(), Node::output, and Output::recvReplicaDcdInit().

Referenced by initializeReplicaConverseHandlers().

77  {
79  CmiFree(msg);
80  }
static Node * Object()
Definition: Node.h:86
Output * output
Definition: Node.h:182
void recvReplicaDcdInit(ReplicaDcdInitMsg *msg)
Definition: Output.C:689
void replica_barrier ( )

Definition at line 168 of file DataExchanger.C.

References CPROXY_DE, and recvRedCalledEarly.

Referenced by colvarproxy_namd::replica_comm_barrier(), and ScriptTcl::run().

168  {
169  for ( ; recvRedCalledEarly > 0; --recvRedCalledEarly ) CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_red();
170  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].barrier();
171  CpvAccess(breakScheduler) = 0;
172  while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
173  }
static int recvRedCalledEarly
Definition: DataExchanger.C:27
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
void replica_bcast ( char *  buf,
int  count,
int  root = 0 
)

Definition at line 175 of file DataExchanger.C.

References DataMessage::data, NAMD_bug(), replica_recv(), replica_send(), and DataMessage::size.

Referenced by replica_min_double().

175  {
176  if ( root != 0 ) NAMD_bug("replica_bcast root must be zero");
177  int rank = CmiMyPartition();
178  int size = CmiNumPartitions();
179  int i;
180  for ( i=1; i<size; i*=2 );
181  for ( i/=2; i>0; i/=2 ) {
182  if ( rank & (i - 1) ) continue;
183  if ( rank & i ) {
184  int src = rank - i;
185  //CkPrintf("rank %d recv from %d\n", rank, src);
186  DataMessage *recvMsg = NULL;
187  replica_recv(&recvMsg, src, CkMyPe());
188  if ( recvMsg == NULL ) NAMD_bug("recvMsg == NULL in replica_bcast");
189  if ( recvMsg->size != count ) NAMD_bug("size != count in replica_bcast");
190  memcpy(buf, recvMsg->data, count);
191  CmiFree(recvMsg);
192  } else {
193  int dst = rank + i;
194  if ( dst < size ) {
195  //CkPrintf("rank %d send to %d\n", rank, dst);
196  replica_send(buf, count, dst, CkMyPe());
197  }
198  }
199  }
200  }
void replica_send(const char *sndbuf, int sendcount, int destPart, int destPE)
void replica_recv(DataMessage **precvMsg, int srcPart, int srcPE)
void NAMD_bug(const char *err_msg)
Definition: common.C:123
char data[1]
Definition: DataExchanger.h:23
void replica_eval ( const char *  cmdbuf,
int  targPart,
int  targPE,
DataMessage **  precvMsg 
)

Definition at line 159 of file DataExchanger.C.

References CPROXY_DE.

159  {
160  ConstPointer sendPointer(cmdbuf);
161  Pointer recvPointer((char *) precvMsg);
162  int sendcount = strlen(cmdbuf) + 1;
163  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].eval(sendPointer,sendcount,targPart,targPE,recvPointer);
164  CpvAccess(breakScheduler) = 0;
165  while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
166  }
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
Definition: Pointer.h:4
void replica_min_double ( double *  dat,
int  count 
)

Definition at line 202 of file DataExchanger.C.

References DataMessage::data, NAMD_bug(), replica_bcast(), replica_recv(), replica_send(), and DataMessage::size.

Referenced by PatchMap::makePatches().

202  {
203  int rank = CmiMyPartition();
204  int size = CmiNumPartitions();
205  for ( int i=1; i<size; i*=2 ) {
206  if ( rank & i ) {
207  int dst = rank - i;
208  //CkPrintf("rank %d send to %d\n", rank, dst);
209  replica_send((char*)dat, count * sizeof(double), dst, CkMyPe());
210  } else {
211  int src = rank + i;
212  if ( src < size ) {
213  //CkPrintf("rank %d recv from %d\n", rank, src);
214  DataMessage *recvMsg = NULL;
215  replica_recv(&recvMsg, src, CkMyPe());
216  if ( recvMsg == NULL ) NAMD_bug("recvMsg == NULL in replica_bcast");
217  if ( recvMsg->size != count * sizeof(double) ) NAMD_bug("size != count in replica_min_double");
218  double *rdat = new double[count];
219  memcpy(rdat, recvMsg->data, count * sizeof(double));
220  CmiFree(recvMsg);
221  for ( int j=0; j<count; ++j ) {
222  if ( rdat[j] < dat[j] ) dat[j] = rdat[j];
223  }
224  delete [] rdat;
225  }
226  }
227  if ( rank & (2 * i - 1) ) break;
228  }
229  replica_bcast((char*)dat, count * sizeof(double), 0);
230  }
void replica_send(const char *sndbuf, int sendcount, int destPart, int destPE)
void replica_recv(DataMessage **precvMsg, int srcPart, int srcPE)
void replica_bcast(char *buf, int count, int root)
void NAMD_bug(const char *err_msg)
Definition: common.C:123
char data[1]
Definition: DataExchanger.h:23
void replica_recv ( DataMessage **  precvMsg,
int  srcPart,
int  srcPE 
)

Definition at line 144 of file DataExchanger.C.

References CPROXY_DE.

Referenced by replica_bcast(), colvarproxy_namd::replica_comm_recv(), and replica_min_double().

144  {
145  Pointer recvPointer((char *) precvMsg);
146  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv(recvPointer,srcPart,srcPE);
147  CpvAccess(breakScheduler) = 0;
148  while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
149  }
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
Definition: Pointer.h:4
void replica_send ( const char *  sndbuf,
int  sendcount,
int  destPart,
int  destPE 
)

Definition at line 133 of file DataExchanger.C.

References CPROXY_DE, and packSend().

Referenced by replica_bcast(), colvarproxy_namd::replica_comm_send(), and replica_min_double().

133  {
134  if ( CpvAccess(inEval) ) {
135  packSend(destPE,destPart,sndbuf,sendcount,CkpvAccess(recv_data_idx),1);
136  return;
137  }
138  ConstPointer sendPointer(sndbuf);
139  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].send(sendPointer,sendcount,destPart,destPE);
140  CpvAccess(breakScheduler) = 0;
141  while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
142  }
void packSend(int dst, int dstPart, const char *data, int size, int handler, int code)
Definition: DataExchanger.C:34
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
void replica_sendRecv ( const char *  sndbuf,
int  sendcount,
int  destPart,
int  destPE,
DataMessage **  precvMsg,
int  srcPart,
int  srcPE 
)

Definition at line 151 of file DataExchanger.C.

References CPROXY_DE.

151  {
152  ConstPointer sendPointer(sndbuf);
153  Pointer recvPointer((char *) precvMsg);
154  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].sendRecv(sendPointer,sendcount,destPart,destPE,recvPointer,srcPart,srcPE);
155  CpvAccess(breakScheduler) = 0;
156  while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
157  }
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
Definition: Pointer.h:4
void sendReplicaDcdAck ( int  dstPart,
ReplicaDcdAckMsg msg 
)

Definition at line 67 of file DataExchanger.C.

References ReplicaDcdAckMsg::core.

Referenced by Output::recvReplicaDcdData(), and Output::recvReplicaDcdInit().

67  {
68  CmiSetHandler(msg->core, CkpvAccess(recv_replica_dcd_ack_idx));
69  int msgsize = sizeof(ReplicaDcdAckMsg);
70 #if CMK_HAS_PARTITION
71  CmiInterSyncSendAndFree(0,dstPart,msgsize,(char*)msg);
72 #else
73  CmiSyncSendAndFree(0,msgsize,(char*)msg);
74 #endif
75  }
char core[CmiMsgHeaderSizeBytes]
Definition: DataExchanger.h:55
void sendReplicaDcdData ( int  dstPart,
ReplicaDcdDataMsg msg,
int  msgsize 
)

Definition at line 56 of file DataExchanger.C.

References CollectionMaster::blockPositions(), ReplicaDcdDataMsg::core, and CollectionMaster::Object().

56  {
57  CmiSetHandler(msg->core, CkpvAccess(recv_replica_dcd_data_idx));
58 #if CMK_HAS_PARTITION
59  CmiInterSyncSendAndFree(0,dstPart,msgsize,(char*)msg);
60 #else
61  CmiSyncSendAndFree(0,msgsize,(char*)msg);
62 #endif
63  CollectionMaster::Object()->blockPositions(); // ensure ordering
64  CkpvAccess(_qd)->create(); // ensure completion
65  }
static CollectionMaster * Object()
char core[CmiMsgHeaderSizeBytes]
Definition: DataExchanger.h:44
void sendReplicaDcdInit ( int  dstPart,
ReplicaDcdInitMsg msg,
int  msgsize 
)

Definition at line 45 of file DataExchanger.C.

References CollectionMaster::blockPositions(), ReplicaDcdInitMsg::core, and CollectionMaster::Object().

Referenced by Output::replicaDcdInit().

45  {
46  CmiSetHandler(msg->core, CkpvAccess(recv_replica_dcd_init_idx));
47 #if CMK_HAS_PARTITION
48  CmiInterSyncSendAndFree(0,dstPart,msgsize,(char*)msg);
49 #else
50  CmiSyncSendAndFree(0,msgsize,(char*)msg);
51 #endif
52  CollectionMaster::Object()->blockPositions(); // ensure ordering
53  CkpvAccess(_qd)->create(); // ensure completion
54  }
char core[CmiMsgHeaderSizeBytes]
Definition: DataExchanger.h:36
static CollectionMaster * Object()