{"action":"created","comment":{"url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments/45150942","id":45150942,"diff_hunk":"@@ -54,39 +54,67 @@ cpdef move_data_serial(np.int32_t[:] counts,\n                        np.int32_t[:] src,\n                        np.int32_t[:] dest,\n                        int repeat):\n-   cdef:\n-       int idx, r\n+    cdef:\n+        int idx, r\n+\n+    assert src.size == dest.size, \"Sizes of src and dest arrays must match\"\n+    with nogil:\n+        for r in range(repeat):\n+            for idx in range(src.shape[0]):\n+                if counts[src[idx]] > 0:\n+                    counts[dest[idx]] += 1\n+                    counts[src[idx]] -= 1\n+\n \n-   assert src.size == dest.size, \"Sizes of src and dest arrays must match\"\n-   with nogil:\n-       for r in range(repeat):\n-           for idx in range(src.shape[0]):\n-               if counts[src[idx]] > 0:\n-                   counts[dest[idx]] += 1\n-                   counts[src[idx]] -= 1\n+cdef void lock_and_increment(int idx, omp_lock_t *lock, int increment_by, np.int32_t[:] counts) nogil:\n+    acquire(lock)\n+    counts[idx] += increment_by\n+    release(lock)\n \n \n cpdef move_data_fine_grained(np.int32_t[:] counts,\n                              np.int32_t[:] src,\n                              np.int32_t[:] dest,\n                              int repeat):\n-   cdef:\n-       int idx, r\n-       omp_lock_t *locks = get_N_locks(counts.shape[0])\n+    cdef:\n+        int idx, r, src_idx, dest_idx\n+        omp_lock_t *locks = get_N_locks(counts.shape[0])\n+        omp_lock_t *min_lock\n+        omp_lock_t *max_lock\n+\n+    ##########s\n+    # Your code here\n+    # Use parallel.prange() and a lock for each element of counts to parallelize\n+    # data movement.  Be sure to avoid deadlock, and double-locking.\n+    ##########\n+    with nogil:\n+        for r in range(repeat):\n+            for idx in prange(src.shape[0], num_threads=4):\n+\n+                # checking the locks instead of ids allows this code to\n+                # work almost unchanged for coarse-grained locking\n+                min_lock = &locks[src[idx]] if src[idx] < dest[idx] else &locks[dest[idx]]","path":"HW2/P2/parallel_vector.pyx","position":55,"original_position":55,"commit_id":"3e32cccfe383ef3c07f81327c83113010a3d600a","original_commit_id":"3e32cccfe383ef3c07f81327c83113010a3d600a","user":{"login":"ankitvgupta","id":5473865,"avatar_url":"https://avatars.githubusercontent.com/u/5473865?v=3","gravatar_id":"","url":"https://api.github.com/users/ankitvgupta","html_url":"https://github.com/ankitvgupta","followers_url":"https://api.github.com/users/ankitvgupta/followers","following_url":"https://api.github.com/users/ankitvgupta/following{/other_user}","gists_url":"https://api.github.com/users/ankitvgupta/gists{/gist_id}","starred_url":"https://api.github.com/users/ankitvgupta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankitvgupta/subscriptions","organizations_url":"https://api.github.com/users/ankitvgupta/orgs","repos_url":"https://api.github.com/users/ankitvgupta/repos","events_url":"https://api.github.com/users/ankitvgupta/events{/privacy}","received_events_url":"https://api.github.com/users/ankitvgupta/received_events","type":"User","site_admin":false},"body":"nice this is a neat way to do them in order cleanly.","created_at":"2015-11-18T02:00:33Z","updated_at":"2015-11-18T02:00:33Z","html_url":"https://github.com/harvard-cs205/cs205-homework/pull/350#discussion_r45150942","pull_request_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350","_links":{"self":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments/45150942"},"html":{"href":"https://github.com/harvard-cs205/cs205-homework/pull/350#discussion_r45150942"},"pull_request":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350"}}},"pull_request":{"url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350","id":49778256,"html_url":"https://github.com/harvard-cs205/cs205-homework/pull/350","diff_url":"https://github.com/harvard-cs205/cs205-homework/pull/350.diff","patch_url":"https://github.com/harvard-cs205/cs205-homework/pull/350.patch","issue_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/350","number":350,"state":"open","locked":false,"title":"HW2","user":{"login":"araftery","id":5026528,"avatar_url":"https://avatars.githubusercontent.com/u/5026528?v=3","gravatar_id":"","url":"https://api.github.com/users/araftery","html_url":"https://github.com/araftery","followers_url":"https://api.github.com/users/araftery/followers","following_url":"https://api.github.com/users/araftery/following{/other_user}","gists_url":"https://api.github.com/users/araftery/gists{/gist_id}","starred_url":"https://api.github.com/users/araftery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/araftery/subscriptions","organizations_url":"https://api.github.com/users/araftery/orgs","repos_url":"https://api.github.com/users/araftery/repos","events_url":"https://api.github.com/users/araftery/events{/privacy}","received_events_url":"https://api.github.com/users/araftery/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-05T03:24:49Z","updated_at":"2015-11-18T02:00:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"01a6253fab3803404ea08d8051c97debdb271c59","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350/commits","review_comments_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350/comments","review_comment_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/350/comments","statuses_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/statuses/3e32cccfe383ef3c07f81327c83113010a3d600a","head":{"label":"araftery:HW2","ref":"HW2","sha":"3e32cccfe383ef3c07f81327c83113010a3d600a","user":{"login":"araftery","id":5026528,"avatar_url":"https://avatars.githubusercontent.com/u/5026528?v=3","gravatar_id":"","url":"https://api.github.com/users/araftery","html_url":"https://github.com/araftery","followers_url":"https://api.github.com/users/araftery/followers","following_url":"https://api.github.com/users/araftery/following{/other_user}","gists_url":"https://api.github.com/users/araftery/gists{/gist_id}","starred_url":"https://api.github.com/users/araftery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/araftery/subscriptions","organizations_url":"https://api.github.com/users/araftery/orgs","repos_url":"https://api.github.com/users/araftery/repos","events_url":"https://api.github.com/users/araftery/events{/privacy}","received_events_url":"https://api.github.com/users/araftery/received_events","type":"User","site_admin":false},"repo":{"id":41928248,"name":"cs205-homework","full_name":"araftery/cs205-homework","owner":{"login":"araftery","id":5026528,"avatar_url":"https://avatars.githubusercontent.com/u/5026528?v=3","gravatar_id":"","url":"https://api.github.com/users/araftery","html_url":"https://github.com/araftery","followers_url":"https://api.github.com/users/araftery/followers","following_url":"https://api.github.com/users/araftery/following{/other_user}","gists_url":"https://api.github.com/users/araftery/gists{/gist_id}","starred_url":"https://api.github.com/users/araftery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/araftery/subscriptions","organizations_url":"https://api.github.com/users/araftery/orgs","repos_url":"https://api.github.com/users/araftery/repos","events_url":"https://api.github.com/users/araftery/events{/privacy}","received_events_url":"https://api.github.com/users/araftery/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/araftery/cs205-homework","description":"","fork":true,"url":"https://api.github.com/repos/araftery/cs205-homework","forks_url":"https://api.github.com/repos/araftery/cs205-homework/forks","keys_url":"https://api.github.com/repos/araftery/cs205-homework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/araftery/cs205-homework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/araftery/cs205-homework/teams","hooks_url":"https://api.github.com/repos/araftery/cs205-homework/hooks","issue_events_url":"https://api.github.com/repos/araftery/cs205-homework/issues/events{/number}","events_url":"https://api.github.com/repos/araftery/cs205-homework/events","assignees_url":"https://api.github.com/repos/araftery/cs205-homework/assignees{/user}","branches_url":"https://api.github.com/repos/araftery/cs205-homework/branches{/branch}","tags_url":"https://api.github.com/repos/araftery/cs205-homework/tags","blobs_url":"https://api.github.com/repos/araftery/cs205-homework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/araftery/cs205-homework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/araftery/cs205-homework/git/refs{/sha}","trees_url":"https://api.github.com/repos/araftery/cs205-homework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/araftery/cs205-homework/statuses/{sha}","languages_url":"https://api.github.com/repos/araftery/cs205-homework/languages","stargazers_url":"https://api.github.com/repos/araftery/cs205-homework/stargazers","contributors_url":"https://api.github.com/repos/araftery/cs205-homework/contributors","subscribers_url":"https://api.github.com/repos/araftery/cs205-homework/subscribers","subscription_url":"https://api.github.com/repos/araftery/cs205-homework/subscription","commits_url":"https://api.github.com/repos/araftery/cs205-homework/commits{/sha}","git_commits_url":"https://api.github.com/repos/araftery/cs205-homework/git/commits{/sha}","comments_url":"https://api.github.com/repos/araftery/cs205-homework/comments{/number}","issue_comment_url":"https://api.github.com/repos/araftery/cs205-homework/issues/comments{/number}","contents_url":"https://api.github.com/repos/araftery/cs205-homework/contents/{+path}","compare_url":"https://api.github.com/repos/araftery/cs205-homework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/araftery/cs205-homework/merges","archive_url":"https://api.github.com/repos/araftery/cs205-homework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/araftery/cs205-homework/downloads","issues_url":"https://api.github.com/repos/araftery/cs205-homework/issues{/number}","pulls_url":"https://api.github.com/repos/araftery/cs205-homework/pulls{/number}","milestones_url":"https://api.github.com/repos/araftery/cs205-homework/milestones{/number}","notifications_url":"https://api.github.com/repos/araftery/cs205-homework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/araftery/cs205-homework/labels{/name}","releases_url":"https://api.github.com/repos/araftery/cs205-homework/releases{/id}","created_at":"2015-09-04T17:14:57Z","updated_at":"2015-09-04T17:14:57Z","pushed_at":"2015-11-05T03:22:47Z","git_url":"git://github.com/araftery/cs205-homework.git","ssh_url":"git@github.com:araftery/cs205-homework.git","clone_url":"https://github.com/araftery/cs205-homework.git","svn_url":"https://github.com/araftery/cs205-homework","homepage":null,"size":3351,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"harvard-cs205:master","ref":"master","sha":"6706ee708d97c656caa08b284792b3eee63892cf","user":{"login":"harvard-cs205","id":13456002,"avatar_url":"https://avatars.githubusercontent.com/u/13456002?v=3","gravatar_id":"","url":"https://api.github.com/users/harvard-cs205","html_url":"https://github.com/harvard-cs205","followers_url":"https://api.github.com/users/harvard-cs205/followers","following_url":"https://api.github.com/users/harvard-cs205/following{/other_user}","gists_url":"https://api.github.com/users/harvard-cs205/gists{/gist_id}","starred_url":"https://api.github.com/users/harvard-cs205/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harvard-cs205/subscriptions","organizations_url":"https://api.github.com/users/harvard-cs205/orgs","repos_url":"https://api.github.com/users/harvard-cs205/repos","events_url":"https://api.github.com/users/harvard-cs205/events{/privacy}","received_events_url":"https://api.github.com/users/harvard-cs205/received_events","type":"Organization","site_admin":false},"repo":{"id":40614104,"name":"cs205-homework","full_name":"harvard-cs205/cs205-homework","owner":{"login":"harvard-cs205","id":13456002,"avatar_url":"https://avatars.githubusercontent.com/u/13456002?v=3","gravatar_id":"","url":"https://api.github.com/users/harvard-cs205","html_url":"https://github.com/harvard-cs205","followers_url":"https://api.github.com/users/harvard-cs205/followers","following_url":"https://api.github.com/users/harvard-cs205/following{/other_user}","gists_url":"https://api.github.com/users/harvard-cs205/gists{/gist_id}","starred_url":"https://api.github.com/users/harvard-cs205/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harvard-cs205/subscriptions","organizations_url":"https://api.github.com/users/harvard-cs205/orgs","repos_url":"https://api.github.com/users/harvard-cs205/repos","events_url":"https://api.github.com/users/harvard-cs205/events{/privacy}","received_events_url":"https://api.github.com/users/harvard-cs205/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/harvard-cs205/cs205-homework","description":"","fork":false,"url":"https://api.github.com/repos/harvard-cs205/cs205-homework","forks_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/forks","keys_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/teams","hooks_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/hooks","issue_events_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/events{/number}","events_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/events","assignees_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/assignees{/user}","branches_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/branches{/branch}","tags_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/tags","blobs_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/refs{/sha}","trees_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/statuses/{sha}","languages_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/languages","stargazers_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/stargazers","contributors_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/contributors","subscribers_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/subscribers","subscription_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/subscription","commits_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/commits{/sha}","git_commits_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/commits{/sha}","comments_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/comments{/number}","issue_comment_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/comments{/number}","contents_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/contents/{+path}","compare_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/merges","archive_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/downloads","issues_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues{/number}","pulls_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls{/number}","milestones_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/milestones{/number}","notifications_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/labels{/name}","releases_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/releases{/id}","created_at":"2015-08-12T17:18:15Z","updated_at":"2015-10-21T19:21:28Z","pushed_at":"2015-11-18T01:58:18Z","git_url":"git://github.com/harvard-cs205/cs205-homework.git","ssh_url":"git@github.com:harvard-cs205/cs205-homework.git","clone_url":"https://github.com/harvard-cs205/cs205-homework.git","svn_url":"https://github.com/harvard-cs205/cs205-homework","homepage":null,"size":162893,"stargazers_count":5,"watchers_count":5,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":99,"mirror_url":null,"open_issues_count":361,"forks":99,"open_issues":361,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350"},"html":{"href":"https://github.com/harvard-cs205/cs205-homework/pull/350"},"issue":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/350"},"comments":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/350/comments"},"review_comments":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350/comments"},"review_comment":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/350/commits"},"statuses":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/statuses/3e32cccfe383ef3c07f81327c83113010a3d600a"}}}}