]>
vgcfreebox.myrthtech.pt Git - ue-pp-squarematrixparallelisation.git/blob - BetterSequencialMatrixSearch.c
5 const int m_rows
= 40000;
6 const int m_cols
= m_rows
;
13 printf("1st --> Allocate aligned memory\n");
14 clock_t t_t1
; t_t1
= clock();
15 size_t rows_size
= m_rows
* sizeof(int*);
16 matrix
= malloc(rows_size
);
18 perror("malloc failled");
21 size_t data_size
= (size_t)m_rows
* m_cols
* sizeof(int);
23 if(posix_memalign((void**)&data
, 64, data_size
) != 0){
24 perror("not able to alocate memory");
28 t_t1
= clock() - t_t1
;
29 double t1_ttaken
= ((double)t_t1
)/CLOCKS_PER_SEC
;
30 printf(" %f sec \n",t1_ttaken
);
32 printf("2nd --> Populate the matrix\n");
33 clock_t t_t2
; t_t2
= clock();
34 for(int r
= 0; r
<m_rows
;r
++){
35 matrix
[r
] = data
+ r
* m_cols
;
37 for(int r
= 0; r
< m_rows
; r
++){
38 for(int c
= 0; c
< m_cols
; c
++){
39 matrix
[r
][c
] = r
*m_cols
+c
;
42 t_t2
= clock() - t_t2
;
43 double t2_ttaken
= ((double)t_t2
)/CLOCKS_PER_SEC
;
44 printf(" %f sec\n ",t2_ttaken
);
46 printf("3rd --> Search matrix \n");
47 clock_t t_t3
; t_t3
= clock();
48 for(int r
= 0; r
< m_rows
; r
++){
49 for(int c
= 0; c
< m_cols
; c
++){
50 if(matrix
[r
][c
] > hv
){
55 t_t3
= clock() - t_t3
;
56 double t3_ttaken
= ((double)t_t3
)/CLOCKS_PER_SEC
;
57 printf(" %f sec\n",t3_ttaken
);
59 printf("Done\n The biggest value found is %d", hv
);