我试图使用以下代码在C程序中获得并行效果:
#include<iostream> using namespace std; int main() { #pragma omp parallel sections { #pragma omp section { cout<<"Hello"; cout<<" "; cout<<"World"; cout<<endl; } #pragma omp section { cout<<"H"; cout<<"ello"; cout<<" W"; cout<<"orld"; cout<<endl; } #pragma omp section cout<<"Hello"<<" "<<"World"<<endl; #pragma omp section { cout<<"Hello "; cout<<"World"<<endl; } } return 0; }
我曾多次运行这个程序.由于并行性,我期待交错输出.
但是,每次运行此程序时,输出为:
Hello World Hello World Hello World Hello World
难道我做错了什么?
谢谢