【问题标题】:MPI_Wtime timer runs about 2 times faster in OpenMPI 2.0.2MPI_Wtime 计时器在 OpenMPI 2.0.2 中运行速度大约快 2 倍
【发布时间】:2019-09-11 07:06:49
【问题描述】:

在将 OpenMPI 从 1.8.4 更新到 2.0.2 后,我使用 MPI_Wtime() 进行了错误的时间测量。在 1.8.4 版本中,结果与 omp_get_wtime() 计时器返回的结果相同,现在 MPI_Wtime 的运行速度提高了大约 2 倍。

什么会导致这种行为?

我的示例代码:

#include <omp.h>
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>

int some_work(int rank, int tid){
  int count = 10000;
  int arr[count];
  for( int i=0; i<count; i++)
    arr[i] = i + tid + rank;
  for( int val=0; val<4000000; val++)
    for(int i=0; i<count-1; i++)
      arr[i] = arr[i+1];

  return arr[0];
}


int main (int argc, char *argv[]) {

  MPI_Init(NULL, NULL);
  int rank, size;

  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  if (rank == 0)
    printf("there are %d mpi processes\n", size);

  MPI_Barrier(MPI_COMM_WORLD);

  double omp_time1 = omp_get_wtime();
  double mpi_time1 = MPI_Wtime();
  #pragma omp parallel 
  {
    int tid = omp_get_thread_num();
    if ( tid == 0 ) {
      int nthreads = omp_get_num_threads();
      printf("There are %d threads for process %d\n", nthreads, rank);
      int result = some_work(rank, tid);
      printf("result for process %d thread %d is %d\n", rank, tid, result);
    }
  }

  MPI_Barrier(MPI_COMM_WORLD);
  double mpi_time2 = MPI_Wtime();
  double omp_time2 = omp_get_wtime();
  printf("process %d omp time: %f\n", rank, omp_time2 - omp_time1);
  printf("process %d mpi time: %f\n", rank,  mpi_time2 - mpi_time1);
  printf("process %d ratio: %f\n", rank, (mpi_time2 - mpi_time1)/(omp_time2 - omp_time1) );

  MPI_Finalize();

  return EXIT_SUCCESS;
}

编译

g++ -O3 src/example_main.cpp -o bin/example -fopenmp -I/usr/mpi/gcc/openmpi-2.0.2/include -L /usr/mpi/gcc/openmpi-2.0.2/lib -lmpi

正在运行

salloc -N2 -n2 mpirun --map-by ppr:1:node:pe=16 bin/example 

提供类似的东西

there are 2 mpi processes
There are 16 threads for process 0
There are 16 threads for process 1
result for process 1 thread 0 is 10000
result for process 0 thread 0 is 9999
process 1 omp time: 5.066794
process 1 mpi time: 10.098752
process 1 ratio: 1.993125
process 0 omp time: 5.066816
process 0 mpi time: 8.772390
process 0 ratio: 1.731342

比例和我一开始写的不一致,但仍然足够大。

OpenMPI 1.8.4 的结果正常:

g++ -O3 src/example_main.cpp -o bin/example -fopenmp -I/usr/mpi/gcc/openmpi-1.8.4/include -L /usr/mpi/gcc/openmpi-1.8.4/lib -lmpi -lmpi_cxx

result for process 0 thread 0 is 9999
result for process 1 thread 0 is 10000
process 0 omp time: 4.655244
process 0 mpi time: 4.655232
process 0 ratio: 0.999997
process 1 omp time: 4.655335
process 1 mpi time: 4.655321
process 1 ratio: 0.999997

【问题讨论】:

  • 请贴出您用来测量的代码以及具体的测量结果(不仅仅是因子)。
  • 添加小例子,比例不一致。

标签: mpi openmpi


【解决方案1】:

我的集群上有类似的行为(与您的 OpenMPI 版本相同,2.0.2),问题是 CPU 频率的默认调节器,即“保守”调节器。 一旦将调控器设置为“性能”,MPI_Wtime() 的输出就会与正确的时间对齐(在我的例子中是“时间”的输出)。 看来,对于一些较旧的 Xeon 处理器(如 Xeon E5620),当使用过于激进的动态频率调整策略时,某些时钟功能会出现偏差 - 相同的 OpenMPI 版本在同一集群中的较新 Xeon 上不会遇到此问题。

【讨论】:

    【解决方案2】:

    也许 MPI_Wtime() 本身可能是一项昂贵的操作? 如果您避免将 MPI_Wtime() 消耗的时间作为 OpenMP-Time 的一部分进行测量,结果是否会更加一致? 例如:

    double mpi_time1 = MPI_Wtime();
    double omp_time1 = omp_get_wtime();
    /* do something */
    double omp_time2 = omp_get_wtime();
    double mpi_time2 = MPI_Wtime();
    

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 2016-11-12
      • 1970-01-01
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多