FFTW3 - 并行化1D就位复杂fft很慢

问题描述 投票:2回答:1

所以我正致力于并行化1D FFT。作为第一项任务,我在具有16个内核的Intel(R)Xeon(R)CPU E5-2620 v3 @ 2.40GHz上执行了FFTW3库的基准测试。我刚刚做了一个基本的1D复合FFT,OpenMP作为我的线程库。我使用以下命令在ICC上编译:

icc -Wall -Werror
-I/.../mkl/include -I/apps/intel/linux/mkl/include/fftw  
fftw3_dft.c   
-L/.../intel/linux/mkl/.../intel64 -lmkl_rt 
-L/.../intel/.../linux/mkl/../compiler/lib/intel64 
-L/apps/intel/.../clinux/mkl/../tbb/lib/intel64/gcc4.4 
-liomp5 -lm -lpthread -ldl 
 -o fftw3_dft.out

我计算了不同问题规模的加速度量。我无法解释这个情节

  • 对于2 ^ 21和2 ^ 24之间的问题大小,为什么使用2个处理器没有加速? (即使有4,8和16个线程有一些加速)
  • 当问题规模大于2 ^ 27时,为什么加速会突然增加?

Speedup vs problem size graph

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>

#include "fftw3.h"
#include "mkl.h"

/* Compute (K*L)%M accurately */
static double moda(int K, int L, int M)
{
    return (double)(((long long)K * L) % M);
}

/* Initialize array x[N] with harmonic H */
static void init(fftw_complex *x, int N, int H)
{
    double TWOPI = 6.2831853071795864769, phase;
    int n;

    for (n = 0; n < N; n++)
    {
         phase  = moda(n,H,N) / N;
         x[n][0] = cos( TWOPI * phase ) / N;
        x[n][1] = sin( TWOPI * phase ) / N;
    }
}

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

    if(argc < 3) {
         printf("Error : give args\n");
        return 0;
     }


int N = atoi(argv[1]);
int p = atoi(argv[2]);

int H =  -N/2;
fftw_plan forward_plan = 0, backward_plan = 0;
fftw_complex *x = 0;
int status = 0;

fftw_init_threads();
fftw_plan_with_nthreads(p);

x  = fftw_malloc(sizeof(fftw_complex)*N);

forward_plan = fftw_plan_dft(1, &N, x, x, FFTW_FORWARD, FFTW_ESTIMATE);

init(x, N, H);

double start_time = dsecnd();

/*--------------ALG STARTS HERE --------------------------*/
fftw_execute(forward_plan);
/*--------------ALG ENDS HERE --------------------------*/

double end_time = dsecnd();

printf(LI", %d, %lf\n", N, p, end_time - start_time);
fftw_cleanup_threads()
fftw_destroy_plan(forward_plan);
fftw_free(x);

}
openmp fftw icc
1个回答
1
投票

即使对于n = 2 ^ 14,我确实获得了2个核心的加速,并且在此之后它始终保持在1.5以上。记得多次运行代码并扔掉用于旋转的第一部分。现代核心需要一些时间才能全速运转。

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>

#include "fftw3.h"
#include "omp.h"

/* Compute (K*L)%M accurately */
static double moda(int K, int L, int M)
{
    return (double)(((long long)K * L) % M);
}

/* Initialize array x[N] with harmonic H */
static void init(fftw_complex *x, int N, int H)
{
    double TWOPI = 6.2831853071795864769, phase;
    int n;

    for (n = 0; n < N; n++)
    {
         phase  = moda(n,H,N) / N;
         x[n][0] = cos( TWOPI * phase ) / N;
        x[n][1] = sin( TWOPI * phase ) / N;
    }
}

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

    if(argc < 2) {
         printf("Error : give args\n");
        return 0;
     }


int max_pow = atoi(argv[1]);
int p = 1;
#pragma omp parallel
{
#pragma omp single
{
  p = omp_get_num_threads();
}
}
printf("%i\n", p);

fftw_plan forward_plan = 0;
fftw_complex *x = 0;

fftw_init_threads();
fftw_plan_with_nthreads(p);

for(int iter=1;iter<=2;iter++){
  //throw away the first round, a couple of seconds is enough
  for(int pw=12;pw<=max_pow;pw++){
    int N = pow(2, pw);
    int H =  -N/2;

    x  = fftw_malloc(sizeof(fftw_complex)*N);

    forward_plan = fftw_plan_dft(1, &N, x, x, FFTW_FORWARD, FFTW_MEASURE);

    init(x, N, H);

    double start_time = omp_get_wtime();

    /*--------------ALG STARTS HERE --------------------------*/
    for(int i=1;i<=5;i++){fftw_execute(forward_plan);}
    /*--------------ALG ENDS HERE --------------------------*/

    double end_time = omp_get_wtime();

    printf("%i %lf\n", pw, (end_time - start_time)/5);
    fftw_destroy_plan(forward_plan);
    fftw_free(x);
  }
}

return 0;
}

> gfortran -fopenmp fftw1d.c -lfftw3 -lfftw3_omp
> OMP_NUM_THREADS=2 ./a.out 24

由于库已经编译,因此有和没有-O3的结果相同。

enter image description here

在四核英特尔(R)Core(TM)i7-3770 CPU @ 3.40GHz上测试

© www.soinside.com 2019 - 2024. All rights reserved.