OpenMP reductions not supported
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 26
Description
Reproducer. Partial credits for the inspiration (all errors are mine): https://rookiehpc.org/openmp/docs/reduction/index.html
```Makefile
# Makefile
ENZLLD = ${HOME}/repositories/ENZYME/Enzyme-v0.0.180/enzyme/build-v0.0.180/Enzyme/LLDEnzyme-20.so
run: issue.exe
./$?
issue.exe: issue.o
clang -fopenmp=libomp $? -o $@ -v -fuse-ld=lld -flto -Wl,--load-pass-plugin=$(ENZLLD)
issue.o: issue.c
clang -fopenmp=libomp -flto -c issue.c
clean:
rm *.o *.exe
```
```c
// issue.c
#include
#include
#include
double __enzyme_autodiff(void*, ...);
extern int enzyme_const, enzyme_dup, enzyme_out;
double compute(double* myArray, const int ARRAY_SIZE) {
// Calculate the sum of all elements
double sum = 0;
#pragma omp parallel for default(none) shared(myArray) firstprivate(ARRAY_SIZE) reduction(+: sum)
for(int i = 0; i < ARRAY_SIZE; i++)
{
sum += myArray[i];
}
return sum;
}
int main(int argc, char* argv[])
{
// Use 2 threads when creating OpenMP parallel regions
omp_set_num_threads(2);
double total = 0;
const int ARRAY_SIZE = 10;
double* myArray = malloc(sizeof(double) * ARRAY_SIZE);
double* myArray_der = malloc(sizeof(double) * ARRAY_SIZE);
if(myArray_der == NULL)
{
printf("Cannot allocate the array \"myArray\".\n");
return EXIT_FAILURE;
}
// Initialise the array
for(int i = 0; i < ARRAY_SIZE; i++)
{
myArray[i] = i;
myArray_der[i] = 0;
}
total = compute(myArray, ARRAY_SIZE);
printf("The sum of all array elements is equal to %f.\n", total);
__enzyme_autodiff((void*)compute,
enzyme_dup, myArray, myArray_der,
enzyme_const, ARRAY_SIZE - 1);
printf("The derivative of the sum of the array elements is equal to:\n");
for(int i = 0; i < ARRAY_SIZE; i++)
{
printf("%f, ", myArray_der[i]);
}
printf("\n");
printf("Note last element is zero because we passed ARRAY_SIZE - 1\n");
free(myArray);
free(myArray_der);
return EXIT_SUCCESS;
}
```
Works fine once one removes OpenMP.
Contributor guide
Assessment
This issue has not been assessed yet.