예제 #1
0
파일: randoom.c 프로젝트: bleepster/randoom
long int randoom(void)
{
    long int rval = 0;
    struct timeval tv;

#if defined (__linux__)
    struct drand48_data buff;
    long int res;
#endif

#if defined (__linux__)
    gettimeofday(&tv, NULL);
    srand48_r(tv.tv_usec, &buff);
    lrand48_r(&buff, &res);
    rval = (res % (tv.tv_usec + 1)) / 100;
#elif (defined (__FreeBSD__) || defined (__OpenBSD__))
    gettimeofday(&tv, NULL);
    rval = (arc4random() % (tv.tv_usec + 1)) / 100;
#else
    gettimeofday(&tv, NULL);
    srand((tv.tv_sec + tv.tv_usec) >> (sizeof(long) / 2));
    rval = (random() % (tv.tv_usec + 1)) / 100;
#endif

    return (rval);
}
예제 #2
0
파일: usemem.c 프로젝트: aaronlu/usemem
static inline long os_random_long(unsigned long max, struct drand48_data *rs)
{
        long val;

        lrand48_r(rs, &val);
	return (unsigned long)((double)max * val / (RAND_MAX + 1.0));
}
예제 #3
0
파일: common.c 프로젝트: gnb/Droplet-tests
u64
dpltest_get_oid(int oflag,
                struct drand48_data *pdrbuffer)
{
  static u64 static_oid = 0;
  static pthread_mutex_t oid_lock = PTHREAD_MUTEX_INITIALIZER;
  u64 oid;

  if (1 == oflag)
    {
      long int tmp;
      pthread_mutex_lock(&oid_lock);
      lrand48_r(pdrbuffer, &tmp);
      oid = tmp;
      pthread_mutex_unlock(&oid_lock);
      return oid;
    }
  else
    {
      pthread_mutex_lock(&oid_lock);
      oid = static_oid++;
      pthread_mutex_unlock(&oid_lock);

      return oid;
    }
}
예제 #4
0
파일: utils.c 프로젝트: akshatha-g/perfTest
/*
 * Randomize an array.
 */
void randomize_more(int *index, int size,struct drand48_data *randBuffer ) {
    int i;
    long int random = 0;
    for( i = 0 ; i < size; i++) {
        lrand48_r(randBuffer, &random);
        index[i] = random % size + 1;
    }
    return;
}
예제 #5
0
파일: util.c 프로젝트: muttu2244/MyPython
char* gen_zid(struct drand48_data * rdata, long long int zid_start, long long int zid_end, long int *zid)
{
	long int d;
	lrand48_r(rdata, &d);
	d = d % (zid_end - zid_start);
	if(zid) *zid = d;
	char * zauth = get_zauth((unsigned long int) (d+zid_start));
	return (zauth);
}
예제 #6
0
unsigned long int get_random_number_perf(int index)
{
    unsigned long int val_8 ;

    lrand48_r(&th_array[index].buffer, &th_array[index].random_pattern);
    val_8 = (th_array[index].random_pattern <<16)| th_array[index].random_pattern ;

    return val_8 ;
}
예제 #7
0
int getRandTo_r(int Ceiling, reent *seedp) {
  long int r = 1234;
#ifdef __CYGWIN__
  r = rand_r(seedp);
#else
  lrand48_r(seedp, &r);
#endif

  return (int) (r % Ceiling);
}
예제 #8
0
void testValues() {
    f = 2;
    
    struct drand48_data data;
    long d;
    lrand48_r(&data, &d);
    //@ assert 0 <= d < 2147483648;

    //@ assert f == 2;
    //@ assert vacuous: \false;
}
예제 #9
0
파일: io_uring.c 프로젝트: arh/fio
static void init_io(struct submitter *s, unsigned index)
{
	struct io_uring_sqe *sqe = &s->sqes[index];
	unsigned long offset;
	struct file *f;
	long r;

	if (do_nop) {
		sqe->opcode = IORING_OP_NOP;
		return;
	}

	if (s->nr_files == 1) {
		f = &s->files[0];
	} else {
		f = &s->files[s->cur_file];
		if (f->pending_ios >= file_depth(s)) {
			s->cur_file++;
			if (s->cur_file == s->nr_files)
				s->cur_file = 0;
			f = &s->files[s->cur_file];
		}
	}
	f->pending_ios++;

	lrand48_r(&s->rand, &r);
	offset = (r % (f->max_blocks - 1)) * BS;

	if (register_files) {
		sqe->flags = IOSQE_FIXED_FILE;
		sqe->fd = f->fixed_fd;
	} else {
		sqe->flags = 0;
		sqe->fd = f->real_fd;
	}
	if (fixedbufs) {
		sqe->opcode = IORING_OP_READ_FIXED;
		sqe->addr = (unsigned long) s->iovecs[index].iov_base;
		sqe->len = BS;
		sqe->buf_index = index;
	} else {
		sqe->opcode = IORING_OP_READV;
		sqe->addr = (unsigned long) &s->iovecs[index];
		sqe->len = 1;
		sqe->buf_index = 0;
	}
	sqe->ioprio = 0;
	sqe->off = offset;
	sqe->user_data = (unsigned long) f;
}
예제 #10
0
파일: utils.c 프로젝트: akshatha-g/perfTest
/*
 * Name             open_read_close
 * Description      This metric is only applicable for small files.
 *                  -   Measures the time taken to open a small file, read all of the file and
 *                      close the file.
 *                  -   Files to be opened/read/closed are chosen in random ( lessen prefetching
 *                      effects.)
 *                  -   Overhead : one if-loop + overhead of measuring time.
 * Input            struct share_it
 * Input            filepath - to pick files from.
 * Output           Boolean to indicate if all reads succeed.
 */
