Skip to content

Commit

Permalink
This is broken, getting an error on credits ~50%
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwell S Reeser committed Apr 4, 2019
1 parent 9b514ee commit c10f397
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 11 deletions.
58 changes: 48 additions & 10 deletions src/dist_objects_4/src/template_dist_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <hpx/include/lcos.hpp>
#include <hpx/include/parallel_for_each.hpp>
#include <hpx/lcos/barrier.hpp>
#include <hpx/runtime/serialization/unordered_map.hpp>
#include <hpx/util/assert.hpp>
#include <hpx/util/bind.hpp>

Expand All @@ -34,15 +35,20 @@ namespace dist_object {
hpx::components::component_base<meta_object_server>> {
public:

meta_object_server(std::size_t num_locs) : b(num_locs)
meta_object_server(std::size_t num_locs, std::size_t root) : b(num_locs), root_(root)
{
servers_ = std::unordered_map<std::size_t, hpx::id_type>();
retrieved = false;
}

std::unordered_map<std::size_t, hpx::id_type> get_server_list() {
return servers_;
}

//std::vector<hpx::id_type> get_server_list() {
// return servers__;
//}

std::unordered_map<std::size_t, hpx::id_type> registration(std::size_t source_loc, hpx::id_type id)
{
{
Expand All @@ -53,13 +59,26 @@ namespace dist_object {
return servers_;
}

//std::vector< hpx::id_type> registration(std::size_t source_loc, hpx::id_type id)
//{
// {
// std::lock_guard<hpx::lcos::local::spinlock> l(lk);
// servers__[source_loc] = id;
// }
// b.wait();
// return servers__;
//}

HPX_DEFINE_COMPONENT_ACTION(meta_object_server, get_server_list);
HPX_DEFINE_COMPONENT_ACTION(meta_object_server, registration);

private:
hpx::lcos::local::barrier b;
hpx::lcos::local::spinlock lk;
bool retrieved;
std::size_t root_;
std::unordered_map<std::size_t, hpx::id_type> servers_;
std::vector<hpx::id_type> servers__;
};


Expand All @@ -78,24 +97,35 @@ namespace dist_object {
typedef hpx::components::client_base<meta_object, meta_object_server> base_type;

meta_object(std::string basename, std::size_t num_locs, std::size_t root) :
base_type(hpx::new_<meta_object_server>(hpx::find_here(), num_locs))
base_type(hpx::new_<meta_object_server>(hpx::find_here(), num_locs, root))
{
if (hpx::get_locality_id() == root) {
hpx::register_with_basename(basename, get_id(),hpx::get_locality_id());
}
meta_object_0 = hpx::find_from_basename(basename, root).get();
}

hpx::future<std::unordered_map<std::size_t, hpx::id_type>> get_server_list() {
std::unordered_map<std::size_t, hpx::id_type> get_server_list() {

return hpx::async(get_list_action(), meta_object_0);
return hpx::async(get_list_action(), meta_object_0).get();
}

//hpx::future<std::vector<hpx::id_type>> get_server_list() {

// return hpx::async(get_list_action(), meta_object_0);
//}

std::unordered_map<std::size_t, hpx::id_type> registration(hpx::id_type id)
{
return hpx::async(register_with_meta_action(), meta_object_0,
hpx::get_locality_id(), id).get();
}

//std::vector<hpx::id_type> registration(hpx::id_type id)
//{
// return hpx::async(register_with_meta_action(), meta_object_0,
// hpx::get_locality_id(), id).get();
//}

private:
hpx::id_type meta_object_0;
Expand Down Expand Up @@ -126,15 +156,21 @@ namespace dist_object {
: base_type(create_server(data)), base_(base)
{
assert(localities.size() > 0);
assert(std::find(localities.begin(), localities.end(),
hpx::get_locality_id()));
bool here_listed = std::find(localities.begin(), localities.end(),
hpx::get_locality_id()) != localities.end();

localities = std::sort(localities.begin(), localities.end());
std::sort(localities.begin(), localities.end());

if (type == construction_type::Meta_Object) {
meta_object mo(base, localities.size(), localities[0]);
std::vector<hpx::id_type> other_servers =
mo.registration(get_id());
if(here_listed)
locs = mo.registration(get_id());
else {
locs = mo.get_server_list();
while (locs.size() != localities.size()) {
locs = mo.get_server_list();
}
}
basename_registration_helper(base);
}
else if (type == construction_type::All_to_All) {
Expand Down Expand Up @@ -246,9 +282,11 @@ namespace dist_object {
std::unordered_map<std::size_t, hpx::id_type> locs;

hpx::id_type get_basename_helper(int idx) {
if (!basename_list[idx]) {
if (!locs[idx]) {
//basename_list[idx] = hpx::find_from_basename(base_ + std::to_string(idx), idx).get();
locs[idx] = hpx::find_from_basename(base_ + std::to_string(idx), idx).get();
}
//return basename_list[idx];
return locs[idx];
}
void basename_registration_helper(std::string base) {
Expand Down
38 changes: 37 additions & 1 deletion src/dist_objects_4/src/template_dist_object_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,48 @@ void run_dist_object_matrix_mo() {
assert((*M3) == m3);
}

void run_dist_object_matrix_mo_loc_list() {
int val = 42 + static_cast<int>(hpx::get_locality_id());
int rows = 5, cols = 5;

std::vector<std::vector<int>> m1(rows, std::vector<int>(cols, val));
std::vector<std::vector<int>> m2(rows, std::vector<int>(cols, val));
std::vector<std::vector<int>> m3(rows, std::vector<int>(cols, 0));

std::vector<std::size_t> locs{ 1,2 };

typedef dist_object::construction_type c_t;

dist_object::dist_object<std::vector<int>> M1("M1_meta", m1, c_t::Meta_Object, locs);
dist_object::dist_object<std::vector<int>> M2("M2_meta", m2, c_t::Meta_Object, locs);
dist_object::dist_object<std::vector<int>> M3("M3_meta", m3, c_t::Meta_Object, locs);

for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
(*M3)[i][j] = (*M1)[i][j] + (*M2)[i][j];
}
}

for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
m3[i][j] = m1[i][j] + m2[i][j];
}
}
hpx::lcos::barrier b("/meta/barrier", hpx::find_all_localities().size());
b.wait();

hpx::future<std::vector<std::vector<int>>> k = M3.fetch(1);
std::cout << "The value of first partition's first element (with meta_object and loc list) is " << k.get()[0][0] << std::endl;
assert((*M3) == m3);
}

int hpx_main() {
std::cout << "Hello world from locality " << hpx::get_locality_id() << std::endl;
run_dist_object_vector();
run_dist_object_matrix();
run_dist_object_matrix_all_to_all();
run_dist_object_matrix_mo();
std::cout << "Hello world from locality " << hpx::get_locality_id() << std::endl;
run_dist_object_matrix_mo_loc_list();
return hpx::finalize();
}

Expand Down

0 comments on commit c10f397

Please sign in to comment.