我建立一个程序,找出恒科普兰 - 鄂尔多斯子在C++ 11提高使用OpenMP {科普兰 - 鄂尔多斯常数冲
Copeland-Erdős constant是为了所有的素数串一串的串行建筑: 2,3,5,7,11,13 ...→23571113 ...
我需要检查给定的子字符串是否在该常量内,并以快速方式执行。
到目前为止,我已经使用Miller Rabin函数构建了一个串行程序,用于检查计数器生成的数字是否为素数并添加到主字符串(常量)。要找到8th Marsene Number(2 -1)该程序花费8分钟。
然后,我使用find来检查给定的子字符串是否在常量和它开始的位置。
问题:
我用串行编程。我从0开始,检查是否所有数字都是主要的添加或不添加......我不知道是否有其他方式来做到这一点。子字符串可以是素数的混合。例如:1 .. {1131} .. 7(11,13,17的子串)
您是否有任何提议通过使用OpenMP来提高程序执行时间?
我想计算“人类时间”中的第9个梅赛德数。我花了一天多的时间,但没有找到它(好吧,到达号码)。
gcc version 4.4.7 20120313
Main.cpp的
while (found == -1 && lastNumber < LIMIT) //while not found & not pass our limit
{
//I generate at least a string with double size of the input (llargada)
for (lastNumber; primers.length() <= 2*llargada; lastNumber++){
if (is_prime_mr(lastNumber))
primers += to_string(lastNumber); //if prime, we add it to the main string
}
found = primers.find(sequencia); //search substring and keep position
if (found == string::npos){ //if not found
indexOfZero += primers.length()/2; //keep IndexOfZero, the position of string in global constant
primers.erase(0,primers.length()/2); //delete first middle part of calculated string
}
}
if (found != -1){
cout << "FOUNDED!" << endl;
cout << "POS: " << indexOfZero << " + " << found << " = " << indexOfZero+found << endl;} //that give us the real position of the substring in the main string
//although we only spend 2*inputString.size() memory
else
cout << "NOT FOUND" << endl;
首先优化你的串行代码,然后进行并行化。 – bolov
我投票结束这个题目,因为它属于 Computational Science http://scicomp.stackexchange.com/ – Gilles