Last change
on this file since 137 was
134,
checked in by kane, 14 years ago
|
add multi write buffer in cc_xcache_v4
|
File size:
1.2 KB
|
Line | |
---|
1 | #include "matrix_multiplication.h" |
---|
2 | #include "stdio.h" |
---|
3 | #include "system.h" |
---|
4 | |
---|
5 | void matrix_multiplication_st (int ** a, |
---|
6 | int ** b, |
---|
7 | int ** d, |
---|
8 | unsigned int n) |
---|
9 | { |
---|
10 | int x, y; |
---|
11 | |
---|
12 | for (x=0; x<n; ++x) |
---|
13 | { |
---|
14 | printf("%d, ",x); |
---|
15 | |
---|
16 | for (y=0; y<n; ++y) |
---|
17 | { |
---|
18 | int i; |
---|
19 | |
---|
20 | int tmp = 0; |
---|
21 | for (i=0; i<n; ++i) |
---|
22 | tmp += a[x][i] * b[i][y]; |
---|
23 | d[x][y] = tmp; |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | printf("finish\n"); |
---|
28 | } |
---|
29 | |
---|
30 | static int lock; |
---|
31 | static int next; |
---|
32 | |
---|
33 | void matrix_multiplication_mt (int ** a, |
---|
34 | int ** b, |
---|
35 | int ** d, |
---|
36 | unsigned int n, |
---|
37 | int lock_by_line) |
---|
38 | { |
---|
39 | int x, y; |
---|
40 | |
---|
41 | while (1) |
---|
42 | { |
---|
43 | lock_lock(&lock); |
---|
44 | |
---|
45 | x=next++; |
---|
46 | |
---|
47 | lock_unlock(&lock); |
---|
48 | |
---|
49 | if (x >= n) |
---|
50 | break; |
---|
51 | |
---|
52 | printf("%d, ",x); |
---|
53 | for (y=0; y<n; ++y) |
---|
54 | { |
---|
55 | int line =(lock_by_line)?x:y; |
---|
56 | int column=(lock_by_line)?y:x; |
---|
57 | |
---|
58 | int i; |
---|
59 | int tmp = 0; |
---|
60 | for (i=0; i<n; ++i) |
---|
61 | tmp += a[column][i] * b[i][line]; |
---|
62 | d[column][line] = tmp; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | printf("finish\n"); |
---|
67 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.