[問題] 除了OpenMP外,有沒有更好得MP可用?

看板C_and_CPP作者 (蘇打)時間16年前 (2009/10/24 16:01), 編輯推噓6(606)
留言12則, 6人參與, 最新討論串1/3 (看更多)
遇到的問題: 因為我的程式需要大量的運算,剛好系統擁有八核心 想要透過多核心處理機制 之前使用OpenMP,但是OpenMP不支援iterator 想請問是否有其他類似OpenMP的函式庫可用 (希望能支援iterator的@~@) 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux) g++ 有問題的code: (請善用置底文標色功能) 使用STL+iterator,接著加上平行處理就會錯 (Compile無法通過,因OpenMP僅能處理index為int or long) 範例: #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { srand( time(NULL) ); vector<int> tmp; vector<int>::iterator it; unsigned int i; for( i = 0 ; i < 20 ; ++i ) tmp.push_back( rand() % 100); for( it = tmp.begin() ; it != tmp.end() ; ++it ) { cout<<(*it)<<endl; } getchar(); #pragma omp parallel for for( it = tmp.begin() ; it != tmp.end() ; ++it ) { cout<<(*it)<<endl; } return 0; } 編譯指令 g++ -fopenmp aaa.cpp 錯誤 aaa.cpp: In function 'int main()': aaa.cpp:22: error: invalid type for iteration variable 'it' aaa.cpp:22: error: invalid controlling predicate aaa.cpp:22: error: invalid increment expression 補充說明: -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.152.129

10/24 16:55, , 1F
VC++2008 OK!
10/24 16:55, 1F

10/24 17:26, , 2F
問題是我的程式要在linux上跑QQ
10/24 17:26, 2F

10/24 18:06, , 3F
gcc版本?
10/24 18:06, 3F

10/24 19:00, , 4F
gcc-4.1.2 Centos 5.3 測試沒問題
10/24 19:00, 4F

10/24 19:01, , 5F
有可能是gcc版本太舊...?
10/24 19:01, 5F

10/24 20:01, , 6F
我的gcc也是4.1.2耶..系統是scientific linux 5.1
10/24 20:01, 6F

10/24 20:02, , 7F
所以大家用openmp+iterator都正常嗎?為什麼我看說明好像
10/24 20:02, 7F

10/24 20:02, , 8F
寫openmp不支援iterator?
10/24 20:02, 8F

10/24 20:29, , 9F
sorry 沒看到fopenmp參數,測試好像不行
10/24 20:29, 9F

10/25 00:17, , 10F
openmp的迴圈中的index一定要是整數且是可知的
10/25 00:17, 10F

10/25 20:57, , 11F
gcc 不是從 4.2 開始才支援 fopenmp 嗎 ?
10/25 20:57, 11F

10/25 20:58, , 12F
如果要用 openmp 3.0 的話, 建議用更高版本的 gcc
10/25 20:58, 12F
文章代碼(AID): #1AuhHTi8 (C_and_CPP)
文章代碼(AID): #1AuhHTi8 (C_and_CPP)