STEllAR-GROUP / phylanx

An Asynchronous Distributed C++ Array Processing Toolkit
Boost Software License 1.0
75 stars 76 forks source link

ostream does not work properly having more than one locality #1150

Closed NanmiaoWu closed 4 years ago

NanmiaoWu commented 4 years ago

The wrong result for the test (https://github.com/STEllAR-GROUP/phylanx/blob/dist_diag/tests/unit/plugins/dist_matrixops/dist_diag_2_loc.cpp) is: Screenshot from 2020-04-22 16-10-32,

taless474 commented 4 years ago

This happens sometimes on docker, too. The ostream of MSVC works properly.

NanmiaoWu commented 4 years ago
#include <phylanx/phylanx.hpp>

#include <hpx/hpx_init.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/testing.hpp>

#include <string>
#include <utility>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
phylanx::execution_tree::primitive_argument_type compile_and_run(
    std::string const& name, std::string const& codestr)
{
    phylanx::execution_tree::compiler::function_list snippets;
    phylanx::execution_tree::compiler::environment env =
        phylanx::execution_tree::compiler::default_environment();

    auto const& code =
        phylanx::execution_tree::compile(name, codestr, snippets, env);
    return code.run().arg_;
}

void test_constant_d_operation(std::string const& name, std::string const& code,
    std::string const& expected_str)
{
    phylanx::execution_tree::primitive_argument_type result =
        compile_and_run(name, code);
    phylanx::execution_tree::primitive_argument_type comparison =
        compile_and_run(name, expected_str);

    HPX_TEST_EQ(result, comparison);
}
void test_output()
{
    if (hpx::get_locality_id() == 0)
    {
        test_constant_d_operation("test_constant_2loc1d", R"(
            constant_d(42, list(4), 0, 2, "array_name")
        )", R"(
            annotate_d([42, 42], "array_name",
                list("tile", list("columns", 0, 2)))
        )");
    }
    else
    {
        test_constant_d_operation("test_constant_2loc1d", R"(
            constant_d(42, list(4), 1, 2, "array_name")
        )", R"(
            annotate_d([42, 42], "array_name",
                list("tile", list("columns", 2, 4)))
        )");
    }
}
int hpx_main(int argc, char* argv[])
{
    test_output();

    hpx::finalize();
    return hpx::util::report_errors();
}
int main(int argc, char* argv[])
{
    std::vector<std::string> cfg = {
        "hpx.run_hpx_main!=1"
    };

    return hpx::init(argc, argv, cfg);
}

The mess result is shown as:

168: Test command: /usr/bin/python3.7 "/phylanx/build/bin/phylanxrun.py" "/phylanx/build/bin/dist_constant_2_loc_test" "-e" "0" "-l" "2" "-t" "1" "-p" "tcp" "-v" "--"
168: Test timeout computed to be: 200
168: /repos/phylanx/tests/unit/plugins/dist_matrixops/dist_constant_2_loc.cpp(39): test 'result == comparison' failed in function 'void test_constant_d_operation(const std::string &, const std::string &, const std::string &)': '/repos/phylanx/tests/unit/plugins/dist_matrixops/dist_constant_2_loc.cpp(39): test 'result == comparison' failed in function 'void test_constant_d_operation(const std::string &, const std::string &, const std::string &)': '[42, 42][42, 42], , annotation(annotation(""llooccaalliittiieess"", , list(list(""mmeettaa__00"", , list(list(""ttiillee"", , list(list(""ccoolluummnnss"", , 00, 2, 2))), list("meta)_1")), list("tile", list("co, llist(umns"", meta_1", list("tile", list("columns", 22, , 44)))))), list(, list("l"olcoaclailtiyt"y", , 01, , 22)), list(, "list(name"", n"aamrer"ay_n, am"ea/r0r"ay)_n)ame/' != '0"))' != '[[42, 42]42, 42], annotation("localities", list("meta_0", list("tile", list("columns", , annotation("localities", list("meta_0", list(0"tile", list("columns", , 02, )2)), list("meta_1", list("tile"), )list(")columns", , list("meta_1", list("tile", list("columns", 22, , 44)))))), list(, list("lo"calliotyc"ality, ", 01, , 22)), , list(list(""nnaammee"", ", a"rarrarya_yn_anmaem/e0/"0"))))''.

The reason is that the types of the value, which is 42 in this example, are different. One is std::int64_t and another is float. Since we don't give it a dtype, the default dtype is float.

hkaiser commented 4 years ago

@NanmiaoWu, @taless474: please see https://github.com/STEllAR-GROUP/hpx/pull/4561 for a possible solution to this problem.

hkaiser commented 4 years ago

@NanmiaoWu STEllAR-GROUP/hpx#4561 has been merged now. You can now rewrite the tests in question to use hpx::cout as the first argument to all HPX_TEST_xxx macros to solve the issue described here.