標籤:
使用vs直接到setting裡面設定即可支援openmp了,然而我太懶了裝了個codeblocks with mingw版本
本來gcc4.4後就完全支援openmp了,結果codeblocks怎麼配置都提示-fopenmp這些找不到。
搞了一上午終於發現,雖然mingw支援openmp但是在codeblocks安裝過程中並不讓裝這些組件,需要自己裝個tdm-gcc with mingw,蛋疼╮(╯▽╰)╭
配置流程:
1)下載tdm-gcc,安裝的時候注意預設openmp支援是沒有勾選的,記得勾選起來,要麼安裝全部組件...
路徑的話安裝的時候會自己配置,沒有的話自己搞一下
2)安裝codeblocks(不用帶mingw了)
3)Settings->compiler裡設定codeblocks編譯器路徑
4)Setting->compiler->Compiler settings->other options裡輸入-fopenmp
Setting->compiler->linker settings->other linker options裡輸入-lgomp -lpthread
5)至此配置完畢_(:зゝ∠)_ 寫一下代碼試試看
#include "omp.h"#include <iostream>#include <time.h>void test(){ int a = 0; for (int i=0;i<100000000;i++) a++;}int main() { clock_t t1 = clock(); for (int i=0;i<8;i++) test(); clock_t t2 = clock(); std::cout<<"sequential time: "<<t2-t1<<std::endl; clock_t t3 = clock(); #pragma omp parallel for for (int i=0;i<8;i++) test(); clock_t t4 = clock(); std::cout<<"parallel time: "<<t4-t3<<std::endl; return 0; }
運行結果發現串列和並行已耗用時間還是有區別的!
還有一點是編譯時間候我是debug模式編譯的,用release模式編譯時間就全部都是0了(因為速度太快了....)
windows下codeblocks配置openmp