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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:04:13+00:00 2026-06-15T14:04:13+00:00

A compiler that implements the OpenMP standard may, but is not obliged to, exploit

  • 0

A compiler that implements the OpenMP standard may, but is not obliged to, exploit special hardware instructions to make certain memory updates following a #pragma omp atomic directive atomic, avoiding expensive locks. According to http://gcc.gnu.org/onlinedocs/gccint/OpenMP.html, GCC implements an atomic update as follows:

Whenever possible, an atomic update built-in is used. If that fails, a compare-and-swap loop is attempted. If that also fails, a regular critical section around the expression is used.

  1. How can I determine which of the three is actually used on a given machine and GCC version? Is there some verbosity option for GCC that I can set to find out without having to profile my program or look a the generated bytecode?

  2. Is there some documentation listing CPUs/architectures that provide atomic addition/increment/etc instructions, allowing me to predict the outcome for a given machine?

I’m using GCC versions 4.2 to 4.6 on a variety of different machines.

  • 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-15T14:04:13+00:00Added an answer on June 15, 2026 at 2:04 pm

    You may look at the intermediate tree representations with the -fdump-tree-all option. Given that option, GCC writes a set of files at several intermediate steps and one can observe the successive transformations applied to the tree. The .ompexp file is of particular interest here, since it contains the tree just after the OpenMP expressions were expanded into their concrete implementations.

    For example, the block inside the parallel region in the following simple code:

    int main (void)
    {
        int i = 0;
    
        #pragma omp parallel
        {
           #pragma omp atomic
           i++;
        }
    
        return i;
    }
    

    is transformed by GCC 4.7.2 on 64-bit Linux into:

    ;; Function main._omp_fn.0 (main._omp_fn.0, funcdef_no=1, decl_uid=1712, cgraph_uid=1)
    
    main._omp_fn.0 (struct .omp_data_s.0 * .omp_data_i)
    {
      int D.1726;
      int D.1725;
      int i [value-expr: *.omp_data_i->i];
      int * D.1723;
      int * D.1722;
    
    <bb 2>:
      D.1722_2 = .omp_data_i_1(D)->i;
      D.1723_3 = &*D.1722_2;
      __atomic_fetch_add_4 (D.1723_3, 1, 0);
      return;
    
    }
    

    which finally ends into:

    00000000004006af <main._omp_fn.0>:
      4006af:       55                      push   %rbp
      4006b0:       48 89 e5                mov    %rsp,%rbp
      4006b3:       48 89 7d f8             mov    %rdi,-0x8(%rbp)
      4006b7:       48 8b 45 f8             mov    -0x8(%rbp),%rax
      4006bb:       48 8b 00                mov    (%rax),%rax
      4006be:       f0 83 00 01             lock addl $0x1,(%rax)
      4006c2:       5d                      pop    %rbp
      4006c3:       c3                      retq
    

    As for the second question, it might also depend on how GCC was built.

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

Sidebar

Related Questions

I know that C++11 provides <atomic> , but this isn't implemented by any compiler
I'm trying to write a class that implements 64-bit ints for a compiler that
SOLVED! This works, I need to tell the compiler that T implements IEquatable of
We wrote a small Windows class library that implements extension methods for some standard
This doesn't seem to work (compiler complains that Something 's getFoo() method doesn't implement
I have a cross compiler that specifies a custom loader in its .interp header:
Is there any compiler that has a directive or a parameter to cast integer
I was working with a polyhedral compiler that produce quite unreadable code, here is
I have studied that The inline specifier is a hint to the compiler that
I am looking for a Lua front-end compiler that is type-checked at compile time,

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.