<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hi! I&#039;m clsung &#187; c++</title>
	<atom:link href="http://blog.dragon2.net/category/hacker/programming/c-programming-hacker/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.dragon2.net</link>
	<description>clsung&#039;s blog site</description>
	<lastBuildDate>Mon, 06 Feb 2012 09:29:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>From UnitTest++ to GoogleTest</title>
		<link>http://blog.dragon2.net/2009/06/25/858.php</link>
		<comments>http://blog.dragon2.net/2009/06/25/858.php#comments</comments>
		<pubDate>Thu, 25 Jun 2009 01:47:12 +0000</pubDate>
		<dc:creator>clsung</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[gtest]]></category>
		<category><![CDATA[unittest]]></category>

		<guid isPermaLink="false">http://blog.dragon2.net/2009/06/25/858.php</guid>
		<description><![CDATA[We&#8217;ve decided to replace UnitTest++ with googletest The first thing to notice: Remember, when they fail, ASSERT_* yields a fatal failure and returns from the current function, while EXPECT_* yields a nonfatal failure, allowing the function to continue running. In either case, an assertion failure means its containing test fails. Remarkable modification: CHECK => (ASSERT&#124;EXPECT)_TRUE CHECK_EQUAL => (ASSERT&#124;EXPECT)_EQ CHECK_EQUAL => (ASSERT&#124;EXPECT)_STREQ (if you&#8217;re comparing strings, such as (char *result) For Test Fixture, UnitTest++ only provides constructor/destructor for SetUp()/TearDown(), where Google Test provides SetUp()/TearDown(). Note that different tests in the same test case have different test fixture objects, and Google Test always deletes a test fixture before it creates the next one. Google Test does not reuse the same test fixture for multiple tests. Any changes one test makes to the fixture do not affect other tests. The best thing what unittest++ doesn&#8217;t have, but gtest has: Getting the Current Test&#8217;s Name Sometimes a function may need to know the name of the currently running test. For example, you may be using the SetUp() method of your test fixture to set the golden file name based on which test is running. Reference: Musings on C++ Testing Tools Google Mock 玩转Google开源C++单元测试框架Google Test系列(gtest)(总)玩转Google开源C++单元测试框架Google [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve decided to replace <a href="http://unittest-cpp.sourceforge.net/" title="UnitTest++">UnitTest++</a> with <a href="http://code.google.com/p/googletest/" title="Google Test">googletest</a><br />
<span id="more-858"></span><br />
The first thing to notice:</p>
<blockquote><p>Remember, when they fail, ASSERT_* yields a fatal failure and returns from the current function, while EXPECT_* yields a nonfatal failure, allowing the function to continue running. In either case, an assertion failure means its containing test fails. </p></blockquote>
<p>Remarkable modification:</p>
<ul>
<li>CHECK => (ASSERT|EXPECT)_TRUE</li>
<li>CHECK_EQUAL => (ASSERT|EXPECT)_EQ</li>
<li>CHECK_EQUAL => (ASSERT|EXPECT)_STREQ (if you&#8217;re comparing strings, such as (char *result)</li>
<li>For <strong>Test Fixture</strong>, <a href="http://unittest-cpp.sourceforge.net/" title="UnitTest++">UnitTest++</a> only provides constructor/destructor for SetUp()/TearDown(), where <a href="http://code.google.com/p/googletest/" title="Google Test">Google Test</a> provides SetUp()/TearDown().</li>
<blockquote><p>Note that different tests in the same test case have different test fixture objects, and Google Test always deletes a test fixture before it creates the next one. Google Test does not reuse the same test fixture for multiple tests. Any changes one test makes to the fixture do not affect other tests.</p></blockquote>
</ul>
<p>The best thing what unittest++ doesn&#8217;t have, but gtest has:</p>
<ul>
<li><a href="http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide#Getting_the_Current_Test%27s_Name">Getting the Current Test&#8217;s Name</a></li>
<blockquote><p>Sometimes a function may need to know the name of the currently running test. For example, you may be using the SetUp() method of your test fixture to set the golden file name based on which test is running.</p></blockquote>
</ul>
<p>Reference:</p>
<ul>
<li><a href="http://cpptesting.blogspot.com/" title="Musings on C++ Testing Tools">Musings on C++ Testing Tools</a></li>
<li><a href="http://code.google.com/p/googlemock/" title="Google Mock">Google Mock</a></li>
<li><a href="http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html">玩转Google开源C++单元测试框架Google Test系列(gtest)(总)</a>玩转Google开源C++单元测试框架Google Test系列(gtest)(总)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.dragon2.net/2009/06/25/858.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Passing UTF-8 String from C# to Unmanaged C++ DLL</title>
		<link>http://blog.dragon2.net/2009/02/05/821.php</link>
		<comments>http://blog.dragon2.net/2009/02/05/821.php#comments</comments>
		<pubDate>Thu, 05 Feb 2009 08:38:38 +0000</pubDate>
		<dc:creator>clsung</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://blog.dragon2.net/?p=821</guid>
		<description><![CDATA[我有個 DLL ，輪入 keystroke 可以傳出文字（不限英文中文）。今年寫了個應用程式，還可以把選出來的文字再傳回去算詞頻。 最近遇到了問題。原先想將 C# 應用程式選出的字串傳進 C++ 寫的 DLL 裡，沒想到傳了老半天，英文（ANSI Str）可以，中文（UTF-8 Str）就是不行。 當我傳入的 string[] 宣告為如下的時候，進去 DLL 的文字（const char **）變亂碼了。 &#91;In, MarshalAs&#40;UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr&#41;&#93; the UTF-8 word will be changed from "丁零当郎" to "^ANH?aj??" 由於我原先的 library 寫的是可以傳一整串陣列的資料進去，不過在這 AP 中，只會用到一個，所以我將問題簡單化。就是我要怎麼在 C# 傳（單一） UTF-8 字串到 C/C++ 的 DLL 呢？ 試過了 BStr、LPStr、LPWSTR 等等的，都是亂碼。仔細去看傳入的字串，發現都被當成 Unicode 來處理，所以 3-byte 的字只有 2-byte 進去，這樣當然沒好結果。所以只好回頭想想，來試看看 byte[] 吧。 &#91;DllImport&#40;dllPath&#41;&#93; &#160; &#160; &#160; &#160; public extern static int WriteSingle&#40;string keystroke, byte&#91;&#93; word&#41;; 因為轉成 byte[] ，這樣對於 UTF-8 String 來說我可以這麼做： System.Text.Encoding.UTF8.GetBytes&#40; selectstr &#41; 所以 function 呼叫時就變成了： WriteSingle &#40;keystroke, System.Text.Encoding.UTF8.GetBytes&#40; selectstr &#41;&#41;; 這樣就解決了傳入 UTF-8 String 到 Unmanaged C++ DLL 的問題了。至於陣列形式的，我還沒試，不過應該是類似的方法吧。 Ref: byte array 的轉換可以參考一下這篇及它的評論。]]></description>
			<content:encoded><![CDATA[<p>我有個 DLL ，輪入 keystroke 可以傳出文字（不限英文中文）。今年寫了個應用程式，還可以把選出來的文字再傳回去算詞頻。<span id="more-821"></span><br />
最近遇到了問題。原先想將 C# 應用程式選出的字串傳進 C++ 寫的 DLL 裡，沒想到傳了老半天，英文（ANSI Str）可以，中文（UTF-8 Str）就是不行。</p>
<p>當我傳入的 string[] 宣告為如下的時候，進去 DLL 的文字（const char **）變亂碼了。</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span><span class="kw1">In</span>, MarshalAs<span class="br0">&#40;</span>UnmanagedType.<span class="me1">LPArray</span>, ArraySubType <span class="sy0">=</span> UnmanagedType.<span class="me1">LPWStr</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</div>
<p>the UTF-8 word will be changed from "丁零当郎" to "^ANH?aj??"</p>
<p>由於我原先的 library 寫的是可以傳一整串陣列的資料進去，不過在這 AP 中，只會用到一個，所以我將問題簡單化。就是我要怎麼在 C# 傳（單一） UTF-8 字串到 C/C++ 的 DLL 呢？</p>
<p>試過了 BStr、LPStr、LPWSTR 等等的，都是亂碼。仔細去看傳入的字串，發現都被當成 Unicode 來處理，所以 3-byte 的字只有 2-byte 進去，這樣當然沒好結果。所以只好回頭想想，來試看看 byte[] 吧。</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>DllImport<span class="br0">&#40;</span>dllPath<span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">extern</span> <span class="kw1">static</span> <span class="kw4">int</span> WriteSingle<span class="br0">&#40;</span><span class="kw4">string</span> keystroke, <span class="kw4">byte</span><span class="br0">&#91;</span><span class="br0">&#93;</span> word<span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>因為轉成 byte[] ，這樣對於 UTF-8 String 來說我可以這麼做：</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw5">System.<span class="me1">Text</span></span>.<span class="me1">Encoding</span>.<span class="me1">UTF8</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span> selectstr <span class="br0">&#41;</span></div>
</div>
<p>所以 function 呼叫時就變成了：</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;">WriteSingle <span class="br0">&#40;</span>keystroke, <span class="kw5">System.<span class="me1">Text</span></span>.<span class="me1">Encoding</span>.<span class="me1">UTF8</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span> selectstr <span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>這樣就解決了傳入 UTF-8 String 到 Unmanaged C++ DLL 的問題了。至於陣列形式的，我還沒試，不過應該是類似的方法吧。</p>
<p>Ref: byte array 的轉換可以參考一下<a href="http://giftdotyoung.blogspot.com/2007/05/byte-array-string-in-c-net.html" title="Byte array <=> String in C# .Net">這篇及它的評論</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dragon2.net/2009/02/05/821.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>由 C# 傳 Callback function 給 C++ DLL</title>
		<link>http://blog.dragon2.net/2008/12/25/791.php</link>
		<comments>http://blog.dragon2.net/2008/12/25/791.php#comments</comments>
		<pubDate>Thu, 25 Dec 2008 08:57:26 +0000</pubDate>
		<dc:creator>clsung</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://blog.dragon2.net/?p=791</guid>
		<description><![CDATA[一般來說，在 C# 呼叫 C++ 寫的 DLL ，可以用下面的方式來宣告： public class ClassA &#123; &#160; &#160; &#160; &#160; const string dllPath = @&#34;pathToTheDLL.dll&#34;; &#160; &#160; &#160; &#160; &#91;DllImport&#40;dllPath&#41;&#93; &#160; &#160; &#160; &#160; public extern static void FuncionA&#40;string argA&#41;; &#160; &#160; &#160; &#160; &#8230;. &#160; &#160; &#160; &#160; public ClassA&#40;&#41; // constructor &#160; &#160; &#160; &#160; &#123; &#160; &#160; &#160; &#160; &#125; &#160; &#160; &#160; &#160; void callFunctionA&#40;string argA&#41; &#160; &#160; &#160; &#160; &#123; &#160; &#160; &#160; &#160; &#160; &#160;FunctionA&#40;argA&#41;; &#160; &#160; &#160; &#160; &#125; &#125; 啊不過之前在寫程式時遇到麻煩，就是要傳個 callback function 進去，這就很困擾了。中間的過程就不贅述了。 好像是 .Net 2.0 之後，由 C# 呼叫 (unmanaged) C++ 所作出的 DLL ，就可以直接如下寫： &#91;UnmanagedFunctionPointer&#40;CallingConvention.Cdecl&#41;&#93; public delegate int Filter&#40;string input, string matched&#41;; public class ClassA &#123; &#160; &#160; &#160; &#160; &#91;DllImport&#40;dllPath&#41;&#93; &#160; &#160; &#160; &#160; public extern static int FuncionB&#40;string argA, Filter callback&#41;; &#160; &#160; &#160; &#160; &#8230; &#125; 當然， CallingConvention 視你用的是什麼而定。 Ref: C# Delegates and Events—Win32 callbacks Using C calling convention callback functions in C# and VB &#8211; the easy way Unmanaged Callbacks in .NET 2.0]]></description>
			<content:encoded><![CDATA[<p>一般來說，在 C# 呼叫 C++ 寫的 DLL ，可以用下面的方式來宣告：<span id="more-791"></span></p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw4">class</span> ClassA<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">const</span> <span class="kw4">string</span> dllPath <span class="sy0">=</span> <span class="st_h">@&quot;pathToTheDLL.dll&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>DllImport<span class="br0">&#40;</span>dllPath<span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">extern</span> <span class="kw1">static</span> <span class="kw1">void</span> FuncionA<span class="br0">&#40;</span><span class="kw4">string</span> argA<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8230;.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> ClassA<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="co1">// constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">void</span> callFunctionA<span class="br0">&#40;</span><span class="kw4">string</span> argA<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FunctionA<span class="br0">&#40;</span>argA<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>啊不過之前在寫程式時遇到麻煩，就是要傳個 callback function 進去，這就很困擾了。中間的過程就不贅述了。<br />
好像是 .Net 2.0 之後，由 C# 呼叫 (unmanaged) C++ 所作出的 DLL ，就可以直接如下寫：</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>UnmanagedFunctionPointer<span class="br0">&#40;</span>CallingConvention.<span class="me1">Cdecl</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">delegate</span> <span class="kw4">int</span> Filter<span class="br0">&#40;</span><span class="kw4">string</span> input, <span class="kw4">string</span> matched<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> ClassA<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>DllImport<span class="br0">&#40;</span>dllPath<span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">extern</span> <span class="kw1">static</span> <span class="kw4">int</span> FuncionB<span class="br0">&#40;</span><span class="kw4">string</span> argA, Filter callback<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8230;<br />
<span class="br0">&#125;</span></div>
</div>
<p>當然， CallingConvention 視你用的是什麼而定。</p>
<p>Ref:</p>
<ul>
<li><a href="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Win32_callbacks">C# Delegates and Events—Win32 callbacks</a></li>
<li><a href="http://www.codeproject.com/KB/dotnet/Cdecl_CSharp_VB.aspx">Using C calling convention callback functions in C# and VB &#8211; the easy way</a></li>
<li><a href="http://www.informit.com/guides/content.aspx?g=dotnet&#038;seqNum=473">Unmanaged Callbacks in .NET 2.0</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.dragon2.net/2008/12/25/791.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to clear ostringstream?</title>
		<link>http://blog.dragon2.net/2008/09/18/580.php</link>
		<comments>http://blog.dragon2.net/2008/09/18/580.php#comments</comments>
		<pubDate>Thu, 18 Sep 2008 08:28:15 +0000</pubDate>
		<dc:creator>clsung</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.dragon2.net/?p=580</guid>
		<description><![CDATA[下面這程式真有清掉嗎？ ostringstream os; &#8230; os.clear&#40;&#41;; cerr &#60;&#60; os.str&#40;&#41; 沒有！得用 os.str&#40;&#34;&#34;&#41;; 才行]]></description>
			<content:encoded><![CDATA[<p>下面這程式真有清掉嗎？</p>
<div class="codesnip-container" >
<div class="c codesnip" style="font-family:monospace;">ostringstream os<span class="sy0">;</span><br />
&#8230;<br />
<span class="me1">os</span>.<span class="me1">clear</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
cerr <span class="sy0">&lt;&lt;</span> os.<span class="me1">str</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<p><span id="more-580"></span></p>
<p>沒有！得用</p>
<div class="codesnip-container" >
<div class="c codesnip" style="font-family:monospace;">os.<span class="me1">str</span><span class="br0">&#40;</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>才行</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dragon2.net/2008/09/18/580.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>openmp tutorials &#8211; scheduling</title>
		<link>http://blog.dragon2.net/2008/09/07/567.php</link>
		<comments>http://blog.dragon2.net/2008/09/07/567.php#comments</comments>
		<pubDate>Sat, 06 Sep 2008 17:22:32 +0000</pubDate>
		<dc:creator>clsung</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[openmp]]></category>

		<guid isPermaLink="false">http://blog.dragon2.net/?p=567</guid>
		<description><![CDATA[目前會的，就是 在 for loop 中， schedule 設為 dynamic 與 guided 的不同。 從 scheduling 的角度來看，static 好的地方在於在一開始的時候就設定好每個 thread 所要 run 的 iteration；而 dynamic 則是每個 thread 根據 chunk_size 的大小，每次 run 完該 chunk_size 的 iteration 後，再去（跟 OS?）要下一次的 iteration （當剩下的 iteration 小於 chunk_size ，自然就全都是該 thread 了）；guided 的話，有個公式可以直接參考： iterations_to_do = max&#40;iterations_not_assigned/omp_get_num_threads&#40;&#41;, chunk-size&#41; 也就是愈前面的 thread ，該次要處理的 iteration 數會是最多，之後則約略為指數遞減。 所以，若每個 iteration 所要處理的 resource 差不多，則 guided 會是比較（比 dynamic ）好的 scheduling 方法，因為要處理分配 iteration 給 thread 所造成的 overhead 比較小。反之，若每個 iteration 要處理的 resource 是不定量（會變動，你自己也不確定）的，那麼用 dynamic 會比較能達到 load balance 的功能。 當然，dynamic/guided 一般來說都比 static 更能達成 load balance 的效果。 FMI, OpenMP and C++ &#8211; Reap the Benefits of Multithreading without All the Work Guide into OpenMP: Easy multithreading programming for C++ OpenMP Tutorial]]></description>
			<content:encoded><![CDATA[<p>目前會的，就是 在 for loop 中， schedule 設為 dynamic 與 guided 的不同。 <span id="more-567"></span></p>
<p>從 scheduling 的角度來看，<strong>static</strong> 好的地方在於在一開始的時候就設定好每個 thread 所要 run 的 iteration；而 <strong>dynamic</strong> 則是每個 thread 根據 <em>chunk_size</em> 的大小，每次 run 完該 <em>chunk_size</em> 的 iteration 後，再去（跟 OS?）要下一次的 iteration （當剩下的 iteration 小於 <em>chunk_size</em> ，自然就全都是該 thread 了）；<strong>guided</strong> 的話，有個公式可以直接<a href="http://msdn.microsoft.com/zh-tw/magazine/cc163717.aspx" title="OpenMP and C++ - Reap the Benefits of Multithreading without All the Work">參考</a>：</p>
<div class="codesnip-container" >
<div class="c codesnip" style="font-family:monospace;">iterations_to_do <span class="sy0">=</span> max<span class="br0">&#40;</span>iterations_not_assigned<span class="sy0">/</span>omp_get_num_threads<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> chunk<span class="sy0">-</span>size<span class="br0">&#41;</span></div>
</div>
<p>也就是愈前面的 thread ，該次要處理的 iteration 數會是最多，之後則約略為指數遞減。</p>
<p>所以，若每個 iteration 所要處理的 resource 差不多，則 <strong>guided</strong> 會是比較（比 <strong>dynamic</strong> ）好的 scheduling 方法，因為要處理分配 iteration 給 thread 所造成的 overhead 比較小。反之，若每個 iteration 要處理的 resource 是不定量（會變動，你自己也不確定）的，那麼用 <strong>dynamic</strong> 會比較能達到 load balance 的功能。</p>
<p>當然，<strong>dynamic</strong>/<strong>guided</strong> 一般來說都比 <strong>static</strong> 更能達成 load balance 的效果。</p>
<p>FMI,
<ul>
<li><a href="http://msdn.microsoft.com/zh-tw/magazine/cc163717.aspx">OpenMP and C++ &#8211; Reap the Benefits of Multithreading without All the Work</a></li>
<li><a href="http://bisqwit.iki.fi/story/howto/openmp/">Guide into OpenMP: Easy multithreading programming for C++</a></li>
<li><a href="http://www.kallipolis.com/openmp/">OpenMP Tutorial</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.dragon2.net/2008/09/07/567.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

