The following code is my code for calculating pi = 3.1415 ... approximately using this formula:
use Time;
var timer = new Timer();
config const n = 10**9;
var x = 0.0, s = 0.0;
for k in 0 .. n {
s = ( if k % 2 == 0 then 1.0 else -1.0 );
x += s / ( 2.0 * k + 1.0 );
}
writef( "pi (approx) = %30.20dr\n", x * 4 );
When the above code is compiled as chpl --fast test.chpland executed as time ./a.out, it works with ~ 4 seconds as
pi (approx) = 3.14159265458805059268
real 0m4.334s
user 0m4.333s
sys 0m0.006s
On the other hand, if I uncomment the lines [1--3](for use Timer), the program runs much slower with ~ 10 seconds as
time = 10.2284
pi (approx) = 3.14159265458805059268
real 0m10.238s
user 0m10.219s
sys 0m0.018s
The same slowdown happens when I uncomment only the line [4](to print the built-in pi value when the lines [1-3]stayed in the know):
pi (approx) = 3.14159265458805059268
pi (exact) = 3.14159265358979311600
real 0m10.144s
user 0m10.141s
sys 0m0.009s
So, I wonder why this slowdown happens ...
- (, Timer)?
- OSX10.11 + chapel-1.16, .
:
$ printchplenv --anonymize
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: clang
CHPL_TARGET_ARCH: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_MAKE: make
CHPL_ATOMICS: intrinsics
CHPL_GMP: gmp
CHPL_HWLOC: hwloc
CHPL_REGEXP: re2
CHPL_WIDE_POINTERS: struct
CHPL_AUX_FILESYS: none
$ clang --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
, , this CHPL_TARGET_COMPILER=gnu ~/.chplconfig ( make). ~ 4 . , clang OSX10.11. , OSX ( >= 10.12) , OSX/clang ( >= 9.0). FYI, ( GNU) :
$ printchplenv --anonymize
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: gnu +
CHPL_TARGET_ARCH: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_MAKE: make
CHPL_ATOMICS: intrinsics
CHPL_GMP: none
CHPL_HWLOC: hwloc
CHPL_REGEXP: none
CHPL_WIDE_POINTERS: struct
CHPL_AUX_FILESYS: none