Exemplo n.º 1
0
void* CkPriorityPtr(void *msg)
{
#if CMK_ERROR_CHECKING
  if (UsrToEnv(msg)->getPriobits() == 0) CkAbort("Trying to access priority bits, but none was allocated");
#endif
  return UsrToEnv(msg)->getPrioPtr();
}
Exemplo n.º 2
0
// Function called right before an entry method
void CpdBeforeEp(int ep, void *obj, void *msg) {
#if CMK_CHARMDEBUG
  if (CpvAccess(cmiArgDebugFlag)) {
    DebugRecursiveEntry entry;
    entry.previousChareID = setMemoryChareIDFromPtr(obj);
    entry.alreadyUserCode = _entryTable[ep]->inCharm ? 0 : 1;
    entry.memoryBackup = NULL;
    entry.obj = obj;
    if (msg != NULL) {
      entry.msg = msg;
      CmiReference(UsrToEnv(msg));
    }
    else entry.msg = NULL;
    _debugData.push(entry);
    setMemoryStatus(entry.alreadyUserCode);
    //if (CkpvAccess(_debugEntryTable)[ep].isBreakpoint) printf("CpdBeforeEp breakpointed %d\n",ep);
    memoryBackup = &_debugData.peek().memoryBackup;
    if (!_entryTable[ep]->inCharm) {
      CpdResetMemory();
      CpdSystemExit();
    }
    CkVec<DebugPersistentCheck> &preExecutes = CkpvAccess(_debugEntryTable)[ep].preProcess;
    for (int i=0; i<preExecutes.size(); ++i) {
      preExecutes[i].object->cpdCheck(preExecutes[i].msg);
    }
  }
#endif
}
Exemplo n.º 3
0
// handle GroupTable and data
void CkPupGroupData(PUP::er &p, CmiBool create)
{
	int numGroups, i;

	if (!p.isUnpacking()) {
	  numGroups = CkpvAccess(_groupIDTable)->size();
	}
	p|numGroups;
	if (p.isUnpacking()) {
	  if(CkMyPe()==0)  
            CkpvAccess(_numGroups) = numGroups+1; 
          else 
	    CkpvAccess(_numGroups) = 1;
	}
	DEBCHK("[%d] CkPupGroupData %s: numGroups = %d\n", CkMyPe(),p.typeString(),numGroups);

	GroupInfo *tmpInfo = new GroupInfo [numGroups];
	if (!p.isUnpacking()) {
	  for(i=0;i<numGroups;i++) {
		tmpInfo[i].gID = (*CkpvAccess(_groupIDTable))[i];
		TableEntry ent = CkpvAccess(_groupTable)->find(tmpInfo[i].gID);
		tmpInfo[i].MigCtor = _chareTable[ent.getcIdx()]->migCtor;
		tmpInfo[i].DefCtor = _chareTable[ent.getcIdx()]->defCtor;
		strncpy(tmpInfo[i].name,_chareTable[ent.getcIdx()]->name,255);
		//CkPrintf("[%d] CkPupGroupData: %s group %s \n", CkMyPe(), p.typeString(), tmpInfo[i].name);

		if(tmpInfo[i].MigCtor==-1) {
			char buf[512];
			sprintf(buf,"Group %s needs a migration constructor and PUP'er routine for restart.\n", tmpInfo[i].name);
			CkAbort(buf);
		}
	  }
  	}
	for (i=0; i<numGroups; i++) p|tmpInfo[i];

	for(i=0;i<numGroups;i++) 
	{
	  CkGroupID gID = tmpInfo[i].gID;
	  if (p.isUnpacking()) {
	    //CkpvAccess(_groupIDTable)->push_back(gID);
	    int eIdx = tmpInfo[i].MigCtor;
	    // error checking
	    if (eIdx == -1) {
	      CkPrintf("[%d] ERROR> Group %s's migration constructor is not defined!\n", CkMyPe(), tmpInfo[i].name); CkAbort("Abort");
	    }
	    void *m = CkAllocSysMsg();
	    envelope* env = UsrToEnv((CkMessage *)m);
		if(create)
		    CkCreateLocalGroup(gID, eIdx, env);
	  }   // end of unPacking
	  IrrGroup *gobj = CkpvAccess(_groupTable)->find(gID).getObj();
	  // if using migration constructor, you'd better have a pup
	  	if(!create)
			gobj->mlogData->teamRecoveryFlag = 1;
          gobj->pup(p);
         // CkPrintf("Group PUP'ed: gid = %d, name = %s\n",gobj->ckGetGroupID().idx, tmpInfo[i].name);
	}
	delete [] tmpInfo;
}
Exemplo n.º 4
0
static inline void _sendStats(void)
{
  DEBUGF(("[%d] _sendStats\n", CkMyPe()));
  envelope *env = UsrToEnv(CkpvAccess(_myStats));
  env->setSrcPe(CkMyPe());
  CmiSetHandler(env, _exitHandlerIdx);
  CmiSyncSendAndFree(0, env->getTotalsize(), (char *)env);
}
Exemplo n.º 5
0
void* CkCopyMsg(void **pMsg)
{// cannot simply memcpy, because srcMsg could be varsize msg
  register void *srcMsg = *pMsg;
  register envelope *env = UsrToEnv(srcMsg);
  register unsigned char msgidx = env->getMsgIdx();
  if(!env->isPacked() && _msgTable[msgidx]->pack) {
    srcMsg = _msgTable[msgidx]->pack(srcMsg);
    UsrToEnv(srcMsg)->setPacked(1);
  }
  register int size = UsrToEnv(srcMsg)->getTotalsize();
  register envelope *newenv = (envelope *) CmiAlloc(size);
  CmiMemcpy(newenv, UsrToEnv(srcMsg), size);
  //memcpy(newenv, UsrToEnv(srcMsg), size);
  if(UsrToEnv(srcMsg)->isPacked() && _msgTable[msgidx]->unpack) {
    srcMsg = _msgTable[msgidx]->unpack(srcMsg);
    UsrToEnv(srcMsg)->setPacked(0);
  }
  *pMsg = srcMsg;
  if(newenv->isPacked() && _msgTable[msgidx]->unpack) {
    srcMsg = _msgTable[msgidx]->unpack(EnvToUsr(newenv));
    UsrToEnv(srcMsg)->setPacked(0);
  } else srcMsg = EnvToUsr(newenv);

  setMemoryTypeMessage(newenv);
  return srcMsg;
}
Exemplo n.º 6
0
void alignmentTest(std::vector<TestMessage*> &allMsgs, const std::string &identifier) {

  int alignHdr = std::numeric_limits<int>::max();
  int alignEnv = std::numeric_limits<int>::max();
  int alignUsr = std::numeric_limits<int>::max();
  int alignVar1 = std::numeric_limits<int>::max();
  int alignVar2 = std::numeric_limits<int>::max();
  int alignPrio = std::numeric_limits<int>::max();

  for (int i = 0; i < allMsgs.size(); i++) {
    TestMessage *msg = allMsgs[i];
    envelope *env = UsrToEnv(msg);

#if CMK_USE_IBVERBS | CMK_USE_IBUD
    intptr_t startHdr = (intptr_t) &(((infiCmiChunkHeader *) env)[-1]);
#else
    intptr_t startHdr = (intptr_t) BLKSTART(env);
#endif
    intptr_t startEnv = (intptr_t) env;
    intptr_t startUsr = (intptr_t) msg;
    intptr_t startVar1 = (intptr_t) msg->varArray1;
    intptr_t startVar2 = (intptr_t) msg->varArray2;
    intptr_t startPrio = (intptr_t) env->getPrioPtr();

    if (! (startHdr < startEnv && startEnv < startUsr &&
           startUsr <= startVar1 && startVar1 < startVar2 &&
           startVar2 < startPrio)) {
      CkAbort("Charm++ fatal error. Pointers to component fields "
              "of a message do not follow an increasing order.\n");
    }
    alignHdr = std::min(alignCheck(startHdr), alignHdr);
    alignEnv = std::min(alignCheck(startEnv), alignEnv);
    alignUsr = std::min(alignCheck(startUsr), alignUsr);
    alignVar1 = std::min(alignCheck(startVar1), alignVar1);
    alignVar2 = std::min(alignCheck(startVar2), alignVar2);
    alignPrio = std::min(alignCheck(startPrio), alignPrio);
  }

  CkPrintf("Alignment information at the %s:\n", identifier.c_str());
  CkPrintf("Chunk header aligned to %d bytes\n", alignHdr);
  CkPrintf("Envelope aligned to %d bytes\n", alignEnv);
  CkPrintf("Start of user data aligned to %d bytes\n", alignUsr);
  CkPrintf("First varsize array aligned to %d bytes\n", alignVar1);
  CkPrintf("Second varsize array aligned to %d bytes\n", alignVar2);
  CkPrintf("Priority field aligned to %d bytes\n", alignPrio);

  if (alignEnv >= ALIGN_BYTES && alignUsr >= ALIGN_BYTES &&
      alignVar1 >= ALIGN_BYTES && alignVar2 >= ALIGN_BYTES &&
      alignHdr >= ALIGN_BYTES && alignPrio >= ALIGN_BYTES) {
    CkPrintf("All passed.\n");
  }
  else {
    CkAbort("Alignment requirements failed.\n");
  }

}
Exemplo n.º 7
0
CkMarshallMsg *CkAllocateMarshallMsgNoninline(int size,const CkEntryOptions *opts)
{
	//Allocate the message
	CkMarshallMsg *m=new (size,opts->getPriorityBits())CkMarshallMsg;
	//Copy the user's priority data into the message
	envelope *env=UsrToEnv(m);
	setMemoryTypeMessage(env);
	if (opts->getPriorityPtr() != NULL)
	CmiMemcpy(env->getPrioPtr(),opts->getPriorityPtr(),env->getPrioBytes());
	//Set the message's queueing type
	env->setQueueing((unsigned char)opts->getQueueing());
	env->setGroupDep(opts->getGroupDepID());
	return m;
}
Exemplo n.º 8
0
// handle NodeGroupTable and data
void CkPupNodeGroupData(PUP::er &p, CmiBool create)
{
	int numNodeGroups, i;
	if (!p.isUnpacking()) {
	  numNodeGroups = CksvAccess(_nodeGroupIDTable).size();
	}
	p|numNodeGroups;
	if (p.isUnpacking()) {
	  if(CkMyPe()==0){ CksvAccess(_numNodeGroups) = numNodeGroups+1; }
	  else { CksvAccess(_numNodeGroups) = 1; }
	}
	if(CkMyPe() == 3)
	CkPrintf("[%d] CkPupNodeGroupData %s: numNodeGroups = %d\n",CkMyPe(),p.typeString(),numNodeGroups);

	GroupInfo *tmpInfo = new GroupInfo [numNodeGroups];
	if (!p.isUnpacking()) {
	  for(i=0;i<numNodeGroups;i++) {
		tmpInfo[i].gID = CksvAccess(_nodeGroupIDTable)[i];
		TableEntry ent2 = CksvAccess(_nodeGroupTable)->find(tmpInfo[i].gID);
		tmpInfo[i].MigCtor = _chareTable[ent2.getcIdx()]->migCtor;
		if(tmpInfo[i].MigCtor==-1) {
			char buf[512];
			sprintf(buf,"NodeGroup %s either need a migration constructor and\n\
				     declared as [migratable] in .ci to be able to checkpoint.",\
				     _chareTable[ent2.getcIdx()]->name);
			CkAbort(buf);
		}
	  }
	}
	for (i=0; i<numNodeGroups; i++) p|tmpInfo[i];
	for (i=0;i<numNodeGroups;i++) {
		CkGroupID gID = tmpInfo[i].gID;
		if (p.isUnpacking()) {
			//CksvAccess(_nodeGroupIDTable).push_back(gID);
			int eIdx = tmpInfo[i].MigCtor;
			void *m = CkAllocSysMsg();
			envelope* env = UsrToEnv((CkMessage *)m);
			if(create){
				CkCreateLocalNodeGroup(gID, eIdx, env);
			}
		}
		TableEntry ent2 = CksvAccess(_nodeGroupTable)->find(gID);
		IrrGroup *obj = ent2.getObj();
		obj->pup(p);
		if(CkMyPe() == 3) CkPrintf("Nodegroup PUP'ed: gid = %d, name = %s\n",
			obj->ckGetGroupID().idx,
			_chareTable[ent2.getcIdx()]->name);
	}
	delete [] tmpInfo;
}
Exemplo n.º 9
0
void* CkAllocBuffer(void *msg, int bufsize)
{
  bufsize = CkMsgAlignLength(bufsize);
  register envelope *env = UsrToEnv(msg);
  register envelope *packbuf;
  packbuf = _allocEnv(env->getMsgtype(), bufsize, 
                      env->getPriobits());
  
  register int size = packbuf->getTotalsize();
  CmiMemcpy(packbuf, env, sizeof(envelope));
  packbuf->setTotalsize(size);
  packbuf->setPacked(!env->isPacked());
  CmiMemcpy(packbuf->getPrioPtr(), env->getPrioPtr(), packbuf->getPrioBytes());

  return EnvToUsr(packbuf);;
}
Exemplo n.º 10
0
	virtual void ArraySend(CkDelegateData *pd,int ep,void *m,const CkArrayIndex &idx,CkArrayID a)
	{
		CkArray *arrMgr=CProxy_CkArray(a).ckLocalBranch();
		int onPE=arrMgr->lastKnown(idx);
		if (onPE==CkMyPe()) 
		{ //Send to local element
			arrMgr->deliver((CkMessage *)m, CkDeliver_queue);
		} else 
		{ //Forward to remote element
			ckout<<"DelegateMgr> Sending message for "<<idx.data()[0]<<" to "<<onPE<<endl;
			envelope *env=UsrToEnv(m);
			CkPackMessage(&env);
			forwardMsg(ep,idx,a,env->getTotalsize(),(char *)env);
			CkFreeMsg(m);
		}
	}
