Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dash::copy copies the wrong values in global to local #656

Closed
bertwesarg opened this issue Jul 11, 2019 · 1 comment
Closed

dash::copy copies the wrong values in global to local #656

bertwesarg opened this issue Jul 11, 2019 · 1 comment

Comments

@bertwesarg
Copy link
Member

Extending the example in #653 gives now the wrong values in the target matrix:

#include <iostream>

#include <libdash.h>

int
main(int ac, char *av[])
{
    using TeamSpecT = dash::TeamSpec<2>;
    using MatrixT = dash::NArray<double, 2>;
    using PatternT = typename MatrixT::pattern_type;
    using SizeSpecT = dash::SizeSpec<2>;
    using DistSpecT = dash::DistributionSpec<2>;

    dash::init(&ac, &av);

    auto size_spec = SizeSpecT(16, 16);
    auto dist_spec = DistSpecT(dash::BLOCKED, dash::BLOCKED);

    auto& team_all = dash::Team::All();
    TeamSpecT team_all_spec(team_all.size(), 1);
    team_all_spec.balance_extents();
    MatrixT grid_more(size_spec, dist_spec, team_all, team_all_spec);
    dash::fill(grid_more.begin(), grid_more.end(), (double)team_all.myid());
    team_all.barrier();

    if (team_all.myid() == 0) {
        auto gextents = grid_more.extents();
        for (    uint32_t y = 0; y < gextents[0]; ++y) {
            std::cout << "[" << y << "] := {";
            for (uint32_t x = 0; x < gextents[1]; ++x)
                std::cout << " " << (double)grid_more[y][x];
            std::cout << "}\n";
        }
    }

    dash::Team& team_fewer= team_all.split(4);
    team_all.barrier();
    if (!team_fewer.is_null() && 0 == team_fewer.position()) {
        TeamSpecT team_fewer_spec(team_fewer.size(), 1);
        team_fewer_spec.balance_extents();

        MatrixT grid_fewer(size_spec, dist_spec, team_fewer, team_fewer_spec);
        dash::fill(grid_fewer.begin(), grid_fewer.end(), -1.0);

        auto lextents= grid_fewer.pattern().local_extents();

        for (uint32_t y = 0; y < lextents[0]; ++y) {
            auto gcorner_fewer = grid_fewer.pattern().global({y, 0});
            auto gbegin = grid_more.begin() + grid_more.pattern().global_at(gcorner_fewer);

            auto loffset = grid_fewer.pattern().local_at({y, 0});
            dash::copy(gbegin, gbegin + lextents[1],
                       grid_fewer.lbegin() + loffset);
        }
        team_fewer.barrier();

        if (team_fewer.myid() == 0) {
            auto gextents = grid_fewer.extents();
            for (    uint32_t y = 0; y < gextents[0]; ++y) {
                std::cout << "[" << y << "] := {";
                for (uint32_t x = 0; x < gextents[1]; ++x)
                    std::cout << " " << (double)grid_fewer[y][x];
                std::cout << "}\n";
            }
        }

        team_fewer.barrier();
    }
    team_all.barrier();

    dash::finalize();

    return 0;
}

The source matrix looks like this:

[0] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[1] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[2] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[3] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[4] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[5] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[6] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[7] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[8] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[9] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[10] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[11] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[12] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[13] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[14] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
[15] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}

But the result matrix looks like this:

[0] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[1] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[2] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[3] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[4] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[5] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[6] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[7] := { 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1}
[8] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[9] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[10] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[11] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[12] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[13] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[14] := { 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2}
[15] := { 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3}
@devreal
Copy link
Member

devreal commented Jul 11, 2019

Analysis: The current implementation of dash::copy (dash::copy_impl) does not observe the iteration space of the iterator but instead uses the local iteration space(s), starting from the first unit in the range passed to copy. That of course is not how dash::copy should operate.

Working on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants