File: prism-cilkc.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (42 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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>