Skip to content

Commit

Permalink
vendor some interesting less known frameworks + cilk/staccato benches
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Dec 1, 2019
1 parent 2496bb7 commit 042783a
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
[submodule "benchmarks/vendor/bots"]
path = benchmarks/vendor/bots
url = https://github.com/bsc-pm/bots
[submodule "benchmarks/vendor/staccato"]
path = benchmarks/vendor/staccato
url = https://github.com/rkuchumov/staccato
[submodule "benchmarks/vendor/uts-benchmark-code"]
path = benchmarks/vendor/uts-benchmark-code
url = https://git.code.sf.net/p/uts-benchmark/code
[submodule "benchmarks/vendor/fibril"]
path = benchmarks/vendor/fibril
url = https://github.com/chaoran/fibril
[submodule "benchmarks/vendor/tasking-2.0"]
path = benchmarks/vendor/tasking-2.0
url = https://github.com/aprell/tasking-2.0
73 changes: 73 additions & 0 deletions benchmarks/fibonacci/cilk_fib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <iostream>
#include <chrono>
#include <thread>

#include <cilk/cilk.h>
#include <cilk/cilk_api.h>

using namespace std;
using namespace std::chrono;

void fib(int n, unsigned long *sum)
{
if (n < 2) {
*sum = 1;
return;
}

unsigned long x;
cilk_spawn fib(n - 1, &x);

unsigned long y;
fib(n - 2, &y);

cilk_sync;

*sum = x + y;
}

void test(int n, unsigned long *sum)
{
cilk_spawn fib(n, sum);
cilk_sync;
}

int main(int argc, char *argv[])
{
size_t n = 40;
unsigned long answer;
const char *nthreads = nullptr;

if (argc >= 2)
nthreads = argv[1];
if (argc >= 3)
n = atoi(argv[2]);
if (nthreads == nullptr)
nthreads = to_string(thread::hardware_concurrency()).c_str();

__cilkrts_end_cilk();

auto start = system_clock::now();

if (__cilkrts_set_param("nworkers", nthreads) != 0) {
cerr << "Failed to set worker count\n";
exit(EXIT_FAILURE);
}

__cilkrts_init();

test(n, &answer);

__cilkrts_end_cilk();

auto stop = system_clock::now();

cout << "Scheduler: cilk\n";
cout << "Benchmark: fib\n";
cout << "Threads: " << nthreads << "\n";
cout << "Time(us): " << duration_cast<microseconds>(stop - start).count() << "\n";
cout << "Input: " << n << "\n";
cout << "Output: " << answer << "\n";

return 0;
}
73 changes: 73 additions & 0 deletions benchmarks/fibonacci/staccato_fib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <iostream>
#include <chrono>
#include <thread>

#include <staccato/include/task.hpp>
#include <staccato/include/scheduler.hpp>

using namespace std;
using namespace chrono;
using namespace staccato;

class FibTask: public task<FibTask>
{
public:
FibTask (int n_, unsigned long *sum_): n(n_), sum(sum_)
{ }

void execute() {
if (n < 2) {
*sum = 1;
return;
}

unsigned long x;
spawn(new(child()) FibTask(n - 1, &x));

unsigned long y;
spawn(new(child()) FibTask(n - 2, &y));

wait();

*sum = x + y;

return;
}

private:
int n;
unsigned long *sum;
};

int main(int argc, char *argv[])
{
size_t n = 40;
unsigned long answer;
size_t nthreads = 0;

if (argc >= 2)
nthreads = atoi(argv[1]);
if (argc >= 3)
n = atoi(argv[2]);
if (nthreads == 0)
nthreads = thread::hardware_concurrency();

auto start = system_clock::now();

{
scheduler<FibTask> sh(2, nthreads);
sh.spawn(new(sh.root()) FibTask(n, &answer));
sh.wait();
}

auto stop = system_clock::now();

cout << "Scheduler: staccato\n";
cout << "Benchmark: fib\n";
cout << "Threads: " << nthreads << "\n";
cout << "Time(us): " << duration_cast<microseconds>(stop - start).count() << "\n";
cout << "Input: " << n << "\n";
cout << "Output: " << answer << "\n";

return 0;
}
2 changes: 1 addition & 1 deletion benchmarks/nqueens/weave_nqueens.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ proc nqueens_par(n, j: int32, a: CharArray): int32 =
localCounts[i] = spawn nqueens_par(n, j+1, b)

for i in 0 ..< n:
if localCounts[i].isAllocated:
if localCounts[i].isSpawned():
result += sync(localCounts[i])

const solutions = [
Expand Down
1 change: 1 addition & 0 deletions benchmarks/vendor/fibril
Submodule fibril added at 9991aa
1 change: 1 addition & 0 deletions benchmarks/vendor/staccato
Submodule staccato added at 4e22cb
1 change: 1 addition & 0 deletions benchmarks/vendor/tasking-2.0
Submodule tasking-2.0 added at 303ce3
1 change: 1 addition & 0 deletions benchmarks/vendor/uts-benchmark-code
Submodule uts-benchmark-code added at 722e89
6 changes: 3 additions & 3 deletions weave/datatypes/flowvars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type
else:
chan: ptr ChannelSpscSingleObject[T]

func isAllocated*(fv: Flowvar): bool {.inline.}=
## Returns true if a future is allocated
func isSpawned*(fv: Flowvar): bool {.inline.}=
## Returns true if a future is spawned
## This may be useful for recursive algorithms that
## may or may not return a future.
## may or may not spawn a future depending on a condition.
## This is similar to Option or Maybe types
when defined(WV_LazyFlowvar):
return not fv.lfv.isNil
Expand Down

0 comments on commit 042783a

Please sign in to comment.