Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def potential_reduction_complete(potential_lco):
    contval = potential_lco.get()
    potential_lco.delete()
    hpx.thread_continue('array', contval)
    return hpx.SUCCESS
Beispiel #4
0
def save_and_continue_moments(node_gas, moments_lco):
    node = node_gas.try_pin()
    node['moments'] = moments_lco.get()
    moments_lco.delete()
    hpx.thread_continue('array', node['moments'])
    return hpx.SUCCESS
Beispiel #5
0
def set_future():
    rtarray = np.arange(12).reshape((3, 4))
    hpx.thread_continue('array', rtarray)
    return hpx.SUCCESS
Beispiel #6
0
def return_an_array():
    rtv_array = np.arange(30).reshape((5, 6))
    hpx.thread_continue('array', rtv_array)
    return hpx.SUCCESS