def create_node(low, high): # this function returns a GlobalMemory object for the created node where = map_bound_to_locality(low, high) rtv = hpx.GlobalMemory.alloc_local_at(1, 1, node_type, hpx.THERE(where)) vals = np.array( [(hpx.NULL().addr, hpx.NULL().addr, low, high, np.array([(0.0, 0.0, 0.0)], dtype=moment_type), hpx.NULL().addr, 0)], dtype=node_type) rtv[0].set(vals) return rtv
def node_compute_potential(current, pos, theta): # (int, float, float) print(current) current_gas = hpx.GlobalAddress(current) node = hpx.construct_array(current_gas.try_pin(), (1, ), node_type)[0] dist = pos - node['moments']['xcom'] size = node['high'] - node['low'] test = size / dist if test < theta: retval = node_compute_approx(node, pos) hpx.thread_continue('array', retval) elif is_leaf(node): parts_gas = hpx.GlobalAddress(node['parts']) particle_array = hpx.construct_array(parts_gas.try_pin(), (node['count'], ), particle_type) retval = node_compute_direct(particle_array, pos) parts_gas.unpin() hpx.thread_continue('array', retval) else: potential_lco = hpx.Reduce(2, (1, ), np.dtype(float), float_sum_id, float_sum_op) if node['left'] != hpx.NULL().addr: node_compute_potential(node['left'], node['left'], pos, theta, rsync_lco=potential_lco) else: potential_lco.set(array=np.array([0.0], dtype=float), sync='async') if node['right'] != hpx.NULL().addr: node_compute_potential(node['right'], node['right'], pos, theta, rsync_lco=potential_lco) else: potential_lco.set(array=np.array([0.0], dtype=float), sync='async') hpx.call_cc(potential_reduction_complete, potential_lco.addr, potential_lco, gate=potential_lco) current_gas.unpin() return hpx.SUCCESS
def spawn_computation(current, root, sync, theta): # (int, GlobalMemory, LCO, float) current_local = hpx.GlobalAddress(current).try_pin() node = hpx.construct_array(current_local, (1, ), node_type)[0] if (is_leaf(node)): parts_addr = hpx.GlobalAddress(node['parts'], node['count'] * particle_type.itemsize) parts_gas = hpx.GlobalAddressBlock(parts_addr, (node['count'], ), particle_type, (particle_type.itemsize, )) parts = parts_gas.try_pin() for i in range(node['count']): compute_and_save(hpx.HERE(), root, sync, parts_gas[i], parts[i]['pos'], theta) parts_gas.unpin() else: if node['left'] != hpx.NULL().addr: spawn_computation(node['left'], node['left'], root, sync, theta) if node['right'] != hpx.NULL().addr: spawn_computation(node['right'], node['right'], root, sync, theta) return hpx.SUCCESS
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 is_leaf(node): return (node['left'] == hpx.NULL().addr) and (node['right'] == hpx.NULL().addr)