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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:53:59+00:00 2026-06-17T16:53:59+00:00

I have the following program: int main(){ double sum=0; #pragma omp parallel for reduction(+:sum)

  • 0

I have the following program:

int main(){
   double sum=0;
   #pragma omp parallel for reduction(+:sum)
   for(double x=0;x<10;x+=0.1)
   sum+=x*x;
}

When I compile it, I get the error invalid type for iteration variable ‘x’.

I take this to mean that I can only apply a parallel for construct to integer-based loops. But the internals of my loop really do depend on it being floating-point.

Is there a way to convince OpenMP to do this? Is there a recommended alternative method?

  • 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-17T16:54:00+00:00Added an answer on June 17, 2026 at 4:54 pm

    From comments:

    No, OpenMP won’t do this for you for the same reasons as in this answer given to a question about OpenMP loops with integer arithmetic; it’s extremely difficult for the compiler to reason about floating point numbers – in particular, the compiler needs to know before entering the loop the loop’s tripcount, and floating point arithmetic in the loop makes that very difficult in general, even if there are some simple cases that would be ok (say, looping by 0.5 to 10.0).

    For the same reason, even purely serial optimization/vectorization of loops of this form would suffer. The best way to do it is to make an equivalent integer loop and calculate your float based on the integer index;

    for (int i=0; i<100; i++) { 
        double x=0.1*i; 
        sum += x*x; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following C program: #include <stdio.h> int main() { double x=0; double
I have following simple program: import std.stdio; int main(string[] argv) { writeln(Hello, world!); return
Hi I have the following program. When I compile on the terminal gcc main.c
I have the following program #include <stdio.h> int main(void) { unsigned short int length
Suppose I have the following program: #include <stdio.h> int main() { printf(This is a
I have a question on constant objects. In the following program: class const_check{ int
I have a program structure like following : int firstFunction(unsigned char *firstValue, int s,
I have a following program but for some reason it is throwing an error
The following program crashes with a bad glibc double free error: #include <iostream> #include
Consider the following program: #include <array> int main() { std::array<int, 1> x = {

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.