Skip to content

Commit

Permalink
Reverting accidental change to remote_add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed May 16, 2020
1 parent a7a2b67 commit 42a15db
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions tests/unit/distributed/remote_add.cpp
Original file line number Diff line number Diff line change
@@ -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 <phylanx/execution_tree/primitives/generic_function.hpp>
#include <phylanx/phylanx.hpp>
#include <phylanx/plugins/plugin_factory.hpp>
#include <phylanx/util/random.hpp>

#include <hpx/hpx_init.hpp>
#include <hpx/include/iostreams.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/util.hpp>
#include <hpx/include/runtime.hpp>
#include <hpx/testing.hpp>

#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
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 =
Expand All @@ -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);
Expand All @@ -93,7 +101,6 @@ int hpx_main(int argc, char* argv[])

int main(int argc, char* argv[])
{
std::vector<std::string> 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();
}

0 comments on commit 42a15db

Please sign in to comment.