Exemple #1
0
/*
Any live cell with fewer than two live neighbours dies, as if caused by under-population.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overcrowding.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
*/
void LifeGame::update(){
	int i;
	for (i = 0; i < (size*size); i++) {
		if (curr_board)
			update_cell(i, board_b, board_a);
		else
			update_cell(i, board_a, board_b);
	}
	curr_board = !curr_board; //swap the buffer!
}
Exemple #2
0
void update_world(world w) {
	int i;
	
	for(i=0 ; i < w->cells_counter ; i++) {
		update_cell(&(w->cells[i]), w);
	}
}
    inline void EulerUpstreamResidual<GI, RP, BC>::
    computeResidual(const std::vector<double>& saturation,
                    const typename GI::Vector& gravity,
                    const PressureSolution& pressure_sol,
                    const Opm::SparseVector<double>& injection_rates,
                    const bool method_viscous,
                    const bool method_gravity,
                    const bool method_capillary,
                    std::vector<double>& residual) const
    {
	// Make sure sat_change is zero, and has the right size.
	residual.clear();
	residual.resize(saturation.size(), 0.0);

        pinjection_rates_ = &injection_rates;
        method_viscous_ = method_viscous;
        method_gravity_ = method_gravity;
        method_capillary_ = method_capillary;

	// For every face, we will modify residual for adjacent cells.
	// We loop over every cell and intersection, and modify only if
	// this cell has lower index than the neighbour, or we are on the boundary.
        typedef EulerUpstreamResidualDetails::UpdateForCell<EulerUpstreamResidual<GI,RP,BC>, PressureSolution> CellUpdater;
        CellUpdater update_cell(*this, saturation, gravity, pressure_sol, residual);
        EulerUpstreamResidualDetails::UpdateLoopBody<CellUpdater> body(update_cell);
        EulerUpstreamResidualDetails::IndirectRange<CIt> r(cell_iters_);
#ifdef USE_TBB
        tbb::parallel_for(r, body);
#else
        body(r);
#endif
    }
/*********************************************************
 * MAIN ENTRY
 *********************************************************/
int main(int argc, char *argv[]) {
    if ( argc != 3 ) {
        printf("usage: ./cell_cpu dimension nSteps\n");
        exit(1);
    }
    int dim = atoi(argv[1]); // dimension
    int nSteps = atoi(argv[2]); // number of steps
//    int frequency = atoi(argv[3]); // frequency of printing outputs
    int size = dim * dim; // size of 1-d array
    int *grid = NULL; // grid use to update
    int *grid_copy = NULL; // copy of original grid in each iteration
    int *temp = NULL;
    clock_t start;
    
    grid = (int *)malloc(size * sizeof(int));
    memset((void *)grid, 0, size);
    grid[1] = 1;
    grid[dim + 2] = 1;
    grid[dim * 2] = 1;
    grid[dim * 2 + 1] = 1;
    grid[dim * 2 + 2] = 1;
    
    grid_copy = (int *)malloc(size * sizeof(int));
    memcpy((void *)grid_copy, (const void *)grid, size * sizeof(int));
    
    //---- get initial time ----
    start=clock();
    for (int iter = 0; iter < nSteps; iter++) {
        //------- update grid ------
        for (int i = 0; i < size; i++) {
            update_cell(grid, grid_copy, i, dim, iter);
        }
        //---- update grid_copy ----
        temp = grid_copy;
        grid_copy = grid;
        grid = temp;
    }
    
    //-------- print elapsed time ------
    printf("%f\n", ((float)(clock() - start)) / CLOCKS_PER_SEC);
    
    return 0;
}
Exemple #5
0
void update_grid()
{
  int i, j;
  int count = 0;
  recursion_count++;
  for(i=0; i<9; i++)
  {
    for(j=0;j<9;j++)
    {
      if(grid[i][j] == 0)
      {
        count += update_cell(i,j);
      }
    }
  }

  if(count > 0)
    update_grid();

  else
  {
    if(resolved_cells == 81)
    {
      printf("\nSolution:\n");
      display();
    }
    else
    {
      if(eliminate())
        update_grid();
      else
      {
        display();
        printf("\nAfter %d recursive steps cells resolved: %d.\n\n", recursion_count, resolved_cells);
      }
    }
  }
}
Exemple #6
0
void			draw_player_cells(t_world *world, t_view *view, t_player *player)
{
	t_elem		*cellrunner;
	t_cell		*cell;

	cellrunner = player->cells->begin;
	while (cellrunner)
	{
		cell = cellrunner->cell;
		clear_cell(cell, view->surface);
		if (cell->area < 9)
		{
			list_remove_elem(player->cells, cellrunner);/*
			dprintf(2, "\033[2J\033[HAlive cells: %d\n", player->cells->size);*/
		}
		else
		{
			update_cell(world, view, cell);
			draw_cell(cell, view->surface);
		}
		cellrunner = cellrunner->next;
	}
}
Exemple #7
0
/* Handler: retrieveForces
 * Extracts forces and potential energy from message sent from cellPair and
 * update atom coordinates in each cell
 */
