Two changes, initComlibManager is no longer an initproc call
[charm.git] / src / ck-com / PrioStreaming.C
1 #include "PrioStreaming.h"
2 #include "MsgPacker.h"
3
4 PrioStreaming::PrioStreaming(int periodMs,int bufferMax_, int prio)
5     : StreamingStrategy(periodMs, bufferMax_), basePriority(prio)
6 {
7 }
8
9 void PrioStreaming::insertMessage(CharmMessageHolder *cmsg) {
10
11     ComlibPrintf("Prio Straming: InsertMessage %d, %d\n",  
12                  PERIOD, bufferMax);
13
14     int pe=cmsg->dest_proc;
15     char* msg = cmsg->getCharmMessage();
16     envelope *env = UsrToEnv(msg);
17     int msg_prio = *(int*)env->getPrioPtr();
18
19     if(streamingMsgCount[pe] == 0) 
20         minPrioVec[pe] = msg_prio;
21     else if(minPrioVec[pe] > msg_prio)
22         minPrioVec[pe] = msg_prio;
23
24     streamingMsgBuf[pe].enq(cmsg);
25     streamingMsgCount[pe]++;   
26
27     if(msg_prio <= basePriority)
28         flushPE(pe);
29
30     if (streamingMsgCount[pe] > bufferMax) 
31         flushPE(pe);
32 }
33
34 void PrioStreaming::pup(PUP::er &p){
35
36     StreamingStrategy::pup(p);
37     p | basePriority;
38
39     if(p.isUnpacking())
40         minPrioVec.resize(CkNumPes());
41 }