- if (not simgrid::config::get_value<std::string>("smpi/papi-events").empty()) {
- if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
- XBT_ERROR("Could not initialize PAPI library; is it correctly installed and linked?"
- " Expected version is %u", PAPI_VER_CURRENT);
-
- typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
- boost::char_separator<char> separator_units(";");
- std::string str = simgrid::config::get_value<std::string>("smpi/papi-events");
- Tokenizer tokens(str, separator_units);
-
- // Iterate over all the computational units. This could be processes, hosts, threads, ranks... You name it.
- // I'm not exactly sure what we will support eventually, so I'll leave it at the general term "units".
- for (auto const& unit_it : tokens) {
- boost::char_separator<char> separator_events(":");
- Tokenizer event_tokens(unit_it, separator_events);
-
- int event_set = PAPI_NULL;
- if (PAPI_create_eventset(&event_set) != PAPI_OK) {
- // TODO: Should this let the whole simulation die?
- XBT_CRITICAL("Could not create PAPI event set during init.");
- }
-
- // NOTE: We cannot use a map here, as we must obey the order of the counters
- // This is important for PAPI: We need to map the values of counters back
- // to the event_names (so, when PAPI_read() has finished)!
- papi_counter_t counters2values;
-
- // Iterate over all counters that were specified for this specific
- // unit.
- // Note that we need to remove the name of the unit
- // (that could also be the "default" value), which always comes first.
- // Hence, we start at ++(events.begin())!
- for (Tokenizer::iterator events_it = ++(event_tokens.begin()); events_it != event_tokens.end(); ++events_it) {
-
- int event_code = PAPI_NULL;
- char* event_name = const_cast<char*>((*events_it).c_str());
- if (PAPI_event_name_to_code(event_name, &event_code) != PAPI_OK) {
- XBT_CRITICAL("Could not find PAPI event '%s'. Skipping.", event_name);
- continue;
- }
- if (PAPI_add_event(event_set, event_code) != PAPI_OK) {
- XBT_ERROR("Could not add PAPI event '%s'. Skipping.", event_name);
- continue;
- }
- XBT_DEBUG("Successfully added PAPI event '%s' to the event set.", event_name);
-
- counters2values.push_back(
- // We cannot just pass *events_it, as this is of type const basic_string
- std::make_pair<std::string, long long>(std::string(*events_it), 0));
- }
-
- std::string unit_name = *(event_tokens.begin());
- papi_process_data config = {.counter_data = std::move(counters2values), .event_set = event_set};
-
- units2papi_setup.insert(std::make_pair(unit_name, std::move(config)));
- }
- }
-#endif
-}
-
-void smpi_global_destroy()
-{
- smpi_bench_destroy();
- smpi_shared_destroy();
- smpi_deployment_cleanup_instances();
-
- if (simgrid::smpi::Colls::smpi_coll_cleanup_callback != nullptr)
- simgrid::smpi::Colls::smpi_coll_cleanup_callback();
-
- MPI_COMM_WORLD = MPI_COMM_NULL;