Created
November 20, 2011 10:52
-
-
Save anonymous/1380140 to your computer and use it in GitHub Desktop.
Intel Cilk Plus -- Example #2 (multiplication table 16x16)
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
#include <stdio.h> | |
#include <cstdlib> | |
#include <cilk/cilk.h> | |
#include <iostream> | |
/* ex: set tabstop=8 softtabstop=4 expandtab: */ | |
int main(int argc, char* argv[]) | |
{ | |
int N = 16; | |
int M = 16; | |
int * arr = (int *) _mm_malloc(N * M * sizeof(int), 64); | |
cilk_for(int j = 0; j < N; j++) { | |
arr[j] = j + 1; | |
} | |
cilk_for(int i = 1; i < M; i++) { | |
int * a = &(arr[i * N]); | |
a[0:N] = arr[0:N] * (i + 1); | |
} | |
int (* a)[N] = (int (*)[N]) arr; | |
for(int i = 0; i < M; i++) { | |
for(int j = 0; j < N; j++) { | |
printf("%4d ", a[i][j]); | |
} | |
std::cout << std::endl; | |
} | |
_mm_free(a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment