Slowdown of pi calculation when Timer is used

北慕城南 提交于 2019-12-05 14:43:58

Am I missing something in the above code (e.g., wrong usage of Timer)?

No, you're not missing anything and are using Timer (and Chapel) in a completely reasonable way. From my own experimentation (which confirms yours and is noted in the comments under your question), this looks to be a back-end compiler issue rather than a fundamental problem in Chapel or your use of it.

[--fast] reduces run-time checks, yet not the issue may re-run here

Kindly may also note, how big are setup/operation add-on overheads,
brought in just for educational purposes
( to experiment with concurrent-processing ), that make the forall-constructor equipped with Atomics .add() method, accrue a way much higher overheads, than a concurrent-processing allow to gain, as there is so tiny computation inside the [PAR]-enabled fraction of the process ( ref. newly re-formulated Amdahl's Law on these too thin [PAR]-gains v/s indeed too high add-on overheads to the [SEQ]-costs ).

An exemplary message.

use Time;
var timer = new Timer();

config const n = 10**9;
         var s = 0.0, x = 0.0;
         var AtomiX: atomic real;                           // [AtomiX]______
             AtomiX.write( 0.0 );                           // [AtomiX]______

timer.start();                                              // [1]_____

for k in 0 .. n {
    s  = ( if k % 2 == 0 then 1.0 else -1.0 );     // (-1)^k
    x += s / ( 2.0 * k + 1.0 );
}

/* forall k in 0..n { AtomiX.add( ( if k % 2 == 0 then 1.0 else -1.0 )
                                / ( 2.0 * k + 1.0 )
                                  ); } */                   // [AtomiX]______

timer.stop();                                               // [2]_____
writeln( "time = ", timer.elapsed() );                      // [3]_____

   writef( "pi (approx) = %30.20dr\n", 4 * x );    
// writef( "pi (approx) = %30.20dr\n", 4 * AtimiX.read() ); // [AtomiX]______
// writef( "pi (exact)  = %30.20dr\n", pi );                // [4]_____

/*
--------------------------------------------------- [--fast] // AN EMPTY RUN
time = 1e-06

Real time:  9.582 s
User time:  8.479 s
Sys. time:  0.591 s
CPU share: 94.65 %
Exit code: 0
--------------------------------------------------- [--fast] // all commented

pi (approx) =         3.14159265458805059268

Real time: 15.553 s
User time: 13.484 s ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> Timer ~ +/- 1 second ( O/S noise )
Sys. time:  0.985 s
CPU share: 93.03 %
Exit code: 0
-------------------------------------------------- [--fast ] // Timer-un-commented
time = 5.30128
time = 5.3329
pi (approx) =         3.14159265458805059268

Real time: 14.356 s
User time: 13.047 s ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< Timer ~ +/- 1 second ( O/S noise )
Sys. time:  0.585 s
CPU share: 94.95 %
Exit code: 0

Real time: 16.804 s
User time: 14.853 s
Sys. time:  0.925 s
CPU share: 93.89 %
Exit code: 0

-------------------------------------------------- [--fast] // Timer-un-commented + forall + Atomics

time = 14.7406
pi (approx) =         3.14159265458805680993

Real time: 28.099 s
User time: 26.246 s
Sys. time: 0.914 s
CPU share: 96.65 %
Exit code: 0
*/
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!