diff --git a/CMakeLists.txt b/CMakeLists.txt index 20a02317..0c8328da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -784,6 +784,13 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/pkgconfig/apex.pc.in ${CMAKE_BINARY_DIR}/pkgconfig/apex.pc @ONLY) INSTALL_FILES(/lib/pkgconfig FILES pkgconfig/apex.pc) +if (APEX_USE_WEAK_SYMBOLS) + add_definitions(-DAPEX_USE_WEAK_SYMBOLS) +else() + find_library(DYNAMICLIB dl) + set(LIBS ${LIBS} ${DYNAMICLIB}) +endif (APEX_USE_WEAK_SYMBOLS) + message(INFO " Getting processor count...") include(ProcessorCount) # how many cores at our disposal? if(PROCESSOR_COUNT) diff --git a/src/apex/CMakeLists.hpx b/src/apex/CMakeLists.hpx index a0fd0a0f..f59a9655 100644 --- a/src/apex/CMakeLists.hpx +++ b/src/apex/CMakeLists.hpx @@ -304,6 +304,13 @@ if(APEX_WITH_MSR) hpx_libraries(${MSR_LIBRARIES}) endif() +if (APEX_USE_WEAK_SYMBOLS) + add_definitions(-DAPEX_USE_WEAK_SYMBOLS) +else() + find_library(DYNAMICLIB dl) + hpx_libraries(${DYNAMICLIB}) +endif (APEX_USE_WEAK_SYMBOLS) + set(apex_sources apex.cpp apex_options.cpp diff --git a/src/apex/apex_ompt.cpp b/src/apex/apex_ompt.cpp index 570d95e3..ceff4445 100644 --- a/src/apex/apex_ompt.cpp +++ b/src/apex/apex_ompt.cpp @@ -41,8 +41,14 @@ class linked_timer { std::shared_ptr &parent, bool auto_start) : prev(p), timing(auto_start) { - tw = apex::new_task(name, task_id, parent); - if (auto_start) { this->start(); } + // No GUIDs generated by the runtime? Generate our own. + if (task_id == 0ULL) { + tw = apex::new_task(name); + } else { + tw = apex::new_task(name, task_id, parent); + } + if (auto_start) { this->start(); + } } /* destructor */ ~linked_timer() { diff --git a/src/apex/concurrency_handler.cpp b/src/apex/concurrency_handler.cpp index 8bdd7869..852d4ac4 100644 --- a/src/apex/concurrency_handler.cpp +++ b/src/apex/concurrency_handler.cpp @@ -77,7 +77,7 @@ bool concurrency_handler::_handler(void) { apex* inst = apex::instance(); if (inst == nullptr) return false; // running after finalization! if (apex_options::use_tau()) { - Tau_start("concurrency_handler::_handler"); + tau_listener::Tau_start_wrapper("concurrency_handler::_handler"); } map *counts = new(map); @@ -119,7 +119,7 @@ bool concurrency_handler::_handler(void) { _power_samples.push_back(power); } if (apex_options::use_tau()) { - Tau_stop("concurrency_handler::_handler"); + tau_listener::Tau_stop_wrapper("concurrency_handler::_handler"); } #ifdef APEX_WITH_JUPYTER_SUPPORT // update the timeout, if the user changed it. diff --git a/src/apex/otf2_listener.cpp b/src/apex/otf2_listener.cpp index 81689435..73c722d9 100644 --- a/src/apex/otf2_listener.cpp +++ b/src/apex/otf2_listener.cpp @@ -293,7 +293,8 @@ namespace apex { if (evt_writer == nullptr && create) { // should already be locked by the "new thread" event. uint64_t my_node_id = my_saved_node_id; - my_node_id = (my_node_id << 32) + thread_instance::get_id(); + //my_node_id = (my_node_id << 32) + thread_instance::get_id(); + my_node_id = (my_node_id << 32) + _event_threads.size(); evt_writer = OTF2_Archive_GetEvtWriter( archive, my_node_id ); if (thread_instance::get_id() == 0) { comm_evt_writer = evt_writer; @@ -570,11 +571,12 @@ namespace apex { uint64_t map_size = global_region_indices.size(); OTF2_IdMap * my_map = OTF2_IdMap_CreateFromUint64Array(map_size, mappings, false); - for (int i = 0 ; i < thread_instance::get_num_threads() ; i++) { - if (event_file_exists(i)) { + //for (int i = 0 ; i < thread_instance::get_num_threads() ; i++) { + for (size_t i = 0 ; i < _event_threads.size() ; i++) { + //if (event_file_exists(i)) { OTF2_DefWriter_WriteMappingTable(getDefWriter(i), OTF2_MAPPING_REGION, my_map); - } + //} } // free the map OTF2_IdMap_Free(my_map); @@ -598,11 +600,12 @@ namespace apex { uint64_t map_size = global_metric_indices.size(); OTF2_IdMap * my_map = OTF2_IdMap_CreateFromUint64Array(map_size, mappings, false); - for (int i = 0 ; i < thread_instance::get_num_threads() ; i++) { - if (event_file_exists(i)) { + //for (int i = 0 ; i < thread_instance::get_num_threads() ; i++) { + for (size_t i = 0 ; i < _event_threads.size() ; i++) { + //if (event_file_exists(i)) { OTF2_DefWriter_WriteMappingTable(getDefWriter(i), OTF2_MAPPING_METRIC, my_map); - } + //} } // free the map OTF2_IdMap_Free(my_map); @@ -717,7 +720,8 @@ namespace apex { /* if we are node 0, write the global definitions */ if (my_saved_node_id == 0) { // save my number of threads - rank_thread_map[0] = thread_instance::get_num_threads(); + //rank_thread_map[0] = thread_instance::get_num_threads(); + rank_thread_map[0] = _event_threads.size(); std::cout << "Writing OTF2 definition files..." << std::endl; // make a common list of regions and metrics across all nodes... reduce_regions(); @@ -800,12 +804,13 @@ namespace apex { // write out the counter names we saw reduce_metrics(); } - for (int i = 0 ; i < thread_instance::get_num_threads() ; i++) { + //for (int i = 0 ; i < thread_instance::get_num_threads() ; i++) { + for (size_t i = 0 ; i < _event_threads.size() ; i++) { /* close (and possibly create) the definition files */ - if (event_file_exists(i)) { + //if (event_file_exists(i)) { OTF2_EC(OTF2_Archive_CloseDefWriter( archive, getDefWriter(i) )); - } + //} } if (my_saved_node_id == 0) { std::cout << "Closing the archive..." << std::endl; @@ -983,7 +988,8 @@ namespace apex { // create an attribute list OTF2_AttributeList * al = OTF2_AttributeList_New(); // create an attribute - OTF2_AttributeList_AddUint64( al, 0, p->guid ); + OTF2_AttributeList_AddUint64( al, 0, p->tt_ptr->guid ); + OTF2_AttributeList_AddUint64( al, 1, p->tt_ptr->parent_guid ); // unfortunately, we can't use the timestamp from the // profiler object. bummer. it has to be taken after // the lock is acquired, so that events happen on @@ -1184,7 +1190,8 @@ namespace apex { std::string otf2_listener::write_my_regions(void) { stringstream region_file; // first, output our number of threads. - region_file << thread_instance::get_num_threads() << endl; + //region_file << thread_instance::get_num_threads() << endl; + region_file << _event_threads.size() << endl; // then iterate over the regions and write them out. for (auto const &i : global_region_indices) { task_identifier id = i.first; @@ -1323,7 +1330,8 @@ namespace apex { std::string otf2_listener::write_my_metrics(void) { stringstream metric_file; // first, output our number of threads. - metric_file << thread_instance::get_num_threads() << endl; + //metric_file << thread_instance::get_num_threads() << endl; + metric_file << _event_threads.size() << endl; // then iterate over the metrics and write them out. for (auto const &i : global_metric_indices) { string id = i.first; @@ -1512,7 +1520,8 @@ namespace apex { region_filename << region_filename_prefix << my_saved_node_id; ofstream region_file(region_filename.str(), ios::out | ios::trunc ); // first, output our number of threads. - region_file << thread_instance::get_num_threads() << endl; + //region_file << thread_instance::get_num_threads() << endl; + region_file << _event_threads.size() << endl; // then iterate over the regions and write them out. for (auto const &i : global_region_indices) { task_identifier id = i.first; @@ -1649,7 +1658,8 @@ namespace apex { metric_filename << metric_filename_prefix << my_saved_node_id; ofstream metric_file(metric_filename.str(), ios::out | ios::trunc ); // first, output our number of threads. - metric_file << thread_instance::get_num_threads() << endl; + //metric_file << thread_instance::get_num_threads() << endl; + metric_file << _event_threads.size() << endl; // then iterate over the metrics and write them out. for (auto const &i : global_metric_indices) { string id = i.first; diff --git a/src/apex/otf2_listener.hpp b/src/apex/otf2_listener.hpp index 79885eb5..e169ffff 100644 --- a/src/apex/otf2_listener.hpp +++ b/src/apex/otf2_listener.hpp @@ -9,7 +9,7 @@ #include "event_listener.hpp" #include #include -#include +#include #include #include #include @@ -29,7 +29,7 @@ namespace apex { std::mutex _metric_mutex; std::mutex _comm_mutex; std::mutex _event_set_mutex; - std::unordered_set _event_threads; + std::set _event_threads; /* this is a reader/writer lock. Don't close the archive * if other threads are writing to it. but allow concurrent * access from the writer threads. */ diff --git a/src/apex/policy_handler.cpp b/src/apex/policy_handler.cpp index 570e16da..1b2ae349 100644 --- a/src/apex/policy_handler.cpp +++ b/src/apex/policy_handler.cpp @@ -71,12 +71,12 @@ namespace apex { this->_reset(); if (_terminate) return true; if (apex_options::use_tau()) { - Tau_start("policy_handler::_handler"); + tau_listener::Tau_start_wrapper("policy_handler::_handler"); } periodic_event_data data; this->on_periodic(data); if (apex_options::use_tau()) { - Tau_stop("policy_handler::_handler"); + tau_listener::Tau_stop_wrapper("policy_handler::_handler"); } return true; } diff --git a/src/apex/proc_read.cpp b/src/apex/proc_read.cpp index ea140423..32ab03be 100644 --- a/src/apex/proc_read.cpp +++ b/src/apex/proc_read.cpp @@ -583,7 +583,7 @@ void* proc_data_reader::read_proc(void * _ptw) { _initialized = true; } if (apex_options::use_tau()) { - Tau_start("proc_data_reader::read_proc"); + tau_listener::Tau_start_wrapper("proc_data_reader::read_proc"); } if (done) { return nullptr; } #ifdef APEX_HAVE_LM_SENSORS @@ -605,7 +605,7 @@ void* proc_data_reader::read_proc(void * _ptw) { while(ptw->wait()) { if (done) break; if (apex_options::use_tau()) { - Tau_start("proc_data_reader::read_proc: main loop"); + tau_listener::Tau_start_wrapper("proc_data_reader::read_proc: main loop"); } if (apex_options::use_proc_stat()) { // take a reading @@ -630,7 +630,7 @@ void* proc_data_reader::read_proc(void * _ptw) { #endif if (apex_options::use_tau()) { - Tau_stop("proc_data_reader::read_proc: main loop"); + tau_listener::Tau_stop_wrapper("proc_data_reader::read_proc: main loop"); } } #ifdef APEX_HAVE_LM_SENSORS @@ -638,7 +638,7 @@ void* proc_data_reader::read_proc(void * _ptw) { #endif if (apex_options::use_tau()) { - Tau_stop("proc_data_reader::read_proc"); + tau_listener::Tau_stop_wrapper("proc_data_reader::read_proc"); } delete(oldData); thread_instance::delete_instance(); diff --git a/src/apex/profiler_listener.cpp b/src/apex/profiler_listener.cpp index 583468d4..f4feb967 100644 --- a/src/apex/profiler_listener.cpp +++ b/src/apex/profiler_listener.cpp @@ -587,7 +587,7 @@ std::unordered_set free_profiles; * file, or both. */ void profiler_listener::finalize_profiles(dump_event_data &data) { if (apex_options::use_tau()) { - Tau_start("profiler_listener::finalize_profiles"); + tau_listener::Tau_start_wrapper("profiler_listener::finalize_profiles"); } // our TOTAL available time is the elapsed * the number of threads, or cores int num_worker_threads = thread_instance::get_num_threads(); @@ -718,7 +718,7 @@ std::unordered_set free_profiles; csvfile.close(); } if (apex_options::use_tau()) { - Tau_stop("profiler_listener::finalize_profiles"); + tau_listener::Tau_stop_wrapper("profiler_listener::finalize_profiles"); } } @@ -1038,7 +1038,7 @@ node_color * get_node_color(double v,double vmin,double vmax) _initialized = true; } if (apex_options::use_tau()) { - Tau_start("profiler_listener::process_profiles"); + tau_listener::Tau_start_wrapper("profiler_listener::process_profiles"); } std::shared_ptr p; @@ -1076,7 +1076,7 @@ node_color * get_node_color(double v,double vmin,double vmax) while (!_done) { queue_signal.wait(); if (apex_options::use_tau()) { - Tau_start("profiler_listener::process_profiles: main loop"); + tau_listener::Tau_start_wrapper("profiler_listener::process_profiles: main loop"); } { std::unique_lock queue_lock(queue_mtx); @@ -1095,7 +1095,7 @@ node_color * get_node_color(double v,double vmin,double vmax) } } if (apex_options::use_tau()) { - Tau_stop("profiler_listener::process_profiles: main loop"); + tau_listener::Tau_stop_wrapper("profiler_listener::process_profiles: main loop"); } // release the flag, and wait for the queue_signal consumer_task_running.clear(memory_order_release); @@ -1109,7 +1109,7 @@ node_color * get_node_color(double v,double vmin,double vmax) #endif if (apex_options::use_tau()) { - Tau_stop("profiler_listener::process_profiles"); + tau_listener::Tau_stop_wrapper("profiler_listener::process_profiles"); } } @@ -1276,11 +1276,11 @@ if (rc != 0) cout << "PAPI error! " << name << ": " << PAPI_strerror(rc) << endl std::unique_lock queue_lock(queue_mtx); for (unsigned int i=0; iguid = thread_instance::get_guid(); + p->guid = tt_ptr->guid; thread_instance::instance().set_current_profiler(p); #if APEX_HAVE_PAPI if (num_papi_counters > 0 && !apex_options::papi_suspend()) { diff --git a/src/apex/tau_dummy.cpp b/src/apex/tau_dummy.cpp index 9386bc34..13fb3103 100644 --- a/src/apex/tau_dummy.cpp +++ b/src/apex/tau_dummy.cpp @@ -8,6 +8,8 @@ using namespace std; +#ifdef APEX_USE_WEAK_SYMBOLS + /* Weak symbols that are redefined if we use TAU at runtime */ extern "C" { APEX_EXPORT APEX_WEAK_PRE int Tau_init(int, char**) APEX_WEAK_POST { @@ -24,7 +26,7 @@ APEX_EXPORT APEX_WEAK_PRE int APEX_EXPORT APEX_WEAK_PRE int Tau_start(const char *) APEX_WEAK_POST {return 0;} APEX_EXPORT APEX_WEAK_PRE int Tau_stop(const char *) APEX_WEAK_POST {return 0;} APEX_EXPORT APEX_WEAK_PRE int Tau_exit(const char*) APEX_WEAK_POST {return 0;} -APEX_EXPORT APEX_WEAK_PRE int Tau_dump(void) APEX_WEAK_POST {return 0;} +APEX_EXPORT APEX_WEAK_PRE int Tau_dump_prefix(const char*) APEX_WEAK_POST {return 0;} APEX_EXPORT APEX_WEAK_PRE int Tau_set_node(int) APEX_WEAK_POST {return 0;} APEX_EXPORT APEX_WEAK_PRE int Tau_profile_exit_all_threads(void) APEX_WEAK_POST {return 0;} @@ -35,3 +37,5 @@ APEX_EXPORT APEX_WEAK_PRE int Tau_global_stop(void) APEX_WEAK_POST {return 0;} APEX_EXPORT APEX_WEAK_PRE int Tau_trigger_context_event_thread(char*, double, int) APEX_WEAK_POST {return 0;} } + +#endif // APEX_USE_WEAK_SYMBOLS diff --git a/src/apex/tau_listener.cpp b/src/apex/tau_listener.cpp index 8893c483..c32f6727 100644 --- a/src/apex/tau_listener.cpp +++ b/src/apex/tau_listener.cpp @@ -9,6 +9,26 @@ #include #include +#ifndef APEX_USE_WEAK_SYMBOLS +#define _GNU_SOURCE +#include +#endif // APEX_USE_WEAK_SYMBOLS + +typedef int (*Tau_init_type)(int argc, char **argv); +typedef int (*Tau_register_thread_type)(void); +typedef int (*Tau_create_top_level_timer_if_necessary_type)(void); +typedef int (*Tau_start_type)(const char *); +typedef int (*Tau_stop_type)(const char *); +typedef int (*Tau_exit_type)(const char*); +typedef int (*Tau_dump_prefix_type)(const char *prefix); +typedef int (*Tau_set_node_type)(int); +typedef int (*Tau_profile_exit_all_threads_type)(void); +typedef int (*Tau_get_thread_type)(void); +typedef int (*Tau_profile_exit_all_tasks_type)(void); +typedef int (*Tau_global_stop_type)(void); +typedef int (*Tau_trigger_context_event_thread_type)(char*, double, int); +typedef int (*Tau_metadata_type)(const char*, const char*); + using namespace std; namespace apex { @@ -26,9 +46,12 @@ int (*my_Tau_get_thread)(void) = nullptr; int (*my_Tau_profile_exit_all_tasks)(void) = nullptr; int (*my_Tau_global_stop)(void) = nullptr; int (*my_Tau_trigger_context_event_thread)(char*, double, int) = nullptr; +int (*my_Tau_metadata)(const char*, const char*) = NULL; bool tau_listener::_initialized(false); +#ifdef APEX_USE_WEAK_SYMBOLS + bool assign_function_pointers(void) { if (Tau_init == nullptr) { /* Print an error message, because TAU wasn't preloaded! */ @@ -78,6 +101,79 @@ bool assign_function_pointers(void) { return true; } +#else + +void open_preload_libraries(void) { + /* We might be in a static executable. Get the ld_preload variable */ + const char * preload = getenv("LD_PRELOAD"); + if (preload != NULL) { + fprintf(stderr, "LD_PRELOAD:\n%s\n", preload); + /* tokenize it */ + char* token = strtok(const_cast(preload), ":"); + while (token) { + printf("token: %s\n", token); + /* then, dlopen() first and re-try the dlsym() call. */ + dlopen(token, RTLD_LAZY); + token = strtok(NULL, ":"); + } + } +} + +bool assign_function_pointers(void) { + my_Tau_init = (Tau_init_type)dlsym(RTLD_DEFAULT,"Tau_init"); + if (my_Tau_init == NULL) { + open_preload_libraries(); + my_Tau_init = (Tau_init_type)dlsym(RTLD_DEFAULT,"Tau_init"); + if (my_Tau_init == NULL) { + /* Optional - print an error message, because TAU wasn't preloaded! */ + fprintf(stderr, "TAU libraries not loaded, TAU support unavailable:\n\t%s\n", dlerror()); + return false; + } + } + my_Tau_register_thread = + (Tau_register_thread_type) + dlsym(RTLD_DEFAULT,"Tau_register_thread"); + my_Tau_create_top_level_timer_if_necessary = + (Tau_create_top_level_timer_if_necessary_type) + dlsym(RTLD_DEFAULT,"Tau_create_top_level_timer_if_necessary"); + my_Tau_start = + (Tau_start_type) + dlsym(RTLD_DEFAULT,"Tau_start"); + my_Tau_stop = + (Tau_stop_type) + dlsym(RTLD_DEFAULT,"Tau_stop"); + my_Tau_dump_prefix = + (Tau_dump_prefix_type) + dlsym(RTLD_DEFAULT,"Tau_dump_prefix"); + my_Tau_exit = + (Tau_exit_type) + dlsym(RTLD_DEFAULT,"Tau_exit"); + my_Tau_set_node = + (Tau_set_node_type) + dlsym(RTLD_DEFAULT,"Tau_set_node"); + my_Tau_profile_exit_all_threads = + (Tau_profile_exit_all_threads_type) + dlsym(RTLD_DEFAULT,"Tau_profile_exit_all_threads"); + my_Tau_get_thread = + (Tau_get_thread_type) + dlsym(RTLD_DEFAULT,"Tau_get_thread"); + my_Tau_profile_exit_all_tasks = + (Tau_profile_exit_all_tasks_type) + dlsym(RTLD_DEFAULT,"Tau_profile_exit_all_tasks"); + my_Tau_global_stop = + (Tau_global_stop_type) + dlsym(RTLD_DEFAULT,"Tau_global_stop"); + my_Tau_trigger_context_event_thread = + (Tau_trigger_context_event_thread_type) + dlsym(RTLD_DEFAULT,"Tau_trigger_context_event_thread"); + my_Tau_metadata = + (Tau_metadata_type) + dlsym(RTLD_DEFAULT,"Tau_metadata"); + return true; +} + +#endif // APEX_USE_WEAK_SYMBOLS + bool tau_listener::initialize_tau(int argc, char** argv) { _initialized = assign_function_pointers(); if (!_initialized) { return false; } @@ -217,9 +313,13 @@ bool tau_listener::initialize_tau(int argc, char** argv) { my_Tau_set_node(node_id); } + void tau_listener::set_metadata(const char * name, const char * value) { + my_Tau_metadata(name, value); + } + /* This function is used by APEX threads so that TAU knows about them. */ int initialize_worker_thread_for_tau(void) { - if (apex_options::use_tau()) + if (tau_listener::initialized()) { my_Tau_register_thread(); my_Tau_create_top_level_timer_if_necessary(); @@ -227,5 +327,16 @@ bool tau_listener::initialize_tau(int argc, char** argv) { return 0; } + void tau_listener::Tau_start_wrapper(const char * name) { + if (tau_listener::initialized()) { + my_Tau_start(name); + } + } + + void tau_listener::Tau_stop_wrapper(const char * name) { + if (tau_listener::initialized()) { + my_Tau_global_stop(); // stop the top level timer + } + } } diff --git a/src/apex/tau_listener.hpp b/src/apex/tau_listener.hpp index e1e38329..7637c9be 100644 --- a/src/apex/tau_listener.hpp +++ b/src/apex/tau_listener.hpp @@ -21,6 +21,7 @@ class tau_listener : public event_listener { tau_listener (void); ~tau_listener (void) { }; static bool initialize_tau(int argc, char** avgv); + inline static bool initialized(void) { return _initialized; } void on_startup(startup_event_data &data); void on_dump(dump_event_data &data); void on_reset(task_identifier * id) @@ -42,13 +43,18 @@ class tau_listener : public event_listener { void on_send(message_event_data &data) { APEX_UNUSED(data); }; void on_recv(message_event_data &data) { APEX_UNUSED(data); }; void set_node_id(int node_id, int node_count); + void set_metadata(const char * name, const char * value); + static void Tau_start_wrapper(const char * name); + static void Tau_stop_wrapper(const char * name); }; int initialize_worker_thread_for_tau(void); } +#ifdef APEX_USE_WEAK_SYMBOLS + /* Weak symbols that are redefined if we load TAU at link or runtime */ extern "C" { APEX_EXPORT APEX_WEAK_PRE int Tau_register_thread(void) APEX_WEAK_POST; @@ -67,3 +73,5 @@ APEX_EXPORT APEX_WEAK_PRE int Tau_global_stop(void) APEX_WEAK_POST; APEX_EXPORT APEX_WEAK_PRE int Tau_trigger_context_event_thread(char*, double, int) APEX_WEAK_POST; } + +#endif // APEX_USE_WEAK_SYMBOLS diff --git a/src/unit_tests/C++/apex_hpx_task_wrapper_direct_actions.cpp b/src/unit_tests/C++/apex_hpx_task_wrapper_direct_actions.cpp index 71fe791d..4b5f1526 100644 --- a/src/unit_tests/C++/apex_hpx_task_wrapper_direct_actions.cpp +++ b/src/unit_tests/C++/apex_hpx_task_wrapper_direct_actions.cpp @@ -52,7 +52,8 @@ void innerLoop(int *tid) { std::shared_ptr tt_ptr = apex::new_task(__func__); #ifdef __DEBUG_PRINT__ std::stringstream buf; - buf << "APP: " << *tid << ": Starting thread " << tt_ptr->guid << "\n"; std::cout << buf.str(); + buf << "APP: " << *tid << ": Starting innerLoop " << tt_ptr->guid << + " Parent: " << tt_ptr->parent_guid << "\n"; std::cout << buf.str(); #endif apex::start(tt_ptr); @@ -63,7 +64,8 @@ void innerLoop(int *tid) { std::shared_ptr af = apex::new_task("direct_action"); #ifdef __DEBUG_PRINT__ buf.str(""); buf.clear(); - buf << "APP: " << *tid << ": Starting direct_action " << af->guid << "\n"; std::cout << buf.str(); + buf << "APP: " << *tid << ": Starting direct_action " << af->guid << + " Parent: " << tt_ptr->parent_guid << "\n"; std::cout << buf.str(); #endif apex::start(af); @@ -144,7 +146,8 @@ int main (int argc, char** argv) { if (argc > 1) { test_numthreads = strtoul(argv[1],NULL,0); } else { - test_numthreads = apex::hardware_concurrency() * threads_per_core; // many threads per core. Stress it! + // many threads per core. Stress it! + test_numthreads = apex::hardware_concurrency() * threads_per_core; } #ifndef __APPLE__ pthread_barrier_init(&barrier, NULL, test_numthreads); diff --git a/src/unit_tests/C++/apex_non_worker_thread.cpp b/src/unit_tests/C++/apex_non_worker_thread.cpp index c16573d9..acab3595 100644 --- a/src/unit_tests/C++/apex_non_worker_thread.cpp +++ b/src/unit_tests/C++/apex_non_worker_thread.cpp @@ -3,14 +3,16 @@ #include #include #include +#include +#include "thread_instance.hpp" -#define MAX_OUTER 500 -#define MAX_INNER 500 +#define MAX_OUTER 50 +#define MAX_INNER 50 #define MAX_THREADS 8 uint64_t func(uint64_t i) { char name[128]; - sprintf(name, "func %lu", i); + sprintf(name, "func %llu", static_cast(i)); apex::profiler* p = apex::start(std::string(name)); uint64_t j = i * i; apex::stop(p); @@ -19,6 +21,7 @@ uint64_t func(uint64_t i) { uint64_t foo(uint64_t i) { uint64_t j=0; + apex::register_thread(__func__); apex::profiler* p = apex::start((apex_function_address)(&foo)); for (uint64_t x = 0 ; x < MAX_OUTER ; x++) { for (uint64_t y = 0 ; y < MAX_INNER ; y++) { @@ -31,14 +34,17 @@ uint64_t foo(uint64_t i) { // no timer! uint64_t bar(uint64_t i) { + // ask for a thread instance, as a test. + // + //apex::thread_instance::instance(false); + // create a task, but don't start a timer. + apex::new_task((apex_function_address)&bar); uint64_t j=0; for (uint64_t x = 0 ; x < MAX_OUTER ; x++) { for (uint64_t y = 0 ; y < MAX_INNER ; y++) { j += (x*x) * (y*y) + i; } } - // ask for a thread instance, as a test. - apex::thread_instance::instance(false); return j; }