Skip to content

Commit c8462a2

Browse files
authored
Cilk: Add support for Cilk (with C/C++) (#3522)
1 parent 859f99a commit c8462a2

14 files changed

+255
-3
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+12
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@
306306
"title": "CIL",
307307
"owner": "sbrl"
308308
},
309+
"cilkc": {
310+
"title": "Cilk/C",
311+
"require": "c",
312+
"alias": "cilk-c",
313+
"owner": "OpenCilk"
314+
},
315+
"cilkcpp": {
316+
"title": "Cilk/C++",
317+
"require": "cpp",
318+
"alias": ["cilk-cpp", "cilk"],
319+
"owner": "OpenCilk"
320+
},
309321
"clojure": {
310322
"title": "Clojure",
311323
"owner": "troglotit"

components/prism-cilkc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Prism.languages.cilkc = Prism.languages.insertBefore('c', 'function', {
2+
'parallel-keyword': {
3+
pattern: /\bcilk_(?:for|reducer|s(?:cope|pawn|ync))\b/,
4+
alias: 'keyword'
5+
}
6+
});
7+
8+
Prism.languages['cilk-c'] = Prism.languages['cilkc'];

components/prism-cilkc.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-cilkcpp.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Prism.languages.cilkcpp = Prism.languages.insertBefore('cpp', 'function', {
2+
'parallel-keyword': {
3+
pattern: /\bcilk_(?:for|reducer|s(?:cope|pawn|ync))\b/,
4+
alias: 'keyword'
5+
}
6+
});
7+
8+
Prism.languages['cilk-cpp'] = Prism.languages['cilkcpp'];
9+
Prism.languages['cilk'] = Prism.languages['cilkcpp'];

components/prism-cilkcpp.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-cilkc.html

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h2>Cilk keywords</h2>
2+
<pre><code>cilk_scope {}
3+
cilk_spawn f();
4+
cilk_spawn {}
5+
cilk_sync;
6+
cilk_for () {}
7+
int cilk_reducer() x;</code></pre>
8+
9+
<h2>Full example</h2>
10+
<pre><code>#include &lt;cilk/cilk.h>
11+
12+
int fib_cilk_scope(int n) {
13+
if (n &lt; 2)
14+
return;
15+
int x, y;
16+
cilk_scope {
17+
x = cilk_spawn fib(n-1);
18+
y = fib(n-2);
19+
}
20+
return x + y;
21+
22+
int fib_cilk_sync(int n) {
23+
if (n &lt; 2)
24+
return;
25+
int x = cilk_spawn fib(n-1);
26+
int y = fib(n-2);
27+
cilk_sync;
28+
return x + y;
29+
}
30+
31+
void zero(void *v) {
32+
*(int *)v = 0;
33+
}
34+
void plus(void *l, void *r) {
35+
*(int *)l += *(int *)r;
36+
}
37+
int array_sum_cilk_for_reducer(int *A, int n) {
38+
int cilk_reducer(zero, plus) sum = 0;
39+
cilk_for (int i = 0; i &lt; n; ++i)
40+
sum += A[i];
41+
return sum;
42+
}</code></pre>

examples/prism-cilkcpp.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<h2>Cilk keywords</h2>
2+
<pre><code>cilk_scope {}
3+
cilk_spawn f();
4+
cilk_spawn {}
5+
cilk_sync;
6+
cilk_for () {}
7+
int cilk_reducer() x;</code></pre>
8+
9+
<h2>Full example</h2>
10+
<pre><code>#include &lt;cilk/cilk.h>
11+
#include &lt;vector>
12+
13+
int fib_cilk_scope(int n) {
14+
if (n &lt; 2)
15+
return;
16+
int x, y;
17+
cilk_scope {
18+
x = cilk_spawn fib(n-1);
19+
y = fib(n-2);
20+
}
21+
return x + y;
22+
23+
int fib_cilk_sync(int n) {
24+
if (n &lt; 2)
25+
return;
26+
int x = cilk_spawn fib(n-1);
27+
int y = fib(n-2);
28+
cilk_sync;
29+
return x + y;
30+
}
31+
32+
void zero(void *v) {
33+
*(int *)v = 0;
34+
}
35+
void plus(void *l, void *r) {
36+
*(int *)l += *(int *)r;
37+
}
38+
int array_sum_cilk_for_reducer(std::vector&lt;int> A) {
39+
int cilk_reducer(zero, plus) sum = 0;
40+
cilk_for (auto itr = A.cbegin(); itr != A.cend(); ++itr)
41+
sum += *itr;
42+
return sum;
43+
}</code></pre>

plugins/autoloader/prism-autoloader.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"clike",
3434
"cpp"
3535
],
36+
"cilkc": "c",
37+
"cilkcpp": "cpp",
3638
"coffeescript": "javascript",
3739
"crystal": "ruby",
3840
"css-extras": "css",
@@ -195,6 +197,9 @@
195197
"cs": "csharp",
196198
"dotnet": "csharp",
197199
"cfc": "cfscript",
200+
"cilk-c": "cilkc",
201+
"cilk-cpp": "cilkcpp",
202+
"cilk": "cilkcpp",
198203
"coffee": "coffeescript",
199204
"conc": "concurnas",
200205
"jinja2": "django",

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
"cfscript": "CFScript",
7070
"cfc": "CFScript",
7171
"cil": "CIL",
72+
"cilkc": "Cilk/C",
73+
"cilk-c": "Cilk/C",
74+
"cilkcpp": "Cilk/C++",
75+
"cilk-cpp": "Cilk/C++",
76+
"cilk": "Cilk/C++",
7277
"cmake": "CMake",
7378
"cobol": "COBOL",
7479
"coffee": "CoffeeScript",

0 commit comments

Comments
 (0)