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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:20:40+00:00 2026-05-27T23:20:40+00:00

In my VS2010 C code I am successfully using the pragma directive here: void

  • 0

In my VS2010 C code I am successfully using the pragma directive here:

 void doSomething(void)
{
     n = doSomethingElse();
     j = doOnceMore();
     k = n + j;
}

   #pragma omp parallel for
   for (i = 0; i < 5; ++i)
   {
        doSomething();
   }

But I cannot get it to work if I move the work of “doSomething()” inline:

    #pragma omp parallel for
     for (int i = 0; i < 5; ++i)
    {
         n = doSomethingElse();
         j = doOnceMore();
         k = n + j;
     }

I always assumed that the pragma directive would take the stuff inside the brackets and assign it a unique thread. Am I dead wrong about that, or is there some other omp syntax I should use?

  • 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-27T23:20:41+00:00Added an answer on May 27, 2026 at 11:20 pm

    n,j,k are by default thread shared, hence it does not work. Every thread is writing on n,j,k at the same time, currently.

    It depends what you want to do whether they have to be private or shared though. If they are local for one loop pass, you can declare them as thread private and it should work fine (the loop counter, here i, is by default thread private).

    #pragma omp parallel for private(n,j,k)
     for (int i = 0; i < 5; ++i)
    {
         n = doSomethingElse();
         j = doOnceMore();
         k = n + j;
     }
    

    Since openmp cannot guess what purpose variables have, it is your job to tell the pragma how to handle them. You find more information about Clauses and Variables here. There is also a very good talk on the openmp webpage about data structures and constructing proper parallel regions.

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

Sidebar

Related Questions

I'm using VS2010 Ultimate. Having code: //file IntSet.h #include stdafx.h #pragma once /*Class representing
I am using SQLite wrapper provided by http://sqlite.phxsoftware.com in VS2010 Here is the code
This code fails to compile under VS2010: #include <functional> using namespace std; void test()
I'm using VS2010 Beta 2 to debug some multi-threaded code. Love parallel stacks, etc.
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I'm trying to generate a VS2010 solution for ASEPRITE (http://code.google.com/p/aseprite/) but when I follow
Consider the following code fragment in VS2010 Beta 1: let array = Array2D.zeroCreate 1000
I'm using VS2010 Beta 2, I have a Complex Type called Address with the
I am using VS2010 C#.NET 3.5 and application settings (the Settings.settings file). What I
I run my C code in vs2010 (win32 console application). It was compiled as

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.