-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_processing_serial.c
More file actions
61 lines (45 loc) · 1.23 KB
/
array_processing_serial.c
File metadata and controls
61 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#define ARRAY_ELEMENT_LIMIT 10u
#define n 20000u
#define m 20000u
int array[n][m];
uint64_t sum = 0;
/* Initialize each element in the array with a random element between 0 and ARRAY_ELEMENT_LIMIT */
void initializeArray(void){
int i, j;
/*Initialize seed*/
srand(time(NULL));
for (i = 0; i<n; i++){
for (j = 0; j<m; j++){
//array[i][j] = rand() % ARRAY_ELEMENT_LIMIT;
array[i][j] = 1;
//printf("%d ", array[i][j]);
}
//printf("\n");
}
}
void fnc(int a, int b){
sum = sum + array[a][b];
}
int main(){
struct timespec start, end;
uint64_t delta_us;
clock_gettime(CLOCK_MONOTONIC, &start);
/* Insert code below for measurement*/
int i, j;
initializeArray();
for (i = 0; i<n; i++){
for (j = 0; j<m; j++){
fnc(i,j);
}
}
printf("Sum of array elements is %lu", sum);
/* End code measurement */
clock_gettime(CLOCK_MONOTONIC, &end);
delta_us = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
printf("\n\nExecution time:\n%lu ms\n%lu ms\n", delta_us / 1000, delta_us % 1000);
return 0;
}