Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Shared Data with QVector
Forum Updated to NodeBB v4.3 + New Features

Shared Data with QVector

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 345 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by beecksche
    #1

    Hi,
    i work with the FFTW library for complex to complex transformations. For the execution of the FFT you have to "bake" a plan, where all the internal buffers are created with the set input and output vectors. In my case I use QVectors to hold the input and output data.

    The first time the plan is created with the set input data, the output data holds the correct results. If I want to use the same plan again but with changed input data, the output is incorrect.

    A simple example:

    QVector<fftw_complex> input(12);
    QVector<fftw_complex> output(12);
    
    // fill input with data
    
    fftw_plan plan = fftw_plan_dft_1d(input.size(), input.data(), output.data(), FFTW_FORWARD, FFTW_ESTIMATE);
    
    fftw_execute(plan);
    
    // output = correct
    
    // change the data of the input vector
    input[0] = ...;
    input[1] = ...;
    ...
    
    fftw_execute(plan);
    
    // output = incorrect
    

    If I use an array fftw_complex input[12] instead of the QVector, the output is also correct after changing the input data.

    I think it's because of the implicit shared data of the QVector, but I'm not sure.

    Performance is a big issue in my case, so "baking" the plan again after changing the input data is no option (25 threads run 300.000 512x512 2D-FFTs, each).

    Is there a way to use the QVector (or another Qt class) in such a case?
    Thanks!

    kshegunovK 1 Reply Last reply
    0
    • beeckscheB beecksche

      Hi,
      i work with the FFTW library for complex to complex transformations. For the execution of the FFT you have to "bake" a plan, where all the internal buffers are created with the set input and output vectors. In my case I use QVectors to hold the input and output data.

      The first time the plan is created with the set input data, the output data holds the correct results. If I want to use the same plan again but with changed input data, the output is incorrect.

      A simple example:

      QVector<fftw_complex> input(12);
      QVector<fftw_complex> output(12);
      
      // fill input with data
      
      fftw_plan plan = fftw_plan_dft_1d(input.size(), input.data(), output.data(), FFTW_FORWARD, FFTW_ESTIMATE);
      
      fftw_execute(plan);
      
      // output = correct
      
      // change the data of the input vector
      input[0] = ...;
      input[1] = ...;
      ...
      
      fftw_execute(plan);
      
      // output = incorrect
      

      If I use an array fftw_complex input[12] instead of the QVector, the output is also correct after changing the input data.

      I think it's because of the implicit shared data of the QVector, but I'm not sure.

      Performance is a big issue in my case, so "baking" the plan again after changing the input data is no option (25 threads run 300.000 512x512 2D-FFTs, each).

      Is there a way to use the QVector (or another Qt class) in such a case?
      Thanks!

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @beecksche said in Shared Data with QVector:

      Is there a way to use the QVector (or another Qt class) in such a case?

      Make sure you don't detach the vector. "Baking" the plans isn't reentrant anyway, so you're stuck to doing it before anything else anyway. After that enforce constness on the vector and it should be okay.

      Read and abide by the Qt Code of Conduct

      beeckscheB 1 Reply Last reply
      2
      • kshegunovK kshegunov

        @beecksche said in Shared Data with QVector:

        Is there a way to use the QVector (or another Qt class) in such a case?

        Make sure you don't detach the vector. "Baking" the plans isn't reentrant anyway, so you're stuck to doing it before anything else anyway. After that enforce constness on the vector and it should be okay.

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by beecksche
        #3

        @kshegunov

        I'm sorry, the example i wrote works fine. I found the mistake in my algorithm, the input buffer was recreated, instead of the entries

        ...
        input = QVector<fftw_complex>(12); // this doesn't work!
        ...
        

        Thanks anyway!

        EDIT:

        To complete the answer, the FFTW library has a "New-Array Execution" function, where the input and output buffer can be set when executing the plan.

        And with QVarLengthArray you can handle the arrays easily with high performance. QVarLengthArray won't check if the data is shared.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved