Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Genetic Algorithm Library

, 7 Apr 2012
A framework for genetic algorithms
galdemoapps.zip
TSP.exe
GeneticLibrary.dll
TestApp1.exe
TestApp2.exe
GaSchedule.exe
GaSchedule.cfg
GalDemoSource.zip
TestApp1
TestApp1.vcxproj.filters
TestApp2
TestApp2.vcxproj.filters
TSP
res
.svn
entries
prop-base
Toolbar.bmp.svn-base
TSP.ico.svn-base
props
text-base
Toolbar.bmp.svn-base
TSP.ico.svn-base
TSP.rc2.svn-base
tmp
prop-base
props
text-base
Toolbar.bmp
TSP.ico
TSP.vcxproj.filters
GaSchedule
Algorithm
GaSchedule.cfg
GaSchedule.vcxproj.filters
res
GaSchedule.ico
galdocumentation.zip
doxygen.png
Graphic
ab_cp.png
alg_st.png
a_cr.png
c_cp.png
i_cp.png
mp_cr.png
mv_cr.png
r_cp.png
s_cp.png
s_cr.png
galsource.zip
GeneticLibrary
build
release
gcc_bsd
gcc_linux
gcc_macos
gcc_solaris
icc_linux
icc_macos
icc_win
mingw
msvc
scc_solaris
makefiles
gcc_bsd_debug
gcc_bsd_release
gcc_linux_debug
gcc_linux_release
gcc_macos_debug
gcc_macos_release
gcc_solaris_debug
gcc_solaris_release
icc_linux_debug
icc_linux_release
icc_macos_debug
icc_macos_release
scc_solaris_debug
scc_solaris_release
source
vs
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Genetic Algorithm Library: Algorithm::GaMultithreadingAlgorithm Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespace_algorithm.html">Algorithm</a>::<a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html">GaMultithreadingAlgorithm</a>
  </div>
</div>
<div class="contents">
<h1>Algorithm::GaMultithreadingAlgorithm Class Reference</h1><!-- doxytag: class="Algorithm::GaMultithreadingAlgorithm" --><!-- doxytag: inherits="Algorithm::GaBaseAlgorithm" -->This class implements features to allow parallel execution of some operations of genetic algorithm. It runs multiple threads which execute work which can be done in parallel, one control thread which controls workers and executes all operations which must be executed sequentially.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;source/MultithreadingAlgorithm.h&gt;</code>
<p>
Inherits <a class="el" href="class_algorithm_1_1_ga_base_algorithm.html">Algorithm::GaBaseAlgorithm</a>.
<p>
Inherited by <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_incremental_algorithm.html">Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm</a>, and <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_simple_algorithm.html">Algorithm::SimpleAlgorithms::GaSimpleAlgorithm</a>.
<p>

