Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void mm(double* a, double* b, double* c, int width){
  5. for (int i = 0; i < width; i++) {
  6. for (int j = 0; j < width; j++) {
  7. double sum = 0;for (int k = 0; k < width; k++) {
  8. double x = a[i * width + k];
  9. double y = b[k * width + j];
  10. sum += x * y;
  11. }
  12. c[i * width + j] = sum;
  13. }
  14. }
  15. }
  16.  
  17. int main(){
  18. int width = 2000;
  19. double *a = (double*) malloc (width * width * sizeof(double));
  20. double *b = (double*) malloc (width * width * sizeof(double));
  21. double *c = (double*) malloc (width * width * sizeof(double));
  22. for(int i = 0; i < width; i++) {
  23. for(int j = 0; j < width; j++) {
  24. a[i*width+j] = i;
  25. b[i*width+j] = j;
  26. c[i*width+j] = 0;
  27. }
  28. }
  29.  
  30. mm(a,b,c,width);
  31. // for(int i = 0; i < width; i++) {
  32. // for(int j = 0; j < width; j++) {
  33. // printf("\n c[%d][%d] = %f",i,j,c[i*width+j]);
  34. // }
  35. // }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement