Skip to content

Commit

Permalink
Fixing examples that use scoped timers.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Mar 24, 2018
1 parent 25ba1d9 commit 2e48b47
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions bootstrap-configs/bootstrap-macbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ unset TAU_ROOT
# other CMake variables - for special situations / architectures / compilers.

cmake_build_type="-DCMAKE_BUILD_TYPE=Debug -DAPEX_DEBUG=TRUE -DBUILD_TESTS=TRUE -DBUILD_EXAMPLES=TRUE" # Debug, Release, RelWithDebInfo, etc.
#cmake_build_type="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DAPEX_DEBUG=FALSE -DBUILD_TESTS=TRUE -DBUILD_EXAMPLES=TRUE" # Debug, Release, RelWithDebInfo, etc.
cmake_apex_throttle="-DAPEX_THROTTLE=FALSE" # TRUE or FALSE
cmake_build_shared_libs="-DBUILD_SHARED_LIBS=TRUE" # TRUE or FALSE
cmake_install_prefix="-DCMAKE_INSTALL_PREFIX=../install" # the installation path
Expand All @@ -28,6 +29,7 @@ cmake_install_prefix="-DCMAKE_INSTALL_PREFIX=../install" # the installation path
cmake_make_verbose="" # for verbose, use -DCMAKE_VERBOSE_MAKEFILE=ON
cmake_use_mpi="-DUSE_MPI=FALSE" # TRUE or FALSE
cmake_other_settings="-DMPI_C_COMPILER=mpicc -DMPI_CXX_COMPILER=mpicxx -DOTF2_ROOT=$HOME/install/otf2/2.0" # anything else?
#cmake_other_settings="-DMPI_C_COMPILER=mpicc -DMPI_CXX_COMPILER=mpicxx" # anything else?

# runtime parameters for testing APEX with "make test"

