<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64797>64797</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Attributor][OpenMP] Previous AA fix breaks code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
jdoerfert
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
doru1004
</td>
</tr>
</table>
<pre>
Back to back distribute functions fail when this patch is enabled:
https://reviews.llvm.org/rG0cd8a28941ac88ed7567589466d12bf5d7549224
This is the code:
```
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_N 32
void reset_input(double *a, double *a_h, double *b, double *c) {
for(int i = 0 ; i < MAX_N ; i++) {
a[i] = a_h[i] = i;
b[i] = i*2;
c[i] = i-3;
}
}
int main(int argc, char *argv[]) {
double * a = (double *) malloc(MAX_N * sizeof(double));
double * a_h = (double *) malloc(MAX_N * sizeof(double));
double * d = (double *) malloc(MAX_N * sizeof(double));
double * d_h = (double *) malloc(MAX_N * sizeof(double));
double * b = (double *) malloc(MAX_N * sizeof(double));
double * c = (double *) malloc(MAX_N * sizeof(double));
#pragma omp target enter data map(to:a[:MAX_N],b[:MAX_N],c[:MAX_N],d[:MAX_N])
for (int n = 32 ; n < 33 ; n+=5000) {
reset_input(a, a_h, b, c);
#pragma omp target update to(a[:n],b[:n],c[:n],d[:n])
int t = 0;
for (int tms = 256 ; tms <= 256 ; tms *= 2) { // 8 times
for (int ths = 1024 ; ths <= 1024 ; ths *= 2) { // 6 times
t++;
printf("Try with TEAMS = %d, THREADS = %d\n", tms, ths);
#pragma omp target
#pragma omp teams num_teams(tms) thread_limit(ths)
{
#pragma omp distribute parallel for
for (int i = 0; i < n; ++i) {
a[i] += b[i] + c[i];
}
#pragma omp distribute parallel for
for (int i = 0; i < n; ++i) {
d[i] -= b[i] + c[i];
}
}
} // loop over 'ths'
} // loop over 'tms'
// check results for each 'n'
for (int times = 0 ; times < t ; times++) {
printf("H: ");
for (int i = 0; i < n; ++i) {
a_h[i] += b[i] + c[i];
printf("%f ", a_h[i]);
}
printf("\n");
}
#pragma omp target update from(a[:n],d[:n])
printf("D: ");
for (int i = 0; i < n; ++i) {
printf("%f ", a[i]);
}
printf("\n");
for (int i = 0; i < n; ++i) {
if (a_h[i] != a[i]) {
printf("A Error at n = %d, i = %d: host = %f, device = %f\n", n, i, a_h[i], a[i]);
return 1;
}
}
} // loop over 'n'
printf("Succeeded\n");
return 0;
}
```
The failure goes away when OpenMP OPT is disabled.
The failure also goes away when OpenMP OPT is enabled and the above patch is reverted.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V0-TmzoS_zTypWumQBgDBx-wPbO5ZJPazGFvUwI1RglIlCQ8m_30ryRjA_4zlXrJPJcL6Jb0U3er_6iZMWIvEdck3hBKv3OFukJtCaUk3i1Yb2ul11zpPgyC5aJQ_Od6w8ofYBUU7s2FsVoUvUWoellaoaSBiokG3mqUYGthoGO2rEEYQMmKBjmJchLsSDA8a2s743j0mdBnjQeBb-axaQ7to9J7x_pXUPKU0TRbhqxMU-RJvEriNFuuVjykRRXzJF5mlC6nsC9ua2HA1gil4nixK1kFw_9I0kjIsuk5Aom2qu0eaxI93Rozlgv13mgjiunwaRLHSkiEz_l_X_8NEZ2OHpTgoNGgfRWy6y2hKVd90SAQmjNCtzAhX-s5o5iTJaEZkGRzRAaolCY0FdKCABLtIAASbfz3dpDF04Ru_H-6lpF4I0i88-vcvhNSkOi8BUAxH6I5nQ2Xs-GHaBwkyW4wxPnDP528LRNyEJ3pfenULGumvRH0_uA8Nt5daDvaAZjfbWZKN7llTaNKQtNBeZqDEf9HVZ1nEpq5f3QT9LX-CFj-IaAfI2vxEaDlHwI9R1un2b5loNoOLNN7tIDSogbOLIOWdYSmVpEodz5Ootzje3faFlec8orDLznZdHsfdDC4rvSaRdSHmfRhF0VHwgVctIuDILjwYrhIBj4FDIHvw738RZ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