NAMD
Functions | Variables
DataExchanger.C File Reference
#include <stdio.h>
#include "DataExchanger.h"
#include "ProcessorPrivate.h"
#include "common.h"
#include "Node.h"
#include "CollectionMaster.h"
#include "Output.h"
#include "ScriptTcl.h"
#include "qd.h"
#include "DataExchanger.def.h"

Go to the source code of this file.

Functions

 CpvDeclare (int, breakScheduler)
 
 CpvDeclare (int, inEval)
 
void packSend (int dst, int dstPart, const char *data, int size, int handler, int code)
 
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 recvBcast (DataMessage *dmsg)
 
void recvRed (DataMessage *dmsg)
 
void recvEvalCommand (DataMessage *dmsg)
 
void recvEvalResult (DataMessage *dmsg)
 
void replica_send (const char *sndbuf, int sendcount, int destPart, int destPE)
 
void replica_recv (DataMessage **precvMsg, int srcPart, int srcPE)
 
void replica_sendRecv (const char *sndbuf, int sendcount, int destPart, int destPE, DataMessage **precvMsg, int srcPart, int srcPE)
 
void replica_eval (const char *cmdbuf, int targPart, int targPE, DataMessage **precvMsg)
 
void replica_barrier ()
 
void replica_bcast (char *buf, int count, int root)
 
void replica_min_double (double *dat, int count)
 
void initializeReplicaConverseHandlers ()
 

Variables

static int recvRedCalledEarly
 

Function Documentation

CpvDeclare ( int  ,
breakScheduler   
)
CpvDeclare ( int  ,
inEval   
)
void initializeReplicaConverseHandlers ( )

Definition at line 252 of file DataExchanger.C.

References recvAck(), recvBcast(), recvData(), recvEvalCommand(), recvEvalResult(), recvRed(), recvReplicaDcdAck(), recvReplicaDcdData(), and recvReplicaDcdInit().

Referenced by ProcessorPrivateInit().

252  {
253  CkpvInitialize(int, recv_data_idx);
254  CkpvInitialize(int, recv_ack_idx);
255  CkpvInitialize(int, recv_bcast_idx);
256  CkpvInitialize(int, recv_red_idx);
257  CkpvInitialize(int, recv_eval_command_idx);
258  CkpvInitialize(int, recv_eval_result_idx);
259  CkpvInitialize(int, recv_replica_dcd_init_idx);
260  CkpvInitialize(int, recv_replica_dcd_data_idx);
261  CkpvInitialize(int, recv_replica_dcd_ack_idx);
262 
263  CkpvAccess(recv_data_idx) = CmiRegisterHandler((CmiHandler)recvData);
264  CkpvAccess(recv_ack_idx) = CmiRegisterHandler((CmiHandler)recvAck);
265  CkpvAccess(recv_red_idx) = CmiRegisterHandler((CmiHandler)recvRed);
266  CkpvAccess(recv_bcast_idx) = CmiRegisterHandler((CmiHandler)recvBcast);
267  CkpvAccess(recv_eval_command_idx) = CmiRegisterHandler((CmiHandler)recvEvalCommand);
268  CkpvAccess(recv_eval_result_idx) = CmiRegisterHandler((CmiHandler)recvEvalResult);
269  CkpvAccess(recv_replica_dcd_init_idx) = CmiRegisterHandler((CmiHandler)recvReplicaDcdInit);
270  CkpvAccess(recv_replica_dcd_data_idx) = CmiRegisterHandler((CmiHandler)recvReplicaDcdData);
271  CkpvAccess(recv_replica_dcd_ack_idx) = CmiRegisterHandler((CmiHandler)recvReplicaDcdAck);
272 
273 #if CMK_IMMEDIATE_MSG && CMK_SMP && ! ( CMK_MULTICORE || CMK_SMP_NO_COMMTHD )
274  int sleep_commthd_idx = CmiRegisterHandler((CmiHandler)recvSleepCommthdMsg);
275  if ( CkMyPe() == 0 && CkNumNodes() == 1 ) {
276  CkPrintf("Charm++ communication thread will sleep due to single-process run.\n");
277  SleepCommthdMsg *msg = (SleepCommthdMsg *)malloc(sizeof(SleepCommthdMsg));
278  CmiSetHandler(msg, sleep_commthd_idx);
279  CmiBecomeImmediate(msg);
280  CmiPushImmediateMsg(msg);
281  }
282 #endif
283 }
void recvRed(DataMessage *dmsg)
void recvReplicaDcdData(ReplicaDcdDataMsg *msg)
Definition: DataExchanger.C:82
void recvEvalResult(DataMessage *dmsg)
void recvBcast(DataMessage *dmsg)
void recvEvalCommand(DataMessage *dmsg)
void recvData(DataMessage *dmsg)
Definition: DataExchanger.C:93
void recvReplicaDcdAck(ReplicaDcdAckMsg *msg)
Definition: DataExchanger.C:87
void recvReplicaDcdInit(ReplicaDcdInitMsg *msg)
Definition: DataExchanger.C:77
void recvAck(DataMessage *dmsg)
Definition: DataExchanger.C:99
void packSend ( int  dst,
int  dstPart,
const char *  data,
int  size,
int  handler,
int  code 
)

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 recvBcast ( DataMessage dmsg)

Definition at line 105 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

105  {
106  if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvBcast!");
107  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_bcast();
108  CmiFree(dmsg);
109  }
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 recvEvalCommand ( DataMessage dmsg)

Definition at line 121 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

121  {
122  Pointer msg(dmsg);
123  if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvEvalCommand!");
124  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_eval_command(msg);
125  }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
Definition: Pointer.h:4
void recvEvalResult ( DataMessage dmsg)

Definition at line 127 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

127  {
128  Pointer msg(dmsg);
129  if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvEvalResult!");
130  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_eval_result(msg);
131  }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
Definition: Pointer.h:4
void recvRed ( DataMessage dmsg)

Definition at line 111 of file DataExchanger.C.

References CPROXY_DE, and recvRedCalledEarly.

Referenced by initializeReplicaConverseHandlers().

111  {
112  if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) {
114  CmiFree(dmsg);
115  return;
116  }
117  CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_red();
118  CmiFree(dmsg);
119  }
static int recvRedCalledEarly
Definition: DataExchanger.C:27
#define CPROXY_DE(x)
Definition: DataExchanger.h:14
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 
)

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()

Variable Documentation

int recvRedCalledEarly
static

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

Definition at line 27 of file DataExchanger.C.

Referenced by recvRed(), and replica_barrier().