static int _uts_main_action(void *args, size_t size) { Node *root = (Node *)args; Node temp; uts_initRoot(&temp, type); //bots_number_of_tasks = parallel_uts(&temp); printf("Computing Unbalance Tree Search algorithm "); hpx_addr_t theThread = HPX_HERE; counter_t num_nodes; hpx_time_t start; struct thread_data input; input.depth = 0; memcpy(&input.parent, &temp, sizeof(Node)); input.numChildren = getNumRootChildren(&temp); start = hpx_time_now(); hpx_call_sync(theThread, _uts, &num_nodes, sizeof(num_nodes), &input, sizeof(input)); bots_time_program = hpx_time_elapsed_ms(start)/1e3; bots_number_of_tasks = num_nodes; printf(" completed!"); uts_show_stats(); uts_check_result(); hpx_shutdown(HPX_SUCCESS); }
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 _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); }
static int _nqueens_main_action(int *args, size_t size) { int n = *args; int hist[n]; hpx_time_t start; start = hpx_time_now(); parallel_nqueens(n, 0, hist); printf("%d-Queens: %.7f (s)\n", n, hpx_time_elapsed_ms(start)/1e3); verify_queens(n); hpx_exit(HPX_SUCCESS); }
/// 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; }
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; }
static int lco_getall_handler(void) { uint32_t n, ssn; printf("Starting the HPX LCO get all test\n"); for (uint32_t i = 0; i < 6; i++) { ssn = 0; n = i + 1; hpx_time_t t1 = hpx_time_now(); printf("Square series for (%d): ", n); hpx_call_sync(HPX_HERE, _getAll, &ssn, sizeof(ssn), &n, sizeof(n)); printf("%d", ssn); printf(" Elapsed: %.7f\n", hpx_time_elapsed_ms(t1)/1e3); } return HPX_SUCCESS; }
static int lco_waitall_handler(void) { int size = HPX_LOCALITIES; int block_size = 1; int ranks = hpx_get_num_ranks(); printf("Starting the HPX LCO Wait all test\n"); printf("localities: %d\n", size); // Start the timer hpx_time_t t1 = hpx_time_now(); uint32_t blocks = size; uint32_t block_bytes = block_size * sizeof(uint32_t); printf("Number of blocks and bytes per block = %d, %d\n", blocks, block_bytes); printf("Ranks and blocks per rank = %d, %d\n", ranks, blocks / ranks); hpx_addr_t addr = hpx_gas_alloc_cyclic(blocks, sizeof(uint32_t), 0); uint32_t args[2] = { block_size, (blocks / ranks) }; int rem = blocks % ranks; hpx_addr_t done[2] = { hpx_lco_and_new(ranks), hpx_lco_and_new(rem) }; for (int i = 0; i < ranks; i++) { hpx_addr_t there = hpx_addr_add(addr, i * block_bytes, sizeof(uint32_t)); hpx_call(there, _init_memory, done[0], args, sizeof(args)); } for (int i = 0; i < rem; i++) { hpx_addr_t block = hpx_addr_add(addr, args[1] * ranks + i * block_bytes, block_bytes); hpx_call(block, _init_memory, done[1], args, sizeof(args)); } // Blocks the thread until all of the LCO's have been set. hpx_lco_wait_all(2, done, NULL); hpx_lco_delete_all(2, done, HPX_NULL); hpx_gas_free(addr, HPX_NULL); printf(" Elapsed: %g\n", hpx_time_elapsed_ms(t1)); return HPX_SUCCESS; }
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); }
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; }
static int _health_main_action(void *args, size_t size) { char *ptr = (char *)args; struct Village *top; hpx_time_t start; printf("initial top = %p, %u\n", top, top); read_input_data(ptr); allocate_village(&top, ((void *)0), ((void *)0), sim_level, 0);; printf("\ninitial top = %p, %u\n", top, top); start = hpx_time_now(); sim_village_main_hpx(top);; printf("HPX-5 health took: %.7f (s)\n", hpx_time_elapsed_ms(start)/1e3); check_village(top); 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; }
// 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); }
counter_t parallel_uts ( Node *root ) { struct thread_data input; hpx_time_t start; hpx_addr_t theThread = HPX_HERE; counter_t num_nodes; input.depth = 0; memcpy(&input.parent, root, sizeof(Node)); input.numChildren = getNumRootChildren(root); printf("Computing Unbalance Tree Search algorithm "); hpx_addr_t done = hpx_lco_future_new(sizeof(uint64_t)); start = hpx_time_now(); hpx_call_sync(theThread, _uts, &num_nodes, sizeof(num_nodes), &input, sizeof(input)); bots_time_program = hpx_time_elapsed_ms(start)/1e3; printf(" completed!"); return num_nodes; }
static int _main_action(void *args, size_t n) { hpx_addr_t local, global, calloc_global; hpx_time_t t; int size = HPX_LOCALITIES; int ranks = hpx_get_num_ranks(); uint32_t blocks = size; fprintf(stdout, HEADER); fprintf(stdout, "localities: %d, ranks and blocks per rank = %d, %d\n", size, ranks, blocks/ranks); fprintf(stdout, "%s\t%*s%*s%*s%*s%*s%*s\n", "# Size ", HEADER_FIELD_WIDTH, " LOCAL_ALLOC ", HEADER_FIELD_WIDTH, " FREE ", HEADER_FIELD_WIDTH, " GLOBAL_ALLOC ", HEADER_FIELD_WIDTH, " FREE ", HEADER_FIELD_WIDTH, " GLOBAL_CALLOC ", HEADER_FIELD_WIDTH, " FREE "); for (size_t size = 1; size <= MAX_BYTES; size*=2) { t = hpx_time_now(); local = hpx_gas_alloc_local(1, size, 0); fprintf(stdout, "%-*zu%*g", 10, size, FIELD_WIDTH, hpx_time_elapsed_ms(t)); t = hpx_time_now(); hpx_gas_free(local, HPX_NULL); fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t)); t = hpx_time_now(); global = hpx_gas_alloc_cyclic(blocks, size, 0); fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t)); t = hpx_time_now(); hpx_gas_free(global, HPX_NULL); fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t)); t = hpx_time_now(); calloc_global = hpx_gas_calloc_cyclic(blocks, size, 0); fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t)); t = hpx_time_now(); hpx_gas_free(calloc_global, HPX_NULL); fprintf(stdout, "%*g", FIELD_WIDTH, hpx_time_elapsed_ms(t)); fprintf(stdout, "\n"); } hpx_exit(HPX_SUCCESS); }
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); }