Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with prange writing to preallocated list entries #4294

Closed
2 tasks done
stuartarchibald opened this issue Jul 9, 2019 · 4 comments · Fixed by #4305
Closed
2 tasks done

issue with prange writing to preallocated list entries #4294

stuartarchibald opened this issue Jul 9, 2019 · 4 comments · Fixed by #4305

Comments

@stuartarchibald
Copy link
Contributor

Reporting a bug

from numba import njit, prange
import numpy as np

@njit(parallel=True)
def ilikebuffers(x):
    n = len(x)
    buf = [np.zeros_like(x) for _ in range(n)]
    for i in prange(n):
        buf[i] = x + i
    return buf

a = np.ones((10,))

out = ilikebuffers(a)
[print(x) for x in out]

print("")

out = ilikebuffers.py_func(a)
[print(x) for x in out]

does this:

[2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
[2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
[4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
[4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
[6. 6. 6. 6. 6. 6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6. 6. 6. 6. 6. 6.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]

[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
[3. 3. 3. 3. 3. 3. 3. 3. 3. 3.]
[4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
[5. 5. 5. 5. 5. 5. 5. 5. 5. 5.]
[6. 6. 6. 6. 6. 6. 6. 6. 6. 6.]
[7. 7. 7. 7. 7. 7. 7. 7. 7. 7.]
[8. 8. 8. 8. 8. 8. 8. 8. 8. 8.]
[9. 9. 9. 9. 9. 9. 9. 9. 9. 9.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]

and it shouldn't. Suspect it's analysis of writing to the loop slots, but may be something else.

@stuartarchibald
Copy link
Contributor Author

CC @DrTodd13

@DrTodd13
Copy link
Collaborator

DrTodd13 commented Jul 9, 2019

@stuartarchibald I'm unable to replicate.

NUMBA_DEBUG_ARRAY_OPT=0 python /tmp/issue4294.py
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
[3. 3. 3. 3. 3. 3. 3. 3. 3. 3.]
[4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
[5. 5. 5. 5. 5. 5. 5. 5. 5. 5.]
[6. 6. 6. 6. 6. 6. 6. 6. 6. 6.]
[7. 7. 7. 7. 7. 7. 7. 7. 7. 7.]
[8. 8. 8. 8. 8. 8. 8. 8. 8. 8.]
[9. 9. 9. 9. 9. 9. 9. 9. 9. 9.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]

[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
[3. 3. 3. 3. 3. 3. 3. 3. 3. 3.]
[4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
[5. 5. 5. 5. 5. 5. 5. 5. 5. 5.]
[6. 6. 6. 6. 6. 6. 6. 6. 6. 6.]
[7. 7. 7. 7. 7. 7. 7. 7. 7. 7.]
[8. 8. 8. 8. 8. 8. 8. 8. 8. 8.]
[9. 9. 9. 9. 9. 9. 9. 9. 9. 9.]
[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]

@stuartarchibald
Copy link
Contributor Author

@DrTodd13 thanks for trying, after poking about a bit more, I think this is related to core count. I'm going to guess that you ran this on a >10 core machine? Try this one, I get 4 distinct blocks of results, and ran this on a 4 core machine:

from numba import njit, prange
import numpy as np

@njit(parallel=True)
def ilikebuffers(x):
    n = 100
    buf = [np.zeros_like(x) for _ in range(n)]
    for i in prange(n):
        buf[i] = x + i
    return buf

a = np.ones((2,))

out = ilikebuffers(a)
[print(x) for x in out]

print("")

out = ilikebuffers.py_func(a)
[print(x) for x in out]

also if I set NUMBA_NUM_THREADS=8 I get 8 distinct blocks in the results.

Thanks.

@DrTodd13
Copy link
Collaborator

@stuartarchibald Confirmed. NUMBA_NUM_THREADS=1 gives me an output consisting of all 10's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants