templeos-info/public/Wb/Demo/MultiCore/MPAdd.HC.HTML

117 lines
8.9 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF9>I64</span><span class=cF0> mp_n;
<a name="l2"></a>
<a name="l3"></a></span><span class=cF9>I64</span><span class=cF0> MPSum(</span><span class=cF9>I64</span><span class=cF0> my_mp_cnt)
<a name="l4"></a>{</span><span class=cF2>//We could use the formula n*(n+1)/2</span><span class=cF0>
<a name="l5"></a> </span><span class=cF9>I64</span><span class=cF0> lo=mp_n*</span><span class=cF5>Gs</span><span class=cF0>-&gt;num/my_mp_cnt,
<a name="l6"></a> hi=mp_n*(</span><span class=cF5>Gs</span><span class=cF0>-&gt;num+1)/my_mp_cnt,
<a name="l7"></a> res=0,i;
<a name="l8"></a> </span><span class=cF1>for</span><span class=cF0> (i=lo;i&lt;hi;i++)
<a name="l9"></a> res+=i;
<a name="l10"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l11"></a>}
<a name="l12"></a>
<a name="l13"></a></span><span class=cF9>I64</span><span class=cF0> Sum(</span><span class=cF9>I64</span><span class=cF0> n,</span><span class=cF9>I64</span><span class=cF0> my_mp_cnt)
<a name="l14"></a>{
<a name="l15"></a> </span><span class=cF9>CJob</span><span class=cF0> *tmpm[</span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>];
<a name="l16"></a> </span><span class=cF9>I64</span><span class=cF0> res=0,i;
<a name="l17"></a> mp_n=n+1;
<a name="l18"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;my_mp_cnt;i++)
<a name="l19"></a> tmpm[i]=</span><span class=cF5>JobQue</span><span class=cF0>(&amp;MPSum,my_mp_cnt,i,0);
<a name="l20"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;my_mp_cnt;i++)
<a name="l21"></a> res+=</span><span class=cF5>JobResGet</span><span class=cF0>(tmpm[i]);
<a name="l22"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l23"></a>}
<a name="l24"></a>
<a name="l25"></a>#</span><span class=cF1>define</span><span class=cF0> SAMPLE_SIZE 100
<a name="l26"></a>
<a name="l27"></a></span><span class=cF1>F64</span><span class=cF0> Test(</span><span class=cF9>I64</span><span class=cF0> n,</span><span class=cF9>I64</span><span class=cF0> my_mp_cnt)
<a name="l28"></a>{
<a name="l29"></a> </span><span class=cF9>I64</span><span class=cF0> i,val=0;
<a name="l30"></a> </span><span class=cF1>F64</span><span class=cF0> </span><span class=cF1>start</span><span class=cF0>,</span><span class=cF1>end</span><span class=cF0>;
<a name="l31"></a> </span><span class=cF1>start</span><span class=cF0>=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l32"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;SAMPLE_SIZE;i++)
<a name="l33"></a> val+=Sum(n,my_mp_cnt);
<a name="l34"></a> </span><span class=cF1>end</span><span class=cF0>=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l35"></a> </span><span class=cF6>&quot;Val:%,d\n&quot;</span><span class=cF0>,val/SAMPLE_SIZE;
<a name="l36"></a> </span><span class=cF6>&quot;$RED$N:%12,d Time:%10.8f$FG$\n&quot;</span><span class=cF0>,n,(</span><span class=cF1>end</span><span class=cF0>-</span><span class=cF1>start</span><span class=cF0>)/SAMPLE_SIZE;
<a name="l37"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF1>end</span><span class=cF0>-</span><span class=cF1>start</span><span class=cF0>;
<a name="l38"></a>}
<a name="l39"></a>
<a name="l40"></a>#</span><span class=cF1>define</span><span class=cF0> VAL_MIN 1000
<a name="l41"></a>#</span><span class=cF1>define</span><span class=cF0> TEST_MIN 3
<a name="l42"></a>#</span><span class=cF1>define</span><span class=cF0> TEST_MAX 7
<a name="l43"></a>#</span><span class=cF1>define</span><span class=cF0> TESTS_NUM (TEST_MAX-TEST_MIN+1)
<a name="l44"></a>#</span><span class=cF1>define</span><span class=cF0> PERCENT_MAX 200
<a name="l45"></a>
<a name="l46"></a></span><span class=cF1>U0</span><span class=cF0> MPAdd()
<a name="l47"></a>{
<a name="l48"></a> </span><span class=cF9>I64</span><span class=cF0> i,n,
<a name="l49"></a> h=</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_width,
<a name="l50"></a> v=</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_height;
<a name="l51"></a> </span><span class=cF1>F64</span><span class=cF0> t1,t2,ress[TESTS_NUM];
<a name="l52"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc=</span><span class=cF5>DCAlias</span><span class=cF0>;
<a name="l53"></a>
<a name="l54"></a> </span><span class=cF1>for</span><span class=cF0> (i=0,n=VAL_MIN;i&lt;TESTS_NUM;i++,n*=10) </span><span class=cF7>{</span><span class=cF0>
<a name="l55"></a> t1=Test(n,1);
<a name="l56"></a> t2=Test(n,</span><span class=cFB>mp_cnt</span><span class=cF0>);
<a name="l57"></a> ress[i]=t2*100.0/t1;
<a name="l58"></a> </span><span class=cF6>&quot;$GREEN$%8.4f%%$FG$\n\n&quot;</span><span class=cF0>,ress[i];
<a name="l59"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l60"></a> </span><span class=cF5>PressAKey</span><span class=cF0>;
<a name="l61"></a>
<a name="l62"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l63"></a>
<a name="l64"></a> dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l65"></a> </span><span class=cF1>for</span><span class=cF0> (i=PERCENT_MAX/10;i&lt;PERCENT_MAX;i+=PERCENT_MAX/10) </span><span class=cF7>{</span><span class=cF0>
<a name="l66"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,0,v-</span><span class=cF5>ToF64</span><span class=cF7>(</span><span class=cF0>i</span><span class=cF7>)</span><span class=cF0>/PERCENT_MAX*v-</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>,</span><span class=cF6>&quot;%3d%%&quot;</span><span class=cF0>,i);
<a name="l67"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,0,v-</span><span class=cF5>ToF64</span><span class=cF7>(</span><span class=cF0>i</span><span class=cF7>)</span><span class=cF0>/PERCENT_MAX*v,h,v-</span><span class=cF5>ToF64</span><span class=cF7>(</span><span class=cF0>i</span><span class=cF7>)</span><span class=cF0>/PERCENT_MAX*v);
<a name="l68"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l69"></a>
<a name="l70"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TESTS_NUM-1;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l71"></a> dc-&gt;color=</span><span class=cF3>RED</span><span class=cF0>;
<a name="l72"></a> dc-&gt;thick=2;
<a name="l73"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,i*h/</span><span class=cF7>(</span><span class=cF0>TESTS_NUM-1</span><span class=cF7>)</span><span class=cF0>, v-ress[i ]/PERCENT_MAX*v,0,
<a name="l74"></a> </span><span class=cF7>(</span><span class=cF0>i+1</span><span class=cF7>)</span><span class=cF0>*h/</span><span class=cF7>(</span><span class=cF0>TESTS_NUM-1</span><span class=cF7>)</span><span class=cF0>,v-ress[i+1]/PERCENT_MAX*v,0);
<a name="l75"></a> dc-&gt;color=</span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l76"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,i*h/</span><span class=cF7>(</span><span class=cF0>TESTS_NUM-1</span><span class=cF7>)</span><span class=cF0>,v-</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>,</span><span class=cF6>&quot;10e%d&quot;</span><span class=cF0>,i+TEST_MIN);
<a name="l77"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,i*h/</span><span class=cF7>(</span><span class=cF0>TESTS_NUM-1</span><span class=cF7>)</span><span class=cF0>,0,i*h/</span><span class=cF7>(</span><span class=cF0>TESTS_NUM-1</span><span class=cF7>)</span><span class=cF0>,v);
<a name="l78"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l79"></a> </span><span class=cF5>PressAKey</span><span class=cF0>;
<a name="l80"></a>
<a name="l81"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l82"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l83"></a>}
<a name="l84"></a>
<a name="l85"></a>MPAdd;
</span></pre></body>
</html>