Clean up some compiler warnings
[charm.git] / src / ck-com / PipeBroadcastStrategy.C
1 /**
2    @addtogroup ComlibCharmStrategy
3    @{
4    @file 
5 */
6
7 #include "PipeBroadcastStrategy.h"
8
9 PipeBroadcastStrategy::PipeBroadcastStrategy(int _topology, CkArrayID _aid, int _pipeSize)
10   : PipeBroadcastConverse(_topology, _pipeSize), CharmStrategy() {
11   ComlibPrintf("Creating charm pipebcast (%x)\n",this);
12   setType(ARRAY_STRATEGY);
13   ainfo.setDestinationArray(_aid);
14   //commonInit(_topology, _pipeSize);
15 }
16
17 PipeBroadcastStrategy::PipeBroadcastStrategy(CkGroupID _gid, int _topology, int _pipeSize)
18   : PipeBroadcastConverse(_topology, _pipeSize), CharmStrategy() {
19   setType(GROUP_STRATEGY);
20   //ginfo.setSourceGroup(_gid);
21   //commonInit(_topology, _pipeSize);
22 }
23
24 CmiFragmentHeader *PipeBroadcastStrategy::getFragmentHeader(char *msg) {
25   return (CmiFragmentHeader*)EnvToUsr((envelope*)msg);
26 }
27
28 void PipeBroadcastStrategy::deliver(char *msg, int dim) {
29   envelope *env = (envelope*)msg;
30   ComlibPrintf("[%d] PipeBroadcastStrategy::deliver\n",CkMyPe());
31   CkUnpackMessage(&env);
32   //ComlibPrintf("isArray = %d\n", (getType() == ARRAY_STRATEGY));
33
34   if (getType() == ARRAY_STRATEGY) {
35     // deliver the message to the predefined group "ainfo"
36     ainfo.localBroadcast(env);
37   }
38
39   if (getType() == GROUP_STRATEGY) {
40     // deliver the message to the predifined group "ginfo"
41     //CkGroupID gid;
42     //ginfo.getSourceGroup(gid);
43     CkSendMsgBranchInline(env->getEpIdx(), EnvToUsr(env), CkMyPe(), env->getGroupNum());
44   }
45 }
46
47 /*
48 void PipeBroadcastStrategy::commonInit(int _topology, int _pipeSize) {
49   converseStrategy = new PipeBroadcastConverse(_topology, _pipeSize, this);
50 }
51
52 PipeBroadcastStrategy::PipeBroadcastStrategy(int _topology, int _pipeSize)
53   : CharmStrategy() {
54   //isArray = 0;
55   commonInit(_topology, _pipeSize);
56 }
57
58 void PipeBroadcastStrategy::insertMessage(CharmMessageHolder *cmsg){
59   messageBuf->enq(cmsg);
60   doneInserting();
61 }
62
63
64 // routine for interfacing with converse.
65 // Require only the converse reserved header if forceSplit is true
66 void PipeBroadcastStrategy::conversePipeBcast(envelope *env, int totalSize) {
67   // set the instance ID to be used by the receiver using the XHandler variable
68   CmiSetXHandler(env, myInstanceID);
69   ComlibPrintf("[%d] PipeBroadcast charm, setting instid to %d\n",CkMyPe(),myInstanceID);
70
71   if (totalSize > ((PipeBroadcastConverse*)converseStrategy)->getPipeSize()) {
72     ((PipeBroadcastConverse*)converseStrategy)->conversePipeBcast((char*)env, totalSize);
73   } else {
74     // the message fit into the pipe, so send it in a single chunk
75     ComlibPrintf("[%d] Propagating message in one single chunk (%d)\n",CkMyPe(),CsvAccess(pipeBcastPropagateHandle));
76     CmiSetHandler(env, CsvAccess(pipeBcastPropagateHandle));
77     env->setSrcPe(CkMyPe());
78     ((PipeBroadcastConverse*)converseStrategy)->propagate((char*)env, false, CkMyPe(), totalSize, &envelope::setSrcPe);
79   }
80 }
81
82 void PipeBroadcastStrategy::doneInserting(){
83   ComlibPrintf("[%d] DoneInserting\n",CkMyPe());
84   while (!messageBuf->isEmpty()) {
85     CharmMessageHolder *cmsg = messageBuf->deq();
86     // modify the Handler to deliver the message to the propagator
87     envelope *env = UsrToEnv(cmsg->getCharmMessage());
88
89     delete cmsg;
90     conversePipeBcast(env, env->getTotalsize());
91   }
92 }
93 */
94
95 void PipeBroadcastStrategy::pup(PUP::er &p){
96   ComlibPrintf("[%d] PipeBroadcastStrategy::pup %s\n",CkMyPe(), (p.isPacking()==0)?(p.isUnpacking()?"UnPacking":"sizer"):("Packing"));
97   PipeBroadcastConverse::pup(p);
98   CharmStrategy::pup(p);
99
100   /*
101   if (p.isUnpacking()) {
102     converseStrategy = new PipeBroadcastConverse(0,0,this);
103   }
104   p | *converseStrategy;
105
106   if (p.isUnpacking()) {
107     //propagateHandle = CmiRegisterHandler((CmiHandler)propagate_handler);
108
109     ComlibPrintf("[%d] registered handler single to %d\n",CmiMyPe(),CsvAccess(pipeBcastPropagateHandle));
110     messageBuf = new CkQ<CharmMessageHolder *>;
111     converseStrategy->setHigherLevel(this);
112   }
113   */
114 }
115
116 /*
117 void PipeBroadcastStrategy::beginProcessing(int x){ 
118   CsvAccess(pipeBcastPropagateHandle) = CkRegisterHandler((CmiHandler)propagate_handler);
119 }
120 */
121
122 /*@}*/