Expand Down
5 changes: 3 additions & 2 deletions src/examples/CountCalls/count_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ uint64_t do_work(uint64_t work) {
void* someThread(void* tmp)
{
UNUSED(tmp);
apex::self_stopping_timer proxy((apex_function_address)someThread, "threadTest thread");
apex::scoped_thread ast("threadTest thread");
apex::scoped_timer proxy((apex_function_address)someThread);
#if defined (__APPLE__)
printf("The ID of this thread is: %lu\n", (unsigned long)pthread_self());
#else
Expand All @@ -57,7 +58,7 @@ void* someThread(void* tmp)
int main(int argc, char **argv)
{
apex::init(argv[0], 0, 1);
apex::self_stopping_timer proxy((apex_function_address)main);
apex::scoped_timer proxy((apex_function_address)main);
printf("PID of this process: %d\n", getpid());
pthread_t thread[NUM_THREADS];
int i;
Expand Down
5 changes: 3 additions & 2 deletions src/examples/TestGetPower/getpower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
void* someThread(void* tmp)
{
UNUSED(tmp);
apex::self_stopping_timer proxy((apex_function_address)someThread, "threadTest thread");
apex::scoped_thread ast("threadTest thread");
apex::scoped_timer proxy((apex_function_address)someThread);
printf("PID of this process: %d\n", getpid());
#if defined (__APPLE__)
printf("The ID of this thread is: %lu\n", (unsigned long)pthread_self());
Expand All @@ -26,7 +27,7 @@ void* someThread(void* tmp)
int main(int argc, char **argv)
{
apex::init(argv[0], 0, 1);
apex::self_stopping_timer proxy((apex_function_address)main);
apex::scoped_timer proxy((apex_function_address)main);
double currentpower = apex::current_power_high();
printf("Power at start: %f Watts\n", currentpower);
printf("PID of this process: %d\n", getpid());
Expand Down
5 changes: 3 additions & 2 deletions src/examples/TestThreads/testThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
void* someThread(void* tmp)
{
UNUSED(tmp);
apex::self_stopping_timer proxy((apex_function_address)someThread, "threadTest thread");
apex::scoped_thread ast("threadTest thread");
apex::scoped_timer proxy((apex_function_address)someThread);
printf("PID of this process: %d\n", getpid());
#if defined (__APPLE__)
printf("The ID of this thread is: %lu\n", (unsigned long)pthread_self());
Expand All @@ -26,7 +27,7 @@ void* someThread(void* tmp)
int main(int argc, char **argv)
{
apex::init(argv[0], 0, 1);
apex::self_stopping_timer proxy((apex_function_address)main);
apex::scoped_timer proxy((apex_function_address)main);
printf("PID of this process: %d\n", getpid());
pthread_t thread[NUM_THREADS];
int i;
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/C++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ set(example_programs
apex_hpx_direct_actions
apex_hpx_task_wrapper_direct_actions
apex_profiler_guids
apex_fibonacci_std_async
)
#apex_fibonacci_std_async
#apex_set_thread_cap
#apex_setup_power_cap_throttling
#apex_setup_custom_tuning
Expand Down
5 changes: 3 additions & 2 deletions src/unit_tests/C++/apex_current_power_high.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
void* someThread(void* tmp)
{
UNUSED(tmp);
apex::self_stopping_timer proxy((uint64_t)&someThread, "threadTest thread");
apex::scoped_thread ast("threadTest thread");
apex::scoped_timer proxy((uint64_t)&someThread);
printf("PID of this process: %d\n", getpid());
#if defined (__APPLE__)
printf("The ID of this thread is: %lu\n", (unsigned long)pthread_self());
Expand All @@ -26,7 +27,7 @@ void* someThread(void* tmp)
int main(int argc, char **argv)
{
apex::init(NULL, 0, 1);
apex::self_stopping_timer proxy((apex_function_address)main);
apex::scoped_timer proxy((apex_function_address)main);
double currentpower = apex::current_power_high();
printf("Power at start: %f Watts\n", currentpower);
printf("PID of this process: %d\n", getpid());
Expand Down
16 changes: 10 additions & 6 deletions src/unit_tests/C++/apex_fibonacci_std_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
#define FIB_RESULTS_PRE 41
int fib_results[FIB_RESULTS_PRE] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155};

int fib (int in) {
apex::self_stopping_timer foo((void*)&fib, "fib thread");
int fib (int in, apex::task_wrapper * parent) {
apex::scoped_thread st("fib thread");
apex::scoped_timer ast((uint64_t)&fib, parent);
if (in == 0) {
return 0;
}
else if (in == 1) {
return 1;
}
int a = in-1;
auto future_a = std::async(std::launch::async, fib, a);
auto future_a = std::async(std::launch::async, fib, a, ast.get_task_wrapper());

int b = in-2;
auto future_b = std::async(std::launch::async, fib, b);
auto future_b = std::async(std::launch::async, fib, b, ast.get_task_wrapper());

//apex::yield(twp);
int result_a = future_a.get();
int result_b = future_b.get();
return (result_a + result_b);
//apex::start(twp);
int result = result_a + result_b;
return result;
}

int main(int argc, char *argv[]) {
Expand All @@ -46,7 +50,7 @@ int main(int argc, char *argv[]) {
return -1;
}

auto future = std::async(fib, i);
auto future = std::async(fib, i, nullptr);
int result = future.get();
std::cout << "fib of " << i << " is " << result << " (valid value: " << fib_results[i] << ")" << std::endl;
apex::finalize();
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/C++/apex_hpx_direct_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void* someThread(void* tmp)
/* Register this thread with APEX */
int* tid = (int*)tmp;
char name[32];
sprintf(name, "worker thread %d", *tid);
sprintf(name, "worker-thread %d", *tid);
#ifndef __APPLE__
#ifndef APEX_HAVE_OTF2
pthread_barrier_wait(&barrier);
Expand Down
5 changes: 3 additions & 2 deletions src/unit_tests/C++/apex_new_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ int fib_results[FIB_RESULTS_PRE] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610
std::atomic<uint64_t> task_id(-1);

int fib (int in) {
apex::self_stopping_timer foo((uint64_t)&fib, "fib thread");
apex::scoped_thread ast("fib thread");
apex::scoped_timer foo((uint64_t)&fib);
if (in == 0) {
return 0;
}
Expand All @@ -35,7 +36,7 @@ int fib (int in) {

int main(int argc, char *argv[]) {
apex::init("apex_new_task_cpp unit test", 0, 1);
apex::self_stopping_timer foo((uint64_t)&main);
apex::scoped_timer foo((uint64_t)&main);
#if defined(APEX_HAVE_TAU) || (APEX_HAVE_OTF2)
int i = 5;
#else
Expand Down
7 changes: 3 additions & 4 deletions src/unit_tests/C++/apex_pthread_flood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ typedef void*(*start_routine_t)(void*);

void* someThread(void* tmp)
{
apex::scoped_thread("threadTest thread");
unsigned long * result = (unsigned long *)tmp;
apex::register_thread("threadTest thread");
int i = 0;
unsigned long total = 0;
{ // only time this for loop
apex::self_stopping_timer proxy((apex_function_address)someThread);
apex::scoped_timer proxy((apex_function_address)someThread);
for (i = 0 ; i < ITERATIONS ; i++) {
apex::profiler * p = apex::start((apex_function_address)foo);
total += foo(i);
apex::stop(p);
}
}
apex::exit_thread();
*result = total;
return NULL;
}
Expand All @@ -63,7 +62,7 @@ int main(int argc, char **argv)
apex::apex_options::use_screen_output(true);
sleep(1); // if we don't sleep, the proc_read thread won't have time to read anything.

apex::self_stopping_timer proxy((apex_function_address)main);
apex::scoped_timer proxy((apex_function_address)main);
printf("PID of this process: %d\n", getpid());
std::cout << "Expecting " << numthreads << " threads." << std::endl;
pthread_t * thread = (pthread_t*)(malloc(sizeof(pthread_t) * numthreads));
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/C++/apex_task_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int fib (int in, apex::task_wrapper * tt) {

int main(int argc, char *argv[]) {
apex::init("apex_new_task_cpp unit test", 0, 1);
apex::self_stopping_timer foo((uint64_t)&main);
apex::scoped_timer foo((uint64_t)&main);
#if defined(APEX_HAVE_TAU) || (APEX_HAVE_OTF2)
int i = 5;
#else
Expand Down

0 comments on commit 2e48b47

Please sign in to comment.