]>
vgcfreebox.myrthtech.pt Git - ue-pp-squarematrixparallelisation.git/blob - ParallelMatrixSearch.c
2a3c49964e929ae079199b5346206172058aaf9b
6 const int m_rows
= 40000;
7 const int m_cols
= m_rows
;
14 printf("1st --> Allocate memory\n");
15 clock_t t_t1
; t_t1
= clock();
16 size_t rows_size
= m_rows
* sizeof(int*);
17 matrix
= malloc(rows_size
);
19 perror("malloc failled");
22 size_t data_size
= (size_t)m_rows
* m_cols
* sizeof(int);
24 if(posix_memalign((void**)&data
, 64, data_size
) != 0){
25 perror("not able to alocate memory");
29 t_t1
= clock() - t_t1
;
30 double t1_ttaken
= ((double)t_t1
)/CLOCKS_PER_SEC
;
31 printf(" %f sec\n",t1_ttaken
);
33 printf("2nd --> Populate the matrix\n");
34 clock_t t_t2
; t_t2
= clock();
35 for(int r
= 0; r
<m_rows
;r
++){
36 matrix
[r
] = data
+ r
* m_cols
;
38 for(int r
= 0; r
< m_rows
; r
++){
39 for(int c
= 0; c
< m_cols
; c
++){
40 matrix
[r
][c
] = r
*m_cols
+c
;
43 t_t2
= clock() - t_t2
;
44 double t2_ttaken
= ((double)t_t2
)/CLOCKS_PER_SEC
;
45 printf(" %f sec\n",t2_ttaken
);
48 printf("3rd --> Search matrix\n");
49 clock_t t_t3
; t_t3
= clock();
50 for(int r
= 0; r
< m_rows
; r
++){
51 for(int c
= 0; c
< m_cols
; c
++){
52 if(matrix
[r
][c
] > hv
){
57 t_t3
= clock() - t_t3
;
58 double t3_ttaken
= ((double)t_t3
)/CLOCKS_PER_SEC
;
59 printf(" %f sec\n",t3_ttaken
);
61 printf("Done\n The biggest value found is %d", hv
);