As written the loop cannot trivially be parallelised with OpenMP because the test-expr in the loop (i.e. (i<n) & !flag) does not conform with the OpenMP restrictions :-
test-expr One of the following: var relational-op ub ub relational-op var relational-op One of the following: <, <=, >, >=, !=
(OpenMP standard). At a semantic level this is because the test on flag prevents the loop iteration count from being determinable at entry to the loop, which is what OpenMP requires.
In recent OpenMP standards there is a cancel construct which could be used here, something like (untested, uncompiled code)
bool flag = false; #pragma omp parallel for for(int i=0;(i<n);i++){ a[i] = 2.3 *i; if (a[i]<b[i]) { #pragma omp atomic write flag = true; } #pragma omp cancel for if (flag) }
However it seems unlikely that a loop with this little work in it will be profitable for parallelisation in a real code (rather than an exam question).
flag. Regardless, see: Loop Parallelism.