You should use reduction like this:
#pragma omp parallel for reduction (+:sum)
for (int i=0;i<n;i++)
sum=sum+a[i];
More Related Contents:
- Cholesky decomposition with OpenMP
- Difference between section and task openmp
- No performance gain after using openMP on a program optimize for sequential running
- Reductions in parallel in logarithmic time
- Access element of array of pointer of structure
- Explanation of output of this C code
- whats the difference between dynamic memory allocation and normal memory allocation?
- Getting an error while running following code
- Finding target sum of two numbers in array
- Please explain the following parallel code template
- Correctly allocating multi-dimensional arrays
- Array-size macro that rejects pointers
- How to initialize array to 0 in C?
- Freaky way of allocating two-dimensional array?
- c structure array initializing
- Why am I being allowed to use a const qualified variable as an array size in C?
- Pointer vs array in C, non-trivial difference
- Using Dynamic Memory allocation for arrays
- Array type char[] is not assignable [duplicate]
- Accesing a 2D array using a single pointer
- Why does “memset(arr, -1, sizeof(arr)/sizeof(int))” not clear an integer array to -1?
- Hex to char array in C
- Array of variable length in a structure
- C array declaration and assignment?
- openMP nested parallel for loops vs inner parallel for
- How can I change the size of an array in C?
- Variable Sized Arrays vs calloc in C
- How can I malloc a struct array inside a function? Code works otherwise
- problems with char array = char array
- C pointer notation compared to array notation: When passing to function