Esempio n. 1
0
static int
abt_init(int argc, char *argv[])
{
	int	nrequested = abt_max_num_xstreams();
	int	nrequired = 1 /* primary xstream */ + DSS_XS_NR_TOTAL;
	int	rc;

	/*
	 * Set ABT_MAX_NUM_XSTREAMS to the larger of nrequested and nrequired.
	 * If we don't do this, Argobots may use a default or requested value
	 * less than nrequired. We may then hit Argobots assertion failures
	 * because xstream_data.xd_mutex's internal queue has fewer slots than
	 * some xstreams' rank numbers need.
	 */
	rc = set_abt_max_num_xstreams(max(nrequested, nrequired));
	if (rc != 0)
		return daos_errno2der(errno);

	/* Now, initialize Argobots. */
	rc = ABT_init(argc, argv);
	if (rc != ABT_SUCCESS) {
		D_ERROR("failed to init ABT: %d\n", rc);
		return dss_abterr2der(rc);
	}

	return 0;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
File: glt.c Progetto: adcastel/GLT
GLT_func_prefix void glt_init(int argc, char * argv[]) {
    int num_threads = get_nprocs();
   
    main_team = (glt_team_t *) malloc(sizeof (glt_team_t));
    CHECK(ABT_init(argc, argv),ABT_SUCCESS);

    if (getenv("GLT_NUM_THREADS") != NULL) {
        num_threads = atoi(getenv("GLT_NUM_THREADS"));
    }

    int num_pools = num_threads;

    if (getenv("GLT_NUM_POOLS") != NULL) {
        num_pools = atoi(getenv("GLT_NUM_POOLS"));
    }

    CHECK(ABT_xstream_self(&main_team->master),ABT_SUCCESS);

    main_team->num_xstreams = num_threads;
    main_team->num_pools = num_pools;
    main_team->max_elem = get_nprocs();
    main_team->team = (ABT_xstream *) malloc(sizeof (ABT_xstream) * num_threads);//main_team->max_elem);
    main_team->pools = (ABT_pool *) malloc(sizeof (ABT_pool) * num_pools);//main_team->max_elem);

    for (int i = 0; i < num_pools; i++) {
        CHECK(ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE,
                &main_team->pools[i]),ABT_SUCCESS);
    }

    CHECK(ABT_xstream_self(&main_team->team[0]),ABT_SUCCESS);
    CHECK(ABT_xstream_set_main_sched_basic(main_team->team[0], ABT_SCHED_DEFAULT,
            1, &main_team->pools[0]),ABT_SUCCESS);

    for (int i = 1; i < num_threads; i++) {
        CHECK(ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1,
                &main_team->pools[i % main_team->num_pools],
                ABT_SCHED_CONFIG_NULL, &main_team->team[i]),ABT_SUCCESS);
        CHECK(ABT_xstream_start(main_team->team[i]),ABT_SUCCESS);
    }
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    if (argc != 5) {
        printf("Usage: %s <max # of ESs> <timeout> <server> <port>\n", argv[0]);
        return EXIT_SUCCESS;
    }

    max_xstreams = atoi(argv[1]);
    if (max_xstreams < 1) {
        max_xstreams = 1;
    }
    num_xstreams = max_xstreams;

    g_timeout = atof(argv[2]);

    printf("# of ESs  : %d\n", max_xstreams);
    printf("Timeout   : %.1f sec.\n", g_timeout);

    abt_connect(argv[3], argv[4]);

    /* Initialize */
    ABT_init(argc, argv);

    init(num_xstreams);

    thread_add_sched((void *)0);

    finalize();

    /* Finalize */
    ABT_finalize();

    abt_disconnect();

    printf("Done.\n"); fflush(stdout);

    return EXIT_SUCCESS;
}
Esempio n. 5
0
/* 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;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    int i, provided;
    int ret;
    int num_threads = DEFAULT_NUM_THREADS;
    if (argc > 1)
        num_threads = atoi(argv[1]);
    if (num_threads % 2 != 0) {
        if (rank == 0)
            printf("number of user level threads should be even\n");
        exit(0);
    }
    assert(num_threads >= 0);
    num_loop = NUM_LOOP;
    if (argc > 2)
        num_loop = atoi(argv[2]);
    assert(num_loop >= 0);
    buf_size = BUF_SIZE;
    if (argc > 3)
        buf_size = atoi(argv[3]);
    assert(buf_size >= 0);

    /* Initialize */
    ret = ABT_init(argc, argv);
    if (ret != ABT_SUCCESS) {
        printf("Failed to initialize Argobots\n");
        return EXIT_FAILURE;
    }

    ret = MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
    if (provided != MPI_THREAD_MULTIPLE) {
        printf("Cannot initialize with MPI_THREAD_MULTIPLE\n");
        return EXIT_FAILURE;
    }

    send_buf = (int *) malloc(buf_size * sizeof(int));
    recv_buf = (int *) malloc(buf_size * sizeof(int));

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    if (profiling)
        t1 = MPI_Wtime();
    ABT_xstream xstream;
    ABT_pool pools;
    ABT_thread *threads = (ABT_thread *) malloc(num_threads * sizeof(ABT_thread));

    ABT_xstream_self(&xstream);
    ABT_xstream_get_main_pools(xstream, 1, &pools);
    for (i = 0; i < num_threads; i++) {
        size_t tid = i + 1;
        if (i % 2 == 0) {
            ret = ABT_thread_create(pools,
                                    thread_send_func, (void *) tid,
                                    ABT_THREAD_ATTR_NULL, &threads[i]);
        } else {
            ret = ABT_thread_create(pools,
                                    thread_recv_func, (void *) tid,
                                    ABT_THREAD_ATTR_NULL, &threads[i]);
        }
        HANDLE_ERROR(ret, "ABT_thread_create");
    }

    /* Join and free the ULT children */
    for (i = 0; i < num_threads; i++)
        ABT_thread_free(&threads[i]);

    if (profiling) {
        t2 = MPI_Wtime();
        if (rank == 0) {
            fprintf(stdout, "%*s%*f\n", FIELD_WIDTH, "Time", FIELD_WIDTH, t2 - t1);
        }
    }

    /* Finalize */
    free(threads);
    free(send_buf);
    free(recv_buf);
    MPI_Finalize();
    ABT_finalize();
    return EXIT_SUCCESS;
}
Esempio n. 7
0
void
__kmp_global_initialize(void)
{
    int i;
    int status;

    /* Initialize Argobots before other initializations. */
    status = ABT_init(0, NULL);
    KMP_CHECK_SYSFAIL( "ABT_init", status );

    __kmp_global.g = { 0 };

    /* --------------------------------------------------------------------------- */
    /* map OMP 3.0 schedule types with our internal schedule types */
    static sched_type sch_map[ kmp_sched_upper - kmp_sched_lower_ext + kmp_sched_upper_std - kmp_sched_lower - 2 ] = {
        kmp_sch_static_chunked,     // ==> kmp_sched_static            = 1
        kmp_sch_dynamic_chunked,    // ==> kmp_sched_dynamic           = 2
        kmp_sch_guided_chunked,     // ==> kmp_sched_guided            = 3
        kmp_sch_auto,               // ==> kmp_sched_auto              = 4
        kmp_sch_trapezoidal         // ==> kmp_sched_trapezoidal       = 101
                                    // will likely not used, introduced here just to debug the code
                                    // of public intel extension schedules
    };
    KMP_MEMCPY(__kmp_global.sch_map, sch_map, sizeof(sch_map));

#if OMP_40_ENABLED
    __kmp_global.nested_proc_bind = { NULL, 0, 0 };
    __kmp_global.affinity_num_places = 0;
#endif

    __kmp_global.place_num_sockets = 0;
    __kmp_global.place_socket_offset = 0;
    __kmp_global.place_num_cores = 0;
    __kmp_global.place_core_offset = 0;
    __kmp_global.place_num_threads_per_core = 0;

    __kmp_global.tasking_mode = tskm_task_teams;
    __kmp_global.task_stealing_constraint = 1;   /* Constrain task stealing by default */
#if OMP_41_ENABLED
    __kmp_global.max_task_priority = 0;
#endif

    __kmp_global.settings = FALSE;
    __kmp_global.duplicate_library_ok = 0;
    __kmp_global.force_reduction_method = reduction_method_not_defined;
    __kmp_global.determ_red = FALSE;

    __kmp_global.cpuinfo = { 0 };

    /* ------------------------------------------------------------------------ */

    __kmp_global.init_serial   = FALSE;
    __kmp_global.init_gtid     = FALSE;
    __kmp_global.init_common   = FALSE;
    __kmp_global.init_middle   = FALSE;
    __kmp_global.init_parallel = FALSE;
    __kmp_global.init_runtime  = FALSE;

    __kmp_global.init_counter = 0;
    __kmp_global.root_counter = 0;
    __kmp_global.version = 0;

    /* list of address of allocated caches for commons */
    __kmp_global.threadpriv_cache_list = NULL;

    /* Global Locks */
    ABT_mutex_create(&__kmp_global.stdio_lock);
    ABT_mutex_create(&__kmp_global.cat_lock);
    ABT_mutex_create(&__kmp_global.initz_lock);
    ABT_mutex_create(&__kmp_global.task_team_lock);
    for (i = 0; i < KMP_NUM_CRIT_LOCKS; i++) {
        ABT_mutex_create(&__kmp_global.crit_lock[i]);
    }

    __kmp_global.library = library_none;
    __kmp_global.sched = kmp_sch_default;  /* scheduling method for runtime scheduling */
    __kmp_global.sched_static = kmp_sch_static_greedy; /* default static scheduling method */
    __kmp_global.sched_guided = kmp_sch_guided_iterative_chunked; /* default guided scheduling method */
    __kmp_global.sched_auto = kmp_sch_guided_analytical_chunked; /* default auto scheduling method */
    __kmp_global.chunk = 0;

    __kmp_global.stksize    = KMP_DEFAULT_STKSIZE;
    __kmp_global.stkoffset  = KMP_DEFAULT_STKOFFSET;
    __kmp_global.stkpadding = KMP_MIN_STKPADDING;

    __kmp_global.malloc_pool_incr  = KMP_DEFAULT_MALLOC_POOL_INCR;
    __kmp_global.env_chunk       = FALSE;  /* KMP_CHUNK specified?     */
    __kmp_global.env_stksize     = FALSE;  /* KMP_STACKSIZE specified? */
    __kmp_global.env_omp_stksize = FALSE;  /* OMP_STACKSIZE specified? */
    __kmp_global.env_all_threads     = FALSE;/* KMP_ALL_THREADS or KMP_MAX_THREADS specified? */
    __kmp_global.env_omp_all_threads = FALSE;/* OMP_THREAD_LIMIT specified? */
    __kmp_global.env_checks      = FALSE;  /* KMP_CHECKS specified?    */
    __kmp_global.env_consistency_check  = FALSE;  /* KMP_CONSISTENCY_CHECK specified? */
    __kmp_global.generate_warnings = kmp_warnings_low;
    __kmp_global.reserve_warn = 0;

#ifdef DEBUG_SUSPEND
    __kmp_global.suspend_count = 0;
#endif

    /* ------------------------------------------------------------------------- */

    __kmp_global.allThreadsSpecified = 0;

    __kmp_global.align_alloc = CACHE_LINE;

    __kmp_global.xproc = 0;
    __kmp_global.avail_proc = 0;
    __kmp_global.sys_min_stksize = KMP_MIN_STKSIZE;
    __kmp_global.sys_max_nth = KMP_MAX_NTH;
    __kmp_global.max_nth = 0;
    __kmp_global.threads_capacity = 0;
    __kmp_global.dflt_team_nth = 0;
    __kmp_global.dflt_team_nth_ub = 0;
    __kmp_global.tp_capacity = 0;
    __kmp_global.tp_cached = 0;
    __kmp_global.dflt_nested = TRUE;
    __kmp_global.dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT; /* max_active_levels limit */
#ifdef KMP_DFLT_NTH_CORES
    __kmp_global.ncores = 0;
#endif
    __kmp_global.abort_delay = 0;

    /* Initialize the library data structures when we fork a child process, defaults to TRUE */
    __kmp_global.need_register_atfork = TRUE; /* At initialization, call pthread_atfork to install fork handler */
    __kmp_global.need_register_atfork_specified = TRUE;

    __kmp_global.tls_gtid_min = INT_MAX;
    __kmp_global.foreign_tp = TRUE;
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
    __kmp_global.inherit_fp_control = TRUE;
    __kmp_global.init_x87_fpu_control_word = 0;
    __kmp_global.init_mxcsr = 0;
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */

#if KMP_NESTED_HOT_TEAMS
    __kmp_global.hot_teams_mode      = 0; /* 0 - free extra threads when reduced */
                                          /* 1 - keep extra threads when reduced */
    __kmp_global.hot_teams_max_level = 1; /* nesting level of hot teams */
#endif

#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
    __kmp_global.mic_type = non_mic;
#endif

#ifdef USE_LOAD_BALANCE
    __kmp_global.load_balance_interval   = 1.0;
#endif /* USE_LOAD_BALANCE */

    __kmp_global.nested_nth = { NULL, 0, 0 };

#if OMP_40_ENABLED
    __kmp_global.display_env           = FALSE;
    __kmp_global.display_env_verbose   = FALSE;
    __kmp_global.omp_cancellation      = FALSE;
#endif

    /* ------------------------------------------------------ */
    /* STATE mostly syncronized with global lock */
    /* data written to rarely by masters, read often by workers */
    __kmp_global.threads = NULL;
    __kmp_global.team_pool = NULL;
    __kmp_global.thread_pool = NULL;

    /* data read/written to often by masters */
    __kmp_global.nth = 0;
    __kmp_global.all_nth = 0;
    __kmp_global.thread_pool_nth = 0;
    __kmp_global.thread_pool_active_nth = 0;

    __kmp_global.root = NULL;
    /* ------------------------------------------------------ */

    __kmp_init_global = TRUE;
}
Esempio n. 8
0
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, 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;
}
Esempio n. 11
0
void accalt_init(int argc, char * argv[]) {

    int num_threads = 1;
    main_team = (accalt_team_t *) malloc(sizeof (accalt_team_t));

#ifdef ARGOBOTS


    ABT_init(argc, argv);
    int num_pools = 1;
    if (getenv("ACCALT_NUM_THREADS") != NULL) {
        num_threads = atoi(getenv("ACCALT_NUM_THREADS"));
    }
    if (getenv("ACCALT_NUM_POOLS") != NULL) {
        num_pools = atoi(getenv("ACCALT_NUM_POOLS"));
    }
    main_team->num_xstreams = num_threads;
    main_team->num_pools = num_pools;
    //printf("Argobots %d ES, %d Pools\n", num_threads, num_pools);
    ABT_xstream_self(&main_team->master);

    main_team->team = (ABT_xstream *) malloc(sizeof (ABT_xstream) * num_threads);
    main_team->pools = (ABT_pool *) malloc(sizeof (ABT_pool) * num_pools);

    for (int i = 0; i < num_pools; i++) {
        ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE,
                &main_team->pools[i]);
    }

    ABT_xstream_self(&main_team->team[0]);
    ABT_xstream_set_main_sched_basic(main_team->team[0], ABT_SCHED_DEFAULT,
            1, &main_team->pools[0]);
    for (int i = 1; i < num_threads; i++) {
        ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1,
                &main_team->pools[i % main_team->num_pools],
                ABT_SCHED_CONFIG_NULL, &main_team->team[i]);
        ABT_xstream_start(main_team->team[i]);
    }
