int main(int argc, char *argv[]) { double t1, t2; Node root; StealStack *ss; /* initialize stealstacks and comm. layer */ ss = ss_init(&argc, &argv); /* determine benchmark parameters */ uts_parseParams(argc, argv); /* Initialize trace collection structures */ ss_initStats(ss); /* show parameter settings */ if (ss_get_thread_num() == 0) { uts_printParams(); } fflush(NULL); // Workers will return 1 from ss_start(), all others (managers) // will return 0 here once the computation ends if (ss_start(sizeof(Node), chunkSize)) { /* initialize root node and push on thread 0 stack */ if (ss_get_thread_num() == 0) { uts_initRoot(&root, type); #ifdef TRACE ss_markSteal(ss, 0); // first session is own "parent session" #endif ss_put_work(ss, &root); } /* time parallel search */ t1 = uts_wctime(); parTreeSearch(ss); t2 = uts_wctime(); ss->walltime = t2 - t1; #ifdef TRACE ss->startTime = t1; ss->sessionRecords[SS_IDLE][ss->entries[SS_IDLE] - 1].endTime = t2; #endif } ss_stop(); /* display results */ showStats(); ss_finalize(); return 0; }
void parTreeSearch(StealStack *ss) { Node *parent; Node *child; void *parent_buf, *child_buf; #ifdef USING_GTC parent_buf = (void*) gtc_task_create_ofclass(sizeof(Node), uts_tclass); parent = gtc_task_body((task_t*)parent_buf); child_buf = (void*) gtc_task_create_ofclass(sizeof(Node), uts_tclass); child = gtc_task_body((task_t*)child_buf); #else child = malloc(sizeof(Node)); parent = malloc(sizeof(Node)); parent_buf = parent; child_buf = child; #endif while (ss_get_work(ss, parent_buf) == STATUS_HAVEWORK) { genChildren(parent, child_buf, child, ss); #if DEBUG_PROGRESS > 0 // Debugging: Witness progress... if (ss->nNodes % DEBUG_PROGRESS == 0) printf("Thread %3d: Progress is %d nodes\n", ss_get_thread_num(), ss->nNodes); #endif } #ifdef USING_GTC gtc_task_destroy(parent_buf); gtc_task_destroy(child_buf); #else free(parent); free(child); #endif }
/* Fatal error */ void ss_error(char *str, int error) { fprintf(stderr, "*** [Thread %i] %s\n", ss_get_thread_num(), str); ss_abort(error); }