def worker(current_rank, num_ranks, and_lco): target_rank = (current_rank + 1) % num_ranks array = np.empty((128//NUM_TRY, 1024, 1024)) finish_copy = hpx.Future() some_marshalled_action(hpx.THERE(target_rank), array, sync='async', lsync_lco=finish_copy, rsync_lco=and_lco) finish_copy.wait() print("worker {0} sends {1} bytes".format(current_rank, array.nbytes)) return hpx.SUCCESS
def compute_and_save(root, sync, current, pos, theta): compdone = hpx.Future(shape=(1, ), dtype=np.dtype(float)) node_compute_potential(root[0], root.addr.addr, pos, theta, rsync_lco=compdone) particle_set_approx(current, current, compdone, gate=compdone, rsync_lco=sync) return hpx.SUCCESS
def main(): future = hpx.Future() set_lco(hpx.HERE(), future, 2) future.wait() future.delete() out_array = np.zeros((5, 6), dtype=int) return_an_array(hpx.HERE(), sync='rsync', out_array=out_array) assert np.array_equal(out_array, np.arange(30).reshape((5, 6))) future = hpx.Future((3, 4), dtype=np.dtype(int)) call_cc(hpx.HERE(), sync='lsync', rsync_lco=future) out_array = future.get() assert np.array_equal(out_array, np.arange(12).reshape((3, 4))) future.delete() # test lsync calling interface with gate future1 = hpx.Future() future2 = hpx.Future((3, 4), dtype=np.dtype(int)) set_funture_2(hpx.HERE(), future2, gate=future1) set_lco(hpx.HERE(), future1, 2) out_array = future2.get() assert np.array_equal(out_array, np.arange(12).reshape((3, 4))) future1.delete() future2.delete() # test rsync calling interface with gate future1 = hpx.Future() out_array = np.zeros((3, 4), dtype=int) set_lco(hpx.HERE(), future1, 2) set_future(hpx.HERE(), sync='rsync', gate=future1, out_array=out_array) assert np.array_equal(out_array, np.arange(12).reshape((3, 4))) future1.delete() rtv = np.arange(6).reshape((2, 3)) hpx.exit(rtv)
def main(n_parts, n_partition, theta_c, domain_size): set_domain_size(hpx.NULL(), domain_size, sync='rsync') root = create_node(0.0, domain_size) parts = generate_parts(n_parts, domain_size, root.addr) done = hpx.Future(shape=(1, ), dtype=moment_type) partition_node(root[0], root[0], parts, n_parts, n_partition, sync='lsync', rsync_lco=done) done.wait() done.delete() alldone = hpx.And(n_parts) spawn_computation(root[0], root[0].addr.addr, root, alldone, theta_c) alldone.wait() alldone.delete() hpx.exit()
def main(): # test lsync reduce_lco = hpx.Reduce(5, (3, 4, 5), np.dtype(np.int), set_zero, add) for i in range(5): array = np.ones((3, 4, 5), dtype=np.int) reduce_lco.set(array, sync='lsync') return_array = reduce_lco.get() expect_array = np.zeros((3, 4, 5), dtype=np.int) expect_array[:] = 6 assert np.array_equal(return_array, expect_array) # test async reduce_lco = hpx.Reduce(5, (3, 4, 5), np.dtype(np.int), set_zero, add) for i in range(5): and_lco = hpx.Future() array = np.ones((3, 4, 5), dtype=np.int) reduce_lco.set(array, sync='async', lsync_lco=and_lco) and_lco.wait() return_array = reduce_lco.get() expect_array = np.zeros((3, 4, 5), dtype=np.int) expect_array[:] = 6 assert np.array_equal(return_array, expect_array) hpx.exit()
def partition_node(node_gas, parts, n_parts, n_partition): node = node_gas.try_pin() node['parts'] = parts.addr.addr node['count'] = n_parts if n_parts <= n_partition: parts_local = parts[0].try_pin() node['moments'] = compute_moments(parts_local, n_parts) parts[0].unpin() hpx.thread_continue('array', node['moments']) else: parts_local = parts[0].try_pin() split = 0.5 * (node[0]['low'] + node[0]['high']) parts_local_left = parts_local[parts_local['pos'] < split] parts_local_right = parts_local[parts_local['pos'] >= split] parts[0].unpin() reduce_lco = hpx.Reduce(2, (1, ), moment_type, moment_reduction_id, moment_reduction_op) if parts_local_left.shape[0] > 0: node_left = create_node(node[0]['low'], split) node['left'] = node_left.addr.addr parts_left = hpx.GlobalMemory.alloc_local_at( 1, parts_local_left.shape[0], particle_type, node['left']) cpy_done = hpx.Future() parts_left[0].set(parts_local_left, sync='lsync', rsync_lco=cpy_done) cpy_done.wait() cpy_done.delete() partition_node(node_left[0], node_left[0], parts_left, parts_local_left.shape[0], n_partition, rsync_lco=reduce_lco) else: empty = np.zeros(1, dtype=moment_type) reduce_lco.set(array=empty) if parts_local_right.shape[0] > 0: node_right = create_node(split, node[0]['high']) node['right'] = node_right.addr.addr parts_right = hpx.GlobalMemory.alloc_local_at( 1, parts_local_right.shape[0], particle_type, node['right']) parts_right[0].set(parts_local_right) partition_node(node_right[0], node_right[0], parts_right, parts_local_right.shape[0], n_partition, rsync_lco=reduce_lco) else: empty = np.zeros(1, dtype=moment_type) reduce_lco.set(array=empty) hpx.call_cc(save_and_continue_moments, hpx.thread_current_target(), node_gas, reduce_lco, gate=reduce_lco) return hpx.SUCCESS