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

Async action on component present on hpx::find_here is executing synchronously #2424

Closed
grgvineet opened this issue Dec 12, 2016 · 2 comments

Comments

@grgvineet
Copy link

grgvineet commented Dec 12, 2016

Created a components on each available locality and executed action on it. Future returned by the component on hpx::find_here is always ready. It appears that it is scheduled immediately where as what I expect it to to schedule it on a separate OS thread and wait_all at the end waits for all.

Using latest master branch of HPX
HPX built in release mode
More than 1 OS thread is used for locality 0
Tested using 1, 2, 3, 4 localities

Minimal code used for testing

#include <hpx/hpx_init.hpp> 
#include <hpx/include/actions.hpp> 
#include <hpx/include/components.hpp> 
#include <hpx/lcos/wait_all.hpp>

#include <utility> 
#include <vector>
#include <ctime>
#include <cstdlib>

struct bar_server : public hpx::components::component_base<bar_server> 
{ 
    int get_foo() { 
        for(int i=0; i<1000000000LL; i++); // waste some time and return
        return 42;
    } 
    HPX_DEFINE_COMPONENT_DIRECT_ACTION(bar_server, get_foo, get_foo_action); 
}; 
using bar_server_type = hpx::components::component<bar_server>; 
HPX_REGISTER_COMPONENT(bar_server_type, bar_server); 

HPX_REGISTER_ACTION(bar_server::get_foo_action); 

struct bar : public hpx::components::client_base<bar, bar_server> 
{ 
    public: 
        using base_type = hpx::components::client_base<bar, bar_server>; 

        bar() = default; 

        bar(hpx::id_type id) : base_type(hpx::new_<bar_server>(id)) 
        { 
        } 

        hpx::future<int> get_foo() { 
            bar_server::get_foo_action act; 
            return hpx::async(act, get_id()); 
        } 

}; 

int hpx_main(int, char*[]) 
{ 

    std::vector<hpx::naming::id_type> localities = hpx::find_all_localities();

    std::srand(std::time(NULL));
    std::vector<bar> bs;
    for(int i=0; i<localities.size(); i++) {
        if (localities[i] == hpx::find_here()) {
            continue; // Ignore this locality for now
        }
        bs.push_back(bar(localities[i])); 
    }
    int this_loc_bs_index = (int)(std::rand()%localities.size());
    bs.insert(bs.begin() + this_loc_bs_index, hpx::find_here());
    std::cout << "find_here bs index " << this_loc_bs_index << std::endl;
    std::vector<hpx::future<int>> f;
    for(int i=0; i<bs.size(); i++) {
        f.push_back(bs[i].get_foo());
        std::cout << i <<  " Is future ready " << f.back().is_ready() << std::endl; 
    }
    hpx::wait_all(f);

    return hpx::finalize(); 
} 

int main(int argc, char* argv[]) 
{ 
    return hpx::init(argc, argv); 
}

Future for component of b on hpx::find_here is always ready.

@hkaiser hkaiser added this to the 1.0.0 milestone Dec 12, 2016
@hkaiser
Copy link
Member

hkaiser commented Dec 12, 2016

That's exactly what direct actions are for. They are executed inline if execution is local. If you need asynchronous behavior, please use

HPX_DEFINE_COMPONENT_ACTION(bar_server, get_foo, get_foo_action); 

instead.

@grgvineet
Copy link
Author

Oops!, missed that.
Thanks for a quick response.

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

No branches or pull requests

2 participants