<p>
<a href="class_algorithm_1_1_ga_multithreading_algorithm-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">GAL_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#0da22c2dd02396f597eb2cf10c87c278">GaMultithreadingAlgorithm</a> (const <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm_params.html">GaMultithreadingAlgorithmParams</a> &amp;parameters)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This constructor initializes control structures with user-defined parameters.  <a href="#0da22c2dd02396f597eb2cf10c87c278"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual GAL_API&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#2f5992b2889eba8431772618a9156f9f">~GaMultithreadingAlgorithm</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destructors releases acquired resources such as threads and synchronization objects and memory used by control structures.  <a href="#2f5992b2889eba8431772618a9156f9f"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual GAL_API void GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#cf9dc964bacf71e51720db9afde2b1d2">SetAlgorithmParameters</a> (const <a class="el" href="class_algorithm_1_1_ga_algorithm_params.html">GaAlgorithmParams</a> &amp;parameters)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method should be called from classes that inherit this class when user changes algorithm parameters. It updates structures which control multithreading execution.  <a href="#cf9dc964bacf71e51720db9afde2b1d2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual GAL_API bool GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#a1257bb542be02ebe8198b4269e1048b">WaitForThreads</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method waits for control and working thread to finish their execution.  <a href="#a1257bb542be02ebe8198b4269e1048b"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#ed57cdcb991e7f354e40e3b263ca7675">BeforeWorkers</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is called before workers execute their steps. It is executed in control thread context.  <a href="#ed57cdcb991e7f354e40e3b263ca7675"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#163ebb706325ce12f43b4c80f00c54dd">WorkStep</a> (int workerId)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">After control thread executes BeforeWork method, working threads starts execution and steps in this method. Working threads get their identification numbers which are assigned sequentially to them.  <a href="#163ebb706325ce12f43b4c80f00c54dd"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#d5aecd36a751c439ee470d0fb489585e">AfterWorkers</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is called after workers finish their steps. It is executed in control thread context.  <a href="#d5aecd36a751c439ee470d0fb489585e"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#df503b76df1c4078ef6a63303e48e7ea">OnStart</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method starts control and working threads.  <a href="#df503b76df1c4078ef6a63303e48e7ea"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#6acf172ccc36200727e71f6f107598a9">OnStop</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Empty method imeplmentation. Always returns <code>true</code>.  <a href="#6acf172ccc36200727e71f6f107598a9"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#6fa37c65c2acd09d4c550a78a217a713">OnPause</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Empty method imeplmentation. Always returns <code>true</code>.  <a href="#6fa37c65c2acd09d4c550a78a217a713"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#0220fbb88afdd89f61ca2eea0a1a3d18">OnResume</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method starts control and working threads.  <a href="#0220fbb88afdd89f61ca2eea0a1a3d18"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual GAL_API void GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#b173e6e2c585ede80b84dcbab9a66c29">ControlFlow</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method implements work flow of control thread.  <a href="#b173e6e2c585ede80b84dcbab9a66c29"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual GAL_API void GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#831fde6e0d9c94525d47685d7aae2c0e">WorkFlow</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method implements work flow of working thread.  <a href="#831fde6e0d9c94525d47685d7aae2c0e"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual GAL_API bool GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#56b4fb30945114fd0f959e8828bc2486">StartThreads</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method starts control and working threads.  <a href="#56b4fb30945114fd0f959e8828bc2486"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">SysSemaphoreObject&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#24c29a2616ab05f8192a9cda0d6ad3fb">_workerForkSync</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Object for synchronization of working step start.  <a href="#24c29a2616ab05f8192a9cda0d6ad3fb"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">SysEventObject&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#4ddfd22e0f72650c1d049db0e1288039">_workerJoinSync</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Object for synchronization of worker threads with control thread after end of work step.  <a href="#4ddfd22e0f72650c1d049db0e1288039"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#2b35dfd3be3928254694c331d0f88e5b">_workersThreadIn</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Number of workers thread currently executing working section of code.  <a href="#2b35dfd3be3928254694c331d0f88e5b"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#e94b5c3bbf576650a98d8be5936da7c7">_parametersChange</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This flag indicates that user has changed some aspect of the algorithm, but algorithm didn't refresh its control structures.  <a href="#e94b5c3bbf576650a98d8be5936da7c7"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#ad914b221d2e6882c62694d8c61fa661">_numberOfThreads</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Number of threads which are used by algorithm (working and control threads).  <a href="#ad914b221d2e6882c62694d8c61fa661"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">volatile int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#3a3d3dda7a693e5289b46e38f54aaad5">_workerIdCounter</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This attribute is used for assigning identifiers to working threads when algorithm starts execution.  <a href="#3a3d3dda7a693e5289b46e38f54aaad5"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="class_threading_1_1_ga_thread.html">GaThread</a> **&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#3a40cb74ce3980a873a375356427bd5c">_threads</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Array of threads which are used by the algorithm (working and control threads).  <a href="#3a40cb74ce3980a873a375356427bd5c"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Static Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static ThreadFunctionReturn GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#4fd3ea5d47334d10fa27edfd1df858c2">ControlFlowWrapper</a> (<a class="el" href="class_threading_1_1_ga_thread.html">GaThread</a> *thread, void *params)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is used as wrapper for control flow method and is used when algorithm starts control thread.  <a href="#4fd3ea5d47334d10fa27edfd1df858c2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static ThreadFunctionReturn GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#5048d8983c81f4c5493b532f0f45a4f8">WorkFlowWrapper</a> (<a class="el" href="class_threading_1_1_ga_thread.html">GaThread</a> *thread, void *params)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is used as wrapper for working flow method and is used when algorithm starts working thread.  <a href="#5048d8983c81f4c5493b532f0f45a4f8"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
This class implements features to allow parallel execution of some operations of genetic algorithm. It runs multiple threads which execute work which can be done in parallel, one control thread which controls workers and executes all operations which must be executed sequentially. 
<p>
This class has no built-in synchronizator, so <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code> macros cannot be used with instances of this class, but all public method and operators are thread-safe. <hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="0da22c2dd02396f597eb2cf10c87c278"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::GaMultithreadingAlgorithm" ref="0da22c2dd02396f597eb2cf10c87c278" args="(const GaMultithreadingAlgorithmParams &amp;parameters)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Algorithm::GaMultithreadingAlgorithm::GaMultithreadingAlgorithm           </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm_params.html">GaMultithreadingAlgorithmParams</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>parameters</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This constructor initializes control structures with user-defined parameters. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>parameters</em>&nbsp;</td><td>reference to algorithm parameters.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="2f5992b2889eba8431772618a9156f9f"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::~GaMultithreadingAlgorithm" ref="2f5992b2889eba8431772618a9156f9f" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Algorithm::GaMultithreadingAlgorithm::~GaMultithreadingAlgorithm           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Destructors releases acquired resources such as threads and synchronization objects and memory used by control structures. 
<p>

