static void *monteCarloTaskStart(void *initialData)
{
	assert(initialData != NULL);
	MonteCarloConfig *mcc = (MonteCarloConfig*) initialData;

	int nb = floor(world.worldSize / mcc->boxSize);

	if (nb < 0)
		die("World so small (or boxSize so big) that I can't fit a "
				"single box in there!\n");

	/* adjust boxsize to get the correct world size! */
	double trueBoxSize = world.worldSize / nb;
	printf("Requested boxsize %f, actual box size %f\n",
						mcc->boxSize, trueBoxSize);
	if (world.twoDimensional) {
		printf("Allocating grid for 2D world, %d boxes/dim.\n", nb);
		allocGrid(nb, nb, 1, trueBoxSize);
	} else {
		printf("Allocating grid for 3D world, %d boxes/dim.\n", nb);
		allocGrid(nb, nb, nb, trueBoxSize);
	}
	
	fillWorld();

	MonteCarloState *state = malloc(sizeof(*state));
	state->conf = *mcc;
	state->attempted = 0;
	state->accepted = 0;

	free(mcc);
	return state;
}
Exemple #2
0
/*
 * Main
 */
int main(int argc, char *argv[]) {
  // Parse command line
  if(!optparse(argc, argv))
    abort();

  /* Nanosleep Setup */
  int milisec = 250; // length of time to sleep, in miliseconds
  struct timespec req = {0};
  req.tv_sec = 0;
  req.tv_nsec = milisec * 1000000L;

  // Initialisieren der Welt und den Zellen
  world_t world;

  /* Allocate Memory */
  allocateMemory(&world);

  /* Welt befüllen */
  if(path) {
    read_world(&world, path);
  } else if (!create_world(&world)) {
      printf("error creating world\n");
      exit(-2);
  } else {
    fillWorld(&world);
  }

  /* Welt ausgeben */
  printWorld(&world);

  /*
   * Nächster Schritt ausführen
   * TODO: Beenden der Schleife wenn sich nichts mehr ändert
   */
  while (true) {
    (automode) ? nanosleep(&req, (struct timespec *)NULL) : bwait();
    nextStep(&world);
    printWorld(&world);
  }
  return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{
	bool keepGoing = true;

	srand(time(NULL)); //seed random generator

	parseArguments(argc, argv);

	allocWorld();
	fillWorld();
	
	Timer renderTimer = makeTimer(1.0 / config.framerate);

	if (config.render)
		initRender();

	if (config.measureSamples < 0) {
		/* Loop forever, or until the user quits the renderer */
		while (stepSimulation(&renderTimer));
	} else {
		printf("Waiting for system to relax.\n");
		for (double t = 0; keepGoing && t < config.measureWait; t += config.timeStep) {
			keepGoing = stepSimulation(&renderTimer);
			if (fmod(t, config.measureWait / 100) < config.timeStep) {
				printf("\rRelax time %13f of %f",
						(t + config.measureWait/100) / TIME_FACTOR, 
						config.measureWait / TIME_FACTOR);
				fflush(stdout);
			}
		}

		/* Perform the measurements */
		printf("\nStarting measurement.\n");
		FILE *outstream = fopen(DATA_FILE_NAME, "w");
		//plotHeader(outstream);
		double intervalTime = 0;
		for (long sample = 0; keepGoing && sample < config.measureSamples; sample++) {
			while (keepGoing && intervalTime <= config.measureInterval) {
				keepGoing = stepSimulation(&renderTimer);
				intervalTime += config.timeStep;
			}
			if (!keepGoing)
				break;

			/* Check for numerical drift (or bugs) before 
			 * commiting measurement. */
			if (!physicsCheck())
				die("You broke physics!\n");

			dumpEnergies(outstream);
			printf("\rMeasured sample %ld/%ld", sample + 1, config.measureSamples);
			fflush(stdout);
			intervalTime -= config.measureInterval;
		}
		printf("\n");
		fclose(outstream);
	}

	freeWorld();
	return 0;
}