File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdlib.h>
2
+ #include <stdio.h>
3
+ #include <sys/time.h>
4
+
5
+ #define ARRSIZE 1000000
6
+
7
+ int main () {
8
+ int * A , * B , * C ;
9
+ A = (int * )malloc (ARRSIZE * sizeof (int ));
10
+ B = (int * )malloc (ARRSIZE * sizeof (int ));
11
+ C = (int * )malloc (ARRSIZE * sizeof (int ));
12
+
13
+ for (int i = 0 ; i < ARRSIZE ; i ++ ) {
14
+ A [i ] = i ;
15
+ B [i ] = i ;
16
+ }
17
+
18
+ struct timeval start , end ;
19
+ gettimeofday (& start , NULL );
20
+ #pragma omp parallel for default(none) shared(A,B,C)
21
+ for (int i = 0 ; i < ARRSIZE ; i ++ ) {
22
+ C [i ] = A [i ] + B [i ];
23
+ }
24
+ gettimeofday (& end , NULL );
25
+
26
+ double time_taken = (end .tv_sec ) + (end .tv_usec /1e6 ) - ((start .tv_sec ) + (start .tv_usec /1e6 ));
27
+ printf ("Time taken to add integer arrays of length %d: %g (seconds)\n" , ARRSIZE , time_taken );
28
+
29
+ free (A );
30
+ free (B );
31
+ free (C );
32
+ }
You can’t perform that action at this time.
0 commit comments