Exemplo n.º 11
0
// default load balancing strategy
LBMigrateMsg* CentralLB::Strategy(LDStats* stats)
{
#if CMK_LBDB_ON
  double strat_start_time = CkWallTimer();
  if (_lb_args.debug())
    CkPrintf("CharmLB> %s: PE [%d] strategy starting at %f\n", lbname, cur_ld_balancer, strat_start_time);

  work(stats);


  if (_lb_args.debug()>2)  {
    CkPrintf("CharmLB> Obj Map:\n");
    for (int i=0; i<stats->n_objs; i++) CkPrintf("%d ", stats->to_proc[i]);
    CkPrintf("\n");
  }

  LBMigrateMsg *msg = createMigrateMsg(stats);

	/* Extra feature for MetaBalancer
  if (_lb_args.metaLbOn()) {
    int clients = CkNumPes();
    LBInfo info(clients);
    getPredictedLoadWithMsg(stats, clients, msg, info, 0);
    LBRealType mLoad, mCpuLoad, totalLoad, totalLoadWComm;
    info.getSummary(mLoad, mCpuLoad, totalLoad);
    theLbdb->UpdateDataAfterLB(mLoad, mCpuLoad, totalLoad/clients);
  }
	*/

  if (_lb_args.debug()) {
    double strat_end_time = CkWallTimer();
    envelope *env = UsrToEnv(msg);

    double lbdbMemsize = LBDatabase::Object()->useMem()/1000;
    CkPrintf("CharmLB> %s: PE [%d] Memory: LBManager: %d KB CentralLB: %d KB\n",
  	      lbname, cur_ld_balancer, (int)lbdbMemsize, (int)(useMem()/1000));
    CkPrintf("CharmLB> %s: PE [%d] #Objects migrating: %d, LBMigrateMsg size: %.2f MB\n", lbname, cur_ld_balancer, msg->n_moves, env->getTotalsize()/1024.0/1024.0);
    CkPrintf("CharmLB> %s: PE [%d] strategy finished at %f duration %f s\n",
	      lbname, cur_ld_balancer, strat_end_time, strat_end_time-strat_start_time);
    theLbdb->SetStrategyCost(strat_end_time - strat_start_time);
  }
  return msg;
#else
  return NULL;
#endif
}
Exemplo n.º 12
0
void CkArrayReductionMgr::startNodeGroupReduction(int number,CkGroupID groupID){
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
    Chare *oldObj =CpvAccess(_currentObj);
    CpvAccess(_currentObj) = this;
#endif
	ARPRINT("[%d] startNodeGroupReductions for red No %d my group %d attached group %d on %p \n",CkMyNode(),number,thisgroup.idx, attachedGroup.idx,this);
	if(attachedGroup.isZero()){
		setAttachedGroup(groupID);
	}
	startLocalGroupReductions(number);
	CkReductionNumberMsg *msg = new CkReductionNumberMsg(number);
	envelope::setSrcPe((char *)UsrToEnv(msg),CkMyNode());
	((CkNodeReductionMgr *)this)->ReductionStarting(msg);
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
    CpvAccess(_currentObj) = oldObj;
#endif
}
Exemplo n.º 13
0
//Send the multicast message the local array elements. The message is 
//copied and sent if elements exist. 
void RectMulticastStrategy::localMulticast(envelope *env, 
					   ComlibRectSectionHashObject *obj) {
    int nIndices = obj->indices.size();
    
    if(obj->msg != NULL) {
        CmiFree(obj->msg);
	obj->msg = NULL;
    } 
    
    if(nIndices > 0) {
	void *msg = EnvToUsr(env);
	void *msg1 = msg;
        
        msg1 = CkCopyMsg(&msg);
	
        ComlibArrayInfo::localMulticast(&(obj->indices), UsrToEnv(msg1));
    }    
}
Exemplo n.º 14
0
// Function called right after an entry method
void CpdAfterEp(int ep) {
#if CMK_CHARMDEBUG
  if (CpvAccess(cmiArgDebugFlag)) {
    DebugRecursiveEntry entry = _debugData.peek();
    CkVec<DebugPersistentCheck> &postExecutes = CkpvAccess(_debugEntryTable)[ep].postProcess;
    for (int i=0; i<postExecutes.size(); ++i) {
      postExecutes[i].object->cpdCheck(postExecutes[i].msg);
    }
    memoryBackup = &entry.memoryBackup;
    if (!_entryTable[ep]->inCharm) {
      CpdSystemEnter();
      CpdCheckMemory();
    }
    if (entry.msg != NULL) CmiFree(UsrToEnv(entry.msg));
    setMemoryChareID(entry.previousChareID);
    setMemoryStatus(entry.alreadyUserCode);
    _debugData.deq();
  }
#endif
}
Exemplo n.º 15
0
void main::recv(testMsg *msg)
{
  CkPrintf("message as received\n");
    // get pointer to envelope header
    unsigned char *env= (unsigned char*) UsrToEnv(msg);
    unsigned char *hdr= (unsigned char*) msg;
    hdr-=sizeof(envelope);
    hdr-=CmiReservedHeaderSize;
    // output converse header field by field
    
    // output converse header byte by byte
    CkPrintf("CmiHeader\n");
    for(int i=0;i<CmiReservedHeaderSize;i++)
      CkPrintf("%03u|",hdr[i]);
    CkPrintf("\n");
    CkPrintf("Envelope\n");
    for(int i=0;i<sizeof(envelope);i++)
      CkPrintf("%03u|",env[i]);
    CkPrintf("\n");
    CkExit();
}
Exemplo n.º 16
0
  virtual void pup(PUP::er &p, CpdListItemsRequest &req) {
    int length;
    void ** messages;
    int curObj=0;
    void *msg;

    length = CdsFifo_Length((CdsFifo)(CpvAccess(conditionalQueue)));
    messages = CdsFifo_Enumerate(CpvAccess(conditionalQueue));
    for (curObj=-length; curObj<0; curObj++) {
      void *msg = messages[length+curObj];
      pupSingleMessage(p, curObj-1, msg);
    }
    delete[] messages;
    
    curObj = 0;
    length = CdsFifo_Length((CdsFifo)(CkpvAccess(debugQueue)));
    messages = CdsFifo_Enumerate(CkpvAccess(debugQueue));
    
    if (CkpvAccess(lastBreakPointMsg) != NULL) {
      beginItem(p, -1);
      envelope *env=(envelope *)UsrToEnv(CkpvAccess(lastBreakPointMsg));
      p.comment("name");
      char *type=(char*)"Breakpoint";
      p(type,strlen(type));
      p.comment("charmMsg");
      p.synchronize(PUP::sync_begin_object);
      CkUnpackMessage(&env);
      CpdPupMessage(p, EnvToUsr(env));
      p.synchronize(PUP::sync_end_object);
    }

    for(curObj=req.lo; curObj<req.hi; curObj++)
      if ((curObj>=0) && (curObj<length))
      {
        void *msg=messages[curObj]; /* converse message */
        pupSingleMessage(p, curObj, msg);
      }
    delete[] messages;

  }
Exemplo n.º 17
0
// handle plain non-migratable chare
void CkPupChareData(PUP::er &p)
{
  int i, n;
  if (!p.isUnpacking()) n = CkpvAccess(chare_objs).size();
  p|n;
  for (i=0; i<n; i++) {
        int chare_type;
	if (!p.isUnpacking()) {
		chare_type = CkpvAccess(chare_types)[i];
	}
	p | chare_type;
	if (p.isUnpacking()) {
		int migCtor = _chareTable[chare_type]->migCtor;
		if(migCtor==-1) {
			char buf[512];
			sprintf(buf,"Chare %s needs a migration constructor and PUP'er routine for restart.\n", _chareTable[chare_type]->name);
			CkAbort(buf);
		}
	        void *m = CkAllocSysMsg();
	        envelope* env = UsrToEnv((CkMessage *)m);
		CkCreateLocalChare(migCtor, env);
		CkFreeSysMsg(m);
	}
	Chare *obj = (Chare*)CkpvAccess(chare_objs)[i];
	obj->pup(p);
  }

  if (!p.isUnpacking()) n = CkpvAccess(vidblocks).size();
  p|n;
  for (i=0; i<n; i++) {
	VidBlock *v;
	if (p.isUnpacking()) {
		v = new VidBlock();
		CkpvAccess(vidblocks).push_back(v);
	}
	else
		v = CkpvAccess(vidblocks)[i];
	v->pup(p);
  }
}
Exemplo n.º 18
0
void CpdDeliverSingleMessage () {
  if (!CpdIsFrozen()) return; /* Do something only if we are in freeze mode */
  if ( (CkpvAccess(lastBreakPointMsg) != NULL) && (CkpvAccess(lastBreakPointObject) != NULL) ) {
    EntryInfo * breakPointEntryInfo = CpvAccess(breakPointEntryTable)->get(CkpvAccess(lastBreakPointIndex));
    if (breakPointEntryInfo != NULL) {
      if (_conditionalDelivery) {
        if (_conditionalDelivery==1) conditionalShm->msgs[conditionalShm->count++] = -1;
        void *env = UsrToEnv(CkpvAccess(lastBreakPointMsg));
        CmiReference(env);
        CdsFifo_Enqueue(CpvAccess(conditionalQueue),env);
      }
      breakPointEntryInfo->call(CkpvAccess(lastBreakPointMsg), CkpvAccess(lastBreakPointObject));
    }
    CkpvAccess(lastBreakPointMsg) = NULL;
    CkpvAccess(lastBreakPointObject) = NULL;
#if CMK_BIGSIM_CHARM
    ((workThreadInfo*)cta(threadinfo))->stopScheduler();
#endif
  }
  else {
    // we were not stopped at a breakpoint, then deliver the first message in the debug queue
    if (!CdsFifo_Empty(CkpvAccess(debugQueue))) {
      CkpvAccess(skipBreakpoint) = 1;
      char *queuedMsg = (char *)CdsFifo_Dequeue(CkpvAccess(debugQueue));
      if (_conditionalDelivery) {
        if (_conditionalDelivery==1) conditionalShm->msgs[conditionalShm->count++] = 0;
        CmiReference(queuedMsg);
        CdsFifo_Enqueue(CpvAccess(conditionalQueue),queuedMsg);
      }
#if CMK_BIGSIM_CHARM
      stopVTimer();
      BgProcessMessageDefault(cta(threadinfo), queuedMsg);
      startVTimer();
#else
      CmiHandleMessage(queuedMsg);
#endif
      CkpvAccess(skipBreakpoint) = 0;
    }
  }
}
Exemplo n.º 19
0
void NullLB::AtSync()
{
  // tried to reset the database so it doesn't waste memory
  // if nobody else is here, the stat collection is not even turned on
  // so I should not have to clear loads.
//  theLbdb->ClearLoads();
  
  // disable the batsyncer if no balancer exists
  // theLbdb->SetLBPeriod(1e10);

#if ! NULLLB_CONVERSE
  // prevent this charm message from being seen by QD
  // so that the QD detection works
  CpvAccess(_qd)->create(-1);
  thisProxy[CkMyPe()].migrationsDone();
#else
  // send converse message to escape the QD detection
  envelope *env = UsrToEnv(CkAllocSysMsg());
  CmiSetHandler(env, _migDoneHandle);
  CmiSyncSendAndFree(CkMyPe(), env->getTotalsize(), (char *)env);
#endif
}
Exemplo n.º 20
0
main::main(CkArgMsg *m) {
    delete m;
    mainProxy=thishandle;
    CmiPrintf("Info: converse header: %d envelope: %d\n", CmiReservedHeaderSize, sizeof(envelope));
    // make a message with 1 payload
    testMsg *msg = new testMsg;
    // get pointer to envelope header
    unsigned char *env= (unsigned char*) UsrToEnv(msg);
    unsigned char *hdr= (unsigned char*) msg;
    hdr-=sizeof(envelope);
    hdr-=CmiReservedHeaderSize;
    // output converse header field by field
    
    // output converse header byte by byte
    CkPrintf("CmiHeader\n");
    for(int i=0;i<CmiReservedHeaderSize;i++)
      CkPrintf("%03u|",hdr[i]);
    CkPrintf("\n");
    CkPrintf("Envelope\n");
    for(int i=0;i<sizeof(envelope);i++)
      CkPrintf("%03u|",env[i]);
    CkPrintf("\n");
    mainProxy.recv(msg);
  }
