VisualStudio2022下配置 OpenMP多線程編程環(huán)境與運行
一、創(chuàng)建項目時選擇“創(chuàng)建新項目 -> 空項目 -> 下一步 -> 創(chuàng)建”
二、右鍵“源文件 -> 添加 -> 新建項 -> 添加”
三、配置
1. 測試程序:
#include "stdafx.h" #include "omp.h" int _tmain(int argc, _TCHAR* argv[]) { printf("Hello from serial.\n"); printf("Thread number = %d\n", omp_get_thread_num()); //串行執(zhí)行 #pragma omp parallel num_threads(4) //開始并行執(zhí)行 { printf("Hello from parallel. Thread number = %d\n", omp_get_thread_num()); } printf("Hello from serial again.\n"); return 0; }
最開始的時候錯誤很多:
2.將 “ include "stdafx.h" ” 刪掉,添加 “ include <tchar.h> ”和“#include<stdio.h>”
#include<tchar.h> #include<stdio.h>
結(jié)果: 但這時還不能正常并行處理程序
更改后代碼:
//#include "stdafx.h" #include<tchar.h> #include<stdio.h> #include <omp.h> int _tmain(int argc, _TCHAR* argv[]) { printf("Hello from serial.\n"); printf("Thread number = %d\n", omp_get_thread_num()); //串行執(zhí)行 #pragma omp parallel num_threads(4) //開始并行執(zhí)行 { printf("Hello from parallel. Thread number = %d\n", omp_get_thread_num()); } printf("Hello from serial again.\n"); return 0; }
3.右擊 “項目” -> 點擊屬性,按圖在“所有配置”和“所有平臺”下,找到OpenMP按鈕,更改為“是”,點擊確定。
四、重新運行,在步驟三全部完成后重新點擊“ 開始執(zhí)行(不調(diào)試) ”,此時程序成功實現(xiàn)并行處理。
到此這篇關(guān)于VisualStudio2022下配置 OpenMP多線程編程環(huán)境與運行的文章就介紹到這了,更多相關(guān)VS2022配置OpenMP環(huán)境內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++實現(xiàn)LeetCode(186.翻轉(zhuǎn)字符串中的單詞之二)
這篇文章主要介紹了C++實現(xiàn)LeetCode(186.翻轉(zhuǎn)字符串中的單詞之二),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08c語言中回調(diào)函數(shù)的使用以及實際作用詳析
回調(diào)函數(shù)就是一個通過函數(shù)指針調(diào)用的函數(shù),如果你把函數(shù)的指針(地址)作為參數(shù)傳遞給另一個函數(shù),當(dāng)這個指針被用來調(diào)用其所指向的函數(shù)時,我們就說這是回調(diào)函數(shù),這篇文章主要給大家介紹了關(guān)于c語言中回調(diào)函數(shù)的使用以及實際作用的相關(guān)資料,需要的朋友可以參考下2021-07-07