OpenMP在Windows下用VS使用
生活随笔
收集整理的這篇文章主要介紹了
OpenMP在Windows下用VS使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡述
直接新建一個項目來使用就好了。
- 在項目中需要把C++\語言中把對openMP的支持選擇是。
- 否則程序只會調用一個線程。
代碼
#include <iostream> #include <omp.h> using namespace std; #pragma warning(disable : 4996) void Hello(); int main(int argc, char **argv) {if (argc == 1) return 0;int thread_count = strtol(argv[1], NULL, 10); #pragma omp parallel num_threads (thread_count)Hello(); }void Hello() {int my_rank = omp_get_thread_num();int thread_count = omp_get_num_threads();char data[50];sprintf(data, "Hello from thread %d of %d\n", my_rank, thread_count);cout << data; }操作
- 在VS上先編譯
- 再用命令行來調用
效果如下:
總結
以上是生活随笔為你收集整理的OpenMP在Windows下用VS使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关系数据库设计【笔记】
- 下一篇: 常微分方程数值求解【python】