Esempio n. 1
0
static void span(Surface& s,
                 WFMath::CoordType z,
                 WFMath::CoordType xStart,
                 WFMath::CoordType xEnd)
{
    assert(xStart <= xEnd); 

    // quantize and accumulate into the buffer data
    unsigned int row = I_ROUND(z),
        ixStart = I_ROUND(xStart),
        ixEnd = I_ROUND(xEnd);
 
    //std::cout << "span @ z=" << row << ", " << ixStart << " -> " << ixEnd << std::endl;
    
    if (ixStart == ixEnd) {
        contribute(s, ixStart, row, ROW_HEIGHT * (xEnd - xStart));
    } else {
        contribute(s, ixStart, row, ROW_HEIGHT * (ixStart - xStart + 0.5f));
        
        for (unsigned int i=ixStart+1; i < ixEnd; ++i)
            contribute(s, i, row, ROW_HEIGHT);
        
        contribute(s, ixEnd, row, ROW_HEIGHT * (xEnd - ixEnd + 0.5f));
    }
}
Esempio n. 2
0
    void check_and_compute() {
        compute_kernel();

        // calculate error
        // not being done right now since we are doing a fixed no. of iterations

        double *tmp;
        tmp = temperature;
        temperature = new_temperature;
        new_temperature = tmp;

        constrainBC();

        if (iterations % CKP_FREQ == 0 || iterations > MAX_ITER) {
#ifdef CMK_MEM_CHECKPOINT
            contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
#elif CMK_MESSAGE_LOGGING
            if(iterations > MAX_ITER)
                contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
            else
                AtSync();
#else
            contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
#endif
        } else {
            doStep();
        }
    }
Esempio n. 3
0
void BTest::receive(MyMess *msg) {
  delete msg;

  if (thisIndex==0) {
    if (iter==threshold_msgs) startTime=CmiWallTimer();
    //if (iter>0) totalTime += CmiWallTimer() - startTime;
    //if (thisIndex==0) CkPrintf("Finished iteration %d (type %d)\n",iter+1,type);
    if (iter++<MAX_ITER) {
      //CkPrintf("[%2d] totaltime with '%s' = %f\n",CmiMyPe(),conversion[type],totalTime/(iter-1));
      //startTime=CmiWallTimer();
      send();
      //contribute(0, &count, CkReduction::sum_int, cb);
    } else {
      iter=0;
      //CkPrintf("[%2d] totaltime with '%s' = %f\n",CmiMyPe(),conversion[type],(CmiWallTimer()-startTime)/(MAX_ITER-threshold_msgs));
      if (type==0) cinst7.beginIteration();
      else if (type==1) cinst6.beginIteration();
      else if (type==2) cinst5.beginIteration();
      else if (type==3) cinst4.beginIteration();
      else if (type==4) cinst3.beginIteration();
      else if (type==5) cinst2.beginIteration();
      else if (type==5) cinst1.beginIteration();

      // global barrier
      contribute(0, &count, CkReduction::sum_int, cb);

      /*
      if (++type==MAX_TYPE) {
	if (++length==MAX_LENGTH) {
	  mainProxy.exit();
	} else {
	  type = 0;
	  //sendall();
	  contribute(0, &count, CkReduction::sum_int, cball);
	}
      } else {
	totalTime=0;
	//startTime = CmiWallTimer();
	send();
	//contribute(0, &count, CkReduction::sum_int, cb);
      }
      */
    }
  } else {
    if (iter++<MAX_ITER) {
      iter = 0;
      contribute(0, &count, CkReduction::sum_int, cball);
    }
  }
}
Esempio n. 4
0
void HybridBaseLB::MigrationDone(int balancing)
{
#if CMK_LBDB_ON
  LevelData *lData = levelData[0];

  DEBUGF(("[%d] HybridBaseLB::MigrationDone!\n", CkMyPe()));

  theLbdb->incStep();

  // reset 
  for (int i=0; i<tree->numLevels(); i++) 
    levelData[i]->clear();
  newObjs.free();

  DEBUGF(("[%d] calling ResumeClients.\n", CkMyPe()));
  if (balancing && _lb_args.syncResume()) {
    // max load of all
    CkCallback cb(CkIndex_HybridBaseLB::ResumeClients((CkReductionMsg*)NULL),
                  thisProxy);
    contribute(sizeof(double), &maxLoad, CkReduction::max_double, cb);
  }
  else
    thisProxy[CkMyPe()].ResumeClients(balancing);

  maxLoad = 0.0;
#endif
}
Esempio n. 5
0
  void communicate(int iters, bool useTram) {
    GroupMeshStreamer<DataItem, Participant, SimpleMeshRouter> *localStreamer;
    if (useTram) {
      localStreamer = aggregator.ckLocalBranch();
    }

    int ctr = 0;
    for (int i = 0; i < iters; i++) {
      for (int j=0; j<CkNumPes(); j++) {
        if (useTram) {
          localStreamer->insertData(myItem, neighbors[j]);
        }
        else {
          allToAllGroup[neighbors[j]].receive(myItem);
          ctr++;
        }
      }
      if (!useTram) {
        if (ctr == 1024) {
          ctr = 0;
          CthYield();
        }
      }
    }
    if (useTram) {
      localStreamer->done();
    }
    else {
      contribute(CkCallback(CkReductionTarget(Main, allDone), mainProxy));
    }
  }