#endif
#ifdef MASSIVETHREADS
    char buff[10];
    if (getenv("ACCALT_NUM_THREADS") != NULL) {
        num_threads = atoi(getenv("ACCALT_NUM_THREADS"));
        sprintf(buff, "%d", num_threads);
        setenv("MYTH_WORKER_NUM", buff, 1);
    } else
        num_threads = atoi(getenv("MYTH_WORKER_NUM"));

    setenv("MYTH_BIND_WORKERS", "1", 1);

    //printf("Massive %d Workers\n", num_threads);
    main_team->num_workers = num_threads;
    myth_init(); //MassiveThreads
#endif
#ifdef QTHREADS
    char buff[10];
    int num_workers_per_thread;
    if (getenv("ACCALT_NUM_THREADS") != NULL) {
        num_threads = atoi(getenv("ACCALT_NUM_THREADS"));
        sprintf(buff, "%d", num_threads);
        setenv("QTHREAD_NUM_SHEPHERDS", buff, 1);
    } else
        num_threads = atoi(getenv("QTHREAD_NUM_SHEPHERDS"));

    if (getenv("ACCALT_NUM_WORKERS_PER_THREAD") != NULL) {
        num_workers_per_thread = atoi(getenv("ACCALT_NUM_WORKERS_PER_THREAD"));
        sprintf(buff, "%d", num_workers_per_thread);
        setenv("QTHREAD_NUM_WORKERS_PER_SHEPHERD", buff, 1);
    } else
        num_workers_per_thread = atoi(getenv("QTHREAD_NUM_WORKERS_PER_SHEPHERD"));
    if (num_threads == 1 && num_workers_per_thread > 1) {
        setenv("QTHREAD_SHEPHERDS_BOUNDARY", "node", 1);
        setenv("QTHREAD_WORKER_UNIT", "core", 1);
    }
    if (num_threads > 1) {
        setenv("QTHREAD_SHEPHERDS_BOUNDARY", "core", 1);
        setenv("QTHREAD_WORKER_UNIT", "core", 1);
    }
    setenv("QTHREAD_AFFINITY", "yes", 1);

    //printf("Qthreads %d Shepherds, %d Workers_per_shepherd\n", num_threads, num_workers_per_thread);

    main_team->num_shepherds = num_threads;
    main_team->num_workers_per_shepherd = num_workers_per_thread;
    qthread_initialize(); //qthreads
