Example #1
0
void entrypoint(void *arg) {

    int n_asyncs = 5;
    int *count = (int *)malloc(sizeof(int));
    assert(count);
    *count = 0;

    hclib_start_finish();
    int i;
    hclib_future_t *prev = NULL;
    for (i = 0; i < n_asyncs; i++) {
        if (prev) {
            hclib_future_t **future_list = (hclib_future_t **)malloc(
                    2 * sizeof(hclib_future_t *));
            assert(future_list);
            future_list[0] = prev;
            future_list[1] = NULL;
            prev = hclib_async_future(async_fct, count, future_list, NULL,
                    NULL, NO_PROP);
        } else {
            prev = hclib_async_future(async_fct, count, NULL, NULL, NULL,
                    NO_PROP);
        }
    }
    hclib_end_finish();

    assert(*count == n_asyncs);
}
Example #2
0
hclib_future_t *hclib_forasync_future(void *forasync_fct, void *argv,
                                      int dim, hclib_loop_domain_t *domain,
                                      forasync_mode_t mode) {

    hclib_start_finish();
    hclib_forasync(forasync_fct, argv, dim, domain, mode);
    return hclib_end_finish_nonblocking();
}
Example #3
0
static void pragma46_omp_task_hclib_async(void *____arg) {
    pragma46_omp_task *ctx = (pragma46_omp_task *)____arg;
    int n; n = ctx->n;
    hclib_start_finish();
(*(ctx->y_ptr)) = fib(n - 2) ;     ; hclib_end_finish_nonblocking();

    free(____arg);
}
Example #4
0
static void pragma147_omp_task_hclib_async(void *____arg) {
    pragma147_omp_task *ctx = (pragma147_omp_task *)____arg;
    hclib_start_finish();
{
              par_sort((*(ctx->buf_ptr)));
          } ;     ; hclib_end_finish();

    free(____arg);
}
Example #5
0
static void main_entrypoint(void *____arg) {
    main_entrypoint_ctx *ctx = (main_entrypoint_ctx *)____arg;
    int n; n = ctx->n;
{
hclib_start_finish(); {
                par_res = fib(n);
            } ; hclib_end_finish(); 
    } ;     free(____arg);
}
Example #6
0
static void pragma26_omp_task_hclib_async(void *____arg) {
    pragma26_omp_task *ctx = (pragma26_omp_task *)____arg;
    int block_x; block_x = ctx->block_x;
    int block_y; block_y = ctx->block_y;
    hclib_start_finish();
copy_block((*(ctx->nx_ptr)), (*(ctx->ny_ptr)), block_x, block_y, (*(ctx->u__ptr)), (*(ctx->unew__ptr)), (*(ctx->block_size_ptr))) ;     ; hclib_end_finish_nonblocking();

    free(____arg);
}
Example #7
0
void shmem_hclib_end_finish() {
  hclib_end_finish();
  /*
   * In HC-OpenSHMEM, there is no start_finish equivalent call. 
   * The end_finish is called everytime user will call shmem_fence/shmem_barrier etc.
   * Once the end_finish (implicitely) is called from HC-OpenSHMEM, 
   * a new start_finish scope is started to pair with
   * the hclib_end_finish implicitely called at the end of user_main.
   */
  hclib_start_finish();
}
Example #8
0
void entrypoint(void *arg) {
    volatile int * indices = (int *) malloc(sizeof(int)*NB_ASYNC);
    ran = (int *) malloc(sizeof(int)*NB_ASYNC);
    init_ran(ran, NB_ASYNC);

    hclib_start_finish();

    spawn_async(indices, 0);

    hclib_end_finish();

    printf("Call Finalize\n");
}
Example #9
0
void spawn_async(volatile int * indices, int i) {
    if (i < NB_ASYNC) {
        hclib_start_finish();

        indices[i] = i;
        hclib_async(async_fct, (void*) (indices+i), NO_FUTURE, NO_PHASER,
                ANY_PLACE, NO_PROP);
        spawn_async(indices, i+1);

        hclib_end_finish();
        assert_done(i, i+1);
    }
}
Example #10
0
// this would go away once hclib fibre support is fixed for communication worker
void temporary_wrapper(void* entrypoint) {
  /*
   * In HC-OpenSHMEM, there is no start_finish equivalent call.
   * The end_finish is called everytime user will call shmem_fence/shmem_barrier etc.
   * Once the end_finish (implicitely) is called from HC-OpenSHMEM,
   * a new start_finish scope is started to pair with
   * the hclib_end_finish implicitely called at the end of user_main.
   */
  hclib_start_finish();
  asyncFct_t funcPtr = (asyncFct_t) entrypoint;
  funcPtr(NULL);
  hclib_end_finish();
}
Example #11
0
void par_sort(void* arg) {
  sort_data_t *in = (sort_data_t*) arg;
  TYPE* data = in->buffer;
  int left = in->left; 
  int right = in->right;

  if (right - left + 1 > HC_GRANULARITY) {
    int index = partition(data, left, right);
hclib_start_finish(); {
        if (left < index - 1) {
          sort_data_t* buf = (sort_data_t*) malloc(sizeof(sort_data_t)); 
          buf->buffer = data;
          buf->left = left;
          buf->right = index - 1; 
 { 
pragma137_omp_task *new_ctx = (pragma137_omp_task *)malloc(sizeof(pragma137_omp_task));
new_ctx->buf_ptr = &(buf);
new_ctx->index_ptr = &(index);
new_ctx->in_ptr = &(in);
new_ctx->data_ptr = &(data);
new_ctx->left_ptr = &(left);
new_ctx->right_ptr = &(right);
new_ctx->arg_ptr = &(arg);
hclib_async(pragma137_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } 
        }
        if (index < right) {
          sort_data_t* buf = (sort_data_t*) malloc(sizeof(sort_data_t)); 
          buf->buffer = data;
          buf->left = index;
          buf->right = right; 
 { 
pragma147_omp_task *new_ctx = (pragma147_omp_task *)malloc(sizeof(pragma147_omp_task));
new_ctx->buf_ptr = &(buf);
new_ctx->index_ptr = &(index);
new_ctx->in_ptr = &(in);
new_ctx->data_ptr = &(data);
new_ctx->left_ptr = &(left);
new_ctx->right_ptr = &(right);
new_ctx->arg_ptr = &(arg);
hclib_async(pragma147_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } 
        }
        } ; hclib_end_finish(); 
  }
  else {
    //  quicksort in C library
    qsort(data+left, right - left + 1, sizeof(TYPE), compare);
  }
  free(arg);
} 
Example #12
0
static void main_entrypoint(void *____arg) {
    main_entrypoint_ctx *ctx = (main_entrypoint_ctx *)____arg;
    int size; size = ctx->size;
{
	total_count=0;

        bots_message("Computing N-Queens algorithm (n=%d) ", size);
hclib_start_finish(); {
			char *a;

			a = (char *)malloc(size * sizeof(char));
			nqueens(size, 0, a, &total_count,0);
		} ; hclib_end_finish(); 
	bots_message(" completed!\n");
    } ;     free(____arg);
}
Example #13
0
void entrypoint(void *arg) {
    int *ran = (int *)arg;
    // This is ok to have these on stack because this
    // code is alive until the end of the program.

    init_ran(ran, H1*H2);
    loop_domain_t loop0 = {0,H1,1,T1};
    loop_domain_t loop1 = {0,H2,1,T2};
    loop_domain_t loop[2] = {loop0, loop1};

    hclib_start_finish();
    hclib_forasync(forasync_fct2, (void*)(ran), NULL, 2, loop,
            FORASYNC_MODE_RECURSIVE);
    hclib_end_finish();

    printf("Call Finalize\n");
}
Example #14
0
void entrypoint(void *arg) {

    int n_asyncs = 5;
    int *count = (int *)malloc(sizeof(int));
    assert(count);
    *count = 0;

    hclib_start_finish();
    int i;
    hclib_future_t *prev = NULL;
    for (i = 0; i < n_asyncs; i++) {
        if (prev) {
            prev = hclib_async_future(async_fct, count, &prev, 1, NULL);
        } else {
            prev = hclib_async_future(async_fct, count, NULL, 0, NULL);
        }
    }
    hclib_end_finish();

    assert(*count == n_asyncs);
}
Example #15
0
static void pragma126_omp_task_hclib_async(void *____arg) {
    pragma126_omp_task *ctx = (pragma126_omp_task *)____arg;
    int (*csols); csols = ctx->csols;
    int i; i = ctx->i;
    int n; n = ctx->n;
    int j; j = ctx->j;
    char (*a); a = ctx->a;
    int (*solutions); solutions = ctx->solutions;
    int depth; depth = ctx->depth;
    hclib_start_finish();
{
	  		/* allocate a temporary array and copy <a> into it */
	  		char * b = (char *)malloc(n * sizeof(char));
	  		memcpy(b, a, j * sizeof(char));
	  		b[j] = (char) i;
	  		if (ok(j + 1, b))
       				nqueens(n, j + 1, b,&csols[i],depth); //FIXME: depth or depth+1 ???
		} ;     ; hclib_end_finish_nonblocking();

    free(____arg);
}
Example #16
0
long long fib (int n)
{
	long long x, y;
	if (n < 2) return n;

 { 
pragma44_omp_task *new_ctx = (pragma44_omp_task *)malloc(sizeof(pragma44_omp_task));
new_ctx->x_ptr = &(x);
new_ctx->y_ptr = &(y);
new_ctx->n = n;
hclib_async(pragma44_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } ;
 { 
pragma46_omp_task *new_ctx = (pragma46_omp_task *)malloc(sizeof(pragma46_omp_task));
new_ctx->x_ptr = &(x);
new_ctx->y_ptr = &(y);
new_ctx->n = n;
hclib_async(pragma46_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } ;

 hclib_end_finish(); hclib_start_finish(); ;
	return x + y;
} 
Example #17
0
void nqueens(int n, int j, char *a, int *solutions, int depth)
{
	int *csols;
	int i;


	if (n == j) {
		/* good solution, count it */
		*solutions = 1;
		return;
	}


	*solutions = 0;
	csols = (int *)malloc(n*sizeof(int));
	memset(csols,0,n*sizeof(int));

     	/* try each possible position for queen <j> */
	for (i = 0; i < n; i++) {

 { 
pragma126_omp_task *new_ctx = (pragma126_omp_task *)malloc(sizeof(pragma126_omp_task));
new_ctx->csols = csols;
new_ctx->i = i;
new_ctx->n = n;
new_ctx->j = j;
new_ctx->a = a;
new_ctx->solutions = solutions;
new_ctx->depth = depth;
hclib_async(pragma126_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } 
	}

 hclib_end_finish(); hclib_start_finish(); ;
	for ( i = 0; i < n; i++) *solutions += csols[i];
    free(csols);
} 
Example #18
0
void sweep (int nx, int ny, double dx, double dy, double *f_,
            int itold, int itnew, double *u_, double *unew_, int block_size)
{
    int it;
    int block_x, block_y;

    if (block_size == 0)
        block_size = nx;

    int max_blocks_x = (nx / block_size);
    int max_blocks_y = (ny / block_size);

hclib_start_finish(); {
        for (it = itold + 1; it <= itnew; it++) {
            // Save the current estimate.
            for (block_x = 0; block_x < max_blocks_x; block_x++) {
                for (block_y = 0; block_y < max_blocks_y; block_y++) {
 { 
pragma26_omp_task *new_ctx = (pragma26_omp_task *)malloc(sizeof(pragma26_omp_task));
new_ctx->it_ptr = &(it);
new_ctx->block_x = block_x;
new_ctx->block_y = block_y;
new_ctx->max_blocks_x_ptr = &(max_blocks_x);
new_ctx->max_blocks_y_ptr = &(max_blocks_y);
new_ctx->nx_ptr = &(nx);
new_ctx->ny_ptr = &(ny);
new_ctx->dx_ptr = &(dx);
new_ctx->dy_ptr = &(dy);
new_ctx->f__ptr = &(f_);
new_ctx->itold_ptr = &(itold);
new_ctx->itnew_ptr = &(itnew);
new_ctx->u__ptr = &(u_);
new_ctx->unew__ptr = &(unew_);
new_ctx->block_size_ptr = &(block_size);
hclib_async(pragma26_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } ;
                }
            }

 hclib_end_finish(); hclib_start_finish(); ;

            // Compute a new estimate.
            for (block_x = 0; block_x < max_blocks_x; block_x++) {
                for (block_y = 0; block_y < max_blocks_y; block_y++) {
 { 
pragma36_omp_task *new_ctx = (pragma36_omp_task *)malloc(sizeof(pragma36_omp_task));
new_ctx->block_x = block_x;
new_ctx->block_y = block_y;
new_ctx->nx_ptr = &(nx);
new_ctx->ny_ptr = &(ny);
new_ctx->dx_ptr = &(dx);
new_ctx->dy_ptr = &(dy);
new_ctx->f__ptr = &(f_);
new_ctx->u__ptr = &(u_);
new_ctx->unew__ptr = &(unew_);
new_ctx->block_size_ptr = &(block_size);
hclib_async(pragma36_omp_task_hclib_async, new_ctx, NO_FUTURE, ANY_PLACE);
 } ;
                }
            }

 hclib_end_finish(); hclib_start_finish(); ;
        }
    } ; hclib_end_finish(); 
} 
Example #19
0
void shmem_task_scope_begin() {
  hclib_start_finish(); 
}
Example #20
0
volatile int *hclib_start_finish_special() {
    hclib_start_finish();
    hclib_worker_state *ws = CURRENT_WS_INTERNAL;
    return &(ws->current_finish->counter);
}
Example #21
0
static void hclib_entrypoint(const char **module_dependencies,
        const int n_module_dependencies, const int instrument) {
    /*
     * Assert that the completion flag structures are each on separate cache
     * lines.
     */
    HASSERT(sizeof(worker_done_t) == 64);

    load_dependencies(module_dependencies, n_module_dependencies);

    hclib_call_module_pre_init_functions();

    srand(0);

    hc_context = (hclib_context *)malloc(sizeof(hclib_context));
    HASSERT(hc_context);

    /*
     * Parse the platform description from the HPT configuration file and load
     * it into the hclib_context.
     */
    hclib_global_init();

    // Initialize any registered modules
    hclib_call_module_post_init_functions();

    // init timer stats
    hclib_init_stats(0, hc_context->nworkers);

    if (instrument) {
        initialize_instrumentation(hc_context->nworkers);
    }

    /* Create key to store per thread worker_state */
    if (pthread_key_create(&ws_key, NULL) != 0) {
        log_die("Cannot create ws_key for worker-specific data");
    }

    /*
     * set pthread's concurrency. Doesn't seem to do much on Linux, only
     * relevant when there are more pthreads than hardware cores to schedule
     * them on. */
    pthread_setconcurrency(hc_context->nworkers);

#ifdef HCLIB_STATS
    worker_stats = (per_worker_stats *)calloc(hc_context->nworkers,
            sizeof(*worker_stats));
    HASSERT(worker_stats);
    for (int i = 0; i < hc_context->nworkers; i++) {
        worker_stats[i].stolen_tasks_per_thread = (size_t *)calloc(
                hc_context->nworkers, sizeof(size_t));
        HASSERT(worker_stats[i].stolen_tasks_per_thread);
    }
#endif

    // Launch the worker threads
    pthread_attr_t attr;
    if (pthread_attr_init(&attr) != 0) {
        fprintf(stderr, "Error in pthread_attr_init\n");
        exit(3);
    }

    create_hwloc_cpusets();

    // Start workers
    for (int i = 1; i < hc_context->nworkers; i++) {
        if (pthread_create(&hc_context->workers[i]->t, &attr, worker_routine,
                           &hc_context->workers[i]->id) != 0) {
            fprintf(stderr, "Error launching thread\n");
            exit(4);
        }

    }
    set_current_worker(0);

    set_up_worker_thread_affinities(0);

    const unsigned dist_id = hclib_register_dist_func(default_dist_func);
    HASSERT(dist_id == HCLIB_DEFAULT_LOOP_DIST);

    // allocate root finish
    hclib_start_finish();
}