Exemple #1
0
void display(void)
{
	static std::vector<float> tex(Mapsize*Mapsize*3);

	const float texture_mul = 2.0;
	const std::unique_ptr<std::unique_ptr<double[]>[] >& rd_v = rd.get_v_ref();
	for(int i = 0; i < Mapsize; i++){
		for(int j = 0; j < Mapsize; j++){
			const float fcolor = static_cast<float>(std::min(texture_mul*(rd_v[i][j]), 1.0));
			tex[(i*Mapsize+j)*3] = 0.0;
			tex[(i*Mapsize+j)*3+1] = fcolor;
			tex[(i*Mapsize+j)*3+2] = fcolor;
		}
	}
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Mapsize, Mapsize, 0, GL_RGB, GL_FLOAT, &(tex[0]));

	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();


	glColor3f(1.0,1.0,1.0);
	glBegin(GL_POLYGON);
	glTexCoord2f(0,0);glVertex2f(-1.0f, 1.0f);
	glTexCoord2f(1,0);glVertex2f(-1.0f, -1.0f);
	glTexCoord2f(1,1);glVertex2f(1.0f, -1.0f);
	glTexCoord2f(0,1);glVertex2f(1.0f, 1.0f);
	glEnd();

	display_params();

	glutSwapBuffers();
}
Exemple #2
0
int			main(int ac, char **av)
{
	t_fract	e;

	if (ac == 2 && (e.fract = check_fract(av[1])))
	{
		var_init(&e);
		e.mlx = mlx_init();
		e.win = mlx_new_window(e.mlx, WIDTH, HEIGHT, "fractol");
		mlx_expose_hook(e.win, draw, &e);
		mlx_mouse_hook(e.win, zoom, &e);
		mlx_key_hook(e.win, key, &e);
		mlx_hook(e.win, 6, (1L << 6), mouse, &e);
		mlx_loop(e.mlx);
	}
	else
		display_params();
	return (0);
}
// -----------------------------------------------------------------------------
int QALSH::read_para_file(			// read "para" file
	char* fname)						// file name of "para" file
{
	FILE* fp = NULL;
	fp = fopen(fname, "r");
	if (!fp) {						// ensure we can open the file
		printf("QALSH::read_para_file could not open %s.\n", fname);
		return 1;
	}

	fscanf(fp, "n = %d\n", &n_pts_);// read <n_pts_>
	fscanf(fp, "d = %d\n", &dim_);	// read <dim_>
	fscanf(fp, "B = %d\n", &B_);	// read <B_>
									// read <appr_ratio_>
	fscanf(fp, "ratio = %f\n", &appr_ratio_);
	fscanf(fp, "w = %f\n", &w_);	// read <w_>
	fscanf(fp, "p1 = %f\n", &p1_);	// read <p1_>
	fscanf(fp, "p2 = %f\n", &p2_);	// read <p2_>
									// read <alpha_>
	fscanf(fp, "alpha = %f\n", &alpha_);
									// read <beta_>
	fscanf(fp, "beta = %f\n", &beta_);
									// read <delta_>
	fscanf(fp, "delta = %f\n", &delta_);

	fscanf(fp, "m = %d\n", &m_);	// read <m_>
	fscanf(fp, "l = %d\n", &l_);	// read <l_>

	a_array_ = new float[m_ * dim_];// read <a_array_>
	g_memory += SIZEFLOAT * m_ * dim_;
	int count = 0;
	for (int i = 0; i < m_; i++) {
		for (int j = 0; j < dim_; j++) {
			fscanf(fp, "%f", &a_array_[count++]);
		}
		fscanf(fp, "\n");
	}
	if (fp) fclose(fp);				// close para file
	
	display_params();				// display params
	return 0;						// success to return
}
Exemple #4
0
static int
checkparams(size_t maxmem, double maxmemfrac, double maxtime,
            int logN, uint32_t r, uint32_t p, int verbose)
{
    size_t memlimit;
    double opps;
    double opslimit;
    uint64_t N;
    int rc;

    /* Figure out the maximum amount of memory we can use. */
    if (memtouse(maxmem, maxmemfrac, &memlimit))
        return (1);

    /* Figure out how fast the CPU is. */
    if ((rc = scryptenc_cpuperf(&opps)) != 0)
        return (rc);
    opslimit = opps * maxtime;

    /* Sanity-check values. */
    if ((logN < 1) || (logN > 63))
        return (7);
    if ((uint64_t)(r) * (uint64_t)(p) >= 0x40000000)
        return (7);

    /* Check limits. */
    N = (uint64_t)(1) << logN;
    if ((memlimit / N) / r < 128)
        return (9);
    if ((opslimit / N) / (r * p) < 4)
        return (10);

    if (verbose)
        display_params(logN, r, p, memlimit, opps, maxtime);

    /* Success! */
    return (0);
}
// -----------------------------------------------------------------------------
void QALSH::init(					// init params of qalsh
	int   n,							// number of points
	int   d,							// dimension of space
	int   B,							// page size
	float ratio, int N,						// approximation ratio
	char* output_folder)				// folder of info of qalsh
{
	n_pts_ = n;						// init <n_pts_>
	dim_   = d;						// init <dim_>
	B_     = B;						// init <B_>
	appr_ratio_ = ratio;			// init <appr_ratio_>
	N_ = N;

									// init <index_path_>
	strcpy(index_path_, output_folder);
	strcat(index_path_, "L2_indices/");

									// init <w_> <delta_> <beta_> <p1_>
	calc_params();					// <p2_> <alpha_> <m_> and <l_>

	gen_hash_func();				// init <a_array_>
	display_params();				// display params
	trees_ = NULL;					// init <trees_>
}
Exemple #6
0
static int
pickparams(size_t maxmem, double maxmemfrac, double maxtime,
           int * logN, uint32_t * r, uint32_t * p, int verbose)
{
    size_t memlimit;
    double opps;
    double opslimit;
    double maxN, maxrp;
    int rc;

    /* Figure out how much memory to use. */
    if (memtouse(maxmem, maxmemfrac, &memlimit))
        return (1);

    /* Figure out how fast the CPU is. */
    if ((rc = scryptenc_cpuperf(&opps)) != 0)
        return (rc);
    opslimit = opps * maxtime;

    /* Allow a minimum of 2^15 salsa20/8 cores. */
    if (opslimit < 32768)
        opslimit = 32768;

    /* Fix r = 8 for now. */
    *r = 8;

    /*
     * The memory limit requires that 128Nr <= memlimit, while the CPU
     * limit requires that 4Nrp <= opslimit.  If opslimit < memlimit/32,
     * opslimit imposes the stronger limit on N.
     */
#ifdef DEBUG
    fprintf(stderr, "Requiring 128Nr <= %zu, 4Nrp <= %f\n",
            memlimit, opslimit);
#endif
    if (opslimit < (double)memlimit / 32) {
        /* Set p = 1 and choose N based on the CPU limit. */
        *p = 1;
        maxN = opslimit / (*r * 4);
        for (*logN = 1; *logN < 63; *logN += 1) {
            if ((uint64_t)(1) << *logN > maxN / 2)
                break;
        }
    } else {
        /* Set N based on the memory limit. */
        maxN = memlimit / (*r * 128);
        for (*logN = 1; *logN < 63; *logN += 1) {
            if ((uint64_t)(1) << *logN > maxN / 2)
                break;
        }

        /* Choose p based on the CPU limit. */
        maxrp = (opslimit / 4) / ((uint64_t)(1) << *logN);
        if (maxrp > 0x3fffffff)
            maxrp = 0x3fffffff;
        *p = (uint32_t)(maxrp) / *r;
    }

    if (verbose)
        display_params(*logN, *r, *p, memlimit, opps, maxtime);

    /* Success! */
    return (0);
}
Exemple #7
0
int main(int argc , char *argv[])
{

    int c;
    int argvidx = 0 ;
    int ret = 0 ;
    int opt_events = 0 ;
    int opt_events_nonblock = 0 ;
    int opt_disp_param = 0 ;
    char *opt_disp_param_arg = NULL;
    char *opt_event_arg = NULL;
    int opt_wps_event = 0;
    acfg_dl_init();

    appname = basename(argv[0]);


    while( (c = getopt(argc , argv , option_args)) != -1 )
    {
        switch (c)
        {
            case 'e':
                opt_events = 1 ;
                opt_event_arg = optarg ;
                break;

            case 'n':
                opt_events_nonblock = 1 ;
                break;

            case 'p':
                opt_disp_param = 1 ;
                opt_disp_param_arg = optarg ;
                break;
            case 'w':
                opt_wps_event = 1 ;
                break;

            case '?':
                /* getopt returns error */
                usage();
                exit(0);
                break;

            default:
                usage();
                exit(0);
                break;
        } //end switch
    }//end while

    argvidx = optind ;

    if(opt_disp_param)
    {
        ret = display_params(opt_disp_param_arg) ;
    }
    else if(opt_events)
    {
        ret = recv_events(opt_event_arg,opt_events_nonblock);
    }
    else if (opt_wps_event)
    {
        recv_wps_events();
    }
    else if (argv[argvidx] != NULL)
        ret = doapitest( &argv[argvidx] );

    if(ret != 0)
    {
        printf("\n<<<<<<<<<< Dumping LOG >>>>>>>>>>>>>\n");
        printf("%s", acfg_get_errstr());
        printf("\n<<<<<<<<<<<<<< End >>>>>>>>>>>>>>>>>\n");
    }

    return ret ;
}