Cilk: Add support for Cilk (with C/C++) (#3522)

This commit is contained in:
Alexandros-Stavros Iliopoulos 2022-08-17 18:49:11 +00:00 committed by GitHub
parent 859f99a042
commit c8462a29fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 255 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -306,6 +306,18 @@
"title": "CIL",
"owner": "sbrl"
},
"cilkc": {
"title": "Cilk/C",
"require": "c",
"alias": "cilk-c",
"owner": "OpenCilk"
},
"cilkcpp": {
"title": "Cilk/C++",
"require": "cpp",
"alias": ["cilk-cpp", "cilk"],
"owner": "OpenCilk"
},
"clojure": {
"title": "Clojure",
"owner": "troglotit"

View File

@ -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'];

1
components/prism-cilkc.min.js vendored Normal file
View File

@ -0,0 +1 @@
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;

View File

@ -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'];

1
components/prism-cilkcpp.min.js vendored Normal file
View File

@ -0,0 +1 @@
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;

42
examples/prism-cilkc.html Normal file
View File

@ -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 &lt;cilk/cilk.h>
int fib_cilk_scope(int n) {
if (n &lt; 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 &lt; 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 &lt; n; ++i)
sum += A[i];
return sum;
}</code></pre>

View File

@ -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 &lt;cilk/cilk.h>
#include &lt;vector>
int fib_cilk_scope(int n) {
if (n &lt; 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 &lt; 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&lt;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>

View File

@ -33,6 +33,8 @@
"clike",
"cpp"
],
"cilkc": "c",
"cilkcpp": "cpp",
"coffeescript": "javascript",
"crystal": "ruby",
"css-extras": "css",
@ -195,6 +197,9 @@
"cs": "csharp",
"dotnet": "csharp",
"cfc": "cfscript",
"cilk-c": "cilkc",
"cilk-cpp": "cilkcpp",
"cilk": "cilkcpp",
"coffee": "coffeescript",
"conc": "concurnas",
"jinja2": "django",

File diff suppressed because one or more lines are too long

View File

@ -69,6 +69,11 @@
"cfscript": "CFScript",
"cfc": "CFScript",
"cil": "CIL",
"cilkc": "Cilk/C",
"cilk-c": "Cilk/C",
"cilkcpp": "Cilk/C++",
"cilk-cpp": "Cilk/C++",
"cilk": "Cilk/C++",
"cmake": "CMake",
"cobol": "COBOL",
"coffee": "CoffeeScript",

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,63 @@
cilk_for()
cilk_for ()
cilk_spawn f();
cilk_spawn {}
cilk_spawn{}
cilk_sync;
cilk_scope {}
cilk_scope{}
int cilk_reducer() x;
int cilk_reducer () x;
----------------------------------------------------
[
["parallel-keyword", "cilk_for"], ["punctuation", "("], ["punctuation", ")"],
["parallel-keyword", "cilk_for"], ["punctuation", "("], ["punctuation", ")"],
["parallel-keyword", "cilk_spawn"],
["function", "f"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["parallel-keyword", "cilk_spawn"],
["punctuation", "{"],
["punctuation", "}"],
["parallel-keyword", "cilk_spawn"],
["punctuation", "{"],
["punctuation", "}"],
["parallel-keyword", "cilk_sync"], ["punctuation", ";"],
["parallel-keyword", "cilk_scope"],
["punctuation", "{"],
["punctuation", "}"],
["parallel-keyword", "cilk_scope"],
["punctuation", "{"],
["punctuation", "}"],
["keyword", "int"],
["parallel-keyword", "cilk_reducer"],
["punctuation", "("],
["punctuation", ")"],
" x",
["punctuation", ";"],
["keyword", "int"],
["parallel-keyword", "cilk_reducer"],
["punctuation", "("],
["punctuation", ")"],
" x",
["punctuation", ";"]
]
----------------------------------------------------
Check Cilk keywords.

View File

@ -0,0 +1,63 @@
cilk_for()
cilk_for ()
cilk_spawn f();
cilk_spawn {}
cilk_spawn{}
cilk_sync;
cilk_scope {}
cilk_scope{}
int cilk_reducer() x;
int cilk_reducer () x;
----------------------------------------------------
[
["parallel-keyword", "cilk_for"], ["punctuation", "("], ["punctuation", ")"],
["parallel-keyword", "cilk_for"], ["punctuation", "("], ["punctuation", ")"],
["parallel-keyword", "cilk_spawn"],
["function", "f"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["parallel-keyword", "cilk_spawn"],
["punctuation", "{"],
["punctuation", "}"],
["parallel-keyword", "cilk_spawn"],
["punctuation", "{"],
["punctuation", "}"],
["parallel-keyword", "cilk_sync"], ["punctuation", ";"],
["parallel-keyword", "cilk_scope"],
["punctuation", "{"],
["punctuation", "}"],
["parallel-keyword", "cilk_scope"],
["punctuation", "{"],
["punctuation", "}"],
["keyword", "int"],
["parallel-keyword", "cilk_reducer"],
["punctuation", "("],
["punctuation", ")"],
" x",
["punctuation", ";"],
["keyword", "int"],
["parallel-keyword", "cilk_reducer"],
["punctuation", "("],
["punctuation", ")"],
" x",
["punctuation", ";"]
]
----------------------------------------------------
Check Cilk keywords.