在 C 中使用 MPI 编译 FFTW

标签 c mpi fftw

我已经在我的 mac 上安装了 Open MPI 和 FFTW。我已经成功地使用了 FFTW,现在我正在尝试将它与 MPI 一起使用。

这是我要运行的:

int main(int argc, char **argv){
    clock_t time0, time1;
    int N = 10;
    fftw_complex *in, *out;
    fftw_plan p;
    MPI_Init(&argc, &argv);
    fftw_mpi_init();
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    p = fftw_mpi_plan_dft_1d(N, in, out,MPI_COMM_WORLD, FFTW_FORWARD, FFTW_ESTIMATE);
    for (int i = 0; i<N; i++) {
        in[i]=i+(i+1)*I;
    }
    time0 = clock();
    fftw_execute(p);
    time1 = clock();
    printf(" FFT time = %f \n\n", (float)(time1 - time0)/CLOCKS_PER_SEC);
    fftw_destroy_plan(p);
    fftw_free(in); fftw_free(out);
    MPI_Finalize();
    return 0;
}

这是我尝试编译的方式:

gcc -I/usr/local/include test.c -L/usr/local/lib -lfftw3_mpi

这与我在没有 mpi 的情况下编译的方式几乎相同,并且一切正常:

gcc -I/usr/local/include test.c -L/usr/local/lib -lfftw3

但现在我看到了很多这样的东西:

enter image description here

我该如何解决这个问题?我知道我安装了 OpenMPI,没有它 FFTW 安装失败。

最佳答案

  1. -lfftw3_mpi之后添加-lfftw3

  2. 使用mpicxx代替gcc

命令:mpicxx test.c -lfftw3_mpi -lfftw3

关于在 C 中使用 MPI 编译 FFTW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497757/

相关文章:

c - OpenCV 傅立叶幅度 - 似乎不正确

python - pyFFTW 是否允许保留输入数组

c - 使用 char 时双重释放或损坏**

python - MPI 中的设计模式 : sleep root process on blocking send and proper load balancing

c++ - 如何在 iOS 上编译 fftw3

c - C 语言中的 MPI 逐行矩阵乘法

r - 从 R 调用并行 fortran MPI 子例程

c - 函数中的数组成员比较不起作用

c - 当要解析的文件是由程序编写时使用解析器生成器或手动代码?

c - 为什么这个c程序中出现Segmentation failure错误?