To set this compiler option in the Visual Studio development environment
-
Open the project's Property Pages(属性页) dialog box. For details, see How to: Open Project Property Pages.
-
Expand the Configuration Properties(配置属性) node.
-
Expand the C/C++ node.
-
Select the Language(语言) property page.
-
Modify the OpenMP Support(OpenMP支持) property.
来自: http://msdn.microsoft.com/en-us/library/fw509c3b.aspx
简单实例:
#include "stdafx.h"
#include "omp.h"
int _tmain(int argc, _TCHAR* argv[])
{
#pragma omp parallel num_threads(4)
{
_tprintf(_T("Hello, World! ThreadId=%d\n"),omp_get_thread_num());
}
return 0;
}
运行结果: