Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2011 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1380145 to your computer and use it in GitHub Desktop.
Save anonymous/1380145 to your computer and use it in GitHub Desktop.
Intel Cilk Plus -- Example #4 (bug with array segment notation)
#include <stdio.h>
#include <cstdlib>
#include <cilk/cilk.h>
#include <iostream>
/* ex: set tabstop=8 softtabstop=4 expandtab: */
int main(int argc, char* argv[])
{
#define N 16
#define M 16
int a[M][N];
cilk_for(int j = 0; j < N; j++) {
a[0][j] = j + 1;
}
cilk_for(int i = 1; i < M; i++) {
a[i][:] = a[0][:];
}
int chunks = 2;
int chunk = N/chunks; // make sure N % chunks == 0
cilk_for(int k = 0; k < chunks; k++) {
int start = k * chunk;
int end = (k + 1) * chunk;
for(int i = 1; i < M; i++) {
// this brings wrong results:
// a[i][start:end] += a[i - 1][start:end];
// although, this works properly:
for(int j = start; j < end; j++) {
a[i][j] += a[i - 1][j];
}
}
}
for(int i = 0; i < M; i++) {
for(int j = 0; j < N; j++) {
printf("%4d ", a[i][j]);
}
std::cout << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment