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

Hw3 #424

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Hw3 #424

wants to merge 6 commits into from

Conversation

jacobbaron
Copy link

No description provided.

//for (j = 1; j <= lim; j++) { // YOUR CODE HERE
offset=get_local_size(0)>>j;
//printf("global_id[%d], offset=%d\n",global_id,offset);
fast[local_id]=fast[local_id]+fast[local_id+offset];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you compare this to the code in the link above, you'll see that an if statement is missing.
This causes 2 issues:

  1. Some threads may access data that is beyond the end of the input array.
  2. The output may differ because in some iteration, given two threads A and B (where B_id = A_id + offset), B may update its value, and then A will read the new value.
    This may also explain why you saw an error when using more than 32 threads, or when the global size was larger than 4096.

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

Successfully merging this pull request may close these issues.

2 participants