#endif
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
  // Argobots definitions
  int ret, i;
  num_threads = 0;

  // Sockets Definitions
  int fd, cfd;
  struct sockaddr_in svaddr;
  struct sockaddr_storage claddr;
  socklen_t addrlen;
  signal(SIGINT, sighandler);

  ABT_init(argc, argv);

  int abts = 0;//ABT_snoozer_xstream_self_set();
  if (abts != 0){
    fprintf(stderr, "%s\n", "ABT snoozer xstream self error");
    exit(-1);
  }
  xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * CORES);
  ret = ABT_xstream_self(&xstreams[0]);
  if(ret != 0){
    fprintf(stderr, "%s\n", "ABT xstream self error");
    exit(-1);
  }
  ret = ABT_xstream_get_main_pools(xstreams[0], 1, &pool);
  if(ret != 0){
    fprintf(stderr, "%s\n", "ABT xstream pool error");
    exit(-1);
  }
  ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &g_pool);

  /* ES creation */
  ABT_xstream_self(&xstreams[0]);
  ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT,
                                   1, &g_pool);
  for (i = 1; i < CORES; i++) {
      ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool,
                               ABT_SCHED_CONFIG_NULL, &xstreams[i]);
      ABT_xstream_start(xstreams[i]);
  }
  //abtio = abt_io_init(CORES);
  //assert(abtio != NULL);

  fd = socket(AF_INET, SOCK_STREAM, 0);
  if(fd < 0){
    fprintf(stderr, "%s\n", "Socket creating error");
    exit(-1);
  }
  memset(&svaddr, 0, sizeof(struct sockaddr_in));
  svaddr.sin_family = AF_INET;
  svaddr.sin_addr.s_addr = INADDR_ANY;
  svaddr.sin_port = htons(PORTNUM);

  ret = bind(fd, (struct sockaddr *) &svaddr, sizeof(struct sockaddr_in));
  if(ret < 0){
    fprintf(stderr, "%s\n", "Socket binding error");
    exit(-1);
  }
  if( listen(fd, BACKLOG) == -1)
  {
    fprintf(stderr, "%s\n", "Socket listening error");
    exit(-1);
  }
  int aio_sock =  abt_io_socket_initialize(1000);
  if(aio_sock <= 0)
    printf("Initialize io_sock error\n");
  //printf("USer: main: epoll fd = %d\n", aio_sock);
  addrlen = sizeof(struct sockaddr_storage);
  while(1){
    cfd = accept(fd, (struct sockaddr *)&claddr, &addrlen);
    if(cfd == -1){
      fprintf(stderr, "%s\n", "Socket accepting error");
      exit(-1);
    }
    //printf("accepted client on file descriptor %d\n", cfd);
    struct thread_args* ta = (struct thread_args*) malloc (sizeof(ta));
    ta->epfd = aio_sock;
    ta->fd = cfd;
    ABT_thread_create(g_pool, handle_client, (void *) ta, ABT_THREAD_ATTR_NULL, threads[num_threads++]);
  }

  return 0;
}
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;
}