Debian Codegraph @

3rdparty/dissection/src/Driver/QueueRuntime.hpp

raw
1 /*! \file QueueRuntime.hpp
2 \brief management of threads for Dissection Matrix
3 \author Atsushi Suzuki, Laboratoire Jacques-Louis Lions
4 \date Jun. 20th 2014
5 \date Jul. 12th 2015
6 \date Nov. 30th 2016
7 */
8
9 // This file is part of Dissection
10 //
11 // Dissection is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // Linking Dissection statically or dynamically with other modules is making
17 // a combined work based on Disssection. Thus, the terms and conditions of
18 // the GNU General Public License cover the whole combination.
19 //
20 // As a special exception, the copyright holders of Dissection give you
21 // permission to combine Dissection program with free software programs or
22 // libraries that are released under the GNU LGPL and with independent modules
23 // that communicate with Dissection solely through the Dissection-fortran
24 // interface. You may copy and distribute such a system following the terms of
25 // the GNU GPL for Dissection and the licenses of the other code concerned,
26 // provided that you include the source code of that other code when and as
27 // the GNU GPL requires distribution of source code and provided that you do
28 // not modify the Dissection-fortran interface.
29 //
30 // Note that people who make modified versions of Dissection are not obligated
31 // to grant this special exception for their modified versions; it is their
32 // choice whether to do so. The GNU General Public License gives permission to
33 // release a modified version without this exception; this exception also makes
34 // it possible to release a modified version which carries forward this
35 // exception. If you modify the Dissection-fortran interface, this exception
36 // does not apply to your modified version of Dissection, and you must remove
37 // this exception when you distribute your modified version.
38 //
39 // This exception is an additional permission under section 7 of the GNU
40 // General Public License, version 3 ("GPLv3")
41 //
42 // Dissection is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU General Public License for more details.
46 //
47 // You should have received a copy of the GNU General Public License
48 // along with Dissection. If not, see <http://www.gnu.org/licenses/>.
49 //
50
51 #ifndef _QUEUE_RUNTIME_
52 # define _QUEUE_RUNTIME_
53 #include "Compiler/OptionLibrary.hpp"
54 #include "Driver/C_threads_tasks.hpp"
55 #include "Compiler/elapsed_time.hpp"
56 #include <time.h>
57 #include <cstdlib>
58 #include <string>
59 #ifdef POSIX_THREADS
60 #include <pthread.h>
61 #else
62 #include <thread>
63 #include <mutex>
64 #include <condition_variable>
65 #endif
66
67 #ifdef POSIX_THREADS
68 typedef pthread_t QueueRuntime_thread;
69 typedef pthread_mutex_t QueueRuntime_mutex;
70 typedef pthread_cond_t QueueRuntime_cond;
71 #define MUTEX_LOCK(a, b) pthread_mutex_lock(&(a))
72 #define COND_BROADCAST(b) pthread_cond_broadcast(&(b))
73 #define MUTEX_UNLOCK(b) pthread_mutex_unlock(&(b))
74 #define COND_WAIT(a, b, c) pthread_cond_wait(&(b), &(a))
75 #else
76 typedef std::thread QueueRuntime_thread;
77 typedef std::mutex QueueRuntime_mutex;
78 typedef std::condition_variable QueueRuntime_cond;
79 #define MUTEX_LOCK(a, b) std::unique_lock<std::mutex>(b)((a))
80 #define COND_BROADCAST(b) (b).notify_all()
81 #define MUTEX_UNLOCK(b)
82 #define COND_WAIT(a, b, c) (b).wait((c))
83 #endif
84
85 class QueueRuntime
86 {
87 public:
88 QueueRuntime(int nb_doms, int num_threads, const bool isSym,
89 const bool verbose, FILE *fp);
90
91 ~QueueRuntime();
92
93 void generate_queue(C_task_seq* &_queue_symb,
94 list<C_task_seq*>* &_queue_static,
95 vector<C_task_seq *>* &_queue_dynamic,
96 list<C_task *> &queue_null,
97 // list<C_task *> &queue_dummy,
98 Dissection::Tree* btree,
99 vector<int>* children,
100 vector<C_task *>* tasks_SparseSymb,
101 vector<C_task *>* tasks_SparseNum,
102 vector<C_task *>* tasks_SparseLocalSchur,
103 vector<C_task *>* tasks_DFillSym,
104 vector<C_task *>* tasks_DFullLDLt,
105 vector<C_task *>* tasks_DTRSMScale,
106 vector<C_task *>* tasks_DSymmGEMM,
107 vector<C_task *>** tasks_Dsub,
108 vector<C_task *>* tasks_deallocLower,
109 vector<C_task *>* tasks_deallocLocalSchur,
110 long **nops_queue,
111 vector<vector<int> > all_fathersIndex,
112 vector<int> nrow_DFullLDLt,
113 vector<bool> isMergedDTRSM,
114 vector<bool> isDividedDTRSM,
115 const int level_last);
116
117 void write_dependency(FILE *fp);
118 void exec_symb_fact();
119 void exec_num_fact(const int called);
120 void exec_num_fact_debug();
121 void execute_task_debug(C_task_seq *seq, int pos,
122 int *permute_block,
123 int pid);
124 void exec_fwbw();
125 void exec_fwbw_seq();
126 void thread_queue_symb_factorize(const int pid, const int num_threads);
127 void thread_queue_num_factorize(const int pid, const int num_threads);
128 void thread_queue_fwbw(const int pid, const int num_threads);
129
130 void thread_queue_C_DFULL(const int pid, const int num_thraeds,
131 C_task_seq *it,
132 int *permute_block,
133 const int cnt_cdfull,
134 const int zone_first_entered,
135 const int zone_idxn);
136
137 void thread_queue_parallel_dynamic(const int pid, const int num_threads,
138 C_task_seq *it,
139 int *permute_block,
140 const int zone_idxn);
141
142 void thread_queue_parallel_static(const int pid, const int num_threads,
143 C_task_seq *it,
144 int *permute_block,
145 const int zone_idxp,
146 const int zone_idxn,
147 const int zone_first_entered,
148 const int zone_last_entered);
149
150 void thread_queue_single(const int pid, const int num_threads,
151 C_task_seq *it,
152 int *permute_block,
153 const int zone_idxn);
154
155 int execute_task_dynamic_buffer(int *permute_block,
156 int pid,
157 QueueRuntime_mutex &mutex_depenency);
158
159 void execute_task(C_task_seq *seq, int pos,
160 int *permute_block,
161 int pid,
162 QueueRuntime_mutex &mutex_depenency);
163
164 void execute_task(C_task_seq *seq, int pos,
165 int *permute_block,
166 int pid);
167
168 int check_parents_done(C_task *it,
169 QueueRuntime_mutex &mutex_depenency);
170
171 int check_parents_done(C_task *it);
172
173 void set_queue_fwbw(C_task_seq* &queue_fwbw)
174 {
175 _queue_fwbw = queue_fwbw;
176 }
177
178 QueueRuntime(const QueueRuntime &s) { } // copy constrcutor : dummy
179
180 private:
181 int _nb_doms;
182 int _num_threads;
183
184 C_task_seq* _queue_symb;
185 C_task_seq* _queue_fwbw;
186 list<C_task_seq*> *_queue_static;
187 vector<C_task_seq *> *_queue_dynamic;
188 // list<C_task *>* _queue_dummy;
189
190 QueueRuntime_mutex _mutex_root;
191 QueueRuntime_mutex _mutex_dependency;
192 QueueRuntime_mutex *_mutex_group;
193 QueueRuntime_mutex _mutex_debug;
194 QueueRuntime_mutex _mutex_file;
195 QueueRuntime_cond _cond_root;
196
197 int *_zone_entered;
198 int *_zone_finished;
199
200 int ***_group_entered;
201 int ***_group_finished;
202 int ***_group_task_ends;
203 int ***_group_static_assigned;
204
205 int *_group_task_id;
206 int *_zone_static_assigned;
207
208 int **_begins;
209 int **_ends;
210 int ***_begins_group;
211 int ***_ends_group;
212 long **_group_nops;
213
214 unsigned char _waiting_root; // num. of threads should be less than 255
215 int _phase_dynamic;
216 int _queue_dynamic_pos_start;
217 int _queue_dynamic_pos;
218 int _queue_dynamic_notcopied;
219 //
220 // ofstream _fout;
221
222 // forward-backward substitutions
223
224 bool _verbose;
225 FILE *_fp;
226 bool _isSym;
227
228 }; // End class DissictionQueue
229
230 struct THREAD_QUEUE_EXEC {
231 int id;
232 int num_threads;
233 QueueRuntime* dissectionRuntime;
234 THREAD_QUEUE_EXEC(int id_,
235 int num_threads_,
236 QueueRuntime* dissectionRuntime_) :
237 id(id_),
238 num_threads(num_threads_),
239 dissectionRuntime(dissectionRuntime_) {}
240 };
241
242 void copytask_list2seq(list<C_task_seq*> &queue_static,
243 list<C_task_seq*> queue_lists,
244 list<C_task *> &queue_null,
245 string task_name,
246 int task_id,
247 int mutex_id,
248 int parallel_single,
249 int num_threads,
250 int level,
251 int phase);
252
253 void task_assign_diag1(list<C_task_seq*> * &queue_static,
254 vector<C_task *>* &tasks_queue,
255 list<C_task *> &queue_null,
256 // list<C_task *> &queue_dummy,
257 vector<int> &nrow_DFullLDLt,
258 vector<bool> &isMergedDTRSM,
259 string queue_symbol,
260 int queue_id,
261 int level_id,
262 int num_threads,
263 int level_last,
264 int level,
265 int begdom,
266 int enddom,
267 long *nops_sum,
268 vector<int> starts,
269 list<C_task_seq*>* &queue_lists,
270 bool queue_lists_clear,
271 Dissection::Tree* btree,
272 vector<int>* children);
273
274 void task_assign_diag2(list<C_task_seq*> *&queue_static,
275 vector<C_task *>* &tasks_queue,
276 vector<C_task *> &queue_null,
277 // vector<C_task *> &queue_dummy,
278 vector<bool> &isMergedDTRSM,
279 string queue_symbol,
280 int queue_id,
281 int level_id,
282 int num_threads,
283 int level_last,
284 int level,
285 int begdom,
286 int enddom,
287 long *nops_sum,
288 vector<int> starts,
289 vector<int> starts_sub,
290 list<C_task_seq*>* &queue_lists,
291 bool queue_lists_clear,
292 Dissection::Tree* btree,
293 vector<int>* children);
294
295 void allocate_int2d(int **&array, const int num_threads);
296 void allocate_unsigned2d(long **&array, const int num_threads);
297 void allocate_int3d(int ***&array, const int num_threads);
298 void deallocate_int2d(int **&array);
299 void deallocate_unsigned2d(long **&array);
300 void deallocate_int3d(int ***&array);
301
302 void *thread_queue_num_factorize_(void *arg);
303 void *thread_queue_symb_factorize_(void *arg);
304 void *thread_queue_fwbw_(void *arg);
305
306 #endif