#include <stdio.h>
#include <omp.h>

#define ARRAY_SIZE 1000

int main() {
    int array[ARRAY_SIZE];
    long long sum = 0;

    // Initialize the array with some values
    for (int i = 0; i < ARRAY_SIZE; i++) {
        array[i] = i + 1; // Filling the array with numbers 1 to ARRAY_SIZE
    }

    // Parallel region to calculate the sum
    #pragma omp parallel
    {
        long long local_sum = 0;

        // Parallel for loop with reduction to avoid race conditions
        #pragma omp for reduction(+:sum)
        for (int i = 0; i < ARRAY_SIZE; i++) {
            local_sum += array[i];
        }

        // Update the total sum
        sum += local_sum;
    }

    printf("The sum of the array is: %lld\n", sum);
    return 0;
}