Exemplo n.º 21
0
void RectMulticastStrategy::insertMessage(CharmMessageHolder *cmsg){
  cmsg->checkme();

  
  //    ComlibPrintf("[%d] Comlib Rect Section Multicast: insertMessage \n", 


    if(cmsg->dest_proc == IS_SECTION_MULTICAST && cmsg->sec_id != NULL) { 
        CkSectionID *sid = cmsg->sec_id;
        int cur_sec_id = sid->getSectionID();
	ComlibPrintf("[%d] Comlib Rect Section Multicast: insertMessage section id %d\n", CkMyPe(), cur_sec_id);           
        if(cur_sec_id > 0) {        
            sinfo.processOldSectionMessage(cmsg);            

	    //	    ComlibPrintf("[%d] insertMessage old sectionid %d \n",CkMyPe(),cur_sec_id);
	    ComlibPrintf("[%d] insertMessage old sectionid %d \n",CkMyPe(),cur_sec_id);
            ComlibSectionHashKey 
                key(CkMyPe(), sid->_cookie.sInfo.cInfo.id);        
            ComlibRectSectionHashObject *obj = sec_ht.get(key);

            if(obj == NULL)
                CkAbort("Cannot Find Section\n");

            envelope *env = UsrToEnv(cmsg->getCharmMessage());
#ifndef LOCAL_MULTI_OFF
	    localMulticast(env, obj);
#endif
	    if(obj->sourceInRectangle) 
	      {
		remoteMulticast(env, obj);
	      }
	    else // forward
	      {
		forwardMulticast(env, obj);
	      }
        }
        else {
	  ComlibPrintf("[%d] insertMessage new section id %d\n", CkMyPe(), cur_sec_id);           
	  //New sec id, so send it along with the message
	  void *newmsg = sinfo.getNewMulticastMessage(cmsg, needSorting());
	  insertSectionID(sid);

	  ComlibSectionHashKey 
	    key(CkMyPe(), sid->_cookie.sInfo.cInfo.id);        
	  ComlibPrintf("[%d] insertMessage new sectionid %d \n",CkMyPe(),sid->_cookie.sInfo.cInfo.id);
	  ComlibRectSectionHashObject *obj = sec_ht.get(key);

	  if(obj == NULL)
	    CkAbort("Cannot Find Section\n");

	  /*
	    ComlibPrintf("%u: Src = %d dest:", key.hash(), CkMyPe());
	    for (int i=0; i<obj->npes; ++i)
	    ComlibPrintf(" %d",obj->pelist[i]);
	    ComlibPrintf(", map:");
	    ComlibMulticastMsg *lll = (ComlibMulticastMsg*)newmsg;
	    envelope *ppp = UsrToEnv(newmsg);
	    CkUnpackMessage(&ppp);
	    int ttt=0;
	    for (int i=0; i<lll->nPes; ++i) {
	    ComlibPrintf(" %d (",lll->indicesCount[i].pe);
	    for (int j=0; j<lll->indicesCount[i].count; ++j) {
	    ComlibPrintf(" %d",((int*)&(lll->indices[ttt]))[1]);
	    ttt++;
	    }
	    ComlibPrintf(" )");
	    }
	    CkPackMessage(&ppp);
	    ComlibPrintf("\n");
	  */
	  // our object needs indices, npes, pelist
	  sinfo.getRemotePelist(sid->_nElems, sid->_elems, obj->npes, obj->pelist);
	  sinfo.getLocalIndices(sid->_nElems, sid->_elems, obj->indices);
	  char *msg = cmsg->getCharmMessage();
	  /*
	    ComlibMulticastMsg *lll = (ComlibMulticastMsg*)newmsg;
	    envelope *ppp = UsrToEnv(newmsg);
	    CkUnpackMessage(&ppp);
	    int ttt=0;
	    int uuu=0;
	    for (int i=0; i<lll->nPes; ++i) {
	    //	      ComlibPrintf(" %d (",lll->indicesCount[i].pe);
	    uuu++;
	    for (int j=0; j<lll->indicesCount[i].count; ++j) {
	    //		ComlibPrintf(" %d",((int*)&(lll->indices[ttt]))[1]);
	    ttt++;
	    }
	    //	      ComlibPrintf(" )");
	    }


	    ComlibPrintf("[%d] newmsg for sendRectDest has %d indices %d pes\n",CkMyPe(),ttt, uuu);
	    CkAssert(uuu>0);
	    CkAssert(ttt>0);
	  */
	  envelope *ppp = UsrToEnv(newmsg);
	  CkPackMessage(&ppp);	    
#ifndef LOCAL_MULTI_OFF
	  localMulticast(UsrToEnv(msg), obj);
#endif

	  sendRectDest(obj ,CkMyPe(), UsrToEnv(newmsg));
	  //            CkFreeMsg(msg);	    // need this?

        }        
    }
    else 
        CkAbort("Section multicast cannot be used without a section proxy");

    delete cmsg;       
}
Exemplo n.º 22
0
/**
   Create a new multicast message based upon the section info stored inside cmsg.
*/
ComlibMulticastMsg * ComlibSectionInfo::getNewMulticastMessage(CharmMessageHolder *cmsg, int needSort, int instanceID){
    
  //  cmsg->checkme();

    if(cmsg->sec_id == NULL || cmsg->sec_id->_nElems == 0)
        return NULL;

    void *m = cmsg->getCharmMessage();
    envelope *env = UsrToEnv(m);
        
    // Crate a unique identifier for section id in cmsg->sec_id
    initSectionID(cmsg->sec_id);   

    CkPackMessage(&env);

    const CkArrayID destArrayID(env->getArrayMgr());
    int nRemotePes=-1, nRemoteIndices=-1;
    ComlibMulticastIndexCount *indicesCount;
    int *belongingList;


    //  Determine the last known locations of all the destination objects.
    getPeCount(cmsg->sec_id->_nElems, cmsg->sec_id->_elems, destArrayID, nRemotePes, nRemoteIndices, indicesCount, belongingList);

    //     if (nRemotePes == 0) return NULL;

#if 0
    CkPrintf("nRemotePes=%d\n", nRemotePes);
    CkPrintf("nRemoteIndices=%d\n",nRemoteIndices);
    CkPrintf("env->getTotalsize()=%d\n", env->getTotalsize());
    CkPrintf("cmsg->sec_id->_nElems=%d\n", cmsg->sec_id->_nElems);
 #endif

    int sizes[3];
    sizes[0] = nRemotePes;
    sizes[1] = nRemoteIndices; // only those remote ///cmsg->sec_id->_nElems;
    sizes[2] = env->getTotalsize();
    
    ComlibPrintf("Creating new comlib multicast message %d, %d %d\n", sizes[0], sizes[1], sizes[2]);
    
    ComlibMulticastMsg *msg = new(sizes, 0) ComlibMulticastMsg;
    msg->nPes = nRemotePes;
    msg->_cookie.info.sInfo.cInfo.instId = instanceID;
    msg->_cookie.info.sInfo.cInfo.id = MaxSectionID - 1;
    msg->_cookie.info.sInfo.cInfo.status = COMLIB_MULTICAST_NEW_SECTION;
    msg->_cookie.get_type() = COMLIB_MULTICAST_MESSAGE;
    msg->_cookie.get_pe() = CkMyPe();

    // fill in the three pointers of the ComlibMulticastMsg
    memcpy(msg->indicesCount, indicesCount, sizes[0] * sizeof(ComlibMulticastIndexCount));
    //memcpy(msg->indices, cmsg->sec_id->_elems, sizes[1] * sizeof(CkArrayIndex));

    CkArrayIndex **indicesPe = (CkArrayIndex**)alloca(nRemotePes * sizeof(CkArrayIndex*));

    if (needSort) {
    	// if we are sorting the array, then we need to fix the problem that belongingList
    	// refers to the original ordering! This is done by mapping indicesPe in a way coherent
    	// with the original ordering.
    	int previous, i, j;
    	qsort(msg->indicesCount, sizes[0], sizeof(ComlibMulticastIndexCount), indexCountCompare);

    	for (j=0; j<nRemotePes; ++j) if (indicesCount[j].pe == msg->indicesCount[0].pe) break;
    	indicesPe[j] = msg->indices;
    	previous = j;
    	for (i=1; i<nRemotePes; ++i) {
    		for (j=0; j<nRemotePes; ++j) if (indicesCount[j].pe == msg->indicesCount[i].pe) break;
    		indicesPe[j] = indicesPe[previous] + indicesCount[previous].count;
    		previous = j;
    	}
    } else {
    	indicesPe[0] = msg->indices;
    	for (int i=1; i<nRemotePes; ++i) indicesPe[i] = indicesPe[i-1] + indicesCount[i-1].count;
    }

    for (int i=0; i<cmsg->sec_id->_nElems; ++i) {
    	if (belongingList[i] >= 0) {
    		// If the object is located on a remote PE (-1 is local)
    		*indicesPe[belongingList[i]] = cmsg->sec_id->_elems[i];
    		indicesPe[belongingList[i]]++;
    	}
    }
    memcpy(msg->usrMsg, env, sizes[2] * sizeof(char));
    envelope *newenv = UsrToEnv(msg);
    delete [] indicesCount;
    delete [] belongingList;

    newenv->getArrayMgr() = env->getArrayMgr();
    newenv->getsetArraySrcPe() = env->getsetArraySrcPe();
    newenv->getsetArrayEp() = env->getsetArrayEp();
    newenv->getsetArrayHops() = env->getsetArrayHops();
    newenv->getsetArrayIndex() = env->getsetArrayIndex();

#if CMK_REPLAYSYSTEM || CMK_TRACE_ENABLED
    newenv->setEvent(env->getEvent());
#endif
    newenv->setSrcPe(env->getSrcPe());
    
    return (ComlibMulticastMsg *)EnvToUsr(newenv);
}
Exemplo n.º 23
0
void RectMulticastStrategy::handleNewMulticastMessage(envelope *env) {
    
    ComlibPrintf("[%d] : In handleNewMulticastMessage\n", CkMyPe());

    CkUnpackMessage(&env);    
    int sender=env->getSrcPe();
    int localElems;
    envelope *newenv;
    CkArrayIndex *local_idx_list;    
    
    sinfo.unpack(env, localElems, local_idx_list, newenv);

    ComlibMulticastMsg *cbmsg = (ComlibMulticastMsg *)EnvToUsr(env);
    ComlibSectionHashKey key(cbmsg->_cookie.pe, 
                             cbmsg->_cookie.sInfo.cInfo.id);
    
    ComlibRectSectionHashObject *old_obj = NULL;

    old_obj = sec_ht.get(key);

    if(old_obj != NULL) {
        delete old_obj;
    }

    /*
    CkArrayIndex *idx_list_array = new CkArrayIndex[idx_list.size()];
    for(int count = 0; count < idx_list.size(); count++)
        idx_list_array[count] = idx_list[count];
    */

    int cur_sec_id=cbmsg->_cookie.sInfo.cInfo.id;

    // need everyPe for rectangle not just local_idx_list

    ComlibMulticastMsg *lll = cbmsg;
    envelope *ppp = UsrToEnv(cbmsg);
    CkUnpackMessage(&ppp);
    int ttt=0;
    int uuu=0;
    for (int i=0; i<lll->nPes; ++i) {
      //	      ComlibPrintf(" %d (",lll->indicesCount[i].pe);
      uuu++;
      for (int j=0; j<lll->indicesCount[i].count; ++j) {
	//		ComlibPrintf(" %d",((int*)&(lll->indices[ttt]))[1]);
	ttt++;
      }
      //	      ComlibPrintf(" )");
    }
    ComlibPrintf("[%d] cbmsg for intermediate has %d indices %d pes\n",CkMyPe(),ttt, uuu);
    CkAssert(uuu>0);
    CkAssert(ttt>0);

    ComlibRectSectionHashObject *new_obj = createObjectOnIntermediatePe(ttt, cbmsg->indices, cbmsg->nPes, cbmsg->indicesCount, sender, cur_sec_id );
    // now revise obj for local use only
    sinfo.getRemotePelist(localElems, local_idx_list, new_obj->npes, new_obj->pelist);
    sinfo.getLocalIndices(localElems, local_idx_list, new_obj->indices);

    sec_ht.put(key) = new_obj;
    CkPackMessage(&newenv);   
#ifndef LOCAL_MULTI_OFF        

    localMulticast(newenv, new_obj); //local multicast always copies
#endif
    CmiFree(newenv);  //NEED this
}
Exemplo n.º 24
0
/// Pack/unpack/sizing operator
void Event::pup(PUP::er &p) 
{
  int msgSize, spawn = 0;
  SpawnedEvent *tmp = NULL;
  
  evID.pup(p); p(fnIdx); p(timestamp); p(done); p(commitBfrLen); p(commitErr);
  p(srt); p(ert); p(svt); p(evt);
  // commitBfr
  if (p.isUnpacking() && (commitBfrLen > 0)) { // unpack non-empty commitBfr
    commitBfr = new char[commitBfrLen];
    p(commitBfr, commitBfrLen);
  }
  else if (commitBfrLen > 0) // pack/size non-empty commitBfr
    p(commitBfr, commitBfrLen);
  else // unpack empty commitBfr
    commitBfr = NULL;
  
  // msg
  if (p.isUnpacking()) { // unpack msg
    p(msgSize); // unpack msgSize
    if (msgSize > 0) { // if nonzero, unpack msg
      msg = (eventMsg *)CmiAlloc(msgSize); // allocate space
      p((char *)msg, msgSize); // unpack into space
      msg = (eventMsg *)EnvToUsr((envelope *)msg); // reset msg pointer
    }
    else // empty message
      msg = NULL; // set msg to null
  }
  else { // pack msg
    if (msg != NULL) { // msg is not null
      msgSize = (UsrToEnv(msg))->getTotalsize(); // get msg size
      p(msgSize); // pack msg size
      p((char *)(UsrToEnv(msg)), msgSize); // pack from start of envelope
    }
    else { // msg is null
      msgSize = 0;                           
      p(msgSize); // pack size of zero
    }
  }
  
  // spawnedList
  if (p.isUnpacking()) { // unpack spawnedList
    p(spawn); // unpack spawn count
    if (spawn > 0) spawnedList = tmp = new SpawnedEvent();
    else spawnedList = NULL;
    while (spawn > 0) { // unpack each spawned event record
      tmp->pup(p);
      tmp->next = NULL;
      spawn--;
      if (spawn > 0) {
	tmp->next = new SpawnedEvent();
	tmp = tmp->next;
      }
    }
  }
  else { // pack/size spawnedList
    tmp = spawnedList;
    while (tmp != NULL) { // count the spawn
      spawn++;
      tmp = tmp->next;
    }
    p(spawn); // pack the spawn count
    tmp = spawnedList;
    while (tmp != NULL) { // pack each spawn
      tmp->pup(p);
      tmp = tmp->next;
    }
  }
  
  if (p.isUnpacking()) {
    cpData = NULL; // to be set later
    serialCPdata = NULL;
    serialCPdataSz = 0;
  }
}
Exemplo n.º 25
0
void  CkFreeMsg(void *msg)
{
  if (msg!=NULL) {
      CmiFree(UsrToEnv(msg));
  }
}
Exemplo n.º 26
0
// Interpret data in a message in a user-friendly way.
//  Ignores most of the envelope fields used by CkPupMessage,
//  and instead concentrates on user data
void CpdPupMessage(PUP::er &p, void *msg)
{
  envelope *env=UsrToEnv(msg);
  //int wasPacked=env->isPacked();
  int size=env->getTotalsize();
  int prioBits=env->getPriobits();
  int from=env->getSrcPe();
  PUPn(from);
  //PUPn(wasPacked);
  PUPn(prioBits);
  int userSize=size-sizeof(envelope)-sizeof(int)*CkPriobitsToInts(prioBits);
  PUPn(userSize);
  int msgType = env->getMsgIdx();
  PUPn(msgType);
  int envType = env->getMsgtype();
  PUPn(envType);

  //p.synchronize(PUP::sync_last_system);

  int ep=CkMessageToEpIdx(msg);
  PUPn(ep);

  // Pup the information specific to this envelope type
  if (envType == ForArrayEltMsg || envType == ArrayEltInitMsg) {
    int arrID = env->getArrayMgr().idx;
    PUPn(arrID);
    CkArrayIndex &idx = env->getsetArrayIndex();
    int nInts = idx.nInts;
    int dimension = idx.dimension;
    PUPn(nInts);
    PUPn(dimension);
    p.comment("index");
    if (dimension >=4 && dimension <=6) {
      p((short int *)idx.index, dimension);
    } else {
      p(idx.index, nInts);
    }
  } else if (envType == ForNodeBocMsg || envType == ForBocMsg) {
    int groupID = env->getGroupNum().idx;
    PUPn(groupID);
  } else if (envType == BocInitMsg || envType == NodeBocInitMsg) {
    int groupID = env->getGroupNum().idx;
    PUPn(groupID);
  } else if (envType == NewVChareMsg || envType == ForVidMsg || envType == FillVidMsg) {
    p.comment("ptr");
    void *ptr = env->getVidPtr();
    pup_pointer(&p, &ptr);
  } else if (envType == ForChareMsg) {
    p.comment("ptr");
    void *ptr = env->getObjPtr();
    pup_pointer(&p, &ptr);
  }
  
  /* user data */
  p.comment("data");
  p.synchronize(PUP::sync_begin_object);
  if (_entryTable[ep]->messagePup!=NULL)
    _entryTable[ep]->messagePup(p,msg);
  else
    CkMessage::ckDebugPup(p,msg);
  p.synchronize(PUP::sync_end_object);
}
Exemplo n.º 27
0
void CentralLB::ProcessReceiveMigration(CkReductionMsg  *msg)
{
#if CMK_LBDB_ON
	int i;
        LBMigrateMsg *m = storedMigrateMsg;
        CmiAssert(m!=NULL);
        delete msg;

#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
	int *dummyCounts;

	DEBUGF(("[%d] Starting ReceiveMigration WITH step %d m->step %d\n",CkMyPe(),step(),m->step));
	// CmiPrintf("[%d] Starting ReceiveMigration step %d m->step %d\n",CkMyPe(),step(),m->step);
	if(step() > m->step){
		char str[100];
		envelope *env = UsrToEnv(m);
		return;
	}
	lbDecisionCount = m->lbDecisionCount;
#endif

  if (_lb_args.debug() > 1) 
    if (CkMyPe()%1024==0) CmiPrintf("[%d] Starting ReceiveMigration step %d at %f\n",CkMyPe(),step(), CmiWallTimer());

  for (i=0; i<CkNumPes(); i++) theLbdb->lastLBInfo.expectedLoad[i] = m->expectedLoad[i];
  CmiAssert(migrates_expected <= 0 || migrates_completed == migrates_expected);
/*FAULT_EVAC*/
  if(!CmiNodeAlive(CkMyPe())){
	delete m;
	return;
  }
  migrates_expected = 0;
  future_migrates_expected = 0;
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
	int sending=0;
    int dummy=0;
	LBDB *_myLBDB = theLbdb->getLBDB();
	if(_restartFlag){
        dummyCounts = new int[CmiNumPes()];
        bzero(dummyCounts,sizeof(int)*CmiNumPes());
    }
#endif
  for(i=0; i < m->n_moves; i++) {
    MigrateInfo& move = m->moves[i];
    const int me = CkMyPe();
    if (move.from_pe == me && move.to_pe != me) {
      DEBUGF(("[%d] migrating object to %d\n",move.from_pe,move.to_pe));
      // migrate object, in case it is already gone, inform toPe
#if (!defined(_FAULT_MLOG_) && !defined(_FAULT_CAUSAL_))
      if (theLbdb->Migrate(move.obj,move.to_pe) == 0) 
         thisProxy[move.to_pe].MissMigrate(!move.async_arrival);
#else
            if(_restartFlag == 0){
                DEBUG(CmiPrintf("[%d] need to move object from %d to %d \n",CkMyPe(),move.from_pe,move.to_pe));
                theLbdb->Migrate(move.obj,move.to_pe);
                sending++;
            }else{
                if(_myLBDB->validObjHandle(move.obj)){
                    DEBUG(CmiPrintf("[%d] need to move object from %d to %d \n",CkMyPe(),move.from_pe,move.to_pe));
                    theLbdb->Migrate(move.obj,move.to_pe);
                    sending++;
                }else{
                    DEBUG(CmiPrintf("[%d] dummy move to pe %d detected after restart \n",CmiMyPe(),move.to_pe));
                    dummyCounts[move.to_pe]++;
                    dummy++;
                }
            }
#endif
    } else if (move.from_pe != me && move.to_pe == me) {
       DEBUGF(("[%d] expecting object from %d\n",move.to_pe,move.from_pe));
      if (!move.async_arrival) migrates_expected++;
      else future_migrates_expected++;
    }
    else {
#if CMK_GLOBAL_LOCATION_UPDATE      
      UpdateLocation(move); 
#endif
    }

  }
  DEBUGF(("[%d] in ReceiveMigration %d moves expected: %d future expected: %d\n",CkMyPe(),m->n_moves, migrates_expected, future_migrates_expected));
  // if (_lb_debug) CkPrintf("[%d] expecting %d objects migrating.\n", CkMyPe(), migrates_expected);

#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
	if(_restartFlag){
		sendDummyMigrationCounts(dummyCounts);
		_restartFlag  =0;
    	delete []dummyCounts;
	}
#endif


#if 0
  if (m->n_moves ==0) {
    theLbdb->SetLBPeriod(theLbdb->GetLBPeriod()*2);
  }
#endif
  cur_ld_balancer = m->next_lb;
  if((CkMyPe() == cur_ld_balancer) && (cur_ld_balancer != 0)){
      LBDatabaseObj()->set_avail_vector(m->avail_vector, -2);
  }

  if (migrates_expected == 0 || migrates_completed == migrates_expected)
    MigrationDone(1);
  delete m;

//	CkEvacuatedElement();
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
//  migrates_expected = 0;
//  //  ResumeClients(1);
#endif
#endif
}
Exemplo n.º 28
0
void CentralLB::LoadBalance()
{
#if CMK_LBDB_ON
  int proc;
  const int clients = CkNumPes();

#if ! USE_REDUCTION
  // build data
  buildStats();
#else
  for (proc = 0; proc < clients; proc++) statsMsgsList[proc] = NULL;
#endif

  theLbdb->ResetAdaptive();
  if (!_lb_args.samePeSpeed()) statsData->normalize_speed();

  if (_lb_args.debug()) 
      CmiPrintf("\nCharmLB> %s: PE [%d] step %d starting at %f Memory: %f MB\n",
		  lbname, cur_ld_balancer, step(), start_lb_time,
		  CmiMemoryUsage()/(1024.0*1024.0));

  // if we are in simulation mode read data
  if (LBSimulation::doSimulation) simulationRead();

  char *availVector = LBDatabaseObj()->availVector();
  for(proc = 0; proc < clients; proc++)
      statsData->procs[proc].available = (CmiBool)availVector[proc];

  preprocess(statsData);

//    CkPrintf("Before Calling Strategy\n");

  if (_lb_args.printSummary()) {
      LBInfo info(clients);
        // not take comm data
      info.getInfo(statsData, clients, 0);
      LBRealType mLoad, mCpuLoad, totalLoad;
      info.getSummary(mLoad, mCpuLoad, totalLoad);
      int nmsgs, nbytes;
      statsData->computeNonlocalComm(nmsgs, nbytes);
      CkPrintf("[%d] Load Summary (before LB): max (with bg load): %f max (obj only): %f average: %f at step %d nonlocal: %d msgs %.2fKB.\n", CkMyPe(), mLoad, mCpuLoad, totalLoad/clients, step(), nmsgs, 1.0*nbytes/1024);
//      if (_lb_args.debug() > 1) {
//        for (int i=0; i<statsData->n_objs; i++)
//          CmiPrintf("[%d] %.10f %.10f\n", i, statsData->objData[i].minWall, statsData->objData[i].maxWall);
//      }
  }

#if CMK_REPLAYSYSTEM
  LDHandle *loadBalancer_pointers;
  if (_replaySystem) {
    loadBalancer_pointers = (LDHandle*)malloc(CkNumPes()*sizeof(LDHandle));
    for (int i=0; i<statsData->n_objs; ++i) loadBalancer_pointers[statsData->from_proc[i]] = statsData->objData[i].handle.omhandle.ldb;
  }
#endif
  
  LBMigrateMsg* migrateMsg = Strategy(statsData);
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
	migrateMsg->step = step();
#endif

#if CMK_REPLAYSYSTEM
  CpdHandleLBMessage(&migrateMsg);
  if (_replaySystem) {
    for (int i=0; i<migrateMsg->n_moves; ++i) migrateMsg->moves[i].obj.omhandle.ldb = loadBalancer_pointers[migrateMsg->moves[i].from_pe];
    free(loadBalancer_pointers);
  }
#endif
  
  LBDatabaseObj()->get_avail_vector(migrateMsg->avail_vector);
  migrateMsg->next_lb = LBDatabaseObj()->new_lbbalancer();

  // if this is the step at which we need to dump the database
  simulationWrite();

//  calculate predicted load
//  very time consuming though, so only happen when debugging is on
  if (_lb_args.printSummary()) {
      LBInfo info(clients);
        // not take comm data
      getPredictedLoadWithMsg(statsData, clients, migrateMsg, info, 0);
      LBRealType mLoad, mCpuLoad, totalLoad;
      info.getSummary(mLoad, mCpuLoad, totalLoad);
      int nmsgs, nbytes;
      statsData->computeNonlocalComm(nmsgs, nbytes);
      CkPrintf("[%d] Load Summary (after LB): max (with bg load): %f max (obj only): %f average: %f at step %d nonlocal: %d msgs %.2fKB useMem: %.2fKB.\n", CkMyPe(), mLoad, mCpuLoad, totalLoad/clients, step(), nmsgs, 1.0*nbytes/1024, (1.0*useMem())/1024);
      for (int i=0; i<clients; i++)
        migrateMsg->expectedLoad[i] = info.peLoads[i];
  }

  DEBUGF(("[%d]calling recv migration\n",CkMyPe()));
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_)) 
    lbDecisionCount++;
    migrateMsg->lbDecisionCount = lbDecisionCount;
#endif

  envelope *env = UsrToEnv(migrateMsg);
  if (1) {
      // broadcast
    thisProxy.ReceiveMigration(migrateMsg);
  }
  else {
    // split the migration for each processor
    for (int p=0; p<CkNumPes(); p++) {
      LBMigrateMsg *m = extractMigrateMsg(migrateMsg, p);
      thisProxy[p].ReceiveMigration(m);
    }
    delete migrateMsg;
  }

  // Zero out data structures for next cycle
  // CkPrintf("zeroing out data\n");
  statsData->clear();
  stats_msg_count=0;
#endif
}
Exemplo n.º 29
0
void  CkSetQueueing(void *msg, int strategy)
{
  UsrToEnv(msg)->setQueueing((unsigned char) strategy);
}
Exemplo n.º 30
0
/**
  This is the main charm setup routine.  It's called
  on all processors after Converse initialization.
  This routine gets passed to Converse from "main.C".
  
  The main purpose of this routine is to set up the objects
  and Ckpv's used during a regular Charm run.  See the comment
  at the top of the file for overall flow.
*/
void _initCharm(int unused_argc, char **argv)
{ 
	int inCommThread = (CmiMyRank() == CmiMyNodeSize());

	DEBUGF(("[%d,%.6lf ] _initCharm started\n",CmiMyPe(),CmiWallTimer()));

	CkpvInitialize(size_t *, _offsets);
	CkpvAccess(_offsets) = new size_t[32];
	CkpvInitialize(PtrQ*,_buffQ);
	CkpvInitialize(PtrVec*,_bocInitVec);
	CkpvInitialize(void*, _currentChare);
	CkpvInitialize(int,   _currentChareType);
	CkpvInitialize(CkGroupID, _currentGroup);
	CkpvInitialize(void *, _currentNodeGroupObj);
	CkpvInitialize(CkGroupID, _currentGroupRednMgr);
	CkpvInitialize(GroupTable*, _groupTable);
	CkpvInitialize(GroupIDTable*, _groupIDTable);
	CkpvInitialize(CmiImmediateLockType, _groupTableImmLock);
        CkpvInitialize(bool, _destroyingNodeGroup);
        CkpvAccess(_destroyingNodeGroup) = false;
	CkpvInitialize(UInt, _numGroups);
	CkpvInitialize(int, _numInitsRecd);
	CkpvInitialize(int, _initdone);
	CkpvInitialize(char**, Ck_argv); CkpvAccess(Ck_argv)=argv;
	CkpvInitialize(MsgPool*, _msgPool);
	CkpvInitialize(CkCoreState *, _coreState);
	/*
		Added for evacuation-sayantan
	*/
#ifndef __BIGSIM__
	CpvInitialize(char *,_validProcessors);
#endif
	CkpvInitialize(char ,startedEvac);
	CpvInitialize(int,serializer);

	_initChareTables();            // for checkpointable plain chares

	CksvInitialize(UInt, _numNodeGroups);
	CksvInitialize(GroupTable*, _nodeGroupTable);
	CksvInitialize(GroupIDTable, _nodeGroupIDTable);
	CksvInitialize(CmiImmediateLockType, _nodeGroupTableImmLock);
	CksvInitialize(CmiNodeLock, _nodeLock);
	CksvInitialize(PtrVec*,_nodeBocInitVec);
	CksvInitialize(UInt,_numInitNodeMsgs);
	CkpvInitialize(int,_charmEpoch);
	CkpvAccess(_charmEpoch)=0;
	CksvInitialize(int, _triggersSent);
	CksvAccess(_triggersSent) = 0;

	CkpvInitialize(_CkOutStream*, _ckout);
	CkpvInitialize(_CkErrStream*, _ckerr);
	CkpvInitialize(Stats*, _myStats);

	CkpvAccess(_groupIDTable) = new GroupIDTable(0);
	CkpvAccess(_groupTable) = new GroupTable;
	CkpvAccess(_groupTable)->init();
	CkpvAccess(_groupTableImmLock) = CmiCreateImmediateLock();
	CkpvAccess(_numGroups) = 1; // make 0 an invalid group number
	CkpvAccess(_buffQ) = new PtrQ();
	CkpvAccess(_bocInitVec) = new PtrVec();

	CkpvAccess(_currentNodeGroupObj) = NULL;

	if(CkMyRank()==0)
	{
	  	CksvAccess(_numNodeGroups) = 1; //make 0 an invalid group number
          	CksvAccess(_numInitNodeMsgs) = 0;
		CksvAccess(_nodeLock) = CmiCreateLock();
		CksvAccess(_nodeGroupTable) = new GroupTable();
		CksvAccess(_nodeGroupTable)->init();
		CksvAccess(_nodeGroupTableImmLock) = CmiCreateImmediateLock();
		CksvAccess(_nodeBocInitVec) = new PtrVec();
	}

	CkCallbackInit();
	
	CmiNodeAllBarrier();

#if ! CMK_BIGSIM_CHARM
	initQd(argv);         // bigsim calls it in ConverseCommonInit
#endif

	CkpvAccess(_coreState)=new CkCoreState();

	CkpvAccess(_numInitsRecd) = 0;
	CkpvAccess(_initdone) = 0;

	CkpvAccess(_ckout) = new _CkOutStream();
	CkpvAccess(_ckerr) = new _CkErrStream();

	_charmHandlerIdx = CkRegisterHandler((CmiHandler)_bufferHandler);
	_initHandlerIdx = CkRegisterHandler((CmiHandler)_initHandler);
	CkNumberHandlerEx(_initHandlerIdx, (CmiHandlerEx)_initHandler, CkpvAccess(_coreState));
	_roRestartHandlerIdx = CkRegisterHandler((CmiHandler)_roRestartHandler);
	_exitHandlerIdx = CkRegisterHandler((CmiHandler)_exitHandler);
	//added for interoperabilitY
	_libExitHandlerIdx = CkRegisterHandler((CmiHandler)_libExitHandler);
	_bocHandlerIdx = CkRegisterHandler((CmiHandler)_initHandler);
	CkNumberHandlerEx(_bocHandlerIdx, (CmiHandlerEx)_initHandler, CkpvAccess(_coreState));

#ifdef __BIGSIM__
	if(BgNodeRank()==0) 
#endif
	_infoIdx = CldRegisterInfoFn((CldInfoFn)_infoFn);

	_triggerHandlerIdx = CkRegisterHandler((CmiHandler)_triggerHandler);
	_ckModuleInit();

	CldRegisterEstimator((CldEstimator)_charmLoadEstimator);

	_futuresModuleInit(); // part of futures implementation is a converse module
	_loadbalancerInit();
        _metabalancerInit();
	
#if CMK_MEM_CHECKPOINT
        init_memcheckpt(argv);
#endif

	initCharmProjections();
#if CMK_TRACE_IN_CHARM
        // initialize trace module in ck
        traceCharmInit(argv);
#endif
 	
    CkpvInitialize(int, envelopeEventID);
    CkpvAccess(envelopeEventID) = 0;
	CkMessageWatcherInit(argv,CkpvAccess(_coreState));
	
	/**
	  The rank-0 processor of each node calls the 
	  translator-generated "_register" routines. 
	  
	  _register routines call the charm.h "CkRegister*" routines,
	  which record function pointers and class information for
	  all Charm entities, like Chares, Arrays, and readonlies.
	  
	  There's one _register routine generated for each
	  .ci file.  _register routines *must* be called in the 
	  same order on every node, and *must not* be called by 
	  multiple threads simultaniously.
	*/
#ifdef __BIGSIM__
	if(BgNodeRank()==0) 
#else
	if(CkMyRank()==0)
#endif
	{
		SDAG::registerPUPables();
		CmiArgGroup("Charm++",NULL);
		_parseCommandLineOpts(argv);
		_registerInit();
		CkRegisterMsg("System", 0, 0, CkFreeMsg, sizeof(int));
		CkRegisterChareInCharm(CkRegisterChare("null", 0, TypeChare));
		CkIndex_Chare::__idx=CkRegisterChare("Chare", sizeof(Chare), TypeChare);
		CkRegisterChareInCharm(CkIndex_Chare::__idx);
		CkIndex_Group::__idx=CkRegisterChare("Group", sizeof(Group), TypeGroup);
                CkRegisterChareInCharm(CkIndex_Group::__idx);
		CkRegisterEp("null", (CkCallFnPtr)_nullFn, 0, 0, 0+CK_EP_INTRINSIC);
		
		/**
		  These _register calls are for the built-in
		  Charm .ci files, like arrays and load balancing.
		  If you add a .ci file to charm, you'll have to 
		  add a call to the _register routine here, or make
		  your library into a "-module".
		*/
		_registerCkFutures();
		_registerCkArray();
		_registerLBDatabase();
    _registerMetaBalancer();
		_registerCkCallback();
		_registertempo();
		_registerwaitqd();
		_registerCkCheckpoint();
#if CMK_MEM_CHECKPOINT
		_registerCkMemCheckpoint();
#endif


		/*
		  Setup Control Point Automatic Tuning Framework.

		  By default it is enabled as a part of charm, 
		  however it won't enable its tracing module 
		  unless a +CPEnableMeasurements command line argument
		  is specified. See trace-common.C for more info

		  Thus there should be no noticable overhead to 
		  always having the control point framework linked
		  in.
		  
		*/
#if CMK_WITH_CONTROLPOINT
		_registerPathHistory();
		_registerControlPoints();
		_registerTraceControlPoints();
#endif


		/**
		  CkRegisterMainModule is generated by the (unique)
		  "mainmodule" .ci file.  It will include calls to 
		  register all the .ci files.
		*/
		CkRegisterMainModule();

		/**
		  _registerExternalModules is actually generated by 
		  charmc at link time (as "moduleinit<pid>.C").  
		  
		  This generated routine calls the _register functions
		  for the .ci files of libraries linked using "-module".
		  This funny initialization is most useful for AMPI/FEM
		  programs, which don't have a .ci file and hence have
		  no other way to control the _register process.
		*/
		_registerExternalModules(argv);
		
		_registerDone();
	}
	/* The following will happen on every virtual processor in BigEmulator, not just on once per real processor */
	if (CkMyRank() == 0) {
	  CpdBreakPointInit();
	}
	CmiNodeAllBarrier();

	// Execute the initcalls registered in modules
	_initCallTable.enumerateInitCalls();

#if CMK_CHARMDEBUG
	CpdFinishInitialization();
#endif

	//CmiNodeAllBarrier();

	CkpvAccess(_myStats) = new Stats();
	CkpvAccess(_msgPool) = new MsgPool();

	CmiNodeAllBarrier();

#if !(__FAULT__)
	CmiBarrier();
	CmiBarrier();
	CmiBarrier();
#endif
#if CMK_SMP_TRACE_COMMTHREAD
	_TRACE_BEGIN_COMPUTATION();	
#else
 	if (!inCommThread) {
	  _TRACE_BEGIN_COMPUTATION();
	}
#endif

#ifdef ADAPT_SCHED_MEM
    if(CkMyRank()==0){
	memCriticalEntries = new int[numMemCriticalEntries];
	int memcnt=0;
	for(int i=0; i<_entryTable.size(); i++){
	    if(_entryTable[i]->isMemCritical){
		memCriticalEntries[memcnt++] = i;
	    }
	}
    }
#endif

#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
    _messageLoggingInit();
#endif

#ifndef __BIGSIM__
	/*
		FAULT_EVAC
	*/
	CpvAccess(_validProcessors) = new char[CkNumPes()];
	for(int vProc=0;vProc<CkNumPes();vProc++){
		CpvAccess(_validProcessors)[vProc]=1;
	}
	_ckEvacBcastIdx = CkRegisterHandler((CmiHandler)_ckEvacBcast);
	_ckAckEvacIdx = CkRegisterHandler((CmiHandler)_ckAckEvac);
#endif
	CkpvAccess(startedEvac) = 0;
	CpvAccess(serializer) = 0;

	evacuate = 0;
	CcdCallOnCondition(CcdSIGUSR1,(CcdVoidFn)CkDecideEvacPe,0);
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_)) 
    CcdCallOnCondition(CcdSIGUSR2,(CcdVoidFn)CkMlogRestart,0);
#endif

	if(_raiseEvac){
		processRaiseEvacFile(_raiseEvacFile);
		/*
		if(CkMyPe() == 2){
		//	CcdCallOnConditionKeep(CcdPERIODIC_10s,(CcdVoidFn)CkDecideEvacPe,0);
			CcdCallFnAfter((CcdVoidFn)CkDecideEvacPe, 0, 10000);
		}
		if(CkMyPe() == 3){
			CcdCallFnAfter((CcdVoidFn)CkDecideEvacPe, 0, 10000);
		}*/
	}	
    
    if (CkMyRank() == 0) {
      TopoManager_init();
    }
    CmiNodeAllBarrier();

    if (!_replaySystem) {
        CkFtFn  faultFunc_restart = CkRestartMain;
        if (faultFunc == NULL || faultFunc == faultFunc_restart) {         // this is not restart from memory
            // these two are blocking calls for non-bigsim
#if ! CMK_BIGSIM_CHARM
	  CmiInitCPUAffinity(argv);
          CmiInitMemAffinity(argv);
#endif
        }
        CmiInitCPUTopology(argv);
#if CMK_SHARED_VARS_POSIX_THREADS_SMP
        if (CmiCpuTopologyEnabled()) {
            int *pelist;
            int num;
            CmiGetPesOnPhysicalNode(0, &pelist, &num);
#if !CMK_MULTICORE && !CMK_SMP_NO_COMMTHD
            // Count communication threads, if present
            // XXX: Assuming uniformity of node size here
            num += num/CmiMyNodeSize();
#endif
            if (!_Cmi_forceSpinOnIdle && num > CmiNumCores())
            {
              if (CmiMyPe() == 0)
                CmiPrintf("\nCharm++> Warning: the number of SMP threads (%d) is greater than the number of physical cores (%d), so threads will sleep while idling. Use +CmiSpinOnIdle or +CmiSleepOnIdle to control this directly.\n\n", num, CmiNumCores());
              CmiLock(CksvAccess(_nodeLock));
              if (! _Cmi_sleepOnIdle) _Cmi_sleepOnIdle = 1;
              CmiUnlock(CksvAccess(_nodeLock));
            }
        }
#endif
    }

    if(CmiMyPe() == 0) {
        char *topoFilename;
        if(CmiGetArgStringDesc(argv,"+printTopo",&topoFilename,"topo file name")) 
        {
            std::stringstream sstm;
            sstm << topoFilename << "." << CmiMyPartition();
            std::string result = sstm.str();
            FILE *fp;
            fp = fopen(result.c_str(), "w");
            if (fp == NULL) {
              CkPrintf("Error opening %s file, writing to stdout\n", topoFilename);
              fp = stdout;
            }
	    TopoManager_printAllocation(fp);
            fclose(fp);
        }
    }

