/*
编译器编译指令
MSVC :cl /EHsc /std:c++latest /O2 parallel_sort.cpp /Femo.exe
Intel C++ :icl /EHsc /std:c++latest /O2 parallel_sort.cpp /Feio.exe
GNU g++ :g++ -std=c++2a -fopenmp -D_GLIBCXX_PARALLEL -O3 parallel_sort.cpp -o go.exe
clang++ :clang++ -std=c++2a -O3 parallel_sort.cpp -o co.exe
*/
一、下载Visual Studio 2022 社区版本
地址:
二、下载MSYS2
地址:https://www.msys2.org/MSYS2Software Distribution and Building Platform for Windowshttps://www.msys2.org/
下载完成之后,打开MSYS2 MINGW64。
1、运行指令 panman -Syu
2、运行指令安装gcc
pacman -S mingw-w64-x86_64-gcc base-devel
3、运行指令安装clang
pacman -S mingw-w64-x86_64-clang base-devel
4、确定系统是否安装tbb
pacman -Ss tbb
5、安装tbb
pacman -S mingw-w64-x86_64-tbb
6、确定系统是否安装gmp
pacman -Ss gmp
7、安装gmp
pacman -S mingw-w64-x86_64-gmp
三、下载Visual Studio Code
地址:https://code.visualstudio.com/
四、下载C++ Library Extensions
地址:
四、下载Intel oneAPI Threading Building Blocks Alone for use with MSVC++
1、下载
安装之后将其include文件添加到系统环境变量中。
2、配置到MSVC++
在桌面上新建msvc-vars.bat文件,其内容设置为
@echo off
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
call "C:\Program Files (x86)\Intel\oneAPI\tbb\2021.8.0\env\vars.bat" intel64 vs2019
echo For Microsoft Visual C++ Compiler
设置完成之后,将smvc-vars.bat文件拷贝到C:/Windows/目录下
在桌面上复制一份vs2022的 x64 Native Tools Command Prompt for VS 2022的快捷方式,将其重命名为x64 MSVC,右键,选择属性,并将其目标和起始位置设置如下:
起始位置:表示运行x64 MSVC,控制台的起始位置。
五、下载Intel oneAPI Threading Building Blocks Alone for use with GNU g++ and clang
1、打开MSYS2 MINGW64,安装tbb
pacman -S mingw-w64-x86_64-tbb
pacman -S mingw-w64-clang-x86_64-tbb
2、配置到GNU clang
在桌面上新建gnu-vars.bat文件,其内容设置为
@echo off
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
set PATH=%GNU_PATH%;%PATH%
echo For GNU g++ and LLVM clang++
设置完成之后,将gnu-vars.bat文件拷贝到C:/Windows/目录下
在系统环境中添加新的变量,
GUN_PATH = C:\DevSoft\msys64\bin;C:\DevSoft\msys64\mingw64\bin;
CPLUS_INCLUDE_PATH = C:\DevSoft\CppExtension\include;
在桌面上复制一份vs2022的 x64 Native Tools Command Prompt for VS 2022的快捷方式,将其重命名为x64 GNU CLANG,右键,选择属性,并将其目标和起始位置设置如下:
起始位置:表示运行x64 GNU CLANG,控制台的起始位置。
#include <tbb/tbb.h>
#include <iostream>
// cl /EHsc /std:c++17 hello.cpp tbb12.lib /Fe: m.exe
// clang++ -std=c++17 hello.cpp -ltbb12 -o c.exe
// g++ -std=c++17 hello.cpp -ltbb12 -o g.exe
int main()
{
auto task1 = [](){ std::cout<< "Hello, World 1!" << std::endl; };
auto task2 = [](){ std::cout<< "Hello, World 2!" << std::endl; };
tbb::parallel_invoke(task1, task2);
}