Burgundy
Burgundy

Reputation: 121

Compiling FFTW with MPI in C

I have installed both Open MPI and FFTW onto my mac. I've successfully used FFTW, now I'm trying to use it with MPI.

Here is what I am trying to run:

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;
}

Here is how I am attempting to compile:

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

This is nearly identical to how I compiled without mpi and all worked fine:

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

But Now I see a lot of this:

enter image description here

How can I fix this issue? I know I installed OpenMPI, the installation of FFTW failed without it.

Upvotes: 2

Views: 539

Answers (1)

petrmikheev
petrmikheev

Reputation: 342

  1. Add -lfftw3 after -lfftw3_mpi

  2. Use mpicxx instead of gcc

Command: mpicxx test.c -lfftw3_mpi -lfftw3

Upvotes: 1

Related Questions