Skip to Content.
Sympa Menu

charm - [charm] About Delegation

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

[charm] About Delegation


Chronological Thread 
  • From: SAGAR SHEDGE <sagar.shedge92 AT gmail.com>
  • To: charm AT cs.uiuc.edu
  • Subject: [charm] About Delegation
  • Date: Tue, 12 Jul 2011 14:07:30 +0530
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/charm>
  • List-id: CHARM parallel programming system <charm.cs.uiuc.edu>

Respected Sir/Mam,

Hereby I am trying for delegation code.
I execute code from /test/charm++/delegation/1DArray/. It shows some error in file hello.C( I have attached file ) on line 58,84,85. So I made some changes in that file on line 60 and 88.

Now code is running but ...
1. I am calling remote method through array proxy which is register to delegate manager group and also I have overload virtual function virtual void ArraySend(int ep,void *m,const   CkArrayIndexMax &idx,CkArrayID a) but it does not call that function.

Why is it so? Is there any missing in that code or is there any other method to call it?

Thanks for reply in advance.
--
Sagar Dilip Shedge,
C-DAC R&D,
Pune.
 
With Regards.
 

#include <stdio.h>
#include "hello.decl.h"
#include "envelope.h"

/*readonly*/ CProxy_Main mainProxy;
/*readonly*/ CProxy_Hello arr;
/*readonly*/ int nElements;
/*readonly*/ CProxy_DelegateMgr delMgr;

/*mainchare*/
class Main : public Chare
{
public:
  Main(CkArgMsg* m)
  {
    //Process command-line arguments
    nElements=5;
    if(m->argc >1 ) nElements=atoi(m->argv[1]);
    delete m;

    //Start the computation
    CkPrintf("Running Hello on %d processors for %d elements\n",
	     CkNumPes(),nElements);
    mainProxy = thishandle;
 
    delMgr = CProxy_DelegateMgr::ckNew();

    arr = CProxy_Hello::ckNew(nElements);

    arr[0].SayHi(17);
  };

  void done(void)
  {
    CkPrintf("All done\n");
    CkExit();
  };
};

/*group*/
class DelegateMgr : public CkDelegateMgr {
public:
	DelegateMgr(void) 
	{
		CkPrintf("in delegate mgr on processor %d \n",CkMyPe());	
	}
	virtual void ArraySend(int ep,void *m,const CkArrayIndexMax &idx,CkArrayID a)
	{


		CkArray *arrMgr=CProxy_CkArray(a).ckLocalBranch();
		int onPE=arrMgr->lastKnown(idx);
		ckout<<"in ArraySend DelegateMgr> Sending message for "<<idx.data()[0]<<" to "<<onPE<<endl;
		if (onPE==CkMyPe()) 
		{ //Send to local element

		/*------------------ original code -------------------
			arrMgr->deliverViaQueue((CkMessage *)m);
		*/
			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);
		}
	}
	void forwardMsg(int ep,const CkArrayIndexMax &idx,
			const CkArrayID &a,
			int nBytes,char *env)
	{
		ckout<<"DelegateMgr> Recv message for "<<idx.data()[0]<<endl;
		//Have to allocate a new message because of Charm++'s 
		// weird allocate rules:
		envelope *msg=(envelope *)CmiAlloc(nBytes);
		memcpy(msg,env,nBytes);
		CkUnpackMessage(&msg);
		
		
		/*----------------- original code -----------------------
		CProxy_CkArray ap(msg->array_mgr());
		ap.ckLocalBranch()->deliver((CkMessage *)EnvToUsr(msg),CkDeliver_inline);
		*/

		a.ckLocalBranch()->deliver((CkMessage *)EnvToUsr(msg),CkDeliver_inline);
	}
};

/*array [1D]*/
class Hello : public ArrayElement1D
{
public:
  Hello()
  {
    CkPrintf("Hello %d created\n",thisIndex);
  }

  Hello(CkMigrateMessage *m) {}
  
  void SayHi(int hiNo)
  {
    CkPrintf("Hi[%d] from element %d\n",hiNo,thisIndex);
    CProxy_Hello delArr=arr;
    delArr.ckDelegate(delMgr.ckLocalBranch());
    if (thisIndex < nElements-1)
	delArr[thisIndex+1].SayHi(hiNo+1);
      //Pass the hello on:
     else 
      //We've been around once-- we're done.
    mainProxy.done();
  }
};

#include "hello.def.h"

Attachment: hello.ci
Description: Binary data




Archive powered by MHonArc 2.6.16.

Top of Page