All ATOMIC references to the same storage location must use the same type.
The OpenMP* specification states that all references to a single storage location that appear on the left-hand side of an ATOMIC assignment anywhere in the program must use compatible types. Constructs that allow the program to refer to the same storage under different types (like C unions or FORTRAN EQUIVALENCE) must be used consistently. This error indicates that this rule is violated.
The ATOMIC construct always applies to a statement that reads a variable, computes a new value, and stores that value. Adding ATOMIC ensures that no other thread can read or write that same location in another ATOMIC region between the read and the write. This restriction allows the bookkeeping associated with this kind of lock to be more efficient. For example, suppose a thread wishes to execute an atomic update of an integer. Before granting access the system must ensure that no other thread is currently doing an atomic update of the same location. To answer this question, the implementation need only be concerned with other atomic updates of the same type.
ID |
Observation |
Description |
---|---|---|
1 |
OpenMP usage error |
The ATOMIC construct where the error was detected |
2 |
OpenMP usage error |
Another ATOMIC construct accessing the same address using a different type |
// Example A.20.1c from OpenMP 3.0 Specification // Copyright (C) 1997-2008 OpenMP Architecture Review Board void a20_1_wrong () { union {int n; float x;} u; #pragma omp parallel { #pragma omp atomic u.n++; #pragma omp atomic u.x += 1.0; /* Incorrect because the atomic constructs reference the same location through incompatible types */ } }Here is the same example in FORTRAN:
! Example A.20.1f from OpenMP 3.0 Specification ! Copyright (C) 1997-2008 OpenMP Architecture Review Board SUBROUTINE A20_1_WRONG() INTEGER:: I REAL:: R EQUIVALENCE(I,R) !$OMP PARALLEL !$OMP ATOMIC I = I + 1 !$OMP ATOMIC R = R + 1.0 ! incorrect because I and R reference the same location ! through incompatible types !$OMP END PARALLEL END SUBROUTINE A20_1_WRONG
Copyright © 1997-2008 OpenMP Architecture Review Board.
Permission to copy without fee all or part of this material is granted, provided the OpenMP Architecture Review Board copyright notice and the title of this document appear. Notice is given that copying is by permission of OpenMP Architecture Review Board.
Copyright © 2010, Intel Corporation. All rights reserved.