Пример #1
0
void fixed_jump(tinymt32_t * tiny, const char * poly_str,
		uint64_t lower_step,
		uint64_t upper_step,
		uint32_t seed)
{
    tinymt32_t new_tiny_z;
    tinymt32_t * new_tiny = &new_tiny_z;
    char jump_str[100];
    polynomial charcteristic;
    polynomial jump_poly;
    polynomial tee;

    strtop(&charcteristic, poly_str);
    tee.ar[0] = 2;
    tee.ar[1] = 0;
    polynomial_power_mod(&jump_poly,
			 &tee,
			 lower_step,
			 upper_step,
			 &charcteristic);
    memset(jump_str, 0, sizeof(jump_str));
    ptostr(jump_str, &jump_poly);
    printf("lower_step: %"PRIu64" upper_step:%"PRIu64"\n",
	   lower_step, upper_step);
    printf("jump_poly:%s\n", jump_str);
    printf("check data:\n");
    printf("seed = %u\n", seed);
    tinymt32_init(tiny, seed);
    *new_tiny = *tiny;
    printf("before:\n");
    for (int i = 0; i < 3; i++) {
	for (int j = 0; j < 5; j++) {
	    printf("%10"PRIu32" ", tinymt32_generate_uint32(tiny));
	}
	printf("\n");
    }
    /* period jump */
    tinymt32_jump(new_tiny,
		  lower_step,
		  upper_step,
		  poly_str);
    printf("after:\n");
    for (int i = 0; i < 3; i++) {
	for (int j = 0; j < 5; j++) {
	    printf("%10"PRIu32" ", tinymt32_generate_uint32(new_tiny));
	}
	printf("\n");
    }
}
Пример #2
0
int main(int argc, char * argv[]) {
    if (argc < 4) {
	printf("%s mat1 mat2 tmat [seed]\n", argv[0]);
	return -1;
    }
    tinymt32_t tinymt;
    tinymt.mat1 = strtoul(argv[1], NULL, 16);
    tinymt.mat2 = strtoul(argv[2], NULL, 16);
    tinymt.tmat = strtoul(argv[3], NULL, 16);
    int seed = 1;
    uint32_t seed_array[4];

    if (argc >= 5) {
	seed = strtol(argv[4], NULL, 0);
    }
    printf("tinymt32 0x%08"PRIx32, tinymt.mat1);
    printf(" 0x%08"PRIx32, tinymt.mat2);
    printf(" 0x%08"PRIx32, tinymt.tmat);
    for (int n = 0; n < 4; n++) {
        seed_array[n] = seed + n;
    }
    printf(" seed array = [%d, %d, %d, %d]\n", 
        seed_array[0],
        seed_array[1],
        seed_array[2],
        seed_array[3]);
    tinymt32_init_by_array(&tinymt, seed_array, 4);
    state_dump(&tinymt);
    printf("mat1 %u ", tinymt.mat1);
    printf("mat2 %u ", tinymt.mat2);
    printf("tmat %u\n", tinymt.tmat);
    for (int i = 0; i < 10; i++) {
	    printf("%"PRIu32"\n", tinymt32_generate_uint32(&tinymt));
	    state_dump(&tinymt);
    }
}
Пример #3
0
//Between 0 and 999 inclusive
int get_random_int()
{
    return ((int)((unsigned int) tinymt32_generate_uint32(&state) % 1000));
}
Пример #4
0
int rnd_uint(lua_State *L)
{
    unsigned int r = tinymt32_generate_uint32(&random_handler);
    lua_pushunsigned(L, r);
    return 1;
}
int
main ()
{
unsigned int N_KEYS;
unsigned int N_BATCH;

printf("\n number of keys:");
scanf("%u",&N_KEYS);

printf("\n batch size:");
scanf("%u",&N_BATCH);






  tinymt32_t tinymt32;
//initialize random generator
  tinymt32_init (&tinymt32, 0);


  int iter;
  int sec_iter;
  int stop;
  int counter;


//initialize database
  char *errptr = NULL;

  leveldb_options_t *options = leveldb_options_create ();

/* initializeOptions */
  leveldb_options_set_create_if_missing (options, 1);
  leveldb_options_set_write_buffer_size(options,120000000 );
  leveldb_options_set_max_open_files(options,800000);
/*open Database */

  leveldb_t *db_helper =
    leveldb_open (options, "/mnt/database/database_helper", &errptr);
  leveldb_t *db = leveldb_open (options, "/mnt/database/database", &errptr);



  leveldb_readoptions_t *readoptions = leveldb_readoptions_create ();

  leveldb_writeoptions_t *writeoptions = leveldb_writeoptions_create ();

leveldb_writebatch_t* batch=leveldb_writebatch_create();


  int64_t diff = zclock_time ();

//write into database_helper
  iter=0;
  while( iter < N_KEYS)
    {
     sec_iter=0;
     while((iter<N_KEYS) && (sec_iter<N_BATCH)){
      unsigned int key = tinymt32_generate_uint32 (&tinymt32);
      unsigned int val = tinymt32_generate_uint32 (&tinymt32);
      leveldb_writebatch_put (batch,
		   (const char *) &key, sizeof (int),
		   (const char *) &val, sizeof (int));
    sec_iter++;
    iter++;
    }
      leveldb_write(
    db_helper,
    writeoptions,
    batch,
    &errptr);

      if(errptr!=NULL){
      printf("\n%s",errptr);
      }
      assert (errptr == NULL);
      leveldb_writebatch_clear(batch);
    }
  
      leveldb_writebatch_destroy(batch);

  diff = zclock_time () - diff;

  printf ("\nrandom write:  %d", diff);


  diff = zclock_time ();
//write sequentially into db

  leveldb_iterator_t *liter = leveldb_create_iterator (db_helper,
						       readoptions);

  leveldb_iter_seek_to_first (liter);

  while (leveldb_iter_valid (liter))
    {
      size_t length;
      char key[4];
      memcpy (key, leveldb_iter_key (liter, &length), 4);
      char val[4];
      memcpy (val, leveldb_iter_value (liter, &length), 4);

      leveldb_iter_get_error (liter, &errptr);
      assert (errptr == NULL);
      leveldb_put (db,
		   writeoptions,
		   (const char *) &key, sizeof (int),
		   (const char *) &val, sizeof (int), &errptr);
      assert (errptr == NULL);
      leveldb_iter_next (liter);
    }


  diff = zclock_time () - diff;




  leveldb_close (db);
  leveldb_close (db_helper);





}
Пример #6
0
int
main ()
{

  int64_t diff;
  unsigned int N_KEYS;
  unsigned int TN_KEYS;
  int bool_bench;
  int N_THREADS;

  printf ("\n number of keys to retrieve:");
  scanf ("%u", &N_KEYS);

  printf ("\n total number of keys:");
  scanf ("%u", &TN_KEYS);

  printf("\n benchmark randomly inserted database or sequentially inserted database:(1->rand or 0->seq)");
  scanf ("%u", &bool_bench);

  printf ("\n number of threads:");
  scanf ("%u", &N_THREADS);
//zeromq context
  zctx_t *ctx = zctx_new ();

//initialize worker args
  worker_args_t worker_args;


//initialize rb_tree;
  struct dbkey_rb_t dbkey_rb;
  RB_INIT (&dbkey_rb);






//initialize keys

  unsigned int factor = (unsigned int) N_KEYS / TN_KEYS;
  tinymt32_t tinymt32;
/*initializing random generator with the same seed  */
  tinymt32_init (&tinymt32, 0);

  unsigned int *keys =
    (unsigned int *) malloc (sizeof (unsigned int) * N_KEYS);
  unsigned int sec_iter;
  unsigned int iter;

  iter = 0;
  while (iter < N_KEYS)
    {

      keys[iter] = tinymt32_generate_uint32 (&tinymt32);
      tinymt32_generate_uint32 (&tinymt32);
      for (sec_iter = 1; sec_iter < factor; sec_iter++)
	{
	  tinymt32_generate_uint32 (&tinymt32);
	  tinymt32_generate_uint32 (&tinymt32);
	}
      iter++;
    }





//initialize database
  char *errptr = NULL;

  leveldb_options_t *options = leveldb_options_create ();
  worker_args.options = &options;

/* initialize Options */
  leveldb_options_set_create_if_missing (options, 1);
  leveldb_options_set_write_buffer_size (options, 62914560);
  leveldb_options_set_max_open_files (options, 800000);
//bloom filter
  leveldb_filterpolicy_t *bloom = leveldb_filterpolicy_create_bloom (10);
  leveldb_options_set_filter_policy (options, bloom);




  leveldb_readoptions_t *readoptions = leveldb_readoptions_create ();
  worker_args.readoptions = readoptions;




  leveldb_writeoptions_t *writeoptions = leveldb_writeoptions_create ();
  worker_args.writeoptions = writeoptions;


  int rc;
  void *push = zsocket_new (ctx, ZMQ_PUSH);

  int water = 2000000000;
  zsocket_set_hwm (push, water);

  rc = zsocket_bind (push, "inproc://bind_point");

  //connect 
  void *pub = zsocket_new (ctx, ZMQ_PUB);
  rc = zsocket_bind (pub, "inproc://pub_point");

//connect 
  void *router = zsocket_new (ctx, ZMQ_ROUTER);
  rc = zsocket_bind (router, "inproc://response_point");

//sleep a while
  zclock_sleep (1000);

//this assumes some synchronization at the start and end of each new bench
  leveldb_t *db_pointer;
  worker_args.db = &db_pointer;

//initialize the threads
  void *pipe[6];

  unsigned char i;
  for (i = 0; i < N_THREADS; i++)
    {
      pipe[i] = zthread_fork (ctx, &worker_fn, (void *) &(worker_args));
    }

//sleep a while
  zclock_sleep (1000);


  if(bool_bench==0){

  db_pointer = leveldb_open (options, "/mnt/database/database", &errptr);


  benchmark_notree (push, pub, router, N_KEYS, keys,N_THREADS);



  printf ("\n benchmark with tree 1st pass");

  leveldb_close (db_pointer);

  db_pointer = leveldb_open (options, "/mnt/database/database", &errptr);

  benchmark_tree (push, pub, router, N_KEYS, keys, dbkey_rb ,N_THREADS);

  leveldb_close (db_pointer);

  }else{if(bool_bench==1){
  db_pointer =
    leveldb_open (options, "/mnt/database/database_helper", &errptr);


  printf
    ("\n starting random read without a rb_btree on random inserted database");


  benchmark_notree (push, pub, router, N_KEYS, keys,N_THREADS);

  leveldb_close (db_pointer);

  db_pointer =
    leveldb_open (options, "/mnt/database/database_helper", &errptr);

  printf ("\n with a tree");

  benchmark_tree (push, pub, router, N_KEYS, keys, dbkey_rb,N_THREADS);

  leveldb_close (db_pointer);
}
}
}
Пример #7
0
unsigned long mt_random(void)
{
	return tinymt32_generate_uint32(&trandom);
}
Пример #8
0
uint32_t random_uint32(void)
{
    return tinymt32_generate_uint32(&_random);
}
Пример #9
0
//---------------------------------------------------------------------------
u32 Rnd32(void)
{
	return tinymt32_generate_uint32(&MathTinyMt);
}