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 local to global #657

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

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

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

Comments

@bertwesarg
Copy link
Member

Extending the example in #656 even further by copying the values back to the larger team by the smaller team, reveals that the local-to-global mode of dash::copy also does not work

#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(8, 8);
    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();

    auto gextents = grid_more.extents();

    if (team_all.myid() == 0) {
        std::cout << "init\n";
        for (    uint32_t y = 0; y < gextents[0]; ++y) {
            std::cout << "[" << std::setw(2) << y << "] := {";
            for (uint32_t x = 0; x < gextents[1]; ++x)
                std::cout << " " << std::setw(2) << (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) {
            std::cout << "subteam " << 0 << "\n";
            auto gextents = grid_fewer.extents();
            for (    uint32_t y = 0; y < gextents[0]; ++y) {
                std::cout << "[" << std::setw(2) << y << "] := {";
                for (uint32_t x = 0; x < gextents[1]; ++x)
                    std::cout << " " << std::setw(2) << (double)grid_fewer[y][x];
                std::cout << "}\n";
            }
        }
        team_fewer.barrier();

        dash::fill(grid_fewer.begin(), grid_fewer.end(), (double)team_all.myid());

        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 lbegin = grid_fewer.lbegin() + grid_fewer.pattern().local_at({y, 0});
            dash::copy(lbegin, lbegin + lextents[1],
                       gbegin);
        }
        team_fewer.barrier();

    }
    team_all.barrier();

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

    dash::finalize();

    return 0;
}

The result with 4 units should be:

final
[ 0] := {  0  0  0  0  0  0  0  0}
[ 1] := {  0  0  0  0  0  0  0  0}
[ 2] := {  0  0  0  0  0  0  0  0}
[ 3] := {  0  0  0  0  0  0  0  0}
[ 4] := {  0  0  0  0  0  0  0  0}
[ 5] := {  0  0  0  0  0  0  0  0}
[ 6] := {  0  0  0  0  0  0  0  0}
[ 7] := {  0  0  0  0  0  0  0  0}

but I get:

final
[ 0] := {  0  0  0  0  0  0  0  0}
[ 1] := {  0  0  0  0  0  0  0  0}
[ 2] := {  0  0  0  0  0  0  0  0}
[ 3] := {  0  0  0  0  0  0  0  0}
[ 4] := {  0  0  0  0  3  3  3  3}
[ 5] := {  0  0  0  0  3  3  3  3}
[ 6] := {  0  0  0  0  3  3  3  3}
[ 7] := {  0  0  0  0  3  3  3  3}

For 16 units the correct result is:

final
[ 0] := {  0  0  0  0  1  1  1  1}
[ 1] := {  0  0  0  0  1  1  1  1}
[ 2] := {  0  0  0  0  1  1  1  1}
[ 3] := {  0  0  0  0  1  1  1  1}
[ 4] := {  2  2  2  2  3  3  3  3}
[ 5] := {  2  2  2  2  3  3  3  3}
[ 6] := {  2  2  2  2  3  3  3  3}
[ 7] := {  2  2  2  2  3  3  3  3}

The faulty result:

final
[ 0] := {  0  0  0  0  2  2  1  1}
[ 1] := {  0  0  0  0  1  1  1  1}
[ 2] := {  0  0  5  5  1  1  7  7}
[ 3] := {  0  0  5  5  1  1  7  7}
[ 4] := {  2  2  9  9  3  3 11 11}
[ 5] := {  2  2  9  9  3  3 11 11}
[ 6] := {  2  2 13 13  3  3 15 15}
[ 7] := {  2  2 13 13  3  3 15 15}
devreal added a commit that referenced this issue Jul 18, 2019
@devreal
Copy link
Member

devreal commented Jul 18, 2019

Fixed in #659

@devreal devreal closed this as completed Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants