Skip to content

Commit

Permalink
Redesign to supply LaceWorker* in every task
Browse files Browse the repository at this point in the history
  • Loading branch information
trolando committed Mar 6, 2023
1 parent a35d64c commit ac10ed5
Show file tree
Hide file tree
Showing 19 changed files with 1,546 additions and 1,591 deletions.
76 changes: 38 additions & 38 deletions benchmarks/cholesky/cholesky-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static Matrix set_matrix(int depth, Matrix a, int r, int c, Real value)
*/
TASK_5(Matrix, mul_and_subT, int, depth, int, lower, Matrix, a, Matrix, b, Matrix, r)

Matrix mul_and_subT(int depth, int lower, Matrix a, Matrix b, Matrix r)
Matrix mul_and_subT(LaceWorker* worker, int depth, int lower, Matrix a, Matrix b, Matrix r)
{
if (depth == BLOCK_DEPTH) {
LeafNode *A = (LeafNode *) a;
Expand Down Expand Up @@ -389,46 +389,46 @@ Matrix mul_and_subT(int depth, int lower, Matrix a, Matrix b, Matrix r)
// first spawn

if (a->child[_00] && b->child[TR_00])
mul_and_subT_SPAWN(depth, lower, a->child[_00], b->child[TR_00], r00);
mul_and_subT_SPAWN(worker, depth, lower, a->child[_00], b->child[TR_00], r00);
if (!lower && a->child[_00] && b->child[TR_01])
mul_and_subT_SPAWN(depth, 0, a->child[_00], b->child[TR_01], r01);
mul_and_subT_SPAWN(worker, depth, 0, a->child[_00], b->child[TR_01], r01);
if (a->child[_10] && b->child[TR_00])
mul_and_subT_SPAWN(depth, 0, a->child[_10], b->child[TR_00], r10);
mul_and_subT_SPAWN(worker, depth, 0, a->child[_10], b->child[TR_00], r10);
if (a->child[_10] && b->child[TR_01])
mul_and_subT_SPAWN(depth, lower, a->child[_10], b->child[TR_01], r11);
mul_and_subT_SPAWN(worker, depth, lower, a->child[_10], b->child[TR_01], r11);

// then sync

if (a->child[_10] && b->child[TR_01])
r11 = mul_and_subT_SYNC();
r11 = mul_and_subT_SYNC(worker);
if (a->child[_10] && b->child[TR_00])
r10 = mul_and_subT_SYNC();
r10 = mul_and_subT_SYNC(worker);
if (!lower && a->child[_00] && b->child[TR_01])
r01 = mul_and_subT_SYNC();
r01 = mul_and_subT_SYNC(worker);
if (a->child[_00] && b->child[TR_00])
r00 = mul_and_subT_SYNC();
r00 = mul_and_subT_SYNC(worker);

// first spawn

if (a->child[_01] && b->child[TR_10])
mul_and_subT_SPAWN(depth, lower, a->child[_01], b->child[TR_10], r00);
mul_and_subT_SPAWN(worker, depth, lower, a->child[_01], b->child[TR_10], r00);
if (!lower && a->child[_01] && b->child[TR_11])
mul_and_subT_SPAWN(depth, 0, a->child[_01], b->child[TR_11], r01);
mul_and_subT_SPAWN(worker, depth, 0, a->child[_01], b->child[TR_11], r01);
if (a->child[_11] && b->child[TR_10])
mul_and_subT_SPAWN(depth, 0, a->child[_11], b->child[TR_10], r10);
mul_and_subT_SPAWN(worker, depth, 0, a->child[_11], b->child[TR_10], r10);
if (a->child[_11] && b->child[TR_11])
mul_and_subT_SPAWN(depth, lower, a->child[_11], b->child[TR_11], r11);
mul_and_subT_SPAWN(worker, depth, lower, a->child[_11], b->child[TR_11], r11);

// then sync

if (a->child[_11] && b->child[TR_11])
r11 = mul_and_subT_SYNC();
r11 = mul_and_subT_SYNC(worker);
if (a->child[_11] && b->child[TR_10])
r10 = mul_and_subT_SYNC();
r10 = mul_and_subT_SYNC(worker);
if (!lower && a->child[_01] && b->child[TR_11])
r01 = mul_and_subT_SYNC();
r01 = mul_and_subT_SYNC(worker);
if (a->child[_01] && b->child[TR_10])
r00 = mul_and_subT_SYNC();
r00 = mul_and_subT_SYNC(worker);

if (r == NULL) {
if (r00 || r01 || r10 || r11)
Expand All @@ -449,7 +449,7 @@ Matrix mul_and_subT(int depth, int lower, Matrix a, Matrix b, Matrix r)
*/
TASK_3(Matrix, backsub, int, depth, Matrix, a, Matrix, l)

Matrix backsub(int depth, Matrix a, Matrix l)
Matrix backsub(LaceWorker* worker, int depth, Matrix a, Matrix l)
{
if (depth == BLOCK_DEPTH) {
LeafNode *A = (LeafNode *) a;
Expand All @@ -470,20 +470,20 @@ Matrix backsub(int depth, Matrix a, Matrix l)
l10 = l->child[_10];
l11 = l->child[_11];

if (a00) backsub_SPAWN(depth, a00, l00);
if (a10) backsub_SPAWN(depth, a10, l00);
if (a10) a10 = backsub_SYNC();
if (a00) a00 = backsub_SYNC();
if (a00) backsub_SPAWN(worker, depth, a00, l00);
if (a10) backsub_SPAWN(worker, depth, a10, l00);
if (a10) a10 = backsub_SYNC(worker);
if (a00) a00 = backsub_SYNC(worker);

if (a00 && l10) mul_and_subT_SPAWN(depth, 0, a00, l10, a01);
if (a10 && l10) mul_and_subT_SPAWN(depth, 0, a10, l10, a11);
if (a10 && l10) a11 = mul_and_subT_SYNC();
if (a00 && l10) a01 = mul_and_subT_SYNC();
if (a00 && l10) mul_and_subT_SPAWN(worker, depth, 0, a00, l10, a01);
if (a10 && l10) mul_and_subT_SPAWN(worker, depth, 0, a10, l10, a11);
if (a10 && l10) a11 = mul_and_subT_SYNC(worker);
if (a00 && l10) a01 = mul_and_subT_SYNC(worker);

if (a01) backsub_SPAWN(depth, a01, l11);
if (a11) backsub_SPAWN(depth, a11, l11);
if (a11) a11 = backsub_SYNC();
if (a01) a01 = backsub_SYNC();
if (a01) backsub_SPAWN(worker, depth, a01, l11);
if (a11) backsub_SPAWN(worker, depth, a11, l11);
if (a11) a11 = backsub_SYNC(worker);
if (a01) a01 = backsub_SYNC(worker);

a->child[_00] = a00;
a->child[_01] = a01;
Expand All @@ -499,7 +499,7 @@ Matrix backsub(int depth, Matrix a, Matrix l)
*/
TASK_2(Matrix, cholesky, int, depth, Matrix, a)

Matrix cholesky(int depth, Matrix a)
Matrix cholesky(LaceWorker* worker, int depth, Matrix a)
{
if (depth == BLOCK_DEPTH) {
LeafNode *A = (LeafNode *) a;
Expand All @@ -514,14 +514,14 @@ Matrix cholesky(int depth, Matrix a)
a11 = a->child[_11];

if (!a10) {
cholesky_SPAWN(depth, a00);
a11 = cholesky(depth, a11);
a00 = cholesky_SYNC();
cholesky_SPAWN(worker, depth, a00);
a11 = cholesky(worker, depth, a11);
a00 = cholesky_SYNC(worker);
} else {
a00 = cholesky(depth, a00);
a10 = backsub(depth, a10, a00);
a11 = mul_and_subT(depth, 1, a10, a10, a11);
a11 = cholesky(depth, a11);
a00 = cholesky(worker, depth, a00);
a10 = backsub(worker, depth, a10, a00);
a11 = mul_and_subT(worker, depth, 1, a10, a10, a11);
a11 = cholesky(worker, depth, a11);
}
a->child[_00] = a00;
a->child[_10] = a10;
Expand Down
34 changes: 17 additions & 17 deletions benchmarks/cilksort/cilksort-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ ELM *binsplit(ELM val, ELM *low, ELM *high)

VOID_TASK_5(cilkmerge, ELM*, low1, ELM*, high1, ELM*, low2, ELM*, high2, ELM*, lowdest)

void cilkmerge(ELM* low1, ELM* high1, ELM* low2, ELM* high2, ELM* lowdest)
void cilkmerge(LaceWorker* worker, ELM* low1, ELM* high1, ELM* low2, ELM* high2, ELM* lowdest)
{
/*
* Cilkmerge: Merges range [low1, high1] with range [low2, high2]
Expand Down Expand Up @@ -352,15 +352,15 @@ void cilkmerge(ELM* low1, ELM* high1, ELM* low2, ELM* high2, ELM* lowdest)
* the appropriate location
*/
*(lowdest + lowsize + 1) = *split1;
cilkmerge_SPAWN(low1, split1 - 1, low2, split2, lowdest);
cilkmerge(split1 + 1, high1, split2 + 1, high2, lowdest + lowsize + 2);
cilkmerge_SYNC();
cilkmerge_SPAWN(worker, low1, split1 - 1, low2, split2, lowdest);
cilkmerge(worker, split1 + 1, high1, split2 + 1, high2, lowdest + lowsize + 2);
cilkmerge_SYNC(worker);
return;
}

VOID_TASK_3(cilksort, ELM*, low, ELM*, tmp, long, size)

void cilksort(ELM* low, ELM* tmp, long size)
void cilksort(LaceWorker* worker, ELM* low, ELM* tmp, long size)
{
/*
* divide the input in four parts of the same size (A, B, C, D)
Expand All @@ -386,20 +386,20 @@ void cilksort(ELM* low, ELM* tmp, long size)
D = C + quarter;
tmpD = tmpC + quarter;

cilksort_SPAWN(A, tmpA, quarter);
cilksort_SPAWN(B, tmpB, quarter);
cilksort_SPAWN(C, tmpC, quarter);
cilksort_SPAWN(D, tmpD, size - 3 * quarter);
cilksort_SYNC();
cilksort_SYNC();
cilksort_SYNC();
cilksort_SYNC();
cilksort_SPAWN(worker, A, tmpA, quarter);
cilksort_SPAWN(worker, B, tmpB, quarter);
cilksort_SPAWN(worker, C, tmpC, quarter);
cilksort_SPAWN(worker, D, tmpD, size - 3 * quarter);
cilksort_SYNC(worker);
cilksort_SYNC(worker);
cilksort_SYNC(worker);
cilksort_SYNC(worker);

cilkmerge_SPAWN(A, A + quarter - 1, B, B + quarter - 1, tmpA);
cilkmerge(C, C + quarter - 1, D, low + size - 1, tmpC);
cilkmerge_SYNC();
cilkmerge_SPAWN(worker, A, A + quarter - 1, B, B + quarter - 1, tmpA);
cilkmerge(worker, C, C + quarter - 1, D, low + size - 1, tmpC);
cilkmerge_SYNC(worker);

cilkmerge(tmpA, tmpC - 1, tmpC, tmpA + size - 1, A);
cilkmerge(worker, tmpA, tmpC - 1, tmpC, tmpA + size - 1, A);
}

void scramble_array(ELM *arr, unsigned long size)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/dfs/dfs-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ int __attribute__((noinline)) loop()

TASK_1(int, tree, int, d)

int tree(int d)
int tree(LaceWorker* worker, int d)
{
if( d>0 ) {
int i;
for (i=0;i<w;i++) tree_SPAWN(d-1);
for (i=0;i<w;i++) tree_SYNC();
for (i=0;i<w;i++) tree_SPAWN(worker, d-1);
for (i=0;i<w;i++) tree_SYNC(worker );
return 0;
} else {
return loop();
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/fib/fib-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

TASK_1(int, pfib, int, n)

int pfib(int n)
int pfib(LaceWorker *worker, int n)
{
if( n < 2 ) {
return n;
} else {
pfib_SPAWN(n-1);
int k = pfib(n-2);
int m = pfib_SYNC();
pfib_SPAWN(worker, n-1);
int k = pfib(worker, n-2);
int m = pfib_SYNC(worker);
return m+k;
}
}
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/fib/fib-lace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

TASK_1(int, pfib, int, n)

int pfib(int n)
int pfib(LaceWorker* worker, int n)
{
if( n < 2 ) {
return n;
} else {
int m,k;
pfib_SPAWN(n-1);
k = pfib(n-2);
m = pfib_SYNC();
pfib_SPAWN(worker, n-1);
k = pfib(worker, n-2);
m = pfib_SYNC(worker);
return m+k;
}
}
Expand Down
28 changes: 14 additions & 14 deletions benchmarks/heat/heat-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ VOID_TASK_5(diffuse, double**, out, double**, in, int, il, int, iu, double, t);
VOID_TASK_0(prep);
VOID_TASK_0(test);

void heat(double ** m, int il, int iu)
void heat(LaceWorker* worker, double ** m, int il, int iu)
{
if (iu - il > 1) {
int im = (il + iu) / 2;

heat_SPAWN(m, il, im);
heat(m, im, iu);
heat_SYNC();
heat_SPAWN(worker, m, il, im);
heat(worker, m, im, iu);
heat_SYNC(worker);

return;
}
Expand All @@ -81,14 +81,14 @@ void heat(double ** m, int il, int iu)
}
}

void diffuse(double ** out, double ** in, int il, int iu, double t)
void diffuse(LaceWorker* worker, double ** out, double ** in, int il, int iu, double t)
{
if (iu - il > 1) {
int im = (il + iu) / 2;

diffuse_SPAWN(out, in, il, im, t);
diffuse(out, in, im, iu, t);
diffuse_SYNC();
diffuse_SPAWN(worker, out, in, il, im, t);
diffuse(worker, out, in, im, iu, t);
diffuse_SYNC(worker);

return;
}
Expand Down Expand Up @@ -145,23 +145,23 @@ void init(int n)
}
}

void prep()
void prep(LaceWorker* worker)
{
heat(even, 0, nx);
heat(worker, even, 0, nx);
}

void test()
void test(LaceWorker* worker)
{
double t = tu;
int i;

for (i = 1; i <= nt; i += 2) {
diffuse(odd, even, 0, nx, t += dt);
diffuse(even, odd, 0, nx, t += dt);
diffuse(worker, odd, even, 0, nx, t += dt);
diffuse(worker, even, odd, 0, nx, t += dt);
}

if (nt % 2) {
diffuse(odd, even, 0, nx, t += dt);
diffuse(worker, odd, even, 0, nx, t += dt);
}
}

Expand Down
8 changes: 4 additions & 4 deletions benchmarks/integrate/integrate-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static double f(double x)
TASK_5(double, integrate, double, x1, double, y1, double, x2, double, y2, double, area)

double
integrate(double x1, double y1, double x2, double y2, double area)
integrate(LaceWorker* worker, double x1, double y1, double x2, double y2, double area)
{
double half = (x2 - x1) / 2;
double x0 = x1 + half;
Expand All @@ -30,9 +30,9 @@ integrate(double x1, double y1, double x2, double y2, double area)
return area_x1x2;
}

integrate_SPAWN(x1, y1, x0, y0, area_x1x0);
area_x0x2 = integrate(x0, y0, x2, y2, area_x0x2);
area_x1x0 = integrate_SYNC();
integrate_SPAWN(worker, x1, y1, x0, y0, area_x1x0);
area_x0x2 = integrate(worker, x0, y0, x2, y2, area_x0x2);
area_x1x0 = integrate_SYNC(worker);

return area_x1x0 + area_x0x2;
}
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/knapsack/knapsack-lace.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int read_input(const char *filename, struct item *items, int *capacity, int *n)
*/
TASK_4(int, knapsack, struct item *, e, int, c, int, n, int, v)

int knapsack(struct item *e, int c, int n, int v)
int knapsack(LaceWorker* worker, struct item *e, int c, int n, int v)
{
int with, without, best;
double ub;
Expand All @@ -89,12 +89,12 @@ int knapsack(struct item *e, int c, int n, int v)
/*
* compute the best solution without the current item in the knapsack
*/
knapsack_SPAWN(e + 1, c, n - 1, v);
knapsack_SPAWN(worker, e + 1, c, n - 1, v);

/* compute the best solution with the current item in the knapsack */
with = knapsack(e + 1, c - e->weight, n - 1, v + e->value);
with = knapsack(worker, e + 1, c - e->weight, n - 1, v + e->value);

without = knapsack_SYNC();
without = knapsack_SYNC(worker);

best = with > without ? with : without;

Expand Down

0 comments on commit ac10ed5

Please sign in to comment.