<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic About my threadpool engine... in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809908#M965</link>
    <description>&lt;BR /&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;In my threadpool engine the worker threads enters in a wait state &lt;BR /&gt;when there is no job in the lock-free queues - for more efficiency - &lt;BR /&gt;&lt;DIV&gt;you can download the source code from:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;A href="http://pages.videotron.com/aminer/"&gt;http://pages.videotron.com/aminer/&lt;/A&gt;&lt;/DIV&gt;&lt;BR /&gt;but if you look at the threadpool engine source code i am using &lt;BR /&gt;the following code on the producer side: &lt;/DIV&gt;&lt;DIV&gt;---&lt;/DIV&gt;&lt;DIV&gt;events[local_balance].setevent;&lt;BR /&gt;---&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;and using the followingcode on the consumer side&lt;/DIV&gt;&lt;DIV&gt;:&lt;BR /&gt;---&lt;/DIV&gt;&lt;DIV&gt;if ThreadPool.Queues[self.threadcount].count &amp;lt;&amp;gt; 0 &lt;BR /&gt;then continue;&lt;/DIV&gt;&lt;DIV&gt;for i:=0 to FThreadpool.Fthreadcount-1 do count:=count+FThreadPool.Queues&lt;I&gt;.count; &lt;/I&gt;&lt;/DIV&gt;&lt;DIV&gt;if count=0 then &lt;BR /&gt;begin&lt;BR /&gt;FThreadpool.events[self.threadcount].waitfor(INFINITE);&lt;BR /&gt;FThreadpool.events[self.threadcount].resetevent;&lt;BR /&gt;end;&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;So a question follows..&lt;BR /&gt;&lt;BR /&gt;If for example the consumer thread is on &lt;BR /&gt;FThreadpool.events[self.threadcount].waitfor(INFINITE);&lt;/DIV&gt;&lt;DIV&gt;and it receives two items before entering the &lt;/DIV&gt;&lt;DIV&gt;FThreadpool.events[self.threadcount].resetevent;&lt;BR /&gt;can it forget to process the second item cause the consumer thread &lt;BR /&gt;will reset the event but one item will still be on the queue...&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Answer:&lt;/DIV&gt;&lt;DIV&gt;No, it will still process correctly the second item cause we arecatching &lt;BR /&gt;the number of items with the following code on the consumer side: &lt;/DIV&gt;&lt;DIV&gt;---&lt;BR /&gt;if ThreadPool.Queues[self.threadcount].count &amp;lt;&amp;gt; 0 &lt;BR /&gt;then continue;&lt;/DIV&gt;&lt;DIV&gt;for i:=0 to FThreadpool.Fthreadcount-1 do count:=count+FThreadPool.Queues&lt;I&gt;.count; &lt;BR /&gt;---&lt;/I&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Thank you.&lt;BR /&gt;Amine Moulay Ramdane.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Sun, 03 Jun 2012 15:10:19 GMT</pubDate>
    <dc:creator>aminer10</dc:creator>
    <dc:date>2012-06-03T15:10:19Z</dc:date>
    <item>
      <title>About my threadpool engine...</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809908#M965</link>
      <description>&lt;BR /&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;In my threadpool engine the worker threads enters in a wait state &lt;BR /&gt;when there is no job in the lock-free queues - for more efficiency - &lt;BR /&gt;&lt;DIV&gt;you can download the source code from:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;A href="http://pages.videotron.com/aminer/"&gt;http://pages.videotron.com/aminer/&lt;/A&gt;&lt;/DIV&gt;&lt;BR /&gt;but if you look at the threadpool engine source code i am using &lt;BR /&gt;the following code on the producer side: &lt;/DIV&gt;&lt;DIV&gt;---&lt;/DIV&gt;&lt;DIV&gt;events[local_balance].setevent;&lt;BR /&gt;---&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;and using the followingcode on the consumer side&lt;/DIV&gt;&lt;DIV&gt;:&lt;BR /&gt;---&lt;/DIV&gt;&lt;DIV&gt;if ThreadPool.Queues[self.threadcount].count &amp;lt;&amp;gt; 0 &lt;BR /&gt;then continue;&lt;/DIV&gt;&lt;DIV&gt;for i:=0 to FThreadpool.Fthreadcount-1 do count:=count+FThreadPool.Queues&lt;I&gt;.count; &lt;/I&gt;&lt;/DIV&gt;&lt;DIV&gt;if count=0 then &lt;BR /&gt;begin&lt;BR /&gt;FThreadpool.events[self.threadcount].waitfor(INFINITE);&lt;BR /&gt;FThreadpool.events[self.threadcount].resetevent;&lt;BR /&gt;end;&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;So a question follows..&lt;BR /&gt;&lt;BR /&gt;If for example the consumer thread is on &lt;BR /&gt;FThreadpool.events[self.threadcount].waitfor(INFINITE);&lt;/DIV&gt;&lt;DIV&gt;and it receives two items before entering the &lt;/DIV&gt;&lt;DIV&gt;FThreadpool.events[self.threadcount].resetevent;&lt;BR /&gt;can it forget to process the second item cause the consumer thread &lt;BR /&gt;will reset the event but one item will still be on the queue...&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Answer:&lt;/DIV&gt;&lt;DIV&gt;No, it will still process correctly the second item cause we arecatching &lt;BR /&gt;the number of items with the following code on the consumer side: &lt;/DIV&gt;&lt;DIV&gt;---&lt;BR /&gt;if ThreadPool.Queues[self.threadcount].count &amp;lt;&amp;gt; 0 &lt;BR /&gt;then continue;&lt;/DIV&gt;&lt;DIV&gt;for i:=0 to FThreadpool.Fthreadcount-1 do count:=count+FThreadPool.Queues&lt;I&gt;.count; &lt;BR /&gt;---&lt;/I&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Thank you.&lt;BR /&gt;Amine Moulay Ramdane.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 03 Jun 2012 15:10:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809908#M965</guid>
      <dc:creator>aminer10</dc:creator>
      <dc:date>2012-06-03T15:10:19Z</dc:date>
    </item>
    <item>
      <title>About my threadpool engine...</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809909#M966</link>
      <description>&lt;BR /&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;As you will notice my threadpool engine is a simpleand efficient threadpool engine , i have designed it like that to easy the learning step for those who want to learn how to implementa simple and efficient threadpool.&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;On a multicore system, your goal is to spread the work &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #ff0000; font-family: Arial;"&gt;&lt;STRONG&gt;efficiently&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt; among many cores so that it does executes simultaneously. And performance gain should be directly related to how many cores you have. So, a quad core system should be able to get the work done 4 times faster than a single core system. A 16-core platform should be 4-times faster than a quad-core system, and 16-times faster than a single core... &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;That's where my Threadpool is usefull , it spreads the work &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #ff0000; font-family: Arial;"&gt;&lt;STRONG&gt;efficiently&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt; among many cores. Threadpool (and Threadpool with priority) consist of lock-free thread safe/concurrent enabled local FIFO queues of work items, so when you call ThreadPool.execute() , your work item get queued in the local lock-free queues. The worker threads pick them out in a First In First Out order (i.e., FIFO order), and execute them. .&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;&lt;BR /&gt;The following have been added to Threadpool: &lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;- Lock-free_mpmc - flqueue that i have modified, enhanced and improved... - &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;- It uses a lock-free queue for each worker thread and it uses work-stealing - for more efficiency - &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;- The worker threads enters in a wait state when there is no job in the lock-free queues - for more efficiency - &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;- You can distribute your jobs to the worker threads and call any method with the threadpool's execute() method.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;Work-Stealing scheduling algorithm offer many feature over the ordinary scheduling algorithm:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="color: #008000; font-family: Arial;"&gt;&lt;STRONG&gt;Effective&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;: &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;Using local queues, this will minimize contention.&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="color: #008000; font-family: Arial;"&gt;&lt;STRONG&gt;Load Balancing&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;: &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;Every thread can steal work from the other threads, so Work-Stealing provides implicitly Load Balancing.&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;My Threadpool allows &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-family: Arial;"&gt;&lt;STRONG&gt;load balancing&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;, and also &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-family: Arial;"&gt;&lt;STRONG&gt;minimize &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;contention.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;Amine Moulay Ramdane.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2012 15:30:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809909#M966</guid>
      <dc:creator>aminer10</dc:creator>
      <dc:date>2012-06-03T15:30:57Z</dc:date>
    </item>
    <item>
      <title>About my threadpool engine...</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809910#M967</link>
      <description>Amine,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I think that it would be a better idea for you to write an article with a complete example of the usage of your thread engine on different Intel architectures, with several sample algorithms.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;That is the best way someone in the forums will pay attention to your work.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;It is not a good idea to promote your engine by adding dozens of messages in these forums.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Cheers,&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Gaston Hillar&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Jun 2012 02:20:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/About-my-threadpool-engine/m-p/809910#M967</guid>
      <dc:creator>gaston-hillar</dc:creator>
      <dc:date>2012-06-27T02:20:07Z</dc:date>
    </item>
  </channel>
</rss>

