Exemple #1
0
/*------------------------------------------------
 * Single step evolution of the simulation.
 * 
 * The cell values represent:
 * 	0  : empty space
 * 	<0 : crystal  -- for consistency with alternative formulation
 * 
 * Particles are held in a separate array.
 */
void dla_evolve_plist (int *pic, int rows, int cols, PartStr *p, int *particles, PartStr *changes, int *numChanges)
{
  int i;
  *numChanges=0;
  
  for (i = 0; i < *particles; i++)
	{
	  int new_x = p[i].x + three_way ();
	  if (new_x == 0)  // bounce off boundaries
	    new_x = 1;
	  else if (new_x == cols - 1)
	    new_x = cols - 2;

	  int new_y = p[i].y + three_way ();
	  if (new_y == 0)  // bounce off boundaries
	    new_y = 1;
	  else if (new_y == rows - 1)
	    new_y = rows - 2;

	  if (pic[new_y * cols + new_x] == 0)	// steps into empty space
	    {
	      int turnCrystal = check_proxim (pic, cols, new_x, new_y);
	      if(turnCrystal<0)
	      {
		 // The application of changes can take place here in a sequential program
		 // but this affects the behavior of the code. For consistency with the 
		 // parallel version, a separate function is used for this purpose
                 // pic[new_y * cols + new_x] = -1;
                 
		 // record crystal change 
		 changes[*numChanges].x = new_x;
		 changes[*numChanges].y = new_y;
		 (*numChanges) ++;
		 // erase particle from list
		 p[i] = p[(*particles) - 1];
		 i--;
		 (*particles)--;
	      }
	      else  // change position to particle
	      {
		p[i].x=new_x;
		p[i].y=new_y;
	      }
	    }
	}
}
Exemple #2
0
/*------------------------------------------------
 * Single step evolution of the simulation.
 * 
 * The cell values represent:
 * 	0: empty space
 * 	>0 : multiple particles
 * 	<0 : crystal
 * 
 * Returns the address of the structure holding the last update */
int *dla_evolve (int *pic, int *pic2, int rows, int cols)
{
  int x, y, k;

  // prepare array to hold new state
  for (y = 1; y < rows-1; y++)
    for (x = 1; x < cols-1; x++)
      pic2[y * cols + x] = pic[y * cols + x] > 0 ? 0 : pic[y * cols + x];

  for (y = 1; y < rows - 1; y++)
    for (x = 1; x < cols - 1; x++)
      for (k = 0; k < pic[y * cols + x]; k++)
	{
	  int new_x = x + three_way ();
	  if (new_x == 0)
	    new_x = 1;
	  else if (new_x == cols - 1)
	    new_x = cols - 2;

	  int new_y = y + three_way ();
	  if (new_y == 0)
	    new_y = 1;
	  else if (new_y == rows - 1)
	    new_y = rows - 2;

	  if (pic2[new_y * cols + new_x] > 0)	// steps into empty space
	    pic2[new_y * cols + new_x]++;
	  else if (pic2[new_y * cols + new_x] == 0)	// steps into unchecked space
	    {
	      pic2[new_y * cols + new_x] =
		check_proxim (pic2, cols, new_x, new_y);
	    }
	  /* if pic2[new_y * cols + new_x] <0 the particle steps into space that will be part
	   * of the structure on the next iteration. In this case nothing is done and
	   * the particle is effectively "lost", which helps calculation simplicity */
	}

  return pic2;
}
Exemple #3
0
int main(int argc, char** argv) {
    std::string one = argv[1];
    std::string two = argv[1]+std::string(";");
    std::string three = "";
    
    clock_t begin = clock();
    unsigned r = three_way(one.c_str(), two.c_str(), three.c_str());
    clock_t end = clock();
    std::cout << "three_way:\t" << (end-begin) << " ticks\t" << r << '\n';
    
    begin = clock();
    r = two_way(one, two, three);
    end = clock();
    std::cout << "two_way:\t" << (end-begin) << " ticks\t" << r << '\n';
    
    begin = clock();
    r = two_wayish(one, two, three);
    end = clock();
    std::cout << "two_wayish:\t" << (end-begin) << " ticks\t" << r << '\n';
    
}
Exemple #4
0
int main(int argc, char *argv[])
{
	int c;
	const char *fname1, *fname2, *fname_exclude=NULL;
	struct hash_handle *hh1, *hh2, *hh_exclude=NULL;

	setlinebuf(stdout);

	options.line_fuzz = 6;
	options.min_matches = 2;

	while ((c = getopt(argc, argv, "hx:Af:m:u:")) != -1) {
		switch (c) {
		case 'x':
			fname_exclude = optarg;
			break;
		case 'f':
			options.line_fuzz = atoi(optarg);
			break;
		case 'm':
			options.min_matches = atoi(optarg);
			break;
		case 'u':
			options.max_uses = atoi(optarg);
			break;
		case 'A':
			options.avoid_self_matches = 1;
			break;
		case 'h':
		default:
			usage();
			exit(0);
		}
		
	}

	argv += optind;
	argc -= optind;

	if (argc != 2) {
		usage();
		exit(1);
	}

	fname1 = argv[0];
	fname2 = argv[1];

	hh1 = hh_open(fname1);
	if (!hh1) {
		perror(fname1);
		exit(1);
	}

	hh2 = hh_open(fname2);
	if (!hh2) {
		perror(fname2);
		exit(1);
	}

	if (hh1->token_width != hh2->token_width) {
		fprintf(stderr,"Token widths do not match! %s=%d %s=%d\n", 
			hh1->fname, hh1->token_width,
			hh2->fname, hh2->token_width);
		exit(1);
	}

	if (fname_exclude) {
		hh_exclude = hh_open(fname_exclude);
		if (!hh_exclude) {
			perror(fname_exclude);
			exit(1);
		}
	}

	three_way(hh1, hh2, hh_exclude);

	return 0;
}