{"action":"created","comment":{"url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/comments/34799569","id":34799569,"diff_hunk":"@@ -14,71 +23,127 @@ double *X;\n double *X_old;\n double *temp;\n \n+void *partial_jacobi(void *arg)\n+{\n+    int i, j;\n+    double xi;\n+    struct jacobi_args *params = arg;\n+\n+    //actual iteration step\n+    for (i = params->start; i < params->end; ++i)\n+    {\n+        xi = 0;\n+        for(j = 0; j < MATRIX_SIZE; ++j)\n+        {\n+            if(j==i)\n+            {\n+                continue;\n+            }\n+            xi += A[i][j]*X_old[j];\n+        }\n+        xi = b[i]-xi;\n+        xi /= A[i][i];\n+        X[i] = xi;\n+    }\n+    return NULL;\n+}\n+\n int main(int argc, char **argv)\n {\n-\tunsigned int i, j;\n-\tunsigned int iterations = 0;\n-\tdouble error, xi, norm, max = 0.0;\n-\tstruct timeval start, end;\n-\n-\tprintf(\"\\nInitialize system of linear equations...\\n\");\n-\t/* allocate memory for the system of linear equations */\n-\tinit_matrix(&A, &b, MATRIX_SIZE);\n-\tX = (double *)malloc(sizeof(double) * MATRIX_SIZE);\n-\tX_old = (double *)malloc(sizeof(double) * MATRIX_SIZE);\n-\n-\t/* a \"random\" solution vector */\n-\tfor (i = 0; i < MATRIX_SIZE; i++) {\n-\t\tX[i] = ((double)rand()) / ((double)RAND_MAX) * 10.0;\n-\t\tX_old[i] = 0.0;\n-\t}\n-\n-\tprintf(\"Start Jacobi method...\\n\");\n-\n-\tgettimeofday(&start, NULL);\n-\n-\t/* TODO: Hier muss die Aufgabe geloest werden */\n-\n-\tgettimeofday(&end, NULL);\n-\n-\tif (MATRIX_SIZE < 16) {\n-\t\tprintf(\"Print the solution...\\n\");\n-\t\t/* print solution */\n-\t\tfor (i = 0; i < MATRIX_SIZE; i++) {\n-\t\t\tfor (j = 0; j < MATRIX_SIZE; j++)\n-\t\t\t\tprintf(\"%8.2f\\t\", A[i][j]);\n-\t\t\tprintf(\"*\\t%8.2f\\t=\\t%8.2f\\n\", X[i], b[i]);\n-\t\t}\n-\t}\n-\n-\tprintf(\"Check the result...\\n\");\n-\t/* \n-\t * check the result \n-\t * X[i] have to be 1\n-\t */\n-\tfor (i = 0; i < MATRIX_SIZE; i++) {\n-\t\terror = fabs(X[i] - 1.0f);\n-\n-\t\tif (max < error)\n-\t\t\tmax = error;\n-\t\tif (error > 0.01f)\n-\t\t\tprintf(\"Result is on position %d wrong (%f != 1.0)\\n\",\n-\t\t\t       i, X[i]);\n-\t}\n-\tprintf(\"maximal error is %f\\n\", max);\n-\n-\tprintf(\"\\nmatrix size: %d x %d\\n\", MATRIX_SIZE, MATRIX_SIZE);\n-\tprintf(\"number of iterations: %d\\n\", iterations);\n-\tprintf(\"Time : %lf sec\\n\",\n-\t       (double)(end.tv_sec - start.tv_sec) + (double)(end.tv_usec -\n-\t\t\t\t\t\t\t      start.tv_usec) /\n-\t       1000000.0);\n-\n-\t/* frees the allocated memory */\n-\tfree(X_old);\n-\tfree(X);\n-\tclean_matrix(&A);\n-\tclean_vector(&b);\n-\n-\treturn 0;\n+    unsigned int i, j;\n+    unsigned int iterations = 0;\n+    double error, norm, max = 0.0;\n+    struct timeval start, end;\n+    pthread_t threads[NUM_THREADS];\n+    struct jacobi_args threadargs[NUM_THREADS];\n+\n+    //fill start and end indices for all threads\n+    for(i = 0; i < NUM_THREADS; ++i)\n+    {\n+        threadargs[i].start = i*THREAD_STEP;\n+        threadargs[i].end = (i+1)*THREAD_STEP;\n+    }\n+\n+    printf(\"\\nInitialize system of linear equations...\\n\");\n+    /* allocate memory for the system of linear equations */\n+    init_matrix(&A, &b, MATRIX_SIZE);\n+    X = (double *)aligned_alloc(16, sizeof(double) * MATRIX_SIZE);\n+    X_old = (double *)aligned_alloc(16, sizeof(double) * MATRIX_SIZE);\n+\n+    /* a \"random\" solution vector */\n+    for (i = 0; i < MATRIX_SIZE; i++) {\n+        X[i] = ((double)rand()) / ((double)RAND_MAX) * 10.0;\n+        X_old[i] = 0.0;\n+    }\n+\n+    printf(\"Start Jacobi method...\\n\");\n+\n+    gettimeofday(&start, NULL);\n+\n+    norm = euklid_norm_sq();\n+    while(norm >= .0000001*MATRIX_SIZE)\n+    {\n+        //swap X_old and X\n+        temp = X_old;\n+        X_old = X;\n+        X = temp;\n+\n+        //create threads\n+        for(i = 0; i < NUM_THREADS; ++i)\n+        {\n+            pthread_create(&threads[i], NULL, partial_jacobi,\n+                           &threadargs[i]);\n+        }\n+        //threads are running, wait for them to finish\n+        for(i = 0; i < NUM_THREADS; ++i)\n+        {\n+            pthread_join(threads[i], NULL);\n+        }\n+\n+        norm = euklid_norm_sq();\n+        iterations++;\n+    }","path":"main.c","position":168,"original_position":168,"commit_id":"61466580faf1c903aae3a85e4347991fd970869b","original_commit_id":"61466580faf1c903aae3a85e4347991fd970869b","user":{"login":"daniel-k","id":224128,"avatar_url":"https://avatars.githubusercontent.com/u/224128?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-k","html_url":"https://github.com/daniel-k","followers_url":"https://api.github.com/users/daniel-k/followers","following_url":"https://api.github.com/users/daniel-k/following{/other_user}","gists_url":"https://api.github.com/users/daniel-k/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-k/subscriptions","organizations_url":"https://api.github.com/users/daniel-k/orgs","repos_url":"https://api.github.com/users/daniel-k/repos","events_url":"https://api.github.com/users/daniel-k/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-k/received_events","type":"User","site_admin":false},"body":":+1: ","created_at":"2015-07-16T15:22:20Z","updated_at":"2015-07-16T15:22:20Z","html_url":"https://github.com/RWTH-OS/gi4_uebung07/pull/4#discussion_r34799569","pull_request_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/comments/34799569"},"html":{"href":"https://github.com/RWTH-OS/gi4_uebung07/pull/4#discussion_r34799569"},"pull_request":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4","id":38092154,"html_url":"https://github.com/RWTH-OS/gi4_uebung07/pull/4","diff_url":"https://github.com/RWTH-OS/gi4_uebung07/pull/4.diff","patch_url":"https://github.com/RWTH-OS/gi4_uebung07/pull/4.patch","issue_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues/4","number":4,"state":"open","locked":false,"title":"Übung 7","user":{"login":"mowfask","id":7459936,"avatar_url":"https://avatars.githubusercontent.com/u/7459936?v=3","gravatar_id":"","url":"https://api.github.com/users/mowfask","html_url":"https://github.com/mowfask","followers_url":"https://api.github.com/users/mowfask/followers","following_url":"https://api.github.com/users/mowfask/following{/other_user}","gists_url":"https://api.github.com/users/mowfask/gists{/gist_id}","starred_url":"https://api.github.com/users/mowfask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mowfask/subscriptions","organizations_url":"https://api.github.com/users/mowfask/orgs","repos_url":"https://api.github.com/users/mowfask/repos","events_url":"https://api.github.com/users/mowfask/events{/privacy}","received_events_url":"https://api.github.com/users/mowfask/received_events","type":"User","site_admin":false},"body":"SSE-Optimierung des Jacobi-Schritts hat nicht so ganz geklappt, siehe commits a7257a260ebecefd26a4181c05feac25aacdbd01\r\nd433c0ad9d4c77b15ee983fe46240693e9052678","created_at":"2015-06-19T09:49:00Z","updated_at":"2015-07-16T15:22:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a8c9e19a50883c3e0e5c8d4454776b0c9983ffbc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4/commits","review_comments_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4/comments","review_comment_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues/4/comments","statuses_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/statuses/61466580faf1c903aae3a85e4347991fd970869b","head":{"label":"mowfask:master","ref":"master","sha":"61466580faf1c903aae3a85e4347991fd970869b","user":{"login":"mowfask","id":7459936,"avatar_url":"https://avatars.githubusercontent.com/u/7459936?v=3","gravatar_id":"","url":"https://api.github.com/users/mowfask","html_url":"https://github.com/mowfask","followers_url":"https://api.github.com/users/mowfask/followers","following_url":"https://api.github.com/users/mowfask/following{/other_user}","gists_url":"https://api.github.com/users/mowfask/gists{/gist_id}","starred_url":"https://api.github.com/users/mowfask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mowfask/subscriptions","organizations_url":"https://api.github.com/users/mowfask/orgs","repos_url":"https://api.github.com/users/mowfask/repos","events_url":"https://api.github.com/users/mowfask/events{/privacy}","received_events_url":"https://api.github.com/users/mowfask/received_events","type":"User","site_admin":false},"repo":{"id":37608572,"name":"gi4_uebung07","full_name":"mowfask/gi4_uebung07","owner":{"login":"mowfask","id":7459936,"avatar_url":"https://avatars.githubusercontent.com/u/7459936?v=3","gravatar_id":"","url":"https://api.github.com/users/mowfask","html_url":"https://github.com/mowfask","followers_url":"https://api.github.com/users/mowfask/followers","following_url":"https://api.github.com/users/mowfask/following{/other_user}","gists_url":"https://api.github.com/users/mowfask/gists{/gist_id}","starred_url":"https://api.github.com/users/mowfask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mowfask/subscriptions","organizations_url":"https://api.github.com/users/mowfask/orgs","repos_url":"https://api.github.com/users/mowfask/repos","events_url":"https://api.github.com/users/mowfask/events{/privacy}","received_events_url":"https://api.github.com/users/mowfask/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mowfask/gi4_uebung07","description":"GI4 - Übung 7","fork":true,"url":"https://api.github.com/repos/mowfask/gi4_uebung07","forks_url":"https://api.github.com/repos/mowfask/gi4_uebung07/forks","keys_url":"https://api.github.com/repos/mowfask/gi4_uebung07/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mowfask/gi4_uebung07/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mowfask/gi4_uebung07/teams","hooks_url":"https://api.github.com/repos/mowfask/gi4_uebung07/hooks","issue_events_url":"https://api.github.com/repos/mowfask/gi4_uebung07/issues/events{/number}","events_url":"https://api.github.com/repos/mowfask/gi4_uebung07/events","assignees_url":"https://api.github.com/repos/mowfask/gi4_uebung07/assignees{/user}","branches_url":"https://api.github.com/repos/mowfask/gi4_uebung07/branches{/branch}","tags_url":"https://api.github.com/repos/mowfask/gi4_uebung07/tags","blobs_url":"https://api.github.com/repos/mowfask/gi4_uebung07/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mowfask/gi4_uebung07/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mowfask/gi4_uebung07/git/refs{/sha}","trees_url":"https://api.github.com/repos/mowfask/gi4_uebung07/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mowfask/gi4_uebung07/statuses/{sha}","languages_url":"https://api.github.com/repos/mowfask/gi4_uebung07/languages","stargazers_url":"https://api.github.com/repos/mowfask/gi4_uebung07/stargazers","contributors_url":"https://api.github.com/repos/mowfask/gi4_uebung07/contributors","subscribers_url":"https://api.github.com/repos/mowfask/gi4_uebung07/subscribers","subscription_url":"https://api.github.com/repos/mowfask/gi4_uebung07/subscription","commits_url":"https://api.github.com/repos/mowfask/gi4_uebung07/commits{/sha}","git_commits_url":"https://api.github.com/repos/mowfask/gi4_uebung07/git/commits{/sha}","comments_url":"https://api.github.com/repos/mowfask/gi4_uebung07/comments{/number}","issue_comment_url":"https://api.github.com/repos/mowfask/gi4_uebung07/issues/comments{/number}","contents_url":"https://api.github.com/repos/mowfask/gi4_uebung07/contents/{+path}","compare_url":"https://api.github.com/repos/mowfask/gi4_uebung07/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mowfask/gi4_uebung07/merges","archive_url":"https://api.github.com/repos/mowfask/gi4_uebung07/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mowfask/gi4_uebung07/downloads","issues_url":"https://api.github.com/repos/mowfask/gi4_uebung07/issues{/number}","pulls_url":"https://api.github.com/repos/mowfask/gi4_uebung07/pulls{/number}","milestones_url":"https://api.github.com/repos/mowfask/gi4_uebung07/milestones{/number}","notifications_url":"https://api.github.com/repos/mowfask/gi4_uebung07/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mowfask/gi4_uebung07/labels{/name}","releases_url":"https://api.github.com/repos/mowfask/gi4_uebung07/releases{/id}","created_at":"2015-06-17T17:00:56Z","updated_at":"2015-06-17T17:00:57Z","pushed_at":"2015-06-19T09:46:47Z","git_url":"git://github.com/mowfask/gi4_uebung07.git","ssh_url":"git@github.com:mowfask/gi4_uebung07.git","clone_url":"https://github.com/mowfask/gi4_uebung07.git","svn_url":"https://github.com/mowfask/gi4_uebung07","homepage":"","size":94,"stargazers_count":0,"watchers_count":0,"language":"C","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":"RWTH-OS:master","ref":"master","sha":"5b5a174ede6ad1580c676402fcbe0d48c250626a","user":{"login":"RWTH-OS","id":6057191,"avatar_url":"https://avatars.githubusercontent.com/u/6057191?v=3","gravatar_id":"","url":"https://api.github.com/users/RWTH-OS","html_url":"https://github.com/RWTH-OS","followers_url":"https://api.github.com/users/RWTH-OS/followers","following_url":"https://api.github.com/users/RWTH-OS/following{/other_user}","gists_url":"https://api.github.com/users/RWTH-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RWTH-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RWTH-OS/subscriptions","organizations_url":"https://api.github.com/users/RWTH-OS/orgs","repos_url":"https://api.github.com/users/RWTH-OS/repos","events_url":"https://api.github.com/users/RWTH-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RWTH-OS/received_events","type":"Organization","site_admin":false},"repo":{"id":37377699,"name":"gi4_uebung07","full_name":"RWTH-OS/gi4_uebung07","owner":{"login":"RWTH-OS","id":6057191,"avatar_url":"https://avatars.githubusercontent.com/u/6057191?v=3","gravatar_id":"","url":"https://api.github.com/users/RWTH-OS","html_url":"https://github.com/RWTH-OS","followers_url":"https://api.github.com/users/RWTH-OS/followers","following_url":"https://api.github.com/users/RWTH-OS/following{/other_user}","gists_url":"https://api.github.com/users/RWTH-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RWTH-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RWTH-OS/subscriptions","organizations_url":"https://api.github.com/users/RWTH-OS/orgs","repos_url":"https://api.github.com/users/RWTH-OS/repos","events_url":"https://api.github.com/users/RWTH-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RWTH-OS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RWTH-OS/gi4_uebung07","description":"GI4 - Übung 7","fork":false,"url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07","forks_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/forks","keys_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/teams","hooks_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/hooks","issue_events_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues/events{/number}","events_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/events","assignees_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/assignees{/user}","branches_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/branches{/branch}","tags_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/tags","blobs_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/git/refs{/sha}","trees_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/statuses/{sha}","languages_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/languages","stargazers_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/stargazers","contributors_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/contributors","subscribers_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/subscribers","subscription_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/subscription","commits_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/commits{/sha}","git_commits_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/git/commits{/sha}","comments_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/comments{/number}","issue_comment_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues/comments{/number}","contents_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/contents/{+path}","compare_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/merges","archive_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/downloads","issues_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues{/number}","pulls_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls{/number}","milestones_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/milestones{/number}","notifications_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/labels{/name}","releases_url":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/releases{/id}","created_at":"2015-06-13T15:57:17Z","updated_at":"2015-06-13T16:07:35Z","pushed_at":"2015-06-21T06:54:22Z","git_url":"git://github.com/RWTH-OS/gi4_uebung07.git","ssh_url":"git@github.com:RWTH-OS/gi4_uebung07.git","clone_url":"https://github.com/RWTH-OS/gi4_uebung07.git","svn_url":"https://github.com/RWTH-OS/gi4_uebung07","homepage":"","size":238,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4"},"html":{"href":"https://github.com/RWTH-OS/gi4_uebung07/pull/4"},"issue":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues/4"},"comments":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/RWTH-OS/gi4_uebung07/statuses/61466580faf1c903aae3a85e4347991fd970869b"}}}}