diff --git a/tests/unit/distributed/remote_add.cpp b/tests/unit/distributed/remote_add.cpp index 38779ebbb..373d2f049 100644 --- a/tests/unit/distributed/remote_add.cpp +++ b/tests/unit/distributed/remote_add.cpp @@ -1,40 +1,45 @@ -// Copyright (c) 2017-2020 Hartmut Kaiser -// Copyright (c) 2020 Maxwell Reeser -// Copyright (c) 2020 Bita Hasheminezhad +// Copyright (c) 2018 Parsa Amini +// Copyright (c) 2018 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#include #include +#include #include #include #include -#include -#include +#include #include #include #include #include #include -#include #include /////////////////////////////////////////////////////////////////////////////// -char const* const cannon_product_code = R"(block( - define(cannon, dim_size, - block( - define(array1, random_d(list(dim_size, dim_size), find_here(), 2)), - define(array2, random_d(list(dim_size, dim_size), find_here(), 2)), - cannon_product(array1, array2) - ) - ), - cannon -))"; - -//////////////////////////////////////////////////////////////////////////////// -int hpx_main(int argc, char* argv[]) +std::string load_data_str = R"( + define(load_data, rows, cols, random(list(rows, cols))) +)"; + +std::string add_str = R"( + define(add, a, b, a + b) +)"; + +std::string columnwise_tile_str = R"( + define(columnwise_tile, m, n, hsplit(m, n)) +)"; + +std::string columnwise_merge_str = R"( + define(columnwise_merge, tiles, hstack(tiles)) +)"; + +/////////////////////////////////////////////////////////////////////////////// +phylanx::execution_tree::compiler::function compile_and_run( + std::string const& codestr, hpx::id_type const& there) { phylanx::execution_tree::compiler::function_list snippets; phylanx::execution_tree::compiler::environment env = @@ -60,22 +65,25 @@ void test_remote_add(hpx::id_type const& here, hpx::id_type const& there) // tile both matrices using namespace phylanx::execution_tree; - // compile the given code - compiler::function_list snippets; - auto const& code_cannon_product = - compile("cannon", cannon_product_code, snippets); - auto cannon = code_cannon_product.run(); + auto columnwise_tile = compile_and_run(columnwise_tile_str, here); + auto m1_tiles = + extract_list_value(columnwise_tile(m1, std::int64_t(2))).args(); + auto m2_tiles = + extract_list_value(columnwise_tile(m2, std::int64_t(2))).args(); - hpx::util::high_resolution_timer t; + // perform remote addition + auto result1 = add_here.eval(m1_tiles[0], m2_tiles[0]); - std::int64_t dim_size = 12; - auto result = cannon(dim_size); + auto add_there = compile_and_run(add_str, there); + auto result2 = add_there.eval(m1_tiles[1], m2_tiles[1]); - auto elapsed = t.elapsed(); + // wait for add operations to finish + hpx::wait_all(result1, result2); - std::cout << "Result: \n" - << extract_numeric_value(result) << std::endl - << "Calculated in: " << elapsed << " seconds" << std::endl; + // merge tiles + auto columnwise_merge = compile_and_run(columnwise_merge_str, here); + auto result = columnwise_merge(primitive_argument_type{ + primitive_arguments_type{result1.get(), result2.get()}}); std::cout << "using seed: " << seed << "\n"; HPX_TEST_EQ(expected, result); @@ -93,7 +101,6 @@ int hpx_main(int argc, char* argv[]) int main(int argc, char* argv[]) { - std::vector cfg = {"hpx.run_hpx_main!=1"}; - - return hpx::init(argc, argv, cfg); + HPX_TEST_EQ(hpx::init(argc, argv), 0); + return hpx::util::report_errors(); }