[問題] 除了OpenMP外,有沒有更好得MP可用?
遇到的問題:
因為我的程式需要大量的運算,剛好系統擁有八核心
想要透過多核心處理機制
之前使用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
10/24 16:55, 1F
→
10/24 17:26, , 2F
10/24 17:26, 2F
推
10/24 18:06, , 3F
10/24 18:06, 3F
推
10/24 19:00, , 4F
10/24 19:00, 4F
→
10/24 19:01, , 5F
10/24 19:01, 5F
→
10/24 20:01, , 6F
10/24 20:01, 6F
→
10/24 20:02, , 7F
10/24 20:02, 7F
→
10/24 20:02, , 8F
10/24 20:02, 8F
推
10/24 20:29, , 9F
10/24 20:29, 9F
推
10/25 00:17, , 10F
10/25 00:17, 10F
推
10/25 20:57, , 11F
10/25 20:57, 11F
→
10/25 20:58, , 12F
10/25 20:58, 12F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):