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 (char *sndbuf, int sendcount, int destPart, int destPE)
void replica_recv (DataMessage **precvMsg, int srcPart, int srcPE)
void replica_sendRecv (char *sndbuf, int sendcount, int destPart, int destPE, DataMessage **precvMsg, int srcPart, int srcPE)
void replica_eval (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  ,
inEval   
)

CpvDeclare ( int  ,
breakScheduler   
)

void initializeReplicaConverseHandlers (  ) 

Definition at line 248 of file DataExchanger.C.

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

Referenced by ProcessorPrivateInit().

00248                                          {
00249   CkpvInitialize(int, recv_data_idx);
00250   CkpvInitialize(int, recv_ack_idx);
00251   CkpvInitialize(int, recv_bcast_idx);
00252   CkpvInitialize(int, recv_red_idx);
00253   CkpvInitialize(int, recv_eval_command_idx);
00254   CkpvInitialize(int, recv_eval_result_idx);
00255   CkpvInitialize(int, recv_replica_dcd_init_idx);
00256   CkpvInitialize(int, recv_replica_dcd_data_idx);
00257   CkpvInitialize(int, recv_replica_dcd_ack_idx);
00258 
00259   CkpvAccess(recv_data_idx) = CmiRegisterHandler((CmiHandler)recvData);                   
00260   CkpvAccess(recv_ack_idx) = CmiRegisterHandler((CmiHandler)recvAck);                     
00261   CkpvAccess(recv_red_idx) = CmiRegisterHandler((CmiHandler)recvRed);                     
00262   CkpvAccess(recv_bcast_idx) = CmiRegisterHandler((CmiHandler)recvBcast);                 
00263   CkpvAccess(recv_eval_command_idx) = CmiRegisterHandler((CmiHandler)recvEvalCommand);    
00264   CkpvAccess(recv_eval_result_idx) = CmiRegisterHandler((CmiHandler)recvEvalResult);      
00265   CkpvAccess(recv_replica_dcd_init_idx) = CmiRegisterHandler((CmiHandler)recvReplicaDcdInit);
00266   CkpvAccess(recv_replica_dcd_data_idx) = CmiRegisterHandler((CmiHandler)recvReplicaDcdData);
00267   CkpvAccess(recv_replica_dcd_ack_idx) = CmiRegisterHandler((CmiHandler)recvReplicaDcdAck);
00268 
00269 #if CMK_IMMEDIATE_MSG && CMK_SMP && ! ( CMK_MULTICORE || CMK_SMP_NO_COMMTHD )
00270   int sleep_commthd_idx = CmiRegisterHandler((CmiHandler)recvSleepCommthdMsg);
00271   if ( CkMyPe() == 0 && CkNumNodes() == 1 ) {
00272     CkPrintf("Charm++ communication thread will sleep due to single-process run.\n");
00273     SleepCommthdMsg *msg = (SleepCommthdMsg *)malloc(sizeof(SleepCommthdMsg));
00274     CmiSetHandler(msg, sleep_commthd_idx);
00275     CmiBecomeImmediate(msg);
00276     CmiPushImmediateMsg(msg);
00277   }
00278 #endif
00279 }

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

00034                                                                                          {
00035     int msgsize = sizeof(DataMessage) + size;
00036     DataMessage *dmsg = (DataMessage *)CmiAlloc(msgsize);
00037     dmsg->setMessage(data,CkMyPe(),CmiMyPartition(),size,handler,code);
00038 #if CMK_HAS_PARTITION
00039     CmiInterSyncSendAndFree(dst,dstPart,msgsize,(char*)dmsg);
00040 #else
00041     CmiSyncSendAndFree(dst,msgsize,(char*)dmsg);
00042 #endif
00043   }

void recvAck ( DataMessage dmsg  ) 

Definition at line 99 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

00099                                   {
00100     if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvAck!");
00101     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_ack();
00102     CmiFree(dmsg);
00103   }

void recvBcast ( DataMessage dmsg  ) 

Definition at line 105 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

00105                                     {
00106     if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvBcast!");
00107     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_bcast();
00108     CmiFree(dmsg);
00109   }

void recvData ( DataMessage dmsg  ) 

Definition at line 93 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

00093                                    {
00094     Pointer msg(dmsg);
00095     if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvData!");
00096     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_data(msg);
00097   }

void recvEvalCommand ( DataMessage dmsg  ) 

Definition at line 121 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

