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 6245039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:26:10+00:00 2026-05-24T12:26:10+00:00

I have a basic calculation function that I apply on each item in an

  • 0

I have a basic calculation function that I apply on each item in an array. This function does more then just summing two vectors.

I wanted to work on multiple items from my array in parallel using SIMD commands.

As I found these kind of examples too simple for my case (they don’t include function calls):
http://www.doc.ic.ac.uk/~nloriant/files/scfpsc-pc.pdf

I tried using array notation as in here:
http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/cpp/mac/optaps/common/optaps_elem_functions.htm

But this did not accelerate my code. I don’t understand what I am doing wrong and if I need to go to the more assembly-like style of SIMD, how do I introduce function calls there…

If anyone can help me or refer me to a good source for my needs I’ll be very thakful.

Thank you!!!!


code example:

This is the basic function applied on each item in the array:

float VarFlow::gauss_seidel_step(IplImage* u, int i, float h, float J11, float J12, float J13, float vi){

int x = i%u->width;
int y = i/u->width;

int start_y, end_y, start_x, end_x;
int N_num = 0;

start_y = y - 1;
end_y = y + 1;
start_x = x - 1;
end_x = x+1;         

float temp_u = 0;

// Sum top neighbor    
if(start_y > -1){              

    temp_u += *((float*)(u->imageData + start_y*u->widthStep) + x);

    N_num++;

}

// Sum bottom neighbor            
if(end_y < u->height){   

    temp_u += *((float*)(u->imageData + end_y*u->widthStep) + x);

    N_num++;

}

// Sum left neighbor
if(start_x > -1){              

    temp_u += *((float*)(u->imageData + y*u->widthStep) + start_x);

    N_num++;

}

// Sum right neighbor
if(end_x < u->width){              

    temp_u += *((float*)(u->imageData + y*u->widthStep) + end_x);

    N_num++;

}

temp_u = temp_u - (h*h/alpha)*(J12*vi + J13);
temp_u = temp_u / (N_num + (h*h/alpha)*J11);

return temp_u;

}

I’d like to declare it with __declspec (vector) and call it like so:

    u_ptr[0:max_i:1] = gauss_seidel_step(imgU, vect[0:max_i:1], h, fxfx_ptr[0:max_i:1], fxfy_ptr[0:max_i:1], fxft_ptr[0:max_i:1], v_ptr[0:max_i:1]);
    v_ptr[0:max_i:1] = gauss_seidel_step(imgV, vect[0:max_i:1], h, fyfy_ptr[0:max_i:1], fxfy_ptr[0:max_i:1], fyft_ptr[0:max_i:1], u_ptr[0:max_i:1]);

Instead of a for loop.

I’ll be happy to get a direction with this (maybe a link to a similar example) but not a full solution.

Thanks!

  • 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-05-24T12:26:11+00:00Added an answer on May 24, 2026 at 12:26 pm

    SIMD and conditional branching do not mix well.

    Turn your conditional statements into boolean masks and multiplications. That will send you down the right path for vectorizing the operations.

    e.g.

    if(end_x < u->width){                  
        temp_u += value;    
        N_num++;    
    }
    

    becomes

    ltmask = (end_x < u->width); // see _mm_cmplt_ps
    temp_u += ltmask*value; // see _mm_add_ps, _mm_and_ps
    N_num += ltmask; // use _mm_and_ps with a vector of 1.0f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've scoured the internet and my own intellect to answer this basic question, however,
I am new to Qt Programming, but I have basic on C++. I want
I'm embarrassed by the 'basicness' of this question, but after wasted hours, here goes.
I have an jQuery accordion for a form on an internal company website. They
I'm building a basic forum where every post contains some text, first and last
I have the following available: last reported lat,lon w/timestamp target lat,lon estimated time to
I have two questions concerning fitting a gauss curve to histogram peaks. My first
I want to use GeoDjango to do basic location searches. Specifically I want to
I am writing an application that interprets a time delayed stream of data. The
I totally understand that in order to learn javascript I need to know how

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.