Today, using OpenMP, I am very fond of OpenMP's fool mode, importing a header file
Direct parallel for
#include <iostream>#include <omp.h>using namespace STD;intMain () {//cout<< "Thread num = =" <<omp_get_thread_num () <<endl; #pragma omp parallel for num_threads (4) for(intI=0;i<4; i++) { for(intj=0;j<4; j + +) {printf("(%d,%d)", i,j);cout<<"Thread num = ="<<omp_get_thread_num () <<endl; } }}
You can see that the for in this compiler directive is only useful for the next for this sentence
With curly braces
#include <iostream>#include <omp.h>using namespace STD;intMain () {//cout<< "Thread num = =" <<omp_get_thread_num () <<endl; #pragma omp parallel num_threads (4){ for(intI=0;i<4; i++) { for(intj=0;j<4; j + +) {printf("(%d,%d)", i,j);cout<<"Thread num = ="<<omp_get_thread_num () <<endl; } } }}
It can be seen that all 4*4 cycles are completely disrupted.
over~~~~~~
OpenMP #pragma omp parallel for parallelization of small probe