コード例 #1
0
ファイル: sort.c プロジェクト: nip3o/tddd56
////////////////////////////////////////////////////////////////////////////////
// main computation function
////////////////////////////////////////////////////////////////////////////////
void computeImages()
{
  const char *outputname_cpu = "task1_out_cpu.rbm";
  const char *outputname_gpu = "task1_out_gpu.rbm";
  unsigned int seed;
  int i, length = dataWidth * dataHeight; // SIZE OF DATA
  unsigned short int header[2];

  gettimeofday(&t_s_cpu, NULL);
  seed = (unsigned int)t_s_cpu.tv_usec;
  printf("\nseed: %u\n",seed);

  if (init_OpenCL()<0)
  {
    close_OpenCL();
    return;
  }

  data_cpu = generateRandomField(seed,length);
  data_gpu = (unsigned int *)malloc (length*sizeof(unsigned int));

  if ((!data_cpu)||(!data_gpu))
  {
    printf("\nError allocating data.\n\n");
    return;
  }
  
  for(i=0;i<length;i++)
    data_gpu[i]=data_cpu[i];
  
  gettimeofday(&t_s_cpu, NULL);
  cpu_Sort(data_cpu,length);
  gettimeofday(&t_e_cpu, NULL);

  gettimeofday(&t_s_gpu, NULL);
  gpu_Sort(data_gpu,length);
  gettimeofday(&t_e_gpu, NULL);

// For small data sets you may print out errors here.
//  for(i=0;i<length;i++)
//    if(data_gpu[i]!=data_cpu[i]) printf("error @ %u\n",i);

  printf("\n time needed: \nCPU: %i us\n",(int)(t_e_cpu.tv_usec-t_s_cpu.tv_usec + (t_e_cpu.tv_sec-t_s_cpu.tv_sec)*1000000));
  printf("\nGPU: %i us\n\n",(int)(t_e_gpu.tv_usec-t_s_gpu.tv_usec + (t_e_gpu.tv_sec-t_s_gpu.tv_sec)*1000000));

  header[0]=dataWidth;
  header[1]=dataHeight;

  close_OpenCL();

  return;
}
コード例 #2
0
ファイル: main.c プロジェクト: tsccsj/SpatialRandomField
int main(int argc, char ** argv)
{
	if(argc < 6)
	{
		printf("Incorrect number of input arguments: \n\tRandomField <OutputFieldName> <ReferenceFileName> <Distance> <Exponent> <flat> <seed(optional)>\n");
		return 1;
	}

	double d = atof(argv[3]);
	double e = atof(argv[4]);
	double f = atof(argv[5]);

	bool withSeed = false;

	unsigned seed;

	if(argc > 6)
	{
		seed = atoi(argv[6]);
		withSeed = true;
	}

	double xMin, xMax, yMin, yMax, cellSize;
	int nCol, nRow, bound;

	
	getRasterInfo(argv[2], &nRow, &nCol, &xMin, &yMax, &cellSize);

	xMax = xMin + nCol * cellSize;
	yMin = yMax - nRow * cellSize;

	bound = d / cellSize;

	printf("Generating spatial random field of %d(col) X %d(row)\n", nCol, nRow);
	printf("Cell Size: %lf\n", cellSize);
	printf("xRange: %lf ~ %lf\n", xMin, xMax);
	printf("yRange: %lf ~ %lf\n", yMin, yMax);
	printf("D=%lf\tE=%lf\tF=%lf\n", d, e, f);

	double * noise;
	double * mask;
	double * normal;
	float * uniform;

	if(NULL == (noise = (double *) malloc ((nCol + 2 * bound) * (nRow + 2 * bound) * sizeof(double))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (mask = (double *) malloc ((1 + 2 * bound) * (1 + 2 * bound) * sizeof(double))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (normal = (double *) malloc (nCol * nRow * sizeof(double))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (uniform = (float *) malloc (nCol * nRow * sizeof(float))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(withSeed)
	{
		getNoise(noise, (nCol + 2 * bound) * (nRow + 2 * bound), seed);
	}
	else
	{
		getNoise(noise, (nCol + 2 * bound) * (nRow + 2 * bound));
	}

	getMask(mask, bound, cellSize, d, e, f);
	
	generateRandomField(noise, normal, mask, nCol, nRow, bound);

	free(noise);
	free(mask);

	normalToUniform(normal, uniform, nRow * nCol);

	free(normal);

	writeGeoTiffF(argv[1], uniform, nRow, nCol, xMin, yMax, cellSize);

	free(uniform);

	
	return 0;
}