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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:57:35+00:00 2026-06-11T23:57:35+00:00

Is it ok to use omp pragmas like critical, single, master, or barrier outside

  • 0

Is it ok to use omp pragmas like critical, single, master, or barrier outside of an omp parallel block? I have a function that can be called either from an OMP parallel block, or not. If yes, I need to enclose part of the code in a critical section. In other words, is this code fine?

void myfunc(){
    #pragma omp critical
    { /* code */ }
}

// not inside an omp parallel region
myfunc();

#pragma omp parallel
{
    // inside an omp parallel region
    myfunc();
}

I have found no mention of this in the OpenMP documentation. I guess the code should behave exactly like with 1 thread execution – and this is how it works with gcc. I would like to know if this behavior is portable, or is it something that the specification does not define and anything can be expected.

  • 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-11T23:57:37+00:00Added an answer on June 11, 2026 at 11:57 pm

    According to this document:

    The DO/for, SECTIONS, SINGLE, MASTER and BARRIER directives bind to the dynamically enclosing PARALLEL, if one exists. If no parallel region is currently being executed, the directives have no effect.

    So the answer is those pragmas can be used outside a parallel region. Although I still do not find it explicitly written in the documentation.

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

Sidebar

Related Questions

If I use nested parallel for loops like this: #pragma omp parallel for schedule(dynamic,1)
Can I use pragma omp parallel sections to solve two concurrent parts of my
Possible Duplicates: C/C++ pragma in define macro Conditional “pragma omp” How can I use
Which one can gain a better performance? Example 1 #pragma omp parallel for private
Is it OK to use loop increment greater than 1? #pragma omp parallel for
I have a C extension in which I'd like to use OpenMP. When I
I'm trying to use a simple #pragma omp parallel for under Visual Studio 10
To loop over elements of a container, I would typically use an iterator, like
USE master GO DECLARE @DbName nvarchar(MAX) SET @DbName = N'DataBase' ALTER DATABASE @DbName SET
I've got some code for which I'd like to use OpenMP in the following

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.