Beispiel #1
0
  void SayHi(HiMsg *m)
  {
    redNo ++;
    CmiAssert(m->data[0] == 22 && m->data[1] == 28);

    CkGetSectionInfo(sid, m);

    CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();
    int dataSize = (int)(CompleteMsgSize);
    int* data = new int [dataSize];
    int fragSize = dataSize/NumFrags;
    CkAssert (0 != fragSize);
    for (int i=0; i<dataSize; i++) {
      data [i] = thisIndex;
    }
    CkCallback cb(CkIndex_Hello::cb_client(NULL), CkArrayIndex1D(0), thisProxy);
    mg->contribute(dataSize*sizeof(int), data,CkReduction::sum_int, sid, cb, fragSize*sizeof(int));
//    data[0] = thisIndex+2;
//    data[1] = thisIndex+2;
//    mg->contribute(2*sizeof(int), &data,CkReduction::max_int, sid, sizeof(int));
//    data[0] = thisIndex+1;
//    data[1] = thisIndex+1;
//    mg->contribute(2*sizeof(int), &data,CkReduction::product_int, sid, sizeof(int));
    delete m;
    if (1)
      ckMigrate((CkMyPe()+1)%CkNumPes());
  }
Beispiel #2
0
  Main(CkArgMsg* m): numArrays(2), numElements(5), sectionSize(numElements), maxIter(3), numIter(0)
  {
    //Process command-line arguments
    if (m->argc > 1) numElements = atoi(m->argv[1]);
    if (m->argc > 2) numArrays   = atoi(m->argv[2]);
    if (m->argc > 3) sectionSize = atoi(m->argv[3]); else sectionSize = numElements;
    if (m->argc > 4) maxIter     = atoi(m->argv[4]);
    if (m->argc > 5)
    { CkPrintf("Syntax: %s [numElements numArrays sectionSize maxIter]",m->argv[0]); CkAbort("Wrong Usage\n"); }
    delete m;

    CkPrintf("Running a cross-array section demo.\n");
    CkPrintf("\tnum PEs = %d\n\tnum arrays = %d\n\tnum elements = %d\n\tsection size = %d\n\tnum iterations = %d\n",
             CkNumPes(), numArrays, numElements, sectionSize, maxIter);

    // Create a multicast manager group
    CkGroupID mcastMgrGID = CProxy_CkMulticastMgr::ckNew();
    CkMulticastMgr *mcastMgr = CProxy_CkMulticastMgr(mcastMgrGID).ckLocalBranch();

    // Setup section member index bounds
    int afloor = 0, aceiling = sectionSize-1;

    // Allocate space
    CProxy_Hello *arrayOfArrays = new CProxy_Hello[numArrays];
    CkArrayID *arrID            = new CkArrayID[numArrays];
    int *nelems                 = new int[numArrays];
    CkArrayIndex **elems     = new CkArrayIndex*[numArrays];

    // Create a list of array section members
    for(int k=0; k < numArrays; k++)
    {
        // Create the array
        arrayOfArrays[k] = CProxy_Hello::ckNew(k, mcastMgrGID, numElements);
        // Store the AID
        arrID[k]  = arrayOfArrays[k].ckGetArrayID();
        // Create a list of section member indices in this array
        nelems[k] = sectionSize;
        elems[k]  = new CkArrayIndex[sectionSize];
        for(int i=afloor,j=0; i <= aceiling; i++,j++)
            elems[k][j] = CkArrayIndex1D(i);
    }
    // Create the x-array-section
    sectionProxy = CProxySection_Hello(numArrays, arrID, elems, nelems);

    // Delegate the section comm to the CkMulticast library
    sectionProxy.ckSectionDelegate(mcastMgr);
    // Configure the client of the section reduction
    CkCallback *rednCB = new CkCallback(CkIndex_Main::rednPong(NULL), thisProxy); 
    mcastMgr->setReductionClient(sectionProxy, rednCB);

    // Start the test by pinging the section
    pingMsg *msg = new pingMsg(numIter);
    sectionProxy.mcastPing(msg);
  }
Beispiel #3
0
  void pup(PUP::er &p) {
    p|sid;
    p(init);
    p|cnt;
    p|mcp;
#if 1
    if (p.isUnpacking() && thisIndex == 0) {
      CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();
      mg->resetSection(mcp);
      CkCallback *cb = new CkCallback(CkIndex_Hello::cb_client(NULL), CkArrayIndex1D(0), thisProxy);
      mg->setReductionClient(mcp, cb);
    }
#endif
  }
Beispiel #4
0
//  void cb_client(CkSectionInfo sid, void *param, int dataSize, void *data)
  void cb_client(CkReductionMsg *msg)
  {
    int dataSize = msg->getSize();
    void *data = msg->getData();
    CmiPrintf("RESULT [%d]: %d\n", cnt.reductionNo, *(int *)data); 

    // check correctness
    int result;
    int redno = msg->getRedNo();
    if (redno%3 == 0) {
      result = 0;
      for (int i=0; i<sectionSize; i++) result+=i;
    }
    else if (redno%3 == 2) {
      result = 1;
      for (int i=1; i<sectionSize+1; i++) result*=i;
    }
    else {
      result = sectionSize+1;
    }
    if (*(int *)data != result) {
      CmiPrintf("Expected: %d acual:%d\n", result, *(int *)data);
      CmiAbort("reduction result is wrong!");
    }
  
    cnt.reductionsRemaining--;
    if (cnt.reductionsRemaining<=0) {
      CProxy_main mproxy(mid);
      mproxy.maindone();
      cnt.reductionNo++;
    }
    else {
#if 0
      CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();
      if (cnt->reductionNo % 32 == 0)
        mg->rebuild(mcp.ckGetSectionInfo());
#endif
  
      if (cnt.reductionNo%3 == 0) {
        HiMsg *hiMsg = new (2, 0) HiMsg;
        //hiMsg->data[0] = 18+cnt.reductionNo;
        hiMsg->data[0] = 22;
        hiMsg->data[1] = 28;
        mcp.SayHi(hiMsg);
      }
      cnt.reductionNo++;
    }
    delete msg;
  }
Beispiel #5
0
void Patch::localCreateSection() {
#ifdef USE_SECTION_MULTICAST
  CkVec<CkArrayIndex6D> elems;
  for (int num=0; num<numNbrs; num++)
    elems.push_back(CkArrayIndex6D(computesList[num][0], computesList[num][1], computesList[num][2], computesList[num][3], computesList[num][4], computesList[num][5]));

  CkArrayID computeArrayID = computeArray.ckGetArrayID();
  mCastSecProxy = CProxySection_Compute::ckNew(computeArrayID, elems.getVec(), elems.size()); 

  CkMulticastMgr *mCastGrp = CProxy_CkMulticastMgr(mCastGrpID).ckLocalBranch();
  mCastSecProxy.ckSectionDelegate(mCastGrp);
  mCastGrp->setReductionClient(mCastSecProxy, new CkCallback(CkIndex_Patch::reduceForces(NULL), thisProxy(thisIndex.x, thisIndex.y, thisIndex.z)));

#endif
}
Beispiel #6
0
void Test3D::compute(DummyMsg *m)
{

    /*char buf[2048];	//for debugging

	sprintf(buf, "Compute called :: thisIndex = { %d, %d }, m->section = %d", thisIndex.x, thisIndex.y, m->section);	//debugging */

	//cookie stuff.
	int section = m->section;
	int oldLength = cookies.length();
	int newLength = section + 1;
	if(oldLength < newLength) { //only if the section proxy calling 
								//this method is a new section proxy 
								//(that hasn't already called this method 
								//before, increase the size of the cookies array.
		cookies.resize(section+1);
		for (int i = oldLength; i < newLength; i++) {
			CkSectionInfo tempCookie;
			cookies[i] = tempCookie;
		}
	}
	CkGetSectionInfo(cookies[section], m);	//the index of the cookie identifies, which section proxy we are refering to.

    /* DEBUG
	CkSectionInfo si = cookies[section];
	sprintf(buf + strlen(buf), ", Cookie:"
			 "  type = %d"
			 "  pe = %d"
			 "  sCookie = { redNo:%d, val:%p }\n",
			 (int)(si.type), si.pe,
			 si.sInfo.sCookie.redNo,
			 si.sInfo.sCookie.val
			);
    CkPrintf(buf);	*/

	CkVec<double> myVector(vectorSize);	//creates elements with vectorSize elements
	for(int i = 0; i < vectorSize; i++)	{
		myVector[i] = doubleVector[i];
	}
	CkMulticastMgr *mCastGrp = CProxy_CkMulticastMgr(mCastGrpID).ckLocalBranch();
	CkCallback cb(CkIndex_Main::reportSum(NULL), mainProxy);
	mCastGrp->contribute(sizeof(double)*vectorSize, myVector.getVec(), CkReduction::sum_double, cookies[section], cb);
	delete m;
};
Beispiel #7
0
    // only on index 0
  void start()
  {
    CkAssert(thisIndex == 0);
CmiPrintf("start %d elements\n", nElements);
    CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();

    // create section proxy
//    CkVec<CkArrayIndex1D> al;
//    for (int i=0; i<sectionSize; i++)
//      al.push_back(CkArrayIndex1D(i));
//    mcp = CProxySection_Hello::ckNew(thisArrayID, al.getVec(), al.size());
#if 0
    mcast = new CProxySection_Hello(thisArrayID, al, sectionSize, mCastGrpId);
#endif
    mcp = CProxySection_Hello::ckNew(thisArrayID, 0, sectionSize-1, 1);
    mcp.ckSectionDelegate(mg);

#if 0
    mcp.ckDelegate(mg);
    mg->setSection(mcp);
#endif

#if 0
    mg->setSection(sid, thisArrayID, al, sectionSize);
    sid.create(thisArrayID);
    for (int i=0; i<sectionSize; i++) 
      sid.addMember(CkArrayIndex1D(i));
    mg->setSection(sid);
#endif

    cnt.reductionsRemaining=REDUCE_TIME;
    cnt.reductionNo=0;
//    mg->setReductionClient(mcp, client, cnt);
    CkCallback *cb = new CkCallback(CkIndex_Hello::cb_client(NULL), CkArrayIndex1D(0), thisProxy);
    mg->setReductionClient(mcp, cb);

    HiMsg *hiMsg = new (2, 0) HiMsg;
    hiMsg->data[0] = 22;
    hiMsg->data[1] = 28;
    mcp.SayHi(hiMsg);
  }
Beispiel #8
0
  void SayHi(HiMsg *m)
  {
    // CkPrintf("[%d] Hi[%d] from element %d\n",CmiMyPe(), m->data[0],thisIndex);
    CmiAssert(m->data[0] == 22 && m->data[1] == 28);

    CkGetSectionInfo(sid, m);
//CmiPrintf("[%d] SayHi: sid on %d %p\n", CmiMyPe(), sid.pe, sid.val);

    CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();

    int data = thisIndex;
    CkCallback cb(CkIndex_Hello::cb_client(NULL), CkArrayIndex1D(0), thisProxy);
    mg->contribute(sizeof(int), &data,CkReduction::sum_int, sid, cb);
    data = thisIndex+2;
    mg->contribute(sizeof(int), &data,CkReduction::max_int, sid);
    data = thisIndex+1;
    mg->contribute(sizeof(int), &data,CkReduction::product_int, sid);
    delete m;
    if (1)
    ckMigrate((CkMyPe()+1)%CkNumPes());
  }
Beispiel #9
0
void client(CkSectionInfo sid, void *param, int dataSize, void *data)
{
  myReductionCounter *c=(myReductionCounter *)param;
  CmiPrintf("RESULT [%d]: %d\n", c->reductionNo, *(int *)data); 
  // check correctness
  int result;
  if (c->reductionNo%3 == 0) {
    result = 0;
    for (int i=0; i<sectionSize; i++) result+=i;
  }
  else if (c->reductionNo%3 == 2) {
    result = 1;
    for (int i=1; i<sectionSize+1; i++) result*=i;
  }
  else {
    result = sectionSize+1;
  }
  if (*(int *)data != result) {
    CmiAbort("wrong!");
  }

  c->reductionsRemaining--;
  if (c->reductionsRemaining<=0) {
    CProxy_main mproxy(mid);
    mproxy.maindone();
    c->reductionNo++;
  }
  else {
    CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();
    if (c->reductionNo % 32 == 0)
    mg->rebuild(mcp.ckGetSectionInfo());

    if (c->reductionNo%3 == 0) {
    HiMsg *hiMsg = new (1, 0) HiMsg;
    hiMsg->data[0] = 18+c->reductionNo;
    mcp.SayHi(hiMsg);
    }
    c->reductionNo++;
  }
}
Beispiel #10
0
  void start()
  {
    CkMulticastMgr *mg = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();

    sectionSize = SectionSize;
    if (sectionSize > NumElements) sectionSize = NumElements;
    CkArrayIndex *al = new CkArrayIndex[sectionSize];
    for (int i=0; i<sectionSize; i++) {
      al[i] = CkArrayIndex1D(i);
    }
    mcp = CProxySection_Hello::ckNew(thisArrayID, al, sectionSize);
    mcp.ckSectionDelegate(mg);
    delete [] al;
    cnt.reductionsRemaining=NumReductions;
    cnt.reductionNo=0;
    CkCallback *cb = new CkCallback(CkIndex_Hello::cb_client(NULL), CkArrayIndex1D(0), thisProxy);
    mg->setReductionClient(mcp, cb);

    HiMsg *hiMsg = new (2, 0) HiMsg;
    hiMsg->data[0] = 22;
    hiMsg->data[1] = 28;
    startTime = CkWallTimer ();
    mcp.SayHi(hiMsg);
  }
Beispiel #11
0
 Hello(int _aNum, CkGroupID mcastMgrGID): aNum(_aNum), mcastMgr(NULL), isCookieSet(false)
 {
   CkPrintf("Array %d, Element %d created on PE %d\n", aNum, thisIndex, CkMyPe());
   mcastMgr = CProxy_CkMulticastMgr(mcastMgrGID).ckLocalBranch();
 }