2016-04-22 4 views
1

J'ai besoin d'utiliser FFTW avec différentes précisions arithmétiques et plans multithread.Comment configurer FFTW avec des threads et différentes précisions?

J'ai besoin de configurer le multithreading pour toutes les précisions? Comme ceci:

fftwf_init_threads(); 
fftwf_plan_with_nthreads(nthreads); 
fftw_init_threads(); 
fftw_plan_with_nthreads(nthreads); 
fftwl_init_threads(); 
fftwl_plan_with_nthreads(nthreads); 

Ou écrire dans mon début routine

fftw_init_threads(); 
fftw_plan_with_nthreads(nthreads); 

sera suffisant?

Répondre

1

Les bibliothèques fftw pour différentes précisions sont complètement indépendantes les unes des autres. Par conséquent, vous devez multithreading de configuration pour tous les precisions en appelant la fonction correspondante de FFTW:

int nbthreads=2; 
fftw_init_threads(); 
fftw_plan_with_nthreads(nbthreads); 
fftwf_init_threads(); 
fftwf_plan_with_nthreads(nbthreads); 
fftwq_init_threads(); 
fftwq_plan_with_nthreads(nbthreads); 

... 

fftw_cleanup_threads(); 
fftwf_cleanup_threads(); 
fftwq_cleanup_threads(); 

Voici un exemple de code pour vous convinve. Il peut être compilé par gcc main.c -o main -lfftw3_threads -lfftw3 -lfftw3f_threads -lfftw3f -lfftw3q_threads -lfftw3q -lm -lpthread -Wall sous Unix, une fois les bibliothèques correctives construites.

#include <stdlib.h> 
#include <stdio.h> 
#include <time.h> 

#include <fftw3.h> 

int main (){ 
    int n = 40000000; 
    int nf = n*2; 
    int nq =n/32; 

    fftw_complex *in; 
    fftw_complex *in2; 
    fftw_complex *out; 
    fftw_plan plan_backward; 
    fftw_plan plan_forward; 

    fftwf_complex *inf; 
    fftwf_complex *in2f; 
    fftwf_complex *outf; 
    fftwf_plan plan_backwardf; 
    fftwf_plan plan_forwardf; 

    fftwq_complex *inq; 
    fftwq_complex *in2q; 
    fftwq_complex *outq; 
    fftwq_plan plan_backwardq; 
    fftwq_plan plan_forwardq; 

    //thread parameters 
    int nbthreads=2; 
    fftw_init_threads(); 
    fftw_plan_with_nthreads(nbthreads); 
    fftwf_init_threads(); 
    fftwf_plan_with_nthreads(nbthreads); 
    fftwq_init_threads(); 
    fftwq_plan_with_nthreads(nbthreads); 

    in = fftw_malloc (sizeof (fftw_complex) * n); 
    out = fftw_malloc (sizeof (fftw_complex) * n); 

    inf = fftwf_malloc (sizeof (fftwf_complex) * nf); 
    outf = fftwf_malloc (sizeof (fftwf_complex) * nf); 

    inq = fftwq_malloc (sizeof (fftwq_complex) * nq); 
    outq = fftwq_malloc (sizeof (fftwq_complex) * nq); 

    // forward fft 
    plan_forward = fftw_plan_dft_1d (n, in, out, FFTW_FORWARD, FFTW_ESTIMATE); 
    fftw_execute (plan_forward); 

    plan_forwardf = fftwf_plan_dft_1d (nf, inf, outf, FFTW_FORWARD, FFTW_ESTIMATE); 
    fftwf_execute (plan_forwardf); 

    plan_forwardq = fftwq_plan_dft_1d (nq, inq, outq, FFTW_FORWARD, FFTW_ESTIMATE); 
    fftwq_execute (plan_forwardq); 

    // backward fft 
    in2 = fftw_malloc (sizeof (fftw_complex) * n); 
    plan_backward = fftw_plan_dft_1d (n, out, in2, FFTW_BACKWARD, FFTW_ESTIMATE); 
    fftw_execute (plan_backward); 

    in2f = fftwf_malloc (sizeof (fftwf_complex) * nf); 
    plan_backwardf = fftwf_plan_dft_1d (nf, outf, in2f, FFTW_BACKWARD, FFTW_ESTIMATE); 
    fftwf_execute (plan_backwardf); 

    in2q = fftwq_malloc (sizeof (fftwq_complex) * nq); 
    plan_backwardq = fftwq_plan_dft_1d (nq, outq, in2q, FFTW_BACKWARD, FFTW_ESTIMATE); 
    fftwq_execute (plan_backwardq); 

    fftw_cleanup_threads(); 
    fftw_destroy_plan (plan_forward); 
    fftw_destroy_plan (plan_backward); 

    fftw_free (in); 
    fftw_free (in2); 
    fftw_free (out); 

    fftwf_cleanup_threads(); 
    fftwf_destroy_plan (plan_forwardf); 
    fftwf_destroy_plan (plan_backwardf); 

    fftwf_free (inf); 
    fftwf_free (in2f); 
    fftwf_free (outf); 

    fftwq_cleanup_threads(); 
    fftwq_destroy_plan (plan_forwardq); 
    fftwq_destroy_plan (plan_backwardq); 

    fftwq_free (inq); 
    fftwq_free (in2q); 
    fftwq_free (outq); 

    return 0; 
} 

Vous pouvez commenter fftwq_init_threads(); fftwq_plan_with_nthreads(nbthreads); et fftwq_cleanup_threads(); et surveiller l'utilisation de cpu pour vérifier que FFTW ne pas utiliser multithreading pour la précision de quad dans ce cas.

Pour construire fftw3 pour différentes en utilisant precisions intel simd sse2, faites:

./configure --enable-threads --enable-shared --enable-sse2 
make 
make install 
./configure --enable-threads --enable-shared --enable-sse2 --enable-float 
make 
make install 
./configure --enable-threads --enable-shared --enable-quad-precision 
make 
make install 

Il n'y a pas de support SSE2 pour la précision de quad.