Exemple #1
0
def main():
    data = hpx.GlobalMemory.alloc_cyclic(NUM_NODE, (DATA_PER_NODE, DIM),
                                         np.dtype(np.float))

    generate_data_complete = hpx.And(NUM_NODE)
    for i in range(NUM_NODE):
        generate_data(data[i], node_size(i), rsync_lco=generate_data_complete)
    generate_data_complete.wait()

    data_this_block = data[0].try_pin()
    centers = data_this_block[:K]
    data[0].unpin()
    iterations = 0
    while iterations < MAX_ITERATION:
        count_lco = hpx.Reduce(NUM_NODE, (K, ), np.dtype(np.int),
                               initialize_count, sum_count)
        position_lco = hpx.Reduce(NUM_NODE, (K, DIM), np.dtype(np.float),
                                  initialize_position, sum_position)
        and_lco = hpx.And(NUM_NODE)
        for i in range(NUM_NODE):
            calculate_centers(data[i], node_size(i), centers, count_lco,
                              position_lco, and_lco)
        counts = count_lco.get()
        positions = position_lco.get()
        centers = positions / counts.reshape((K, 1))
        and_lco.wait()
        count_lco.delete_sync()
        position_lco.delete_sync()
        and_lco.delete_sync()
        iterations = iterations + 1

    hpx.exit()
Exemple #2
0
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()
Exemple #3
0
def main_action():
    num_node = hpx.get_num_ranks()
    print("program runs on {0} nodes".format(num_node))
    step_size = (high - low) / total_cells
    cell_per_node = total_cells // num_node

    result_lco = hpx.Reduce(num_node, (1, ), np.dtype(float), result_init,
                            result_op)
    for i in range(num_node):
        calculate_integral(hpx.THERE(i), low + i * step_size * cell_per_node,
                           step_size, cell_per_node, result_lco)
    print(result_lco.get())
    print(fint(high) - fint(low))
    hpx.exit()
Exemple #4
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
Exemple #5
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