int main(int argc, char *argv[]) { int i, ret; if (argc > 1) num_units = atoi(argv[1]); assert(num_units >= 0); /* Initialize */ ABT_test_init(argc, argv); /* Create schedulers and ESs */ init_global_data(); create_scheds_and_xstreams(); /* Create work units */ create_work_units(); /* Join ESs */ for (i = 1; i < g_data.num_scheds; i++) { ret = ABT_xstream_join(g_data.xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); } free_scheds_and_xstreams(); /* Finalize */ ret = ABT_test_finalize(0); fini_global_data(); return ret; }
GLT_func_prefix void glt_finalize() { for (int i = 1; i < main_team->num_xstreams; i++) { CHECK(ABT_xstream_join(main_team->team[i]),ABT_SUCCESS); CHECK(ABT_xstream_free(&main_team->team[i]),ABT_SUCCESS); } CHECK(ABT_finalize(),ABT_SUCCESS); }
int main(int argc, char *argv[]) { ABT_xstream xstreams[NUM_XSTREAMS]; ABT_sched scheds[NUM_XSTREAMS]; int num_pools[NUM_XSTREAMS]; ABT_pool *pools[NUM_XSTREAMS]; int i, k; ABT_init(argc, argv); /* Create schedulers */ for (i = 0; i < NUM_XSTREAMS; i++) { ABT_sched_predef predef; predef = (i % 2) ? ABT_SCHED_BASIC : ABT_SCHED_PRIO; ABT_sched_create_basic(predef, 0, NULL, ABT_SCHED_CONFIG_NULL, &scheds[i]); } /* Create ESs */ ABT_xstream_self(&xstreams[0]); ABT_xstream_set_main_sched(xstreams[0], scheds[0]); for (i = 1; i < NUM_XSTREAMS; i++) { ABT_xstream_create(scheds[i], &xstreams[i]); } /* Get the pools associated with each scheduler */ for (i = 0; i < NUM_XSTREAMS; i++) { ABT_sched_get_num_pools(scheds[i], &num_pools[i]); pools[i] = (ABT_pool *)malloc(num_pools[i] * sizeof(ABT_pool)); ABT_sched_get_pools(scheds[i], num_pools[i], 0, pools[i]); } /* Create ULTs */ for (i = 0; i < NUM_XSTREAMS; i++) { for (k = num_pools[i] - 1; k >= 0; k--) { size_t tid = (i + 1) * 10 + k; ABT_thread_create(pools[i][k], thread_hello, (void *)tid, ABT_THREAD_ATTR_NULL, NULL); } } /* Join & Free */ for (i = 1; i < NUM_XSTREAMS; i++) { ABT_xstream_join(xstreams[i]); ABT_xstream_free(&xstreams[i]); } for (i = 0; i < NUM_XSTREAMS; i++) { free(pools[i]); } ABT_finalize(); return 0; }
void accalt_finalize() { #ifdef ARGOBOTS for (int i = 1; i < main_team->num_xstreams; i++) { ABT_xstream_join(main_team->team[i]); ABT_xstream_free(&main_team->team[i]); } ABT_finalize(); #endif #ifdef MASSIVETHREADS myth_fini(); //MassiveThreads #endif }
void sighandler(int sig) { printf("%s\n", "Caught signal for terminating..."); printf("%s\n", "Joining threads..."); int i; /* join other threads */ for(i = 0; i < num_threads;i++){ ABT_thread_join(threads[i]); ABT_thread_free(&threads[i]); } printf("%s\n", "Joining streams..."); /* join ESs */ for (i = 1; i < CORES; i++) { ABT_xstream_join(xstreams[i]); ABT_xstream_free(&xstreams[i]); } ABT_finalize(); abt_io_finalize(abtio); free(xstreams); exit(0); }
int main(int argc, char *argv[]) { int i, j; int ret; int num_xstreams = DEFAULT_NUM_XSTREAMS; int num_threads = DEFAULT_NUM_THREADS; if (argc > 1) num_xstreams = atoi(argv[1]); assert(num_xstreams >= 0); if (argc > 2) num_threads = atoi(argv[2]); assert(num_threads >= 0); ABT_xstream *xstreams; ABT_thread **threads; thread_arg_t **args; xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); threads = (ABT_thread **)malloc(sizeof(ABT_thread *) * num_xstreams); args = (thread_arg_t **)malloc(sizeof(thread_arg_t *) * num_xstreams); for (i = 0; i < num_xstreams; i++) { threads[i] = (ABT_thread *)malloc(sizeof(ABT_thread) * num_threads); for (j = 0; j < num_threads; j++) { threads[i][j] = ABT_THREAD_NULL; } args[i] = (thread_arg_t *)malloc(sizeof(thread_arg_t) * num_threads); } /* Initialize */ ABT_test_init(argc, argv); /* Create Execution Streams */ ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the pools attached to an execution stream */ ABT_pool *pools; pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams); for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, pools+i); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create threads */ for (i = 0; i < num_xstreams; i++) { for (j = 0; j < num_threads; j++) { int tid = i * num_threads + j + 1; args[i][j].id = tid; args[i][j].num_threads = num_threads; args[i][j].threads = &threads[i][0]; ret = ABT_thread_create(pools[i], thread_func, (void *)&args[i][j], ABT_THREAD_ATTR_NULL, &threads[i][j]); ABT_TEST_ERROR(ret, "ABT_thread_create"); } } /* Join Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); } /* Free threads and Execution Streams */ for (i = 0; i < num_xstreams; i++) { for (j = 0; j < num_threads; j++) { ret = ABT_thread_free(&threads[i][j]); ABT_TEST_ERROR(ret, "ABT_thread_free"); } if (i == 0) continue; ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } /* Finalize */ ret = ABT_test_finalize(0); for (i = 0; i < num_xstreams; i++) { free(args[i]); free(threads[i]); } free(args); free(threads); free(pools); free(xstreams); return ret; }
/* Main function */ int main(int argc, char *argv[]) { int n, i, expected; int num_xstreams; ABT_xstream *xstreams; ABT_thread thread; thread_args args; if (argc > 1 && strcmp(argv[1], "-h") == 0) { printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]); return EXIT_SUCCESS; } n = argc > 1 ? atoi(argv[1]) : N; num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS; printf("# of ESs: %d\n", num_xstreams); /* initialization */ ABT_init(argc, argv); /* shared pool creation */ ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &g_pool); /* ES creation */ xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); ABT_xstream_self(&xstreams[0]); ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, &g_pool); for (i = 1; i < num_xstreams; i++) { ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool, ABT_SCHED_CONFIG_NULL, &xstreams[i]); ABT_xstream_start(xstreams[i]); } args.n = n; args.future = ABT_FUTURE_NULL; ABT_thread_create(g_pool, fibonacci, &args, ABT_THREAD_ATTR_NULL, &thread); /* join the thread */ ABT_thread_join(thread); ABT_thread_free(&thread); /* join ESs */ for (i = 1; i < num_xstreams; i++) { ABT_xstream_join(xstreams[i]); ABT_xstream_free(&xstreams[i]); } ABT_finalize(); free(xstreams); printf("Fib(%d): %d\n", n, args.result); expected = verify(n); if (args.result != expected) { fprintf(stderr, "ERROR: expected=%d\n", expected); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { ABT_xstream xstream; ABT_pool pool; ABT_timer timer; int i, iter; double t_overhead; ABT_test_read_args(argc, argv); iter = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER); ABT_timer_create(&timer); ABT_timer_start(timer); ABT_timer_stop(timer); ABT_timer_get_overhead(&t_overhead); for (i = 0; i < T_LAST; i++) t_timers[i] = 0.0; /* measure init/finalize time (cold) */ ABT_timer_start(timer); ABT_init(argc, argv); ABT_finalize(); ABT_timer_stop_and_read(timer, &t_timers[T_INIT_FINALIZE_COLD]); t_timers[T_INIT_FINALIZE_COLD] -= t_overhead; /* measure init/finalize time */ for (i = 0; i < iter; i++) { ABT_timer_start(timer); ABT_init(argc, argv); ABT_timer_stop_and_add(timer, &t_timers[T_INIT]); ABT_timer_start(timer); ABT_finalize(); ABT_timer_stop_and_add(timer, &t_timers[T_FINALIZE]); } t_timers[T_INIT] /= iter; t_timers[T_INIT] -= t_overhead; t_timers[T_FINALIZE] /= iter; t_timers[T_FINALIZE] -= t_overhead; t_timers[T_INIT_FINALIZE] = t_timers[T_INIT] + t_timers[T_FINALIZE]; /* measure time of init/finalize with work */ for (i = 0; i < iter; i++) { ABT_timer_start(timer); ABT_init(argc, argv); ABT_timer_stop_and_add(timer, &t_timers[T_INIT_FINALIZE_WITH_WORK]); ABT_xstream_create(ABT_SCHED_NULL, &xstream); ABT_xstream_get_main_pools(xstream, 1, &pool); ABT_thread_create(pool, thread_func, NULL, ABT_THREAD_ATTR_NULL, NULL); ABT_xstream_join(xstream); ABT_xstream_free(&xstream); ABT_timer_start(timer); ABT_finalize(); ABT_timer_stop_and_add(timer, &t_timers[T_INIT_FINALIZE_WITH_WORK]); } t_timers[T_INIT_FINALIZE_WITH_WORK] /= iter; t_timers[T_INIT_FINALIZE_WITH_WORK] -= t_overhead; /* output */ int line_size = 45; ABT_test_print_line(stdout, '-', line_size); printf("Avg. execution time (in seconds, %d times)\n", iter); ABT_test_print_line(stdout, '-', line_size); for (i = 0; i < T_LAST; i++) { printf("%-23s %.9f\n", t_names[i], t_timers[i]); } ABT_test_print_line(stdout, '-', line_size); ABT_timer_free(&timer); return EXIT_SUCCESS; }
/* Main function */ int main(int argc, char *argv[]) { int n, i, result, expected; int num_xstreams; ABT_xstream *xstreams; ABT_thread thread; thread_args args_thread; ABT_task task; task_args *args_task; if (argc > 1 && strcmp(argv[1], "-h") == 0) { printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]); return EXIT_SUCCESS; } n = argc > 1 ? atoi(argv[1]) : N; num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS; printf("# of ESs: %d\n", num_xstreams); if (n <= 2) { result = 1; goto fn_result; } /* initialization */ ABT_init(argc, argv); /* shared pool creation */ ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &g_pool); /* ES creation */ xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); ABT_xstream_self(&xstreams[0]); ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, &g_pool); for (i = 1; i < num_xstreams; i++) { ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool, ABT_SCHED_CONFIG_NULL, &xstreams[i]); ABT_xstream_start(xstreams[i]); } /* creating thread */ args_thread.n = n - 1; args_thread.eventual = ABT_EVENTUAL_NULL; ABT_thread_create(g_pool, fibonacci_thread, &args_thread, ABT_THREAD_ATTR_NULL, &thread); /* creating task */ args_task = (task_args *)malloc(sizeof(task_args)); args_task->n = n - 2; args_task->result = 0; ABT_mutex_create(&args_task->mutex); args_task->parent = NULL; ABT_task_create(g_pool, fibonacci_task, args_task, &task); /* switch to other user-level threads */ ABT_thread_yield(); /* join other threads */ ABT_thread_join(thread); ABT_thread_free(&thread); /* join ESs */ for (i = 1; i < num_xstreams; i++) { ABT_xstream_join(xstreams[i]); ABT_xstream_free(&xstreams[i]); } result = args_thread.result + args_task->result; free(args_task); ABT_finalize(); free(xstreams); fn_result: printf("Fib(%d): %d\n", n, result); expected = verify(n); if (result != expected) { fprintf(stderr, "ERROR: expected=%d\n", expected); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int i, ret; ABT_xstream *xstreams; ABT_pool *pools; ABT_thread *threads; int num_xstreams = DEFAULT_NUM_XSTREAMS; /* Initialize */ ABT_test_init(argc, argv); if (argc >= 2) { num_xstreams = ABT_test_get_arg_val(ABT_TEST_ARG_N_ES); num_threads = ABT_test_get_arg_val(ABT_TEST_ARG_N_ULT); } ABT_test_printf(1, "# of ESs : %d\n", num_xstreams); ABT_test_printf(1, "# of ULTs/ES: %d\n", num_threads); xstreams = (ABT_xstream *)malloc(num_xstreams * sizeof(ABT_xstream)); pools = (ABT_pool *)malloc(num_xstreams * sizeof(ABT_pool)); threads = (ABT_thread *)malloc(num_xstreams * sizeof(ABT_thread)); /* Create Execution Streams */ ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the first pool of each ES */ for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, &pools[i]); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create one ULT for each ES */ for (i = 1; i < num_xstreams; i++) { ret = ABT_thread_create(pools[i], thread_create, (void *)0, ABT_THREAD_ATTR_NULL, &threads[i]); ABT_TEST_ERROR(ret, "ABT_thread_create"); } thread_create((void *)0); /* Join and free ULTs */ for (i = 1; i < num_xstreams; i++) { ret = ABT_thread_free(&threads[i]); ABT_TEST_ERROR(ret, "ABT_thread_free"); } /* Join and free ESs */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } /* Finalize */ ret = ABT_test_finalize(0); free(xstreams); free(pools); free(threads); return ret; }
int main(int argc, char *argv[]) { ABT_xstream *xstreams; ABT_thread *masters; int i, ret; /* Initialize */ ABT_test_init(argc, argv); if (argc < 2) { num_xstreams = DEFAULT_NUM_XSTREAMS; num_threads = DEFAULT_NUM_THREADS; num_tasks = DEFAULT_NUM_TASKS; num_iter = DEFAULT_NUM_ITER; } else { num_xstreams = ABT_test_get_arg_val(ABT_TEST_ARG_N_ES); num_tasks = ABT_test_get_arg_val(ABT_TEST_ARG_N_TASK); num_threads = num_tasks * 2; num_iter = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER); } ABT_test_printf(1, "# of ESs : %d\n", num_xstreams); ABT_test_printf(1, "# of ULTs/ES : %d\n", num_threads + num_tasks); ABT_test_printf(1, "# of tasklets/ES: %d\n", num_tasks); ABT_test_printf(1, "# of iter : %d\n", num_iter); xstreams = (ABT_xstream *)malloc(num_xstreams * sizeof(ABT_xstream)); pools = (ABT_pool *)malloc(num_xstreams * sizeof(ABT_pool)); masters = (ABT_thread *)malloc(num_xstreams * sizeof(ABT_thread)); /* Create Execution Streams */ ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the main pool of each ES */ for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, &pools[i]); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create a master ULT for each ES */ for (i = 1; i < num_xstreams; i++) { ret = ABT_thread_create(pools[i], eventual_test, (void *)(size_t)i, ABT_THREAD_ATTR_NULL, &masters[i]); ABT_TEST_ERROR(ret, "ABT_thread_create"); } eventual_test((void *)0); /* Join master ULTs */ for (i = 1; i < num_xstreams; i++) { ret = ABT_thread_free(&masters[i]); ABT_TEST_ERROR(ret, "ABT_thread_free"); } /* Join and free Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } /* Finalize */ ret = ABT_test_finalize(0); free(xstreams); free(pools); free(masters); return ret; }
int main(int argc, char *argv[]) { int i, j; int ret; int num_xstreams = DEFAULT_NUM_XSTREAMS; int num_threads = DEFAULT_NUM_THREADS; if (argc > 1) num_xstreams = atoi(argv[1]); assert(num_xstreams >= 0); if (argc > 2) num_threads = atoi(argv[2]); assert(num_threads >= 0); ABT_xstream *xstreams; xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); ABT_pool *pools; pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams); /* Initialize */ ABT_test_init(argc, argv); /* Create Execution Streams */ ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the pools attached to an execution stream */ for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, pools+i); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create threads */ for (i = 0; i < num_xstreams; i++) { for (j = 0; j < num_threads; j++) { size_t tid = i * num_threads + j + 1; ret = ABT_thread_create(pools[i], thread_func, (void *)tid, ABT_THREAD_ATTR_NULL, NULL); ABT_TEST_ERROR(ret, "ABT_thread_create"); } } /* Join Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); } /* Free Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } /* Finalize */ ret = ABT_test_finalize(0); free(pools); free(xstreams); return ret; }
int main(int argc, char *argv[]) { int i, j; int ret, expected; int num_xstreams = DEFAULT_NUM_XSTREAMS; int num_threads = DEFAULT_NUM_THREADS; if (argc > 1) num_xstreams = atoi(argv[1]); assert(num_xstreams >= 0); if (argc > 2) num_threads = atoi(argv[2]); assert(num_threads >= 0); ABT_mutex mutex; ABT_xstream *xstreams; thread_arg_t **args; xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); assert(xstreams != NULL); args = (thread_arg_t **)malloc(sizeof(thread_arg_t *) * num_xstreams); assert(args != NULL); for (i = 0; i < num_xstreams; i++) { args[i] = (thread_arg_t *)malloc(sizeof(thread_arg_t) * num_threads); } /* Initialize */ ABT_test_init(argc, argv); /* Create Execution Streams */ ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the pools attached to an execution stream */ ABT_pool *pools; pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams); for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, pools+i); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create a mutex */ ret = ABT_mutex_create(&mutex); ABT_TEST_ERROR(ret, "ABT_mutex_create"); /* Create threads */ for (i = 0; i < num_xstreams; i++) { for (j = 0; j < num_threads; j++) { int tid = i * num_threads + j + 1; args[i][j].id = tid; args[i][j].mutex = mutex; ret = ABT_thread_create(pools[i], thread_func, (void *)&args[i][j], ABT_THREAD_ATTR_NULL, NULL); ABT_TEST_ERROR(ret, "ABT_thread_create"); } } /* Switch to other user level threads */ ABT_thread_yield(); /* Join Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); } /* Free the mutex */ ret = ABT_mutex_free(&mutex); ABT_TEST_ERROR(ret, "ABT_mutex_free"); /* Free Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } /* Validation */ expected = num_xstreams * num_threads; if (g_counter != expected) { printf("g_counter = %d\n", g_counter); } /* Finalize */ ret = ABT_test_finalize(g_counter != expected); for (i = 0; i < num_xstreams; i++) { free(args[i]); } free(args); free(xstreams); free(pools); return ret; }
int main(int argc, char *argv[]) { int i, j; int ntasks; int start, end; int num_xstreams; ABT_xstream *xstreams; vector_scal_task_args_t *args; struct timeval t_start, t_end, t_end2; char *str, *endptr; float *a; num_xstreams = argc > 1 ? atoi(argv[1]) : NUM_XSTREAMS; if (argc > 2) { str = argv[2]; } ntasks = argc > 2 ? strtoll(str, &endptr, 10) : NUM_TASKS; if (ntasks < num_xstreams) { ntasks = num_xstreams; } printf("# of ESs: %d\n", num_xstreams); xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); args = (vector_scal_task_args_t *)malloc(sizeof(vector_scal_task_args_t) * num_xstreams); g_pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams); a = malloc(sizeof(float) * ntasks); for (i = 0; i < ntasks; i++) { a[i] = i + 100.0f; } /* initialization */ ABT_init(argc, argv); for (i = 0; i < num_xstreams; i++) { ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &g_pools[i]); } /* ES creation */ ABT_xstream_self(&xstreams[0]); ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, &g_pools[0]); for (i = 1; i < num_xstreams; i++) { ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pools[i], ABT_SCHED_CONFIG_NULL, &xstreams[i]); ABT_xstream_start(xstreams[i]); } /* Work here */ start = end = 0; int bloc = ntasks / num_xstreams; int rest = ntasks % num_xstreams; gettimeofday(&t_start, NULL); for (j = 0; j < num_xstreams; j++) { start = end; end = start + bloc; if (j < rest) { end++; } args[j].ptr = a; args[j].value = 0.9f; args[j].start = start; args[j].end = end; args[j].id = j; ABT_thread_create_on_xstream(xstreams[j], task_creator, (void *)&args[j], ABT_THREAD_ATTR_NULL, NULL); } gettimeofday(&t_end2, NULL); for (i = 0; i < num_xstreams; i++) { size_t size; do { ABT_thread_yield(); ABT_pool_get_size(g_pools[i], &size); } while (size != 0); } gettimeofday(&t_end, NULL); for (i = 0; i < ntasks; i++) { if (a[i] != (i + 100.0f) * 0.9f) { printf("error: a[%d]\n", i); } } double time = (t_end.tv_sec * 1000000 + t_end.tv_usec) - (t_start.tv_sec * 1000000 + t_start.tv_usec); double time2 = (t_end2.tv_sec * 1000000 + t_end2.tv_usec) - (t_start.tv_sec * 1000000 + t_start.tv_usec); printf("nxstreams: %d\nntasks %d\nTime(s): %f\n", num_xstreams, ntasks, time / 1000000.0); /* join ESs */ for (i = 1; i < num_xstreams; i++) { ABT_xstream_join(xstreams[i]); ABT_xstream_free(&xstreams[i]); } printf("Creation time=%f\n", time2 / 1000000.0); ABT_finalize(); free(xstreams); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int i, j, ret; int num_xstreams = DEFAULT_NUM_XSTREAMS; int num_threads = DEFAULT_NUM_THREADS; int num_tasks = DEFAULT_NUM_TASKS; if (argc > 1) num_xstreams = atoi(argv[1]); assert(num_xstreams >= 0); if (argc > 2) num_threads = atoi(argv[2]); assert(num_threads >= 0); if (argc > 3) num_tasks = atoi(argv[3]); assert(num_tasks >= 0); ABT_xstream *xstreams; ABT_thread **threads; thread_arg_t **thread_args; ABT_task *tasks; task_arg_t *task_args; xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); threads = (ABT_thread **)malloc(sizeof(ABT_thread *) * num_xstreams); thread_args = (thread_arg_t **)malloc(sizeof(thread_arg_t*) * num_xstreams); for (i = 0; i < num_xstreams; i++) { threads[i] = (ABT_thread *)malloc(sizeof(ABT_thread) * num_threads); for (j = 0; j < num_threads; j++) { threads[i][j] = ABT_THREAD_NULL; } thread_args[i] = (thread_arg_t *)malloc(sizeof(thread_arg_t) * num_threads); } tasks = (ABT_task *)malloc(sizeof(ABT_task) * num_tasks); task_args = (task_arg_t *)malloc(sizeof(task_arg_t) * num_tasks); /* Initialize */ ABT_test_init(argc, argv); /* Create Execution Streams */ ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the pools attached to an execution stream */ ABT_pool *pools; pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams); for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, pools+i); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create threads */ for (i = 0; i < num_xstreams; i++) { for (j = 0; j < num_threads; j++) { int tid = i * num_threads + j + 1; thread_args[i][j].id = tid; thread_args[i][j].num_threads = num_threads; thread_args[i][j].threads = &threads[i][0]; ret = ABT_thread_create(pools[i], thread_func, (void *)&thread_args[i][j], ABT_THREAD_ATTR_NULL, &threads[i][j]); ABT_TEST_ERROR(ret, "ABT_thread_create"); } } /* Create tasks with task_func1 */ for (i = 0; i < num_tasks; i++) { size_t num = 100 + i; ret = ABT_task_create(pools[i % num_xstreams], task_func1, (void *)num, NULL); ABT_TEST_ERROR(ret, "ABT_task_create"); } /* Create tasks with task_func2 */ for (i = 0; i < num_tasks; i++) { task_args[i].num = 100 + i; ret = ABT_task_create(pools[i % num_xstreams], task_func2, (void *)&task_args[i], &tasks[i]); ABT_TEST_ERROR(ret, "ABT_task_create"); } /* Switch to other work units */ ABT_thread_yield(); /* Results of task_funcs2 */ for (i = 0; i < num_tasks; i++) { ABT_task_state state; do { ABT_task_get_state(tasks[i], &state); ABT_thread_yield(); } while (state != ABT_TASK_STATE_TERMINATED); ABT_test_printf(1, "task_func2: num=%lu result=%llu\n", task_args[i].num, task_args[i].result); /* Free named tasks */ ret = ABT_task_free(&tasks[i]); ABT_TEST_ERROR(ret, "ABT_task_free"); } /* Join Execution Streams */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); } /* Free Execution Streams */ for (i = 0; i < num_xstreams; i++) { for (j = 0; j < num_threads; j++) { ret = ABT_thread_free(&threads[i][j]); ABT_TEST_ERROR(ret, "ABT_thread_free"); } if (i == 0) continue; ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } /* Finalize */ ret = ABT_test_finalize(0); for (i = 0; i < num_xstreams; i++) { free(thread_args[i]); free(threads[i]); } free(thread_args); free(threads); free(task_args); free(tasks); free(pools); free(xstreams); return ret; }
int main(int argc, char *argv[]) { ABT_xstream *xstreams; ABT_pool *pools; ABT_thread *threads; int num_xstreams; int es = 0; int *args; int i, j, iter, t; int ret; /* Initialize */ ABT_test_init(argc, argv); if (argc < 2) { num_xstreams = 4; N = 10; iter = 100; } else { num_xstreams = ABT_test_get_arg_val(ABT_TEST_ARG_N_ES); N = ABT_test_get_arg_val(ABT_TEST_ARG_N_ULT); iter = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER); } ABT_test_printf(1, "# of ESs : %d\n", num_xstreams); ABT_test_printf(1, "# of ULTs: %d\n", N * N); ABT_test_printf(1, "# of iter: %d\n", iter); xstreams = (ABT_xstream *)malloc(num_xstreams * sizeof(ABT_xstream)); pools = (ABT_pool *)malloc(num_xstreams * sizeof(ABT_pool)); threads = (ABT_thread *)malloc(N * N * sizeof(ABT_thread)); values = (int *)malloc(N * sizeof(int)); row_barrier = (ABT_barrier *)malloc(N * sizeof(ABT_barrier)); col_barrier = (ABT_barrier *)malloc(N * sizeof(ABT_barrier)); /* Create the values and barriers */ for (i = 0; i < N; i++) { ret = ABT_barrier_create((size_t)N, &row_barrier[i]); ABT_TEST_ERROR(ret, "ABT_barrier_create"); ret = ABT_barrier_create((size_t)N, &col_barrier[i]); ABT_TEST_ERROR(ret, "ABT_barrier_create"); } ret = ABT_barrier_create((size_t)N * N, &global_barrier); ABT_TEST_ERROR(ret, "ABT_barrier_create"); args = (int *)malloc(2 * N * N * sizeof(int)); /* Create ESs */ for (t = 0; t < iter; t++) { ABT_test_printf(1, "iter=%d\n", t); ret = ABT_xstream_self(&xstreams[0]); ABT_TEST_ERROR(ret, "ABT_xstream_self"); for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_create"); } /* Get the first pool of each ES */ for (i = 0; i < num_xstreams; i++) { ret = ABT_xstream_get_main_pools(xstreams[i], 1, &pools[i]); ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools"); } /* Create ULTs */ for (i = 0; i < N; i++) { values[i] = i; } for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { args[2*(i*N+j)] = i; args[2*(i*N+j)+1] = j; ret = ABT_thread_create(pools[es], run, (void *)&args[2*(i*N+j)], ABT_THREAD_ATTR_NULL, &threads[i*N+j]); ABT_TEST_ERROR(ret, "ABT_thread_create"); es = (es + 1) % num_xstreams; } } /* Join and free ULTs */ for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { ret = ABT_thread_free(&threads[i*N+j]); ABT_TEST_ERROR(ret, "ABT_thread_free"); } } /* Join ESs */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_join(xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_join"); } /* Free ESs */ for (i = 1; i < num_xstreams; i++) { ret = ABT_xstream_free(&xstreams[i]); ABT_TEST_ERROR(ret, "ABT_xstream_free"); } } /* Free the barriers */ for (i = 0; i < N; i++) { ret = ABT_barrier_free(&row_barrier[i]); ABT_TEST_ERROR(ret, "ABT_barrier_create"); ret = ABT_barrier_free(&col_barrier[i]); ABT_TEST_ERROR(ret, "ABT_barrier_create"); } ret = ABT_barrier_free(&global_barrier); ABT_TEST_ERROR(ret, "ABT_barrier_free"); /* Finalize */ ret = ABT_test_finalize(0); free(xstreams); free(pools); free(threads); free(values); free(row_barrier); free(col_barrier); free(args); return ret; }
int main(int argc, char *argv[]) { int i, j, r; int num_xstreams; char *str, *endptr; ABT_xstream *xstreams; ABT_thread *threads; vector_scal_task_args_t *args; int inner_xstreams; double *time, avg_time = 0.0; num_xstreams = (argc > 1) ? atoi(argv[1]) : NUM_XSTREAMS; inner_xstreams = (argc > 2) ? atoi(argv[2]) : NUM_XSTREAMS; int rep = (argc > 3) ? atoi(argv[3]) : NUM_REPS; time = (double *)malloc(sizeof(double) * rep); init(); g_pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams); xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); threads = (ABT_thread *)malloc(sizeof(ABT_thread) * num_xstreams); args = (vector_scal_task_args_t *)malloc(sizeof(vector_scal_task_args_t) * num_xstreams); /* initialization */ ABT_init(argc, argv); for (i = 0; i < num_xstreams; i++) { ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &g_pools[i]); } /* ES creation */ ABT_xstream_self(&xstreams[0]); ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, &g_pools[0]); for (i = 1; i < num_xstreams; i++) { ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pools[i], ABT_SCHED_CONFIG_NULL, &xstreams[i]); ABT_xstream_start(xstreams[i]); } /* Each task is created on the xstream which is going to execute it */ for (r = 0; r < rep; r++) { time[r] = ABT_get_wtime(); int bloc = NUM / (num_xstreams); int rest = NUM % (num_xstreams); int start = 0; int end = 0; for (j = 0; j < num_xstreams; j++) { start = end; int inc = (j < rest) ? 1 : 0; end += bloc + inc; args[j].start = start; args[j].end = end; args[j].it = NUM; args[j].nxstreams = inner_xstreams; if (j > 0) { ABT_thread_create(g_pools[j], vector_scal_launch, (void *)&args[j], ABT_THREAD_ATTR_NULL, &threads[j]); } } vector_scal_launch((void *)&args[0]); for (j = 1; j < num_xstreams; j++) { ABT_thread_free(&threads[j]); } time[r] = ABT_get_wtime() - time[r]; avg_time += time[r]; } avg_time /= rep; printf("%d %d %f\n", num_xstreams, inner_xstreams, avg_time); check(); for (i = 1; i < num_xstreams; i++) { ABT_xstream_join(xstreams[i]); ABT_xstream_free(&xstreams[i]); } ABT_finalize(); free(g_pools); free(xstreams); free(threads); free(args); free(time); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { ABT_pool (*all_pools)[2]; ABT_sched *scheds; ABT_thread *top_threads; size_t i, t; uint64_t t_start; /* initialize */ ABT_test_init(argc, argv); for (i = 0; i < T_LAST; i++) { t_times[i] = 0; } /* read command-line arguments */ num_xstreams = ABT_test_get_arg_val(ABT_TEST_ARG_N_ES); num_threads = ABT_test_get_arg_val(ABT_TEST_ARG_N_ULT); iter = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER); g_xstreams = (ABT_xstream *)malloc(num_xstreams * sizeof(ABT_xstream)); g_pools = (ABT_pool *)malloc(num_xstreams * sizeof(ABT_pool)); g_threads = (ABT_thread **)malloc(num_xstreams * sizeof(ABT_thread *)); for (i = 0; i < num_xstreams; i++) { g_threads[i] = (ABT_thread *)malloc(num_threads * sizeof(ABT_thread)); } all_pools = (ABT_pool (*)[2])malloc(num_xstreams * sizeof(ABT_pool) * 2); scheds = (ABT_sched *)malloc(num_xstreams * sizeof(ABT_sched)); top_threads = (ABT_thread *)malloc(num_xstreams * sizeof(ABT_thread)); /* create pools and schedulers */ for (i = 0; i < num_xstreams; i++) { ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPSC, ABT_TRUE, &all_pools[i][0]); ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_PRIV, ABT_TRUE, &all_pools[i][1]); g_pools[i] = all_pools[i][1]; ABT_sched_create_basic(ABT_SCHED_DEFAULT, 2, all_pools[i], ABT_SCHED_CONFIG_NULL, &scheds[i]); } /* create ESs */ ABT_xstream_self(&g_xstreams[0]); ABT_xstream_set_main_sched(g_xstreams[0], scheds[0]); for (i = 1; i < num_xstreams; i++) { ABT_xstream_create(scheds[i], &g_xstreams[i]); } /* benchmarking */ for (t = 0; t < T_LAST; t++) { void (*test_fn)(void *); if (t == T_YIELD) { if (t_times[T_YIELD_ALL] > t_times[T_YIELD_OVERHEAD]) { t_times[t] = t_times[T_YIELD_ALL] - t_times[T_YIELD_OVERHEAD]; } else { t_times[t] = 0; } continue; } else if (t == T_YIELD_TO) { if (t_times[T_YIELD_TO_ALL] > t_times[T_YIELD_TO_OVERHEAD]) { t_times[t] = t_times[T_YIELD_TO_ALL] - t_times[T_YIELD_TO_OVERHEAD]; } else { t_times[t] = 0; } continue; } switch (t) { case T_CREATE_JOIN: test_fn = test_create_join; break; case T_CREATE_UNNAMED: test_fn = test_create_unnamed; break; case T_YIELD_OVERHEAD: test_fn = test_yield_overhead; break; case T_YIELD_ALL: test_fn = test_yield; break; case T_YIELD_TO_OVERHEAD: test_fn = test_yield_to_overhead; break; case T_YIELD_TO_ALL: test_fn = test_yield_to; break; #ifdef TEST_MIGRATE_TO case T_MIGRATE_TO_XSTREAM: test_fn = test_migrate_to_xstream; break; #endif default: assert(0); } /* warm-up */ for (i = 0; i < num_xstreams; i++) { ABT_thread_create(all_pools[i][0], test_fn, (void *)i, ABT_THREAD_ATTR_NULL, &top_threads[i]); } for (i = 0; i < num_xstreams; i++) { ABT_thread_free(&top_threads[i]); } /* measurement */ #ifdef USE_TIME t_start = ABT_get_wtime(); #else t_start = ABT_test_get_cycles(); #endif for (i = 0; i < num_xstreams; i++) { ABT_thread_create(all_pools[i][0], test_fn, (void *)i, ABT_THREAD_ATTR_NULL, &top_threads[i]); } for (i = 0; i < num_xstreams; i++) { ABT_thread_free(&top_threads[i]); } #ifdef USE_TIME t_times[t] = ABT_get_wtime() - t_start; #else t_times[t] = ABT_test_get_cycles() - t_start; #endif } /* join and free */ for (i = 1; i < num_xstreams; i++) { ABT_xstream_join(g_xstreams[i]); ABT_xstream_free(&g_xstreams[i]); } /* finalize */ ABT_test_finalize(0); /* compute the execution time for one iteration */ for (i = 0; i < T_LAST; i++) { t_times[i] = t_times[i] / iter / num_threads; } /* output */ int line_size = 56; ABT_test_print_line(stdout, '-', line_size); printf("%s\n", "Argobots"); ABT_test_print_line(stdout, '-', line_size); printf("# of ESs : %d\n", num_xstreams); printf("# of ULTs per ES: %d\n", num_threads); ABT_test_print_line(stdout, '-', line_size); printf("Avg. execution time (in seconds, %d times)\n", iter); ABT_test_print_line(stdout, '-', line_size); printf("%-20s %-s\n", "operation", "time"); ABT_test_print_line(stdout, '-', line_size); for (i = 0; i < T_LAST; i++) { #ifdef USE_TIME printf("%-19s %.9lf\n", t_names[i], t_times[i]); #else printf("%-19s %11" PRIu64 "\n", t_names[i], t_times[i]); #endif } ABT_test_print_line(stdout, '-', line_size); free(g_xstreams); free(g_pools); for (i = 0; i < num_xstreams; i++) { free(g_threads[i]); } free(g_threads); free(all_pools); free(scheds); free(top_threads); return EXIT_SUCCESS; }