parallel processing - fork-join algorithms with ompss -
openmp/ompss allows define tasks specific inputs , outputs dependencies among different tasks can defined.
most of examples feature different functions tasks connected each other via dependencies. standard parallel for-based program? possible define dependencies i.e. among iterations of consecutive 'parallel for' regions?
you don't need functions define dependencies.
let's take example non-commutative operation such concatenation, here inout
dependency make sure tasks executed in order.
char buf_n[11] = {0}, buf_l[11] = {0}, buf_u[11] = {0}; #pragma omp parallel { #pragma omp single { int i; (i=0; < 10; i++) { #pragma omp task depend(inout:buf_n) firstprivate(i) { char add[] = {'0' + i}; strncat(buf_n, add, 1); } #pragma omp task depend(inout:buf_l) firstprivate(i) { char add[] = {'a' + i}; strncat(buf_l, add, 1); } #pragma omp task depend(inout:buf_u) firstprivate(i) { char add[] = {'a' + i}; strncat(buf_u, add, 1); } } #pragma omp task depend(in:buf_n) { printf("buf (numbers) %s\n", buf_n); } #pragma omp task depend(in:buf_l) { printf("buf (lowercase) %s\n", buf_l); } #pragma omp task depend(in:buf_u) { printf("buf (uppercase) %s\n", buf_u); } } }
this return like:
buf (lowercase) abcdefghij buf (uppercase) abcdefghij buf (numbers) 0123456789
the order of lines may change, concatenations happen in order (i.e. letters , numbers in right order).
Comments
Post a Comment