{"action":"opened","issue":{"url":"https://api.github.com/repos/numba/numba/issues/3213","repository_url":"https://api.github.com/repos/numba/numba","labels_url":"https://api.github.com/repos/numba/numba/issues/3213/labels{/name}","comments_url":"https://api.github.com/repos/numba/numba/issues/3213/comments","events_url":"https://api.github.com/repos/numba/numba/issues/3213/events","html_url":"https://github.com/numba/numba/issues/3213","id":349603461,"node_id":"MDU6SXNzdWUzNDk2MDM0NjE=","number":3213,"title":"prange slower than range","user":{"login":"laoreja","id":9369143,"node_id":"MDQ6VXNlcjkzNjkxNDM=","avatar_url":"https://avatars2.githubusercontent.com/u/9369143?v=4","gravatar_id":"","url":"https://api.github.com/users/laoreja","html_url":"https://github.com/laoreja","followers_url":"https://api.github.com/users/laoreja/followers","following_url":"https://api.github.com/users/laoreja/following{/other_user}","gists_url":"https://api.github.com/users/laoreja/gists{/gist_id}","starred_url":"https://api.github.com/users/laoreja/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laoreja/subscriptions","organizations_url":"https://api.github.com/users/laoreja/orgs","repos_url":"https://api.github.com/users/laoreja/repos","events_url":"https://api.github.com/users/laoreja/events{/privacy}","received_events_url":"https://api.github.com/users/laoreja/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-10T17:50:21Z","updated_at":"2018-08-10T17:50:21Z","closed_at":null,"author_association":"NONE","body":"Numba version: 0.39.0\r\n\r\nTested on MacbookPro and a linux desktop with 8 i7 CPU, the prange version is much slower than the range version (both using `@njit(parallel=True)`)\r\n\r\nTest code:\r\n\r\n```\r\nfrom time import time\r\nimport numpy as np\r\nfrom numba import njit, prange\r\n\r\n@njit(parallel=True)\r\ndef prange_test(A):\r\n\ts = 0\r\n\tfor i in prange(A.shape[0]):\r\n\t\ts += A[i]\r\n\treturn s\r\n\r\n@njit(parallel=True)\r\ndef parallel_range_test(A):\r\n\ts = 0\r\n\tfor i in range(A.shape[0]):\r\n\t\ts += A[i]\r\n\treturn s\r\n\r\n\r\n@njit\r\ndef range_test(A):\r\n\ts = 0\r\n\tfor i in range(A.shape[0]):\r\n\t\ts += A[i]\r\n\treturn s\t\r\n\t\r\nA = np.random.randn(1000000)\r\n\r\nstart = time()\r\nprange_test(A)\r\nt = time() - start\r\nprint('prange', t)\r\n\r\nstart = time()\r\nparallel_range_test(A)\r\nt = time() - start\r\nprint('parallel range', t)\r\n\r\nstart = time()\r\nrange_test(A)\r\nt = time() - start\r\nprint('range', t)\r\n\r\nstart = time()\r\ns = np.sum(A)\r\nt = time() - start\r\nprint('np.sum', t)\r\n\r\n@njit(parallel=True)\r\ndef logistic_regression(Y, X, w, iterations):\r\n\tfor i in range(iterations):\r\n\t\tw -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X, w))) - 1.0) * Y), X)\r\n\treturn w\r\n\t\r\n@njit(parallel=True)\r\ndef logistic_regression_prange(Y, X, w, iterations):\r\n\tfor i in prange(iterations):\r\n\t\tw -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X, w))) - 1.0) * Y), X)\r\n\treturn w\r\n\r\n@njit\r\ndef logistic_regression_no_para(Y, X, w, iterations):\r\n\tfor i in range(iterations):\r\n\t\tw -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X, w))) - 1.0) * Y), X)\r\n\treturn w\r\n\t\r\nN = 10000\r\nD = 100\r\niters = 30\r\nY = np.random.randint(2, size=N)\r\nX = np.random.rand(N, D)\r\nw = np.random.randn(D)\r\n\r\nstart = time()\r\nres_w = logistic_regression(Y, X, w, iters)\r\nt = time() - start\r\nprint('parallel prange', t)\r\n\r\nstart = time()\r\nres_w = logistic_regression(Y, X, w, iters)\r\nt = time() - start\r\nprint('parallel', t)\r\n\r\nstart = time()\r\nres_w = logistic_regression_no_para(Y, X, w, iters)\r\nt = time() - start\r\nprint('no para', t)\r\n\r\n\r\n```\r\n\r\nResult on linux desktop:\r\n\r\n```\r\nprange 0.17235279083251953\r\nparallel range 0.03563380241394043\r\nrange 0.028516769409179688\r\nnp.sum 0.0005030632019042969\r\nparallel prange 0.45892953872680664\r\nparallel 0.022240877151489258\r\nno para 0.26446080207824707\r\n```"}}
{"actor":{"display_login":"laoreja"}}