I do not understand, where do I get this wrong if openmp is compiled without support, code Works correctly But the wrong visibility is obtained with open MP variables.
I had the following intention that each thread has its own maximum advertisement, in which the local maximum gets. Then a global maximum is found in an important section.
#include & lt; Iostream & gt; # Include & lt; Vector & gt; Typedef std :: vector & lt; Long & gt; Vector; Longer Maximum (Cunt Vector & A, Cunt Vector & B) {Long Max = 0; #pragma omp parallel {long max_private = 0; #pragma omp single {for (vector :: const_iterator a_it = a.begin (); a_it! = A.end (); ++ a_it} {#pragma omp task {for (vector :: const_iterator b_it = b.begin ( ); B_it! = B.and (); ++ b_it) {if (* a_it + * b_it> max_private) {max_private = * a_it + * b_it; }}}}} #prima ompi key {std :: cout & lt; & Lt; Maximum_private & lt; & Lt; Std :: endl; If (max_private & gt; max) {max = max_private; }}} Return max; } Int main (int argc, char * argv []) {vector a (100000); Vector b (10000); For (long I = 0; i I do not want to use parallel because later I am going to use the data structures that do not support random access etres.
I G ++ - 4.4 Compiler.
A detailed answer was found on the OpenMP Forum.
Max_private had to create threadprivate.
Comments
Post a Comment