1 | #include "func_mm.h" |
---|
2 | |
---|
3 | void mm_algo1 ( unsigned int size_matrix |
---|
4 | ,unsigned int ** matrix_a |
---|
5 | ,unsigned int ** matrix_b |
---|
6 | ,unsigned int ** matrix_d) |
---|
7 | { |
---|
8 | unsigned int index_i, index_j, index_k; |
---|
9 | |
---|
10 | for (index_i = 0; index_i < size_matrix; index_i ++) |
---|
11 | for (index_j = 0; index_j < size_matrix; index_j ++) |
---|
12 | { |
---|
13 | matrix_d [index_i][index_j] = 0; |
---|
14 | |
---|
15 | for (index_k = 0; index_k < size_matrix; index_k ++) |
---|
16 | matrix_d [index_i][index_j] += matrix_a[index_i][index_k] * matrix_b[index_k][index_j]; |
---|
17 | } |
---|
18 | } |
---|
19 | |
---|
20 | int mm(unsigned int size_matrix, unsigned int algo) |
---|
21 | { |
---|
22 | unsigned int matrix_a [size_matrix][size_matrix]; |
---|
23 | unsigned int matrix_b [size_matrix][size_matrix]; |
---|
24 | unsigned int matrix_d [size_matrix][size_matrix]; |
---|
25 | unsigned int sum , sum_ok; |
---|
26 | unsigned int index_i, index_j; |
---|
27 | |
---|
28 | /* |
---|
29 | * PHASE 1 : Initialisation |
---|
30 | */ |
---|
31 | |
---|
32 | /* Flush matrix_d */ |
---|
33 | for (index_i = 0; index_i < size_matrix; index_i ++) |
---|
34 | for (index_j = 0; index_j < size_matrix; index_j ++) |
---|
35 | { |
---|
36 | matrix_a [index_i][index_j] = index_i+1; |
---|
37 | matrix_b [index_i][index_j] = index_i+1; |
---|
38 | matrix_d [index_i][index_j] = 0; |
---|
39 | } |
---|
40 | |
---|
41 | sum = (size_matrix*(size_matrix+1))>>1; |
---|
42 | /* |
---|
43 | sum = (N*(N+1))/2; |
---|
44 | ici sum = (4*5)/2 = 10 |
---|
45 | |
---|
46 | ( 1 1 1 1 ) |
---|
47 | ( 2 2 2 2 ) |
---|
48 | ( 3 3 3 3 ) |
---|
49 | ( 4 4 4 4 ) |
---|
50 | ( 1 1 1 1 ) 10 10 10 10 -> 1*sum |
---|
51 | ( 2 2 2 2 ) 20 20 20 20 -> 2*sum |
---|
52 | ( 3 3 3 3 ) 30 30 30 30 -> 3*sum |
---|
53 | ( 4 4 4 4 ) 40 40 40 40 -> 4*sum |
---|
54 | */ |
---|
55 | |
---|
56 | /* |
---|
57 | * PHASE 2 : Execution |
---|
58 | */ |
---|
59 | |
---|
60 | switch (algo) |
---|
61 | { |
---|
62 | case 1 : |
---|
63 | { |
---|
64 | /* méthode classique */ |
---|
65 | |
---|
66 | unsigned int index_i, index_j, index_k; |
---|
67 | |
---|
68 | for (index_i=0;index_i<size_matrix;index_i++) |
---|
69 | for (index_j=0;index_j<size_matrix;index_j++) |
---|
70 | { |
---|
71 | matrix_d [index_i][index_j] = 0; |
---|
72 | |
---|
73 | for (index_k=0;index_k<size_matrix;index_k++) |
---|
74 | matrix_d [index_i][index_j] += matrix_a[index_i][index_k] * matrix_b[index_k][index_j]; |
---|
75 | } |
---|
76 | |
---|
77 | //mm_algo1(size_matrix, matrix_a, matrix_b, matrix_d); |
---|
78 | break; |
---|
79 | } |
---|
80 | default :break; |
---|
81 | }/* end switch algo */ |
---|
82 | |
---|
83 | /* |
---|
84 | * PHASE 3 : Test |
---|
85 | */ |
---|
86 | |
---|
87 | sum_ok = 0; |
---|
88 | |
---|
89 | for (index_i=0;index_i<size_matrix;index_i++) |
---|
90 | { |
---|
91 | unsigned int row_sum = (index_i+1)*sum; |
---|
92 | |
---|
93 | for (index_j=0;index_j<size_matrix;index_j++) |
---|
94 | if ((matrix_a[index_i][index_j] == index_i+1) && |
---|
95 | (matrix_b[index_i][index_j] == index_i+1) && |
---|
96 | (matrix_d[index_i][index_j] == row_sum) |
---|
97 | ) |
---|
98 | sum_ok ++; |
---|
99 | } |
---|
100 | |
---|
101 | return (sum_ok == (size_matrix * size_matrix) ); |
---|
102 | } |
---|