#if CMK_USE_PXSHM && ( CMK_CRAYXE || CMK_CRAYXC ) && CMK_SMP
      // for SMP on Cray XE6 (hopper) it seems pxshm has to be initialized
      // again after cpuaffinity is done
    if (CkMyRank() == 0) {
      CmiInitPxshm(argv);
    }
    CmiNodeAllBarrier();
#endif

    //CldCallback();
#if CMK_BIGSIM_CHARM && CMK_CHARMDEBUG
      // Register the BG handler for CCS. Notice that this is put into a variable shared by
      // the whole real processor. This because converse needs to find it. We check that all
      // virtual processors register the same index for this handler.
    CpdBgInit();
#endif

	if (faultFunc) {
#if CMK_WITH_STATS
		if (CkMyPe()==0) _allStats = new Stats*[CkNumPes()];
#endif
		if (!inCommThread) {
                  CkArgMsg *msg = (CkArgMsg *)CkAllocMsg(0, sizeof(CkArgMsg), 0);
                  msg->argc = CmiGetArgc(argv);
                  msg->argv = argv;
                  faultFunc(_restartDir, msg);
                  CkFreeMsg(msg);
                }
	}else if(CkMyPe()==0){
#if CMK_WITH_STATS
		_allStats = new Stats*[CkNumPes()];
#endif
		register size_t i, nMains=_mainTable.size();
		for(i=0;i<nMains;i++)  /* Create all mainchares */
		{
			register int size = _chareTable[_mainTable[i]->chareIdx]->size;
			register void *obj = malloc(size);
			_MEMCHECK(obj);
			_mainTable[i]->setObj(obj);
			CkpvAccess(_currentChare) = obj;
			CkpvAccess(_currentChareType) = _mainTable[i]->chareIdx;
			register CkArgMsg *msg = (CkArgMsg *)CkAllocMsg(0, sizeof(CkArgMsg), 0);
			msg->argc = CmiGetArgc(argv);
			msg->argv = argv;
			_entryTable[_mainTable[i]->entryIdx]->call(msg, obj);
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
            CpvAccess(_currentObj) = (Chare *)obj;
#endif
		}
                _mainDone = 1;

		_STATS_RECORD_CREATE_CHARE_N(nMains);
		_STATS_RECORD_PROCESS_CHARE_N(nMains);




		for(i=0;i<_readonlyMsgs.size();i++) /* Send out readonly messages */
		{
			register void *roMsg = (void *) *((char **)(_readonlyMsgs[i]->pMsg));
			if(roMsg==0)
				continue;
			//Pack the message and send it to all other processors
			register envelope *env = UsrToEnv(roMsg);
			env->setSrcPe(CkMyPe());
			env->setMsgtype(ROMsgMsg);
			env->setRoIdx(i);
			CmiSetHandler(env, _initHandlerIdx);
			CkPackMessage(&env);
			CmiSyncBroadcast(env->getTotalsize(), (char *)env);
			CpvAccess(_qd)->create(CkNumPes()-1);

			//For processor 0, unpack and re-set the global
			CkUnpackMessage(&env);
			_processROMsgMsg(env);
			_numInitMsgs++;
		}

		//Determine the size of the RODataMessage
		PUP::sizer ps;
		for(i=0;i<_readonlyTable.size();i++) _readonlyTable[i]->pupData(ps);

		//Allocate and fill out the RODataMessage
		envelope *env = _allocEnv(RODataMsg, ps.size());
		PUP::toMem pp((char *)EnvToUsr(env));
		for(i=0;i<_readonlyTable.size();i++) _readonlyTable[i]->pupData(pp);

		env->setCount(++_numInitMsgs);
		env->setSrcPe(CkMyPe());
		CmiSetHandler(env, _initHandlerIdx);
		DEBUGF(("[%d,%.6lf] RODataMsg being sent of size %d \n",CmiMyPe(),CmiWallTimer(),env->getTotalsize()));
		CmiSyncBroadcastAndFree(env->getTotalsize(), (char *)env);
		CpvAccess(_qd)->create(CkNumPes()-1);
		_initDone();
	}

	DEBUGF(("[%d,%d%.6lf] inCommThread %d\n",CmiMyPe(),CmiMyRank(),CmiWallTimer(),inCommThread));
	// when I am a communication thread, I don't participate initDone.
        if (inCommThread) {
                CkNumberHandlerEx(_bocHandlerIdx,(CmiHandlerEx)_processHandler,
                                        CkpvAccess(_coreState));
                CkNumberHandlerEx(_charmHandlerIdx,(CmiHandlerEx)_processHandler
,
                                        CkpvAccess(_coreState));
                _processBufferedMsgs();
        }

#if CMK_CHARMDEBUG
        // Should not use CpdFreeze inside a thread (since this processor is really a user-level thread)
       if (CpvAccess(cpdSuspendStartup))
       { 
          //CmiPrintf("In Parallel Debugging mode .....\n");
          CpdFreeze();
       }
#endif


#if __FAULT__
	if(killFlag){                                                  
                readKillFile();                                        
        }
#endif

}