【发布时间】:2012-02-25 20:37:55
【问题描述】:
我有以下用 php 编写的代码,并且一直在阅读 Cuda 以利用我的旧 Geforce 8800 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);
}
}
}
}
}
}
}
【问题讨论】:
-
你能从高层次上解释一下这段代码计算了什么吗?
-
我有一个预算 (CAP_LIMIT) 并且我的 2d 数组 ($a-$e) 中的每个元素都有一个关联的值 (例如 aVal[0]) 我想彻底测试每个组合这 5 个数组找到适合我给定预算“CAP_LIMIT”的最佳值($addSum)
-
我对php不熟悉。在 php 中,二维数组是像标量矩阵,还是更像是对列表?您的代码建议使用后者。
标签: php cuda parallel-processing combinations pycuda