</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="cf9dc964bacf71e51720db9afde2b1d2"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::SetAlgorithmParameters" ref="cf9dc964bacf71e51720db9afde2b1d2" args="(const GaAlgorithmParams &amp;parameters)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Algorithm::GaMultithreadingAlgorithm::SetAlgorithmParameters           </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="class_algorithm_1_1_ga_algorithm_params.html">GaAlgorithmParams</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>parameters</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method should be called from classes that inherit this class when user changes algorithm parameters. It updates structures which control multithreading execution. 
<p>
More details are given in specification of <a class="el" href="class_algorithm_1_1_ga_algorithm.html#52bbbb181cf1b6d70d27571c483cb525" title="SetAlgorithmParameters method sets algorithm parameters.">GaAlgorithm::SetAlgorithmParameters</a> method.<p>
This method is thread-safe. 
<p>Implements <a class="el" href="class_algorithm_1_1_ga_algorithm.html#52bbbb181cf1b6d70d27571c483cb525">Algorithm::GaAlgorithm</a>.</p>

<p>Reimplemented in <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_incremental_algorithm.html#f93a8ac7d41fd35c3dfa5fac235e25de">Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm</a>, and <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_simple_algorithm.html#e19bc56e1111b9f62cf5cd3068cb207a">Algorithm::SimpleAlgorithms::GaSimpleAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="a1257bb542be02ebe8198b4269e1048b"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::WaitForThreads" ref="a1257bb542be02ebe8198b4269e1048b" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Algorithm::GaMultithreadingAlgorithm::WaitForThreads           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method waits for control and working thread to finish their execution. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns <code>true</code> if ther were no errors during waiting.</dd></dl>

</div>
</div><p>
<a class="anchor" name="ed57cdcb991e7f354e40e3b263ca7675"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::BeforeWorkers" ref="ed57cdcb991e7f354e40e3b263ca7675" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void GACALL Algorithm::GaMultithreadingAlgorithm::BeforeWorkers           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method is called before workers execute their steps. It is executed in control thread context. 
<p>

<p>Reimplemented in <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_incremental_algorithm.html#333a99e89146f90c56f545102f9faa5f">Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm</a>, and <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_simple_algorithm.html#e67604157d80a373fc88af7f1f5f2daa">Algorithm::SimpleAlgorithms::GaSimpleAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="163ebb706325ce12f43b4c80f00c54dd"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::WorkStep" ref="163ebb706325ce12f43b4c80f00c54dd" args="(int workerId)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void GACALL Algorithm::GaMultithreadingAlgorithm::WorkStep           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>workerId</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
After control thread executes BeforeWork method, working threads starts execution and steps in this method. Working threads get their identification numbers which are assigned sequentially to them. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>workerId</em>&nbsp;</td><td>identification number of working thread</td></tr>
  </table>
</dl>

<p>Reimplemented in <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_incremental_algorithm.html#150c9c2d62997dea26879255d73e6b15">Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm</a>, and <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_simple_algorithm.html#076e3882a84aa890ecb7ecc2800e574c">Algorithm::SimpleAlgorithms::GaSimpleAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="d5aecd36a751c439ee470d0fb489585e"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::AfterWorkers" ref="d5aecd36a751c439ee470d0fb489585e" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void GACALL Algorithm::GaMultithreadingAlgorithm::AfterWorkers           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method is called after workers finish their steps. It is executed in control thread context. 
<p>

