-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cilk: Add support for Cilk (with C/C++) (#3522)
- Loading branch information
Showing
14 changed files
with
255 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Prism.languages.cilkc = Prism.languages.insertBefore('c', 'function', { | ||
'parallel-keyword': { | ||
pattern: /\bcilk_(?:for|reducer|s(?:cope|pawn|ync))\b/, | ||
alias: 'keyword' | ||
} | ||
}); | ||
|
||
Prism.languages['cilk-c'] = Prism.languages['cilkc']; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Prism.languages.cilkcpp = Prism.languages.insertBefore('cpp', 'function', { | ||
'parallel-keyword': { | ||
pattern: /\bcilk_(?:for|reducer|s(?:cope|pawn|ync))\b/, | ||
alias: 'keyword' | ||
} | ||
}); | ||
|
||
Prism.languages['cilk-cpp'] = Prism.languages['cilkcpp']; | ||
Prism.languages['cilk'] = Prism.languages['cilkcpp']; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<h2>Cilk keywords</h2> | ||
<pre><code>cilk_scope {} | ||
cilk_spawn f(); | ||
cilk_spawn {} | ||
cilk_sync; | ||
cilk_for () {} | ||
int cilk_reducer() x;</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code>#include <cilk/cilk.h> | ||
|
||
int fib_cilk_scope(int n) { | ||
if (n < 2) | ||
return; | ||
int x, y; | ||
cilk_scope { | ||
x = cilk_spawn fib(n-1); | ||
y = fib(n-2); | ||
} | ||
return x + y; | ||
|
||
int fib_cilk_sync(int n) { | ||
if (n < 2) | ||
return; | ||
int x = cilk_spawn fib(n-1); | ||
int y = fib(n-2); | ||
cilk_sync; | ||
return x + y; | ||
} | ||
|
||
void zero(void *v) { | ||
*(int *)v = 0; | ||
} | ||
void plus(void *l, void *r) { | ||
*(int *)l += *(int *)r; | ||
} | ||
int array_sum_cilk_for_reducer(int *A, int n) { | ||
int cilk_reducer(zero, plus) sum = 0; | ||
cilk_for (int i = 0; i < n; ++i) | ||
sum += A[i]; | ||
return sum; | ||
}</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<h2>Cilk keywords</h2> | ||
<pre><code>cilk_scope {} | ||
cilk_spawn f(); | ||
cilk_spawn {} | ||
cilk_sync; | ||
cilk_for () {} | ||
int cilk_reducer() x;</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code>#include <cilk/cilk.h> | ||
#include <vector> | ||
|
||
int fib_cilk_scope(int n) { | ||
if (n < 2) | ||
return; | ||
int x, y; | ||
cilk_scope { | ||
x = cilk_spawn fib(n-1); | ||
y = fib(n-2); | ||
} | ||
return x + y; | ||
|
||
int fib_cilk_sync(int n) { | ||
if (n < 2) | ||
return; | ||
int x = cilk_spawn fib(n-1); | ||
int y = fib(n-2); | ||
cilk_sync; | ||
return x + y; | ||
} | ||
|
||
void zero(void *v) { | ||
*(int *)v = 0; | ||
} | ||
void plus(void *l, void *r) { | ||
*(int *)l += *(int *)r; | ||
} | ||
int array_sum_cilk_for_reducer(std::vector<int> A) { | ||
int cilk_reducer(zero, plus) sum = 0; | ||
cilk_for (auto itr = A.cbegin(); itr != A.cend(); ++itr) | ||
sum += *itr; | ||
return sum; | ||
}</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.