我有以下用php编写的代码,并且一直在阅读Cuda以利用我的旧GeForce8800 Ultra的GPU处理能力。如何将此嵌套组合测试转换为Cuda并行处理代码(如果可能的话……)?2d阵列的总组合:$a、$b、$c、$d、$e迅速上升到数万亿...
foreach($a as $aVal){
foreach($b as $bVal){
foreach($c as $cVal){
foreach($d as $dVal){
foreach($e as $eVal){
$addSum = $aVal[0]+$bVal[0]+$cVal[0]+$dVal[0]+$eVal[0];
$capSum = $aVal[1]+$bVal[1]+$cVal[1]+$dVal[1]+$eVal[1];
if($capSum <= CAP_LIMIT){
$tempArr = array("a" => $aVal[2],"b" => $aVal[2],"c" => $aVal[2],
"d" => $aVal[2],"e" => $aVal[2],"addTotal" => $addSum,"capTotal" => $capSum);
array_push($topCombinations, $tempArr);
if(count($topCombinations) > 1000){
$topCombinations = $ca->arraySortedDescend($topCombinations);
array_splice($topCombinations, 900);
}
}
}
}
}
}
}发布于 2012-02-23 13:53:47
这是一个非常开放的问题。它需要语言之间的转换,以及设计一个并行算法。我不会涉及太多细节,但简而言之:
如何将其并行化取决于数组的大小($a - $e)。如果它们足够大,您可以在网格中的线程中只并行外部的一个或两个循环,并按顺序执行内部循环。如果它们不是超大的,您可能希望展平2-3个外部循环,或者可能使用CUDA中的二维或三维线程块和栅格来实现它们。
https://stackoverflow.com/questions/9125072
复制相似问题