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

HPX counters crashing the application #3224

Closed
xaguilar opened this issue Mar 9, 2018 · 12 comments
Closed

HPX counters crashing the application #3224

xaguilar opened this issue Mar 9, 2018 · 12 comments

Comments

@xaguilar
Copy link
Contributor

xaguilar commented Mar 9, 2018

Using HPX counters in a std::thread makes the program crash.

I create an additional thread to sample some HPX counters with a certain frequency using:

sampler_thread = std::thread(&my_sampling_funct, this);

Then if I create/use a counter in my_sampling_funct, the program crashes.

  • HPX Version: latest
  • Platform (compiler, OS): gcc 7.2.0, CentOS 7.4.1708
@hkaiser
Copy link
Member

hkaiser commented Mar 9, 2018

Could you provide us with a small reproducing test case for this. The way you describe it does not allow for any diagnostics or even fixing. Thanks.

@RANJEET16520
Copy link

Could you give any kind of test case. I am not understand even where it will crash so don't know how to fix it. Thanks

@hkaiser
Copy link
Member

hkaiser commented Mar 10, 2018

@RANJEET16520 I didn't ask you to fix it. I asked you to give us some code that allows us to reproduce the problem you're seeing.

@xaguilar
Copy link
Contributor Author

xaguilar commented Mar 10, 2018

Hi all, I'm sorry that I wasn't clear enough when I opened the issue. Please find below a simplified example where this error occurs.

#include <hpx/hpx_init.hpp>
#include <hpx/include/performance_counters.hpp>
#include <iostream>
#include <thread>

#include <boost/format.hpp>

hpx::id_type idle_rate_counter_;

void my_sampling_funct(void)
{
    // Create one counter per locality
    static const char* idle_counter_name =
        "/threads{locality#%d/total}/idle-rate";

    const std::uint32_t prefix = hpx::get_locality_id();

    std::cerr << "Registering counter "
              << boost::str(boost::format(idle_counter_name) % prefix)
              << std::endl;
    idle_rate_counter_ = hpx::performance_counters::get_counter(
        boost::str(boost::format(idle_counter_name) % prefix));

    // Start the counter
    hpx::performance_counters::stubs::performance_counter::start(
        hpx::launch::sync, idle_rate_counter_);

    // Get the value
    hpx::performance_counters::counter_value idle_value =
        hpx::performance_counters::stubs::performance_counter::get_value(
            hpx::launch::sync, idle_rate_counter_);

    double idle_rate_ = idle_value.get_value<double>() * 0.01;

    std::cout << "Idle rate: " << idle_rate_ << std::endl;

    // Stop the counter
    hpx::performance_counters::stubs::performance_counter::stop(
        hpx::launch::sync, idle_rate_counter_);
}

int hpx_main(int argc, char** argv)
{
    // Create one additional OS-thread
    std::thread sampler_thread = std::thread(&my_sampling_funct);

    sampler_thread.join();

    hpx::finalize();

    //std::terminate();
    return 0;
}

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

Please don't hesitate to ask me again if you need further assistance. Thanks!

@RANJEET16520
Copy link

RANJEET16520 commented Mar 10, 2018 via email

@hkaiser
Copy link
Member

hkaiser commented Mar 12, 2018

@RANJEET16520 Thanks for the code snippet. I'm not sure why you decided to create a new (kernel-) thread for your test function. I would advise not to do that. You should create an HPX thread instead. Either simply switch std::thread for hpx::thread or use hpx::async to launch your function on a new HPX thread. I personally prefer the latter as directly using ...::thread does not (conceptually) scale well.

Generally, it is not possible to directly invoke (most of) HPX's functionality from arbitrary kernel-threads. For this to be possible those threads have to be registered with the runtime. I however admit that the generated error message could be more descriptive. I'll make a note to work on this.

@hkaiser hkaiser closed this as completed Mar 12, 2018
@hkaiser hkaiser added this to the 1.1.0 milestone Mar 12, 2018
@xaguilar
Copy link
Contributor Author

Hi, thanks a lot for your explanation. I wasn't aware that blending kernel threads with HPX wasn't a good idea. I needed to sample the counters every certain period and as I already had a thread doing some work at a certain frequency, I just added the code in there. In any case, knowing now that doing this is not good, I'll move all that code to a function used together with hpx::util::interval_time (I wasn't aware either of such HPX utility actually) and I'll remove the additional thread creation. Thanks again!

@RANJEET16520
Copy link

RANJEET16520 commented Mar 19, 2018 via email

@xaguilar
Copy link
Contributor Author

Which header file? What errors do you have? I could compile this small example in my environment without any problems.

@hkaiser
Copy link
Member

hkaiser commented Mar 19, 2018

@RANJEET16520 you'll have to be a bit more specific about what errors you're seeing. Also, in order to help we'd need to see the code that causes errors for you (or better, a minimal self-contained example that demonstrates the issue you're seeing).

@RANJEET16520
Copy link

RANJEET16520 commented Mar 20, 2018 via email

@hkaiser
Copy link
Member

hkaiser commented Mar 20, 2018

@RANJEET16520 You're saying "...except this error". What error specifically? Can you paste it somewhere?

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

4 participants