Esempio n. 1
0
static int _delete_handler(const hpx_addr_t * const lcos, size_t n) {
  hpx_lco_wait(lcos[2]);
  hpx_lco_delete(lcos[2], HPX_NULL);
  hpx_lco_delete(lcos[0], HPX_NULL);
  hpx_lco_set(lcos[1], 0, NULL, HPX_NULL, HPX_NULL);
  return HPX_SUCCESS;
}
Esempio n. 2
0
/// A utility that tests a certain leaf function through I iterations.
static int _benchmark(char *name, hpx_action_t op, int iters, size_t size) {
  int ranks = HPX_LOCALITIES * HPX_THREADS;
  hpx_addr_t allreduce = hpx_lco_allreduce_new(ranks, ranks, size, _init, _min);
  hpx_addr_t done = hpx_lco_and_new(ranks);
  hpx_time_t start = hpx_time_now();
  hpx_bcast(_fill_node, HPX_NULL, HPX_NULL, &op, &done, &allreduce, &iters, &size);
  hpx_lco_wait(done);
  double elapsed = hpx_time_elapsed_ms(start);
  hpx_lco_delete(allreduce, HPX_NULL);
  hpx_lco_delete(done, HPX_NULL);
  printf("%s: %.7f\n", name, elapsed/iters);
  return HPX_SUCCESS;
}
/// A utility that tests a certain leaf function through I iterations.
static int _test(hpx_action_t leaf) {
  int L = HPX_LOCALITIES;
  int n = N * L;
  hpx_addr_t allreduce = hpx_lco_allreduce_new(n, n, sizeof(int), _init, _sum);
  hpx_addr_t sum = hpx_lco_reduce_new(n, sizeof(int), _init, _sum);
  for (int i = 0; i < I; ++i) {
    int r;
    CHECK( hpx_bcast(_test_bcast, HPX_NULL, HPX_NULL, &allreduce, &sum, &leaf) );
    CHECK( hpx_lco_get_reset(sum, sizeof(r), &r) );
    test_assert(r == n * HPX_LOCALITIES * (N + 1) * N / 2);
  }
  hpx_lco_delete(sum, HPX_NULL);
  hpx_lco_delete(allreduce, HPX_NULL);
  return HPX_SUCCESS;
}
Esempio n. 4
0
static int _jacobi_main_handler(int n, int nsteps) {

  double h = 1.0/n;

  // allocate and initialize arrays 
  hpx_addr_t u = hpx_gas_calloc_local_attr((n+1), BSIZE, 0, HPX_GAS_ATTR_LB);
  hpx_addr_t f = hpx_gas_alloc_local((n+1), BSIZE, 0);
  hpx_addr_t and = hpx_lco_and_new(n+1);
  for (int i = 0; i <= n; ++i) {
    double val = i*h;
    hpx_gas_memput_lsync(IDX(f,i), &val, sizeof(val), and);
  }
  hpx_lco_wait(and);
  hpx_lco_delete(and, HPX_NULL);

  printf("starting jacobi iterations...\n");

  hpx_time_t start = hpx_time_now();
  jacobi(n, nsteps, u, f);
  double elapsed = hpx_time_elapsed_ms(start)/1e3;

  // run the solver
  printf("n: %d\n", n);
  printf("nsteps: %d\n", nsteps);
  printf("seconds: %.7f\n", elapsed);

  // write the results
  if (fname) {
    write_solution(n, u, fname);
  }

  hpx_gas_free(f, HPX_NULL);
  hpx_gas_free(u, HPX_NULL);
  hpx_exit(HPX_SUCCESS);
}
Esempio n. 5
0
int _hpx_process_call(hpx_addr_t process, hpx_addr_t addr, hpx_action_t id,
                      hpx_addr_t result, int n, ...) {
  va_list args;
  va_start(args, n);
  hpx_action_t set = hpx_lco_set_action;
  hpx_parcel_t  *p = action_new_parcel_va(id, addr, result, set, n, &args);
  va_end(args);

  if (hpx_thread_current_pid() == hpx_process_getpid(process)) {
    hpx_parcel_send_sync(p);
    return HPX_SUCCESS;
  }

  hpx_addr_t sync = hpx_lco_future_new(0);
  hpx_parcel_t *q = hpx_parcel_acquire(NULL, parcel_size(p));
  q->target = process;
  q->action = _proc_call;
  q->c_target = sync;
  q->c_action = hpx_lco_set_action;
  hpx_parcel_set_data(q, p, parcel_size(p));
  q->pid = 0;
  q->credit = 0;

  EVENT_PROCESS_CALL(process, q->pid);
  hpx_parcel_send_sync(q);

  parcel_delete(p);
  hpx_lco_wait(sync);
  hpx_lco_delete(sync, HPX_NULL);
  return HPX_SUCCESS;
}
Esempio n. 6
0
// Do sweeps of Jacobi iteration on a 1D Poisson problem
// discretized by n+1 equally spaced mesh points on [0,1].
// u is subject to Dirichlet boundary conditions specified in
// the u[0] and u[n] entries of the initial vector.
void jacobi(int nsteps, int n, hpx_addr_t u, hpx_addr_t f) {
  double h  = 1.0/n;
  double h2 = h*h;
  hpx_addr_t utmp = hpx_gas_alloc_local((n+1), BSIZE, 0);

  // fill boundary conditions into utmp
  hpx_gas_memcpy_sync(IDX(utmp,0), IDX(u,0), sizeof(double));
  hpx_gas_memcpy_sync(IDX(utmp,n), IDX(u,n), sizeof(double));

  hpx_addr_t and = hpx_lco_and_new(n-1);
  for (int sweep = 0; sweep < nsteps; sweep += 2) {
    for (int i = 1; i < n; ++i) {
      hpx_xcall(IDX(utmp, i), _op, and, i, h2, u, f);
    }
    hpx_lco_wait_reset(and);

    for (int i = 1; i < n; ++i) {
      hpx_xcall(IDX(u, i), _op, and, i, h2, utmp, f);
    }
    hpx_lco_wait_reset(and);
  }

  hpx_lco_delete(and, HPX_NULL);
  hpx_gas_free(utmp, HPX_NULL);
}
static int thread_cont_action_handler(void) {
  printf("Starting the Thread continue target and action test\n");
  // Start the timer
  hpx_time_t t1 = hpx_time_now();

  hpx_addr_t *cont_and = calloc(hpx_get_num_ranks(), sizeof(hpx_addr_t));

  for (int i = 0; i < hpx_get_num_ranks(); i++) {
    cont_and[i] = hpx_lco_and_new(2);
    hpx_parcel_t *p = hpx_parcel_acquire(NULL, DATA_SIZE);
    hpx_parcel_set_target(p, HPX_THERE(i));
    hpx_parcel_set_action(p, _thread_current_cont_target);
    hpx_parcel_set_cont_target(p, cont_and[i]);
    hpx_parcel_set_cont_action(p, hpx_lco_set_action);
    hpx_parcel_send_sync(p);
    printf("Started index %d.\n", i);
  }

  for (int i = 0; i < hpx_get_num_ranks(); i++) {
    hpx_lco_wait(cont_and[i]);
    printf("Received continuation from %d\n",i);
    hpx_lco_delete(cont_and[i], HPX_NULL);
  }

  free(cont_and);

  printf(" Elapsed: %g\n", hpx_time_elapsed_ms(t1));
  return HPX_SUCCESS;
}
static int lco_error_handler(void) {
  printf("Starting the HPX LCO get all test\n");
  hpx_time_t t1 = hpx_time_now();
  hpx_addr_t lco = hpx_lco_future_new(0);
  hpx_addr_t done = hpx_lco_future_new(0);
  hpx_call(HPX_HERE, _errorset, done, &lco, sizeof(lco));
  hpx_status_t status = hpx_lco_wait(lco);
  printf("status == %d\n", status);
  assert(status == HPX_ERROR);
  hpx_lco_wait(done);

  hpx_lco_delete(lco, HPX_NULL);
  hpx_lco_delete(done, HPX_NULL);

  printf(" Elapsed: %.7f\n", hpx_time_elapsed_ms(t1)/1e3);
  return HPX_SUCCESS;
}
Esempio n. 9
0
static int _test_recursion_top_handler(void) {
  static int DEPTH = 500;
  hpx_addr_t and = hpx_lco_and_new(DEPTH);
  int e = hpx_xcall(HPX_HERE, _test_recursion, and, DEPTH, and);
  if (HPX_SUCCESS == e) {
    e = hpx_lco_wait(and);
  }
  hpx_lco_delete(and, HPX_NULL);
  return e;
}
/// Use the join_async operation in the allreduce leaf.
static int
_join_async_leaf_handler(hpx_addr_t allreduce, int i, int j, hpx_addr_t sum) {
  int r;
  hpx_addr_t f = hpx_lco_future_new(0);
  CHECK( hpx_lco_allreduce_join_async(allreduce, i, sizeof(j), &j, &r, f) );
  CHECK( hpx_lco_wait(f) );
  hpx_lco_delete(f, HPX_NULL);
  test_assert(r == HPX_LOCALITIES * N * (N + 1) / 2);
  return hpx_call_cc(sum, hpx_lco_set_action, &r, sizeof(r));
}
Esempio n. 11
0
// Testcase to test hpx_lco_get_all function
static int _getAll_handler(uint32_t *args, size_t size) {
  uint32_t n = *args;
  if (n < 2) {
    return HPX_THREAD_CONTINUE(n);
  }

  hpx_addr_t peers[] = {
    HPX_HERE,
    HPX_HERE
  };

  uint32_t ns[] = {
    n - 1,
    n - 2
  };

  hpx_addr_t futures[] =  {
    hpx_lco_future_new(sizeof(uint32_t)),
    hpx_lco_future_new(sizeof(uint32_t))
  };

  uint32_t ssn[] = {
    0,
    0
  };

  void *addrs[] = {
    &ssn[0],
    &ssn[1]
  };

  size_t sizes[] = {
    sizeof(uint32_t),
    sizeof(uint32_t)
  };

  hpx_call(peers[0], _getAll, futures[0], &ns[0], sizeof(uint32_t));
  hpx_call(peers[1], _getAll, futures[1], &ns[1], sizeof(uint32_t));

  hpx_lco_get_all(2, futures, sizes, addrs, NULL);

  hpx_lco_wait(futures[0]);
  hpx_lco_wait(futures[1]);

  hpx_addr_t wait = hpx_lco_future_new(0);
  hpx_lco_delete_all(2, futures, wait);
  hpx_lco_wait(wait);
  hpx_lco_delete(wait, HPX_NULL);

  uint32_t sn = ssn[0] * ssn[0] + ssn[1] * ssn[1];

  return HPX_THREAD_CONTINUE(sn);
}
Esempio n. 12
0
static int lco_wait_handler(void) {
  printf("Starting the LCO wait test.\n");

  // allocate and start a timer
  const hpx_time_t t1 = hpx_time_now();

  const hpx_addr_t termination_lco = hpx_lco_and_new(2 * LCOS_PER_LOCALITY * HPX_LOCALITIES);
  hpx_bcast(_spawn, HPX_NULL, HPX_NULL, &termination_lco);
  hpx_lco_wait(termination_lco);
  hpx_lco_delete(termination_lco, HPX_NULL);

  printf(" Elapsed: %g\n", hpx_time_elapsed_ms(t1));
  return HPX_SUCCESS;
}
Esempio n. 13
0
static int _test_try_task_handler(void) {
  barrier = sr_barrier_new(HPX_THREADS);
  assert(barrier);
  hpx_addr_t and = hpx_lco_and_new(HPX_THREADS + 1);
  assert(and);
  for (int i = 0; i < HPX_THREADS; ++i) {
    int e = hpx_call(HPX_HERE, _test_action, and);
    assert(e == HPX_SUCCESS);
  }
  hpx_lco_wait(and);
  hpx_lco_delete(and, HPX_NULL);
  sync_barrier_delete(barrier);
  return HPX_SUCCESS;
}
Esempio n. 14
0
static int _main_action(int *args, size_t size) {
  int n = *args;
  printf("seqspawn(%d)\n", n); fflush(stdout);

  hpx_addr_t and = hpx_lco_and_new(n);
  hpx_time_t now = hpx_time_now();
  for (int i = 0; i < n; i++)
    hpx_call(HPX_HERE, _nop, and, 0, 0);
  hpx_lco_wait(and);
  double elapsed = hpx_time_elapsed_ms(now)/1e3;
  hpx_lco_delete(and, HPX_NULL);

  printf("seconds: %.7f\n", elapsed);
  printf("localities:   %d\n", HPX_LOCALITIES);
  printf("threads:      %d\n", HPX_THREADS);
  hpx_exit(HPX_SUCCESS);
}
Esempio n. 15
0
/// Use a synchronous join for the allreduce operation.
static int
_allreduce_join_handler(hpx_addr_t allreduce, int iters, size_t size) {
  unsigned char sbuf[size];
  unsigned char rbuf[size];

  for (int i = 0, e = size; i < e; ++i) {
    sbuf[i] = rand();
  }

  int id = (HPX_LOCALITY_ID * HPX_THREADS) + HPX_THREAD_ID;
  hpx_addr_t f = hpx_lco_future_new(0);
  for (int i = 0; i < iters; ++i) {
    hpx_lco_allreduce_join_async(allreduce, id, size, sbuf, rbuf, f);
    hpx_lco_wait_reset(f);
  }
  hpx_lco_delete(f, HPX_NULL);
  return HPX_SUCCESS;
}
int parallel_nqueens(int n, int col, int *hist)
{
	hpx_addr_t theThread = HPX_HERE;
	struct thread_data td;
	//td.lyst = hist;
	td.n = n;
	td.col = col;
	memcpy(td.lyst, hist, MAX_SIZE*sizeof(int));
	//printf("thread_data size:%d\n", sizeof(struct thread_data));
	mutex = hpx_lco_sema_new(1);

	//solve(td.n, td.col, td.lyst);
	hpx_addr_t done = hpx_lco_future_new(sizeof(uint64_t));
	hpx_call(theThread, _nqueens, done, &td, sizeof(td));
	hpx_lco_wait(done);
	hpx_lco_delete(done, HPX_NULL);

	return HPX_SUCCESS;
}
// Test code -- ThreadCreate
static int thread_create_handler(int *args, size_t size) {
  printf("Starting the Threads test\n");
  // Start the timer
  hpx_time_t t1 = hpx_time_now();

  hpx_addr_t addr = hpx_gas_alloc_cyclic(NUM_THREADS, sizeof(initBuffer_t), 0);

  // HPX Threads are spawned as a result of hpx_parcel_send() / hpx_parcel_
  // sync().
  for (int t = 0; t < NUM_THREADS; t++) {
    hpx_addr_t done = hpx_lco_and_new(1);
    hpx_parcel_t *p = hpx_parcel_acquire(NULL, sizeof(initBuffer_t));

    // Fill the buffer
    initBuffer_t *init = hpx_parcel_get_data(p);
    init->index = t;
    strcpy(init->message, "Thread creation test");

    // Set the target address and action for the parcel
    hpx_parcel_set_target(p, hpx_addr_add(addr, sizeof(initBuffer_t) * t, sizeof(initBuffer_t)));
    hpx_parcel_set_action(p, _initData);

    // Set the continuation target and action for parcel
    hpx_parcel_set_cont_target(p, done);
    hpx_parcel_set_cont_action(p, hpx_lco_set_action);

    // and send the parcel, this spawns the HPX thread
    hpx_parcel_send(p, HPX_NULL);
    hpx_lco_wait(done);

    hpx_lco_delete(done, HPX_NULL);
  }

  hpx_gas_free(addr, HPX_NULL);

  printf(" Elapsed: %g\n", hpx_time_elapsed_ms(t1));
  hpx_exit(HPX_SUCCESS);
}
static int parcel_get_continuation_handler(void) {
    printf("Testing parcel contination target and action\n");

    hpx_time_t t1 = hpx_time_now();

    hpx_addr_t addr = hpx_gas_alloc_cyclic(1, sizeof(uint64_t), sizeof(uint64_t));

    hpx_addr_t done = hpx_lco_and_new(1);
    hpx_parcel_t *p = hpx_parcel_acquire(NULL, sizeof(uint64_t));

    // Get access to the data, and fill it with the necessary data.
    uint64_t *result = hpx_parcel_get_data(p);
    *result = 1234;

    // Set the target address and action for the parcel
    hpx_parcel_set_target(p, addr);
    hpx_parcel_set_action(p, _get_cont_value);

    // Set the continuation target and action for the parcel
    hpx_parcel_set_cont_target(p, done);
    hpx_parcel_set_cont_action(p, hpx_lco_set_action);

    hpx_action_t get_act = hpx_parcel_get_cont_action(p);
    assert_msg(get_act == hpx_lco_set_action,
               "Error in getting cont action");

    assert(hpx_parcel_get_cont_target(p) == done);

    // Send the parcel
    hpx_parcel_send(p, HPX_NULL);

    hpx_lco_wait(done);
    hpx_lco_delete(done, HPX_NULL);
    hpx_gas_free(addr, HPX_NULL);

    printf("Elapsed: %g\n", hpx_time_elapsed_ms(t1));
    return HPX_SUCCESS;
}
static int _nqueens_action(void *args, size_t size)
{
	int i, j;
	struct thread_data *my_data;
	my_data = (struct thread_data *) args;

	/*
	printf("n = %d, col = %d, count = %d\n", my_data->n
			, my_data->col
			, count);
	*/

	if (my_data->col == my_data->n) {
		hpx_lco_sema_p(mutex);
		++count;
		/*				
						printf("\nNo. %d\n-----\n", count);
						for (i = 0; i < my_data->n; i++, putchar('\n'))
						for(j = 0; j < my_data->n; j++)
						putchar(j == my_data->lyst[i] ? 'Q' : ((i + j) & 1) ? ' ' : '.');
						*/
		hpx_lco_sema_v_sync(mutex);

		hpx_thread_exit(HPX_SUCCESS);
		//hpx_thread_continue(NULL, 0);
		//return HPX_SUCCESS;
	}


#define p_attack(i, j) (my_data->lyst[j] == i || abs(my_data->lyst[j] - i) == my_data->col - j)

	int dummy=0;
	int num_spawns=0;
	for(i = 0, j = 0; i < my_data->n; i++) {
		for (j = 0; j < my_data->col && !p_attack(i, j); j++);
		if (j < my_data->col) {
			dummy++;
		}
	}
	//printf("dummy/spawns: %d/%d\n", dummy, my_data->n);

	num_spawns = my_data->n - dummy;
	bool D_CALL = false;

	//printf("num_spawns = %d\n", num_spawns);
	if( num_spawns == 0 ) {
		num_spawns = 1;
		D_CALL = true;
	}

	//num_spawns = my_data->n;
	struct thread_data temp[num_spawns];
	hpx_addr_t futures[num_spawns];
	hpx_addr_t threads[num_spawns];
	int pqs[num_spawns];
	size_t p_size[num_spawns];
	void *addrs[num_spawns];

	for(i = 0; i < num_spawns; i++) {
		futures[i] = hpx_lco_future_new(sizeof(int));
		threads[i] = HPX_HERE;
		pqs[i] = 0;
		addrs[i] = &pqs[i];
		p_size[i] = sizeof(size_t);
	}

	int k=0; // counter for hpx data
	for(i = 0, j = 0; i < my_data->n; i++) {
		for (j = 0; j < my_data->col && !p_attack(i, j); j++);
		if (j < my_data->col) {
			//printf("[%d] call continue.\n", i);
			continue;
		}
		//printf("[%d] call nqueens %d\n", i, k);

		my_data->lyst[my_data->col] = i;

		memcpy(temp[k].lyst, my_data->lyst, MAX_SIZE*sizeof(int));
		temp[k].n    = my_data->n;
		temp[k].col  = my_data->col+1;

		//solve(n, col + 1, hist);
		hpx_call(threads[k], _nqueens, futures[k], (void *)&temp[k], sizeof(temp[k]));
		k++;
	}

	if( !D_CALL ) {
		hpx_lco_get_all(num_spawns, futures, p_size, addrs, NULL);

		for(i = 0; i < num_spawns; i++)
			hpx_lco_delete(futures[i], HPX_NULL);
	}

	return HPX_SUCCESS;
}
Esempio n. 20
0
static int _main_action(int *args, size_t size) {
  hpx_time_t t;
  int count;

  fprintf(stdout, HEADER);
  fprintf(stdout, "# Latency in (ms)\n");

  t = hpx_time_now();
  hpx_addr_t done = hpx_lco_future_new(0);
  fprintf(stdout, "Creation time: %g\n", hpx_time_elapsed_ms(t));

  value = 1234;

  t = hpx_time_now();
  hpx_call(HPX_HERE, _set_value, done, &value, sizeof(value));
  fprintf(stdout, "Value set time: %g\n", hpx_time_elapsed_ms(t));

  t = hpx_time_now();
  hpx_lco_wait(done);
  fprintf(stdout, "Wait time: %g\n", hpx_time_elapsed_ms(t));

  t = hpx_time_now();
  hpx_lco_delete(done, HPX_NULL);
  fprintf(stdout, "Deletion time: %g\n", hpx_time_elapsed_ms(t));

  fprintf(stdout, "%s\t%*s%*s%*s\n", "# NumReaders " , FIELD_WIDTH,
         "Get_Value ", FIELD_WIDTH, " LCO_Getall ", FIELD_WIDTH, "Delete");

  for (int i = 0; i < sizeof(num_readers)/sizeof(num_readers[0]); i++) {
    fprintf(stdout, "%d\t\t", num_readers[i]);
    count = num_readers[i];
    int values[count];
    void *addrs[count];
    size_t sizes[count];
    hpx_addr_t futures[count];

    for (int j = 0; j < count; j++) {
      addrs[j] = &values[j];
      sizes[j] = sizeof(int);
      futures[j] = hpx_lco_future_new(sizeof(int));
    }

    t = hpx_time_now();
    for (int j = 0; j < count; j++) {
      t = hpx_time_now();
      hpx_call(HPX_HERE, _get_value, futures[j], NULL, 0);
      hpx_lco_wait(futures[j]);
    }
    fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t));

    t = hpx_time_now();
    hpx_lco_get_all(count, futures, sizes, addrs, NULL);
    fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t));

    t = hpx_time_now();
    for (int j = 0; j < count; j++)
      hpx_lco_delete(futures[j], HPX_NULL);
    fprintf(stdout, "%*g\n", FIELD_WIDTH, hpx_time_elapsed_ms(t));
  }
  hpx_exit(HPX_SUCCESS);
}