void retrieveForces(char *info)
{
  int x, y, z;
  BgGetMyXYZ(&x, &y, &z);
  // CmiPrintf("retrieveForces in node [%d,%d,%d]\n", x, y, z);

  UserData*  ud = (UserData*)BgGetNodeData();
  ForceMsg*  forcemsg = (ForceMsg*)info;

  /* search for which cell on this node has the forces arrived */
  CellData* cellDataArray = ud->cellData ;
  CellCoord* cellCoord = &forcemsg->cellCoord; 

  int cellIndex = 0;
  bool Found = false;
  while(cellIndex < ud->cellCount && !(Found))
  {
	if(cellDataArray[cellIndex].myCoord == *cellCoord)
	   Found = true;
	else
	   cellIndex++;
  }
  
  if(!Found)
  	CmiAbort("Error> Cell not found in NodePrivateData\n");

  CellData* cellData = &cellDataArray[cellIndex];

  cellData->countForceReceived++ ;

  /* update data of the cell */
  cellData->myPotEnergy += forcemsg->potEnergy ;
  Cell *cell = cellData->myCell ;

  for(int j=0, i=0; i<cell->n_atoms; i++)
  {
    	cell->atoms[i].fx += forcemsg->dForceBuff[j++] ; 
    	cell->atoms[i].fy += forcemsg->dForceBuff[j++] ; 
    	cell->atoms[i].fz += forcemsg->dForceBuff[j++] ;	
  }

  /* check if all pair computations are done, update coordinates of atoms */
  if(cellData->countForceReceived==cellData->neighborCount)
  {
  	/* calculate self interactions */
	cellData->myPotEnergy += calc_self_interactions(cellData->myCell, ud->spData);
	cellData->myKinEnergy = update_cell(cell, ud->spData, cellData->firstStep);
	cellData->firstStep = false;

	/* start reduction */
	EnergyMsg* energyMsg = new EnergyMsg;
	energyMsg->potEnergy = cellData->myPotEnergy;
	energyMsg->kinEnergy = cellData->myKinEnergy;

	ud->lmdData->nreported++;
	if (ud->lmdData->nreported == ud->cellCount) {
          CellPairData* clear = NULL;
          while(ud->cellPairData) {
            clear = ud->cellPairData;
            ud->cellPairData = clear->next;
            delete [] clear->cell1->atoms;
            delete clear->cell1;
            delete [] clear->cell2->atoms;
            delete clear->cell2;
            delete clear;
          }
          ud->lmdData->nreported=0;
	  /*
          int x,y,z; BgGetMyXYZ(&x, &y, &z);
          CmiPrintf("report %d %d %d\n", x, y, z);
          */
	}

//    CmiPrintf("report %d %d %d\n", cellCoord->x, cellCoord->y, cellCoord->z);
	BgSendPacket(0, 0, 0, ANYTHREAD, reduceID, LARGE_WORK, sizeof(EnergyMsg), (char*)energyMsg);

  }
  delete forcemsg;
}