Exemplo n.º 1
0
static GEDevDesc*
createRSceneDevice(double width, double height,
		   double ps,
		   RSceneDevice *qdev,
		   RSceneDeviceCreateFun init_fun)
{
    pGEDevDesc gdd;
    // pDevDesc dev;

    R_GE_checkVersionOrDie(R_GE_version);
    R_CheckDeviceAvailable();
    BEGIN_SUSPEND_INTERRUPTS {
	pDevDesc dev;
	/* Allocate and initialize the device driver data */
	if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc))))
	    return 0; /* or error() */
	/* set up device driver or free 'dev' and error() */
	if (!init_fun(dev, width, height, ps, qdev)) {
	    free(dev); // delete qdev; // ??
	    error("unable to start device");
	}
	gdd = GEcreateDevDesc(dev);
	gdd->displayList = R_NilValue;
	// gdd->savedSnapshot = R_NilValue;
	GEaddDevice2(gdd, "QTScene");
    } END_SUSPEND_INTERRUPTS;

    return(gdd);
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {
	if (argc != 5) {
//		fprintf(stderr, "Usage: %s N input_file iterations output_file\n", argv[0]);
//		return 1;
	}
	int rank, size;
	//config

	// initialize globals
	h=(xN-x0)/(N-1);
	d=(tM-t0)/(M-1);
	
	unsigned k = floor(tau/d);

	g_U=(double*)malloc(sizeof(double)*N*M);
	
	unsigned i,j;
	for(i=0; i<M; ++i)
	{
		g_U[index(0,i)]=border_fun(t0+i*d);
	}

	for(i=0; i<N; ++i)
	{
		g_U[index(i,0)]=init_fun(x0+i*h,t0);
	}
	double lambda = tau/d - d;

	double * ut_j = (double*)malloc(sizeof(double)*N);
	double * ut_j1 = (double*)malloc(sizeof(double)*N);

	for(j=0; j<M-1; ++j)
	{
		if(j>=k+1)
		{
			ut_j1[0] = border_fun( t(j+1)-tau);
			ut_j[0]  = border_fun(t(j)-tau);
			for( i = 1; i<N; ++i)
			{
				ut_j1[i] = lambda*g_U[index(i,j+1-k)] + (1-lambda)*g_U[index(i,j-k)];
				ut_j[i]  = lambda*g_U[index(i,j-k)]   + (1-lambda)*g_U[index(i,j-1-k)];
			}
		}
		else if(j == k)
			{
				ut_j1[0] = border_fun(t(j+1)-tau);
				ut_j[0]  = init_fun( x(0), t(j)-tau);
				for( i = 1; i<N; ++i)
				{
					ut_j1[i] = lambda*g_U[index(i,j+1-k)] + (1-lambda)*g_U[index(i,j-k)]; //%lambda*U(i,2) + (1-lambda)*U(i,1);
					ut_j[i]  = init_fun(x(i), t(j)-tau);
				}
			}
			else
			{
				for(i = 0; i<N; ++i)
				{
					ut_j1[i] = init_fun(x(i), t(j+1)-tau);
					ut_j[i] =  init_fun(x(i), t(j)-tau);
				}
			} 
		
		double f_1_j1 = heter_fun(x0, t(j+1), g_U[index(0,j+1)], ut_j1[0]);
		double dot_g_j1 = der_border_fun(t(j+1));
    
		double f_1_j = heter_fun( x0, t(j), g_U[index(0,j)], ut_j[0]);
		double dot_g_j = der_border_fun(t(j));
    
		double F_2_j = 0.5 * (heter_fun(x(0), t(j+1), g_U[index(0,j+1)], ut_j1[0]) 
			+ heter_fun(x(1), t(j), g_U[index(1,j)], ut_j[1]));
    
		g_U[index(1,j+1)] = d*h/(h + 2*a*s*d)* (g_U[index(1,j)]/d -
			a*s		/ (2*h)*(-4*g_U[index(0,j+1)] - 2*h/a*(f_1_j1 - dot_g_j1)) - 
			a*(1-s) / (2*h)*(-4*g_U[index(0,j)]	  - 2*h/a*(f_1_j - dot_g_j) + 4*g_U[index(1,j)]) +  F_2_j);

		for(i=2; i<N; i++)
		{
			double F_i_j = 0.5 * (heter_fun(x(i-1), t(j+1), g_U[index(i-1,j+1)], ut_j1[i-1]) + 
				heter_fun(x(i), t(j), g_U[index(i,j)], ut_j[i]));

			g_U[index(i,j+1)] = 2*d*h/(2*h+3*a*s*d)* (g_U[index(i,j)]/d -
				a*s/    (2*h)*(g_U[index(i-2,j+1)] - 4*g_U[index(i-1,j+1)]) -
				a*(1-s)/(2*h)*(g_U[index(i-2,j)] - 4*g_U[index(i-1,j)] + 3*g_U[index(i,j)]) + F_i_j);
		}
	}
	
	FILE *output;
	output = fopen("output.txt","w");
	
	for(i=0; i<N; i++)
	{
		for(j=0; j<M; j++)
		{
			fprintf(output,"%lf\t",g_U[index(i,j)]);
		}
		fprintf(output,"\n");
	}
	fclose(output);
	printf("OK\n");
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
    int num_benchs = 0;
    time_t rtime = 0, start_t;
    char *benchlet_prefixes[1024] = { "", NULL };

    if (argc < 2) {
        fprintf(stderr,
                "ctrbenchmark, Copyright (C)2011, "
                "Johannes Weiß <*****@*****.**>\n");
        fprintf(stderr,
                "This program comes with ABSOLUTELY NO WARRANTY; "
                "for details type `show w'.\n"
                "This is free software, and you are welcome to redistribute it"
                "\nunder certain conditions; type `show c' for details.\n\n");
        errx(1, "Usage: %s RUNNING-TIME [BENCHLETS...]", argv[0]);
    }

    rtime = atoi(argv[1]);
    if (argc > 2) {
        for (int i = 2; i < argc; i++, num_benchs++) {
            benchlet_prefixes[num_benchs] = argv[i];
            benchlet_prefixes[num_benchs+1] = NULL;
        }
    } else {
        num_benchs = 1;
    }
    printf("numbenchs: %d\n", num_benchs);

    assert(SECTION_SIZE(__benchlet_calls) ==
           SECTION_SIZE(__benchlet_init_calls));

    for (int i = 0; i < SECTION_SIZE(__benchlet_calls); i++) {
        const char **counters;
        const char *counter;
        benchlet_config_t cfg;
        benchlet_info_t info;
        benchlet_init_call_t init_fun = __start___benchlet_init_calls[i];
        benchlet_call_t run_fun = __start___benchlet_calls[i];

        init_fun(&info);
        printf("- benchlet '%s':\n\t* desc: '%s'\n\t* counters: ",
               info.name, info.description);
        counters = info.penetrated_counters;
        while(NULL != (counter = *counters++)) {
            printf("%s, ", counter);
        }
        printf("\b\b  \n");

        cfg.desired_running_time = (int)rtime;
        for (int j = 0; j < num_benchs; j++) {
            if (info.name == strstr(info.name, benchlet_prefixes[j])) {
                printf("- Running '%s' for %ds in 1s...\n",
                       info.name, (int)cfg.desired_running_time);
                sleep(1);
                start_t = time(NULL);
                run_fun(&cfg);
                printf("- OK (%ds)\n", (int)(time(NULL)-start_t));
            } else {
                printf("- not running '%s'\n", info.name);
            }
        }
    }
    return 0;
}