IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 13, 2008, 5:23:13 PM (18 years ago)
Author:
Paul Price
Message:

Learned that of all the fftw_ calls, only fftw_execute is thread-safe: all other calls have to be wrapped in a mutex for thread safety.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fft/psVectorFFT.c

    r11719 r19058  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-02-09 00:45:51 $
     8 *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2008-08-14 03:23:13 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psLogMsg.h"
    2828#include "psConstants.h"
     29#include "psThread.h"
     30#include "psFFT.h"
    2931#include "psVectorFFT.h"
     32
     33// Lock FFTW access
     34#define FFTW_LOCK \
     35if (threaded) { \
     36    psFFTLock(); \
     37}
     38// Unlock FFTW access
     39#define FFTW_UNLOCK \
     40if (threaded) { \
     41    psFFTUnlock(); \
     42}
    3043
    3144#define FFTW_PLAN_RIGOR FFTW_ESTIMATE   // How rigorous the FFTW planning is
     
    4053    PS_ASSERT_PTR_NON_NULL(imag, false);
    4154
     55    bool threaded = psThreadPoolSize(); // Are we running threaded?
     56
    4257    // Make sure the system-level wisdom information is imported.
     58    FFTW_LOCK;
    4359    if (!fftwWisdomImported) {
    4460        fftwf_import_system_wisdom();
    4561        fftwWisdomImported = true;
    4662    }
     63    FFTW_UNLOCK;
    4764
    4865    long num = in->n;                   // Number of elements
    4966
    5067    // Do the FFT
     68    FFTW_LOCK;
    5169    fftwf_complex *out = fftwf_malloc((num/2 + 1) * sizeof(fftwf_complex)); // Output data
    5270    fftwf_plan plan = fftwf_plan_dft_r2c_1d(num, in->data.F32, out, FFTW_PLAN_RIGOR);
     71    FFTW_UNLOCK;
     72
    5373    fftwf_execute(plan);
     74
     75    FFTW_LOCK;
    5476    fftwf_destroy_plan(plan);
     77    FFTW_UNLOCK;
    5578
    5679    // Pull the real and imaginary parts out
     
    6992#endif
    7093    }
     94
     95    FFTW_LOCK;
    7196    fftwf_free(out);
     97    FFTW_UNLOCK;
    7298
    7399    return true;
     
    83109    PS_ASSERT_PTR_NON_NULL(out, false);
    84110
     111    bool threaded = psThreadPoolSize(); // Are we running threaded?
     112
    85113    // Make sure the system-level wisdom information is imported.
     114    FFTW_LOCK;
    86115    if (!fftwWisdomImported) {
    87116        fftwf_import_system_wisdom();
    88117        fftwWisdomImported = true;
    89118    }
     119    FFTW_UNLOCK;
    90120
    91121    long num = real->n;                 // Number of elements
    92122
    93123    // Stuff the real and imaginary parts in
     124    FFTW_LOCK;
    94125    fftwf_complex *in = fftwf_malloc(num * sizeof(fftwf_complex)); // Input data
     126    FFTW_UNLOCK;
    95127    for (int i = 0; i < num; i++) {
    96128#if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I)
     
    107139    // Do the FFT
    108140    *out = psVectorRecycle(*out, origNum, PS_TYPE_F32);
     141    FFTW_LOCK;
    109142    fftwf_plan plan = fftwf_plan_dft_c2r_1d(origNum, in, (*out)->data.F32, FFTW_PLAN_RIGOR);
     143    FFTW_UNLOCK;
     144
    110145    fftwf_execute(plan);
     146
     147    FFTW_LOCK;
    111148    fftwf_destroy_plan(plan);
    112 
    113149    fftwf_free(in);
     150    FFTW_UNLOCK;
    114151
    115152    return true;
Note: See TracChangeset for help on using the changeset viewer.