Esempio n. 6
0
  void check_and_compute ()
  {
//       if (--messages_due == 0) 
//          messages_due = 4;
      compute ();
//          mainProxy.report();
      if (thisIndex < majElements - 1)
	{
//                      printf("DONE WITH index=%d and calling for ind=%d\n",thisIndex,thisIndex+1);
#ifdef PRIOR
	  opts = new CkEntryOptions ();
	  opts1 = new CkEntryOptions ();
	  opts->setPriority (-100);
	  opts1->setPriority (100);

//printf("-------- Jacobi[%d] sending message to next one at time=%f\n",thisIndex,CkWallTimer());
	  thisProxy[thisIndex + 1].begin_iteration (1, opts);
        for(int i=(thisIndex+1)*7;i<(thisIndex+1)*7+7;i++)
                minorProxy[i].begin_iteration(1,opts1);
#else
	  thisProxy[thisIndex + 1].begin_iteration (1);
	  for (int i = (thisIndex + 1) * 7; i < (thisIndex + 1) * 7 + 7; i++)
	    minorProxy[i].begin_iteration (1);
#endif
	}
      else
	{
//                      printf("CAlling report Jacobi[%d] time=%f!!!!!!!!!!1\n",thisIndex,CkWallTimer());

//	  else
//	    mainProxy.report ();
	}
	if (iterations % ldbTime == 4) AtSync();
	else contribute(CkCallback(CkIndex_Main::report(NULL),mainProxy));
  }
Esempio n. 7
0
void Compute::receiveC(float *data, int size, int who) {
  int indexY = thisIndex.y;
  if(who) {
    for(int i=0; i<subBlockDimXy; i++)
      for(int k=0; k<blockDimZ; k++)
	C[indexY*subBlockDimXy*blockDimZ + i*blockDimZ + k] += data[i*blockDimZ + k];
  }
  countC++;
  if(countC == num_chare_y) {
    /*char name[30];
    sprintf(name, "%s_%d_%d_%d", "C", thisIndex.x, thisIndex.y, thisIndex.z);
    FILE *fp = fopen(name, "w");
    for(int i=0; i<subBlockDimXy; i++) {
      for(int k=0; k<blockDimZ; k++)
	fprintf(fp, "%f ", C[indexY*subBlockDimXy*blockDimZ + i*blockDimZ + k]);
      fprintf(fp, "\n");
    }
    fclose(fp);*/

    // counters to keep track of how many messages have been received
    countA = 0;
    countB = 0;
    countC = 0;

    contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::done(), mainProxy));
    // mainProxy.done();
  }
}
Esempio n. 8
0
void Compute::recvHandle(infiDirectUserHandle shdl, int index, int arr) {
  // --- B --- | --- C --- | --- A ---
  if(arr == SENDA) {
    sHandles[num_chare_x + num_chare_y + index] = shdl;
    CkDirect_assocLocalBuffer(&sHandles[num_chare_x + num_chare_y + index], &A[thisIndex.z*subBlockDimXz*blockDimY], sizeof(float)*subBlockDimXz*blockDimY);
    countA++;
  }

  if(arr == SENDB) {
    sHandles[index] = shdl;
    CkDirect_assocLocalBuffer(&sHandles[index], &B[thisIndex.x*subBlockDimYx*blockDimZ], sizeof(float)*subBlockDimYx*blockDimZ);
    countB++;
  }

  if(arr == SENDC) {
    sHandles[num_chare_x + index] = shdl;
    CkDirect_assocLocalBuffer(&sHandles[num_chare_x + index], &C[index*subBlockDimXy*blockDimZ], sizeof(float)*subBlockDimXy*blockDimZ);
    countC++;
  }

  if(countA == num_chare_z-1 && countB == num_chare_x-1 && countC == num_chare_y-1) {
    countA = 0;
    countB = 0;
    countC = 0;
    contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::setupDone(), mainProxy));
    // mainProxy.setupDone();
  }
}
Esempio n. 9
0
/// @brief total feedback quantities for conservation check
/// 
/// Sums are contributed back to main chare.
/// @param bPreDist Is this before the feedback gets distributed.  In
/// this case the "out" quantities need to be summed.
void
TreePiece::massMetalsEnergyCheck(int bPreDist, const CkCallback& cb)
{
    double dTotals[5];
    for(int j = 0; j < 5; j++)
	dTotals[j] = 0.0;
    
    for(unsigned int i = 1; i <= myNumParticles; ++i) {
	GravityParticle *p = &myParticles[i];
	dTotals[0] += p->mass;
	if(p->isGas()) {
	    dTotals[1] += p->mass*p->fMetals();
	    dTotals[2] += p->mass*p->fMFracOxygen();
	    dTotals[3] += p->mass*p->fMFracIron();
	    dTotals[4] += p->mass*p->fESNrate();
	    }
	if(p->isStar()) {
	    dTotals[1] += p->mass*p->fStarMetals();
	    dTotals[2] += p->mass*p->fStarMFracOxygen();
	    dTotals[3] += p->mass*p->fStarMFracIron();
	    if(bPreDist) { // sum up the quantities that will be distributed
		dTotals[0] += p->fMSN();
		dTotals[1] += p->fSNMetals();
		dTotals[2] += p->fMOxygenOut();
		dTotals[3] += p->fMIronOut();
		dTotals[4] += p->fStarESNrate();
		}
	    }
	}
    contribute(sizeof(dTotals), dTotals, CkReduction::sum_double, cb);
    }
Esempio n. 10
0
void CentralLB::ProcessAtSync()
{
#if CMK_LBDB_ON
  if (reduction_started) return;              // reducton in progress

  CmiAssert(CmiNodeAlive(CkMyPe()));
  if (CkMyPe() == cur_ld_balancer) {
    start_lb_time = CkWallTimer();
  }

#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
	initMlogLBStep(thisgroup);
#endif

  // build message
  BuildStatsMsg();

#if USE_REDUCTION
    // reduction to get total number of objects and comm
    // so that processor 0 can pre-allocate load balancing database
  int counts[2];
  counts[0] = theLbdb->GetObjDataSz();
  counts[1] = theLbdb->GetCommDataSz();

  CkCallback cb(CkIndex_CentralLB::ReceiveCounts((CkReductionMsg*)NULL), 
                  thisProxy[0]);
  contribute(2*sizeof(int), counts, CkReduction::sum_int, cb);
  reduction_started = 1;
#else
  SendStats();
#endif
#endif
}
Esempio n. 11
0
void Compute::resetArrays() {
  int indexX = thisIndex.x;
  int indexY = thisIndex.y;
  int indexZ = thisIndex.z;
  
  float tmp;
  
  for(int i=indexZ*subBlockDimXz; i<(indexZ+1)*subBlockDimXz; i++)
    for(int j=0; j<blockDimY; j++) {
      tmp = (float)drand48(); 
      while(tmp > MAX_LIMIT || tmp < (-1)*MAX_LIMIT)
        tmp = (float)drand48();

      A[i*blockDimY + j] = tmp;
  }

  for(int j=indexX*subBlockDimYx; j<(indexX+1)*subBlockDimYx; j++)
    for(int k=0; k<blockDimZ; k++) {
      tmp = (float)drand48();
      while(tmp > MAX_LIMIT || tmp < (-1)*MAX_LIMIT)
        tmp = (float)drand48();

      B[j*blockDimZ + k] = tmp;
  }

  for(int i=0; i<blockDimX; i++)
    for(int k=0; k<blockDimZ; k++) {
      C[i*blockDimZ + k] = 0.0;
#if USE_CKDIRECT
      tmpC[i*blockDimZ + k] = 0.0;
#endif
    }

  contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::resetDone(), mainProxy));
}
Esempio n. 12
0
  void ResumeFromSync ()
  {
//      printf("Jacobi[%d] calling resumeSync\n",thisIndex);
//    if (thisIndex == 0)
//      mainProxy.report ();
//CkPrintf("Coming in MAJ MAJ MAJ RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR ++++++++\n");
	contribute(CkCallback(CkIndex_Main::report(NULL),mainProxy));
  }
Esempio n. 13
0
		void getScannedVertexNum() {
			CmiUInt8 numScannedVertices = 0;
			typedef std::vector<BFSVertex>::iterator Iterator;
			for (Iterator it = vertices.begin(); it != vertices.end(); it++) 
				numScannedVertices += it->getScannedVertexNum();
			contribute(sizeof(CmiUInt8), &numScannedVertices, CkReduction::sum_long,
								 CkCallback(CkReductionTarget(TestDriver, done),
														driverProxy));
		}
Esempio n. 14
0
FFTController::FFTController() {
  first_time = true;
  in_pointer = out_pointer = NULL;

  geps = new GSPACE();
  

  // TODO: A group dependency could probably solve this better
  contribute(CkCallback(CkReductionTarget(Controller, fftControllerReady), controller_proxy));
}
Esempio n. 15
0
	allToAll() {
        iter = 0;
        recvCnt = 0;
		msgs = new allToAllMsg*[numChares*msgCount];
		for(int i = 0; i < msgCount*numChares; i++) {
			msgs[i] = new (msgSize) allToAllMsg;
		}

		// reduction to the mainchare to signal that initialization is complete
		contribute(CkCallback(CkReductionTarget(Main,allToAllReady), mainProxy));
	}
Esempio n. 16
0
void PsiCache::reportFTime() {
  CkReduction::statisticsElement stats(total_time);
  int tuple_size = 2;
  CkReduction::tupleElement tuple_reduction[] = {
    CkReduction::tupleElement(sizeof(double), &total_time, CkReduction::max_double),
    CkReduction::tupleElement(sizeof(CkReduction::statisticsElement), &stats, CkReduction::statistics) };

  CkReductionMsg* msg = CkReductionMsg::buildFromTuple(tuple_reduction, tuple_size);
  msg->setCallback(CkCallback(CkIndex_Controller::reportFTime(NULL), controller_proxy));
  contribute(msg);
}
Esempio n. 17
0
void CentralLB::ReceiveMigration(LBMigrateMsg *m)
{
  storedMigrateMsg = m;
#if CMK_MEM_CHECKPOINT
  CkResetInLdb();
#endif
#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
	restoreParallelRecovery(&resumeAfterRestoreParallelRecovery,(void *)this);
#else
  CkCallback cb(CkIndex_CentralLB::ProcessReceiveMigration((CkReductionMsg*)NULL),
                  thisProxy);
  contribute(0, NULL, CkReduction::max_int, cb);
#endif
}
Esempio n. 18
0
		Pingping(std::size_t index, uChareSet<Pingping, CProxy_Pingping, CBase_Pingping> *uchareset) : 
			uChare<Pingping, CProxy_Pingping, CBase_Pingping>(index, uchareset)  {
			CkPrintf("[uchare=%d, chare=%d,pe=%d]: created \n", 
					getId(), getuChareSet()->getId(), getuChareSet()->getPe());

			pingDone = pongDone = false;

			pingCounters.resize(N_uChares);
			pingCounters.assign(N_uChares, -1);
			pongCounters.resize(N_uChares);
			pongCounters.assign(N_uChares, 999);

			contribute(CkCallback(CkReductionTarget(Main, start), mainProxy));
		}
Esempio n. 19
0
void Compute::receiveC() {
  int indexX = thisIndex.x;
  int indexY = thisIndex.y;
  int indexZ = thisIndex.z;

  // copy C from tmpC to the correct location
  for(int j=0; j<num_chare_y; j++) {
    if( j != indexY) {
      for(int i=0; i<subBlockDimXy; i++)
	for(int k=0; k<blockDimZ; k++)
	  C[indexY*subBlockDimXy*blockDimZ + i*blockDimZ + k] += tmpC[j*subBlockDimXy*blockDimZ + i*blockDimZ + k];
    }
  }
  /*char name[30];
  sprintf(name, "%s_%d_%d_%d", "C", thisIndex.x, thisIndex.y, thisIndex.z);
  FILE *fp = fopen(name, "w");
  for(int i=0; i<subBlockDimXy; i++) {
    for(int k=0; k<blockDimZ; k++)
      fprintf(fp, "%f ", C[indexY*subBlockDimXy*blockDimZ + i*blockDimZ + k]);
    fprintf(fp, "\n");
  }
  fclose(fp);
  CkPrintf("%d_%d_%d\n", thisIndex.x, thisIndex.y, thisIndex.z);
  for(int i=0; i<subBlockDimXy; i++) {
    for(int k=0; k<blockDimZ; k++)
      CkPrintf("%f ", C[indexY*subBlockDimXy*blockDimZ + i*blockDimZ + k]);
    CkPrintf("\n");
  }*/

  // call ready for the buffers
  for(int i=0; i<num_chare_x; i++)
    if(i != indexX)
      CkDirect_ready(&rHandles[i]);

  for(int j=0; j<num_chare_y; j++)
    if(j != indexY)
      CkDirect_ready(&rHandles[num_chare_x + j]);
  
  for(int k=0; k<num_chare_z; k++)
    if(k != indexZ)
      CkDirect_ready(&rHandles[num_chare_x + num_chare_y + k]);

  // counters to keep track of how many messages have been received
  countA = 0;
  countB = 0;
  countC = 0;

  contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::done(), mainProxy));
  // mainProxy.done();
}
Esempio n. 20
0
void Workers::complete() {
  int size = matrixSize * matrixSize * sizeof(ElementType); 
  memcpy(C, h_C, size); 
#ifdef DEBUG
  CkPrintf("[%d] A\n", thisIndex); 
  for (int i=0; i<matrixSize; i++) {
    CkPrintf("[%d] ", thisIndex);
    for (int j=0; j<matrixSize; j++) {
      CkPrintf("%.2f ", A[i*matrixSize+j]); 
    }
    CkPrintf("\n");
  }
  CkPrintf("[%d] B\n", thisIndex); 
  for (int i=0; i<matrixSize; i++) {
    CkPrintf("[%d] ", thisIndex);
    for (int j=0; j<matrixSize; j++) {
      CkPrintf("%.2f ", B[i*matrixSize+j]); 
    }
    CkPrintf("\n");
  }
  CkPrintf("[%d] C\n", thisIndex);
  for (int i=0; i<matrixSize; i++) {
    CkPrintf("[%d] ", thisIndex);
    for (int j=0; j<matrixSize; j++) {
      if(useCublas)
        CkPrintf("%.2f ", C[j*matrixSize+i]);
      else
        CkPrintf("%.2f ", C[i*matrixSize+j]);
    }
    CkPrintf("\n");
  }
  CkPrintf("[%d] C-gold\n", thisIndex);
  for (int i=0; i<matrixSize; i++) {
    CkPrintf("[%d] ", thisIndex);
    for (int j=0; j<matrixSize; j++) {
      C[i*matrixSize + j] = 0; 
      for (int k=0; k<matrixSize; k++) {
	C[i*matrixSize + j] += A[i*matrixSize +k] * B[k * matrixSize + j];
      }
      CkPrintf("%.2f ", C[i*matrixSize+j]); 
    }
    CkPrintf("\n");
  }

#endif

  contribute(CkCallback(CkIndex_Main::finishWork(NULL), mainProxy));
}
Esempio n. 21
0
  void System::ImportFluidData()
  {
#endif
    assert(ImportFluidData_nRequestedUpdates == 0);

    const int nremote     = nimport_glb;
    const int iremote_end = ptcl_act.size();
    const int iremote_beg = iremote_end - nremote;

    std::vector< std::pair<int, int> > request_list;
    request_list.reserve(nremote);
    for (int i = iremote_beg; i < iremote_end; i++)
      if (ptcl_act[i]->is_ngb())
        request_list.push_back(std::make_pair(ptcl_act[i]->chare(), i));

    std::sort(request_list.begin(), request_list.end(), std_pair_first_sort());

    const int nrequest = request_list.size();
    CkVec< pair<int, int> > sites2request;
    sites2request.reserve(nrequest);
    request_list.push_back(std::make_pair(-1,-1));

    for (int i = 0; i < nrequest; i++)
    {
      const int iElement = request_list[i].first;
      const int iId      = request_list[i].second;
      sites2request.push_back(std::make_pair(ptcl_act[iId]->id(), iId));
      assert(iElement >= 0);
      assert(iElement < numElements);
      assert(iElement != thisIndex);
      if (iElement != request_list[i+1].first && sites2request.size() > 0)
      {
        ImportFluidData_nRequestedUpdates++;
        systemProxy[iElement].ImportFluidData_request(sites2request, thisIndex);
        sites2request.clear();
      }
    }


    if (ImportFluidData_nRequestedUpdates == 0)
    {
#if 1
      ImportFluidData_completeCb.send();
#else
      contribute(ImportFluidData_completeCb);
#endif
    }
  }
