#include "stdafx.h"
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
#pragma omp parallel num_threads(4)
{
int i = omp_get_thread_num();
printf_s("Hello from thread %d\n", i);
}
return 0;
}
// omp_parallel.cpp
// compile with: /openmp
执行结果,3次各不相同
Hello from thread 0
Hello from thread 1
Hello from thread 2
Hello from thread 3
D:\Documents and Set
Hello from thread 2
Hello from thread 0
Hello from thread 1
Hello from thread 3
D:\Documents and Set
Hello from thread 0
Hello from thread 3
Hello from thread 1
Hello from thread 2