<p>Reimplemented in <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_incremental_algorithm.html#af3ecdb457a7143aedcf97f074c4b534">Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm</a>, and <a class="el" href="class_algorithm_1_1_simple_algorithms_1_1_ga_simple_algorithm.html#019710b7e5aa190110a1b9584aa9d9b1">Algorithm::SimpleAlgorithms::GaSimpleAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="df503b76df1c4078ef6a63303e48e7ea"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::OnStart" ref="df503b76df1c4078ef6a63303e48e7ea" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnStart           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method starts control and working threads. 
<p>

<p>Implements <a class="el" href="class_algorithm_1_1_ga_base_algorithm.html#0d24f997b73b43e39bd63c660d92dfd3">Algorithm::GaBaseAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="6acf172ccc36200727e71f6f107598a9"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::OnStop" ref="6acf172ccc36200727e71f6f107598a9" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnStop           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Empty method imeplmentation. Always returns <code>true</code>. 
<p>

<p>Implements <a class="el" href="class_algorithm_1_1_ga_base_algorithm.html#99df3113ab7556276832edf5fe3bc9d2">Algorithm::GaBaseAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="6fa37c65c2acd09d4c550a78a217a713"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::OnPause" ref="6fa37c65c2acd09d4c550a78a217a713" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnPause           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Empty method imeplmentation. Always returns <code>true</code>. 
<p>

<p>Implements <a class="el" href="class_algorithm_1_1_ga_base_algorithm.html#4e9d5a9256200a5f8e35a9b2cd01907e">Algorithm::GaBaseAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="0220fbb88afdd89f61ca2eea0a1a3d18"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::OnResume" ref="0220fbb88afdd89f61ca2eea0a1a3d18" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnResume           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method starts control and working threads. 
<p>

<p>Implements <a class="el" href="class_algorithm_1_1_ga_base_algorithm.html#fe4c7623ce0a8d98a8ae14c159762d9a">Algorithm::GaBaseAlgorithm</a>.</p>

</div>
</div><p>
<a class="anchor" name="b173e6e2c585ede80b84dcbab9a66c29"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::ControlFlow" ref="b173e6e2c585ede80b84dcbab9a66c29" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Algorithm::GaMultithreadingAlgorithm::ControlFlow           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method implements work flow of control thread. 
<p>

</div>
</div><p>
<a class="anchor" name="831fde6e0d9c94525d47685d7aae2c0e"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::WorkFlow" ref="831fde6e0d9c94525d47685d7aae2c0e" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Algorithm::GaMultithreadingAlgorithm::WorkFlow           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method implements work flow of working thread. 
<p>

</div>
</div><p>
<a class="anchor" name="56b4fb30945114fd0f959e8828bc2486"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::StartThreads" ref="56b4fb30945114fd0f959e8828bc2486" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Algorithm::GaMultithreadingAlgorithm::StartThreads           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method starts control and working threads. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returs <code>true</code> if all threads are started successafully.</dd></dl>

</div>
</div><p>
<a class="anchor" name="4fd3ea5d47334d10fa27edfd1df858c2"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::ControlFlowWrapper" ref="4fd3ea5d47334d10fa27edfd1df858c2" args="(GaThread *thread, void *params)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">ThreadFunctionReturn Algorithm::GaMultithreadingAlgorithm::ControlFlowWrapper           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="class_threading_1_1_ga_thread.html">GaThread</a> *&nbsp;</td>
          <td class="paramname"> <em>thread</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&nbsp;</td>
          <td class="paramname"> <em>params</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"><code> [static, private]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method is used as wrapper for control flow method and is used when algorithm starts control thread. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>thread</em>&nbsp;</td><td>pointer to control thread.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>params</em>&nbsp;</td><td>pointer to parameters which are passed by algorithm to the control thread.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Returns status of the thread when it finishes its execution.</dd></dl>