Esempio n. 22
0
// Function that checks whether it must start the following step or wait until other messages are received
void Patch::checkNextStep(){
  int i;
  double timer;

  if (updateFlag && incomingFlag) {
    // resetting flags
    updateFlag = false;
    incomingFlag = false;
    stepCount++;

    // adding new elements
    for (i = 0; i < incomingParticles.length(); i++)
      particles.push_back(incomingParticles[i]);
    incomingParticles.removeAll();

    if (thisIndex.x == 0 && thisIndex.y == 0 && thisIndex.z == 0 && stepCount%NUM_STEPS == 0) {
      timer = CmiWallTimer();
      CkPrintf("Step %d Benchmark Time %f ms/step, Total Time Elapsed %f s\n", stepCount, ((timer - stepTime)/NUM_STEPS)*1000, timer);
      stepTime = timer;
//      if (stepCount == 300)
//	traceBegin();
  //    if (stepCount == 400)
//	traceEnd();

    }
 //   if (stepCount == 300 && thisIndex.x*patchArrayDimY*patchArrayDimZ + thisIndex.y*patchArrayDimZ + thisIndex.z < 8)
 //     traceBegin();
 //   if (stepCount == 301 && thisIndex.x*patchArrayDimY*patchArrayDimZ + thisIndex.y*patchArrayDimZ + thisIndex.z < 8)
 //     traceEnd();

    // checking for next step
    if (stepCount >= finalStepCount) {
     // CkPrintf("Final number of particles is %d on Patch [%d][%d][%d]\n", particles.length(), thisIndex.x, thisIndex.y, thisIndex.z);
      print();
      contribute(CkCallback(CkIndex_Main::allDone(), mainProxy)); 
    } else {
      if (perform_lb){
	AtSync();
	LBTurnInstrumentOff();
	perform_lb=false;
      }
      else{
	thisProxy(thisIndex.x, thisIndex.y, thisIndex.z).start();
	//contribute(CkCallback(CkIndex_Main::lbBarrier(),mainProxy));
      }
    }
  }
}
Esempio n. 23
0
void
piPart::compute(int ns)
{
  int i;
  int count=0;
  for (i= 0; i<ns; i++) {
    double x = CrnDrand();
    double y = CrnDrand();
    if ((x*x + y*y) <= 1.0) count++;
  }
#if ! USE_REDUCTION
  CProxy_main mainproxy(mainhandle);
  mainproxy.results(count);
#else
  contribute(sizeof(int), (void *)&count, CkReduction::sum_int);
#endif
}
Esempio n. 24
0
void CentralLB::endMigrationDone(int balancing){
    DEBUGF(("[%d] CentralLB::endMigrationDone step %d\n",CkMyPe(),step()));


  if (balancing && _lb_args.syncResume()) {
    CkCallback cb(CkIndex_CentralLB::ResumeClients((CkReductionMsg*)NULL),
                  thisProxy);
    contribute(0, NULL, CkReduction::sum_int, cb);
  }
  else{
    if(CmiNodeAlive(CkMyPe())){
    DEBUGF(("[%d] Sending ResumeClients balancing %d \n",CkMyPe(),balancing));
    thisProxy [CkMyPe()].ResumeClients(balancing);
    }
  }

}
Esempio n. 25
0
  void check_and_compute ()
  {
//       if (--messages_due == 0) 

//          messages_due = 4;
    compute ();
    if (iterations % ldbTime == 4/* || iterations == 100*/)
      {
//                        printf("MINOR[%d] itr=%d ----------------------------- ssssssssssssss\n",thisIndex,iterations);
	AtSync ();
      }

    else
//      mainProxy.report ();
	contribute(CkCallback(CkIndex_Main::report(NULL),mainProxy));


  }
