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

Unable to register new performance counter #2480

Closed
aserio opened this issue Feb 3, 2017 · 4 comments
Closed

Unable to register new performance counter #2480

aserio opened this issue Feb 3, 2017 · 4 comments

Comments

@aserio
Copy link
Contributor

aserio commented Feb 3, 2017

I am unable to register a new performance counter though I am following the pattern outlined in simplest_performance_counter.cpp My code seg. faults when I try to run the application with --hpx:print-counter=/test/new_counter

I have my code below:

#include <hpx/hpx_main.hpp>
#include <hpx/include/iostreams.hpp>
#include <hpx/include/performance_counters.hpp>
///////////////////////////////////////////////////////////////////////////////
//New counter
std::int64_t new_query(bool reset) {
 return hpx::get_locality_id();
}

void new_counter() {
 hpx::performance_counters::install_counter_type(
  "/test/new_counter",
  &new_query,
  "returns the locality"
  );
}
///////////////////////////////////////////////////////////////////////////////
int main()
{
  hpx::register_startup_function(&new_counter);
 return hpx::init();
}

int hpx_main()
{
  int a=0;

  hpx::performance_counters::performance_counter
                                 counter("/threads/count/cumulative");
  hpx::cout<<"Number of threads: "<<counter.get_value<int>().get()<<std::endl;

  hpx::cout<<"New Counter: "<<hpx::get_locality_id()<<std::endl;

  hpx::cout<<"How many times should I say hello?\n"<<hpx::flush;
  std::cin>>a;
  for (int i=0; i<a; i++) {
  //Say hello to the world!
  hpx::cout<<"Hello World\n"<<hpx::flush;
  }
  hpx::finalize();
}
@sithhell
Copy link
Member

sithhell commented Feb 3, 2017 via email

@hkaiser hkaiser added this to the 1.0.0 milestone Feb 4, 2017
@aserio
Copy link
Contributor Author

aserio commented Mar 9, 2017

@sithhell adding new_counter.start() doesn't compile as new_counter is not a class. I am creating the counter as shown in https://github.com/STEllAR-GROUP/hpx/blob/master/examples/performance_counters/simplest_performance_counter.cpp

I have compiled and ran simplest_performance_counter.cpp and it works... which confuses me more...

@hkaiser hkaiser modified the milestones: 1.0.0, 1.1.0 Apr 23, 2017
@msimberg
Copy link
Contributor

@aserio Did you resolve your problem in the end?

@hkaiser
Copy link
Member

hkaiser commented Nov 21, 2017

You will need to replace #include <hpx/hpx_main.hpp> with #include <hpx/hpx_init.hpp> and pass through int argc, char* argv[] from main to hpx::init:

#include <hpx/hpx_init.hpp>
#include <hpx/include/iostreams.hpp>
#include <hpx/include/performance_counters.hpp>

// New counter
std::int64_t new_query(bool reset)
{
    return hpx::get_num_worker_threads();
}

void new_counter()
{
    hpx::performance_counters::install_counter_type(
        "/test/new_counter", &new_query, "returns the locality");
}

int hpx_main()
{
    hpx::performance_counters::performance_counter counter("/test/new_counter");

    hpx::cout << "Number of threads: "
              << counter.get_value<int>().get()
              << std::endl;

    return hpx::finalize();
}

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

@hkaiser hkaiser closed this as completed Nov 21, 2017
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