1
$\begingroup$

I tried to use the wisdom gather / broadcast feature of FFTW with MPI, but can't get it to work. The following program is a combination of the MPI example from Section 6.3 of the FFTW manual and the code snippets from Section 6.8. When I compile and run it twice, it will crash with a segmentation fault in the second run (after the wisdom is read, before it is broadcast).

#include <iostream>
#include "mpi.h"
#include "fftw3.h"
#include "fftw3-mpi.h"

int main(int argc, char **argv) {
  MPI_Init(&argc, &argv);
  fftw_mpi_init();

  const ptrdiff_t N0 = 16, N1 = 16;
  fftw_plan plan;
  fftw_complex *data;
  ptrdiff_t alloc_local, local_n0, local_0_start, i, j;

  int rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  int importResult = 0;
  if (rank == 0) importResult = fftw_import_wisdom_from_filename("mywisdom");
  MPI_Bcast(&importResult, 1, MPI_INT, 0, MPI_COMM_WORLD);
  std::cout << rank << ": import status = " << importResult << std::endl;

  if(importResult) {
    fftw_mpi_broadcast_wisdom(MPI_COMM_WORLD);
  }
  MPI_Barrier(MPI_COMM_WORLD);

  /* get local data size and allocate */
  alloc_local = fftw_mpi_local_size_2d(N0, N1, MPI_COMM_WORLD, &local_n0, &local_0_start);
  data = fftw_alloc_complex(alloc_local);
 
  /* create plan for in-place forward DFT */
  plan = fftw_mpi_plan_dft_2d(N0, N1, data, data, MPI_COMM_WORLD, FFTW_FORWARD, FFTW_MEASURE);

  std::cout << rank << ": export" << std::endl;
  fftw_mpi_gather_wisdom(MPI_COMM_WORLD);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  if (rank == 0) fftw_export_wisdom_to_filename("mywisdom");
  MPI_Barrier(MPI_COMM_WORLD);

  std::cout << rank << ": end" << std::endl;
  fftw_destroy_plan(plan);
  MPI_Finalize();
}

I use FFTW 3.3.10 with MPICH3.2, g++ version 7.4.0, running on Red Hat 7.9 (Maipo).

Any hint is appreciated. Also, it would be interesting to know whether the segmentation fault is reproducible for other configurations. I have tried a few, but the behavior has been the same.

$\endgroup$
4
  • $\begingroup$ Could you clarify what you mean by "run it twice"? I don't know FFTW but for a generic MPI application, I'd expect an appropriate incantation of mpiexec, mpirun or orterun as appropriate to your environment. $\endgroup$
    – origimbo
    Apr 3 at 12:32
  • $\begingroup$ I mean execute the program two times (as you said, by using mpiexec). In the first run, the wisdom file is written. In the second run, it is read, but the broadcast to the other processes seems to fail. $\endgroup$
    – Hannes
    Apr 3 at 13:35
  • $\begingroup$ Where does the segmentation fault happen? Why does it happen (which pointer is null, for example)? There are so many easy steps one can take to debug this, and none have been shown here. $\endgroup$ Apr 3 at 22:20
  • $\begingroup$ From what I can tell, the segmentation fault happens inside fftw_mpi_broadcast_wisdom. I have not been able to narrow it down more precisely. $\endgroup$
    – Hannes
    Apr 4 at 12:52

1 Answer 1

3
$\begingroup$

The backtrace showed the following:

#0  __GI___libc_free (mem=0x3d1) at malloc.c:3102
#1  0x000055555557b590 in our_free (p=0x555555bb1e20) at kalloc.c:67
#2  0x000055555557b5d1 in fftw_kernel_free (p=0x555555bb1e20) at kalloc.c:143
#3  0x0000555555582837 in fftw_free (p=0x555555bb1e20) at malloc.c:31
#4  0x000055555556d8de in fftw_mpi_broadcast_wisdom (comm_=1140850688)
    at wisdom-api.c:109
#5  0x000055555556961a in main (argc=1, argv=0x7fffffffe278)
    at testWisdom.cpp:35

The solution was to recompile FFTW without the --with-our-malloc option of FFTW. Then, the segmentation fault disappeared.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.