Beispiel #1
0
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);
    }
}
/* 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;
}
/* 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;
}
Beispiel #5
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
}
Beispiel #6
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;
}