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

Numbers don't add up? #7133

Closed
HarveyYan opened this issue Jun 22, 2021 · 2 comments
Closed

Numbers don't add up? #7133

HarveyYan opened this issue Jun 22, 2021 · 2 comments
Labels
no action required No action was needed to resolve.

Comments

@HarveyYan
Copy link

HarveyYan commented Jun 22, 2021

import numpy as np
from numba import prange as parallel_range
from numba import jit

@jit(nopython=True, parallel=True)
def func():
    vector = np.zeros(2)
    for i in parallel_range(2):
        for j in range(2):
            vector[j] += 1
            vector[i] += 1
    return vector

ret = func()
print(ret)

This very simple example gives [4., 3.]... Where does that additional 1 go?

@HarveyYan
Copy link
Author

Alright I see it's because of the race condition — multiple threads trying to write to the same slice or element in an array. Linking to an existing issue #3681

@esc
Copy link
Member

esc commented Jun 22, 2021

@HarveyYan thank you for asking about this on the Numba issue tracker. I believe your analysis is correct.

@esc esc added the no action required No action was needed to resolve. label Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no action required No action was needed to resolve.
Projects
None yet
Development

No branches or pull requests

2 participants