Esempio n. 26
0
  Participant() {

    int numPes = CkNumPes();
    neighbors = new int[numPes];
    for (int i = 0; i < numPes; i++) {
      neighbors[i] = i;
    }

    // shuffle to prevent bottlenecks
    for (int i = numPes-1; i >= 0; i--) {
      int shuffleIndex = rand() % (i+1);
      int temp = neighbors[i];
      neighbors[i] = neighbors[shuffleIndex];
      neighbors[shuffleIndex] = temp;
    }

    contribute(CkCallback(CkReductionTarget(Main, prepare), mainProxy));
  }
Esempio n. 27
0
/* Default constructor */
Patch::Patch(FileDataMsg* fdmsg) {
  LBTurnInstrumentOff();
  inbrs = numNbrs;
  usesAtSync = CmiTrue;

  updateCount = 0;
  forceCount = 0;
  stepCount = 0;
  resumeCount = 0;
  updateFlag = false;
  incomingFlag = false;
  perform_lb = false;
  incomingParticles.resize(0);
  // setMigratable(CmiFalse);

  int i;

  // Particle initialization
  myNumParts = 0;
  for(i=0; i < fdmsg->length; i++) {
    particles.push_back(Particle());
    particles[myNumParts].charge = fdmsg->charge[i];
    particles[myNumParts].mass = fdmsg->mass[i];

    particles[myNumParts].x = fdmsg->coords[i].x;
    particles[myNumParts].y = fdmsg->coords[i].y;
    particles[myNumParts].z = fdmsg->coords[i].z;

    particles[myNumParts].vx = 0;
    particles[myNumParts].vy = 0;
    particles[myNumParts].vz = 0;
    particles[myNumParts].fx = 0;
    particles[myNumParts].fy = 0;
    particles[myNumParts].fz = 0;

    particles[myNumParts].id = (thisIndex.x*patchArrayDimX + thisIndex.y) * numParts / (patchArrayDimX*patchArrayDimY)  + i;

    particles[myNumParts].vdw_type = fdmsg->vdw_type[i];
    myNumParts++;
  }

  delete fdmsg;
  contribute(CkCallback(CkIndex_Main::startUpDone(), mainProxy));
}
Esempio n. 28
0
    void run() {
      for (int i = 0 ; i < numelements; i++) {
        
        if(thisIndex % 2 == 0 && thisIndex != numelements -1 ) {
          myMsg* m = workerarray[thisIndex + 1].sendSmaller(val);
          val = m->val;
          delete m;
        } 
        barrier();
        if (thisIndex % 2 == 1 && thisIndex != numelements -1 ) {
          myMsg* m  = workerarray[thisIndex + 1].sendSmaller(val);
          val = m->val;
          delete m;
        }
        barrier();
      }

      contribute(CkCallback(CkIndex_Main::done(NULL), mainproxy)); 

    }