00121                                           {
00122     Pointer msg(dmsg);
00123     if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvEvalCommand!");
00124     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_eval_command(msg);
00125   }

void recvEvalResult ( DataMessage dmsg  ) 

Definition at line 127 of file DataExchanger.C.

References CPROXY_DE, and NAMD_bug().

Referenced by initializeReplicaConverseHandlers().

00127                                          {
00128     Pointer msg(dmsg);
00129     if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) NAMD_bug("BOCgroup::dataExchanger is zero in recvEvalResult!");
00130     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_eval_result(msg);
00131   }

void recvRed ( DataMessage dmsg  ) 

Definition at line 111 of file DataExchanger.C.

References CPROXY_DE, and recvRedCalledEarly.

Referenced by initializeReplicaConverseHandlers().

00111                                   {
00112     if ( CkpvAccess(BOCclass_group).dataExchanger.isZero() ) {
00113       ++recvRedCalledEarly;
00114       CmiFree(dmsg);
00115       return;
00116     }
00117     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_red();
00118     CmiFree(dmsg);
00119   }

void recvReplicaDcdAck ( ReplicaDcdAckMsg msg  ) 

Definition at line 87 of file DataExchanger.C.

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

Referenced by initializeReplicaConverseHandlers().

00087                                                 {
00088     CmiFree(msg);
00089     CollectionMaster::Object()->unblockPositions();
00090     CkpvAccess(_qd)->process();
00091   }

void recvReplicaDcdData ( ReplicaDcdDataMsg msg  ) 

Definition at line 82 of file DataExchanger.C.

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

Referenced by initializeReplicaConverseHandlers().

00082                                                   {
00083     Node::Object()->output->recvReplicaDcdData(msg);
00084     CmiFree(msg);
00085   }

void recvReplicaDcdInit ( ReplicaDcdInitMsg msg  ) 

Definition at line 77 of file DataExchanger.C.

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

Referenced by initializeReplicaConverseHandlers().

00077                                                   {
00078     Node::Object()->output->recvReplicaDcdInit(msg);
00079     CmiFree(msg);
00080   }

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

00168                          {
00169     for ( ; recvRedCalledEarly > 0; --recvRedCalledEarly ) CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv_red();
00170     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].barrier();
00171     CpvAccess(breakScheduler) = 0;
00172     while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
00173   }

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

00175                                                      {
00176     if ( root != 0 ) NAMD_bug("replica_bcast root must be zero");
00177     int rank = CmiMyPartition();
00178     int size = CmiNumPartitions();
00179     int i;
00180     for ( i=1; i<size; i*=2 );
00181     for ( i/=2; i>0; i/=2 ) {
00182       if ( rank & (i - 1) ) continue;
00183       if ( rank & i ) {
00184         int src = rank - i;
00185         //CkPrintf("rank %d recv from %d\n", rank, src);
00186         DataMessage *recvMsg = NULL;
00187         replica_recv(&recvMsg, src, CkMyPe());
00188         if ( recvMsg == NULL ) NAMD_bug("recvMsg == NULL in replica_bcast");
00189         if ( recvMsg->size != count ) NAMD_bug("size != count in replica_bcast");
00190         memcpy(buf, recvMsg->data, count);
00191         CmiFree(recvMsg);
00192       } else {
00193         int dst = rank + i;
00194         if ( dst < size ) {
00195           //CkPrintf("rank %d send to %d\n", rank, dst);
00196           replica_send(buf, count, dst, CkMyPe());
00197         }
00198       }
00199     }
00200   }

void replica_eval ( char *  cmdbuf,
int  targPart,
int  targPE,
DataMessage **  precvMsg 
)

Definition at line 159 of file DataExchanger.C.

References CPROXY_DE.

00159                                                                                     {
00160     Pointer sendPointer(cmdbuf);
00161     Pointer recvPointer((char *) precvMsg);
00162     int sendcount = strlen(cmdbuf) + 1;
00163     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].eval(sendPointer,sendcount,targPart,targPE,recvPointer);
00164     CpvAccess(breakScheduler) = 0;
00165     while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
00166   }

void replica_min_double ( double *  dat,
int  count 
)

Definition at line 202 of file DataExchanger.C.

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

Referenced by PatchMap::makePatches().

