It appears that the locking example on page 38 of the UPC manual
is broken, on both Citris and Seaborg. This is the example that
calculates PI by integrating 1/(1+x^2).
The example code as-is has a minor error; it translates to C code
which indicates a `float' constant by the `F' suffix, which is
invalid C. Perhaps the UPC->C translator relies on syntax which
is specific to a particular C compiler?
More importantly, when I changed all the `float's to `double's,
the code does compile and link correctly, but outputs `PI=INF',
on both Citris and Seaborg. The locally computed values are also
all wrong, when more than one thread is specified at runtime.
I'm attaching `pi.c' (the original example code) and `pi_revised.c'
(which has all floats changed to doubles). The examples were
compiled as follows:
On Citris: upcc -save-temps -network=mpi <FILE>
On Seaborg: upcc -save-temps <FILE>
and were executed as follows on both platforms:
upcrun -n <NUMTHREADS> ./a.out
(<NUMTHREADS>: tested with 1, 2, 4).
It's entirely possible that I made a mistake somewhere, either in
typing out the example, the compilation step or the execution phase.
Please, somebody let me know as soon as possible if I did, since I
need to get UPC working for Homework 3 :) I'll keep checking to see
if I did make a mistake somewhere.
mfh
It's standard C99, but I can't figure out how to get the
C99 flag passed down to the C compiler. The upcc script
is chopping -std=gnu9x at the =.
- More importantly, when I changed all the `float's to `double's,
- the code does compile and link correctly, but outputs `PI=INF',
I get a more interesting wrong answer. ;) Note that the
limits of integration are switched in their diagram, too.
Somehow the code calculates things like 1/(1+0.1*0.1) == 101.
Cute.
If you break the calculation into steps, it works:
upc_forall(i=0;i<N;i++; i) {
double x, tmp;
x = (0.5 + i) / N;
tmp = 1.0+x*x;
tmp = 1.0/tmp;
local_pi += tmp;
}
I'll report this one, too.
Jason
--
An error in evaluating 1.0/(1.0+x*x) has been fixed in the
runtime. I've updated my copy for CITRIS, and others should
have updated theirs for Seaborg and Alvarez.
- The example code as-is has a minor error; it translates to C code
- which indicates a `float' constant by the `F' suffix, which is
- invalid C.
Two issues here:
Getting upcc to handle 0.0F: Use -Wc,-std=c98 for gcc,
similar flags for other compilers The -Wc only works
well for the "stable" front-end, not the 1.1 front-end.
Getting upcc not to generate 0F, which is illegal (iirc):
No fix yet.
- More importantly, when I changed all the `float's to `double's,
- the code does compile and link correctly, but outputs `PI=INF',
I'm finding that static shared doubles aren't being initialized
properly with the 1.1 remote translator, but they are with the
"nightly" one. I've set my CITRIS compiler to use the nightly
for now, and there are appropriate upc modules on Seaborg and
Alvarez (iirc).
Jason
--