我正在在 CPU 和 GPU 上实现不同的算法。令我感到奇怪的是,一个非常原始的示例(顺序 - 又名 1 个线程 - 创建具有 100*1024*1024 元素的数组的直方图)在服务器 CPU 上花费了 200% - 300% 的时间(诚然,时钟频率略低并且比在工作站 CPU 上更早一代)。两台机器都使用 DDR3 内存,工作站上的 16GB 双通道 (FSB:DRAM 1:6) 和服务器上的 512GB 四通道 (FSB:DRAM 1:12),均以 800Mhz DRAM 时钟速率运行。
在我的工作站上,直方图计算需要 < 100 毫秒(平均 90 毫秒),而在服务器上平均需要300 毫秒,而在零星的情况下,它只需要大约150毫秒毫秒。
我在两台机器上使用相同的版本(任何 CPU,更喜欢 32 位,发布版本)。
在另一个问题上,为什么纯 64 位构建在两台机器上都慢了至少 25%?
public static void Main(string[] args) {
// the array size. say its 100 * 1024 ^ 2, aka 100 Megapixels
const int Size = 100 * 1024 * 1024;
// define a buffer to hold the random data
var buffer = new byte[Size];
// fill the buffer with random bytes
var rndXorshift = new RndXorshift();
rndXorshift.NextBytes(buffer);
// start a stopwatch to time the histogram creation
var stopWatch = new Stopwatch();
stopWatch.Start();
// declare a variable for the histogram
var histo = new uint[256];
// for every element of the array ...
for (int i = 0; i < Size; i++) {
// increment the histogram at the position
// of the current array value
histo[buffer[i]]++;
}
// get the histogram count. must be equal
// to the total elements of the array
long histoCount = 0;
for (int i = 0; i < 256; i++) {
histoCount += histo[i];
}
// stop the stopwatch
stopWatch.Stop();
var et1 = stopWatch.ElapsedMilliseconds;
// output the results
Console.WriteLine("Histogram Sum: {0}", histoCount);
Console.WriteLine("Elapsed Time1: {0}ms", et1);
Console.ReadLine();
}
服务器 CPU:
工作站 CPU: