User`s guide
Cray XMT™ Programming Environment User’s Guide
In these two cases, each reference to x$ results in a separate read of that variable
and requires a separate write to x$. The second write to x$ must be performed by a
thread other than the one executing the code in the example. In the first case, it might
have been the intention of the programmer to add together two successive values of
x$. If so, this code presents no problems provided the program contains additional
code that executes concurrently with the code in the example and performs the second
write to x$. In the second case, it is doubtful that the programmer's intention was to
compare two different values of x$. Also, due to the short-circuiting rules in C and
C++, there is no guarantee that the second read will occur. Thus, you could end up
with a deadlock whether or not have two writes to x$. If you have two writes, but
the second read does not occur due to short-circuiting, your code will deadlock due
to too many writes. On the other hand, if you have one write, and the second read
does occur, your code will deadlock due to too many reads. In both of these cases, if
the intention is to read only one value for x$, a temporary variable should be used,
as in this example:
tmpx = x$;
if ((tmpx >= 10) && (tmpx <= 100)){}
Deadlock can also occur when two or more concurrent functions access global sync
variables in a different order. For example, if a$ and b$ are global sync variables,
and the function fnc1 first loads a$ and then loads b$.
tmp_a = a$;
tmp_b = b$;
In the same program, function fnc2 first loads b$ and then loads a$.
tmp_b = b$;
tmp_a = a$;
If the functions run concurrently, then there is a chance of deadlock. If fnc2 loads
b$ after fnc1 loads a$, but before fnc1 loads b$, then neither function can
continue unless a third concurrently running function eventually writes to either a$ or
b$. You can avoid this problem by always accessing a$ and $b in the same order
each time you use them in functions that may be concurrent.
3.4 Programming Considerations for Floating-point Operations
The base arithmetic for floating-point operations on the Cray XMT uses the IEEE
Standard 754 format double precision (64-bit). A 64-bit floating-point number,
known as a Float64 on the Cray XMT, consists of a sign bit, an 11-bit exponent,
and 52 bits of fraction. Ordinary numbers (those with a biased exponent not equal to
zero or 0x7FF) have an exponent bias of 1023 (0x3FF) and their absolute value can
be expressed using the following equation:
(1.0 + fraction) << (exponent - 0x3FF)
The value is negative if the sign bit is set, positive if it is not set.
26 S–2479–20