Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #define DIM 100
  5.  
  6. typedef struct timeval tv;
  7.  
  8.  
  9. void matrixvector(int first[][DIM], int second[][1], int result[][1])
  10. {
  11. int c;
  12. int d = 0;
  13. int k;
  14. int limit = DIM - 9;
  15.  
  16. for ( c = 0 ; c < DIM ; c++ )
  17. {
  18. for ( k = 0 ; k < limit ; k += 10 )
  19. {
  20. result[c][d] += first[c][k]*second[k][d];
  21. result[c][d] += first[c][k]*second[k+1][d];
  22. result[c][d] += first[c][k]*second[k+2][d];
  23. result[c][d] += first[c][k]*second[k+3][d];
  24. result[c][d] += first[c][k]*second[k+4][d];
  25. result[c][d] += first[c][k]*second[k+5][d];
  26. result[c][d] += first[c][k]*second[k+6][d];
  27. result[c][d] += first[c][k]*second[k+7][d];
  28. result[c][d] += first[c][k]*second[k+8][d];
  29. result[c][d] += first[c][k]*second[k+9][d];
  30. result[c][d] += first[c][k]*second[k+10][d];
  31. }
  32.  
  33. for (; k < DIM; k++) {
  34. result[c][d] += first[c][k]*second[k][d];
  35. }
  36. }
  37.  
  38. }
  39. int main() {
  40. tv start, end;
  41. gettimeofday(&start, NULL);
  42.  
  43.  
  44.  
  45. int first[DIM][DIM];
  46. int second[DIM][1];
  47. int result[DIM][1];
  48. int i=0;
  49. int j=0;
  50. for (i=0;i<DIM;i++) {
  51. for (j=0;j<DIM;j++)
  52. {
  53. first[i][j]=i+j;
  54. second[i][0]=(i+1)*(j+1);
  55. result[i][0]=0;
  56. }
  57.  
  58. }
  59.  
  60. matrixvector(first,second,result);
  61.  
  62. for (i=0;i<DIM;i++)
  63. printf("%d ",result[i][0]);
  64.  
  65. gettimeofday(&end, NULL);
  66.  
  67. printf("\n%d\n", end.tv_usec - start.tv_usec);
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement