/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { manager_t* managerPtr; client_t** clients; TIMER_T start; TIMER_T stop; /* Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_params[PARAM_CLIENTS]); managerPtr = initializeManager(); assert(managerPtr != NULL); clients = initializeClients(managerPtr); assert(clients != NULL); long numThread = global_params[PARAM_CLIENTS]; TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); /* Run transactions */ printf("Running clients... "); fflush(stdout); GOTO_SIM(); TIMER_READ(start); #ifdef OTM #pragma omp parallel { client_run(clients); } #else thread_start(client_run, (void*)clients); #endif TIMER_READ(stop); GOTO_REAL(); puts("done."); printf("Time = %0.6lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); checkTables(managerPtr); /* Clean up */ printf("Deallocating memory... "); fflush(stdout); freeClients(clients); /* * TODO: The contents of the manager's table need to be deallocated. */ manager_free(managerPtr); puts("done."); fflush(stdout); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); SETUP_NUMBER_TASKS(6); /* * Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_numThread); TM_STARTUP(global_numThread, 0); P_MEMORY_STARTUP(global_numThread); SETUP_NUMBER_THREADS(global_numThread); thread_startup(global_numThread); int repeat = global_repeats; double time_total = 0.0; double energy_total = 0.0; for (; repeat > 0; --repeat) { global_meshPtr = mesh_alloc(); assert(global_meshPtr); long initNumElement = mesh_read(global_meshPtr, global_inputPrefix); global_workHeapPtr = heap_alloc(1, &element_heapCompare); assert(global_workHeapPtr); long initNumBadElement = initializeWork(global_workHeapPtr, global_meshPtr); TIMER_T start; TIMER_READ(start); GOTO_SIM(); thread_start(process, NULL); GOTO_REAL(); TIMER_T stop; TIMER_READ(stop); double time_tmp = TIMER_DIFF_SECONDS(start, stop); PRINT_STATS(); time_total += time_tmp; } printf("Time = %0.3lf\n", time_total); fflush(stdout); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
MAIN(argc, argv) { TIMER_T start; TIMER_T stop; GOTO_REAL(); parseArgs(argc, (char** const)argv); long sz = (long)global_params[PARAM_SIZE]; global_array = (aligned_type_t*) malloc(sz * sizeof(aligned_type_t)); long k = 0; for (; k < sz; k++) { global_array[k].value = 0; } long numThread = global_params[PARAM_THREADS]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); printf("Running clients... "); fflush(stdout); TIMER_READ(start); GOTO_SIM(); thread_start(client_run, (void*)&numThread); GOTO_REAL(); TIMER_READ(stop); puts("done."); printf("Time = %0.6lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); long i = 0; long sum = 0; for (;i < sz; i++) { sum += global_array[i].value; // printf("%ld\n", global_array[i].value); } if (sum != 0) { printf("Problem, sum was not zero!: %ld\n", sum); } TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
int main(int argc, char **argv) { set_cpu(the_cores[0]); ssalloc_init(); seeds = seed_rand(); #ifdef PAPI if (PAPI_VER_CURRENT != PAPI_library_init(PAPI_VER_CURRENT)) { printf("PAPI_library_init error.\n"); return 0; } else { printf("PAPI_library_init success.\n"); } if (PAPI_OK != PAPI_query_event(PAPI_L1_DCM)) { printf("Cannot count PAPI_L1_DCM."); } printf("PAPI_query_event: PAPI_L1_DCM OK.\n"); if (PAPI_OK != PAPI_query_event(PAPI_L2_DCM)) { printf("Cannot count PAPI_L2_DCM."); } printf("PAPI_query_event: PAPI_L2_DCM OK.\n"); #endif struct option long_options[] = { // These options don't set a flag {"help", no_argument, NULL, 'h'}, {"duration", required_argument, NULL, 'd'}, {"priority-queue", required_argument, NULL, 'p'}, {"linden", required_argument, NULL, 'L'}, {"spray-list", required_argument, NULL, 'l'}, {"event-simulator", required_argument, NULL, 'e'}, {"initial-size", required_argument, NULL, 'i'}, {"num-threads", required_argument, NULL, 'n'}, {"range", required_argument, NULL, 'r'}, {"seed", required_argument, NULL, 's'}, {"update-rate", required_argument, NULL, 'u'}, {"elasticity", required_argument, NULL, 'x'}, {"nothing", required_argument, NULL, 'l'}, {NULL, 0, NULL, 0} }; sl_intset_t *set; pq_t *linden_set; int i, c, size; val_t last = 0; val_t val = 0; pval_t pval = 0; unsigned long reads, effreads, updates, collisions, effupds, aborts, aborts_locked_read, aborts_locked_write, aborts_validate_read, aborts_validate_write, aborts_validate_commit, add, added, remove, removed, aborts_invalid_memory, aborts_double_write, max_retries, failures_because_contention, depdist; thread_data_t *data; pthread_t *threads; pthread_attr_t attr; barrier_t barrier; struct timeval start, end; struct timespec timeout; int duration = DEFAULT_DURATION; int initial = DEFAULT_INITIAL; int nb_threads = DEFAULT_NB_THREADS; long range = DEFAULT_RANGE; int seed = DEFAULT_SEED; int seed2 = DEFAULT_SEED; int update = DEFAULT_UPDATE; int unit_tx = DEFAULT_ELASTICITY; int alternate = DEFAULT_ALTERNATE; int pq = DEFAULT_PQ; int sl = DEFAULT_SL; int es = DEFAULT_ES; int lin = DEFAULT_LIN; int effective = DEFAULT_EFFECTIVE; sigset_t block_set; while(1) { i = 0; c = getopt_long(argc, argv, "hAplLe:f:d:i:n:r:s:u:x:l:", long_options, &i); if(c == -1) break; if(c == 0 && long_options[i].flag == 0) c = long_options[i].val; switch(c) { case 0: break; case 'h': printf("intset -- STM stress test " "(skip list)\n" "\n" "Usage:\n" " intset [options...]\n" "\n" "Options:\n" " -h, --help\n" " Print this message\n" " -A, --Alternate\n" " Consecutive insert/remove target the same value\n" " -l, --spray-list\n" " Remove via delete_min operations using a spray list\n" " -p, --priority-queue\n" " Remove via delete_min operations using a skip list\n" " -e, --event-simulator\n" " Descrete event simulator experiment, parameter = dependency distance\n" " -L, --linden\n" " Use Linden's priority queue\n" " -f, --effective <int>\n" " update txs must effectively write (0=trial, 1=effective, default=" XSTR(DEFAULT_EFFECTIVE) ")\n" " -d, --duration <int>\n" " Test duration in milliseconds (0=infinite, default=" XSTR(DEFAULT_DURATION) ")\n" " -i, --initial-size <int>\n" " Number of elements to insert before test (default=" XSTR(DEFAULT_INITIAL) ")\n" " -n, --num-threads <int>\n" " Number of threads (default=" XSTR(DEFAULT_NB_THREADS) ")\n" " -r, --range <int>\n" " Range of integer values inserted in set (default=" XSTR(DEFAULT_RANGE) ")\n" " -s, --seed <int>\n" " RNG seed (0=time-based, default=" XSTR(DEFAULT_SEED) ")\n" " -u, --update-rate <int>\n" " Percentage of update transactions (default=" XSTR(DEFAULT_UPDATE) ")\n" " -x, --elasticity (default=4)\n" " Use elastic transactions\n" " 0 = non-protected,\n" " 1 = normal transaction,\n" " 2 = read elastic-tx,\n" " 3 = read/add elastic-tx,\n" " 4 = read/add/rem elastic-tx,\n" " 5 = fraser lock-free\n" ); exit(0); case 'A': alternate = 1; break; case 'l': sl = 1; break; case 'p': pq = 1; break; case 'e': es = 1; depdist = atoi(optarg); break; case 'L': lin = 1; break; case 'f': effective = atoi(optarg); break; case 'd': duration = atoi(optarg); break; case 'i': initial = atoi(optarg); break; case 'n': nb_threads = atoi(optarg); break; case 'r': range = atol(optarg); break; case 's': seed = atoi(optarg); break; case 'u': update = atoi(optarg); break; case 'x': unit_tx = atoi(optarg); break; case '?': printf("Use -h or --help for help\n"); exit(0); default: exit(1); } } assert(duration >= 0); assert(initial >= 0); assert(nb_threads > 0); assert(range > 0); assert(update >= 0 && update <= 100); // if (range < initial) // { range = 100000000; // } printf("Set type : skip list\n"); printf("Duration : %d\n", duration); printf("Initial size : %u\n", initial); printf("Nb threads : %d\n", nb_threads); printf("Value range : %ld\n", range); printf("Seed : %d\n", seed); printf("Update rate : %d\n", update); printf("Elasticity : %d\n", unit_tx); printf("Alternate : %d\n", alternate); printf("Priority Q : %d\n", pq); printf("Spray List : %d\n", sl); printf("Linden : %d\n", lin); printf("Efffective : %d\n", effective); printf("Type sizes : int=%d/long=%d/ptr=%d/word=%d\n", (int)sizeof(int), (int)sizeof(long), (int)sizeof(void *), (int)sizeof(uintptr_t)); timeout.tv_sec = duration / 1000; timeout.tv_nsec = (duration % 1000) * 1000000; if ((data = (thread_data_t *)malloc(nb_threads * sizeof(thread_data_t))) == NULL) { perror("malloc"); exit(1); } if ((threads = (pthread_t *)malloc(nb_threads * sizeof(pthread_t))) == NULL) { perror("malloc"); exit(1); } if (seed == 0) srand((int)time(0)); else srand(seed); *levelmax = floor_log_2((unsigned int) initial); set = sl_set_new(); /* stop = 0; */ *running = 1; // Init STM printf("Initializing STM\n"); TM_STARTUP(); // Populate set printf("Adding %d entries to set\n", initial); i = 0; if (lin) { int offset = 32; // not sure what this does _init_gc_subsystem(); linden_set = pq_init(offset); } if (es) { // event simulator has event ids 1..m // no timeout in ES, finishes when list is empty // timeout.tv_sec = 0; // timeout.tv_nsec = 0; if ((nb_deps = (int *)malloc(initial * sizeof(int))) == NULL) { perror("malloc"); exit(1); } if ((deps = (val_t **)malloc(initial * sizeof(val_t*))) == NULL) { perror("malloc"); exit(1); } while (i < initial) { if ((deps[i] = (val_t*)malloc(MAX_DEPS * sizeof(val_t))) == NULL) { perror("malloc"); exit(1); } int num_deps = 0; nb_deps[i] = 0; if (lin) { insert(linden_set, i, i); } else { sl_add(set, (val_t)i, 0); } while (i < initial-1 && num_deps < MAX_DEPS && rand_range_re(NULL, 3) % 2) { // Add geometrically distributed # of deps TODO: parametrize '2' val_t dep = ((val_t)i)+1; int dep_var = sqrt(depdist); dep += depdist + rand_range_re(NULL,2*dep_var) - dep_var; if (dep >= initial) dep = initial-1; // while (dep < initial-1 && rand_range_re(NULL, 11) % 10) { // dep should be i+GEO(10) TODO: parametrize '10' // dep++; // } deps[i][num_deps] = dep; num_deps++; } nb_deps[i] = num_deps; if (num_deps < MAX_DEPS) { deps[i][num_deps] = -1; // marks last dep } i++; } } else if (lin) { while (i < initial) { #ifdef DISTRIBUTION_EXPERIMENT pval = i; #else pval = rand_range_re(NULL, range); #endif insert(linden_set, pval, pval); last = pval; i++; } } else { while (i < initial) { #ifdef DISTRIBUTION_EXPERIMENT val = i; #else val = rand_range_re(NULL, range); #endif if (sl_add(set, val, 0)) { last = val; i++; } } } #ifdef PRINT_LIST print_skiplist(set); #endif size = sl_set_size(set); printf("Set size : %d\n", size); printf("Level max : %d\n", *levelmax); // Access set from all threads barrier_init(&barrier, nb_threads + 1); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); printf("Creating threads: "); for (i = 0; i < nb_threads; i++) { printf("%d, ", i); data[i].first = last; data[i].range = range; data[i].update = update; data[i].unit_tx = unit_tx; data[i].alternate = alternate; data[i].pq = pq; data[i].sl = sl; data[i].es = es; data[i].effective = effective; data[i].first_remove = -1; data[i].nb_collisions = 0; data[i].nb_add = 0; data[i].nb_clean = 0; data[i].nb_added = 0; data[i].nb_remove = 0; data[i].nb_removed = 0; data[i].nb_contains = 0; data[i].nb_found = 0; data[i].nb_aborts = 0; data[i].nb_aborts_locked_read = 0; data[i].nb_aborts_locked_write = 0; data[i].nb_aborts_validate_read = 0; data[i].nb_aborts_validate_write = 0; data[i].nb_aborts_validate_commit = 0; data[i].nb_aborts_invalid_memory = 0; data[i].nb_aborts_double_write = 0; data[i].max_retries = 0; data[i].nb_threads = nb_threads; data[i].seed = rand(); data[i].seed2 = rand(); data[i].set = set; data[i].barrier = &barrier; data[i].failures_because_contention = 0; data[i].id = i; /* LINDEN */ data[i].lin = lin; data[i].linden_set = linden_set; if (pthread_create(&threads[i], &attr, test, (void *)(&data[i])) != 0) { fprintf(stderr, "Error creating thread\n"); exit(1); } } pthread_attr_destroy(&attr); // Catch some signals if (signal(SIGHUP, catcher) == SIG_ERR || //signal(SIGINT, catcher) == SIG_ERR || signal(SIGTERM, catcher) == SIG_ERR) { perror("signal"); exit(1); } // Start threads barrier_cross(&barrier); printf("STARTING...\n"); gettimeofday(&start, NULL); #ifndef DISTRIBUTION_EXPERIMENT // don't sleep if doing distro experiment if (duration > 0) { nanosleep(&timeout, NULL); } else { sigemptyset(&block_set); sigsuspend(&block_set); } #endif /* AO_store_full(&stop, 1); */ *running = 0; // if (!es) { gettimeofday(&end, NULL); // } printf("STOPPING...\n"); // Wait for thread completion for (i = 0; i < nb_threads; i++) { if (pthread_join(threads[i], NULL) != 0) { fprintf(stderr, "Error waiting for thread completion\n"); exit(1); } } // if (es) { // gettimeofday(&end, NULL); // time when all threads finish // } printf ("duration = %d\n", duration); duration = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); printf ("duration = %d\n", duration); aborts = 0; aborts_locked_read = 0; aborts_locked_write = 0; aborts_validate_read = 0; aborts_validate_write = 0; aborts_validate_commit = 0; aborts_invalid_memory = 0; aborts_double_write = 0; failures_because_contention = 0; reads = 0; effreads = 0; updates = 0; collisions = 0; add = 0; added = 0; remove = 0; removed = 0; effupds = 0; max_retries = 0; for (i = 0; i < nb_threads; i++) { printf("Thread %d\n", i); printf(" #add : %lu\n", data[i].nb_add); printf(" #added : %lu\n", data[i].nb_added); printf(" #remove : %lu\n", data[i].nb_remove); printf(" #removed : %lu\n", data[i].nb_removed); printf(" #cleaned : %lu\n", data[i].nb_clean); printf("first remove : %d\n", data[i].first_remove); printf(" #collisions : %lu\n", data[i].nb_collisions); printf(" #contains : %lu\n", data[i].nb_contains); printf(" #found : %lu\n", data[i].nb_found); printf(" #aborts : %lu\n", data[i].nb_aborts); printf(" #lock-r : %lu\n", data[i].nb_aborts_locked_read); printf(" #lock-w : %lu\n", data[i].nb_aborts_locked_write); printf(" #val-r : %lu\n", data[i].nb_aborts_validate_read); printf(" #val-w : %lu\n", data[i].nb_aborts_validate_write); printf(" #val-c : %lu\n", data[i].nb_aborts_validate_commit); printf(" #inv-mem : %lu\n", data[i].nb_aborts_invalid_memory); printf(" #dup-w : %lu\n", data[i].nb_aborts_double_write); printf(" #failures : %lu\n", data[i].failures_because_contention); printf(" Max retries : %lu\n", data[i].max_retries); aborts += data[i].nb_aborts; aborts_locked_read += data[i].nb_aborts_locked_read; aborts_locked_write += data[i].nb_aborts_locked_write; aborts_validate_read += data[i].nb_aborts_validate_read; aborts_validate_write += data[i].nb_aborts_validate_write; aborts_validate_commit += data[i].nb_aborts_validate_commit; aborts_invalid_memory += data[i].nb_aborts_invalid_memory; aborts_double_write += data[i].nb_aborts_double_write; failures_because_contention += data[i].failures_because_contention; reads += data[i].nb_contains; effreads += data[i].nb_contains + (data[i].nb_add - data[i].nb_added) + (data[i].nb_remove - data[i].nb_removed); updates += (data[i].nb_add + data[i].nb_remove); collisions += data[i].nb_collisions; add += data[i].nb_add; added += data[i].nb_added; remove += data[i].nb_remove; removed += data[i].nb_removed; effupds += data[i].nb_removed + data[i].nb_added; size += data[i].nb_added - data[i].nb_removed; if (max_retries < data[i].max_retries) max_retries = data[i].max_retries; } printf("Set size : %d (expected: %d)\n", sl_set_size(set), size); printf("Duration : %d (ms)\n", duration); printf("#txs : %lu (%f / s)\n", reads + updates, (reads + updates) * 1000.0 / duration); printf("#read txs : "); if (effective) { printf("%lu (%f / s)\n", effreads, effreads * 1000.0 / duration); printf(" #contains : %lu (%f / s)\n", reads, reads * 1000.0 / duration); } else printf("%lu (%f / s)\n", reads, reads * 1000.0 / duration); printf("#eff. upd rate: %f \n", 100.0 * effupds / (effupds + effreads)); printf("#update txs : "); if (effective) { printf("%lu (%f / s)\n", effupds, effupds * 1000.0 / duration); printf(" #upd trials : %lu (%f / s)\n", updates, updates * 1000.0 / duration); } else printf("%lu (%f / s)\n", updates, updates * 1000.0 / duration); printf("#total_remove : %lu\n", remove); printf("#total_removed: %lu\n", removed); printf("#total_add : %lu\n", add); printf("#total_added : %lu\n", added); printf("#net (rem-add): %lu\n", removed-added); printf("#total_collide: %lu\n", collisions); printf("#norm_collide : %f\n", ((double)collisions)/removed); printf("#aborts : %lu (%f / s)\n", aborts, aborts * 1000.0 / duration); printf(" #lock-r : %lu (%f / s)\n", aborts_locked_read, aborts_locked_read * 1000.0 / duration); printf(" #lock-w : %lu (%f / s)\n", aborts_locked_write, aborts_locked_write * 1000.0 / duration); printf(" #val-r : %lu (%f / s)\n", aborts_validate_read, aborts_validate_read * 1000.0 / duration); printf(" #val-w : %lu (%f / s)\n", aborts_validate_write, aborts_validate_write * 1000.0 / duration); printf(" #val-c : %lu (%f / s)\n", aborts_validate_commit, aborts_validate_commit * 1000.0 / duration); printf(" #inv-mem : %lu (%f / s)\n", aborts_invalid_memory, aborts_invalid_memory * 1000.0 / duration); printf(" #dup-w : %lu (%f / s)\n", aborts_double_write, aborts_double_write * 1000.0 / duration); printf(" #failures : %lu\n", failures_because_contention); printf("Max retries : %lu\n", max_retries); #ifdef PRINT_END print_skiplist(set); #endif #ifdef PAPI long total_L1_miss = 0; unsigned k = 0; for (k = 0; k < nb_threads; k++) { total_L1_miss += g_values[k][0]; //printf("[Thread %d] L1_DCM: %lld\n", i, g_values[i][0]); //printf("[Thread %d] L2_DCM: %lld\n", i, g_values[i][1]); } printf("\n#L1 Cache Misses: %lld\n", total_L1_miss); printf("#Normalized Cache Misses: %f\n", ((double)total_L1_miss)/(reads+updates)); #endif // Delete set sl_set_delete(set); // Cleanup STM TM_SHUTDOWN(); free(threads); free(data); return 0; }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); maze_t* mazePtr = maze_alloc(); assert(mazePtr); long numPathToRoute = maze_read(mazePtr, global_inputFile); router_t* routerPtr = router_alloc(global_params[PARAM_XCOST], global_params[PARAM_YCOST], global_params[PARAM_ZCOST], global_params[PARAM_BENDCOST]); assert(routerPtr); list_t* pathVectorListPtr = list_alloc(NULL); assert(pathVectorListPtr); /* * Run transactions */ router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr}; // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using // wallclock time, we want to be sure we read time inside the // simulator, or else we report native cycles spent on the benchmark // instead of simulator cycles. GOTO_SIM(); TIMER_T startTime; TIMER_READ(startTime); #ifdef OTM #pragma omp parallel { router_solve((void *)&routerArg); } #else thread_start(router_solve, (void*)&routerArg); #endif TIMER_T stopTime; TIMER_READ(stopTime); // NB: As above, timer reads must be done inside of the simulated region // for PTLSim/ASF GOTO_REAL(); long numPathRouted = 0; list_iter_t it; list_iter_reset(&it, pathVectorListPtr); while (list_iter_hasNext(&it, pathVectorListPtr)) { vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it, pathVectorListPtr); numPathRouted += vector_getSize(pathVectorPtr); } printf("Paths routed = %li\n", numPathRouted); printf("Elapsed time = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution and clean up */ assert(numPathRouted <= numPathToRoute); bool status = maze_checkPaths(mazePtr, pathVectorListPtr, global_doPrint); assert(status); puts("Verification passed."); maze_free(mazePtr); router_free(routerPtr); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }
int main(int argc, char **argv) { struct option long_options[] = { // These options don't set a flag {"help", no_argument, NULL, 'h'}, {"alternate", no_argument, NULL, 'A'}, {"effective", required_argument, NULL, 'f'}, {"duration", required_argument, NULL, 'd'}, {"initial-size", required_argument, NULL, 'i'}, {"num-threads", required_argument, NULL, 'n'}, {"range", required_argument, NULL, 'r'}, {"seed", required_argument, NULL, 's'}, {"update-rate", required_argument, NULL, 'u'}, {"move-rate", required_argument, NULL, 'm'}, {"snapshot-rate", required_argument, NULL, 'a'}, {"elasticity", required_argument, NULL, 'x'}, {NULL, 0, NULL, 0} }; ht_intset_t *set; int i, c, size; val_t last = 0; val_t val = 0; unsigned long reads, effreads, updates, effupds, moves, snapshots, aborts, aborts_locked_read, aborts_locked_write, aborts_validate_read, aborts_validate_write, aborts_validate_commit, aborts_invalid_memory, aborts_double_write, max_retries, failures_because_contention; thread_data_t *data; pthread_t *threads; pthread_attr_t attr; barrier_t barrier; struct timeval start, end; struct timespec timeout; int duration = DEFAULT_DURATION; int initial = DEFAULT_INITIAL; int nb_threads = DEFAULT_NB_THREADS; long range = DEFAULT_RANGE; int seed = DEFAULT_SEED; int update = DEFAULT_UPDATE; int load_factor = DEFAULT_LOAD; int move = DEFAULT_MOVE; int snapshot = DEFAULT_SNAPSHOT; int unit_tx = DEFAULT_ELASTICITY; int alternate = DEFAULT_ALTERNATE; int effective = DEFAULT_EFFECTIVE; sigset_t block_set; while(1) { i = 0; c = getopt_long(argc, argv, "hAf:d:i:n:r:s:u:m:a:l:x:", long_options, &i); if(c == -1) break; if(c == 0 && long_options[i].flag == 0) c = long_options[i].val; switch(c) { case 0: // Flag is automatically set break; case 'h': printf("intset -- STM stress test " "(hash table)\n" "\n" "Usage:\n" " intset [options...]\n" "\n" "Options:\n" " -h, --help\n" " Print this message\n" " -A, --Alternate\n" " Consecutive insert/remove target the same value\n" " -f, --effective <int>\n" " update txs must effectively write (0=trial, 1=effective, default=" XSTR(DEFAULT_EFFECTIVE) ")\n" " -d, --duration <int>\n" " Test duration in milliseconds (0=infinite, default=" XSTR(DEFAULT_DURATION) ")\n" " -i, --initial-size <int>\n" " Number of elements to insert before test (default=" XSTR(DEFAULT_INITIAL) ")\n" " -n, --num-threads <int>\n" " Number of threads (default=" XSTR(DEFAULT_NB_THREADS) ")\n" " -r, --range <int>\n" " Range of integer values inserted in set (default=" XSTR(DEFAULT_RANGE) ")\n" " -s, --seed <int>\n" " RNG seed (0=time-based, default=" XSTR(DEFAULT_SEED) ")\n" " -u, --update-rate <int>\n" " Percentage of update transactions (default=" XSTR(DEFAULT_UPDATE) ")\n" " -m , --move-rate <int>\n" " Percentage of move transactions (default=" XSTR(DEFAULT_MOVE) ")\n" " -a , --snapshot-rate <int>\n" " Percentage of snapshot transactions (default=" XSTR(DEFAULT_SNAPSHOT) ")\n" " -l , --load-factor <int>\n" " Ratio of keys over buckets (default=" XSTR(DEFAULT_LOAD) ")\n" " -x, --elasticity (default=4)\n" " Use elastic transactions\n" " 0 = non-protected,\n" " 1 = normal transaction,\n" " 2 = read elastic-tx,\n" " 3 = read/add elastic-tx,\n" " 4 = read/add/rem elastic-tx,\n" " 5 = elastic-tx w/ optimized move.\n" ); exit(0); case 'A': alternate = 1; break; case 'f': effective = atoi(optarg); break; case 'd': duration = atoi(optarg); break; case 'i': initial = atoi(optarg); break; case 'n': nb_threads = atoi(optarg); break; case 'r': range = atol(optarg); break; case 's': seed = atoi(optarg); break; case 'u': update = atoi(optarg); break; case 'm': move = atoi(optarg); break; case 'a': snapshot = atoi(optarg); break; case 'l': load_factor = atoi(optarg); break; case 'x': unit_tx = atoi(optarg); break; case '?': printf("Use -h or --help for help\n"); exit(0); default: exit(1); } } assert(duration >= 0); assert(initial >= 0); assert(nb_threads > 0); assert(range > 0 && range >= initial); assert(update >= 0 && update <= 100); assert(move >= 0 && move <= update); assert(snapshot >= 0 && snapshot <= (100-update)); assert(initial < MAXHTLENGTH); assert(initial >= load_factor); printf("Set type : hash table\n"); printf("Duration : %d\n", duration); printf("Initial size : %d\n", initial); printf("Nb threads : %d\n", nb_threads); printf("Value range : %ld\n", range); printf("Seed : %d\n", seed); printf("Update rate : %d\n", update); printf("Load factor : %d\n", load_factor); printf("Move rate : %d\n", move); printf("Snapshot rate: %d\n", snapshot); printf("Elasticity : %d\n", unit_tx); printf("Alternate : %d\n", alternate); printf("Effective : %d\n", effective); printf("Type sizes : int=%d/long=%d/ptr=%d/word=%d\n", (int)sizeof(int), (int)sizeof(long), (int)sizeof(void *), (int)sizeof(uintptr_t)); timeout.tv_sec = duration / 1000; timeout.tv_nsec = (duration % 1000) * 1000000; if ((data = (thread_data_t *)malloc(nb_threads * sizeof(thread_data_t))) == NULL) { perror("malloc"); exit(1); } if ((threads = (pthread_t *)malloc(nb_threads * sizeof(pthread_t))) == NULL) { perror("malloc"); exit(1); } if (seed == 0) srand((int)time(0)); else srand(seed); //maxhtlength = (unsigned int) initial / load_factor; set = ht_new(); stop = 0; // Init STM printf("Initializing STM\n"); TM_STARTUP(); // Populate set printf("Adding %d entries to set\n", initial); i = 0; maxhtlength = (int) (initial / load_factor); while (i < initial) { val = rand_range(range); if (ht_add(set, val, 0)) { last = val; i++; } } size = ht_size(set); printf("Set size : %d\n", size); printf("Bucket amount: %d\n", maxhtlength); printf("Load : %d\n", load_factor); // Access set from all threads barrier_init(&barrier, nb_threads + 1); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for (i = 0; i < nb_threads; i++) { printf("Creating thread %d\n", i); data[i].first = last; data[i].range = range; data[i].update = update; data[i].load_factor = load_factor; data[i].move = move; data[i].snapshot = snapshot; data[i].unit_tx = unit_tx; data[i].alternate = alternate; data[i].effective = effective; data[i].nb_add = 0; data[i].nb_added = 0; data[i].nb_remove = 0; data[i].nb_removed = 0; data[i].nb_move = 0; data[i].nb_moved = 0; data[i].nb_snapshot = 0; data[i].nb_snapshoted = 0; data[i].nb_contains = 0; data[i].nb_found = 0; data[i].nb_aborts = 0; data[i].nb_aborts_locked_read = 0; data[i].nb_aborts_locked_write = 0; data[i].nb_aborts_validate_read = 0; data[i].nb_aborts_validate_write = 0; data[i].nb_aborts_validate_commit = 0; data[i].nb_aborts_invalid_memory = 0; data[i].nb_aborts_double_write = 0; data[i].max_retries = 0; data[i].seed = rand(); data[i].set = set; data[i].barrier = &barrier; data[i].failures_because_contention = 0; if (pthread_create(&threads[i], &attr, test, (void *)(&data[i])) != 0) { fprintf(stderr, "Error creating thread\n"); exit(1); } } pthread_attr_destroy(&attr); // Start threads barrier_cross(&barrier); printf("STARTING...\n"); gettimeofday(&start, NULL); if (duration > 0) { nanosleep(&timeout, NULL); } else { sigemptyset(&block_set); sigsuspend(&block_set); } AO_store_full(&stop, 1); gettimeofday(&end, NULL); printf("STOPPING...\n"); // Wait for thread completion for (i = 0; i < nb_threads; i++) { if (pthread_join(threads[i], NULL) != 0) { fprintf(stderr, "Error waiting for thread completion\n"); exit(1); } } duration = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); aborts = 0; aborts_locked_read = 0; aborts_locked_write = 0; aborts_validate_read = 0; aborts_validate_write = 0; aborts_validate_commit = 0; aborts_invalid_memory = 0; aborts_double_write = 0; failures_because_contention = 0; reads = 0; effreads = 0; updates = 0; effupds = 0; moves = 0; snapshots = 0; max_retries = 0; for (i = 0; i < nb_threads; i++) { printf("Thread %d\n", i); printf(" #add : %lu\n", data[i].nb_add); printf(" #added : %lu\n", data[i].nb_added); printf(" #remove : %lu\n", data[i].nb_remove); printf(" #removed : %lu\n", data[i].nb_removed); printf(" #contains : %lu\n", data[i].nb_contains); printf(" #found : %lu\n", data[i].nb_found); printf(" #move : %lu\n", data[i].nb_move); printf(" #moved : %lu\n", data[i].nb_moved); printf(" #snapshot : %lu\n", data[i].nb_snapshot); printf(" #snapshoted : %lu\n", data[i].nb_snapshoted); printf(" #aborts : %lu\n", data[i].nb_aborts); printf(" #lock-r : %lu\n", data[i].nb_aborts_locked_read); printf(" #lock-w : %lu\n", data[i].nb_aborts_locked_write); printf(" #val-r : %lu\n", data[i].nb_aborts_validate_read); printf(" #val-w : %lu\n", data[i].nb_aborts_validate_write); printf(" #val-c : %lu\n", data[i].nb_aborts_validate_commit); printf(" #inv-mem : %lu\n", data[i].nb_aborts_invalid_memory); printf(" #dup-w : %lu\n", data[i].nb_aborts_double_write); printf(" #failures : %lu\n", data[i].failures_because_contention); printf(" Max retries : %lu\n", data[i].max_retries); aborts += data[i].nb_aborts; aborts_locked_read += data[i].nb_aborts_locked_read; aborts_locked_write += data[i].nb_aborts_locked_write; aborts_validate_read += data[i].nb_aborts_validate_read; aborts_validate_write += data[i].nb_aborts_validate_write; aborts_validate_commit += data[i].nb_aborts_validate_commit; aborts_invalid_memory += data[i].nb_aborts_invalid_memory; aborts_double_write += data[i].nb_aborts_double_write; failures_because_contention += data[i].failures_because_contention; reads += (data[i].nb_contains + data[i].nb_snapshot); effreads += data[i].nb_contains + (data[i].nb_add - data[i].nb_added) + (data[i].nb_remove - data[i].nb_removed) + (data[i].nb_move - data[i].nb_moved) + data[i].nb_snapshoted; updates += (data[i].nb_add + data[i].nb_remove + data[i].nb_move); effupds += data[i].nb_removed + data[i].nb_added + data[i].nb_moved; moves += data[i].nb_move; snapshots += data[i].nb_snapshot; size += data[i].nb_added - data[i].nb_removed; if (max_retries < data[i].max_retries) max_retries = data[i].max_retries; } printf("Set size : %d (expected: %d)\n", ht_size(set), size); printf("Duration : %d (ms)\n", duration); printf("#txs : %lu (%f / s)\n", reads + updates + moves + snapshots, (reads + updates + moves + snapshots) * 1000.0 / duration); printf("#read txs : "); if (effective) { printf("%lu (%f / s)\n", effreads, effreads * 1000.0 / duration); printf(" #cont/snpsht: %lu (%f / s)\n", reads, reads * 1000.0 / duration); } else printf("%lu (%f / s)\n", reads, reads * 1000.0 / duration); printf("#eff. upd rate: %f \n", 100.0 * effupds / (effupds + effreads)); printf("#update txs : "); if (effective) { printf("%lu (%f / s)\n", effupds, effupds * 1000.0 / duration); printf(" #upd trials : %lu (%f / s)\n", updates, updates * 1000.0 / duration); } else printf("%lu (%f / s)\n", updates, updates * 1000.0 / duration); printf("#move txs : %lu (%f / s)\n", moves, moves * 1000.0 / duration); printf("#snapshot txs : %lu (%f / s)\n", snapshots, snapshots * 1000.0 / duration); printf("#aborts : %lu (%f / s)\n", aborts, aborts * 1000.0 / duration); printf(" #lock-r : %lu (%f / s)\n", aborts_locked_read, aborts_locked_read * 1000.0 / duration); printf(" #lock-w : %lu (%f / s)\n", aborts_locked_write, aborts_locked_write * 1000.0 / duration); printf(" #val-r : %lu (%f / s)\n", aborts_validate_read, aborts_validate_read * 1000.0 / duration); printf(" #val-w : %lu (%f / s)\n", aborts_validate_write, aborts_validate_write * 1000.0 / duration); printf(" #val-c : %lu (%f / s)\n", aborts_validate_commit, aborts_validate_commit * 1000.0 / duration); printf(" #inv-mem : %lu (%f / s)\n", aborts_invalid_memory, aborts_invalid_memory * 1000.0 / duration); printf(" #dup-w : %lu (%f / s)\n", aborts_double_write, aborts_double_write * 1000.0 / duration); printf(" #failures : %lu\n", failures_because_contention); printf("Max retries : %lu\n", max_retries); // Delete set ht_delete(set); // Cleanup STM TM_SHUTDOWN(); free(threads); free(data); return 0; }
int main(int argc, char **argv) { struct option long_options[] = { // These options don't set a flag {"help", no_argument, NULL, 'h'}, {"duration", required_argument, NULL, 'd'}, {"initial-size", required_argument, NULL, 'i'}, {"thread-num", required_argument, NULL, 't'}, {"range", required_argument, NULL, 'r'}, {"seed", required_argument, NULL, 'S'}, {"update-rate", required_argument, NULL, 'u'}, {"elasticity", required_argument, NULL, 'x'}, {NULL, 0, NULL, 0} }; avl_intset_t *set; int i, j, c, size, tree_size; val_t last = 0; val_t val = 0; unsigned long reads, effreads, updates, effupds, aborts, aborts_locked_read, aborts_locked_write, aborts_validate_read, aborts_validate_write, aborts_validate_commit, aborts_invalid_memory, aborts_double_write, max_retries, failures_because_contention; thread_data_t *data; maintenance_thread_data_t *maintenance_data; pthread_t *threads; pthread_t *maintenance_threads; pthread_attr_t attr; barrier_t barrier; struct timeval start, end; struct timespec timeout; int duration = DEFAULT_DURATION; int initial = DEFAULT_INITIAL; int nb_threads = DEFAULT_NB_THREADS; int nb_maintenance_threads = DEFAULT_NB_MAINTENANCE_THREADS; long range = DEFAULT_RANGE; int seed = DEFAULT_SEED; int update = DEFAULT_UPDATE; int unit_tx = DEFAULT_ELASTICITY; int alternate = DEFAULT_ALTERNATE; int effective = DEFAULT_EFFECTIVE; sigset_t block_set; while(1) { i = 0; c = getopt_long(argc, argv, "hAf:d:i:t:r:S:u:x:" , long_options, &i); if(c == -1) break; if(c == 0 && long_options[i].flag == 0) c = long_options[i].val; switch(c) { case 0: break; case 'h': printf("intset -- STM stress test " "(avltree)\n" "\n" "Usage:\n" " intset [options...]\n" "\n" "Options:\n" " -h, --help\n" " Print this message\n" " -A, --Alternate\n" " Consecutive insert/remove target the same value\n" " -f, --effective <int>\n" " update txs must effectively write (0=trial, 1=effective, default=" XSTR(DEFAULT_EFFECTIVE) ")\n" " -d, --duration <int>\n" " Test duration in milliseconds (0=infinite, default=" XSTR(DEFAULT_DURATION) ")\n" " -i, --initial-size <int>\n" " Number of elements to insert before test (default=" XSTR(DEFAULT_INITIAL) ")\n" " -t, --thread-num <int>\n" " Number of threads (default=" XSTR(DEFAULT_NB_THREADS) ")\n" " -r, --range <int>\n" " Range of integer values inserted in set (default=" XSTR(DEFAULT_RANGE) ")\n" " -S, --seed <int>\n" " RNG seed (0=time-based, default=" XSTR(DEFAULT_SEED) ")\n" " -u, --update-rate <int>\n" " Percentage of update transactions (default=" XSTR(DEFAULT_UPDATE) ")\n" " -x, --elasticity (default=4)\n" " Use elastic transactions\n" " 0 = non-protected,\n" " 1 = normal transaction,\n" " 2 = read elastic-tx,\n" " 3 = read/add elastic-tx,\n" " 4 = read/add/rem elastic-tx,\n" " 5 = fraser lock-free\n" ); exit(0); case 'A': alternate = 1; break; case 'f': effective = atoi(optarg); break; case 'd': duration = atoi(optarg); break; case 'i': initial = atoi(optarg); break; case 't': nb_threads = atoi(optarg); break; case 'r': range = atol(optarg); break; case 'S': seed = atoi(optarg); break; case 'u': update = atoi(optarg); break; case 'x': unit_tx = atoi(optarg); break; case '?': printf("Use -h or --help for help\n"); exit(0); default: exit(1); } } assert(duration >= 0); assert(initial >= 0); assert(nb_threads > 0); assert(range > 0 && range >= initial); assert(update >= 0 && update <= 100); printf("Set type : avltree\n"); printf("Duration : %d\n", duration); printf("Initial size : %u\n", initial); printf("Nb threads : %d\n", nb_threads); printf("Nb mt threads: %d\n", nb_maintenance_threads); printf("Value range : %ld\n", range); printf("Seed : %d\n", seed); printf("Update rate : %d\n", update); printf("Elasticity : %d\n", unit_tx); printf("Alternate : %d\n", alternate); printf("Efffective : %d\n", effective); printf("Type sizes : int=%d/long=%d/ptr=%d/word=%d\n", (int)sizeof(int), (int)sizeof(long), (int)sizeof(void *), (int)sizeof(uintptr_t)); timeout.tv_sec = duration / 1000; timeout.tv_nsec = (duration % 1000) * 1000000; if ((data = (thread_data_t *)malloc(nb_threads * sizeof(thread_data_t))) == NULL) { perror("malloc"); exit(1); } if ((threads = (pthread_t *)malloc(nb_threads * sizeof(pthread_t))) == NULL) { perror("malloc"); exit(1); } if ((maintenance_data = (maintenance_thread_data_t *)malloc(nb_maintenance_threads * sizeof(maintenance_thread_data_t))) == NULL) { perror("malloc"); exit(1); } if ((maintenance_threads = (pthread_t *)malloc(nb_maintenance_threads * sizeof(pthread_t))) == NULL) { perror("malloc"); exit(1); } if (seed == 0) srand((int)time(0)); else srand(seed); //levelmax = floor_log_2((unsigned int) initial); //set = avl_set_new(); set = avl_set_new_alloc(0, nb_threads); //set->stop = &stop; //#endif stop = 0; global_seed = rand(); #ifdef TLS rng_seed = &global_seed; #else /* ! TLS */ if (pthread_key_create(&rng_seed_key, NULL) != 0) { fprintf(stderr, "Error creating thread local\n"); exit(1); } pthread_setspecific(rng_seed_key, &global_seed); #endif /* ! TLS */ // Init STM printf("Initializing STM\n"); TM_STARTUP(); // Populate set printf("Adding %d entries to set\n", initial); i = 0; while (i < initial) { val = rand_range_re(&global_seed, range); //printf("Adding %d\n", val); if (avl_add(set, val, 0, 0) > 0) { //printf("Added %d\n", val); //print_avltree(set); last = val; i++; } } size = avl_set_size(set); tree_size = avl_tree_size(set); printf("Set size : %d\n", size); printf("Tree size : %d\n", tree_size); //printf("Level max : %d\n", levelmax); // Access set from all threads barrier_init(&barrier, nb_threads + nb_maintenance_threads + 1); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for (i = 0; i < nb_threads; i++) { printf("Creating thread %d\n", i); data[i].id = i; data[i].first = last; data[i].range = range; data[i].update = update; data[i].unit_tx = unit_tx; data[i].alternate = alternate; data[i].effective = effective; data[i].nb_modifications = 0; data[i].nb_add = 0; data[i].nb_added = 0; data[i].nb_remove = 0; data[i].nb_removed = 0; data[i].nb_contains = 0; data[i].nb_found = 0; data[i].nb_aborts = 0; data[i].nb_aborts_locked_read = 0; data[i].nb_aborts_locked_write = 0; data[i].nb_aborts_validate_read = 0; data[i].nb_aborts_validate_write = 0; data[i].nb_aborts_validate_commit = 0; data[i].nb_aborts_invalid_memory = 0; data[i].nb_aborts_double_write = 0; data[i].max_retries = 0; data[i].seed = rand(); data[i].set = set; data[i].barrier = &barrier; data[i].failures_because_contention = 0; if (pthread_create(&threads[i], &attr, test, (void *)(&data[i])) != 0) { fprintf(stderr, "Error creating thread\n"); exit(1); } } for (i = 0; i < nb_maintenance_threads; i++) { maintenance_data[i].nb_maint = nb_maintenance_threads; maintenance_data[i].id = i; maintenance_data[i].nb_removed = 0; maintenance_data[i].nb_rotated = 0; maintenance_data[i].nb_suc_rotated = 0; maintenance_data[i].nb_propagated = 0; maintenance_data[i].nb_suc_propagated = 0; maintenance_data[i].nb_aborts = 0; maintenance_data[i].nb_aborts_locked_read = 0; maintenance_data[i].nb_aborts_locked_write = 0; maintenance_data[i].nb_aborts_validate_read = 0; maintenance_data[i].nb_aborts_validate_write = 0; maintenance_data[i].nb_aborts_validate_commit = 0; maintenance_data[i].nb_aborts_invalid_memory = 0; maintenance_data[i].nb_aborts_double_write = 0; maintenance_data[i].max_retries = 0; maintenance_data[i].t_data = data; maintenance_data[i].nb_threads = nb_threads; maintenance_data[i].set = set; maintenance_data[i].barrier = &barrier; if ((maintenance_data[i].t_nb_trans = (unsigned long *)malloc(nb_threads * sizeof(unsigned long))) == NULL) { perror("malloc"); exit(1); } for(j = 0; j < nb_threads; j++) { maintenance_data[i].t_nb_trans[j] = 0; } if ((maintenance_data[i].t_nb_trans_old = (unsigned long *)malloc(nb_threads * sizeof(unsigned long))) == NULL) { perror("malloc"); exit(1); } for(j = 0; j < nb_threads; j++) { maintenance_data[i].t_nb_trans_old[j] = 0; } printf("Creating maintenance thread %d\n", i); if (pthread_create(&maintenance_threads[i], &attr, test_maintenance, (void *)(&maintenance_data[i])) != 0) { fprintf(stderr, "Error creating thread\n"); exit(1); } } pthread_attr_destroy(&attr); // Catch some signals if (signal(SIGHUP, catcher) == SIG_ERR || //signal(SIGINT, catcher) == SIG_ERR || signal(SIGTERM, catcher) == SIG_ERR) { perror("signal"); exit(1); } // Start threads barrier_cross(&barrier); printf("STARTING...\n"); gettimeofday(&start, NULL); if (duration > 0) { nanosleep(&timeout, NULL); } else { sigemptyset(&block_set); sigsuspend(&block_set); } #ifdef ICC stop = 1; #else AO_store_full(&stop, 1); #endif /* ICC */ gettimeofday(&end, NULL); printf("STOPPING...\n"); // Wait for thread completion for (i = 0; i < nb_threads; i++) { if (pthread_join(threads[i], NULL) != 0) { fprintf(stderr, "Error waiting for thread completion\n"); exit(1); } } // Wait for maintenance thread completion for (i = 0; i < nb_maintenance_threads; i++) { if (pthread_join(maintenance_threads[i], NULL) != 0) { fprintf(stderr, "Error waiting for maintenance thread completion\n"); exit(1); } } duration = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); aborts = 0; aborts_locked_read = 0; aborts_locked_write = 0; aborts_validate_read = 0; aborts_validate_write = 0; aborts_validate_commit = 0; aborts_invalid_memory = 0; aborts_double_write = 0; failures_because_contention = 0; reads = 0; effreads = 0; updates = 0; effupds = 0; max_retries = 0; for (i = 0; i < nb_threads; i++) { printf("Thread %d\n", i); printf(" #add : %lu\n", data[i].nb_add); printf(" #added : %lu\n", data[i].nb_added); printf(" #remove : %lu\n", data[i].nb_remove); printf(" #removed : %lu\n", data[i].nb_removed); printf(" #contains : %lu\n", data[i].nb_contains); printf(" #found : %lu\n", data[i].nb_found); printf(" #aborts : %lu\n", data[i].nb_aborts); printf(" #lock-r : %lu\n", data[i].nb_aborts_locked_read); printf(" #lock-w : %lu\n", data[i].nb_aborts_locked_write); printf(" #val-r : %lu\n", data[i].nb_aborts_validate_read); printf(" #val-w : %lu\n", data[i].nb_aborts_validate_write); printf(" #val-c : %lu\n", data[i].nb_aborts_validate_commit); printf(" #inv-mem : %lu\n", data[i].nb_aborts_invalid_memory); printf(" #dup-w : %lu\n", data[i].nb_aborts_double_write); printf(" #failures : %lu\n", data[i].failures_because_contention); printf(" Max retries : %lu\n", data[i].max_retries); printf(" #set read trans reads: %lu\n", data[i].set_read_reads); printf(" #set write trans reads: %lu\n", data[i].set_write_reads); printf(" #set write trans writes: %lu\n", data[i].set_write_writes); printf(" #set trans reads: %lu\n", data[i].set_reads); printf(" #set trans writes: %lu\n", data[i].set_writes); printf(" set max reads: %lu\n", data[i].set_max_reads); printf(" set max writes: %lu\n", data[i].set_max_writes); printf(" #read trans reads: %lu\n", data[i].read_reads); printf(" #write trans reads: %lu\n", data[i].write_reads); printf(" #write trans writes: %lu\n", data[i].write_writes); printf(" #trans reads: %lu\n", data[i].reads); printf(" #trans writes: %lu\n", data[i].writes); printf(" max reads: %lu\n", data[i].max_reads); printf(" max writes: %lu\n", data[i].max_writes); aborts += data[i].nb_aborts; aborts_locked_read += data[i].nb_aborts_locked_read; aborts_locked_write += data[i].nb_aborts_locked_write; aborts_validate_read += data[i].nb_aborts_validate_read; aborts_validate_write += data[i].nb_aborts_validate_write; aborts_validate_commit += data[i].nb_aborts_validate_commit; aborts_invalid_memory += data[i].nb_aborts_invalid_memory; aborts_double_write += data[i].nb_aborts_double_write; failures_because_contention += data[i].failures_because_contention; reads += data[i].nb_contains; effreads += data[i].nb_contains + (data[i].nb_add - data[i].nb_added) + (data[i].nb_remove - data[i].nb_removed); updates += (data[i].nb_add + data[i].nb_remove); effupds += data[i].nb_removed + data[i].nb_added; size += data[i].nb_added - data[i].nb_removed; if (max_retries < data[i].max_retries) max_retries = data[i].max_retries; } for (i = 0; i < nb_maintenance_threads; i++) { printf("Maintenance thread %d\n", i); printf(" #removed %lu\n", set->nb_removed); printf(" #rotated %lu\n", set->nb_rotated); printf(" #rotated sucs %lu\n", set->nb_suc_rotated); printf(" #propogated %lu\n", set->nb_propogated); printf(" #propogated sucs %lu\n", set->nb_suc_propogated); printf(" #aborts : %lu\n", maintenance_data[i].nb_aborts); printf(" #lock-r : %lu\n", maintenance_data[i].nb_aborts_locked_read); printf(" #lock-w : %lu\n", maintenance_data[i].nb_aborts_locked_write); printf(" #val-r : %lu\n", maintenance_data[i].nb_aborts_validate_read); printf(" #val-w : %lu\n", maintenance_data[i].nb_aborts_validate_write); printf(" #val-c : %lu\n", maintenance_data[i].nb_aborts_validate_commit); printf(" #inv-mem : %lu\n", maintenance_data[i].nb_aborts_invalid_memory); printf(" #dup-w : %lu\n", maintenance_data[i].nb_aborts_double_write); //printf(" #failures : %lu\n", maintenance_data[i].failures_because_contention); printf(" Max retries : %lu\n", maintenance_data[i].max_retries); } printf("Set size : %d (expected: %d)\n", avl_set_size(set), size); printf("Tree size : %d\n", avl_tree_size(set)); printf("Duration : %d (ms)\n", duration); printf("#txs : %lu (%f / s)\n", reads + updates, (reads + updates) * 1000.0 / duration); printf("#read txs : "); if (effective) { printf("%lu (%f / s)\n", effreads, effreads * 1000.0 / duration); printf(" #contains : %lu (%f / s)\n", reads, reads * 1000.0 / duration); } else printf("%lu (%f / s)\n", reads, reads * 1000.0 / duration); printf("#eff. upd rate: %f \n", 100.0 * effupds / (effupds + effreads)); printf("#update txs : "); if (effective) { printf("%lu (%f / s)\n", effupds, effupds * 1000.0 / duration); printf(" #upd trials : %lu (%f / s)\n", updates, updates * 1000.0 / duration); } else printf("%lu (%f / s)\n", updates, updates * 1000.0 / duration); printf("#aborts : %lu (%f / s)\n", aborts, aborts * 1000.0 / duration); printf(" #lock-r : %lu (%f / s)\n", aborts_locked_read, aborts_locked_read * 1000.0 / duration); printf(" #lock-w : %lu (%f / s)\n", aborts_locked_write, aborts_locked_write * 1000.0 / duration); printf(" #val-r : %lu (%f / s)\n", aborts_validate_read, aborts_validate_read * 1000.0 / duration); printf(" #val-w : %lu (%f / s)\n", aborts_validate_write, aborts_validate_write * 1000.0 / duration); printf(" #val-c : %lu (%f / s)\n", aborts_validate_commit, aborts_validate_commit * 1000.0 / duration); printf(" #inv-mem : %lu (%f / s)\n", aborts_invalid_memory, aborts_invalid_memory * 1000.0 / duration); printf(" #dup-w : %lu (%f / s)\n", aborts_double_write, aborts_double_write * 1000.0 / duration); printf(" #failures : %lu\n", failures_because_contention); printf("Max retries : %lu\n", max_retries); //print_avltree(set); // Delete set avl_set_delete(set); // Cleanup STM TM_SHUTDOWN(); #ifndef TLS pthread_key_delete(rng_seed_key); #endif /* ! TLS */ free(threads); free(data); free(maintenance_threads); free(maintenance_data); return 0; }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { char exitmsg[1024]; GOTO_REAL(); load_syncchar_map("sync_char.map.yada"); /* * Initialization */ parseArgs(argc, (char** const)argv); sprintf(exitmsg, "END BENCHMARK %s-parallel-phase\n", argv[0]); SIM_GET_NUM_CPU(global_numThread); TM_STARTUP(global_numThread); P_MEMORY_STARTUP(global_numThread); thread_startup(global_numThread); global_meshPtr = mesh_alloc(); assert(global_meshPtr); printf("Angle constraint = %lf\n", global_angleConstraint); printf("Reading input... "); long initNumElement = mesh_read(global_meshPtr, global_inputPrefix); puts("done."); global_workHeapPtr = heap_alloc(1, &element_heapCompare); assert(global_workHeapPtr); long initNumBadElement = initializeWork(global_workHeapPtr, global_meshPtr); printf("Initial number of mesh elements = %li\n", initNumElement); printf("Initial number of bad elements = %li\n", initNumBadElement); printf("Starting triangulation..."); fflush(stdout); /* * Run benchmark */ TIMER_T start; TIMER_READ(start); OSA_PRINT("entering parallel phase\n",0); START_INSTRUMENTATION(); GOTO_SIM(); #ifdef OTM #pragma omp parallel { process(); } #else thread_start(process, NULL); #endif GOTO_REAL(); OSA_PRINT("exiting parallel phase\n",0); OSA_PRINT(exitmsg,0); STOP_INSTRUMENTATION(); TIMER_T stop; TIMER_READ(stop) puts(" done."); printf("Elapsed time = %0.3lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); /* * Check solution */ long finalNumElement = initNumElement + global_totalNumAdded; printf("Final mesh size = %li\n", finalNumElement); printf("Number of elements processed = %li\n", global_numProcess); fflush(stdout); #if 0 bool_t isSuccess = mesh_check(global_meshPtr, finalNumElement); #else bool_t isSuccess = TRUE; #endif printf("Final mesh is %s\n", (isSuccess ? "valid." : "INVALID!")); fflush(stdout); assert(isSuccess); /* * TODO: deallocate mesh and work heap */ TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { int i; //FILE * wfile; # ifdef SIMULATOR printf("SIMULATOR is defined\n"); # else printf("SIMULATOR is not defined\n"); # endif /* !SIMULATOR */ #if defined(STM) printf("STM is defined\n"); # else printf("STM is not defined\n"); # endif /* !SIMULATOR */ GOTO_REAL(); /* * Initialization */ if(argc !=3) printf("needs two input arguments, \"max_count, num_threads\",argc=%d\n\n", argc); max_count = atoi(argv[1]); long numThread = atoi(argv[2]); if(numThread > MAX_NUM_OF_THREADS) printf("num_threads can be at most %d\n\n", MAX_NUM_OF_THREADS); //else //printf("numThread = %d\n\n", (int)numThread); for(i=0; i<MAX_NUM_OF_THREADS; i++) threads_arg[i]=i; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); /* * Run transactions */ //router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr}; TIMER_T startTime; TIMER_READ(startTime); GOTO_SIM(); thread_start(func_count, (void*)threads_arg); GOTO_REAL(); TIMER_T stopTime; TIMER_READ(stopTime); //printf("Elapsed time = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution and clean up */ TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); //wfile = fopen ("exe_time.txt","a"); //fprintf(wfile, "Elapsed time = %f, Aborts/starts=%f, Aborts=%f, starts=%f\n", TIMER_DIFF_SECONDS(startTime, stopTime), (float)((float)(AbortTally*100)/((float)StartTally)), (float)AbortTally, (float)StartTally); //fclose(wfile); //printf("final value of counter=%d\n\n", my_counter); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; long numVar = global_params[PARAM_VAR]; long numRecord = global_params[PARAM_RECORD]; long randomSeed = global_params[PARAM_SEED]; long maxNumParent = global_params[PARAM_NUMBER]; long percentParent = global_params[PARAM_PERCENT]; global_insertPenalty = global_params[PARAM_INSERT]; global_maxNumEdgeLearned = global_params[PARAM_EDGE]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); printf("Random seed = %li\n", randomSeed); printf("Number of vars = %li\n", numVar); printf("Number of records = %li\n", numRecord); printf("Max num parents = %li\n", maxNumParent); printf("%% chance of parent = %li\n", percentParent); printf("Insert penalty = %li\n", global_insertPenalty); printf("Max num edge learned / var = %li\n", global_maxNumEdgeLearned); printf("Operation quality factor = %f\n", global_operationQualityFactor); fflush(stdout); /* * Generate data */ printf("Generating data... "); fflush(stdout); random_t* randomPtr = random_alloc(); assert(randomPtr); random_seed(randomPtr, randomSeed); data_t* dataPtr = data_alloc(numVar, numRecord, randomPtr); assert(dataPtr); net_t* netPtr = data_generate(dataPtr, -1, maxNumParent, percentParent); puts("done."); fflush(stdout); /* * Generate adtree */ adtree_t* adtreePtr = adtree_alloc(); assert(adtreePtr); printf("Generating adtree... "); fflush(stdout); TIMER_T adtreeStartTime; TIMER_READ(adtreeStartTime); adtree_make(adtreePtr, dataPtr); TIMER_T adtreeStopTime; TIMER_READ(adtreeStopTime); puts("done."); fflush(stdout); printf("Adtree time = %f\n", TIMER_DIFF_SECONDS(adtreeStartTime, adtreeStopTime)); fflush(stdout); /* * Score original network */ float actualScore = score(netPtr, adtreePtr); net_free(netPtr); /* * Learn structure of Bayesian network */ learner_t* learnerPtr = learner_alloc(dataPtr, adtreePtr, numThread); assert(learnerPtr); data_free(dataPtr); /* save memory */ printf("Learning structure..."); fflush(stdout); TIMER_T learnStartTime; TIMER_READ(learnStartTime); GOTO_SIM(); learner_run(learnerPtr); GOTO_REAL(); TIMER_T learnStopTime; TIMER_READ(learnStopTime); puts("done."); fflush(stdout); printf("Time = %f\n", TIMER_DIFF_SECONDS(learnStartTime, learnStopTime)); fflush(stdout); /* * Check solution */ bool_t status = net_isCycle(learnerPtr->netPtr); assert(!status); #ifndef SIMULATOR float learnScore = learner_score(learnerPtr); printf("Learn score = %f\n", learnScore); #endif printf("Actual score = %f\n", actualScore); /* * Clean up */ fflush(stdout); random_free(randomPtr); #ifndef SIMULATOR adtree_free(adtreePtr); # if 0 learner_free(learnerPtr); # endif #endif TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
MAIN(argc, argv) { GOTO_REAL(); SETUP_NUMBER_TASKS(10); /* * Tuple for Scalable Data Generation * stores startVertex, endVertex, long weight and other info */ graphSDG* SDGdata; /* * The graph data structure for this benchmark - see defs.h */ graph* G; #ifdef ENABLE_KERNEL2 /* * Kernel 2 */ edge* maxIntWtList; edge* soughtStrWtList; long maxIntWtListSize; long soughtStrWtListSize; #endif /* ENABLE_KERNEL2 */ #ifdef ENABLE_KERNEL3 # ifndef ENABLE_KERNEL2 # error KERNEL3 requires KERNEL2 # endif /* * Kernel 3 */ V* intWtVList = NULL; V* strWtVList = NULL; Vl** intWtVLList = NULL; Vl** strWtVLList = NULL; Vd* intWtVDList = NULL; Vd* strWtVDList = NULL; #endif /* ENABLE_KERNEL3 */ double totalTime = 0.0; /* ------------------------------------------------------------------------- * Preamble * ------------------------------------------------------------------------- */ /* * User Interface: Configurable parameters, and global program control */ getUserParameters(argc, (char** const) argv); SIM_GET_NUM_CPU(THREADS); TM_STARTUP(THREADS, 0); P_MEMORY_STARTUP(THREADS); SETUP_NUMBER_THREADS(THREADS); thread_startup(THREADS); double time_total = 0.0; int repeat = REPEATS; for (; repeat > 0; --repeat) { SDGdata = (graphSDG*)malloc(sizeof(graphSDG)); assert(SDGdata); genScalData_seq(SDGdata); G = (graph*)malloc(sizeof(graph)); assert(G); computeGraph_arg_t computeGraphArgs; computeGraphArgs.GPtr = G; computeGraphArgs.SDGdataPtr = SDGdata; TIMER_T start; TIMER_READ(start); GOTO_SIM(); thread_start(computeGraph, (void*)&computeGraphArgs); GOTO_REAL(); TIMER_T stop; TIMER_READ(stop); double time_tmp = TIMER_DIFF_SECONDS(start, stop); PRINT_STATS(); time_total += time_tmp; } totalTime += time_total; #ifdef ENABLE_KERNEL2 /* ------------------------------------------------------------------------- * Kernel 2 - Find Max weight and sought string * ------------------------------------------------------------------------- */ printf("\nKernel 2 - getStartLists() beginning execution...\n"); maxIntWtListSize = 0; soughtStrWtListSize = 0; maxIntWtList = (edge*)malloc(sizeof(edge)); assert(maxIntWtList); soughtStrWtList = (edge*)malloc(sizeof(edge)); assert(soughtStrWtList); getStartLists_arg_t getStartListsArg; getStartListsArg.GPtr = G; getStartListsArg.maxIntWtListPtr = &maxIntWtList; getStartListsArg.maxIntWtListSize = &maxIntWtListSize; getStartListsArg.soughtStrWtListPtr = &soughtStrWtList; getStartListsArg.soughtStrWtListSize = &soughtStrWtListSize; TIMER_READ(start); GOTO_SIM(); #ifdef OTM #pragma omp parallel { getStartLists((void*)&getStartListsArg); } #else thread_start(getStartLists, (void*)&getStartListsArg); #endif GOTO_REAL(); TIMER_T stop; TIMER_READ(stop); time = TIMER_DIFF_SECONDS(start, stop); totalTime += time; printf("\n\tgetStartLists() completed execution.\n"); printf("\nTime taken for kernel 2 is %9.6f sec.\n\n", time); #endif /* ENABLE_KERNEL2 */ #ifdef ENABLE_KERNEL3 /* ------------------------------------------------------------------------- * Kernel 3 - Graph Extraction * ------------------------------------------------------------------------- */ printf("\nKernel 3 - findSubGraphs() beginning execution...\n"); if (K3_DS == 0) { intWtVList = (V*)malloc(G->numVertices * maxIntWtListSize * sizeof(V)); assert(intWtVList); strWtVList = (V*)malloc(G->numVertices * soughtStrWtListSize * sizeof(V)); assert(strWtVList); findSubGraphs0_arg_t findSubGraphs0Arg; findSubGraphs0Arg.GPtr = G; findSubGraphs0Arg.intWtVList = intWtVList; findSubGraphs0Arg.strWtVList = strWtVList; findSubGraphs0Arg.maxIntWtList = maxIntWtList; findSubGraphs0Arg.maxIntWtListSize = maxIntWtListSize; findSubGraphs0Arg.soughtStrWtList = soughtStrWtList; findSubGraphs0Arg.soughtStrWtListSize = soughtStrWtListSize; TIMER_READ(start); GOTO_SIM(); #ifdef OTM #pragma omp parallel { findSubGraphs0((void*)&findSubGraphs0Arg); } #else thread_start(findSubGraphs0, (void*)&findSubGraphs0Arg); #endif GOTO_REAL(); TIMER_READ(stop); } else if (K3_DS == 1) { intWtVLList = (Vl**)malloc(maxIntWtListSize * sizeof(Vl*)); assert(intWtVLList); strWtVLList = (Vl**)malloc(soughtStrWtListSize * sizeof(Vl*)); assert(strWtVLList); findSubGraphs1_arg_t findSubGraphs1Arg; findSubGraphs1Arg.GPtr = G; findSubGraphs1Arg.intWtVLList = intWtVLList; findSubGraphs1Arg.strWtVLList = strWtVLList; findSubGraphs1Arg.maxIntWtList = maxIntWtList; findSubGraphs1Arg.maxIntWtListSize = maxIntWtListSize; findSubGraphs1Arg.soughtStrWtList = soughtStrWtList; findSubGraphs1Arg.soughtStrWtListSize = soughtStrWtListSize; TIMER_READ(start); GOTO_SIM(); #ifdef OTM #pragma omp parallel { findSubGraphs1((void*)&findSubGraphs1Arg); } #else thread_start(findSubGraphs1, (void*)&findSubGraphs1Arg); #endif GOTO_REAL(); TIMER_READ(stop); /* Verification on_one_thread { for (i=0; i<maxIntWtListSize; i++) { printf("%ld -- ", i); currV = intWtVLList[i]; while (currV != NULL) { printf("[%ld %ld] ", currV->num, currV->depth); currV = currV->next; } printf("\n"); } for (i=0; i<soughtStrWtListSize; i++) { printf("%ld -- ", i); currV = strWtVLList[i]; while (currV != NULL) { printf("[%ld %ld] ", currV->num, currV->depth); currV = currV->next; } printf("\n"); } } */ } else if (K3_DS == 2) { intWtVDList = (Vd *) malloc(maxIntWtListSize * sizeof(Vd)); assert(intWtVDList); strWtVDList = (Vd *) malloc(soughtStrWtListSize * sizeof(Vd)); assert(strWtVDList); findSubGraphs2_arg_t findSubGraphs2Arg; findSubGraphs2Arg.GPtr = G; findSubGraphs2Arg.intWtVDList = intWtVDList; findSubGraphs2Arg.strWtVDList = strWtVDList; findSubGraphs2Arg.maxIntWtList = maxIntWtList; findSubGraphs2Arg.maxIntWtListSize = maxIntWtListSize; findSubGraphs2Arg.soughtStrWtList = soughtStrWtList; findSubGraphs2Arg.soughtStrWtListSize = soughtStrWtListSize; TIMER_READ(start); GOTO_SIM(); #ifdef OTM #pragma omp parallel { findSubGraphs2((void*)&findSubGraphs2Arg); } #else thread_start(findSubGraphs2, (void*)&findSubGraphs2Arg); #endif GOTO_REAL(); TIMER_READ(stop); /* Verification */ /* on_one_thread { printf("\nInt weight sub-graphs \n"); for (i=0; i<maxIntWtListSize; i++) { printf("%ld -- ", i); for (j=0; j<intWtVDList[i].numArrays; j++) { printf("\n [Array %ld] - \n", j); for (k=0; k<intWtVDList[i].arraySize[j]; k++) { printf("[%ld %ld] ", intWtVDList[i].vList[j][k].num, intWtVDList[i].vList[j][k].depth); } } printf("\n"); } printf("\nStr weight sub-graphs \n"); for (i=0; i<soughtStrWtListSize; i++) { printf("%ld -- ", i); for (j=0; j<strWtVDList[i].numArrays; j++) { printf("\n [Array %ld] - \n", j); for (k=0; k<strWtVDList[i].arraySize[j]; k++) { printf("[%ld %ld] ", strWtVDList[i].vList[j][k].num, strWtVDList[i].vList[j][k].depth); } } printf("\n"); } } */ } else { assert(0); } time = TIMER_DIFF_SECONDS(start, stop); totalTime += time; printf("\n\tfindSubGraphs() completed execution.\n"); printf("\nTime taken for kernel 3 is %9.6f sec.\n\n", time); #endif /* ENABLE_KERNEL3 */ #ifdef ENABLE_KERNEL4 /* ------------------------------------------------------------------------- * Kernel 4 - Graph Clustering * ------------------------------------------------------------------------- */ printf("\nKernel 4 - cutClusters() beginning execution...\n"); TIMER_READ(start); GOTO_SIM(); #ifdef OTM #pragma omp parallel { cutClusters((void*)G); } #else thread_start(cutClusters, (void*)G); #endif GOTO_REAL(); TIMER_READ(stop); time = TIMER_DIFF_SECONDS(start, stop); totalTime += time; printf("\n\tcutClusters() completed execution.\n"); printf("\nTime taken for Kernel 4 is %9.6f sec.\n\n", time); #endif /* ENABLE_KERNEL4 */ printf("Time = %9.6f \n", totalTime); /* ------------------------------------------------------------------------- * Cleanup * ------------------------------------------------------------------------- */ P_FREE(G->outDegree); P_FREE(G->outVertexIndex); P_FREE(G->outVertexList); P_FREE(G->paralEdgeIndex); P_FREE(G->inDegree); P_FREE(G->inVertexIndex); P_FREE(G->inVertexList); P_FREE(G->intWeight); P_FREE(G->strWeight); #ifdef ENABLE_KERNEL3 LONGINT_T i; LONGINT_T j; Vl* currV; Vl* tempV; if (K3_DS == 0) { P_FREE(strWtVList); P_FREE(intWtVList); } if (K3_DS == 1) { for (i = 0; i < maxIntWtListSize; i++) { currV = intWtVLList[i]; while (currV != NULL) { tempV = currV->next; P_FREE(currV); currV = tempV; } } for (i = 0; i < soughtStrWtListSize; i++) { currV = strWtVLList[i]; while (currV != NULL) { tempV = currV->next; P_FREE(currV); currV = tempV; } } P_FREE(strWtVLList); P_FREE(intWtVLList); } if (K3_DS == 2) { for (i = 0; i < maxIntWtListSize; i++) { for (j = 0; j < intWtVDList[i].numArrays; j++) { P_FREE(intWtVDList[i].vList[j]); } P_FREE(intWtVDList[i].vList); P_FREE(intWtVDList[i].arraySize); } for (i = 0; i < soughtStrWtListSize; i++) { for (j = 0; j < strWtVDList[i].numArrays; j++) { P_FREE(strWtVDList[i].vList[j]); } P_FREE(strWtVDList[i].vList); P_FREE(strWtVDList[i].arraySize); } P_FREE(strWtVDList); P_FREE(intWtVDList); } P_FREE(soughtStrWtList); P_FREE(maxIntWtList); #endif /* ENABLE_KERNEL2 */ P_FREE(SOUGHT_STRING); P_FREE(G); P_FREE(SDGdata); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN (argc,argv) { TIMER_T start; TIMER_T stop; /* Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_params[PARAM_THREAD]); printf("Creating gene and segments... "); fflush(stdout); long geneLength = global_params[PARAM_GENE]; long segmentLength = global_params[PARAM_SEGMENT]; long minNumSegment = global_params[PARAM_NUMBER]; long numThread = global_params[PARAM_THREAD]; random_t* randomPtr; gene_t* genePtr; char* gene; segments_t* segmentsPtr; sequencer_t* sequencerPtr; TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); TM_THREAD_ENTER(); // TM_BEGIN(); randomPtr= random_alloc(); assert(randomPtr != NULL); random_seed(randomPtr, 0); genePtr = gene_alloc(geneLength); assert( genePtr != NULL); gene_create(genePtr, randomPtr); gene = genePtr->contents; segmentsPtr = segments_alloc(segmentLength, minNumSegment); assert(segmentsPtr != NULL); segments_create(segmentsPtr, genePtr, randomPtr); sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr); assert(sequencerPtr != NULL); //TM_END(); thread_startup(numThread); puts("done."); printf("Gene length = %li\n", genePtr->length); printf("Segment length = %li\n", segmentsPtr->length); printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr)); fflush(stdout); /* Benchmark */ printf("Sequencing gene... "); fflush(stdout); // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using // wallclock time, we want to be sure we read time inside the // simulator, or else we report native cycles spent on the benchmark // instead of simulator cycles. GOTO_SIM(); TIMER_READ(start); #ifdef OTM #pragma omp parallel { sequencer_run(sequencerPtr); } #else thread_start(sequencer_run, (void*)sequencerPtr); #endif TIMER_READ(stop); // NB: As above, timer reads must be done inside of the simulated region // for PTLSim/ASF GOTO_REAL(); puts("done."); printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); /* Check result */ { char* sequence; int result; //TM_BEGIN(); sequence= sequencerPtr->sequence; result = strcmp(gene, sequence); //TM_END(); printf("Sequence matches gene: %s\n", (result ? "no" : "yes")); if (result) { printf("gene = %s\n", gene); printf("sequence = %s\n", sequence); } fflush(stdout); assert(strlen(sequence) >= strlen(gene)); } /* Clean up */ printf("Deallocating memory... "); fflush(stdout); sequencer_free(sequencerPtr); segments_free(segmentsPtr); gene_free(genePtr); random_free(randomPtr); puts("done."); fflush(stdout); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { /* * Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_numThread); TM_STARTUP(global_numThread); P_MEMORY_STARTUP(global_numThread); thread_startup(global_numThread); global_meshPtr = mesh_alloc(); assert(global_meshPtr); printf("Angle constraint = %lf\n", global_angleConstraint); printf("Reading input... "); long initNumElement = mesh_read(global_meshPtr, (char*)global_inputPrefix); puts("done."); global_workHeapPtr = heap_alloc(1, &yada_heapcompare); assert(global_workHeapPtr); long initNumBadElement = initializeWork(global_workHeapPtr, global_meshPtr); printf("Initial number of mesh elements = %li\n", initNumElement); printf("Initial number of bad elements = %li\n", initNumBadElement); printf("Starting triangulation..."); fflush(stdout); /* * Run benchmark */ // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using // wallclock time, we want to be sure we read time inside the // simulator, or else we report native cycles spent on the benchmark // instead of simulator cycles. GOTO_SIM(); TIMER_T start; TIMER_READ(start); #ifdef OTM #pragma omp parallel { process(); } #else thread_start((void(*)(void*))process, NULL); #endif TIMER_T stop; TIMER_READ(stop); // NB: As above, timer reads must be done inside of the simulated region // for PTLSim/ASF GOTO_REAL(); puts(" done."); printf("Elapsed time = %0.3lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); /* * Check solution */ long finalNumElement = initNumElement + global_totalNumAdded; printf("Final mesh size = %li\n", finalNumElement); printf("Number of elements processed = %li\n", global_numProcess); fflush(stdout); #if 1 bool isSuccess = mesh_check(global_meshPtr, finalNumElement); #else bool isSuccess = true; #endif printf("Final mesh is %s\n", (isSuccess ? "valid." : "INVALID!")); fflush(stdout); assert(isSuccess); /* * TODO: deallocate mesh and work heap */ TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); long percentAttack = global_params[PARAM_ATTACK]; long maxDataLength = global_params[PARAM_LENGTH]; long numFlow = global_params[PARAM_NUM]; long randomSeed = global_params[PARAM_SEED]; printf("Percent attack = %li\n", percentAttack); printf("Max data length = %li\n", maxDataLength); printf("Num flow = %li\n", numFlow); printf("Random seed = %li\n", randomSeed); dictionary_t* dictionaryPtr = dictionary_alloc(); assert(dictionaryPtr); stream_t* streamPtr = stream_alloc(percentAttack); assert(streamPtr); long numAttack = stream_generate(streamPtr, dictionaryPtr, numFlow, randomSeed, maxDataLength); printf("Num attack = %li\n", numAttack); decoder_t* decoderPtr = decoder_alloc(); assert(decoderPtr); vector_t** errorVectors = (vector_t**)malloc(numThread * sizeof(vector_t*)); assert(errorVectors); long i; for (i = 0; i < numThread; i++) { vector_t* errorVectorPtr = vector_alloc(numFlow); assert(errorVectorPtr); errorVectors[i] = errorVectorPtr; } arg_t arg; arg.streamPtr = streamPtr; arg.decoderPtr = decoderPtr; arg.errorVectors = errorVectors; /* * Run transactions */ TIMER_T startTime; TIMER_READ(startTime); GOTO_SIM(); #ifdef OTM #pragma omp parallel { processPackets((void*)&arg); } #else thread_start(processPackets, (void*)&arg); #endif GOTO_REAL(); TIMER_T stopTime; TIMER_READ(stopTime); printf("\nTime = %lf\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution */ /*long numFound = 0; for (i = 0; i < numThread; i++) { vector_t* errorVectorPtr = errorVectors[i]; long e; long numError = vector_getSize(errorVectorPtr); numFound += numError; for (e = 0; e < numError; e++) { long flowId = (long)vector_at(errorVectorPtr, e); bool_t status = stream_isAttack(streamPtr, flowId); assert(status); } }*/ /*printf("Num found = %li\n", numFound); assert(numFound == numAttack);*/ /* * Clean up */ for (i = 0; i < numThread; i++) { vector_free(errorVectors[i]); } free(errorVectors); decoder_free(decoderPtr); stream_free(streamPtr); dictionary_free(dictionaryPtr); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); /* * Initialization */ SETUP_NUMBER_TASKS(3); parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SETUP_NUMBER_THREADS(numThread); SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread, 0); P_MEMORY_STARTUP(numThread); thread_startup(numThread); long percentAttack = global_params[PARAM_ATTACK]; long maxDataLength = global_params[PARAM_LENGTH]; long numFlow = global_params[PARAM_NUM]; long randomSeed = global_params[PARAM_SEED]; /* printf("Percent attack = %li\n", percentAttack); printf("Max data length = %li\n", maxDataLength); printf("Num flow = %li\n", numFlow); printf("Random seed = %li\n", randomSeed); */ double time_total = 0.0; int repeats = global_params[PARAM_REPEAT]; for (; repeats > 0; --repeats) { dictionary_t* dictionaryPtr = dictionary_alloc(); assert(dictionaryPtr); stream_t* streamPtr = stream_alloc(percentAttack); assert(streamPtr); long numAttack = stream_generate(streamPtr, dictionaryPtr, numFlow, randomSeed, maxDataLength); // printf("Num attack = %li\n", numAttack); decoder_t* decoderPtr = decoder_alloc(); assert(decoderPtr); vector_t** errorVectors = (vector_t**)malloc(numThread * sizeof(vector_t*)); assert(errorVectors); long i; for (i = 0; i < numThread; i++) { vector_t* errorVectorPtr = vector_alloc(numFlow); assert(errorVectorPtr); errorVectors[i] = errorVectorPtr; } arg_t arg; arg.streamPtr = streamPtr; arg.decoderPtr = decoderPtr; arg.errorVectors = errorVectors; /* * Run transactions */ TIMER_T startTime; TIMER_READ(startTime); tm_time_t start_clock=TM_TIMER_READ(); GOTO_SIM(); thread_start(processPackets, (void*)&arg); GOTO_REAL(); TIMER_T stopTime; tm_time_t end_clock=TM_TIMER_READ(); TIMER_READ(stopTime); double time_tmp = TIMER_DIFF_SECONDS(startTime, stopTime); time_total += time_tmp; PRINT_STATS(); PRINT_CLOCK_THROUGHPUT(end_clock-start_clock); /* * Check solution */ long numFound = 0; for (i = 0; i < numThread; i++) { vector_t* errorVectorPtr = errorVectors[i]; long e; long numError = vector_getSize(errorVectorPtr); numFound += numError; for (e = 0; e < numError; e++) { long flowId = (long)vector_at(errorVectorPtr, e); bool_t status = stream_isAttack(streamPtr, flowId); assert(status); } } // printf("Num found = %li\n", numFound); assert(numFound == numAttack); /* * Clean up */ for (i = 0; i < numThread; i++) { vector_free(errorVectors[i]); } free(errorVectors); decoder_free(decoderPtr); stream_free(streamPtr); dictionary_free(dictionaryPtr); } printf("Time = %f\n", time_total); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { int max_nclusters = 13; int min_nclusters = 4; char* filename = 0; float* buf; float** attributes; float** cluster_centres = NULL; int i; int j; int best_nclusters; int* cluster_assign; int numAttributes; int numObjects; int use_zscore_transform = 1; char* line; int isBinaryFile = 0; int nloops; int len; int nthreads; float threshold = 0.001; int opt; GOTO_REAL(); line = (char*)malloc(MAX_LINE_LENGTH); /* reserve memory line */ nthreads = 1; while ((opt = getopt(argc,(char**)argv,"p:i:m:n:t:bz")) != EOF) { switch (opt) { case 'i': filename = optarg; break; case 'b': isBinaryFile = 1; break; case 't': threshold = atof(optarg); break; case 'm': max_nclusters = atoi(optarg); break; case 'n': min_nclusters = atoi(optarg); break; case 'z': use_zscore_transform = 0; break; case 'p': nthreads = atoi(optarg); break; case '?': usage((char*)argv[0]); break; default: usage((char*)argv[0]); break; } } if (filename == 0) { usage((char*)argv[0]); } if (max_nclusters < min_nclusters) { fprintf(stderr, "Error: max_clusters must be >= min_clusters\n"); usage((char*)argv[0]); } SIM_GET_NUM_CPU(nthreads); numAttributes = 0; numObjects = 0; /* * From the input file, get the numAttributes and numObjects */ if (isBinaryFile) { int infile; if ((infile = open(filename, O_RDONLY, "0600")) == -1) { fprintf(stderr, "Error: no such file (%s)\n", filename); exit(1); } read(infile, &numObjects, sizeof(int)); read(infile, &numAttributes, sizeof(int)); /* Allocate space for attributes[] and read attributes of all objects */ buf = (float*)malloc(numObjects * numAttributes * sizeof(float)); assert(buf); attributes = (float**)malloc(numObjects * sizeof(float*)); assert(attributes); attributes[0] = (float*)malloc(numObjects * numAttributes * sizeof(float)); assert(attributes[0]); for (i = 1; i < numObjects; i++) { attributes[i] = attributes[i-1] + numAttributes; } read(infile, buf, (numObjects * numAttributes * sizeof(float))); close(infile); } else { FILE *infile; if ((infile = fopen(filename, "r")) == NULL) { fprintf(stderr, "Error: no such file (%s)\n", filename); exit(1); } while (fgets(line, MAX_LINE_LENGTH, infile) != NULL) { if (strtok(line, " \t\n") != 0) { numObjects++; } } rewind(infile); while (fgets(line, MAX_LINE_LENGTH, infile) != NULL) { if (strtok(line, " \t\n") != 0) { /* Ignore the id (first attribute): numAttributes = 1; */ while (strtok(NULL, " ,\t\n") != NULL) { numAttributes++; } break; } } /* Allocate space for attributes[] and read attributes of all objects */ buf = (float*)malloc(numObjects * numAttributes * sizeof(float)); assert(buf); attributes = (float**)malloc(numObjects * sizeof(float*)); assert(attributes); attributes[0] = (float*)malloc(numObjects * numAttributes * sizeof(float)); assert(attributes[0]); for (i = 1; i < numObjects; i++) { attributes[i] = attributes[i-1] + numAttributes; } rewind(infile); i = 0; while (fgets(line, MAX_LINE_LENGTH, infile) != NULL) { if (strtok(line, " \t\n") == NULL) { continue; } for (j = 0; j < numAttributes; j++) { buf[i] = atof(strtok(NULL, " ,\t\n")); i++; } } fclose(infile); } TM_STARTUP(nthreads); thread_startup(nthreads); /* * The core of the clustering */ cluster_assign = (int*)malloc(numObjects * sizeof(int)); assert(cluster_assign); nloops = 1; len = max_nclusters - min_nclusters + 1; #ifdef STM_ENERGY_MONITOR startEnergy(); #endif /* STM_ENERGY_MONITOR */ for (i = 0; i < nloops; i++) { /* * Since zscore transform may perform in cluster() which modifies the * contents of attributes[][], we need to re-store the originals */ memcpy(attributes[0], buf, (numObjects * numAttributes * sizeof(float))); cluster_centres = NULL; cluster_exec(nthreads, numObjects, numAttributes, attributes, /* [numObjects][numAttributes] */ use_zscore_transform, /* 0 or 1 */ min_nclusters, /* pre-define range from min to max */ max_nclusters, threshold, &best_nclusters, /* return: number between min and max */ &cluster_centres, /* return: [best_nclusters][numAttributes] */ cluster_assign); /* return: [numObjects] cluster id for each object */ } #ifdef GNUPLOT_OUTPUT { FILE** fptr; char outFileName[1024]; fptr = (FILE**)malloc(best_nclusters * sizeof(FILE*)); for (i = 0; i < best_nclusters; i++) { sprintf(outFileName, "group.%d", i); fptr[i] = fopen(outFileName, "w"); } for (i = 0; i < numObjects; i++) { fprintf(fptr[cluster_assign[i]], "%6.4f %6.4f\n", attributes[i][0], attributes[i][1]); } for (i = 0; i < best_nclusters; i++) { fclose(fptr[i]); } free(fptr); } #endif /* GNUPLOT_OUTPUT */ #ifdef OUTPUT_TO_FILE { /* Output: the coordinates of the cluster centres */ FILE* cluster_centre_file; FILE* clustering_file; char outFileName[1024]; sprintf(outFileName, "%s.cluster_centres", filename); cluster_centre_file = fopen(outFileName, "w"); for (i = 0; i < best_nclusters; i++) { fprintf(cluster_centre_file, "%d ", i); for (j = 0; j < numAttributes; j++) { fprintf(cluster_centre_file, "%f ", cluster_centres[i][j]); } fprintf(cluster_centre_file, "\n"); } fclose(cluster_centre_file); /* Output: the closest cluster centre to each of the data points */ sprintf(outFileName, "%s.cluster_assign", filename); clustering_file = fopen(outFileName, "w"); for (i = 0; i < numObjects; i++) { fprintf(clustering_file, "%d %d\n", i, cluster_assign[i]); } fclose(clustering_file); } #endif /* OUTPUT TO_FILE */ #ifdef OUTPUT_TO_STDOUT { /* Output: the coordinates of the cluster centres */ for (i = 0; i < best_nclusters; i++) { //printf("%d ", i); for (j = 0; j < numAttributes; j++) { //printf("%f ", cluster_centres[i][j]); } //printf("\n"); } } #endif /* OUTPUT TO_STDOUT */ #ifdef STM_ENERGY_MONITOR float joule=endEnergy(); printf("Threads: %i\tElapsed time: %f Energy: %f",nthreads, global_time, joule); #else printf("Threads: %i\tElapsed time: %f", nthreads, global_time); #endif /* STM_ENERGY_MONITOR */ free(cluster_assign); free(attributes); free(cluster_centres[0]); free(cluster_centres); free(buf); TM_SHUTDOWN(); if (getenv("STM_STATS") != NULL) { unsigned long u; if (stm_get_global_stats("global_nb_commits", &u) != 0){ printf("\tThroughput: %f\n",u/global_time); } } GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); maze_t* mazePtr = maze_alloc(); assert(mazePtr); long numPathToRoute = maze_read(mazePtr, global_inputFile); router_t* routerPtr = router_alloc(global_params[PARAM_XCOST], global_params[PARAM_YCOST], global_params[PARAM_ZCOST], global_params[PARAM_BENDCOST]); assert(routerPtr); list_t* pathVectorListPtr = list_alloc(NULL); assert(pathVectorListPtr); /* * Run transactions */ router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr}; TIMER_T startTime; TIMER_READ(startTime); GOTO_SIM(); #ifdef OTM #pragma omp parallel { router_solve((void *)&routerArg); } #else thread_start(router_solve, (void*)&routerArg); #endif GOTO_REAL(); TIMER_T stopTime; TIMER_READ(stopTime); long numPathRouted = 0; list_iter_t it; list_iter_reset(&it, pathVectorListPtr); while (list_iter_hasNext(&it, pathVectorListPtr)) { vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it, pathVectorListPtr); numPathRouted += vector_getSize(pathVectorPtr); } printf("Paths routed = %li\n", numPathRouted); printf("Elapsed time = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution and clean up */ assert(numPathRouted <= numPathToRoute); bool_t status = maze_checkPaths(mazePtr, pathVectorListPtr, global_doPrint); assert(status == TRUE); puts("Verification passed."); maze_free(mazePtr); router_free(routerPtr); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
/* ============================================================================= * main * ============================================================================= */ MAIN (argc,argv) { TIMER_T start; TIMER_T stop; GOTO_REAL(); /* Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_params[PARAM_THREAD]); printf("Creating gene and segments... "); fflush(stdout); long geneLength = global_params[PARAM_GENE]; long segmentLength = global_params[PARAM_SEGMENT]; long minNumSegment = global_params[PARAM_NUMBER]; long numThread = global_params[PARAM_THREAD]; TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); random_t* randomPtr = random_alloc(); assert(randomPtr != NULL); random_seed(randomPtr, 0); gene_t* genePtr = gene_alloc(geneLength); assert( genePtr != NULL); gene_create(genePtr, randomPtr); char* gene = genePtr->contents; segments_t* segmentsPtr = segments_alloc(segmentLength, minNumSegment); assert(segmentsPtr != NULL); segments_create(segmentsPtr, genePtr, randomPtr); sequencer_t* sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr); assert(sequencerPtr != NULL); puts("done."); printf("Gene length = %li\n", genePtr->length); printf("Segment length = %li\n", segmentsPtr->length); printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr)); fflush(stdout); /* Benchmark */ printf("Sequencing gene... "); fflush(stdout); TIMER_READ(start); GOTO_SIM(); thread_startup(numThread, sequencer_run, (void*)sequencerPtr); thread_start(); GOTO_REAL(); TIMER_READ(stop); puts("done."); printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); /* Check result */ { char* sequence = sequencerPtr->sequence; int result = strcmp(gene, sequence); printf("Sequence matches gene: %s\n", (result ? "no" : "yes")); if (result) { printf("gene = %s\n", gene); printf("sequence = %s\n", sequence); } fflush(stdout); assert(strlen(sequence) >= strlen(gene)); } /* Clean up */ printf("Deallocating memory... "); fflush(stdout); sequencer_free(sequencerPtr); segments_free(segmentsPtr); gene_free(genePtr); random_free(randomPtr); puts("done."); fflush(stdout); al_dump(&sequencerLock); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }