void test_sleep(threaddata_t *tdata) { unsigned usecs = (unsigned) sleep_min_us + (rand() % (sleep_max_us - sleep_min_us)); ACTION_PRINTF("tid=%3d> sleeping %.3f millisecs", tdata->tid, usecs/1000.0); { uint64_t goal = gasnett_ticks_to_us(gasnett_ticks_now()) + usecs; while (gasnett_ticks_to_us(gasnett_ticks_now()) < goal) gasnett_sched_yield(); } ACTION_PRINTF("tid=%3d> awaking", tdata->tid); }
void run() { unsigned i; gasnett_tick_t start, end; hashtable_create(TABLE_SIZE); BARRIER(); start = gasnett_ticks_now(); for (i = 0; i < WRITES_PER_PROC; ++i) { hashtable_insert(grt_id * WRITES_PER_PROC + i); } end = gasnett_ticks_now(); unsigned time = ((unsigned) gasnett_ticks_to_us(end - start)); printf("processor %u: insertion time=%f us\n", grt_id, (double) time); fflush(stdout); grt_write(0, time, ×[grt_id]); BARRIER(); /* sanity check */ for (i = 0; i < WRITES_PER_PROC; ++i) { grt_word_t num = grt_id * WRITES_PER_PROC + i; grt_bool_t found = hashtable_find(num); if (!found) { fprintf(stderr, "processor %d: expected to find %d\n", grt_id, (int) num); } } BARRIER(); if (grt_id == 0) { time = 0, max_time = 0; for (i = 0; i < grt_num_procs; ++i) { gasnett_tick_t this_time = times[i]; time += this_time; if (this_time >= max_time) max_time = this_time; } time_per_op = ((float) time) / NUM_WRITES; printf("total CPU time=%f us\n", (double) time); printf("time per operation=%f us\n", time_per_op); printf("max time=%f us\n", (double) max_time); } BARRIER(); hashtable_destroy(); BARRIER(); }
void run() { unsigned i, time; gasnett_tick_t start, end; hashset_create(params[HASHSET_SIZE], params[ON_PTHREAD]); BARRIER(); start = gasnett_ticks_now(); for (i = 0; i < MY_NUM_OPS; ++i) { if (put_flags[i] == GRT_TRUE) { hashset_insert(numbers[i]); } else { hashset_find(numbers[i]); } } end = gasnett_ticks_now(); time = ((unsigned) gasnett_ticks_to_us(end - start)); //printf("processor %u: execution time=%f us\n", // grt_id, (double) time); fflush(stdout); grt_write(0, time, ×[grt_id]); BARRIER(); if (grt_id == 0) { time = 0, max_time = 0; for (i = 0; i < grt_num_procs; ++i) { gasnett_tick_t this_time = times[i]; time += this_time; if (this_time >= max_time) max_time = this_time; } time_per_op = ((float) time) / params[NUM_OPS]; printf("total CPU time=%f us\n", (double) time); printf("time per operation=%f us\n", time_per_op); printf("max time=%f us\n", (double) max_time); } BARRIER(); hashset_destroy(); BARRIER(); }
void run() { unsigned i, time; gasnett_tick_t start, end; hash_map_create(params[HASHMAP_SIZE], (grt_bool_t) params[ON_PTHREAD]); grt_barrier(); #ifdef LOCKS grt_lock_state_t state; #endif for (i = 0; i < MY_NUM_OPS; ++i) { grt_word_t key = keys[i], val = values[i]; #ifdef LOCKS hash_t hash = compute_hash(key); hash_map_lock(hash.proc, hash.offset, WRITE, &state); #endif hash_map_insert(key, val); #ifdef LOCKS hash_map_unlock(hash.proc, hash.offset); #endif } BARRIER(); start = gasnett_ticks_now(); #ifdef LOCKS grt_lock_state_t state1, state2; #endif for (i = 0; i < MY_NUM_OPS; ++i) { unsigned idx = grt_random_next() * MY_NUM_OPS; grt_word_t key1 = keys[i]; unsigned second_idx = grt_random_next() * MY_NUM_OPS; grt_word_t key2 = keys[second_idx]; #ifdef LOCKS lock(key1, key2, &state1, &state2); #endif grt_word_t val1, val2; #ifndef LOCKS #ifndef NOLOCKS stm_start(grt_id); #endif #endif grt_bool_t found1 = hash_map_find(key1, &val1); grt_bool_t found2 = hash_map_find(key2, &val2); hash_map_insert(key1, val2); hash_map_insert(key2, val1); #ifndef LOCKS #ifndef NOLOCKS stm_commit(grt_id); #endif #endif #if LOCKS unlock(key1, key2); #endif } end = gasnett_ticks_now(); time = ((unsigned) gasnett_ticks_to_us(end - start)); printf("processor %u: execution time=%f us\n", grt_id, (double) time); fflush(stdout); grt_write(0, time, ×[grt_id]); BARRIER(); if (grt_id == 0) { time = 0, max_time = 0; for (i = 0; i < grt_num_procs; ++i) { gasnett_tick_t this_time = times[i]; time += this_time; if (this_time >= max_time) max_time = this_time; } time_per_op = ((float) time) / params[NUM_OPS]; printf("total CPU time=%f us\n", (double) time); printf("time per operation=%f us\n", time_per_op); printf("max time=%f us\n", (double) max_time); } BARRIER(); hash_map_destroy(); BARRIER(); }