Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/time.h>
- #define DIM 100
- typedef struct timeval tv;
- void matrixvector(int first[][DIM], int second[][1], int result[][1])
- {
- int c;
- int d = 0;
- int k;
- int limit = DIM - 9;
- for ( c = 0 ; c < DIM ; c++ )
- {
- for ( k = 0 ; k < limit ; k += 10 )
- {
- result[c][d] += first[c][k]*second[k][d];
- result[c][d] += first[c][k]*second[k+1][d];
- result[c][d] += first[c][k]*second[k+2][d];
- result[c][d] += first[c][k]*second[k+3][d];
- result[c][d] += first[c][k]*second[k+4][d];
- result[c][d] += first[c][k]*second[k+5][d];
- result[c][d] += first[c][k]*second[k+6][d];
- result[c][d] += first[c][k]*second[k+7][d];
- result[c][d] += first[c][k]*second[k+8][d];
- result[c][d] += first[c][k]*second[k+9][d];
- result[c][d] += first[c][k]*second[k+10][d];
- }
- for (; k < DIM; k++) {
- result[c][d] += first[c][k]*second[k][d];
- }
- }
- }
- int main() {
- tv start, end;
- gettimeofday(&start, NULL);
- int first[DIM][DIM];
- int second[DIM][1];
- int result[DIM][1];
- int i=0;
- int j=0;
- for (i=0;i<DIM;i++) {
- for (j=0;j<DIM;j++)
- {
- first[i][j]=i+j;
- second[i][0]=(i+1)*(j+1);
- result[i][0]=0;
- }
- }
- matrixvector(first,second,result);
- for (i=0;i<DIM;i++)
- printf("%d ",result[i][0]);
- gettimeofday(&end, NULL);
- printf("\n%d\n", end.tv_usec - start.tv_usec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement