原子交换排序算法如何在 MultiGPU 中实现?有参考资料吗??
问问题
42 次
1 回答
0
如果您指出可以使用的算法作为帮助回答这个问题的指南,那将会有所帮助。
所以,我从:http ://www.codingunit.com/exchange-sort-algorithm 中提取了一个算法
这是基本算法:
int main(void)
{
int array[5]; // An array of integers.
int length = 5; // Lenght of the array.
int i, j;
int temp;
//Some input
for (i = 0; i < 5; i++)
{
cout << "Enter a number: ";
cin >> array[i];
}
//Algorithm
for(i = 0; i < (length -1); i++)
{
for (j=(i + 1); j < length; j++)
{
if (array[i] < array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
//Some output
for (i = 0; i < 5; i++)
{
cout << array[i] << endl;
}
}
您可能想查看此页面以获取一些可能有帮助的源代码:
http://www.bealto.com/gpu-sorting.html
但是,如果您使用 OpenCL 和上面的等式,您可能需要执行以下操作:
打开到每张卡的连接。
然后,在他们有外循环的地方,将其中的每一个发送到每张卡上,也许以循环方式发送。
然后您需要在一个 GPU 上进行最终排序才能完成,但您可能希望使用不同的算法,因为该算法最适合单线程 CPU。
于 2014-04-24T02:23:34.490 回答