d80752bc69
* User API + reorganized lib folders - omnitrace_user_start_trace - omnitrace_user_stop_trace - omnitrace_user_start_thread_trace - omnitrace_user_stop_thread_trace - omnitrace_user_push_region - omnitrace_user_pop_region * New OpenMP examples/tests * Fix to KokkosP * OMPT support - fixed omnitrace instrumenting reporting - common invoke improvements - component::user_region * exclude kmp_threadprivate_ * Separate omnitrace into multiple files * PTL and timemory submodule updates * Active guards + USE_OMPT guards in omnitrace-dl * Tweak transpose default iterations * omnitrace-precommit build target * Omnitrace exe restructuring pt 2 - Never instrument functions with less than 4 instructions - Never instrument ompt_start_tool or nanosleep - module_function serializes heuristics - removed hash stuff from omnitrace - removed instr_procedures lambda - WAITPID_DEBUG_MESSAGE * set_state, "_hidden" fix, CI exceptions, backtrace fix - set_state function - fixed "_hidden" from appearing in print macros using __FUNCTION__ - OMNITRACE_CI_THROW - more CI checks in library - fixed backtrace init value sample issue being ignored * Tweaks to OMPT tests * cmake-formatting * Removed debug output from backtrace processing * Fix warnings and verbosity * omnitrace-dl fix for libomp * omnitrace-avail fixes - remove second omnitrace_init_library call - fix -r option not working * Additional testing - source/bin/tests - tests for omnitrace-exe - tests for omnitrace-avail * cmake-format * Reduce runtime of openmp-lu * Update openmp-lu and tests timeout * openmp-lu and CI tweaks - decrease iterations - OMP_NUM_THREADS=2 - install clang and libomp-dev in linux-ci - fix data-files in linux-ci
81 líneas
2.2 KiB
C++
81 líneas
2.2 KiB
C++
|
|
#include <omnitrace/user.h>
|
|
|
|
#include <atomic>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <sstream>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
std::atomic<long> total{ 0 };
|
|
|
|
long
|
|
fib(long n) __attribute__((noinline));
|
|
|
|
void
|
|
run(size_t nitr, long) __attribute__((noinline));
|
|
|
|
long
|
|
fib(long n)
|
|
{
|
|
return (n < 2) ? n : fib(n - 1) + fib(n - 2);
|
|
}
|
|
|
|
#define RUN_LABEL \
|
|
std::string{ std::string{ __FUNCTION__ } + "(" + std::to_string(n) + ") x " + \
|
|
std::to_string(nitr) } \
|
|
.c_str()
|
|
|
|
void
|
|
run(size_t nitr, long n)
|
|
{
|
|
omnitrace_user_stop_thread_trace();
|
|
omnitrace_user_push_region(RUN_LABEL);
|
|
long local = 0;
|
|
for(size_t i = 0; i < nitr; ++i)
|
|
local += fib(n);
|
|
total += local;
|
|
omnitrace_user_pop_region(RUN_LABEL);
|
|
omnitrace_user_start_thread_trace();
|
|
}
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
omnitrace_user_push_region(argv[0]);
|
|
omnitrace_user_push_region("initialization");
|
|
size_t nthread = std::min<size_t>(16, std::thread::hardware_concurrency());
|
|
size_t nitr = 50000;
|
|
long nfib = 10;
|
|
if(argc > 1) nfib = atol(argv[1]);
|
|
if(argc > 2) nthread = atol(argv[2]);
|
|
if(argc > 3) nitr = atol(argv[3]);
|
|
omnitrace_user_pop_region("initialization");
|
|
|
|
printf("[%s] Threads: %zu\n[%s] Iterations: %zu\n[%s] fibonacci(%li)...\n", argv[0],
|
|
nthread, argv[0], nitr, argv[0], nfib);
|
|
|
|
omnitrace_user_push_region("thread_creation");
|
|
std::vector<std::thread> threads{};
|
|
threads.reserve(nthread);
|
|
for(size_t i = 0; i < nthread; ++i)
|
|
{
|
|
size_t _nitr = ((i % 2) == 1) ? (nitr - (0.1 * nitr)) : (nitr + (0.1 * nitr));
|
|
threads.emplace_back(&run, _nitr, nfib);
|
|
}
|
|
omnitrace_user_pop_region("thread_creation");
|
|
|
|
run(nitr - 0.25 * nitr, nfib - 0.1 * nfib);
|
|
|
|
omnitrace_user_push_region("thread_wait");
|
|
for(auto& itr : threads)
|
|
itr.join();
|
|
omnitrace_user_pop_region("thread_wait");
|
|
|
|
printf("[%s] fibonacci(%li) x %lu = %li\n", argv[0], nfib, nthread, total.load());
|
|
omnitrace_user_pop_region(argv[0]);
|
|
|
|
return 0;
|
|
}
|