</div>
</div><p>
<a class="anchor" name="5048d8983c81f4c5493b532f0f45a4f8"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::WorkFlowWrapper" ref="5048d8983c81f4c5493b532f0f45a4f8" args="(GaThread *thread, void *params)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">ThreadFunctionReturn Algorithm::GaMultithreadingAlgorithm::WorkFlowWrapper           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="class_threading_1_1_ga_thread.html">GaThread</a> *&nbsp;</td>
          <td class="paramname"> <em>thread</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&nbsp;</td>
          <td class="paramname"> <em>params</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"><code> [static, private]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method is used as wrapper for working flow method and is used when algorithm starts working thread. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>thread</em>&nbsp;</td><td>pointer to working thread.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>params</em>&nbsp;</td><td>pointer to parameters which are passed by algorithm to the working thread.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Returns status of the thread when it finishes its execution.</dd></dl>

</div>
</div><p>
<hr><h2>Member Data Documentation</h2>
<a class="anchor" name="24c29a2616ab05f8192a9cda0d6ad3fb"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_workerForkSync" ref="24c29a2616ab05f8192a9cda0d6ad3fb" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">SysSemaphoreObject <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#24c29a2616ab05f8192a9cda0d6ad3fb">Algorithm::GaMultithreadingAlgorithm::_workerForkSync</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Object for synchronization of working step start. 
<p>

</div>
</div><p>
<a class="anchor" name="4ddfd22e0f72650c1d049db0e1288039"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_workerJoinSync" ref="4ddfd22e0f72650c1d049db0e1288039" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">SysEventObject <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#4ddfd22e0f72650c1d049db0e1288039">Algorithm::GaMultithreadingAlgorithm::_workerJoinSync</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Object for synchronization of worker threads with control thread after end of work step. 
<p>

</div>
</div><p>
<a class="anchor" name="2b35dfd3be3928254694c331d0f88e5b"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_workersThreadIn" ref="2b35dfd3be3928254694c331d0f88e5b" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#2b35dfd3be3928254694c331d0f88e5b">Algorithm::GaMultithreadingAlgorithm::_workersThreadIn</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Number of workers thread currently executing working section of code. 
<p>

</div>
</div><p>
<a class="anchor" name="e94b5c3bbf576650a98d8be5936da7c7"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_parametersChange" ref="e94b5c3bbf576650a98d8be5936da7c7" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#e94b5c3bbf576650a98d8be5936da7c7">Algorithm::GaMultithreadingAlgorithm::_parametersChange</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This flag indicates that user has changed some aspect of the algorithm, but algorithm didn't refresh its control structures. 
<p>

</div>
</div><p>
<a class="anchor" name="ad914b221d2e6882c62694d8c61fa661"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_numberOfThreads" ref="ad914b221d2e6882c62694d8c61fa661" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#ad914b221d2e6882c62694d8c61fa661">Algorithm::GaMultithreadingAlgorithm::_numberOfThreads</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Number of threads which are used by algorithm (working and control threads). 
<p>

</div>
</div><p>
<a class="anchor" name="3a3d3dda7a693e5289b46e38f54aaad5"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_workerIdCounter" ref="3a3d3dda7a693e5289b46e38f54aaad5" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">volatile int <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#3a3d3dda7a693e5289b46e38f54aaad5">Algorithm::GaMultithreadingAlgorithm::_workerIdCounter</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This attribute is used for assigning identifiers to working threads when algorithm starts execution. 
<p>

</div>
</div><p>
<a class="anchor" name="3a40cb74ce3980a873a375356427bd5c"></a><!-- doxytag: member="Algorithm::GaMultithreadingAlgorithm::_threads" ref="3a40cb74ce3980a873a375356427bd5c" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_threading_1_1_ga_thread.html">GaThread</a>** <a class="el" href="class_algorithm_1_1_ga_multithreading_algorithm.html#3a40cb74ce3980a873a375356427bd5c">Algorithm::GaMultithreadingAlgorithm::_threads</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Array of threads which are used by the algorithm (working and control threads). 
<p>

</div>
</div><p>
<hr>The documentation for this class was generated from the following files:<ul>
<li>source/<a class="el" href="_multithreading_algorithm_8h.html">MultithreadingAlgorithm.h</a><li>source/<a class="el" href="_multithreading_algorithm_8cpp.html">MultithreadingAlgorithm.cpp</a></ul>
</div>
<br/><a href="http://www.coolsoft-sd.com/ProductVersion.aspx?vid=9">Genetic Algorithm Library</a><br/><a href="http://www.coolsoft-sd.com/">Coolsoft Software Development</a>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Mladen Janković
Software Developer
Serbia Serbia
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 7 Apr 2012
Article Copyright 2008 by Mladen Janković
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid