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

void prefix_sum(int* input, int* output, int n) {
    output[0] = input[0];  // Initialize the first element
    
    #pragma omp parallel
    {
        // Each thread works in parallel on different sections
        #pragma omp for
        for (int i = 1; i < n; i++) {
            output[i] = output[i - 1] + input[i];
        }
    }
}

int main() {
    int n;

    // Get the size of the array from the user
    printf("Enter the size of the array: ");
    scanf("%d", &n);

    int* input = (int*)malloc(n * sizeof(int));
    int* output = (int*)malloc(n * sizeof(int));

    // Initialize the input array with values from 1 to n
    for (int i = 0; i < n; i++) {
        input[i] = i + 1;
    }

    // Calculate prefix sums
    prefix_sum(input, output, n);

    // Output the result
    printf("Prefix sums:\n");
    for (int i = 0; i < 10 && i < n; i++) {
        printf("%d ", output[i]);
    }
    printf("\n");

    // Free dynamically allocated memory
    free(input);
    free(output);

    return 0;
}
