Skip to content

Instantly share code, notes, and snippets.

@vasilukwolf
Created December 6, 2021 17:17
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 vasilukwolf/d2812e0de748d9da42c7210cc623f80e to your computer and use it in GitHub Desktop.
Save vasilukwolf/d2812e0de748d9da42c7210cc623f80e to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <cilk/cilk.h>
#define n 4096
int s = 4;
double A[n][n];
double B[n][n];
double C[n][n];
float tdiff(struct timeval*start, struct timeval*end){
return (end->tv_sec-start->tv_sec)
+1e-6*(end->tv_usec-start->tv_usec);
}
int main(int argc, const char *argv[]){
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
A[i][j] = (double)rand() / (double)RAND_MAX;
B[i][j] = (double)rand() / (double)RAND_MAX;
C[i][j] = 0;
}
}
struct timeval start, end;
gettimeofday(&start, NULL);
cilk_for(int ih=0; ih<n; ih +=s){
cilk_for(int jh=0; jh<n; jh +=s){
for(int kh=0; kh<n; kh +=s){
for(int il=0; il<s; ++il){
for(int kl=0; kl<s; ++kl){
for(int jl=0; jl<s; ++jl){
C[ih+il][jh+jl] += A[ih+il][kh+kl] + B[kh+kl][jh+jl];
}
}
}
}
}
}
gettimeofday(&end, NULL);
printf ("%0.6f\n", tdiff(&start, &end));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment