作者DRLai (苏打)
看板C_and_CPP
标题[问题] 除了OpenMP外,有没有更好得MPI可用?
时间Sat Oct 24 16:01:30 2009
遇到的问题:
因为我的程式需要大量的运算,刚好系统拥有八核心
想要透过多核心处理机制
之前使用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
1F:推 chrisdar:VC++2008 OK! 10/24 16:55
2F:→ DRLai:问题是我的程式要在linux上跑QQ 10/24 17:26
3F:推 legendmtg:gcc版本? 10/24 18:06
4F:推 godman362:gcc-4.1.2 Centos 5.3 测试没问题 10/24 19:00
5F:→ godman362:有可能是gcc版本太旧...? 10/24 19:01
6F:→ DRLai:我的gcc也是4.1.2耶..系统是scientific linux 5.1 10/24 20:01
7F:→ DRLai:所以大家用openmp+iterator都正常吗?为什麽我看说明好像 10/24 20:02
8F:→ DRLai:写openmp不支援iterator? 10/24 20:02
9F:推 godman362:sorry 没看到fopenmp参数,测试好像不行 10/24 20:29
10F:推 stupidbear:openmp的回圈中的index一定要是整数且是可知的 10/25 00:17
11F:推 CriLit:gcc 不是从 4.2 开始才支援 fopenmp 吗 ? 10/25 20:57
12F:→ CriLit:如果要用 openmp 3.0 的话, 建议用更高版本的 gcc 10/25 20:58