Advertisement
programmer1997

GCC Vectorization Example

Oct 30th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #define SIZE 1000
  6.  
  7. void main() {
  8.     srand(time(NULL));
  9.  
  10.     size_t i;
  11.     int arr1[1000] = { 0 };
  12.     int arr2[1000] = { 0 };
  13.     int arr3[1000] = { 0 };
  14.     long long int sum = 0;
  15.  
  16.     for (i = 0; i < SIZE; i++)
  17.         arr1[i] = rand() % ((1000) + 1 - (-1000)) + (-1000);
  18.  
  19.     for (i = 0; i < SIZE; i++)
  20.         arr2[i] = rand() % ((1000) + 1 - (-1000)) + (-1000);
  21.  
  22.     for (i = 0; i < SIZE; i++)
  23.         arr3[i] = arr1[i] + arr2[i];
  24.  
  25.     for (i = 0; i < SIZE; i++)
  26.         sum += arr3[i];
  27.  
  28.     printf("Sum of third array is %d\n",sum);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement