Last active
February 26, 2021 16:24
-
-
Save IonianIronist/5d3316c25c890d4e736d48c8fc4e530d to your computer and use it in GitHub Desktop.
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 <stdlib.h> | |
#include <sys/timeb.h> | |
#define N 1000 | |
#define R 10 | |
int main() { | |
double *a, *b; | |
int i,j; | |
double mflop; | |
struct timeb ts, te; | |
a = (double *)malloc(N*N*sizeof(double)*2); | |
if (a==NULL) { exit(1); } | |
//b = (double *)malloc(N*N*sizeof(double)); | |
//if (b == NULL){free(a); exit(1);} | |
b = &a[N*N]; | |
ftime(&ts); | |
for (i=0;i<N*N;i++) { | |
a[i] = i % 100; | |
b[i] = -2*i%112; | |
} | |
//i*N + j | |
//i + j*Ν | |
for (i=0;i<N;i++) { | |
for (j=0;j<N;j++) { | |
b[i*N + j] = a[j*N + i]; | |
} | |
} | |
ftime(&te); | |
for (i=0;i<N;i++) { | |
for (j = 0; j<0; j++){ | |
if (a[j*N+i] != b[i*N+j] ) { | |
printf("error\n"); | |
break; | |
} | |
} | |
} | |
free(a); | |
//free(b); | |
int diff = (int) (1000.0 * (te.time - ts.time) | |
+ (te.millitm - ts.millitm)); | |
printf("For N = %d and R = %d\n", N, R); | |
printf("Exec Time (sec) = %f\n", (float)diff/1000); | |
printf("Mflops : %f", (2.0*R*N)/(((float)diff/1000)*1e6)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
matrix transpose example