<?xml version="1.0"?>
<rss version="2.0">
   <channel>
      <title>240-441 MPA by PICHAYA TANDAYYA</title>
      <link>https://padlet.com/pichayat/240441</link>
      <description>Help Desk</description>
      <language>en-us</language>
      <pubDate>2021-12-30 03:45:03 UTC</pubDate>
      <lastBuildDate>2026-01-19 23:54:38 UTC</lastBuildDate>
      <webMaster>hello@padlet.com</webMaster>
      <image>
         <url>https://padlet.net/icons/png/1f4bb.png</url>
      </image>
      <item>
         <title>โพสต์ที่ได้รับการช่วยเหลือและสำเร็จแล้ว (สีเขียว)</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968429288</link>
         <description><![CDATA[<div>โพสต์ที่ได้รับการช่วยเหลือแล้ว และสำเร็จตามความต้องการ จาก TA จะย้ายมาอยู่ทางซ้ายของโพสต์ ที่มี Helpdesk icon และจะปรับพื้นหลังเป็นสีเขียว</div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 03:45:03 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968429288</guid>
      </item>
      <item>
         <title>โพสต์ปัญหาที่ต้องการความช่วยเหลือพร้อมรหัส  AnyDesk</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968429291</link>
         <description><![CDATA[<div>1. เขียนคำอธิบายปัญหา<br>2. แนบรูปหน้าจอประกอบ</div>]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/551945409/822188f3275b63faa3ed0cc4ffb9946b/HelpDesk.png" />
         <pubDate>2021-12-30 03:45:03 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968429291</guid>
      </item>
      <item>
         <title>โพสต์ปัญหาใหม่ (สีขาว)</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968429292</link>
         <description><![CDATA[<div>โพสต์ใหม่ที่ยังไม่ได้รับการช่วยเหลือจาก TA จะอยู่ทางขวาของ Helpdesk icon โพสต์และจะมีพื้นหลังสีขาว</div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 03:45:03 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968429292</guid>
      </item>
      <item>
         <title>โพสต์ข้อมูลแนะนำ (สีฟ้า)</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968429293</link>
         <description><![CDATA[<div>สีพื้นหลังโพสต์จะความหมายดังนี้<br>สีขาว - ขอความช่วยเหลือใหม่<br>สีเหลือง - กำลังเข้าช่วยเหลือ<br>สีเขียว - ช่วยเหลือสำเร็จแล้ว<br>สีฟ้า - ข้อมูลทั่วไปสำหรับทุกคน<br>ขอให้ทุกคนเลือกสีตามที่กำหนด</div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 03:45:03 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968429293</guid>
      </item>
      <item>
         <title>โพสต์กำลังดำเนินการ (สีเหลือง)</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968429294</link>
         <description><![CDATA[<div>TA กำลังให้คำแนะนำและกำลังดำเนินการแก้ปัญหา</div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 03:45:03 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968429294</guid>
      </item>
      <item>
         <title>Program 0</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968447898</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br><br>namespace prog2017_000_your_first_csharp<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; public const int arr_sz = 10;<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] a = new int[arr_sz];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] b = new int[arr_sz];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] c = new int[arr_sz];<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //----initial value in a<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; arr_sz; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a[i] = i + 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b[i] = i * 10;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("a[{0} = {1}\t\tb[{0} = {2}", i, a[i], b[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //----using for loop<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; arr_sz; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c[i] = a[i] + b[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("c[{0}]={1}", i, c[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadKey();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 04:11:16 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968447898</guid>
      </item>
      <item>
         <title>Program 1</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968448224</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Threading;<br><br>namespace prog2017_001_first_parallel_loop<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int x;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Using conventional C# For Loop \n");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (x = 0; x &lt;= 20; x++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("x = {0}, thread = {1}",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("------------------------------------------------------");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("\nUsing Parallel.For \n");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, 20, i =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("i = {0}, thread = {1}", i,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 1; i &lt; 12; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("{0}. {0}*{0}={1}", i, i * i);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 04:11:47 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968448224</guid>
      </item>
      <item>
         <title>Program 2</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1968462770</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Threading;<br>using System.Diagnostics;<br><br>namespace prog2017_002_of_LMS_add_array1<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; public const int arr_sz = 70000000;<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopwatch myStopWatch1 = new Stopwatch();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopwatch myStopWatch2 = new Stopwatch();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long exe_time_for, exe_time_parallel_for;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] a = new int[arr_sz];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] b = new int[arr_sz];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] c = new int[arr_sz];<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //----initial value in a<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i=0;i&lt;arr_sz;i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a[i] = i + 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b[i] = i * 10;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myStopWatch1.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //----using for loop<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i=0;i&lt;arr_sz;i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c[i] = a[i] + b[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; Console.WriteLine("c[{0}]={1}", i, c[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myStopWatch1.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exe_time_for = myStopWatch1.ElapsedMilliseconds;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Console.ReadKey();<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myStopWatch2.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, arr_sz, x=&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c[x] = a[x] + b[x];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; Console.WriteLine("thread id= {0},&nbsp; c[{1}]={2}",Thread.CurrentThread.ManagedThreadId, x, c[x]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myStopWatch2.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exe_time_parallel_for = myStopWatch2.ElapsedMilliseconds;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time of normal for = {0}", exe_time_for);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time of parallel for&nbsp; = {0}", exe_time_parallel_for);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadKey();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2021-12-30 04:33:39 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1968462770</guid>
      </item>
      <item>
         <title>กราฟ</title>
         <author>6110110490</author>
         <link>https://padlet.com/pichayat/240441/wish/1979917921</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526961197/7cd4052c153f458d6a63a91245ead518/6110110490__2_.png" />
         <pubDate>2022-01-07 03:24:13 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979917921</guid>
      </item>
      <item>
         <title></title>
         <author>6110110415</author>
         <link>https://padlet.com/pichayat/240441/wish/1979919069</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518604267/c1c21acd5cd1330f5ed7b4b862f1254c/270814367_633202544498922_5662982403912998748_n.jpg" />
         <pubDate>2022-01-07 03:25:11 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979919069</guid>
      </item>
      <item>
         <title>6110110566 Aekkasit</title>
         <author></author>
         <link>https://padlet.com/pichayat/240441/wish/1979919808</link>
         <description><![CDATA[<div>No input<br><br></div>]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518600390/d05bd2955779d4d2ba783016c1f5db3f/55.jpg" />
         <pubDate>2022-01-07 03:25:47 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979919808</guid>
      </item>
      <item>
         <title></title>
         <author>6210110139</author>
         <link>https://padlet.com/pichayat/240441/wish/1979920011</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526963026/33d135e001a13a5923f2edc578df2b2d/6210110139__1_.jpg" />
         <pubDate>2022-01-07 03:25:58 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979920011</guid>
      </item>
      <item>
         <title></title>
         <author>6110110044</author>
         <link>https://padlet.com/pichayat/240441/wish/1979920210</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518603992/37eb7805e48aee086a811f02e7351945/271362165_350238343199302_7471562665585788314_n.jpg" />
         <pubDate>2022-01-07 03:26:10 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979920210</guid>
      </item>
      <item>
         <title></title>
         <author>6110110015</author>
         <link>https://padlet.com/pichayat/240441/wish/1979920454</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526964451/3a24acd444aae1ff615114efb7907224/269695436_1057232335129405_9154794101162276866_n.jpg" />
         <pubDate>2022-01-07 03:26:22 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979920454</guid>
      </item>
      <item>
         <title>6110110404</title>
         <author>6110110404</author>
         <link>https://padlet.com/pichayat/240441/wish/1979921289</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1489002560/05068a03c5f4c4f14417a0601d19f538/6110110404.png" />
         <pubDate>2022-01-07 03:27:04 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979921289</guid>
      </item>
      <item>
         <title></title>
         <author>6110110019</author>
         <link>https://padlet.com/pichayat/240441/wish/1979922775</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526962871/0bef815264934454683976fbeb21c0dd/270866524_483219103452321_329549669517368688_n.jpg" />
         <pubDate>2022-01-07 03:28:25 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979922775</guid>
      </item>
      <item>
         <title></title>
         <author>6110110490</author>
         <link>https://padlet.com/pichayat/240441/wish/1979923755</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526961197/62115e58bbfaffe38b73a3ae1e4c2f99/2022_01_07__3_.png" />
         <pubDate>2022-01-07 03:29:18 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979923755</guid>
      </item>
      <item>
         <title>6110110566(แก้)</title>
         <author>6110110566</author>
         <link>https://padlet.com/pichayat/240441/wish/1979926282</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518602011/980f073bee912e003a726f7867a08268/66.jpg" />
         <pubDate>2022-01-07 03:31:54 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1979926282</guid>
      </item>
      <item>
         <title>วาดไดอะแกรมความเข้าใจของ  TAS ของคุณ</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1989571146</link>
         <description><![CDATA[]]></description>
         <enclosure url="" />
         <pubDate>2022-01-13 04:09:31 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989571146</guid>
      </item>
      <item>
         <title></title>
         <author>6210110139</author>
         <link>https://padlet.com/pichayat/240441/wish/1989582313</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526963026/c32a1ec3b2700d3c54536c7163a4428f/test.png" />
         <pubDate>2022-01-13 04:19:03 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989582313</guid>
      </item>
      <item>
         <title></title>
         <author>6110110490</author>
         <link>https://padlet.com/pichayat/240441/wish/1989583498</link>
         <description><![CDATA[<div><br><br></div>]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1526961197/db6687c37a50df0c060b2702f978a251/2022_01_13.png" />
         <pubDate>2022-01-13 04:20:08 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989583498</guid>
      </item>
      <item>
         <title>6110110144</title>
         <author>6110110144</author>
         <link>https://padlet.com/pichayat/240441/wish/1989583622</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518609632/19ca9edea01ebcf2dc5536b92195bc84/6110110144.png" />
         <pubDate>2022-01-13 04:20:15 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989583622</guid>
      </item>
      <item>
         <title></title>
         <author>6110110415</author>
         <link>https://padlet.com/pichayat/240441/wish/1989585108</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518604267/7c50ca66601655fba869d55cc0ae87e4/271663714_456059936253065_2783255714777478866_n.jpg" />
         <pubDate>2022-01-13 04:21:36 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989585108</guid>
      </item>
      <item>
         <title>6110110566</title>
         <author>6110110566</author>
         <link>https://padlet.com/pichayat/240441/wish/1989587833</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518602011/6c3bbcdb323ac1e3e5e1f0088a9d91d6/image.png" />
         <pubDate>2022-01-13 04:24:00 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989587833</guid>
      </item>
      <item>
         <title></title>
         <author></author>
         <link>https://padlet.com/pichayat/240441/wish/1989588908</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1535091230/98a28566b1a303090817ab09bb91941c/test_and_lock.jpg" />
         <pubDate>2022-01-13 04:24:56 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989588908</guid>
      </item>
      <item>
         <title></title>
         <author>6110110404</author>
         <link>https://padlet.com/pichayat/240441/wish/1989589711</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1489002560/e797e66af3ffa0617b46889e59bc0e3f/6110110404.PNG" />
         <pubDate>2022-01-13 04:25:37 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989589711</guid>
      </item>
      <item>
         <title></title>
         <author></author>
         <link>https://padlet.com/pichayat/240441/wish/1989590623</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1518600047/4913b36bfaa74199b34a53394b0550f2/zz.jpg" />
         <pubDate>2022-01-13 04:26:19 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989590623</guid>
      </item>
      <item>
         <title></title>
         <author>6110110516</author>
         <link>https://padlet.com/pichayat/240441/wish/1989601854</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/1535114392/c3493999d7d1681de346313e09b607f3/270080753_994504947821153_6639178703749258574_n.jpg" />
         <pubDate>2022-01-13 04:36:56 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1989601854</guid>
      </item>
      <item>
         <title>010 Parallel Task Question Prove</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991587866</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br>//--see http://www.dotnetcurry.com/showarticle.aspx?ID=491<br><br><br>namespace _010_parallel_task_question_prove<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br><br>//---------------------------------------------------------------------------------------------------------------<br>//---approach 1: Use the constructor of the Task(Of TResult) class to initialize the task but execute it later<br>//---------------------------------------------------------------------------------------------------------------<br>/*<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t1 = new Task&lt;int&gt;(GenerateNumbers);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;string&gt;&nbsp; &nbsp; t2 = new Task&lt;string&gt;(PrintCharacters);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t3 = new Task&lt;int&gt;(PrintArray);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Start the tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t3.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Numbers generated till {0}", t1.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp;*/<br><br>//---------------------------------------------------------------------------------------------------------------<br>//---approach 2: using Task&lt;&gt;.Factory.StartNew() to initialize and execute the task at the same time<br>//---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create and execute the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t1 = Task&lt;int&gt;.Factory.StartNew(() =&gt; GenerateNumbers());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t2 = Task&lt;string&gt;.Factory.StartNew(() =&gt; PrintCharacters());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t3 = Task&lt;int&gt;.Factory.StartNew(() =&gt; PrintArray());<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Numbers generated till {0}", t1.Result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int GenerateNumbers()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; 7; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method1 - Number: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(1000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return i;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static string PrintCharacters()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string str = "dotnet";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; str.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method2 - Character: {0}", str[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(100);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return str;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int PrintArray()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = { 1, 2, 3, 4, 5 };<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (int i in arr)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method3 - Array: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return arr.Count();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:13:05 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991587866</guid>
      </item>
      <item>
         <title>001 Try Parallel Loop 1st</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991589705</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br><br>namespace _001_try_parallel_loop1st<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int x;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Using conventional C# For Loop \n");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (x = 0; x &lt;= 20; x++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("x = {0}, thread = {1}",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x , Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("------------------------------------------------------");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("\nUsing Parallel.For \n");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, 20, i =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("i = {0}, thread = {1}", i,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:14:58 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991589705</guid>
      </item>
      <item>
         <title>001 Parallel Loop Racing Condition 1</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991598137</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br><br>//---see http://stackoverflow.com/questions/2774170/parallel-for-update-variable-outside-of-loop to overcome the problem<br>//---see the corrected version in 013_parallel_loop_racing_corrected1 &nbsp; method1<br>//---&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and &nbsp; 014_parallel_loop_racing_corrected2 &nbsp; method2<br><br>namespace _011_parallel_loop_racing_condition1<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = new int[1000];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i, sum = 0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; 1000; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr[i] = i;<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---sequential&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; arr.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += arr[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\nSequential Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+999 = {0}", sum);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\n\n\n");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, arr.Length, j =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += arr[j];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\nParallel Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+999 = {0}", sum);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:22:41 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991598137</guid>
      </item>
      <item>
         <title>012 Parallel Loop Racing Condition 2</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991599371</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br><br>//---see http://stackoverflow.com/questions/2774170/parallel-for-update-variable-outside-of-loop for error corrections<br>//--- the problem of parallel aggregation<br><br><br>namespace _012_parallel_loop_racing_condition2<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const int data_size = 5000000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] data = new int[data_size];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double result_serial, result_parallel;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_serial = 0.0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel = 0.0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---initial values in the array<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; data.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data[i] = i * i;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopwatch stopWatch = new Stopwatch();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long ex_time_serial, ex_time_parallel;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---sequential&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; data.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_serial += ((Math.Sin((double)data[i]) - Math.Cos((double)data[i])) /&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Math.Sin((double)data[i]) + Math.Cos((double)data[i])));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_serial = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\nSequential Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result = {0}", result_serial);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time = {0}", ex_time_serial);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object lockObject = new object();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.ForEach(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The values to be aggregated&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The local initial partial result<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; () =&gt; 0.0d,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The loop body<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (x, loopState, partialResult) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double r_sin, r_cos;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r_sin = Math.Sin((double)x);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r_cos = Math.Cos((double)x);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //local_result += (r_sin - r_cos) / (r_cos + r_sin);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (r_sin - r_cos) / (r_cos + r_sin) + partialResult;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The final step of each local context&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (localPartialSum) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Enforce serial access to single, shared result<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lock (lockObject)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel += localPartialSum;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Parallel Program using Parallel-aggregation pattern");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result = {0}", result_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time = {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}</div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:23:51 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991599371</guid>
      </item>
      <item>
         <title>013 Parallel Loop Racing Corrected 1</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991601655</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br><br><br>//---see http://stackoverflow.com/questions/2774170/parallel-for-update-variable-outside-of-loop<br>//---correct the problem of 011_parallel_loop_racing_condition1 with Interlocked.Add<br><br>namespace _013_parallel_loop_racing_corrected1<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const int a_size = 1000000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = new int[a_size];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i, sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopwatch stopWatch = new Stopwatch();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long ex_time_serial, ex_time_parallel;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; a_size; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr[i] = i;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---sequential&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; arr.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += arr[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_serial = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\nSequential Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+999999 = {0}", sum);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("processing time = {0}", ex_time_serial);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\n\n\n");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, arr.Length, j =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Interlocked.Add(ref sum, arr[j]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //sum += arr[j];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\nParallel Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+999999 = {0}", sum);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("processing time = {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:26:01 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991601655</guid>
      </item>
      <item>
         <title>014 Parallel Loop Racing Corrected 2</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991602790</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Diagnostics;<br>using System.Threading;<br>using System.Threading.Tasks;<br><br>//---see http://stackoverflow.com/questions/2774170/parallel-for-update-variable-outside-of-loop<br>//---see http://msdn.microsoft.com/en-us/library/dd460703.aspx<br><br>namespace _014_parallel_loop_racing_corrected2<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //ParallelOptions options = new ParallelOptions();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //options.MaxDegreeOfParallelism = 2;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const int a_size = 100000000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = new int[a_size];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long sum = 0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopwatch stopWatch = new Stopwatch();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long ex_time_serial, ex_time_parallel;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; a_size; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr[i] = i;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---sequential&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; arr.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += arr[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_serial = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("======================================================================\nSequential Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+{1} = {0}", sum,a_size-1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("processing time = {0}", ex_time_serial);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("======================================================================\n\n\n");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel using thread-local variables&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Use type parameter to make subtotal a long, not an int<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For&lt;long&gt;(0, arr.Length, () =&gt; 0, (j, loop, partial_sum) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partial_sum += arr[j];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return partial_sum;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (x) =&gt; Interlocked.Add(ref sum, x)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("=================================================================\nParallel Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+{1} = {0}", sum, a_size - 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("processing time using thread local variable= {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("=================================================================\n\n\n");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel using parallel aggregation<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object lockObject = new object();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.ForEach&lt;int,long&gt;(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The values to be aggregated&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The local initial partial result<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; () =&gt; 0,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The loop body<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (xx, loopState, partialResult) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return xx + partialResult;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The final step of each local context&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (localPartialSum) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Enforce serial access to single, shared result<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lock (lockObject)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += localPartialSum;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("=================================================================\nParallel Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+{1} = {0}", sum, a_size - 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("processing time using parallel aggregation= {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("=================================================================\n\n\n");<br><br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel using Interlocked.add<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For (0, arr.Length, j =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Interlocked.Add(ref sum, arr[j]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("=================================================================\nParallel Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result of 1+2+...+{1} = {0}", sum, a_size - 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("processing time using Interlocked.Add = {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("=================================================================\n\n\n");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:27:15 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991602790</guid>
      </item>
      <item>
         <title>015 Parallel Task Wait All</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991603723</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br>//--see http://www.dotnetcurry.com/showarticle.aspx?ID=491<br><br><br>namespace _015_parallel_task_wait_ALL<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---approach 1: Use the constructor of the Task(Of TResult) class to initialize the task but execute it later<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t1 = new Task&lt;int&gt;(GenerateNumbers);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;string&gt;&nbsp; &nbsp; t2 = new Task&lt;string&gt;(PrintCharacters);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t3 = new Task&lt;int&gt;(PrintArray);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Start the tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t3.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Numbers generated till {0}", t1.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---approach 2: using Task&lt;&gt;.Factory.StartNew() to initialize and execute the task at the same time<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create and execute the Tasks<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t1 = Task&lt;int&gt;.Factory.StartNew(() =&gt; GenerateNumbers());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t2 = Task&lt;string&gt;.Factory.StartNew(() =&gt; PrintCharacters());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t3 = Task&lt;int&gt;.Factory.StartNew(() =&gt; PrintArray());<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Task.WaitAny(t1, t2, t3);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; 10; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(2);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("main task\n");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t3&gt;Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t2&gt;Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t1&gt;Numbers generated till {0}", t1.Result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int GenerateNumbers()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; 7; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method1 - Number: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(1000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return i;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static string PrintCharacters()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string str = "dotnet";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; str.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method2 - Character: {0}", str[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(100);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return str;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int PrintArray()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = { 1, 2, 3, 4, 5 };<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (int i in arr)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method3 - Array: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return arr.Count();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:28:09 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991603723</guid>
      </item>
      <item>
         <title>016 Parallel Task Wait All 2</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991604841</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br>//--see http://www.dotnetcurry.com/showarticle.aspx?ID=491<br><br><br>namespace _016_parallel_task_wait_all2<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br><br>//---------------------------------------------------------------------------------------------------------------<br>//---approach 1: Use the constructor of the Task(Of TResult) class to initialize the task but execute it later<br>//---------------------------------------------------------------------------------------------------------------<br>/*<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t1 = new Task&lt;int&gt;(GenerateNumbers);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;string&gt;&nbsp; &nbsp; t2 = new Task&lt;string&gt;(PrintCharacters);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t3 = new Task&lt;int&gt;(PrintArray);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Start the tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t3.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Numbers generated till {0}", t1.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp;*/<br><br>//---------------------------------------------------------------------------------------------------------------<br>//---approach 2: using Task&lt;&gt;.Factory.StartNew() to initialize and execute the task at the same time<br>//---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create and execute the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t1 = Task&lt;int&gt;.Factory.StartNew(() =&gt; GenerateNumbers());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t2 = Task&lt;string&gt;.Factory.StartNew(() =&gt; PrintCharacters());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t3 = Task&lt;int&gt;.Factory.StartNew(() =&gt; PrintArray());<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int x = 0; x &lt; 100; x++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("{0} ", x);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Task.WaitAll(t1, t2, t3);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t3&gt;Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t2&gt;Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t1&gt;Numbers generated till {0}", t1.Result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int GenerateNumbers()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; 7; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method1 - Number: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(3000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return i;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static string PrintCharacters()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string str = "dotnet";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; str.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method2 - Character: {0}", str[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(300);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return str;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int PrintArray()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = { 1, 2, 3, 4, 5 };<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (int i in arr)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method3 - Array: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(30);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return arr.Count();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:29:15 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991604841</guid>
      </item>
      <item>
         <title>017 Parallel Task Wait Any 1</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991606062</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br>using System.Threading.Tasks;<br>//--see http://www.dotnetcurry.com/showarticle.aspx?ID=491<br><br><br>namespace _017_parallel_task_waitAny1<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br><br>//---------------------------------------------------------------------------------------------------------------<br>//---approach 1: Use the constructor of the Task(Of TResult) class to initialize the task but execute it later<br>//---------------------------------------------------------------------------------------------------------------<br>/*<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t1 = new Task&lt;int&gt;(GenerateNumbers);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;string&gt;&nbsp; &nbsp; t2 = new Task&lt;string&gt;(PrintCharacters);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt;&nbsp; &nbsp; &nbsp; &nbsp;t3 = new Task&lt;int&gt;(PrintArray);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Start the tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t3.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Print Return Value<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Numbers generated till {0}", t1.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp;*/<br><br>//---------------------------------------------------------------------------------------------------------------<br>//---approach 2: using Task&lt;&gt;.Factory.StartNew() to initialize and execute the task at the same time<br>//---------------------------------------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create and execute the Tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t1 = Task&lt;int&gt;.Factory.StartNew(()&nbsp; &nbsp; &nbsp; =&gt; GenerateNumbers());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t2 = Task&lt;string&gt;.Factory.StartNew(() &nbsp; =&gt; PrintCharacters());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t3 = Task&lt;int&gt;.Factory.StartNew(()&nbsp; &nbsp; &nbsp; =&gt; PrintArray());<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task.WaitAny(t1, t2, t3);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("After one fastest has been completed");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t3&gt;Array Count {0}", t3.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t2&gt;Original String {0}", t2.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("&lt;result t1&gt;Numbers generated till {0}", t1.Result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int GenerateNumbers()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; 7; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method1 - Number: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(1000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return i;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static string PrintCharacters()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string str = "dotnet";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; str.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method2 - Character: {0}", str[i]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(100);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return str;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int PrintArray()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] arr = { 1, 2, 3, 4, 5 };<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (int i in arr)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Method3 - Array: {0}", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return arr.Count();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:30:24 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991606062</guid>
      </item>
      <item>
         <title>ส่ง  Spec เครื่องของคุณ</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991614678</link>
         <description><![CDATA[]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 03:39:05 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991614678</guid>
      </item>
      <item>
         <title>Try Image Bitmap 01</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991657275</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Drawing;<br><br><br>namespace try_image_bitmap01<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; public void SetPixel_Example()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create a Bitmap object from a file.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap myBitmap = new Bitmap("Grapes.jpg");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Draw myBitmap to the screen.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myBitmap.Height);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set each pixel in myBitmap to black.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int Xcount = 0; Xcount &lt; myBitmap.Width; Xcount++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int Ycount = 0; Ycount &lt; myBitmap.Height; Ycount++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myBitmap.SetPixel(Xcount, Ycount, Color.Black);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Draw myBitmap to the screen again.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myBitmap.Width, myBitmap.Height);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 04:20:19 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991657275</guid>
      </item>
      <item>
         <title>018 Parallel Task Image Blender</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991664106</link>
         <description><![CDATA[<div>//===============================================================================<br>// Microsoft patterns &amp; practices<br>// Parallel Programming Guide<br>//===============================================================================<br>// Copyright © Microsoft Corporation.&nbsp; All rights reserved.<br>// This code released under the terms of the&nbsp;<br>// Microsoft patterns &amp; practices license (http://parallelpatterns.codeplex.com/license).<br>//===============================================================================<br><br>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading;<br><br>using System.Drawing;<br>using System.Drawing.Drawing2D;<br>using System.Threading.Tasks;<br>using System.Windows.Forms;<br>using Microsoft.Practices.ParallelGuideSamples.Utilities;<br>using System.IO;<br><br>namespace _018_parallel_task_image_blender<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void SetToGray(Bitmap source, Bitmap layer)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source.CopyPixels(layer);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer.SetGray();&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer.SetAlpha(128);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static void Rotate(Bitmap source, Bitmap layer)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source.CopyPixels(layer);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer.RotateFlip(RotateFlipType.Rotate90FlipNone);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer.SetAlpha(128);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; // Alpha blend: call DrawImage on each layer in turn<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Blend(Bitmap layer1, Bitmap layer2, Graphics blender)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blender.DrawImage(layer1, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blender.DrawImage(layer2, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int SeqentialImageProcessing(Bitmap source1, Bitmap source2,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap layer1, Bitmap layer2, Graphics blender)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetToGray(source1, layer1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rotate(source2, layer2);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Blend(layer1, layer2, blender);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return source1.Width;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int ParallelTaskImageProcessing(Bitmap source1, Bitmap source2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap layer1, Bitmap layer2, Graphics blender)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task toGray = Task.Factory.StartNew(() =&gt; SetToGray(source1, layer1));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task rotate = Task.Factory.StartNew(() =&gt; Rotate(source2, layer2));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task.WaitAll(toGray, rotate);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Blend(layer1, layer2, blender);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return source1.Width;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int ParallelInvokeImageProcessing(Bitmap source1, Bitmap source2,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap layer1, Bitmap layer2, Graphics blender)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.Invoke(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; () =&gt; SetToGray(source1, layer1),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; () =&gt; Rotate(source2, layer2));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Blend(layer1, layer2, blender);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return source1.Width;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;summary&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; /// Parallel tasks sample<br>&nbsp; &nbsp; &nbsp; &nbsp; /// Command line arguments are:<br>&nbsp; &nbsp; &nbsp; &nbsp; ///&nbsp; image source directory, default: current directory<br>&nbsp; &nbsp; &nbsp; &nbsp; ///&nbsp; first source image file, default: flowers.jpg&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; ///&nbsp; second source image file, default: dog.jpg&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; ///&nbsp; blended image destination directory, default: current directory &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; /// If any of the directories or files do not exist, the program exits without results.<br>&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;/summary&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; [STAThread]<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Image Blender Sample\n");<br>#if DEBUG<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("For most accurate timing results, use Release build.\n");<br>#endif<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string sourceDir = Directory.GetCurrentDirectory();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string file1 = "flowers.jpg"; // don't rotate<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string file2 = "dog.jpg";&nbsp; &nbsp; &nbsp;// don't set to gray<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string destDir = Directory.GetCurrentDirectory();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (args.Length &gt; 0) sourceDir = args[0];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (args.Length &gt; 1) file1 = args[1];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (args.Length &gt; 2) file2 = args[2];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (args.Length &gt; 3) destDir = args[3];<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string path1 = Path.Combine(sourceDir, file1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string path2 = Path.Combine(sourceDir, file2);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.CheckDirectoryExists(sourceDir);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.CheckFileExists(path1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.CheckFileExists(path2);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.CheckDirectoryExists(destDir);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Load source images<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var source1 = new Bitmap(path1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var source2 = new Bitmap(path2);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Prepare for result image<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var layer1 = new Bitmap(source1.Width, source1.Height); // new layer apparently includes alpha layer...<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var layer2 = new Bitmap(source2.Width, source2.Height); // ... even when source does not.<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (var result = new Bitmap(source1.Width, source1.Height))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var blender = Graphics.FromImage(result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blender.CompositingMode = CompositingMode.SourceOver; // NOT SourceCopy mode<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Sequential<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.TimedRun(() =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SeqentialImageProcessing(source1, source2, layer1, layer2, blender),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp;Sequential");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // restore layers to iniital condition; layer2 must be unrotated<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer1 = new Bitmap(source1.Width, source1.Height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer2 = new Bitmap(source2.Width, source2.Height);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Parallel tasks<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.TimedRun(() =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ParallelTaskImageProcessing(source1, source2, layer1, layer2, blender),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; Parallel tasks");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // restore layers to initial condition; layer2 must be unrotated<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer1 = new Bitmap(source1.Width, source1.Height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer2 = new Bitmap(source2.Width, source2.Height);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Parallel invoke<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SampleUtilities.TimedRun(() =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ParallelInvokeImageProcessing(source1, source2, layer1, layer2, blender),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; Parallel invoke");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Save blended image in file<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.Save(Path.Combine(destDir, "blended.jpg"));<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Show blended image on screen, pause until user closes window<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Close image window to exit program.");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (var form = new Form())&nbsp; // ensure disposal, prevent warning CA2000<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (var pb = new PictureBox())<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pb.SizeMode = PictureBoxSizeMode.AutoSize; // fit to image - but form is initially smaller<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pb.Image = result;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form.Controls.Add(pb);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form.ShowDialog();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } // using result<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-14 04:27:06 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991664106</guid>
      </item>
      <item>
         <title>Sample Data dog.jpg</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991666334</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/551945409/bacd7bd94796b35f037fa14208e51633/dog.jpg" />
         <pubDate>2022-01-14 04:29:22 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991666334</guid>
      </item>
      <item>
         <title>Sample Data flower.jpg</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991666872</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/551945409/896380c66d8bacad77fce300ebb89749/flowers.jpg" />
         <pubDate>2022-01-14 04:29:55 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991666872</guid>
      </item>
      <item>
         <title>Sample Data bufferfly.jpg</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991667590</link>
         <description><![CDATA[]]></description>
         <enclosure url="https://padlet-uploads.storage.googleapis.com/551945409/f4c87336c13f0e5d128141dc7a82de4f/butterfly.jpg" />
         <pubDate>2022-01-14 04:30:43 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991667590</guid>
      </item>
      <item>
         <title>Facebook Group</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/1991690360</link>
         <description><![CDATA[<div>https://www.facebook.com/groups/447786423719702</div>]]></description>
         <enclosure url="https://www.facebook.com/groups/447786423719702" />
         <pubDate>2022-01-14 04:53:25 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/1991690360</guid>
      </item>
      <item>
         <title>MaxDegreeParallelism</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/2017242412</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Threading;<br><br>namespace prog2017_008_of_LMS_maxDegreeParallelism<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const int newline_num = 3;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, 20, i =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("MaxDegreeofParallelism is not defined: i={0}, thread = {1}", i,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; newline_num; i++) Console.WriteLine();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, 20, new ParallelOptions{MaxDegreeOfParallelism = 2},i=&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("MaxDegreeOfParallelism=2 --&gt;: i={0}, thread = {1}", i,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i=0;i&lt; newline_num; i++) Console.WriteLine();<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ParallelOptions options = new ParallelOptions();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options.MaxDegreeOfParallelism = 4;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, 20, options, i =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("MaxDegreeOfParallelism=4 --&gt;: i={0}, thread = {1}", i,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; newline_num; i++) Console.WriteLine();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options.MaxDegreeOfParallelism = -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, 20, options, i =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("MaxDegreeOfParallelism= -1 --&gt;: i={0}, thread = {1}", i,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.CurrentThread.ManagedThreadId);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-28 04:14:24 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/2017242412</guid>
      </item>
      <item>
         <title>Future and Exception</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/2017248953</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br><br>namespace prog2017_018_Future_and_Exception<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; static int F1_power(int b, int exp)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int r = 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; exp; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = r * b;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("F1_power({0},{1}) success, result = {2}", b, exp, r);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return r;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch(AggregateException)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Exception occurs in F1_power");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; static int F4_DIV(int dividend,int divisor)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int a = dividend / divisor;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return a;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (AggregateException)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Exception occurs in F4_DIV");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int F2_squared(int x)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return x * x;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (AggregateException)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Exception occures in F2_squared");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int F3_factorial(int x)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (x == 1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return x * F3_factorial(x - 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (AggregateException)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Exception occures in F3_factorial");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; static int F5_cubed(int x)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return x*x*x;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (AggregateException)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Exception occurs in F5_cubed");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int a = 15;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int b = 5;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int c = 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt; futureD = Task.Factory.StartNew&lt;int&gt;(() =&gt; F2_squared(F3_factorial(b)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task&lt;int&gt; futureB = Task.Factory.StartNew&lt;int&gt;(() =&gt; F1_power(a, F4_DIV(b, c)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int f = F4_DIV(futureD.Result, futureB.Result);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("F4_DIV [F2_squared(F3_factorial({1}), F1_power({0}, {1})] = {2}", a, b, f);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (AggregateException)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Exception occures in Main");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-28 04:19:39 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/2017248953</guid>
      </item>
      <item>
         <title>ThreadLocal vs Manual Lock</title>
         <author>pichayat</author>
         <link>https://padlet.com/pichayat/240441/wish/2017252911</link>
         <description><![CDATA[<div>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br>using System.Threading;<br><br>namespace prog2017_018_of_LMS_thread_local_vs_manual_var<br>{<br>&nbsp; &nbsp; class Program<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; public static double MyInterlockedAdd(ref double location1, double value)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double newCurrentValue = location1; // non-volatile read, so may be stale<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (true)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double currentValue = newCurrentValue;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double newValue = currentValue + value;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newCurrentValue = Interlocked.CompareExchange(ref location1, newValue, currentValue);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (newCurrentValue == currentValue)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return newValue;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const int data_size = 5000000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int[] data = new int[data_size];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double result_serial, result_parallel;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_serial = 0.0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel = 0.0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---initial values in the array<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; data.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data[i] = i * i;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopwatch stopWatch = new Stopwatch();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long ex_time_serial, ex_time_parallel;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---sequential&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; data.Length; i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_serial += ((Math.Sin((double)data[i]) - Math.Cos((double)data[i])) /<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Math.Sin((double)data[i]) + Math.Cos((double)data[i])));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_serial = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================\nSequential Program");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result = {0}", result_serial);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time = {0}", ex_time_serial);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("========================================");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel using Thread Local Variable<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel = 0.0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For&lt;double&gt;(0, data.Length, () =&gt; 0.0, (j, loop, partialResult) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partialResult += ((Math.Sin((double)data[j]) - Math.Cos((double)data[j])) /<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Math.Sin((double)data[j]) + Math.Cos((double)data[j])));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return partialResult;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (x) =&gt; MyInterlockedAdd(ref result_parallel, x)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Parallel Program using Thread Local Variable");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result = {0}", result_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time = {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel using Thread Local Variable 2<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel = 0.0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For(0, data.Length, j =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double partialResult = 0.0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.For&lt;double&gt;(0, data.Length, () =&gt; 0.0, (j, loop, partialResult) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partialResult += ((Math.Sin((double)data[j]) - Math.Cos((double)data[j])) /<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Math.Sin((double)data[j]) + Math.Cos((double)data[j])));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return partialResult;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (x) =&gt; MyInterlockedAdd(ref result_parallel, x)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Parallel Program using Thread Local Variable");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result = {0}", result_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time = {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---parallel using Parallel Aggregation<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //---------------------------------------------------------------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel = 0.0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object lockObject = new object();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Reset();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Start();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parallel.ForEach(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The values to be aggregated&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The local initial partial result<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; () =&gt; 0.0d,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The loop body<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (x, loopState, partialResult) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double r_sin, r_cos;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r_sin = Math.Sin((double)x);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r_cos = Math.Cos((double)x);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //local_result += (r_sin - r_cos) / (r_cos + r_sin);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (r_sin - r_cos) / (r_cos + r_sin) + partialResult;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The final step of each local context&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (localPartialSum) =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Enforce serial access to single, shared result<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lock (lockObject)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_parallel += localPartialSum;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopWatch.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex_time_parallel = stopWatch.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Parallel Program using Parallel-aggregation pattern");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("the result = {0}", result_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Execution time = {0}", ex_time_parallel);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("====================================================================");<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></div>]]></description>
         <enclosure url="" />
         <pubDate>2022-01-28 04:22:39 UTC</pubDate>
         <guid>https://padlet.com/pichayat/240441/wish/2017252911</guid>
      </item>
   </channel>
</rss>
