int main(int argc, char **argv) { int i; pthread_t *id; double start, time = 0; process_args(argc,argv); // bind_to_core(0); pthread_barrier_init(&tbarrier, NULL, nthreads + 2); id = calloc(nthreads + 1, sizeof(*id)); list = tslist_create(nthreads, nadds * nbatch); /* setup and create threads */ pthread_create(&id[nthreads], NULL, consumer, (void *)NULL); for (i=0; i<nthreads; i++) { pthread_create(&id[i], NULL, producer, (void *)NULL); } pthread_barrier_wait(&tbarrier); start = GET_TS(); for (i=0; i<nthreads + 1; i++) { pthread_join(id[i], NULL); } time = GET_TS() - start; int count = nthreads * nadds * nbatch; printf("Number of elements is %d\n", count); printf("Time: %lf\n", time * 1E6); printf("Performance: %lf Melem/s\n", count / time / 1E6); tslist_append_done(list, nthreads); }
void *f(void* thr_data) { int my_idx = *(int*)thr_data; cpu_set_t set; CPU_ZERO(&set); CPU_SET(my_idx, &set); if( pthread_setaffinity_np(pthread_self(), sizeof(set), &set) ){ abort(); } while( !start ); timings[my_idx][0] = GET_TS(); for(int n = 0; n < niter; ++n) { _Bool flag = false; while( !flag ){ int tmp = acnt; flag = atomic_compare_exchange_weak(&acnt, &tmp, tmp + 1); } ++cnt; // undefined behavior, in practice some updates missed } timings[my_idx][1] = GET_TS(); return 0; }
static int run_test(int server) { int i; if( server ){ connect_server(); } else { connect_client(); } poll_prepare(); for(i=1; i <= 4194304; i *= 2){ int rep, j; if( i < 4096 ){ rep = 100; } else { rep = 10; } /* warmup */ for(j=0; j < rep/10; j++){ progress(server, i); } double start = GET_TS(); for(j=0; j < rep; j++){ progress(server, i); } double time = GET_TS() - start; printf("%d\t%lf\t%lf\n",i, time / rep / 2 * 1000000, (double)progress_count / progress_calls); progress_count = 0; progress_calls = 0; } }
int main(int argc, char **argv) { if( argc < 3 ){ printf("Want <nthr> and <niter>\n"); return 0; } nthr = atoi(argv[1]); niter = atoi(argv[2]); pthread_t thr[nthr]; for(int n = 0; n < nthr; ++n){ indexes[n] = n; pthread_create(&thr[n], NULL, f, &indexes[n]); } start = 1; for(int n = 0; n < nthr; ++n) pthread_join(thr[n], NULL); double min_start = GET_TS(), max_start = 0, avg_start = 0; double min_work = GET_TS(), max_work = 0, avg_work = 0; int min_w_idx = -1, max_w_idx = -1; for(int n=0; n < nthr; n++){ if( min_start > timings[n][0] ){ min_start = timings[n][0]; } avg_start += timings[n][0]; if( max_start < timings[n][0] ){ max_start = timings[n][0]; } double interval = timings[n][1] - timings[n][0]; if( interval < min_work ){ min_work = interval; min_w_idx = n; } if( interval > max_work ){ max_w_idx = n; max_work = interval; } avg_work += interval; } printf("The atomic counter is %u\n", acnt); printf("The non-atomic counter is %u\n", cnt); printf("Start: %lf/%lf/%lf\n", avg_start / nthr, min_start, max_start); printf("Work : %lf / %lf / %lf %d/%d\n", avg_work / nthr, min_work, max_work, min_w_idx, max_w_idx); return 0; }
bool pmixp_server_pp_check_fini(int size) { if ( (pmixp_server_pp_count() + 1) >= (_pmixp_pp_warmup + _pmixp_pp_iters)){ slurm_mutex_lock(&_pmixp_pp_lock); PMIXP_ERROR("latency: %d - %.9lf", size, (GET_TS() - _pmixp_pp_start) / _pmixp_pp_iters ); slurm_mutex_unlock(&_pmixp_pp_lock); return true; } return false; }
void pmixp_server_pp_start(void) { _pmixp_pp_start = GET_TS(); }