Beispiel #1
0
SMC::SMC ()
{
    if (!initialized) {

	init_runtime();

	init_stencil();

	init_chemistry();

	init_variables();

	initialized = true;
    }

    build_multifabs();

    init_from_scratch();

    wt_fb1 = wt_fb2 = wt_chem1 = wt_chem2 = wt_hypdiff = 0.0;
}
Beispiel #2
0
int main(int argc, char** argv)
{
	int i,j,k;
	struct timeval t0,t1;
	double time;
	int validate = 0;

	int ni = NI, nj = NJ;
	int niter = STEPS;
	int di = EDIM, dj = EDIM;

	// stencil weights
	float w0 = 0.166666666f;
	float w1 = 0.333333333f;
	float w2 = 0.166666666f;
	float w3 = 0.166666666f;
	float w4 = 0.166666666f;

	i = 1;
	while (i < argc) {
		if (!strcmp(argv[i],"-n")) { ni = atoi(argv[++i]); nj = atoi(argv[++i]); }
		else if (!strcmp(argv[i],"-i")) niter = atoi(argv[++i]);
		else if (!strcmp(argv[i],"-d")) { di = atoi(argv[++i]), dj = atoi(argv[++i]); }
		else if (!strcmp(argv[i],"--validate")) validate = 1;
		else if (!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h")) goto help;
		else {
			fprintf(stderr,"unrecognized option: %s\n",argv[i]);
			help:
			ERROR("use -n [internal X size] [internal Y size] -i [iteration step count] -d [number of Epiphany cores/threads] --validate\n");
		}
		++i;
	}
	if(ni%di) ERROR("ni = %d is not divisible by di = %d\n", ni, di);
	if(nj%dj) ERROR("nj = %d is not divisible by dj = %d\n", nj, dj);

	printf("Using N = {%d x %d}, # iterations = %d, # cores = {%d x %d} = %d\n", ni, nj, niter, di, dj, di*dj);

	// From here on, we're using padded ni and nj values
	ni += 2;
	nj += 2;

	// allocate memory on host
	float* A = (float*)malloc(ni*nj*sizeof(float));
	float* B = (float*)malloc(ni*nj*sizeof(float));

	// initialize
	init_stencil(A, B, ni, nj);

	gettimeofday(&t0,0);
	update_stencil_epiphany(A, B, ni, nj, di, dj, niter, w0, w1, w2, w3, w4);
	gettimeofday(&t1,0);

	time = t1.tv_sec - t0.tv_sec + 1e-6*(t1.tv_usec - t0.tv_usec);
	float gflops = __gflops(time, ni-2, nj-2, niter);
	printf("Epiphany Performance.... : %f GFLOPS (includes overhead)\n",gflops);
	printf("Execution Time.......... : %f seconds\n",time);

	if (validate) {

		float* A_validate = (float*)malloc(ni*nj*sizeof(float));
		float* B_validate = (float*)malloc(ni*nj*sizeof(float));
		init_stencil(A_validate, B_validate, ni, nj);

		printf("Validating on CPU host....\n");
		gettimeofday(&t0,0);
		update_stencil_cpu(A_validate, B_validate, ni, nj, niter, w0, w1, w2, w3, w4);
		gettimeofday(&t1,0);

		int errors = validate_stencil(B, B_validate, ni, nj);

		print_stencil(B_validate, ni, nj);

		time = t1.tv_sec - t0.tv_sec + 1e-6*(t1.tv_usec - t0.tv_usec);
		printf("CPU Execution time... : %f seconds\n",time);
		printf("Errors............... : %d (%0.1f%%)\n", errors, 100.0f*errors/((ni-2)*(nj-2)));
	}

	return 0;

}