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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:55:42+00:00 2026-06-16T18:55:42+00:00

I was experiencing with parallel scalar producting two vectors and measuring the time elapsed.

  • 0

I was experiencing with parallel scalar producting two vectors and measuring the time elapsed.
I was comparing sequential vs parallel scalar product:

seq: double scalar(int n, double x[], double y[])

for (int i=0; i<n; i++)
{
   sum += x[i]*y[i];
}

parallel: double scalar_shm(int n, double x[], double y[])

#pragma omp parallel for private(i) shared(x,y) reduction(+:sum)
for (i=0; i<n; i++)
{
   sum += x[i]*y[i];
}

I called these one after the other:

//sequential loop
for (int n=0; n<loops; n++)
{ scalar(vlength,x,y); }

//measure sequential time
t1 = omp_get_wtime() - tstart;

//parallel loop
for (int n=0; n<loops; n++)
{ scalar_shm(vlength,x,y); }

//measure parallel time
t2 = omp_get_wtime() - t1 - tstart;

//print the times elapsed
cout<< "total time (sequential): " <<t1 <<" sec" <<endl;
cout<< "total time (parallel  ): " <<t2 <<" sec" <<endl;

Every cycle I filled up the vectors with random doubles, I removed that part, because I consider it irrelevant.

The output for this was:

total time (sequential): 15.3439 sec
total time (parallel  ): 24.5755 sec

My question is why is the parallel one slower? What is it good for if it’s slower? I expected it to be way faster, because I kind of thought that computations like this were the point of it.

note: I ran this on an Intel Core i7-740QM

  • 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-16T18:55:43+00:00Added an answer on June 16, 2026 at 6:55 pm

    You are creating and destroying a new parallel section code for each iteration. This operation is very slow. You could try to create the parallel section outside the internal loop:

    //parallel loop
    int sum;
    #pragma omp parallel private(n) reduction(+:sum)
    {
        for (int n=0; n<loops; n++)
        { 
           scalar_shm(vlength,x,y, sum); 
        }
    }
    

    Inside scalar_shm function, the OpenMP pragma would be:

    #pragma omp for private(i)
    for (i=0; i<n; i++)
    {
       sum += x[i]*y[i];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are experiencing a slow start up time on the first report request of
I am experimenting with parallel programming. I have a normal loop: for (int i
I'm experiencing an issue which has two possible solutions. I am unsure which solution
I'm experimenting with filtering through elements in parallel. For each element, I need to
Experiencing jquery in rails through .js.erb templates; but completely puzzled by a simple problem
When experiencing networking problems on client machines, I'd like to be able to run
Im experiencing a strange situation which i was supposed to handle. The situation is:
i am currently experiencing a problem were i get *** glibc detected *** ./efit:
The problem I'm experiencing is when I add the message Body part of the
I am experiencing a problem with some Javascript - please see my site and

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.