在集群上重用 FFTW 智慧

Reusing FFTW wisdom on clusters

我 运行 在使用多个节点的集群上使用分布式 MPI 程序,我在其中使用一个 运行 下一个 FFTW. To save time I reuse wisdom 的 MPI FFT。为了产生这种智慧,FFTW 使用许多不同的算法进行实验,并且不针对给定的问题。我担心因为我在集群上工作,所以存储为一组 CPUs/nodes 的智慧的最佳解决方案可能不是执行相同任务的另一组 CPUs/nodes 的最佳解决方案,因此我不应该重用智慧,除非我运行宁在与收集智慧的 运行 完全相同的 CPUs/nodes 上。

这是正确的,还是智慧在某种程度上完全不关心生成它的物理硬件?

如果您的集群是同类集群,则保存的 fftw 计划可能有意义,尽管进程连接的方式可能会影响 mpi-related 操作的最佳计划。但是,如果您的集群不是同质的,保存 fftw 计划可能不是最优的,并且与负载平衡相关的问题可能很难解决。

查看 fftw 和 fftw_mpi 为 2D c2c 转换生成的智慧文件,我可以看到可能与需要 mpi 通信的转置等阶段相关的其他行,例如:

(fftw_mpi_transpose_pairwise_register 0 #x1040 #x1040 #x0 #x394c59f5 #xf7d5729e #xe8cf4383 #xce624769)

确实,有不同的算法来转置 2D(或 3D)数组:in the folder mpi of the source of fftw, files transpose-pairwise.c, transpose-alltoall.c and transpose-recurse.c implement these algorithms. As flags FFTW_MEASURE or FFTW_EXHAUSTIVE are set, these algorithms are run to select the fastest, as stated here。结果可能取决于进程网络的拓扑结构(每个节点上有多少个进程?这些节点如何连接?)。 如果最佳计划取决于进程所在的位置 运行 和网络拓扑,使用 wisdom 实用程序将不是决定性的。 否则,使用 wisdom 功能可以节省一些时间随着计划的建立。

要测试最优计划是否改变,您可以执行几次运行并将生成的计划保存在文件中:再现性测试!

int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
fftw_mpi_gather_wisdom(MPI_COMM_WORLD);
if (rank == 0) fftw_export_wisdom_to_filename("wisdommpi.txt");

/* save the plan on each process ! Depending on the file system of the cluster, performing communications can be required */
char filename[42];
sprintf(filename, "wisdom%d.txt",rank);
fftw_export_wisdom_to_filename(filename);

最后,为了比较生成的 wisdom 文件,在 bash 脚本中尝试:

for filename in wis*.txt; do
  for filename2 in wis*.txt; do
    echo "."
    if grep -Fqvf "$filename" "$filename2"; then
        echo "$filename"
        echo "$filename2"
            echo $"There are lines in file1 that don’t occur in file2."
    fi
  done
done

此脚本检查文件中的所有行是否也存在于其他文件中,紧随 Check if all lines from one file are present somewhere in another file 在我的个人计算机上,使用 mpirun -np 4 main,除了行的排列外,所有智慧文件都是相同的。

如果文件与另一个文件不同 运行,这可能是由于进程之间的通信模式...或每个进程的 dft 顺序执行。上面的这段代码保存了每个进程的最优计划。如果与顺序操作相关的行,其中没有fftw_mpi,例如:

  (fftw_codelet_n1fv_10_sse2 0 #x1440 #x1440 #x0 #xa9be7eee #x53354c26 #xc32b0044 #xb92f3bfd)

变得不同,这是最佳顺序算法从一个过程变为另一个过程的线索。 在这种情况下,顺序操作的挂钟时间也可能因进程而异。因此,检查进程之间的负载平衡可能具有指导意义。 正如 FFTW 文档中关于 load balance:

Load balancing is especially difficult when you are parallelizing over heterogeneous machines; ... FFTW does not deal with this problem, however—it assumes that your processes run on hardware of comparable speed, and that the goal is therefore to divide the problem as equally as possible.

这个假设和fftw_mpi_gather_wisdom();

执行的操作是一致的

(If the plans created for the same problem by different processes are not the same, fftw_mpi_gather_wisdom will arbitrarily choose one of the plans.) Both of these functions may result in suboptimal plans for different processes if the processes are running on non-identical hardware...

2D 和 3D fft 中的转置操作需要大量通信:实现之一是调用 MPI_Alltoall,几乎涉及整个数组。因此,节点之间的良好连接(infiniband...)可以证明是有用的。

如果您发现一个 运行 不同的最佳计划,请告诉我们这些计划有何不同!