Exemple #1
0
static void multires_reshape_store_original_grids(MultiresPropagateData *data)
{
  const int num_grids = data->num_grids;
  /* Original data to be backed up. */
  const MDisps *mdisps = data->mdisps;
  const GridPaintMask *grid_paint_mask = data->grid_paint_mask;
  /* Allocate grids for backup. */
  CCGKey *orig_key = &data->reshape_level_key;
  CCGElem **orig_grids_data = allocate_grids(orig_key, num_grids);
  /* Fill in grids. */
  const int orig_grid_size = data->reshape_grid_size;
  const int top_grid_size = data->top_grid_size;
  const int skip = (top_grid_size - 1) / (orig_grid_size - 1);
  for (int grid_index = 0; grid_index < num_grids; grid_index++) {
    CCGElem *orig_grid = orig_grids_data[grid_index];
    for (int y = 0; y < orig_grid_size; y++) {
      const int top_y = y * skip;
      for (int x = 0; x < orig_grid_size; x++) {
        const int top_x = x * skip;
        const int top_index = top_y * top_grid_size + top_x;
        memcpy(CCG_grid_elem_co(orig_key, orig_grid, x, y),
               mdisps[grid_index].disps[top_index],
               sizeof(float) * 3);
        if (orig_key->has_mask) {
          *CCG_grid_elem_mask(
              orig_key, orig_grid, x, y) = grid_paint_mask[grid_index].data[top_index];
        }
      }
    }
  }
  /* Store in the context. */
  data->orig_grids_data = orig_grids_data;
}
Exemple #2
0
/*
 * Initialize cells based on input file, otherwise all cells
 * are DEAD.
 */
void init_grids (struct life_t * life) 
{
	FILE * fd;
	int i,j;

	if (life->infile != NULL) {
		if ((fd = fopen(life->infile, "r")) == NULL) {
			perror("Failed to open file for input");
			exit(EXIT_FAILURE);
		}

		if (fscanf(fd, "%d %d\n", &life->nrows, &life->tcols) == EOF) {
			printf("File must at least define grid dimensions!\nExiting.\n");
			exit(EXIT_FAILURE);
		}
	}

	// resize so each process is in charge of a vertical slice of the whole board
	life->ubound = (((life->rank + 1) * life->tcols / life->size) - 1); // we want 1 col of (overlap?)
	life->lbound = life->rank * life->tcols / life->size;
	life->ncols = (life->ubound - life->lbound) + 1;

	printf("[Process %d] lower bound is %d upper bound is %d width is %d random seed is %d.\n", life->rank, life->lbound, life->ubound, life->ncols, life->randseed);

	allocate_grids(life);

	for (i = 0; i < life->nrows+2; i++) {
		for (j = 0; j < life->ncols+2; j++) {
			life->grid[i][j]      = DEAD;
			life->next_grid[i][j] = DEAD;
		}
	}

	if (life->infile != NULL) {
		while (fscanf(fd, "%d %d\n", &i, &j) != EOF) {
			if (j <= life->ubound && j >= life->lbound){
				fprintf(stderr, "[Process %d] %d %d -> %d %d.\n", life->rank, i, j, i, j - life->lbound);
				life->grid[i+1][j - life->lbound + 1]      = ALIVE;
				life->next_grid[i+1][j- life->lbound + 1] = ALIVE;
			}
		}
		
		fclose(fd);
	} else {
		randomize_grid(life, INIT_PROB);
	}

	if (life->print){
		printf("[Host %d] printing initial slice.\n", life->rank);
		print_grid (life);
	}
}
Exemple #3
0
static void multires_reshape_propagate(MultiresPropagateData *data)
{
  if (data->reshape_level == data->top_level) {
    return;
  }
  const int num_grids = data->num_grids;
  /* Calculate delta made at the reshape level. */
  CCGKey *delta_level_key = &data->top_level_key;
  CCGElem **delta_grids_data = allocate_grids(delta_level_key, num_grids);
  multires_reshape_calculate_delta(data, delta_grids_data);
  /* Propagate deltas to the higher levels. */
  multires_reshape_propagate_and_smooth_delta(data, delta_grids_data);
  /* Finally, apply smoothed deltas. */
  multires_reshape_propagate_apply_delta(data, delta_grids_data);
  /* Cleanup. */
  free_grids(delta_grids_data, num_grids);
}