OpenMPでのbreak
OpenMPループ内でのbreakは許可されていないが、自分でループ範囲を決めてフラグを立てることで同じことが可能。
// from http://hibari.2ch.net/test/read.cgi/tech/1102483474/304 #include <stdio.h> #include <omp.h> #define FIN 100 #define TARGET 70 int main(){ int i, found=0, cnt=0; #pragma omp parallel reduction(+:cnt) { int t, n, is, ie; t = omp_get_num_threads(); n = (FIN + t - 1) / t; is = n * omp_get_thread_num(); ie = (is + n < FIN) ? is + n : FIN; printf("%d: %d-%d\n", omp_get_thread_num(), is, ie); for(i = is; !found && i < ie; i++){ printf("%d: %d\n", omp_get_thread_num(), i); cnt++; if (i == TARGET){ found = 1; #pragma omp flush(found) printf("%d: found\n", omp_get_thread_num()); } } printf("%d: %d loops\n", omp_get_thread_num(), cnt); } printf("total %d loops\n",cnt); return 0; }