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

  • Home
  • SEARCH
  • 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 8102077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:08:44+00:00 2026-06-05T23:08:44+00:00

I am writing simple parallel program in C++ using OpenMP. I am working on

  • 0

I am writing simple parallel program in C++ using OpenMP.
I am working on Windows 7 and on Microsoft Visual Studio 2010 Ultimate.
I changed the Language property of the project to “Yes/OpenMP” to support OpenMP

Here I provide the code:

#include <iostream>
#include <omp.h> 

using namespace std;

double sum; 
int i;
int n = 800000000;

int main(int argc, char *argv[])
{               
    omp_set_dynamic(0);
    omp_set_num_threads(4); 

    sum = 0;    
    #pragma omp for reduction(+:sum)
    for (i = 0; i < n; i++)
        sum+= i/(n/10);

    cout<<"sum="<<sum<<endl;        

    return  EXIT_SUCCESS;
}

But, I couldn’t get any acceleration by changing the x in omp_set_num_threads(x);
It doesn’t matter if I use OpenMp or not, the calculating time is the same, about 7 seconds.

Does Someone know what is the problem?

  • 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-05T23:08:47+00:00Added an answer on June 5, 2026 at 11:08 pm

    Your pragma statement is missing the parallel specifier:

    #include <iostream>
    #include <omp.h> 
    
    using namespace std;
    
    double sum; 
    int i;
    int n = 800000000;
    
    int main(int argc, char *argv[])
    {               
        omp_set_dynamic(0);
        omp_set_num_threads(4); 
    
        sum = 0;    
        #pragma omp parallel for reduction(+:sum)  //  add "parallel"
        for (i = 0; i < n; i++)
            sum+= i/(n/10);
    
        cout<<"sum="<<sum<<endl;        
    
        return  EXIT_SUCCESS;
    }
    

    Sequential:

    sum=3.6e+009
    2.30071
    

    Parallel:

    sum=3.6e+009
    0.618365
    

    Here’s a version that some speedup with Hyperthreading. I had to increase the # of iterations by 10x and bump the datatypes to long long:

    double sum; 
    long long i;
    long long n = 8000000000;
    
    int main(int argc, char *argv[])
    {               
        omp_set_dynamic(0);
        omp_set_num_threads(8); 
    
        double start = omp_get_wtime();
    
    
        sum = 0;    
        #pragma omp parallel for reduction(+:sum)
        for (i = 0; i < n; i++)
            sum+= i/(n/10);
    
        cout<<"sum="<<sum<<endl;       
    
        double end = omp_get_wtime(); 
        cout << end - start << endl;
        system("pause");
    
        return  EXIT_SUCCESS;
    }
    

    Threads: 1

    sum=3.6e+014
    13.0541
    

    Threads: 2

    sum=3.6e+010
    6.62345
    

    Threads: 4

    sum=3.6e+010
    3.85687
    

    Threads: 8

    sum=3.6e+010
    3.285
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple script to run bunch of tasks in parallel using the
I am writing an c++ application in visual studio 2010. I run my code
I am writing simple client-server program. Client send some messages to server using UDP
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm writing simple GUI using wxPyhon and faced some problems. My application does simple
As I'm a novice, I started learning python by writing simple programs using python
I'm writing simple chat program in Ada, and I'm having problem with chat window
I'm thinking of writing simple application for Windows Mobile devices, where user could simply
I am writing simple program for my Ubuntu 10.04. I want to see which
I'm working on writing simple unit tests for a Rails 3 project, but I'm

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.