windows下codeblocks配置openmp

來源:互聯網
上載者:User

標籤:

使用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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.