int main(int argc, char **argv) { PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 256); threadmain("TestFile"); PRThread *thr1 = PR_CreateThread(PR_SYSTEM_THREAD, threadmain, (void *)"TestFile1", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, STACKSIZE); PRThread *thr2 = PR_CreateThread(PR_SYSTEM_THREAD, threadmain, (void *)"TestFile2", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, STACKSIZE); PRThread *thr3 = PR_CreateThread(PR_SYSTEM_THREAD, threadmain, (void *)"TestFile3", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, STACKSIZE); PR_JoinThread(thr1); PR_JoinThread(thr2); PR_JoinThread(thr3); return 0; }
static void mainlauncher(void *arg) { Mainarg *a; a = arg; threadmain(a->argc, a->argv); threadexits("threadmain"); }
int main(int argc, char **argv) { int i; const char *getopt_str; int opt_p=0, opt_g=0, opt_a=0, opt_m=0; #if TEST_MPI init_test_mpi(&argc, &argv); getopt_str = "pgamlvtdi:"; #else getopt_str = "pgalvtdi:"; #endif GASNET_Safe(gasnet_init(&argc, &argv)); GASNET_Safe(gasnet_attach(htable, HANDLER_TABLE_SIZE, TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET)); #if TEST_MPI #define TEST_MPI_USAGE " -m use MPI calls \n" #else #define TEST_MPI_USAGE "" #endif #if GASNET_PAR #define TEST_THREAD_USAGE " [<threads_per_node>]\n\n" \ "<threads_per_node> must be between 1 and "_STRINGIFY(TEST_MAXTHREADS)" \n" #else #define TEST_THREAD_USAGE "\n\n" #endif test_init("testthreads",0, "[ -pgalvtd ] [ -i <iters> ]" TEST_THREAD_USAGE "no options means run all tests with "_STRINGIFY(DEFAULT_ITERS)" iterations\n" "options: \n" " -p use puts \n" " -g use gets \n" " -a use Active Messages \n" " -l use local Active Messages \n" TEST_MPI_USAGE " -v output information about actions taken \n" " -t include AM handler actions with -v \n" " -d dynamic thread creation stress test \n" " -i <iters> use <iters> iterations per thread \n"); while ((i = getopt (argc, argv, getopt_str)) != EOF) { switch (i) { case 'p': opt_p = 1; break; case 'g': opt_g = 1; break; case 'a': opt_a = 1; break; case 'm': opt_m = 1; break; case 'l': AM_loopback = 1; break; case 'i': iters = atoi(optarg); break; case 'v': verbose = 1; break; case 't': amtrace = 1; break; case 'd': threadstress = 1; break; default: test_usage(); } } if (opt_p) test_functions[functions_num++] = test_put; if (opt_g) test_functions[functions_num++] = test_get; if (opt_a) { test_functions[functions_num++] = test_amshort; test_functions[functions_num++] = test_ammedium; test_functions[functions_num++] = test_amlong; } #if TEST_MPI if (opt_m) test_functions[functions_num++] = test_mpi; #endif if (amtrace) verbose = 1; /* Assume all test functions if no option is passed */ if (functions_num == 0) { MSG("running all functions!"); memcpy(test_functions, test_functions_all, sizeof(test_functions_all)); functions_num = NUM_FUNCTIONS; } argc -= optind; if (argc > 1) test_usage(); else if (argc == 1) { argv += optind; threads_num = atoi(argv[0]); } if (threads_num > TEST_MAXTHREADS || threads_num < 1) { printf("ERROR: Threads must be between 1 and %i\n",TEST_MAXTHREADS); exit(EXIT_FAILURE); } /* limit sizes to a reasonable size */ #define LIMIT(sz) MIN(sz,4194304) { int sz = 0; sizes[sz++] = LIMIT(gasnet_AMMaxMedium()-1); sizes[sz++] = LIMIT(gasnet_AMMaxMedium()); sizes[sz++] = LIMIT(gasnet_AMMaxMedium()+1); sizes[sz++] = LIMIT(gasnet_AMMaxLongRequest()-1); sizes[sz++] = LIMIT(gasnet_AMMaxLongRequest()); sizes[sz++] = LIMIT(gasnet_AMMaxLongRequest()+1); sizes[sz++] = LIMIT(gasnet_AMMaxLongReply()-1); sizes[sz++] = LIMIT(gasnet_AMMaxLongReply()); sizes[sz++] = LIMIT(gasnet_AMMaxLongReply()+1); assert(sizes[sz] == 0); } alloc_thread_data(threads_num); #if TEST_MPI attach_test_mpi(); #endif #ifdef GASNET_PAR if (threadstress) { int spawniters = MAX(1,iters/threads_num); int i; MSG("Dynamic thread creation stress test, %d gasnet threads, (%d at a time)", spawniters*threads_num, threads_num); iters = 10; /* enough iters to ensure we get thread registration */ for (i = 0; i < spawniters; i++) { test_createandjoin_pthreads(threads_num, &threadmain, tt_thread_data, sizeof(threaddata_t)); TEST_PROGRESS_BAR(i, spawniters); } } else { MSG("Forking %d gasnet threads and running %d iterations", threads_num, iters); test_createandjoin_pthreads(threads_num, &threadmain, tt_thread_data, sizeof(threaddata_t)); } #else /* for testmpi-seq and -parsync */ #ifdef GASNET_SEQ MSG("Running with 1 thread/node for GASNET_SEQ mode"); #else MSG("Running with 1 thread/node for GASNET_PARSYNC mode"); #endif threadmain(tt_thread_data); #endif BARRIER(); free_thread_data(); MSG("Tests complete"); BARRIER(); gasnet_exit(0); return 0; }