visual studio需要在properties -> C/C++ -> Language -> OpenMP Support设置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <omp.h> #include "iostream" using namespace std; int _tmain(int argc, _TCHAR* argv[]){ omp_set_num_threads(4); //my workstation has 4 cores #pragma omp parallel for for (int i = 0; i < 20; i++){ //cout << "i=" << i << endl; printf("i = %d", i); cout << endl; } system("pause"); return 0; } |