-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fmk - updating day 4 and 5 assingments
- Loading branch information
Showing
7 changed files
with
166 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
extern void myDGEMM(int n, double *A, double *B, double *C); | ||
extern void blasDGEMM(int n, double* A, double* B, double* C); | ||
|
||
void fill(double* p, int n) { | ||
for (int i = 0; i < n; ++i) | ||
p[i] = (double)rand() / (double)RAND_MAX ; | ||
} | ||
|
||
/* The benchmarking program */ | ||
int main(int argc, char** argv) { | ||
|
||
if (argc != 2) { | ||
printf("Correct usage: app matrixDimension?\n"); | ||
exit(0); | ||
} | ||
|
||
// get matrix size | ||
int n = atoi(argv[1]); | ||
n = fabs(n); | ||
if (n == 0) | ||
n = 10; | ||
|
||
int result = 0; | ||
|
||
double *A = 0; // << SOME CODE HERE | ||
double *B = 0; // << SOME CODE HERE | ||
double *C = 0; // << SOME CODE HERE | ||
double *C1 = 0; // << SOME CODE HERE | ||
|
||
if (A == 0 || B == 0 || C == 0 || C1 == 0) { | ||
printf("NO MMEORY ALLOCATED FOR ARRAYS\n"); | ||
exit(0); | ||
} | ||
|
||
fill(A, n * n); | ||
fill(B, n * n); | ||
fill(C, n * n); | ||
|
||
for (int i=0; i<n*n; i++) | ||
C1[i]=C[i]; | ||
|
||
blasDGEMM(n, A, B, C); | ||
|
||
myDGEMM(n, A, B, C1); | ||
|
||
// check they are the same .. take into account there will be differences due to roundoff | ||
for (int j=0; j<n*n; j++) { | ||
double diff = C1[j] - C[j]; | ||
double error = fabs(diff/C[j]); | ||
if (error > 1e-10) { | ||
result = 1; | ||
} | ||
} | ||
|
||
// GOOD PRACTICE TO PUT 4 LINES of CODE HERE | ||
|
||
|
||
printf("%d\n", result); | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const char* dgemm_desc = "Naive, three-loop dgemm."; | ||
|
||
/* | ||
* This routine performs a dgemm operation | ||
* C := C + A * B | ||
* where A, B, and C are lda-by-lda matrices stored in column-major format. | ||
* On exit, A and B maintain their input values. | ||
* | ||
* NOTE: Fortran storage: C(i,j) = C[i + j*n] | ||
*/ | ||
void myDGEMM(int n, double* A, double* B, double* C) { | ||
return; | ||
} |