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

register_with_basename causes hangs #1804

Closed
hkaiser opened this issue Oct 20, 2015 · 3 comments · Fixed by #1807
Closed

register_with_basename causes hangs #1804

hkaiser opened this issue Oct 20, 2015 · 3 comments · Fixed by #1807

Comments

@hkaiser
Copy link
Member

hkaiser commented Oct 20, 2015

The following code was reported to hang:

//  Copyright (c) 2015 Andreas Schaefer
//
//  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 <hpx/hpx.hpp>
#include <hpx/hpx_init.hpp>

#include <iostream>
#include <vector>

#include <boost/shared_ptr.hpp>

static std::string itoa(int i)
{
    std::stringstream buf;
    buf << i;
    return buf.str();
}

struct test_server
  : hpx::components::simple_component_base<test_server>
{
    test_server()
    {}

    hpx::id_type call() const
    {
        return hpx::find_here();
    }
    HPX_DEFINE_COMPONENT_ACTION(test_server, call, call_action);
};

typedef hpx::components::simple_component<test_server> server_type;
HPX_REGISTER_COMPONENT(server_type, test_server);

typedef test_server::call_action call_action;
HPX_REGISTER_ACTION(call_action);

std::string genName(int source, int target)
{
    std::string basename = "/0/HPXSimulatorUpdateGroupSdfafafasdasd";

    return basename + "/PatchLink/" +
        itoa(source) + "-" +
        itoa(target);
}

void testBar()
{
    int rank = hpx::get_locality_id();

    std::vector<hpx::id_type> boundingBoxReceivers;
    std::vector<hpx::id_type> boundingBoxAccepters;
    for (int i = 0; i < 4; ++i) {
        if (i == rank)
            continue;

        std::string name = genName(i, rank);
        std::cout << "registration: " << name << "\n";

        hpx::id_type id = hpx::new_<test_server>(hpx::find_here()).get();
        hpx::register_with_basename(name, id, 0).get();
        boundingBoxReceivers.push_back(id);
    }

    for (int i = 0; i < 4; ++i) {
        if (i == rank)
            continue;

        std::string name = genName(rank, i);
        std::cout << "lookup: " << name << "\n";
        std::vector<hpx::future<hpx::id_type> > ids = hpx::find_all_from_basename(name, 1);
        boundingBoxAccepters.push_back(std::move(ids[0].get()));
    }

    std::cout << "all done " << rank << "\n";
}

int hpx_main(int argc, char **argv)
{
    testBar();
    return hpx::finalize();
}

int main(int argc, char **argv)
{
    // We want HPX to run hpx_main() on all localities to avoid the
    // initial overhead caused by broadcasting the work from one to
    // all other localities:
    std::vector<std::string> config(1, "hpx.run_hpx_main!=1");

    return hpx::init(argc, argv, config);
}
@hkaiser
Copy link
Member Author

hkaiser commented Oct 20, 2015

@gentryx As a workaround, the hang does not occur if you run HPX on more than one core. I know what the problem is, but I'm not sure yet how to fix it.

hkaiser added a commit that referenced this issue Oct 20, 2015
- This fixes #1804: register_with_basename causes hangs
@hkaiser
Copy link
Member Author

hkaiser commented Oct 20, 2015

@gentryx Please try the branch fixing_1804 and report back whether this fixes your issue.

@gentryx
Copy link
Member

gentryx commented Oct 20, 2015

@hkaiser Yeah, this looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants