我正在尝试编写一个 MPI 应用程序来通过计算机集群加速数学算法。但在此之前我正在做某种基准测试。但最初的结果并不像预期的那么好。
测试应用程序在 4 核时具有线性加速,但 5,6 核并未加速应用程序。我正在使用 Odroid N2 平台进行测试。它有 6 个核心。 Nproc 表示有 6 个核心可用。
我是否缺少某种配置?或者我的代码准备得不够充分(它基于 mpi 的基本示例之一)?
是否有需要考虑的响应时间或同步时间?
以下是我基于 MPI 的应用程序的一些措施。我测量了一个函数的总计算时间。
- 1核0.838052秒
- 2核0.438483秒
- 3核0.405501秒
- 4核0.416391秒
- 5核0.514472秒
- 6核0.435128秒
- 12 核(3 个 N2 板中的 4 个核)0.06867 秒
- 18 核(3 个 N2 板中的 6 个核)0.152759 秒
我用 4 核的树莓派 pi4 做了一个基准测试:
- 1 核 1.51 秒
- 2核0.75秒
- 3核0.69秒
- 4核0.67秒
这是我的基准应用程序:
int MyFun(int *array, int num_elements, int j)
{
int result_overall = 0;
for (int i = 0; i < num_elements; i++)
{
result_overall += array[i] / 1000;
}
return result_overall;
}
int compute_sum(int* sub_sums,int num_of_cpu)
{
int sum = 0;
for(int i = 0; i<num_of_cpu; i++)
{
sum += sub_sums[i];
}
return sum;
}
//measuring performance from main(): num_elements_per_proc is equal to 604800
if (world_rank == 0)
{
startTime = std::chrono::high_resolution_clock::now();
}
// Compute the sum of your subset
int sub_sum = 0;
for(int j=0;j<1000;j++)
{
sub_sum += MyFun(sub_intArray, num_elements_per_proc, world_rank);
}
MPI_Allgather(&sub_sum, 1, MPI_INT, sub_sums, 1, MPI_INT, MPI_COMM_WORLD);
int total_sum = compute_sum(sub_sums, num_of_cpu);
if (world_rank == 0)
{
elapsedTime = std::chrono::high_resolution_clock::now() - startTime;
timer = elapsedTime.count();
}
我使用 -O3 优化级别构建它。
UPDATE:新措施:
- 60480个样本,MyFun调用100000次:
1.47 -> 0.74 -> 0.48 -> 0.36
- 6048个样本,MyFun调用1000000次:
1.43 -> 0.7 -> 0.47 -> 0.35
- 6048个样本,MyFun调用10000000次:
14.43 -> 7.08 -> 4.72 -> 3.59
UPDATE2:
By the way when I list the CPU info in linux I got this:
这是正常的吗?
四核 A73 核心不存在。它说有两个3-3芯的插座。
And here is the CPU utilization with sar:
Seems like all of the cores are utilized.
I create some plots from speedup:
看起来 float 计算而不是 int 计算有一点帮助,但核心 5-6 没有多大帮助。我认为内存带宽还可以。在little.BIG架构中平等利用所有CPU时,这是正常行为吗?