Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve OpenMP in Biot-Savart code #44

Open
pazathoth opened this issue Feb 5, 2024 · 0 comments
Open

Improve OpenMP in Biot-Savart code #44

pazathoth opened this issue Feb 5, 2024 · 0 comments

Comments

@pazathoth
Copy link
Member

Multi-threaded FFTW starts to be useful when arrays have a few thousand entries, which is currently not the case in the Biot-Savart computations. Thus it would be more useful to use single-threaded FFTW instead and parallelize the surrounding loop, i.e. instead of

p_fft_output = fftw_alloc_complex(int(nfft, c_size_t))
call c_f_pointer(p_fft_output, fft_output, [nfft])
p_AR = fftw_alloc_real(int(nphi, c_size_t))
call c_f_pointer(p_AR, AR, [nphi])
! ... further input arrays
do kZ = 1, nZ
  do kR = 1, nR
    !$omp parallel do shared(AR) ...
    do kphi = 1, nphi
      ! ... fill input arrays
    end do
    !$omp end parallel do
    call fftw_execute_dft_r2c(plan_nphi, AR, fft_output)
    AnR(0:nmax, kR, kZ, kc) = fft_output(1:nmax+1) / dble(nphi)
    ! ... further transforms
  end do
end do

do

!$omp parallel private(AR, fft_output), shared(AnR)
p_fft_output = fftw_alloc_complex(int(nfft, c_size_t))
call c_f_pointer(p_fft_output, fft_output, [nfft])
p_AR = fftw_alloc_real(int(nphi, c_size_t))
call c_f_pointer(p_AR, AR, [nphi])
! ... further input arrays
!$omp do collapse(3) ...
do kZ = 1, nZ
  do kR = 1, nR
    do kphi = 1, nphi
      ! ... fill input arrays
    end do
    call fftw_execute_dft_r2c(plan_nphi, AR, fft_output)
    AnR(0:nmax, kR, kZ, kc) = fft_output(1:nmax+1) / dble(nphi)
    ! ... further transforms
  end do
end do
!$omp end do
!$omp end parallel

Finally, the question is whether to link fftw3 or fftw3_omp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant