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

Adds small example to test recursive function calls #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/fpcsc/perf_util/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ inline void sleep_for_secs(unsigned Secs) {
std::this_thread::sleep_for(std::chrono::seconds(Secs));
}

inline void sleep_for_millisecs(unsigned Millisecs) {
std::cout << "Sleeping for " << Millisecs << " milliseconds" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(Millisecs));
}

inline void sleep_for_nanosecs(unsigned millisecs) {
std::this_thread::sleep_for(std::chrono::nanoseconds(millisecs));
}
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ add_subdirectory(MultiSharedMultipleRegions)
add_subdirectory(SimpleFeatureInteraction)
add_subdirectory(SimpleSleepLoop)
add_subdirectory(SimpleBusyLoop)
add_subdirectory(PerfDetectiveExample)
add_subdirectory(SingleRecursiveFeature)
12 changes: 12 additions & 0 deletions src/PerfDetectiveExample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_test_binary("PerfDetectiveExample")

add_executable(
PerfDetectiveExample

PDEmain.cpp
)

set_target_properties(MultiSharedMultipleRegions PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
46 changes: 46 additions & 0 deletions src/PerfDetectiveExample/PDEmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "fpcsc/perf_util/sleep.h"

#include <cstdlib>

static int x2 = 0;

int preCalculate(int z) {
if (x2 < 10) return 0;
return 1;
}

void bar(int z) {
for (int i = 0; i < z; i++) {
fpcsc::sleep_for_millisecs(200);
}
}

void baz(int z) {
int flag = preCalculate(z);
for (int i = flag; i < z; i++) {
fpcsc::sleep_for_millisecs(300);
}
}

void foo(int y, int z, int iters) {
for (int i = 0; i < iters; i++) {
for (int j = 0; j < y; j++) {
fpcsc::sleep_for_millisecs(100);
}
}
bar(z);
baz(z);
}

int main(int argc, char *argv[]) {
int x1 __attribute__((feature_variable("x1"))) = std::atoi(argv[1]);
int x2 __attribute__((feature_variable("x2"))) = std::atoi(argv[2]);
int iters __attribute__((feature_variable("iters"))) = std::atoi(argv[3]);

int y = x1 * 3;
int z = x2 / 7;

foo(y, z, iters);

return 0;
}
7 changes: 7 additions & 0 deletions src/SingleRecursiveFeature/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_test_binary("SingleRecursiveFeature")

add_executable(
SingleRecursiveFeature

SRFmain.cpp
)
20 changes: 20 additions & 0 deletions src/SingleRecursiveFeature/SRFmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "fpcsc/perf_util/sleep.h"
#include "fpcsc/perf_util/feature_cmd.h"

#include <string>


int recursiveFunction(long Recurse) {
if (Recurse > 0) {
fpcsc::sleep_for_millisecs(100);
return recursiveFunction(Recurse - 1) + 2;
}

return 0;
}

int main(int argc, char *argv[] ) {
long NumRecursiveCalls = fpcsc::getFeatureValue(argc, argv, "--recurse");

return recursiveFunction(NumRecursiveCalls);
}