Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:35:49+00:00 2026-06-18T20:35:49+00:00

I am trying to write some C code which can be vectorized. This is

  • 0

I am trying to write some C code which can be vectorized. This is the loop I am trying:

for(jj=0;jj<params.nx;jj++)
    for(kk=0;kk<NSPEEDS;kk++)
        local_density_vec[jj] += tmp_cells_chunk[jj].speeds[kk];

GCC gives me the following message when run with the -ftree-vectorizer-verbose=5 flag http://pastebin.com/RfCc04aS.

How can I rewrite it in order that it can be auto vectorized. NSPEEDS is 5.

EDIT:

I’ve continued to work on it, and I don’t seem to be able to vectorize anything with .speeds[kk]. Is there a way of restructuring it so that it can?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:35:50+00:00Added an answer on June 18, 2026 at 8:35 pm
    for (jj = 0; jj < nx; jj++) {
            partial = 0.0f;
            fp = c[jj].speeds;
            for (kk = 0; kk < M; kk++)
                    partial += fp[kk];
            out[jj] = partial;
    }
    (...)
    Calculated minimum iters for profitability: 12
    
    36:   Profitability threshold = 11
    
    Vectorizing loop at autovect.c:36
    
    36: Profitability threshold is 11 loop iterations.
    36: LOOP VECTORIZED.
    

    Important points:

    1) In your dump, the loop was considered “complicated access pattern” (see the last line of your log). As already commented, this is related to the compiler being unable to verify aliasing. For “simple” access patterns, see:
    http://gcc.gnu.org/projects/tree-ssa/vectorization.html#vectorizab

    2) My example loop required 12 iterations for vectorization to be useful. Since NSPEEDS == 5, the compiler would loose time if it vectorized yours.

    3) I was only able to vectorize my loop after I added -funsafe-math-optimizations. I believe this is required due to either different rounding or associativity behavior with the resulting vector operations. See, for example:
    http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

    4) If you reverse the loop you could have problems with “complicated” access patterns again. As already commented, you may need to reverse the array organization. Check the gcc vectorization docs about strided accesses to check if you can match one of the patterns.

    For completeness, here is the complete example:
    http://pastebin.com/CWhyqUny

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some python code which can create multipart mime http requests
I am trying to write some simple code which will read a text file
I'm trying to write some C code which is portable only so far as
I'm trying to write some Haskell code in which there are multiple data types,
I am trying to write some code that that will draw the line which
I'm trying to write some C++ code for Windows 7 which will connect to
I am currently trying to write some code which turns C# Expressions into text.
I am trying to write some code which retrieves the first 10 words of
I'm trying to write some code that uses Numpy. However, I can't import it:
I'm trying to write some c code (objective c) which will take a bank

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.