Exemplo n.º 1
0
/*
   http://www.taygeta.com/random/gaussian.html
*/
double get_gaussian_noise(void) {

  double x1;
  static int nb_call = 0;
  static double x2, w;
  if (nb_call==0) r250_init(0);
  nb_call++;
  if (nb_call%2) {
    do {
      x1 = 2.0 * dr250() - 1.0;
      x2 = 2.0 * dr250() - 1.0;
      w = x1 * x1 + x2 * x2;
    } while ( w >= 1.0 );

    w = sqrt( (-2.0 * log( w ) ) / w );
    return x1 * w;
  }
  else
    return x2 * w;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
void rnd_init(void)
{
  r250_init(time(NULL));
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
void rnd_seed(unsigned seed)
{
  r250_init(seed);
}
Exemplo n.º 4
0
int main(int argc, char** argv) {

	unsigned int* __restrict address;
	unsigned int* __restrict memory;

	unsigned int i, j;
	unsigned int t=0;
	unsigned int numberOfMemoryLocation;

	dictionary *programInput;
	double startTime;
	double elapsedTime = 0, totalElapsedTime = 0;
	double initializationTime, experimentTime;

	programInput = ParseInput(argc, argv);
	ValidateParameters();

	// Initialize memory manager
	MMMasterInitialize(0, 0, FALSE, NULL);

	numberOfMemoryLocation = MemorySize / sizeof(int);

	// Allocate memory
	address = MMUnitAllocate((NumberOfAccess + 8) * sizeof(unsigned int));
	memory = MMUnitAllocate((numberOfMemoryLocation + 32) * sizeof(unsigned int));

	// Set random seed
	r250_init(getRandomSeed());

	// Set start time
	startTime = setStartTime();

	printf("Initialize memory pointers with random values..");


	for (i=0; i<numberOfMemoryLocation + 32; i++) {
		memory[i] = r250();
	}
	// Initialize address and memory
	for (i=0; i<NumberOfAccess + 8; i++) {
		address[i] = (r250() % numberOfMemoryLocation) / 4 * 4;
	}

	printf("finished.\n");

	elapsedTime = getElapsedTime(startTime) - totalElapsedTime;
	totalElapsedTime += elapsedTime;
	initializationTime = elapsedTime;

	// Test memory speed for read
	if (ReadWrite[0] == 'R' || ReadWrite[0] == 'r') {
		for (i=0; i<NumberOfIteration; i++) {
			for (j=0; j<NumberOfAccess; j++) {


				t += memory[address[j]];

			}
		}
	}
	// Test memory speed for write
	if (ReadWrite[0] == 'W' || ReadWrite[0] == 'w') {
		for (i=0; i<NumberOfIteration; i++) {
			for (j=0; j<NumberOfAccess; j++) {
				memory[address[j]] += address[j];
			}
		}
	}

	elapsedTime = getElapsedTime(startTime) - totalElapsedTime;
	totalElapsedTime += elapsedTime;
	experimentTime = elapsedTime;

	// So that compiler does not remove code for variables t and r
	if (t==0) {
		printf("\n");
	}

	printf("Experiment completed.\n");

	printf("Initialization time   = ");
	printElapsedTime(stdout, FALSE, FALSE, TRUE, 2, initializationTime);
	printf("Experiment time       = ");
	printElapsedTime(stdout, FALSE, FALSE, TRUE, 2, experimentTime);
	
	MMUnitFree(address, (NumberOfAccess + 8) * sizeof(unsigned int));
	MMUnitFree(memory, (numberOfMemoryLocation + 32) * sizeof(unsigned int));

	iniparser_freedict(programInput);

	return 0;

}