Exemplo n.º 1
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);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
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;
}