Hello all,
I've run into some issues with the registration of global ids with global
names.
I'm working with the latest hpx trunk.
I have to create several instances of server component objects, which then
have to be found by client objects.
At the time of creation of the server components there are no client
objects yet, as they are supposed to register while the simulation is
running.
In order to find the gids of the server components, I wanted to register
them under a global base name using hpx::register_id_with_basename(), and
retrieve them with hpx::find_all_ids_from_basename(). Looking at those
functions, I thought that multiple ids with the same name should be
possible. The registration of these gids seems to work fine, as the return
value is always true.
But when retrieving those objects, I ran into several problems.
- I don't know the exact number of server objects that will be created but
hpx::find_all_ids_from_basename() expects me to know the expected number
(Though, this might be solvable in another way, as there *should* be as
many of them as there are localities.)
- When trying to use f.get() on anything but the first element in the
vector returned by hpx::find_all_ids_from_basename() the thread doesn't
return.
I was hoping you could tell me what I'm doing wrong, or if there is a
better solution to this problem.
I've attached a minimal example of my code.
Thank you very much for your help.
Regards, Konstantin
#include <hpx/config.hpp>
#include <hpx/hpx_fwd.hpp>
#include <hpx/include/actions.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/components.hpp>
#include <hpx/include/serialization.hpp>
#include <boost/format.hpp>
using namespace std;
namespace server
{
struct ViewRegistrationListener
: hpx::components::managed_component_base<ViewRegistrationListener>
{
ViewRegistrationListener() :
name("<unknown>")
{
cout << "constructed server listener without name" << endl;
}
ViewRegistrationListener(const string &name) :
name(name)
{
cout << boost::format("constructed server listener %1% (%2%)") % name % this << endl;
}
void register_view();
HPX_DEFINE_COMPONENT_ACTION(ViewRegistrationListener, register_view);
string name;
};
}
HPX_REGISTER_ACTION_DECLARATION(server::ViewRegistrationListener::register_view_action, view_registration_listener_register_view_action);
namespace stubs
{
struct ViewRegistrationListener : hpx::components::stub_base<server::ViewRegistrationListener>
{
ViewRegistrationListener()
{
cout << "constructed listener stub" << endl;
}
static void register_view(hpx::naming::id_type const &gid)
{
hpx::async<server::ViewRegistrationListener::register_view_action>(gid).get();
}
};
}
namespace client
{
struct ViewRegistrationListener
: hpx::components::client_base<ViewRegistrationListener, stubs::ViewRegistrationListener>
{
typedef hpx::components::client_base<ViewRegistrationListener, stubs::ViewRegistrationListener> base_type;
ViewRegistrationListener(hpx::future<hpx::naming::id_type> gid)
: base_type(move(gid))
{
cout << "constructed listener client by future" << endl;
}
ViewRegistrationListener(hpx::naming::id_type gid)
: base_type(gid)
{
cout << "constructed listener client by gid" << endl;
}
void register_view()
{
this->base_type::register_view(this->get_gid());
}
};
}
namespace server
{
void ViewRegistrationListener::register_view()
{
cout << boost::format("register view at listener %1% (%2%)") % name % this << endl;
}
}
HPX_REGISTER_COMPONENT_MODULE();
typedef hpx::components::managed_component<server::ViewRegistrationListener> view_registration_listener_type;
HPX_REGISTER_MINIMAL_COMPONENT_FACTORY(view_registration_listener_type, ViewRegistrationListener);
HPX_REGISTER_ACTION(server::ViewRegistrationListener::register_view_action, view_registration_listener_register_view_action);
int hpx_main()
{
{
auto id = hpx::new_<server::ViewRegistrationListener>(hpx::find_here(), string("A")).get();
cout << hpx::register_id_with_basename("Listener", id).get() << endl;
}
{
auto id = hpx::new_<server::ViewRegistrationListener>(hpx::find_here(), string("B")).get();
cout << hpx::register_id_with_basename("Listener", id).get() << endl;
}
{
auto id = hpx::new_<server::ViewRegistrationListener>(hpx::find_here(), string("C")).get();
cout << hpx::register_id_with_basename("Listener", id).get() << endl;
}
{
auto ids = hpx::find_all_ids_from_basename("Listener", 3);
for (auto &f : ids)
{
cout << "trying to get id" << endl;
auto id = f.get(); // works for the first element, hangs for the others
cout << "resolved id: " << id << endl;
client::ViewRegistrationListener client(id);
cout << "created client with id " << client.get_gid() << endl;
client.register_view();
client.register_view();
cout << "registered everything at this id" << endl;
}
}
return hpx::finalize();
}
int main(int argc, char **argv)
{
return hpx::init(argc, argv);
}
_______________________________________________
hpx-users mailing list
[email protected]
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users