![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00034 #ifndef __EVOLUTION_H__ 00035 #define __EVOLUTION_H__ 00036 00037 #include "Board.h" 00038 #include <string.h> 00039 #include <stdlib.h> 00040 #include <stdio.h> 00041 00042 #define WIN32_LEAN_AND_MEAN 00043 00045 #include "tbb/task_scheduler_init.h" 00046 #include "tbb/blocked_range.h" 00047 #include "tbb/parallel_for.h" 00048 #include "tbb/tick_count.h" 00049 00050 #ifndef _CONSOLE 00051 #include <windows.h> 00052 using namespace System::Threading; 00053 #else 00054 typedef unsigned int Int32; 00055 #endif 00056 00057 void UpdateState(Matrix * m_matrix, char * dest ,int begin, int end); 00058 00062 #ifndef _CONSOLE 00063 public ref class Evolution abstract 00064 #else 00065 class Evolution 00066 #endif 00067 { 00068 public: 00069 Evolution( Matrix *m, 00070 BoardPtr board 00071 ) : m_matrix(m), m_board(board), 00072 m_size(m_matrix->height * m_matrix->width), m_done(false) 00073 { 00075 m_dest = new char[m_size]; 00076 is_paused = false; 00077 #ifdef _CONSOLE 00078 m_serial_time = 0; 00079 #endif 00080 } 00081 00082 virtual ~Evolution() 00083 { 00084 delete[] m_dest; 00085 } 00086 00088 #ifndef _CONSOLE 00089 virtual void Run() = 0; 00090 #else 00091 virtual void Run(double execution_time, int nthread) = 0; 00092 #endif 00093 00095 virtual void Quit() { m_done = true; } 00096 00098 virtual void Step() = 0; 00099 00101 virtual void SetPause(bool condition) 00102 { 00103 if ( condition == true ) 00104 is_paused = true; 00105 else 00106 is_paused = false; 00107 } 00108 00109 protected: 00114 void UpdateMatrix(); 00115 00116 protected: 00117 Matrix* m_matrix; 00118 char* m_dest; 00119 BoardPtr m_board; 00120 int m_size; 00121 volatile bool m_done; 00122 Int32 m_nIteration; 00123 volatile bool is_paused; 00124 00126 00130 #ifndef _CONSOLE 00131 static volatile double m_serial_time = 0; 00132 00133 static System::Threading::AutoResetEvent ^m_evt_start_serial = gcnew AutoResetEvent(false), 00134 ^m_evt_start_parallel = gcnew AutoResetEvent(false); 00135 #else 00136 double m_serial_time; 00137 #endif 00138 }; 00139 00143 #ifndef _CONSOLE 00144 public ref class SequentialEvolution: public Evolution 00145 #else 00146 class SequentialEvolution: public Evolution 00147 #endif 00148 { 00149 public: 00150 SequentialEvolution(Matrix *m, BoardPtr board) 00151 : Evolution(m, board) 00152 {} 00153 #ifndef _CONSOLE 00154 virtual void Run() override; 00155 virtual void Step() override; 00156 #else 00157 virtual void Run(double execution_time, int nthread); 00158 virtual void Step(); 00159 #endif 00160 00161 }; 00162 00167 #ifndef _CONSOLE 00168 public ref class ParallelEvolution: public Evolution 00169 #else 00170 class ParallelEvolution: public Evolution 00171 #endif 00172 { 00173 public: 00174 00175 ParallelEvolution(Matrix *m, BoardPtr board) 00176 : Evolution(m, board), 00177 m_parallel_time(0) 00178 { 00179 // instantiate a task_scheduler_init object and save a pointer to it 00180 m_pInit = NULL; 00181 } 00182 00183 ~ParallelEvolution() 00184 { 00186 if (m_pInit != NULL) 00187 delete m_pInit; 00188 } 00189 #ifndef _CONSOLE 00190 virtual void Run() override; 00191 virtual void Step() override; 00192 #else 00193 virtual void Run(double execution_time, int nthread); 00194 virtual void Step(); 00195 #endif 00196 00197 00198 private: 00199 tbb::task_scheduler_init* m_pInit; 00200 00201 double m_parallel_time; 00202 }; 00203 00204 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.