Esempio n. 29
0
void PsiCache::receivePsi(PsiMessage* msg) {
  if (msg->spin_index != 0) {
    CkAbort("Error: We don't support multiple spins yet!\n");
  }
  CkAssert(msg->k_index < K);
  CkAssert(msg->state_index < L);
  CkAssert(msg->size == psi_size);
  if(msg->shifted==false){std::copy(msg->psi, msg->psi+psi_size, psis[msg->k_index][msg->state_index]);}
  if(msg->shifted==true){std::copy(msg->psi, msg->psi+psi_size, psis_shifted[msg->k_index][msg->state_index]);}
  delete msg;

  // Once the cache has received all of it's data start the sliding pipeline
  // sending of psis to P to start the accumulation of fxf'.
  int expected_psis = K*L;
  if(qindex == 0)
    expected_psis += K*L;
  if (++received_psis == expected_psis) {
    //CkPrintf("[%d]: Cache filled\n", CkMyPe());
    contribute(CkCallback(CkReductionTarget(Controller,cachesFilled), controller_proxy));
  }
}
Esempio n. 30
0
void CentralLB::MigrationDone(int balancing)
{
#if CMK_LBDB_ON
  migrates_completed = 0;
  migrates_expected = -1;
  // clear load stats
  if (balancing) theLbdb->ClearLoads();
  // Increment to next step
  theLbdb->incStep();
	DEBUGF(("[%d] Incrementing Step %d \n",CkMyPe(),step()));
  // if sync resume, invoke a barrier

#if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
    savedBalancing = balancing;
    startLoadBalancingMlog(&resumeCentralLbAfterChkpt,(void *)this);
#endif

  LBDatabase::Object()->MigrationDone();    // call registered callbacks

  LoadbalanceDone(balancing);        // callback
#if (!defined(_FAULT_MLOG_) && !defined(_FAULT_CAUSAL_))
  // if sync resume invoke a barrier
  if (balancing && _lb_args.syncResume()) {
    CkCallback cb(CkIndex_CentralLB::ResumeClients((CkReductionMsg*)NULL), 
                  thisProxy);
    contribute(0, NULL, CkReduction::sum_int, cb);
  }
  else{	
    if(CmiNodeAlive(CkMyPe())){
	thisProxy [CkMyPe()].ResumeClients(balancing);
    }	
  }	
#if CMK_GRID_QUEUE_AVAILABLE
  CmiGridQueueDeregisterAll ();
  CpvAccess(CkGridObject) = NULL;
#endif
#endif 
#endif
}