c - How assign task to individual thread using OpenMP? -
I am taking the array of 20. And OpenMP is used to specify 1 / 4th work for each of the four threads in order. And then what is wrong to store the results of the whole array of files?
In the first array, I am assigning the value i * j to each element, then multiply the matrix of 20 x 20.
# include & lt; Stdio.h & gt; #to & lt include, omp.h & gt; #include "head.h" int sum = 0; Int C [20] [20]; //#include<conio.h> Int main (zero) {int a [20] [20], b [20] [20], c [20] [20]; Int i, j, e; Constant amount = 0; File * FP; Unsigned long A, B, C, D; Int threadno; Fp = fopen ("m2.txt", "w"); // clrscr (); Printf ("\ n% d \ n", h [20] [20]); #pragma omp parallel share (A, B, C, D) {thread = omp_get_thread_num (); If (Threado == 0) for {for (i = 0; i & lt; 5; i ++) (j = 0; j & lt; 5; j ++) a [i] [j] = i * J; B [i] [j] = i j *; For (i = 0; i & lt; 5; i ++) for (j = 0; j and lt; 5; j ++) for (e = 0; e & lt; 5; e ++ ) Yoga + = A [i] [E] * B [E] [J]; C [i] [j] = sum; // fprintf (FP, "% d \ t", c [i] [ja]); }} If (thread == 1) {for (i = 5; i & lt; 10; i ++) for (j = 5; j & lt; 10; j ++) a [i] [j] = I * j; B [i] [j] = i j *; For (i = 5; i & lt; 10; i ++) (j = 5; j & lt; 10; j ++) {sum = 0; For (E = 5; E & lt; 10; e ++) Yoga + a = i [e] * b [e] [j]; C [i] [j] = sum; // fprintf (FP, "% d \ t", c [i] [ja]); }} If (thread == 2) {for (i = 10; i & lt; 15; i ++) for (j = 10; j & lt; 15; j ++) a [i] [j] = I * j; B [i] [j] = i j *; For (i = 10; i & lt; 15; i ++) for (j = 10; j & lt; 15; j ++) {for (e = 10; e & lt; 15; e ++ ) Yoga + = A [i] [E] * B] [J]; C [i] [j] = sum; // fprintf (FP, "% d \ t", c [i] [ja]); }} If (thread == 3) {for (i = 15; i & lt; 20; i ++) for (j = 15; j & lt; 20; j ++) a [i] [j] = I * j; B [i] [j] = i j *; For (i = 15; i & lt; 20; i ++) for (j = 15; j & lt; 20; j ++) {for (e = 15; e & lt; 20; e ++ ) Yoga + = A [i] [E] * B] [J]; C [i] [j] = sum; // fprintf (FP, "% d \ t", c [i] [ja]); }} For (i = 0; i & lt; 20; i ++) {for (j = 0; j & lt; 20; j ++) {fprintf (fp, "% d \ t", c [ I] [j]); }}} Fclose (fp); }
You have a bracket mismatch if you if (threadno == 0) after closing their parallel section after the section. In addition, at the end of your code you have an extra brace.
As Dave is mentioned, you are not even looking at some criterion for your statement. This is not the cause of the problem, but the result will not return the expected results as a result of your algorithm. (I = 0; i & lt; n; i ++) function (i) for
C
; In one loop
To execute the same operation, or if you want to include multiple actions for the loop
< Code> (i = 0; i & lt; n; i ++) {function (i); Function2 (i); Function3 (i); }
Comments
Post a Comment