bool open_read_close(struct share_it* my_state, char *filepath) {
    timestamp start     = 0;
    timestamp end       = 0;
    int bytes           = 0;

    struct drand48_data     randBuffer;
    srand48_r(time(NULL), &randBuffer);

    int i           = 0;
    long int random = 0;
    int idx         = 0;

    for (i = 0; i < my_state->count; i++) {
        lrand48_r(&randBuffer, &random);
        idx = random % MAX_FILES + 1;
        char num[5];
        sprintf(num, "%d", idx);

        char my_file[100] = {'\0'};
        strcat(my_file, filepath);
        strcat(my_file, "/file");
        strcat(my_file, num);

        RDTSCP(start);
        int fd = open(my_file, FLAGS);
        if (fd == -1) {
            int err = errno;
            printf("Could not open file descriptor for file %s. Error = %d\n",
                   my_file, err);
            return false;
        }
        bytes = read(fd, my_state->buf, my_state->block_size);
        close(fd);
        RDTSCP(end);


        if (bytes <= 0 || bytes != my_state->block_size)
            return false;
        dummy_call(my_state->buf);
        *(my_state->total_bytes) += bytes;
        my_state->duration  += (end - start);
    }

    return true;

}
예제 #11
0
int
mb_rand_buf(struct drand48_data* rand, char *buf, int buf_size)
{
	long int num;
	long int *ptr;
	int i;

	lrand48_r(rand, &num);

	ptr = (long int *) buf;

	for (i = 0; i < buf_size / sizeof(num); i++) {
		*(ptr + i) = num;
	}

	return 0;
}
예제 #12
0
파일: apib_url.c 프로젝트: apigee/apib
const URLInfo* url_GetNext(RandState rand)
{
  long randVal;

  if (urlCount == 0) {
    return NULL;
  }
  if (urlCount == 1) {
    return &(urls[0]);
  }

#if HAVE_LRAND48_R
  lrand48_r(rand, &randVal);
#elif HAVE_RAND_R
  randVal = rand_r(rand);
#else
  randVal = rand();
#endif

  return &(urls[randVal % urlCount]);
}
예제 #13
0
u_long _create_xid (void)
{
  long res;

  __UCLIBC_MUTEX_LOCK(mylock);

  if (!is_initialized)
    {
      struct timeval now;

      gettimeofday (&now, (struct timezone *) 0);
      srand48_r (now.tv_sec ^ now.tv_usec, &__rpc_lrand48_data);
      is_initialized = 1;
    }

  lrand48_r (&__rpc_lrand48_data, &res);

  __UCLIBC_MUTEX_UNLOCK(mylock);

  return res;
}
예제 #14
0
파일: util.c 프로젝트: jgarzik/nfs4d
void nrand32(void *mem, unsigned int dwords)
{
    uint32_t *v = mem;
    int i;

    for (i = 0; i < dwords; i++) {
#ifdef HAVE_SRAND48_R
        long l[4] = { 0, };

        lrand48_r(&rng, l);

        v[i] = l[0];
#else
        long l;

        l = lrand48();

        v[i] = l;
#endif

    }
}
예제 #15
0
unsigned long
_create_xid (void)
{
  long int res;

  __libc_lock_lock (createxid_lock);

  if (!is_initialized)
    {
      struct timeval now;

      __gettimeofday (&now, (struct timezone *) 0);
      __srand48_r (now.tv_sec ^ now.tv_usec, &__rpc_lrand48_data);
      is_initialized = 1;
    }

  lrand48_r (&__rpc_lrand48_data, &res);

  __libc_lock_unlock (createxid_lock);

  return res;
}
예제 #16
0
/*
 * Randomly generates a graph of the specified size,
 * branching factor, and maximum edge weight.
 *
 * @param size  the number of vertices in the graph; positive.
 *
 * @param b  the branching factor; probability that any given
 * source destination pair will have an edge.
 *
 * @param max_weight  the upper bound edge weight; each edge
 * has a pseudorandomly chosen non-negative weight at most this.
 * Must be a power of 2 less than RAND_MAX for a fair weight
 * distribution.
 */
void pgenerate_graph(unsigned int size,
                    float b,
                    unsigned int max_weight,
                    int *edges)
{
    int bint = b * (double) BIG_POWER_OF_TWO;

#pragma omp parallel
    {
        struct drand48_data buffer;
        srand48_r(current_seed + omp_get_thread_num(), &buffer);

#pragma omp for
        for (int i = 0; i < (size*size); i += 1) {
            long rng;
            lrand48_r(&buffer, &rng);
            const bool should_add_edge = ((int) rng % BIG_POWER_OF_TWO) < bint;
            edges[i] = (should_add_edge) ? (int) rng % (max_weight+1) : -1;
        }
    }
    srand(current_seed);
    current_seed = rand();
}
예제 #17
0
파일: f3write.c 프로젝트: benjaminma/f3
static uint64_t fill_buffer(void *buf, size_t size, uint64_t offset)
{
	uint8_t *p, *ptr_next_sector, *ptr_end;
	struct drand48_data state;

	assert(size > 0);
	assert(size % SECTOR_SIZE == 0);

	p = buf;
	ptr_end = p + size;
	while (p < ptr_end) {
		memmove(p, &offset, sizeof(offset));
		srand48_r(offset, &state);
		ptr_next_sector = p + SECTOR_SIZE;
		p += sizeof(offset);
		for (; p < ptr_next_sector; p += sizeof(long int))
			lrand48_r(&state, (long int *)p);
		assert(p == ptr_next_sector);
		offset += SECTOR_SIZE;
	}

	return offset;
}
예제 #18
0
파일: rand.c 프로젝트: Mellanox/arc_ltp
/* pre: state->size must be set and state->mt must be allocated! */
static void sgenrand(randdata_t *state)
{
	int got = 0;
	got = read(randfd, state->mt, state->size);
	if (got != state->size) {
		int i ;
		/* fall back on lrand48 */
		/* printf("fallback_rand\n"); */

		for (i = got ; i < state->size ; i += 4) {
			long int  rand = 0;
#ifdef HAVE_LRAND48
			lrand48_r(&(state->data), &rand);
#else
			rand = random();
#endif
			assert(rand != 0);
			state->mt[i]   = (rand >> 24) & (512 - 1);
			state->mt[i+1] = (rand >> 16) & (512 - 1);
			state->mt[i+2] = (rand >>  8) & (512 - 1);
			state->mt[i+3] = (rand) & (512 - 1);
		}

	}
예제 #19
0
void ycsb_query::gen_requests(uint64_t thd_id, workload * h_wl) {
#if CC_ALG == HSTORE
	assert(g_virtual_part_cnt == g_part_cnt);
#endif
	int access_cnt = 0;
	set<uint64_t> all_keys;
	part_num = 0;
	double r = 0;
	int64_t rint64 = 0;
	drand48_r(&_query_thd->buffer, &r);
	lrand48_r(&_query_thd->buffer, &rint64);
	if (r < g_perc_multi_part) {
		for (UInt32 i = 0; i < g_part_per_txn; i++) {
			if (i == 0 && FIRST_PART_LOCAL)
				part_to_access[part_num] = thd_id % g_virtual_part_cnt;
			else {
				part_to_access[part_num] = rint64 % g_virtual_part_cnt;
			}
			UInt32 j;
			for (j = 0; j < part_num; j++) 
				if ( part_to_access[part_num] == part_to_access[j] )
					break;
			if (j == part_num)
				part_num ++;
		}
	} else {
		part_num = 1;
		if (FIRST_PART_LOCAL)
			part_to_access[0] = thd_id % g_part_cnt;
		else
			part_to_access[0] = rint64 % g_part_cnt;
	}

	int rid = 0;
	for (UInt32 tmp = 0; tmp < g_req_per_query; tmp ++) {		
		double r;
		drand48_r(&_query_thd->buffer, &r);
		ycsb_request * req = &requests[rid];
		if (r < g_read_perc) {
			req->rtype = RD;
		} else if (r >= g_read_perc && r <= g_write_perc + g_read_perc) {
			req->rtype = WR;
		} else {
			req->rtype = SCAN;
			req->scan_len = SCAN_LEN;
		}

		// the request will access part_id.
		uint64_t ith = tmp * part_num / g_req_per_query;
		uint64_t part_id = 
			part_to_access[ ith ];
		uint64_t table_size = g_synth_table_size / g_virtual_part_cnt;
		uint64_t row_id = zipf(table_size - 1, g_zipf_theta);
		assert(row_id < table_size);
		uint64_t primary_key = row_id * g_virtual_part_cnt + part_id;
		req->key = primary_key;
		int64_t rint64;
		lrand48_r(&_query_thd->buffer, &rint64);
		req->value = rint64 % (1<<8);
		// Make sure a single row is not accessed twice
		if (req->rtype == RD || req->rtype == WR) {
			if (all_keys.find(req->key) == all_keys.end()) {
				all_keys.insert(req->key);
				access_cnt ++;
			} else continue;
		} else {
			bool conflict = false;
			for (UInt32 i = 0; i < req->scan_len; i++) {
				primary_key = (row_id + i) * g_part_cnt + part_id;
				if (all_keys.find( primary_key )
					!= all_keys.end())
					conflict = true;
			}
			if (conflict) continue;
			else {
				for (UInt32 i = 0; i < req->scan_len; i++)
					all_keys.insert( (row_id + i) * g_part_cnt + part_id);
				access_cnt += SCAN_LEN;
			}
		}
		rid ++;
	}
	request_cnt = rid;

	// Sort the requests in key order.
	if (g_key_order) {
		for (int i = request_cnt - 1; i > 0; i--) 
			for (int j = 0; j < i; j ++)
				if (requests[j].key > requests[j + 1].key) {
					ycsb_request tmp = requests[j];
					requests[j] = requests[j + 1];
					requests[j + 1] = tmp;
				}
		for (UInt32 i = 0; i < request_cnt - 1; i++)
			assert(requests[i].key < requests[i + 1].key);
	}

}
예제 #20
0
int
main (void)
{
  time_t t = time (NULL);
  int i, ret = 0;
  double d;
  long int l;
  struct drand48_data data;
  unsigned short int buf[3];

  srand48 ((long int) t);
  for (i = 0; i < 50; i++)
    if ((d = drand48 ()) < 0.0 || d >= 1.0)
      {
        printf ("drand48 %d %g\n", i, d);
        ret = 1;
      }

  srand48_r ((long int) t, &data);
  for (i = 0; i < 50; i++)
    if (drand48_r (&data, &d) != 0 || d < 0.0 || d >= 1.0)
      {
        printf ("drand48_r %d %g\n", i, d);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if ((d = erand48 (buf)) < 0.0 || d >= 1.0)
      {
        printf ("erand48 %d %g\n", i, d);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if (erand48_r (buf, &data, &d) != 0 || d < 0.0 || d >= 1.0)
      {
        printf ("erand48_r %d %g\n", i, d);
        ret = 1;
      }

  srand48 ((long int) t);
  for (i = 0; i < 50; i++)
    if ((l = lrand48 ()) < 0 || l > INT32_MAX)
      {
        printf ("lrand48 %d %ld\n", i, l);
        ret = 1;
      }

  srand48_r ((long int) t, &data);
  for (i = 0; i < 50; i++)
    if (lrand48_r (&data, &l) != 0 || l < 0 || l > INT32_MAX)
      {
        printf ("lrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if ((l = nrand48 (buf)) < 0 || l > INT32_MAX)
      {
        printf ("nrand48 %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if (nrand48_r (buf, &data, &l) != 0 || l < 0 || l > INT32_MAX)
      {
        printf ("nrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  srand48 ((long int) t);
  for (i = 0; i < 50; i++)
    if ((l = mrand48 ()) < INT32_MIN || l > INT32_MAX)
      {
        printf ("mrand48 %d %ld\n", i, l);
        ret = 1;
      }

  srand48_r ((long int) t, &data);
  for (i = 0; i < 50; i++)
    if (mrand48_r (&data, &l) != 0 || l < INT32_MIN || l > INT32_MAX)
      {
        printf ("mrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if ((l = jrand48 (buf)) < INT32_MIN || l > INT32_MAX)
      {
        printf ("jrand48 %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if (jrand48_r (buf, &data, &l) != 0 || l < INT32_MIN || l > INT32_MAX)
      {
        printf ("jrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  return ret;
}
예제 #21
0
/**
 * Возвращает случайное число, больше 0 и меньше max
 * @param conf - рабочая конфигурация
 * @param maxx - максимально допустимое значениеs
 */
unsigned long randVal(CipherInst *conf, unsigned long max)	//TODO test (max <0), псевдослучайность, max == 1
{
	unsigned long out = 0;
	lrand48_r(conf->support->randomBuffer, &out);
	return max? out % max : out;
}
예제 #22
0
void runFailure1() {
    struct drand48_data data;
    long d;
    lrand48_r(&data, NULL);
}
예제 #23
0
void
do_sync_io(th_arg_t *th_arg, int *fd_list)
{
    struct timeval       start_tv;
    struct timeval       timer;
    meter_t             *meter;
    struct drand48_data  rand;
    int64_t              addr;
    void                *buf;
    int                  i;

    int file_idx;
    int64_t *ofst_list;
    int64_t *ofst_min_list;
    int64_t *ofst_max_list;

    meter = th_arg->meter;
    srand48_r(th_arg->common_seed ^ th_arg->tid, &rand);

    register double iowait_time = 0;
    register int64_t io_count = 0;

    buf = memalign(option.blk_sz, option.blk_sz);

    // offset handling
    ofst_list = malloc(sizeof(int64_t) * option.nr_files);
    ofst_min_list = malloc(sizeof(int64_t) * option.nr_files);
    ofst_max_list = malloc(sizeof(int64_t) * option.nr_files);

    for (i = 0; i < option.nr_files; i++) {
        if (option.ofst_start >= 0) {
            ofst_min_list[i] = option.ofst_start;
        } else {
            ofst_min_list[i] = 0;
        }

        if (option.ofst_end >= 0) {
            ofst_max_list[i] = option.ofst_end;
        } else {
            ofst_max_list[i] = option.file_size_list[i] / option.blk_sz;
        }

        if (option.seq) {
            ofst_list[i] = ofst_min_list[i]
                + (ofst_max_list[i] - ofst_min_list[i]) * th_arg->id / option.multi;
        } else {
            ofst_list[i] = ofst_min_list[i];
        }
    }

    file_idx = 0;

    GETTIMEOFDAY(&start_tv);
    if (option.rand){
        while (mb_elapsed_time_from(&start_tv) < option.timeout) {
            for(i = 0;i < 100; i++){
                // select file
                long ret;
                lrand48_r(&rand, &ret);
                file_idx = ret % option.nr_files;

                ofst_list[file_idx] = (int64_t) mb_rand_range_long(&rand,
                                                                   ofst_min_list[file_idx],
                                                                   ofst_max_list[file_idx]);

                addr = ofst_list[file_idx] * option.blk_sz + option.misalign;

                GETTIMEOFDAY(&timer);
                if (mb_read_or_write() == MB_DO_READ) {
                    mb_preadall(fd_list[file_idx], buf, option.blk_sz, addr, option.continue_on_error);
                } else {
                    mb_pwriteall(fd_list[file_idx], buf, option.blk_sz, addr, option.continue_on_error);
                }
                iowait_time += mb_elapsed_time_from(&timer);
                io_count ++;

                long idx;
                volatile double dummy = 0.0;
                for(idx = 0; idx < option.bogus_comp; idx++){
                    dummy += idx;
                }
            }
        }
    } else if (option.seq) {
        while (mb_elapsed_time_from(&start_tv) < option.timeout) {
            for(i = 0;i < 100; i++){
                // select file
                file_idx++;
                file_idx %= option.nr_files;

                // incr offset
                ofst_list[file_idx]++;
                if (ofst_list[file_idx] >= ofst_max_list[file_idx]) {
                    ofst_list[file_idx] = ofst_min_list[file_idx];
                }
                addr = ofst_list[file_idx] * option.blk_sz + option.misalign;
                if (lseek64(fd_list[file_idx], addr, SEEK_SET) == -1){
                    perror("do_sync_io:lseek64");
                    exit(EXIT_FAILURE);
                }

                GETTIMEOFDAY(&timer);
                if (option.read) {
                    mb_readall(fd_list[file_idx], buf, option.blk_sz, option.continue_on_error);
                } else if (option.write) {
                    mb_writeall(fd_list[file_idx], buf, option.blk_sz, option.continue_on_error);
                } else {
                    fprintf(stderr, "Only read or write can be specified in seq.");
                    exit(EXIT_FAILURE);
                }
                iowait_time += mb_elapsed_time_from(&timer);
                io_count ++;

                long idx;
                volatile double dummy = 0.0;
                for(idx = 0; idx < option.bogus_comp; idx++){
                    dummy += idx;
                }
            }
        }
    }

    meter->iowait_time = iowait_time;
    meter->count = io_count;

    free(buf);
}
예제 #24
0
void TraceAnalyzer::colorizeTasks()
{
	unsigned int cpu;
	double nf;
	int n;
	int ncolor;
	double s;
	int step;
	int red;
	int green;
	int blue;
	struct drand48_data rdata;
	int i, j;
	QList<TColor> colorList;
	const TColor black(0, 0, 0);
	const TColor white(255, 255, 255);
	TColor gray;
	TColor tmp;
	long int rnd = 0;

	srand48_r(290876, &rdata);

	for (cpu = 0; cpu <= getMaxCPU(); cpu++) {
		DEFINE_CPUTASKMAP_ITERATOR(iter) = cpuTaskMaps[cpu].begin();
		while (iter != cpuTaskMaps[cpu].end()) {
			CPUTask &task = iter.value();
			iter++;
			if (colorMap.contains(task.pid))
				continue;
			TColor color;
			colorMap.insert(task.pid, color);
		}
	}

	n = colorMap.size();
	nf = (double) n;
	s = 0.95 * cbrt( (1 / nf) * (255 * 255 * 255 ));
	s = TSMIN(s, 128.0);
	s = TSMAX(s, 1.0);
retry:
	step = (int) s;
	for (red = 0; red < 256; red += step) {
		for (green = 0; green < 256; green += step)  {
			for (blue = 0; blue < 256; blue += step) {
				TColor color(red, green, blue);
				if (color.SqDistance(black) < 10000)
					continue;
				if (color.SqDistance(white) < 12000)
					continue;
				gray = TColor(red, red, red);
				if (color.SqDistance(gray) < 2500)
					continue;
				colorList.append(color);
			}
		}
	}

	ncolor = colorList.size();
	if (ncolor < n) {
		s = s * 0.95;
		if (s >= 1) {
			colorList.clear();
			vtl::warnx("Retrying colors in %s:%d\n", __FILE__,
				   __LINE__);
			goto retry;
		}
	}

	/*
	 * Randomize the order by swapping every element with a random
	 * element
	 */
	for (i = 0; i < ncolor; i++) {
		lrand48_r(&rdata, &rnd);
		j = rnd % ncolor;
		tmp = colorList[j];
		colorList[j] = colorList[i];
		colorList[i] = tmp;
	}

	i = 0;

	DEFINE_COLORMAP_ITERATOR(iter) = colorMap.begin();
	while (iter != colorMap.end()) {
		TColor &color = iter.value();
		iter++;
		color = colorList.at(i % ncolor);
		i++;
	}
}
예제 #25
0
void
do_async_io(th_arg_t *arg, int *fd_list)
{
    meter_t *meter;
    struct timeval start_tv;
    int64_t addr;
    int n;
    int i;
    void *buf;
    mb_aiom_t *aiom;
    mb_res_pool_t *buffer_pool;
    struct drand48_data  rand;

    int file_idx;
    int64_t *ofst_list;
    int64_t *ofst_min_list;
    int64_t *ofst_max_list;

    srand48_r(arg->common_seed ^ arg->tid, &rand);

    meter = arg->meter;
    aiom = mb_aiom_make(option.aio_nr_events);
    if (aiom == NULL) {
        perror("do_async_io:mb_aiom_make failed");
        exit(EXIT_FAILURE);
    }
    buf = malloc(option.blk_sz);
    bzero(buf, option.blk_sz);
    buffer_pool = mb_res_pool_make(option.aio_nr_events);
    for(i = 0; i < option.aio_nr_events; i++){
        buf = memalign(512, option.blk_sz);
        mb_res_pool_push(buffer_pool, buf);
    }

    // offset handling
    ofst_list = malloc(sizeof(int64_t) * option.nr_files);
    ofst_min_list = malloc(sizeof(int64_t) * option.nr_files);
    ofst_max_list = malloc(sizeof(int64_t) * option.nr_files);

    for (i = 0; i < option.nr_files; i++) {
        if (option.ofst_start >= 0) {
            ofst_min_list[i] = option.ofst_start;
        } else {
            ofst_min_list[i] = 0;
        }

        if (option.ofst_end >= 0) {
            ofst_max_list[i] = option.ofst_end;
        } else {
            ofst_max_list[i] = option.file_size_list[i] / option.blk_sz;
        }

        if (option.seq) {
            ofst_list[i] = ofst_min_list[i] + (ofst_max_list[i] - ofst_min_list[i]) * arg->id / option.multi;
        } else {
            ofst_list[i] = ofst_min_list[i];
        }
    }

    if (option.read == false && option.write == false) {
        fprintf(stderr, "Only read or write can be specified in sync. mode\n");
        exit(EXIT_FAILURE);
    }

    file_idx = 0;

    GETTIMEOFDAY(&start_tv);
    while(mb_elapsed_time_from(&start_tv) < option.timeout) {
        while(mb_aiom_nr_submittable(aiom) > 0) {
            // select file
            if (option.rand) {
                long ret;
                lrand48_r(&rand, &ret);
                file_idx = ret % option.nr_files;
            } else {
                file_idx++;
                file_idx %= option.nr_files;
            }

            if (option.rand) {
                ofst_list[file_idx] = (int64_t) mb_rand_range_long(&rand,
                                                                   ofst_min_list[file_idx],
                                                                   ofst_max_list[file_idx]);
            } else {
                ofst_list[file_idx]++;
                if (ofst_list[file_idx] >= ofst_max_list[file_idx]) {
                    ofst_list[file_idx] = ofst_min_list[file_idx];
                }
            }
            addr = ofst_list[file_idx] * option.blk_sz + option.misalign;

            buf = mb_res_pool_pop(buffer_pool);
            if (mb_read_or_write() == MB_DO_READ) {
                mb_aiom_prep_pread(aiom, fd_list[file_idx], buf, option.blk_sz, addr);
            } else {
                mb_aiom_prep_pwrite(aiom, fd_list[file_idx], buf, option.blk_sz, addr);
            }
        }
        if (0 >= (n = mb_aiom_submit(aiom))) {
            perror("do_async_io:mb_aiom_submit failed");
            switch(-n){
            case EAGAIN : fprintf(stderr, "EAGAIN\n"); break;
            case EBADF  : fprintf(stderr, "EBADF\n"); break;
            case EFAULT : fprintf(stderr, "EFAULT\n"); break;
            case EINVAL : fprintf(stderr, "EINVAL\n"); break;
            case ENOSYS : fprintf(stderr, "ENOSYS\n"); break;
            }
            exit(EXIT_FAILURE);
        }

        if (0 >= (n = mb_aiom_wait(aiom, NULL))) {
            perror("do_async_io:mb_aiom_wait failed");
            exit(EXIT_FAILURE);
        }

        for(i = 0; i < n; i++) {
            struct io_event *event;
            event = &aiom->events[i];

            mb_res_pool_push(buffer_pool, event->obj->u.c.buf);
        }
    }

    mb_aiom_waitall(aiom);

    meter->count = aiom->iocount;
    meter->iowait_time = aiom->iowait;

    mb_aiom_destroy(aiom);

    free(ofst_list);
    free(ofst_min_list);
    free(ofst_max_list);
}
예제 #26
0
/* concurrent_test do the following:
 *  o It creates and removes randomly entries
 *    whithin the hash table. At the end the count
 *    must be equal to the expected
 */
static void concurrent_test(int num)
{
    int i, ret;
    void *data;
    char *ptr_bucket[TEST_ITER_NO][2];
    struct drand48_data seed_data;
    unsigned long seed;
    long int rand_res;

    seed = get_proper_seed();

    /* init per thread seed */
    srand48_r(seed, &seed_data);


    /* sleep for some amount of time */
    lrand48_r(&seed_data, &rand_res);
    msleep(rand_res % 40000); /* max 4s */

    fprintf(stderr, "+%d", num);

    for (i =0; i < TEST_ITER_NO; i++) {

        int sucess;
        char *key_ptr, *data_ptr;

        /* insert at least TEST_ITER_NO data
         * sets
         */
        do {
            sucess = 1;

            random_string(KEYLEN, &key_ptr, &seed_data);
            random_string(DATALEN, &data_ptr, &seed_data);

            ptr_bucket[i][KEY] = key_ptr;
            ptr_bucket[i][DATA] = data_ptr;

            ret = hi_insert(hi_hndl, (void *) key_ptr,
                            strlen(key_ptr), (void *) data_ptr);
            if (ret < 0) {
                fprintf(stderr, "# Key (%s) already in hash\n", key_ptr);
                fprintf(stderr, "Error %s\n", ret == HI_ERR_SYSTEM ?
                        strerror(errno) : hi_strerror(ret));
                sucess = 0;
                free(key_ptr);
                free(data_ptr);
            }

        } while (!sucess);
    }

    lrand48_r(&seed_data, &rand_res);
    msleep(rand_res % 4000); /* max 4s */

    /* verify storage and cleanup */
    for (i = 0; i < TEST_ITER_NO; i++) {
        ret = hi_remove(hi_hndl, ptr_bucket[i][KEY],
                        strlen(ptr_bucket[i][KEY]), &data);
        if (ret == 0) {
            if (data != ptr_bucket[i][DATA]) {
                fprintf(stderr, "Failed: should %s - is %s\n",
                        ptr_bucket[i][DATA], (char *) data);
            }

            free(ptr_bucket[i][KEY]);
            free(ptr_bucket[i][DATA]);
        } else {
            fprintf(stderr, "# already deleted\n");
        }

    }

    fprintf(stderr, "-%d", num);
}
예제 #27
0
void runSuccess() {
    struct drand48_data data;
    long d;
    lrand48_r(&data, &d);
}
예제 #28
0
void runFailure() {
    struct drand48_data data;
    long d;
    lrand48_r(NULL, &d);
}
예제 #29
0
파일: mp_big.c 프로젝트: aborase/perfTest
int main(int argc, char **argv) {
    if ( argc != 3) {
        printf("Usage: ./mp_small <mnt_directory> <num_of_threads>\n");
        exit(1);
    }

    // Get the mount directory
    char *path = argv[1];
    char *filename = "file";

    // Set the number of threads.
    int nthreads = atoi(argv[2]);
    omp_set_num_threads(nthreads);

    int tid;

    double total_time = 0;
    double read_data = 0;
    double throughput = 0;

    struct drand48_data randBuffer;
    srand48_r(time(NULL), &randBuffer);

    timestamp start = 0;
    timestamp end   = 0;

/* Fork a team of threads with each thread having a private tid variable */
#pragma omp parallel private(tid)
    {
        tid = omp_get_thread_num();

        // Setup
        int *fd_list = (int *) malloc( sizeof(int) * FILE_COUNT);

        // Open all the files
        int i = 0;
        long int random = 0;
        int idx = 0;

        size_t total_bytes = 0;

        for ( i = 0; i < FILE_COUNT; i++) {
            // Prepare the file name
            lrand48_r(&randBuffer, &random);
            idx = random % MAX_FILES + 1;
            char num[5];
            sprintf(num, "%d", idx);

            char my_file[100] = {'\0'};
            strcat(my_file, path);
            strcat(my_file, "/");
            strcat(my_file, filename);
            strcat(my_file, num);

            fd_list[i] = open(my_file, FLAGS);
            int err = errno;
            if (fd_list[i] == -1) {
                printf(" %d : Could not open file descriptor for file %s. Error = %d\n", 
                        tid, my_file, err);
                exit(1);
            }
        }

        struct stat sb;
        if (fstat(fd_list[0], &sb) == -1) {
            printf("%d : File stat failed for file\n", tid);
            exit(1);
        }
 
        char *buf = (char *)malloc(BLOCK_SIZE);

        int pages = sb.st_size / BLOCK_SIZE;
        int *index = (int *)malloc(sizeof(int) * pages);

        randomize(index, pages);

        // Prepare for read.
        struct share_it state;
        state.fd_list     = fd_list;
        state.offsets     = index;
        state.buf         =  buf;
        state.size        = sb.st_size;
        state.block_size  = (32 * 1024); 
        state.count       = FILE_COUNT;
        state.duration    = 0;
        state.total_bytes = &total_bytes;

        // Collect stats
#pragma omp barrier

        if ( tid == 0) {
            RDTSCP(start);
        }
 

        // Wait to read
#pragma omp barrier

        bool success = read_random(&state);
        if (!success) {
            printf("%d : Read failed\n", tid);
            exit(1);
        }

#pragma omp barrier
        if ( tid == 0) {
            RDTSCP(end);
        }

#pragma omp barrier
 

        // Close all the files.

        for( i = 0; i< FILE_COUNT; i++)
           close(fd_list[i]); 

        free(fd_list);
        free(buf);

        if (tid == 0) {
            read_data = sb.st_size * FILE_COUNT;
        } 

    }  /* All threads join master thread and terminate */

    double val = (read_data * nthreads * (CPU_FREQ * 1000000) ) / (  (end - start) * 1024 * 1024 * 1024); // GB/sec
    printf("%lf\n", val);

}
예제 #30
0
int main(int argc, char *argv[]){
    
    int numThreads = atoi(argv[1]);
    int threshold = atoi(argv[2]);
    int levels = atoi(argv[3]);
    int * participantsAtLevel = (int * ) malloc(levels);
    for (int i = 0; i < levels; i++) {
        participantsAtLevel[i] = atoi(argv[4 + i]);
    }
    
    omp_set_num_threads(numThreads);
    
    int numIter = 144 * (0x4ffff) / numThreads;
    
    //int levels = 4;
    //int participantsAtLevel[] = {2, 4, 8, 16};
    //omp_set_num_threads(16);
    //int levels = 2;
    //int participantsAtLevel[] = {12, 36};
    //omp_set_num_threads(36);
    
    //int levels = 2;
    //int participantsAtLevel[] = {2, 4};
    //omp_set_num_threads(4);
    
    struct timeval start;
    struct timeval end;
    uint64_t elapsed;

//#define DOWORK

    
    
#pragma omp parallel
    {
        
        int tid = omp_get_thread_num();
        if(tid == 0)
            gettimeofday(&start, 0);
#ifdef USE_RAND
        struct drand48_data rBuf;
        srand48_r(tid, &rBuf);
        long int ticks;
#endif
        for(int i = 0; i < numIter; i++) {
            QNode * me = new QNode();
#ifdef USE_RAND
            lrand48_r(&rBuf, &ticks);
            uint64_t patience = 100000 + (abs(ticks) % 100000);
#else
//            uint64_t patience = UINT64_MAX;
            uint64_t patience = numIter % 10 == 0 ? 0 : UINT64_MAX;

#endif
            if (Acquire(&MCSLock, me,  patience)) {
            
#ifdef  DOWORK
                DoInsideCS();
#endif
              //  printf("Acquired %d!\n", tid);
            
//#define VALIDATE
#ifdef VALIDATE
                int lvar = var;
                var ++;
                assert(var == lvar + 1);
#endif
                Release(&MCSLock, me);
            } else {
               // printf("========Aborted %d!\n", tid);
            }
            
#ifdef  DOWORK
            DoOutsideCS();
#endif
            
        }
    }
    
    gettimeofday(&end, 0);
    elapsed = TIME_SPENT(start, end);
    double throughPut = (numIter * numThreads * 144 * 0x4ffffL) * 100000.0 / elapsed;
    std::cout<<"\n Throughput = " << throughPut;

    return 0;
}