00202                                                   {
00203     int rank = CmiMyPartition();
00204     int size = CmiNumPartitions();
00205     for ( int i=1; i<size; i*=2 ) {
00206       if ( rank & i ) {
00207         int dst = rank - i;
00208         //CkPrintf("rank %d send to %d\n", rank, dst);
00209         replica_send((char*)dat, count * sizeof(double), dst, CkMyPe());
00210       } else {
00211         int src = rank + i;
00212         if ( src < size ) {
00213           //CkPrintf("rank %d recv from %d\n", rank, src);
00214           DataMessage *recvMsg = NULL;
00215           replica_recv(&recvMsg, src, CkMyPe());
00216           if ( recvMsg == NULL ) NAMD_bug("recvMsg == NULL in replica_bcast");
00217           if ( recvMsg->size != count * sizeof(double) ) NAMD_bug("size != count in replica_min_double");
00218           double *rdat = new double[count];
00219           memcpy(rdat, recvMsg->data, count * sizeof(double));
00220           CmiFree(recvMsg);
00221           for ( int j=0; j<count; ++j ) {
00222             if ( rdat[j] < dat[j] ) dat[j] = rdat[j];
00223           }
00224           delete [] rdat;
00225         }
00226       }
00227       if ( rank & (2 * i - 1) ) break;
00228     }
00229     replica_bcast((char*)dat, count * sizeof(double), 0);
00230   }

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

00144                                                                     {
00145     Pointer recvPointer((char *) precvMsg);
00146     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].recv(recvPointer,srcPart,srcPE);
00147     CpvAccess(breakScheduler) = 0;
00148     while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
00149   }

void replica_send ( 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().

00133                                                                            {
00134     if ( CpvAccess(inEval) ) {
00135       packSend(destPE,destPart,sndbuf,sendcount,CkpvAccess(recv_data_idx),1);
00136       return;
00137     }
00138     Pointer sendPointer(sndbuf);
00139     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].send(sendPointer,sendcount,destPart,destPE); 
00140     CpvAccess(breakScheduler) = 0;
00141     while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
00142   }

void replica_sendRecv ( 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.

00151                                                                                                                                 {
00152     Pointer sendPointer(sndbuf);
00153     Pointer recvPointer((char *) precvMsg);
00154     CPROXY_DE(CkpvAccess(BOCclass_group).dataExchanger)[CkMyPe()].sendRecv(sendPointer,sendcount,destPart,destPE,recvPointer,srcPart,srcPE);
00155     CpvAccess(breakScheduler) = 0;
00156     while(!CpvAccess(breakScheduler)) CsdSchedulePoll();
00157   }

void sendReplicaDcdAck ( int  dstPart,
ReplicaDcdAckMsg msg 
)

Definition at line 67 of file DataExchanger.C.

References ReplicaDcdAckMsg::core.

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

00067                                                              {
00068     CmiSetHandler(msg->core, CkpvAccess(recv_replica_dcd_ack_idx));
00069     int msgsize = sizeof(ReplicaDcdAckMsg);
00070 #if CMK_HAS_PARTITION
00071     CmiInterSyncSendAndFree(0,dstPart,msgsize,(char*)msg);
00072 #else
00073     CmiSyncSendAndFree(0,msgsize,(char*)msg);
00074 #endif
00075   }

void sendReplicaDcdData ( int  dstPart,
ReplicaDcdDataMsg msg,
int  msgsize 
)

Definition at line 56 of file DataExchanger.C.

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

00056                                                                             {
00057     CmiSetHandler(msg->core, CkpvAccess(recv_replica_dcd_data_idx));
00058 #if CMK_HAS_PARTITION
00059     CmiInterSyncSendAndFree(0,dstPart,msgsize,(char*)msg);
00060 #else
00061     CmiSyncSendAndFree(0,msgsize,(char*)msg);
00062 #endif
00063     CollectionMaster::Object()->blockPositions();  // ensure ordering
00064     CkpvAccess(_qd)->create();  // ensure completion
00065   }

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

00045                                                                             {
00046     CmiSetHandler(msg->core, CkpvAccess(recv_replica_dcd_init_idx));
00047 #if CMK_HAS_PARTITION
00048     CmiInterSyncSendAndFree(0,dstPart,msgsize,(char*)msg);
00049 #else
00050     CmiSyncSendAndFree(0,msgsize,(char*)msg);
00051 #endif
00052     CollectionMaster::Object()->blockPositions();  // ensure ordering
00053     CkpvAccess(_qd)->create();  // ensure completion
00054   }


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


Generated on Mon Nov 20 01:17:15 2017 for NAMD by  doxygen 1.4.7