| 1 |
/*! \file DissectionQueue.hpp |
| 2 |
\brief management of threads for factorization and Fw/Bw substitution |
| 3 |
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions |
| 4 |
\date Apr. 22th 2013 |
| 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 |
#include <string> |
| 52 |
|
| 53 |
#include "Driver/C_threads_tasks.hpp" |
| 54 |
#include "Driver/C_Dsub.hpp" |
| 55 |
#include "Driver/DissectionQueue.hpp" |
| 56 |
#include "Driver/QueueRuntime.hpp" |
| 57 |
#include "Compiler/DissectionIO.hpp" |
| 58 |
|
| 59 |
|
| 60 |
#define RATIO_DTRSM_MERGED 0.4 |
| 61 |
|
| 62 |
template<typename T, typename U> |
| 63 |
const T DissectionQueue<T, U>::_one = T(1.0); |
| 64 |
template<typename T, typename U> |
| 65 |
const T DissectionQueue<T, U>::_none = T(-1.0); |
| 66 |
template<typename T, typename U> |
| 67 |
const T DissectionQueue<T, U>::_zero = T(0.0); |
| 68 |
|
| 69 |
|
| 70 |
template<typename T, typename U> |
| 71 |
DissectionQueue<T, U>::DissectionQueue(Dissection::Tree *btree, |
| 72 |
vector<DissectionMatrix<T, U>* >& dM, |
| 73 |
const int num_threads, |
| 74 |
const bool isSym, |
| 75 |
const bool verbose, |
| 76 |
FILE *fp) : |
| 77 |
_btree(btree), _num_threads(num_threads), |
| 78 |
_verbose(verbose), _fp(fp), _isSym(isSym), |
| 79 |
_queue_symb_allocated(false), _queue_numrc_allocated(false), |
| 80 |
_queue_fwbw_allocated(false) |
| 81 |
{ |
| 82 |
const int nb_level = _btree->NumberOfLevels(); |
| 83 |
_nb_level = nb_level; |
| 84 |
const int level_last = nb_level - 1; |
| 85 |
const int nb_doms = _btree->NumberOfSubdomains(); //(1U<<(level_last+1))-1 |
| 86 |
_nb_doms = nb_doms; |
| 87 |
const int nb_doms_dense = (1U << level_last) - 1; |
| 88 |
const int nb_doms_sparse = (1U << level_last); |
| 89 |
|
| 90 |
// _queue_dynamic->reserve(10); |
| 91 |
|
| 92 |
for (int d = 1; d <= nb_doms; d++) { |
| 93 |
const int d1 = _btree->selfIndex(d); |
| 94 |
dM[d1] = new DissectionMatrix<T, U>(_btree, d, isSym, verbose, fp); |
| 95 |
} |
| 96 |
|
| 97 |
// set up working arrays for C_Dsub |
| 98 |
_children = new vector<int>[nb_doms]; |
| 99 |
_tasks_SparseSymb = new vector<C_task *>[nb_doms_sparse]; |
| 100 |
_tasks_SparseNum = new vector<C_task *>[nb_doms]; // nd_doms_sparse is |
| 101 |
_tasks_SparseLocalSchur = new vector<C_task *>[nb_doms]; // enough but |
| 102 |
_tasks_DFillSym = new vector<C_task *>[nb_doms]; // for convinience of |
| 103 |
// dependency |
| 104 |
_tasks_DFullLDLt = new vector<C_task *>[nb_doms_dense]; |
| 105 |
_tasks_DTRSMScale = new vector<C_task *>[nb_doms_dense]; |
| 106 |
_tasks_DSymmGEMM = new vector<C_task *>[nb_doms_dense]; |
| 107 |
_tasks_deallocLocalSchur = |
| 108 |
new vector<C_task *>[nb_doms_dense + nb_doms_sparse]; |
| 109 |
_tasks_Dsub = new vector<C_task *>*[nb_level]; |
| 110 |
_tasks_Dsub[0] = new vector<C_task *>[nb_level * nb_doms_dense]; |
| 111 |
for (int i = 1; i < nb_level; i++) { |
| 112 |
_tasks_Dsub[i] = _tasks_Dsub[0] + i * nb_doms_dense; |
| 113 |
} |
| 114 |
_tasks_deallocLower = new vector<C_task *>[nb_level]; |
| 115 |
_child_contribs = new list<child_contribution<T> >[nb_doms]; |
| 116 |
|
| 117 |
_pivots = new double[nb_doms]; // pass pivot value from a DissectionMatrix to |
| 118 |
// the other is not easy in thread execution |
| 119 |
// initialize state to controle tasks |
| 120 |
|
| 121 |
_dissectionRuntime = new QueueRuntime(nb_doms, num_threads, isSym, |
| 122 |
verbose, fp); |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
template |
| 127 |
DissectionQueue<double>:: |
| 128 |
DissectionQueue(Dissection::Tree *btree, |
| 129 |
vector<DissectionMatrix<double>* >& dM, |
| 130 |
const int num_threads, |
| 131 |
const bool isSym, |
| 132 |
const bool verbose, |
| 133 |
FILE *fp); |
| 134 |
template |
| 135 |
DissectionQueue<quadruple>:: |
| 136 |
DissectionQueue(Dissection::Tree *btree, |
| 137 |
vector<DissectionMatrix<quadruple>* >& dM, |
| 138 |
const int num_threads, |
| 139 |
const bool isSym, |
| 140 |
const bool verbose, |
| 141 |
FILE *fp); |
| 142 |
template |
| 143 |
DissectionQueue<complex<double>, double>:: |
| 144 |
DissectionQueue(Dissection::Tree *btree, |
| 145 |
vector<DissectionMatrix<complex<double>, double>* >& dM, |
| 146 |
const int num_threads, |
| 147 |
const bool isSym, |
| 148 |
const bool verbose, |
| 149 |
FILE *fp); |
| 150 |
|
| 151 |
template |
| 152 |
DissectionQueue<complex<quadruple>, quadruple>:: |
| 153 |
DissectionQueue(Dissection::Tree *btree, |
| 154 |
vector<DissectionMatrix<complex<quadruple>, quadruple>* >& dM, |
| 155 |
const int num_threads, |
| 156 |
const bool isSym, |
| 157 |
const bool verbose, |
| 158 |
FILE *fp); |
| 159 |
|
| 160 |
template |
| 161 |
DissectionQueue<float>:: |
| 162 |
DissectionQueue(Dissection::Tree *btree, |
| 163 |
vector<DissectionMatrix<float>* >& dM, |
| 164 |
const int num_threads, |
| 165 |
const bool isSym, |
| 166 |
const bool verbose, |
| 167 |
FILE *fp); |
| 168 |
|
| 169 |
template |
| 170 |
DissectionQueue<complex<float>, float>:: |
| 171 |
DissectionQueue(Dissection::Tree *btree, |
| 172 |
vector<DissectionMatrix<complex<float>, float>* >& dM, |
| 173 |
const int num_threads, |
| 174 |
const bool isSym, |
| 175 |
const bool verbose, |
| 176 |
FILE *fp); |
| 177 |
// |
| 178 |
|
| 179 |
template<typename T, typename U> |
| 180 |
DissectionQueue<T, U>::~DissectionQueue() |
| 181 |
{ |
| 182 |
// const int nb_level = _btree->NumberOfLevels(); |
| 183 |
// const int num_threads = _num_threads; |
| 184 |
erase_queue(); |
| 185 |
erase_queue_fwbw(); |
| 186 |
// set up working arrays for C_Dsub |
| 187 |
delete [] _children; |
| 188 |
delete [] _tasks_SparseSymb; |
| 189 |
delete [] _tasks_SparseNum; |
| 190 |
delete [] _tasks_SparseLocalSchur; |
| 191 |
delete [] _tasks_DFillSym; // _tasks_DFillSym = new vector<C_task *>[nb_doms]; |
| 192 |
delete [] _tasks_DFullLDLt; |
| 193 |
delete [] _tasks_DTRSMScale; |
| 194 |
delete [] _tasks_DSymmGEMM; |
| 195 |
delete [] _tasks_Dsub[0]; |
| 196 |
delete [] _tasks_Dsub; |
| 197 |
delete [] _tasks_deallocLocalSchur; |
| 198 |
delete [] _tasks_deallocLower; |
| 199 |
// delete [] _tasks_fillSym; |
| 200 |
delete [] _child_contribs; |
| 201 |
delete [] _pivots; |
| 202 |
// nullify the pointer |
| 203 |
_btree = NULL; |
| 204 |
delete _dissectionRuntime; |
| 205 |
} |
| 206 |
|
| 207 |
template |
| 208 |
DissectionQueue<double>::~DissectionQueue(); |
| 209 |
|
| 210 |
template |
| 211 |
DissectionQueue<quadruple>::~DissectionQueue(); |
| 212 |
|
| 213 |
template |
| 214 |
DissectionQueue<complex<double>, double>::~DissectionQueue(); |
| 215 |
|
| 216 |
template |
| 217 |
DissectionQueue<complex<quadruple>, quadruple>::~DissectionQueue(); |
| 218 |
|
| 219 |
template |
| 220 |
DissectionQueue<float>::~DissectionQueue(); |
| 221 |
|
| 222 |
template |
| 223 |
DissectionQueue<complex<float>, float>::~DissectionQueue(); |
| 224 |
// |
| 225 |
|
| 226 |
template<typename T, typename U> |
| 227 |
void DissectionQueue<T, U>:: |
| 228 |
generate_queue(vector<DissectionMatrix<T, U>* >& dM, |
| 229 |
int nnz, |
| 230 |
T *coefs) |
| 231 |
{ |
| 232 |
const int num_threads = _num_threads; |
| 233 |
const int nb_level = _btree->NumberOfLevels(); |
| 234 |
const int level_last = nb_level - 1; |
| 235 |
|
| 236 |
const int nb_doms = _btree->NumberOfSubdomains(); |
| 237 |
const int nb_doms_dense = (1U << level_last) - 1; |
| 238 |
const int nb_doms_sparse = (1U << level_last); |
| 239 |
// set up working arrays for C_Dsub |
| 240 |
|
| 241 |
vector<C_task *> null_task; |
| 242 |
|
| 243 |
for (int level = (level_last - 1); level >= 0; level--){ |
| 244 |
const int begdom = 1U << level; |
| 245 |
const int enddom = begdom * 2; |
| 246 |
for (int d = begdom; d < enddom; d++) { |
| 247 |
const int j = _btree->selfIndex(d); |
| 248 |
const int mm = _btree->childIndex(d); |
| 249 |
const int nn = _btree->brotherIndex(mm); |
| 250 |
_children[j].push_back(_btree->selfIndex(mm)); |
| 251 |
_children[j].push_back(_btree->selfIndex(nn)); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
vector<vector<int> > all_fathersIndex(nb_level); |
| 256 |
|
| 257 |
long **nops_queue = new long*[num_threads + 1]; |
| 258 |
nops_queue[0] = new long[(num_threads + 1) * nb_level]; |
| 259 |
for (int p = 1; p <= num_threads; p++) { |
| 260 |
nops_queue[p] = nops_queue[0] + p * nb_level; |
| 261 |
for (int j = 0; j <= level_last; j++) { |
| 262 |
nops_queue[p][j] = 0L; |
| 263 |
} |
| 264 |
} |
| 265 |
vector<int>* tasks_deallocLocalSchur_indcol = |
| 266 |
new vector<int>[nb_doms_dense + nb_doms_sparse]; |
| 267 |
// sprase subdomains : begin : level == level_last |
| 268 |
{ |
| 269 |
all_fathersIndex[level_last].clear(); |
| 270 |
for (int i = 0; i < nb_doms; i++) { |
| 271 |
_child_contribs[i].clear(); |
| 272 |
} |
| 273 |
|
| 274 |
const int begdom = 1U << level_last; |
| 275 |
const int enddom = begdom * 2; |
| 276 |
|
| 277 |
int k = 0; |
| 278 |
for (int d = begdom; d < enddom; d++, k++) { |
| 279 |
const int j = _btree->selfIndex(d); |
| 280 |
_tasks_SparseSymb[k].resize(1); |
| 281 |
_tasks_SparseNum[j].resize(1); |
| 282 |
_tasks_SparseLocalSchur[j].resize(1); |
| 283 |
// _tasks_DFillSym[j].resize(2); |
| 284 |
|
| 285 |
dM[j]->C_SparseSymbFact_queue(_tasks_SparseSymb[k], |
| 286 |
_btree, |
| 287 |
_verbose, |
| 288 |
&_fp); |
| 289 |
dM[j]->C_SparseNumFact_queue(_tasks_SparseNum[j], |
| 290 |
_btree, |
| 291 |
nnz, |
| 292 |
coefs, |
| 293 |
&_eps_piv, |
| 294 |
&_pivots[j], |
| 295 |
&_kernel_detection, |
| 296 |
&_higher_precision, |
| 297 |
&_aug_dim, |
| 298 |
&_eps_machine, |
| 299 |
_tasks_SparseSymb[k], |
| 300 |
_verbose, |
| 301 |
&_fp); |
| 302 |
dM[j]->C_SparseLocalSchur_queue(_tasks_SparseLocalSchur[j], |
| 303 |
_btree, |
| 304 |
nnz, |
| 305 |
coefs, |
| 306 |
_tasks_SparseNum[j], |
| 307 |
_verbose, |
| 308 |
&_fp); |
| 309 |
|
| 310 |
dM[j]->C_deallocLocalSchur_queue(_tasks_deallocLocalSchur[j], |
| 311 |
tasks_deallocLocalSchur_indcol[j], |
| 312 |
_verbose, |
| 313 |
&_fp); |
| 314 |
|
| 315 |
dM[j]->ChildContrib(_child_contribs, |
| 316 |
_btree, |
| 317 |
dM, |
| 318 |
_verbose, |
| 319 |
&_fp); |
| 320 |
} // loop : d |
| 321 |
|
| 322 |
for (int d = 1; d < begdom; d++) { |
| 323 |
const int j = _btree->selfIndex(d); |
| 324 |
_tasks_DFillSym[j].resize(2); |
| 325 |
dM[j]->C_FillMatrix_queue(_tasks_DFillSym[j], |
| 326 |
nnz, |
| 327 |
coefs, |
| 328 |
_verbose, |
| 329 |
&_fp); |
| 330 |
} |
| 331 |
all_fathersIndex[level_last].resize((1U << level_last) - 1); |
| 332 |
for (int i = 1; i < (1U << level_last); i++) { |
| 333 |
const int j = _btree->selfIndex(i); |
| 334 |
all_fathersIndex[level_last][j] = j; |
| 335 |
} |
| 336 |
for (vector<int>::const_iterator it = all_fathersIndex[level_last].begin(); |
| 337 |
it != all_fathersIndex[level_last].end(); ++it) { |
| 338 |
|
| 339 |
C_Dsub_queue<T>(_isSym, (*it), |
| 340 |
false, // all sparse matrix parts need to be done |
| 341 |
_tasks_Dsub[level_last][(*it)], |
| 342 |
_child_contribs[(*it)], |
| 343 |
(vector<C_task*> *)NULL, // _tasks_DSymmGEMM |
| 344 |
(vector<int> *)NULL, |
| 345 |
false, |
| 346 |
_tasks_DFillSym[(*it)], |
| 347 |
_tasks_SparseLocalSchur, |
| 348 |
null_task, // (vector<C_task*> *)NULL, |
| 349 |
_tasks_deallocLocalSchur, |
| 350 |
tasks_deallocLocalSchur_indcol, |
| 351 |
level_last, |
| 352 |
true, |
| 353 |
_verbose, _fp); |
| 354 |
} |
| 355 |
// tasks to deallocate local Schur complement |
| 356 |
_tasks_deallocLower[level_last].resize(0); // no C- working array of DTSRM |
| 357 |
} // end : level == level_last |
| 358 |
vector<int> nrow_DFullLDLt; |
| 359 |
nrow_DFullLDLt.resize(nb_doms_dense); |
| 360 |
vector<bool> isMergedDTRSM(nb_doms_dense, false); |
| 361 |
vector<bool> isDividedDTRSM(nb_doms_dense, false); |
| 362 |
vector<int>* tasks_DTRSMScale_indcol = new vector<int>[nb_doms_dense]; |
| 363 |
vector<int>* tasks_DTRSMScale_index = new vector<int>[nb_doms_dense]; |
| 364 |
vector<list<int> >* tasks_DTRSMScale_parents_index = new vector<list<int> >[nb_doms_dense]; |
| 365 |
vector<int>* tasks_DTRSMScale_ptr = new vector<int>[nb_doms_dense]; |
| 366 |
vector<int>* tasks_DSymmGEMM_indcol = new vector<int>[nb_doms_dense]; |
| 367 |
|
| 368 |
for (int level = (level_last - 1); level >= 0; level--) { |
| 369 |
int itmp; |
| 370 |
all_fathersIndex[level].clear(); |
| 371 |
for (int i = 0; i < nb_doms; i++) { |
| 372 |
_child_contribs[i].clear(); |
| 373 |
} |
| 374 |
const int begdom = 1U << level; |
| 375 |
const int enddom = begdom * 2; |
| 376 |
for (int d = begdom; d < enddom; d++) { |
| 377 |
const int j = _btree->selfIndex(d); |
| 378 |
|
| 379 |
const int num_row_b = dM[j]->diagBlock().num_blocks(); |
| 380 |
int num_tasks_ldlt; |
| 381 |
num_tasks_ldlt = (num_row_b * (num_row_b + 1) * (num_row_b + 2)) / 6; |
| 382 |
if (level == 0) { |
| 383 |
num_tasks_ldlt += (((num_row_b - 1) * num_row_b * (num_row_b + 1)) / 6 + |
| 384 |
num_row_b); |
| 385 |
} |
| 386 |
nrow_DFullLDLt[j] = num_row_b; |
| 387 |
// factorization by block + whole pivotting |
| 388 |
|
| 389 |
_tasks_DFullLDLt[j].resize(num_tasks_ldlt); |
| 390 |
vector<int> task_indcol; |
| 391 |
vector<int> task_ptr; |
| 392 |
task_indcol.resize(num_tasks_ldlt); |
| 393 |
// _tasks_DTRSMScale[j].resize(num_col_b2); |
| 394 |
// _tasks_DSymmGEMM[j].resize(num_dgemm); |
| 395 |
|
| 396 |
bool isChldrnAlgnd = false; |
| 397 |
int evnchld_id; |
| 398 |
if (level < (level_last - 1)) { |
| 399 |
evnchld_id = _btree->childIndex(d); // "selfIndex(j) + 1 == j" is used |
| 400 |
isChldrnAlgnd = dM[evnchld_id]->isAlignedFather(); |
| 401 |
} |
| 402 |
// vector<C_task *> &task_p = (isChldrnAlgnd ? _tasks_DSymmGEMM[evnchld_id] : |
| 403 |
// _tasks_Dsub[level + 1][j]); |
| 404 |
|
| 405 |
itmp = dM[j]->C_DFullLDLt_queue(_tasks_DFullLDLt[j], |
| 406 |
task_indcol, |
| 407 |
task_ptr, |
| 408 |
// value not yet defined |
| 409 |
&_eps_piv, |
| 410 |
&_kernel_detection, |
| 411 |
&_aug_dim, |
| 412 |
&_eps_machine, |
| 413 |
&_pivots[j], |
| 414 |
&_pivots[_children[j][0]], |
| 415 |
&_pivots[_children[j][1]], |
| 416 |
// task_p, |
| 417 |
(isChldrnAlgnd ? _tasks_DSymmGEMM[evnchld_id] : |
| 418 |
_tasks_Dsub[level + 1][j]), |
| 419 |
isChldrnAlgnd, |
| 420 |
_verbose, |
| 421 |
&_fp); |
| 422 |
if (itmp > 1) { |
| 423 |
itmp = EraseNullParents(_tasks_DFullLDLt[j]); |
| 424 |
} |
| 425 |
#ifdef DEBUG_PREPARE_THREAD |
| 426 |
cout << j << " : " |
| 427 |
<< " generated queue : C_DFullLDLt = " << j |
| 428 |
<< " num_block = " << num_row_b |
| 429 |
<< " num_tasks = " << num_tasks_ldlt |
| 430 |
<< " / " << itmp << endl; |
| 431 |
#endif |
| 432 |
if (level > 0) { |
| 433 |
// vector<C_task *> &task_pp = _tasks_Dsub[level + 1][j]; |
| 434 |
|
| 435 |
itmp = dM[j]->C_DTRSMScale_queue(_tasks_DTRSMScale[j], |
| 436 |
tasks_DTRSMScale_parents_index[j], |
| 437 |
tasks_DTRSMScale_index[j], |
| 438 |
tasks_DTRSMScale_indcol[j], |
| 439 |
tasks_DTRSMScale_ptr[j], |
| 440 |
_btree, |
| 441 |
_tasks_DFullLDLt[j], |
| 442 |
task_indcol, |
| 443 |
task_ptr, |
| 444 |
_tasks_Dsub[level + 1][j], |
| 445 |
// task_pp, |
| 446 |
_verbose, |
| 447 |
&_fp); |
| 448 |
if (itmp > 1) { |
| 449 |
itmp = EraseNullParents(_tasks_DTRSMScale[j]); |
| 450 |
dM[j]->C_DTRSMScale_rearrange(_tasks_DTRSMScale[j], |
| 451 |
tasks_DTRSMScale_parents_index[j], |
| 452 |
tasks_DTRSMScale_index[j], |
| 453 |
tasks_DTRSMScale_indcol[j], |
| 454 |
tasks_DTRSMScale_ptr[j], |
| 455 |
_verbose, |
| 456 |
_fp); |
| 457 |
} |
| 458 |
} |
| 459 |
#ifdef DEBUG_PREPARE_THREAD |
| 460 |
cout << j << " : " |
| 461 |
<< " generated queue : C_DTRSMScale_queue " << j |
| 462 |
<< " num_tasks = " << num_col_b2 << " " |
| 463 |
<< _tasks_DTRSMScale[j].size() << endl; |
| 464 |
#endif |
| 465 |
|
| 466 |
SquareBlockMatrix<T>* f_diag; |
| 467 |
int jf = (-1); |
| 468 |
if (level > 0) { // there is no father for level == 0 |
| 469 |
jf = _btree->selfIndex(_btree->fatherIndex(d)); |
| 470 |
f_diag = dM[jf]->addrdiagBlock(); |
| 471 |
} |
| 472 |
else { |
| 473 |
f_diag = (SquareBlockMatrix<T>*)NULL; |
| 474 |
} |
| 475 |
bool isDirect = dM[j]->isAlignedFather(); |
| 476 |
bool isEven = (level > 0) ? (j % 2 == 0) : false; |
| 477 |
RectBlockMatrix<T> *upper1, *lower1; |
| 478 |
upper1 = (isEven ? dM[j - 1]->addrupperBlock() : |
| 479 |
(RectBlockMatrix<T> *) NULL); |
| 480 |
lower1 = (isEven ? dM[j - 1]->addrlowerBlock() : |
| 481 |
(RectBlockMatrix<T> *) NULL); |
| 482 |
// vector<C_task *> &tasks_q = (isEven ? _tasks_DTRSMScale[j - 1] : |
| 483 |
// null_task); |
| 484 |
vector<int> null_idx; |
| 485 |
// vector<int> &tasks_q_index = (isEven ? tasks_DTRSMScale_index[j - 1] : |
| 486 |
// null_idx); |
| 487 |
|
| 488 |
// vector<int> &tasks_q_indcol = (isEven ? tasks_DTRSMScale_indcol[j - 1] : |
| 489 |
// null_idx); |
| 490 |
// vector<int> &tasks_q_ptr = (isEven ? tasks_DTRSMScale_ptr[j - 1] : |
| 491 |
// null_idx); |
| 492 |
|
| 493 |
itmp = dM[j]->C_DGEMM_local_queue(_tasks_DSymmGEMM[j], |
| 494 |
tasks_DSymmGEMM_indcol[j], |
| 495 |
upper1, |
| 496 |
lower1, |
| 497 |
(!isEven), |
| 498 |
isDirect, |
| 499 |
f_diag, |
| 500 |
_tasks_DTRSMScale[j], |
| 501 |
tasks_DTRSMScale_index[j], |
| 502 |
tasks_DTRSMScale_indcol[j], |
| 503 |
tasks_DTRSMScale_ptr[j], |
| 504 |
(isEven ? _tasks_DTRSMScale[j - 1] : null_task), |
| 505 |
(isEven ? tasks_DTRSMScale_index[j - 1] : null_idx), |
| 506 |
(isEven ? tasks_DTRSMScale_indcol[j - 1] : null_idx), |
| 507 |
(isEven ? tasks_DTRSMScale_ptr[j - 1] : null_idx), |
| 508 |
// tasks_q, |
| 509 |
// tasks_q_index, |
| 510 |
// tasks_q_indcol, |
| 511 |
// tasks_q_ptr, |
| 512 |
(jf >= 0) ? &_tasks_Dsub[level + 1][jf] : |
| 513 |
(vector<C_task *>*)NULL, |
| 514 |
_verbose, |
| 515 |
&_fp); |
| 516 |
if (itmp > 1 ) { |
| 517 |
itmp = EraseNullParents(_tasks_DSymmGEMM[j]); |
| 518 |
} |
| 519 |
dM[j]->C_deallocLocalSchur_queue(_tasks_deallocLocalSchur[j], |
| 520 |
tasks_deallocLocalSchur_indcol[j], |
| 521 |
_verbose, |
| 522 |
&_fp); |
| 523 |
|
| 524 |
|
| 525 |
#ifdef DEBUG_PREPARE_THREAD |
| 526 |
cout << j << " : " |
| 527 |
<< " generated queue : C_DGEMM_local_queue " << j |
| 528 |
<< " num_tasks = " << num_dgemm << " " |
| 529 |
<< _tasks_DGEMM[j].size() << endl; |
| 530 |
#endif |
| 531 |
|
| 532 |
dM[j]->ChildContrib(_child_contribs, |
| 533 |
_btree, |
| 534 |
dM, |
| 535 |
_verbose, |
| 536 |
&_fp); |
| 537 |
|
| 538 |
} // loop : d(j) |
| 539 |
|
| 540 |
all_fathersIndex[level].resize((1U << level) - 1); |
| 541 |
for (int i = 1; i < (1U << level); i++) { |
| 542 |
const int j = _btree->selfIndex(i); |
| 543 |
all_fathersIndex[level][j] = j; |
| 544 |
} |
| 545 |
for (vector<int>::const_iterator it = all_fathersIndex[level].begin(); |
| 546 |
it != all_fathersIndex[level].end(); ++it) { |
| 547 |
bool skip_flag = false; |
| 548 |
const int father_id = _btree->Index2Node((*it)); |
| 549 |
if (_btree->nodeLayer(father_id) == (level - 1)) { |
| 550 |
if (_child_contribs[(*it)].size() == 2) { |
| 551 |
int child_id = _btree->childIndex(father_id); |
| 552 |
int child_id0 = _btree->selfIndex(child_id); |
| 553 |
int child_id1 = _btree->selfIndex(child_id + 1); |
| 554 |
skip_flag = ((dM[child_id0]->isAlignedFather() && |
| 555 |
dM[child_id1]->isAlignedFather()) ? |
| 556 |
true : false); |
| 557 |
diss_printf(_verbose, _fp, |
| 558 |
"%s %d : father_id = %d children_id = %d %d skip = %s\n", |
| 559 |
__FILE__, __LINE__, |
| 560 |
((*it) + 1), (child_id0 + 1), (child_id1 + 1), |
| 561 |
skip_flag ? "true" : "false"); |
| 562 |
} |
| 563 |
} |
| 564 |
C_Dsub_queue<T>(_isSym, (*it), |
| 565 |
skip_flag, |
| 566 |
_tasks_Dsub[level][(*it)], |
| 567 |
_child_contribs[(*it)], |
| 568 |
_tasks_DSymmGEMM, |
| 569 |
tasks_DSymmGEMM_indcol, |
| 570 |
true, |
| 571 |
// (vector<C_task*> *)NULL, // _tasks_DFillSym, |
| 572 |
null_task, |
| 573 |
(vector<C_task*> *)NULL, |
| 574 |
_tasks_Dsub[level + 1][(*it)], |
| 575 |
_tasks_deallocLocalSchur, |
| 576 |
tasks_deallocLocalSchur_indcol, |
| 577 |
level, |
| 578 |
true, |
| 579 |
_verbose, |
| 580 |
_fp); |
| 581 |
} // loop : it |
| 582 |
// tasks to deallocate lower column matrix and local Schur complement |
| 583 |
if (level > 0) { |
| 584 |
_tasks_deallocLower[level].resize(enddom - begdom); |
| 585 |
{ |
| 586 |
int k = 0; |
| 587 |
for (int d = begdom; d < enddom; d++, k++) { |
| 588 |
const int j = _btree->selfIndex(d); |
| 589 |
bool isDirect = dM[j]->isAlignedFather(); |
| 590 |
const int jj = (j % 2 == 1) ? (j + 1) : j; |
| 591 |
dM[j]->deallocLower_queue(_tasks_deallocLower[level][k], |
| 592 |
_isSym, |
| 593 |
_tasks_DSymmGEMM[j], |
| 594 |
isDirect, |
| 595 |
_tasks_DSymmGEMM[jj]); |
| 596 |
|
| 597 |
} // loop : d, k |
| 598 |
} // scope for k |
| 599 |
itmp = EraseNullParents(_tasks_deallocLower[level]); |
| 600 |
} // if (level > 0) |
| 601 |
} // loop : level |
| 602 |
for (int level = (level_last - 1); level > 0; level--) { |
| 603 |
const int begdom = 1U << level; |
| 604 |
const int enddom = begdom * 2; |
| 605 |
for (int d = begdom; d < enddom; d++) { |
| 606 |
const int j = _btree->selfIndex(d); |
| 607 |
if(nrow_DFullLDLt[j] > 2) { |
| 608 |
list <C_task *> tmp1; |
| 609 |
list <C_task *> tmp2; |
| 610 |
const int ncol = dM[j]->upperBlock().num_blocks_c(); |
| 611 |
const int ncol1 = (int)((double)ncol * RATIO_DTRSM_MERGED); |
| 612 |
int i0, i1, k1, kk1, kk2; // int i0, i1, k1, k2, kk1, kk2; |
| 613 |
tmp1.push_back(_tasks_DFullLDLt[j][0]); |
| 614 |
k1 = 1; |
| 615 |
i0 = 1; |
| 616 |
i1 = 0; |
| 617 |
bool first_loop_done = false; |
| 618 |
kk2 = 0; |
| 619 |
while (i0 < _tasks_DFullLDLt[j].size()) { |
| 620 |
const int parallel_max0 =_tasks_DFullLDLt[j][i0]->parallel_max; |
| 621 |
const int parallel_max1 =_tasks_DTRSMScale[j][i1]->parallel_max; |
| 622 |
kk1 = 0; |
| 623 |
for (int m = 0; m < parallel_max0; m++) { |
| 624 |
const int atomic_size = _tasks_DFullLDLt[j][i0]->atomic_size; |
| 625 |
for (int n = 0; n < atomic_size; n++) { |
| 626 |
_tasks_DFullLDLt[j][i0 + n]->parallel_id = kk1; |
| 627 |
_tasks_DFullLDLt[j][i0 + n]->parallel_max = 0; // for conuting |
| 628 |
tmp1.push_back(_tasks_DFullLDLt[j][i0 + n]); |
| 629 |
} |
| 630 |
kk1++; |
| 631 |
i0 += atomic_size; |
| 632 |
} // loop : m |
| 633 |
int ll = 0; |
| 634 |
for (int m = 0; m < parallel_max1; m++) { |
| 635 |
const int atomic_size = _tasks_DTRSMScale[j][i1]->atomic_size; |
| 636 |
for (int n = 0; n < atomic_size; n++) { |
| 637 |
if (first_loop_done) { |
| 638 |
if (ll < ncol1) { |
| 639 |
_tasks_DTRSMScale[j][i1 + n]->parallel_id = kk1; |
| 640 |
_tasks_DTRSMScale[j][i1 + n]->parallel_max = 0; |
| 641 |
tmp1.push_back(_tasks_DTRSMScale[j][i1 + n]); |
| 642 |
} |
| 643 |
else { |
| 644 |
_tasks_DTRSMScale[j][i1 + n]->parallel_id = kk2; |
| 645 |
_tasks_DTRSMScale[j][i1 + n]->parallel_max = 0; |
| 646 |
tmp2.push_back(_tasks_DTRSMScale[j][i1 + n]); |
| 647 |
} |
| 648 |
} |
| 649 |
else { |
| 650 |
_tasks_DTRSMScale[j][i1 + n]->parallel_id = kk1; |
| 651 |
_tasks_DTRSMScale[j][i1 + n]->parallel_max = 0; |
| 652 |
tmp1.push_back(_tasks_DTRSMScale[j][i1 + n]); |
| 653 |
} |
| 654 |
} // loop : n |
| 655 |
if (first_loop_done) { |
| 656 |
if (ll < ncol1) { |
| 657 |
kk1++; |
| 658 |
} |
| 659 |
else { |
| 660 |
kk2++; |
| 661 |
} |
| 662 |
} |
| 663 |
else { |
| 664 |
kk1++; |
| 665 |
} |
| 666 |
ll++; |
| 667 |
if (ll == ncol) { |
| 668 |
ll = 0; |
| 669 |
} |
| 670 |
i1 += atomic_size; |
| 671 |
} // loop : m |
| 672 |
for (list<C_task *>::const_iterator it = tmp1.begin(); |
| 673 |
it != tmp1.end(); |
| 674 |
++it) { |
| 675 |
if ((*it)->parallel_max == 0) { |
| 676 |
(*it)->parallel_max = kk1; |
| 677 |
} |
| 678 |
} |
| 679 |
if (i0 >= _tasks_DFullLDLt[j].size()) { |
| 680 |
break; |
| 681 |
} |
| 682 |
// number of C_dupdateb_Schur_{diag,offdiag} may be large enough |
| 683 |
const int parallel_max2 =_tasks_DFullLDLt[j][i0]->parallel_max; |
| 684 |
kk1 = 0; |
| 685 |
for (int m = 0; m < parallel_max2; m++) { |
| 686 |
const int atomic_size = _tasks_DFullLDLt[j][i0]->atomic_size; |
| 687 |
for (int n = 0; n < atomic_size; n++) { |
| 688 |
_tasks_DFullLDLt[j][i0 + n]->parallel_id = kk1; |
| 689 |
_tasks_DFullLDLt[j][i0 + n]->parallel_max = 0; |
| 690 |
tmp1.push_back(_tasks_DFullLDLt[j][i0 + n]); |
| 691 |
} |
| 692 |
i0 += atomic_size; |
| 693 |
kk1++; |
| 694 |
} // loop : m |
| 695 |
for (list<C_task *>::const_iterator it = tmp1.begin(); |
| 696 |
it != tmp1.end(); ++it) { |
| 697 |
if ((*it)->parallel_max == 0) { |
| 698 |
(*it)->parallel_max = kk1; |
| 699 |
} |
| 700 |
} |
| 701 |
first_loop_done = true; |
| 702 |
} // while (i0 < _tasks_DFullLDLt[j].size()) |
| 703 |
int ll = 0; |
| 704 |
while (i1 < _tasks_DTRSMScale[j].size()) { |
| 705 |
kk1 = 0; |
| 706 |
const int parallel_max =_tasks_DTRSMScale[j][i1]->parallel_max; |
| 707 |
for (int m = 0; m < parallel_max; m++) { |
| 708 |
const int atomic_size = _tasks_DTRSMScale[j][i1]->atomic_size; |
| 709 |
for (int n = 0; n < atomic_size; n++) { |
| 710 |
if (ll < ncol1) { |
| 711 |
_tasks_DTRSMScale[j][i1 + n]->parallel_id = kk1; |
| 712 |
_tasks_DTRSMScale[j][i1 + n]->parallel_max = 0; |
| 713 |
tmp1.push_back(_tasks_DTRSMScale[j][i1 + n]); |
| 714 |
} |
| 715 |
else { |
| 716 |
_tasks_DTRSMScale[j][i1 + n]->parallel_id = kk2; |
| 717 |
_tasks_DTRSMScale[j][i1 + n]->parallel_max = 0; |
| 718 |
tmp2.push_back(_tasks_DTRSMScale[j][i1 + n]); |
| 719 |
} |
| 720 |
} |
| 721 |
if (ll < ncol1) { |
| 722 |
kk1++; |
| 723 |
} |
| 724 |
else { |
| 725 |
kk2++; |
| 726 |
} |
| 727 |
i1 += atomic_size; |
| 728 |
ll++; |
| 729 |
if (ll == ncol) { |
| 730 |
ll = 0; |
| 731 |
} |
| 732 |
} // loop : m |
| 733 |
for (list<C_task *>::const_iterator it = tmp1.begin(); it != tmp1.end(); |
| 734 |
++it) { |
| 735 |
if ((*it)->parallel_max == 0) { |
| 736 |
(*it)->parallel_max = kk1; |
| 737 |
} |
| 738 |
} |
| 739 |
for (list<C_task *>::const_iterator it = tmp2.begin(); it != tmp2.end(); |
| 740 |
++it) { |
| 741 |
if ((*it)->parallel_max == 0) { |
| 742 |
(*it)->parallel_max = kk2; |
| 743 |
} |
| 744 |
} |
| 745 |
} // while (i1 < _tasks_DTRSMScale[j].size()) |
| 746 |
_tasks_DFullLDLt[j].resize(tmp1.size()); |
| 747 |
vector<C_task *>::iterator jt; |
| 748 |
jt = _tasks_DFullLDLt[j].begin(); |
| 749 |
for (list<C_task *>::const_iterator it = tmp1.begin(); it != tmp1.end(); |
| 750 |
++it, ++jt) { |
| 751 |
(*jt) = (*it); |
| 752 |
} |
| 753 |
tmp1.clear(); |
| 754 |
_tasks_DTRSMScale[j].clear(); |
| 755 |
_tasks_DTRSMScale[j].resize(tmp2.size()); |
| 756 |
jt = _tasks_DTRSMScale[j].begin(); |
| 757 |
for (list<C_task *>::const_iterator it = tmp2.begin(); it != tmp2.end(); |
| 758 |
++it, ++jt) { |
| 759 |
(*jt) = (*it); |
| 760 |
} |
| 761 |
isMergedDTRSM[j] = true; |
| 762 |
isDividedDTRSM[j] = true; |
| 763 |
} // if(nrow_DFullLDLt[j] > 2) |
| 764 |
else { |
| 765 |
if (nrow_DFullLDLt[j + ((j % 2 == 0 ) ? (-1) : 1)] > 2) { |
| 766 |
// brother has merged LDLt and DTRSM |
| 767 |
int size0 = _tasks_DFullLDLt[j].size(); |
| 768 |
int size1 = _tasks_DTRSMScale[j].size(); |
| 769 |
vector <C_task *> tmp; |
| 770 |
tmp.resize(size0 + size1); |
| 771 |
int ii = 0; |
| 772 |
for (int k = 0; k < _tasks_DFullLDLt[j].size(); k++, ii++) { |
| 773 |
tmp[ii] = _tasks_DFullLDLt[j][k]; |
| 774 |
tmp[ii]->parallel_max += size1; |
| 775 |
} |
| 776 |
for (int k = 0; k < _tasks_DTRSMScale[j].size(); k++, ii++) { |
| 777 |
tmp[ii] = _tasks_DTRSMScale[j][k]; |
| 778 |
tmp[ii]->parallel_max += size0; |
| 779 |
tmp[ii]->parallel_id += size0; |
| 780 |
} |
| 781 |
_tasks_DFullLDLt[j].resize(tmp.size()); |
| 782 |
vector<C_task *>::iterator jt = _tasks_DFullLDLt[j].begin(); |
| 783 |
for (vector<C_task *>::const_iterator it = tmp.begin(); it != tmp.end(); |
| 784 |
++it, ++jt) { |
| 785 |
(*jt) = (*it); |
| 786 |
} |
| 787 |
_tasks_DTRSMScale[j].clear(); |
| 788 |
isMergedDTRSM[j] = true; |
| 789 |
} // if |
| 790 |
}// else if(nrow_DFullLDLt[j] > 2) |
| 791 |
} // loop : d |
| 792 |
} |
| 793 |
|
| 794 |
list<C_task *> queue_null; |
| 795 |
_dissectionRuntime->generate_queue(_queue_symb, |
| 796 |
_queue_static, |
| 797 |
_queue_dynamic, |
| 798 |
queue_null, |
| 799 |
// _queue_dummy, |
| 800 |
_btree, |
| 801 |
_children, |
| 802 |
_tasks_SparseSymb, |
| 803 |
_tasks_SparseNum, |
| 804 |
_tasks_SparseLocalSchur, |
| 805 |
_tasks_DFillSym, |
| 806 |
_tasks_DFullLDLt, |
| 807 |
_tasks_DTRSMScale, |
| 808 |
_tasks_DSymmGEMM, |
| 809 |
_tasks_Dsub, |
| 810 |
_tasks_deallocLower, |
| 811 |
_tasks_deallocLocalSchur, |
| 812 |
nops_queue, |
| 813 |
all_fathersIndex, |
| 814 |
nrow_DFullLDLt, |
| 815 |
isMergedDTRSM, |
| 816 |
isDividedDTRSM, |
| 817 |
level_last); |
| 818 |
|
| 819 |
queue_null.sort(compare_task_name); |
| 820 |
queue_null.unique(); |
| 821 |
// #define DEBUG_QUEUE_NULL |
| 822 |
#ifdef DEBUG_QUEUE_NULL |
| 823 |
fprintf(_fp, "%s %d : NULL queues : ", __FILE__, __LINE__); |
| 824 |
#endif |
| 825 |
for (list<C_task *>::iterator it = queue_null.begin(); |
| 826 |
it != queue_null.end(); ++it) { |
| 827 |
#ifdef DEBUG_QUEUE_NULL |
| 828 |
fprintf(_fp, "%s %d : %s : %ld\n", |
| 829 |
__FILE__, __LINE__, (*it)->task_name, (*(*it)->ops_complexity)); |
| 830 |
#endif |
| 831 |
erase_task<T, U>(*it); |
| 832 |
} |
| 833 |
queue_null.clear(); |
| 834 |
|
| 835 |
delete [] tasks_deallocLocalSchur_indcol; |
| 836 |
delete [] tasks_DTRSMScale_indcol; |
| 837 |
delete [] tasks_DTRSMScale_index; |
| 838 |
delete [] tasks_DTRSMScale_parents_index; |
| 839 |
delete [] tasks_DTRSMScale_ptr; |
| 840 |
delete [] tasks_DSymmGEMM_indcol; |
| 841 |
delete [] nops_queue[0]; |
| 842 |
delete [] nops_queue; |
| 843 |
|
| 844 |
_queue_symb_allocated = true; |
| 845 |
_queue_numrc_allocated = true; |
| 846 |
} |
| 847 |
|
| 848 |
template |
| 849 |
void DissectionQueue<double>:: |
| 850 |
generate_queue(vector<DissectionMatrix<double>*>& dM, |
| 851 |
int nnz, double *coefs); |
| 852 |
|
| 853 |
template |
| 854 |
void DissectionQueue<quadruple>:: |
| 855 |
generate_queue(vector<DissectionMatrix<quadruple>*>& dM, |
| 856 |
int nnz, quadruple *coefs); |
| 857 |
|
| 858 |
template |
| 859 |
void DissectionQueue<complex<double>, double>:: |
| 860 |
generate_queue(vector<DissectionMatrix<complex<double>, double>*>& dM, |
| 861 |
int nnz, complex<double> *coefs); |
| 862 |
|
| 863 |
template |
| 864 |
void DissectionQueue<complex<quadruple>, quadruple>:: |
| 865 |
generate_queue(vector<DissectionMatrix<complex<quadruple>, quadruple>*>& dM, |
| 866 |
int nnz, complex<quadruple> *coefs); |
| 867 |
|
| 868 |
template |
| 869 |
void DissectionQueue<float>:: |
| 870 |
generate_queue(vector<DissectionMatrix<float>*>& dM, |
| 871 |
int nnz, float *coefs); |
| 872 |
|
| 873 |
template |
| 874 |
void DissectionQueue<complex<float>, float>:: |
| 875 |
generate_queue(vector<DissectionMatrix<complex<float>, float>*>& dM, |
| 876 |
int nnz, complex<float> *coefs); |
| 877 |
// |
| 878 |
|
| 879 |
template<typename T, typename U> |
| 880 |
void DissectionQueue<T, U>:: |
| 881 |
generate_queue_fwbw(vector<DissectionMatrix<T, U>*>& dM, |
| 882 |
int dim, |
| 883 |
int nnz, |
| 884 |
T *coefs) |
| 885 |
{ |
| 886 |
// const T zero(0.0); |
| 887 |
// const T none(-1.0); |
| 888 |
// const T one(1.0); |
| 889 |
const int nb_level = _btree->NumberOfLevels(); |
| 890 |
const int level_last = nb_level - 1; |
| 891 |
|
| 892 |
const int nb_doms = _btree->NumberOfSubdomains(); |
| 893 |
|
| 894 |
// allocation of working array for sereial execution |
| 895 |
// find maximum size of submatrix among dense domains |
| 896 |
// |
| 897 |
_dim = dim; |
| 898 |
_nnz = nnz; |
| 899 |
_nrhs = new int*; |
| 900 |
_isTrans = new bool*; |
| 901 |
_x = new T*; |
| 902 |
_xi = new T**[nb_doms]; |
| 903 |
_yi = new T**[nb_doms]; |
| 904 |
_zi = new T**[nb_doms]; |
| 905 |
_wi = new T**[nb_doms]; |
| 906 |
|
| 907 |
for (int d = 1; d <= nb_doms; d++) { |
| 908 |
const int d0 = _btree->selfIndex(d); |
| 909 |
_xi[d0] = new T*; |
| 910 |
_yi[d0] = new T*; |
| 911 |
_wi[d0] = new T*; |
| 912 |
_zi[d0] = new T*; |
| 913 |
} |
| 914 |
|
| 915 |
_diag_contribs = new list<diag_contribution>[nb_doms]; |
| 916 |
for (int level = level_last; level >= 0; level--) { |
| 917 |
const unsigned begdom = 1U << level; |
| 918 |
const unsigned enddom = begdom * 2; |
| 919 |
for (int d = begdom; d < enddom; d++) { |
| 920 |
int offset_src = 0; |
| 921 |
for (int ll = (level - 1); ll >=0; ll--) { |
| 922 |
const int father_id = _btree->nthfatherIndex(d, (level - ll)); |
| 923 |
const int father_id0 = _btree->selfIndex(father_id); |
| 924 |
// copy data from Xavier's SetOfStrips to list<index_strip> |
| 925 |
list<index_strip> diag; |
| 926 |
const Dissection::SetOfStrips &diag_x = _btree->getFathersStrips(d)[ll]; |
| 927 |
for (Dissection::SetOfStrips::const_iterator it = diag_x.begin(); |
| 928 |
it != diag_x.end(); ++it) { |
| 929 |
diag.push_back(index_strip((*it).begin_dst, |
| 930 |
(*it).begin_src + offset_src, |
| 931 |
(*it).width)); |
| 932 |
} |
| 933 |
list<diag_contribution> &tmp = _diag_contribs[father_id0]; |
| 934 |
tmp.push_back(diag_contribution(d, |
| 935 |
_btree->sizeOfDomain(d), |
| 936 |
_btree->sizeOfFathersStrips(d), |
| 937 |
_btree->sizeOfDomain(father_id), |
| 938 |
diag)); |
| 939 |
|
| 940 |
offset_src += diag_x.numberOfIndices(); |
| 941 |
} |
| 942 |
} |
| 943 |
} |
| 944 |
vector<C_task*> tasks_a(1U << level_last); |
| 945 |
// sparse solver forward substitution phase |
| 946 |
{ // begin : sparse |
| 947 |
const unsigned begdom = 1U << level_last; |
| 948 |
const unsigned enddom = begdom * 2; |
| 949 |
int ipos = 0; |
| 950 |
for (int d = begdom; d < enddom; d++, ipos++) { // to be parallelized |
| 951 |
const int dd0 = d - begdom; |
| 952 |
const int d0 = _btree->selfIndex(d); |
| 953 |
const CSR_indirect &offdiag = _btree->getOffdiagCSR(d); |
| 954 |
int *indVals = offdiag.indVals; |
| 955 |
// get from the global array |
| 956 |
// const int *loc2glob_diag = _btree->getDiagLoc2Glob(d); |
| 957 |
const int colors = dM[d0]->ColorTridiagBlockMatrix(); |
| 958 |
C_SparseFw_arg<T, U> *arg = |
| 959 |
new C_SparseFw_arg<T, U>(colors, |
| 960 |
d, |
| 961 |
_isSym, |
| 962 |
dim, |
| 963 |
_isTrans, // |
| 964 |
_nrhs, |
| 965 |
dM[d0]->addrtridiagBlock(), |
| 966 |
_x, |
| 967 |
_yi[d0], |
| 968 |
_zi[d0], |
| 969 |
coefs, |
| 970 |
(int)_btree->sizeOfDomain(d), |
| 971 |
(int)_btree->sizeOfFathersStrips(d), |
| 972 |
offdiag.ptRows, |
| 973 |
offdiag.indCols, |
| 974 |
(_isSym ? indVals : offdiag.indVals_unsym), |
| 975 |
indVals, |
| 976 |
_btree->getDiagLoc2Glob(d)); |
| 977 |
string task_name = "a : " + to_string(d); |
| 978 |
*(arg->ops_complexity) = (long)dim; |
| 979 |
C_task *task = new C_task(C_SPARSESYMFW, |
| 980 |
task_name, |
| 981 |
(void *)arg, |
| 982 |
C_SparseFw<T, U>, |
| 983 |
1, |
| 984 |
0, |
| 985 |
arg->ops_complexity); |
| 986 |
task->parallel_max = begdom; |
| 987 |
task->parallel_id = dd0; |
| 988 |
task->parents->clear(); // no dependency |
| 989 |
tasks_a[dd0] = task; |
| 990 |
} // loop : d |
| 991 |
} // end : sparse |
| 992 |
// updating RHS vector from level_last to all levels less than level_last |
| 993 |
vector<C_task*> tasks_i((1U << level_last) - 1); |
| 994 |
{ |
| 995 |
const unsigned begdom = 1U; |
| 996 |
const unsigned enddom = 1U << level_last; |
| 997 |
for (int d = begdom; d < enddom; d++) { // to be parallelized |
| 998 |
const int dd0 = d - begdom; |
| 999 |
const int d0 = _btree->selfIndex(d); |
| 1000 |
const int n_diag = _btree->sizeOfDomain(d); |
| 1001 |
if (n_diag == 0) { |
| 1002 |
string task_name = ("i dummy : " + to_string(d)); |
| 1003 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1004 |
tasks_i[dd0] = new C_task(C_DUMMY, |
| 1005 |
task_name, |
| 1006 |
(void *)arg, |
| 1007 |
C_dummy, |
| 1008 |
1, // atomic_size, |
| 1009 |
0, // atomic_id, |
| 1010 |
arg->ops_complexity); |
| 1011 |
} |
| 1012 |
else { |
| 1013 |
C_Dsub_FwBw_arg<T> *arg = |
| 1014 |
new C_Dsub_FwBw_arg<T>(dim, |
| 1015 |
_nrhs, |
| 1016 |
n_diag, |
| 1017 |
true, |
| 1018 |
level_last, |
| 1019 |
_btree, |
| 1020 |
&_diag_contribs[d0], |
| 1021 |
_x, |
| 1022 |
_yi[d0], |
| 1023 |
_zi, |
| 1024 |
_btree->getDiagLoc2Glob(d)); |
| 1025 |
string task_name = "i : " + to_string(d); |
| 1026 |
*(arg->ops_complexity) = (long)n_diag; |
| 1027 |
C_task *task = new C_task(C_DSUB_FWBW, |
| 1028 |
task_name, |
| 1029 |
(void *)arg, |
| 1030 |
C_Dsub_FwBw<T>, |
| 1031 |
1, |
| 1032 |
0, |
| 1033 |
arg->ops_complexity); |
| 1034 |
//task->func(task->func_arg); |
| 1035 |
task->parallel_max = enddom; |
| 1036 |
task->parallel_id = dd0; |
| 1037 |
const int begdom0 = 1U << level_last; |
| 1038 |
for (list<diag_contribution>::const_iterator it = _diag_contribs[d0].begin(); |
| 1039 |
it != _diag_contribs[d0].end(); ++it) { |
| 1040 |
const int child_id = (*it).child_id; |
| 1041 |
if (_btree->nodeLayer(child_id) == level_last) { |
| 1042 |
task->parents->push_back(tasks_a[child_id - begdom0]); |
| 1043 |
} |
| 1044 |
} |
| 1045 |
tasks_i[dd0] = task; |
| 1046 |
} |
| 1047 |
} // loop : d |
| 1048 |
} |
| 1049 |
// forward substitution of dense part |
| 1050 |
vector<C_task*>** tasks_de = new vector<C_task*>*[level_last]; |
| 1051 |
tasks_de[0] = new vector<C_task*>[(1U << (level_last + 1)) - 1]; |
| 1052 |
vector<C_task*>** tasks_k = new vector<C_task*>*[level_last]; |
| 1053 |
tasks_k[0] = new vector<C_task*>[(1U << (level_last + 1)) - 1]; |
| 1054 |
vector<C_task*>* tasks_j = new vector<C_task *>[level_last]; |
| 1055 |
for (int level = (level_last - 1); level >= 0; level--) { |
| 1056 |
const unsigned begdom = 1U << level; |
| 1057 |
const unsigned enddom = begdom * 2; |
| 1058 |
if (level > 0) { |
| 1059 |
tasks_de[level] = tasks_de[0] + ((1U << level) - 1); |
| 1060 |
tasks_k[level] = tasks_k[0] + ((1U << level) - 1); |
| 1061 |
} |
| 1062 |
for (int d = begdom; d < enddom; d++) { // to be parallelized |
| 1063 |
const int dd0 = d - begdom; |
| 1064 |
const int d0 = _btree->selfIndex(d); |
| 1065 |
const int n_diag = _btree->sizeOfDomain(d); |
| 1066 |
// fprintf(stderr, "%s %d : %d %d\n", __FILE__, __LINE__, d, n_diag); |
| 1067 |
const int n_offdiag = _btree->sizeOfFathersStrips(d); |
| 1068 |
SquareBlockMatrix<T> &Diag = dM[d0]->diagBlock(); |
| 1069 |
// const int *permute = Diag.getPermute().getAddr(); |
| 1070 |
{ // closure of tasks_de |
| 1071 |
const int num_block = Diag.num_blocks(); |
| 1072 |
if (n_diag == 0) { |
| 1073 |
tasks_de[level][dd0].resize(1); |
| 1074 |
string task_name = ("d dummy : " + to_string(d)); |
| 1075 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1076 |
tasks_de[level][dd0][0] = new C_task(C_DUMMY, |
| 1077 |
task_name, |
| 1078 |
(void *)arg, |
| 1079 |
C_dummy, |
| 1080 |
1, // atomic_size, |
| 1081 |
0, // atomic_id, |
| 1082 |
arg->ops_complexity); |
| 1083 |
} |
| 1084 |
else { |
| 1085 |
tasks_de[level][dd0].resize((num_block * (num_block + 1)) / 2); |
| 1086 |
for (int k = 0; k < num_block; k++) { |
| 1087 |
const int kk = Diag.IndexBlock(k); |
| 1088 |
const int ncol = Diag.nrowBlock(k); |
| 1089 |
C_DenseFwBw_arg<T> *arg = |
| 1090 |
new C_DenseFwBw_arg<T>(_isSym, |
| 1091 |
false, // isBackward |
| 1092 |
(int)dim, |
| 1093 |
_isTrans, |
| 1094 |
_nrhs, |
| 1095 |
(int)n_diag, |
| 1096 |
(int)ncol, // |
| 1097 |
(int)k, |
| 1098 |
(int)kk, |
| 1099 |
_xi[d0], |
| 1100 |
_wi[d0], |
| 1101 |
_yi[d0], |
| 1102 |
(T **)NULL, |
| 1103 |
dM[d0]->addrdiagBlock(), |
| 1104 |
(k == 0), // isFirstBlock |
| 1105 |
(k == (num_block - 1)), // isLastBlock |
| 1106 |
(int *)NULL, |
| 1107 |
_verbose, |
| 1108 |
&_fp); |
| 1109 |
string task_name = "d : " + to_string(d) + " : " + to_string(k); |
| 1110 |
*(arg->ops_complexity) = (long)n_diag; |
| 1111 |
C_task *task = new C_task(C_DENSE_SYMFW_DIAG, |
| 1112 |
task_name, |
| 1113 |
(void *)arg, |
| 1114 |
C_DenseFwBw_diag<T>, |
| 1115 |
1, |
| 1116 |
0, |
| 1117 |
arg->ops_complexity); |
| 1118 |
if (k == 0) { |
| 1119 |
task->parallel_max = 1; |
| 1120 |
task->parallel_id = 0; |
| 1121 |
tasks_de[level][dd0][0] = task; |
| 1122 |
if (level == (level_last - 1)) { |
| 1123 |
task->parents->push_back(tasks_i[d0]); // |
| 1124 |
} |
| 1125 |
else { |
| 1126 |
task->parents->push_back(tasks_j[level + 1][d0]); |
| 1127 |
} |
| 1128 |
} |
| 1129 |
else { |
| 1130 |
task->parallel_max = num_block - k; |
| 1131 |
task->parallel_id = 0; |
| 1132 |
task->atomic_size = 2; |
| 1133 |
task->atomic_id = 1; |
| 1134 |
int ipos; |
| 1135 |
// depending on e_{k k-1} |
| 1136 |
ipos = 2 + num_block * (k - 1) - ((k - 1) * k) / 2 + k - 1; |
| 1137 |
task->parents->push_back(tasks_de[level][dd0][ipos - 1]); // |
| 1138 |
tasks_de[level][dd0][ipos] = task; |
| 1139 |
for (int m = 0; m < (k - 1); m++) { |
| 1140 |
ipos = num_block * m + k + 1 - (m * (m + 1)) / 2; |
| 1141 |
task->parents->push_back(tasks_de[level][dd0][ipos]); // |
| 1142 |
} |
| 1143 |
} |
| 1144 |
// updating of lower blocks xi[d0] + ii are independent among i |
| 1145 |
for (int i = (k + 1); i < num_block; i++) { |
| 1146 |
const int ii = Diag.IndexBlock(i); |
| 1147 |
const int nrow = Diag.nrowBlock(i); |
| 1148 |
C_DenseFwBwOffdiag_arg<T> *arg = |
| 1149 |
new C_DenseFwBwOffdiag_arg<T>(_isSym ? true : false, //trans |
| 1150 |
true, //isLower |
| 1151 |
(int)dim, |
| 1152 |
_isTrans, |
| 1153 |
_nrhs, |
| 1154 |
(int)n_diag, |
| 1155 |
(int)n_diag, |
| 1156 |
(int)n_diag, //ldc |
| 1157 |
(int)nrow, |
| 1158 |
(int)ncol, |
| 1159 |
_wi[d0], |
| 1160 |
kk, // ii |
| 1161 |
_yi[d0], // |
| 1162 |
_xi[d0], // |
| 1163 |
ii, // jj |
| 1164 |
dM[d0]->addrdiagBlock(), |
| 1165 |
i, // i_block |
| 1166 |
k, // j_block |
| 1167 |
_none, // alpha, |
| 1168 |
_one); // beta |
| 1169 |
string task_name = ("e : " + to_string(d) + " : " + to_string(k) |
| 1170 |
+ " " + to_string(i)); |
| 1171 |
*(arg->ops_complexity) = (long)dim; |
| 1172 |
C_task *task = new C_task(C_DENSE_SYMFW_OFFDIAG, |
| 1173 |
task_name, |
| 1174 |
(void *)arg, |
| 1175 |
C_DenseFwBw_offdiag<T>, |
| 1176 |
1, |
| 1177 |
0, |
| 1178 |
arg->ops_complexity); |
| 1179 |
task->parallel_max = num_block - (k + 1); |
| 1180 |
task->parallel_id = i - (k + 1); |
| 1181 |
int ipos; |
| 1182 |
// depending on d_{k-1} |
| 1183 |
if (k > 0) { |
| 1184 |
ipos = num_block * (k - 1) + i + 1 - ((k - 1) * k) / 2; |
| 1185 |
task->parents->push_back(tasks_de[level][dd0][ipos]); |
| 1186 |
} |
| 1187 |
if (k > 0) { |
| 1188 |
ipos = 2 + num_block * (k - 1) - ((k - 1) * k) / 2 + k - 1; |
| 1189 |
} |
| 1190 |
else { |
| 1191 |
ipos = 0; |
| 1192 |
} |
| 1193 |
task->parents->push_back(tasks_de[level][dd0][ipos]); |
| 1194 |
if (i == (k + 1)) { |
| 1195 |
task->atomic_size = 2; // |
| 1196 |
task->atomic_id = 0; // |
| 1197 |
ipos = 2 + num_block * k - (k * (k + 1)) / 2 + k - 1; |
| 1198 |
tasks_de[level][dd0][ipos] = task; |
| 1199 |
} |
| 1200 |
else { // i > (k + 1) |
| 1201 |
ipos = num_block * k + i + 1 - (k * (k + 1)) / 2; |
| 1202 |
tasks_de[level][dd0][ipos] = task; |
| 1203 |
} // if (i == (k + 1)) |
| 1204 |
} // loop : i |
| 1205 |
} // loop : k |
| 1206 |
} // if (n_diag == 0) |
| 1207 |
} // closure of tasks_de |
| 1208 |
if (level > 0) { |
| 1209 |
// const int num_block = Diag.num_blocks(); // |
| 1210 |
const int num_block_r = Diag.num_blocks(); |
| 1211 |
|
| 1212 |
RectBlockMatrix<T> *upperblock = |
| 1213 |
(_isSym ? dM[d0]->addrupperBlock() : dM[d0]->addrlowerBlock()); |
| 1214 |
RectBlockMatrix<T> *lowerblock = dM[d0]->addrupperBlock(); |
| 1215 |
const int num_block_c = upperblock->num_blocks_c(); |
| 1216 |
if (n_diag == 0) { |
| 1217 |
tasks_k[level][dd0].resize(1); |
| 1218 |
string task_name = ("k dummy : " + to_string(d)); |
| 1219 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1220 |
tasks_k[level][dd0][0] = new C_task(C_DUMMY, |
| 1221 |
task_name, |
| 1222 |
(void *)arg, |
| 1223 |
C_dummy, |
| 1224 |
1, // atomic_size, |
| 1225 |
0, // atomic_id, |
| 1226 |
arg->ops_complexity); |
| 1227 |
} |
| 1228 |
else { |
| 1229 |
tasks_k[level][dd0].resize(num_block_r * num_block_c); |
| 1230 |
|
| 1231 |
// const double alpha = 1.0; |
| 1232 |
for (int i = 0; i < num_block_r; i++) { |
| 1233 |
const int ii = Diag.IndexBlock(i); |
| 1234 |
const int nrow = Diag.nrowBlock(i); |
| 1235 |
const T beta = (i == 0) ? _zero : _one; |
| 1236 |
|
| 1237 |
for (int j = 0; j < num_block_c; j++) { |
| 1238 |
const int jj = upperblock->IndexBlock_c(j); // j * SIZE_B1; |
| 1239 |
const int ncol = upperblock->ncolBlock(j); |
| 1240 |
C_StripsFwBwOffdiag_arg<T> *arg = |
| 1241 |
new C_StripsFwBwOffdiag_arg<T>(true, // isLower |
| 1242 |
(int)dim, |
| 1243 |
_isTrans, |
| 1244 |
_nrhs, |
| 1245 |
(int)n_diag, |
| 1246 |
(int)n_diag, |
| 1247 |
(int)n_offdiag, |
| 1248 |
(int)ncol, // refering to upper |
| 1249 |
(int)nrow, |
| 1250 |
_wi[d0], |
| 1251 |
ii, // ii, |
| 1252 |
_zi[d0], |
| 1253 |
jj, // jj, |
| 1254 |
upperblock, |
| 1255 |
lowerblock, |
| 1256 |
i, |
| 1257 |
j, |
| 1258 |
_one, // alpha, |
| 1259 |
beta); |
| 1260 |
string task_name = ("k : " + to_string(d) + " : " + to_string(i) |
| 1261 |
+ " " + to_string(j)); |
| 1262 |
*(arg->ops_complexity) = (long)n_diag; |
| 1263 |
C_task *task = new C_task(C_STRIPS_SYMFW_OFFDIAG, |
| 1264 |
task_name, |
| 1265 |
(void *)arg, |
| 1266 |
C_StripsFwBw_offdiag<T>, |
| 1267 |
1, |
| 1268 |
0, |
| 1269 |
arg->ops_complexity); |
| 1270 |
task->parallel_max = num_block_c; // sequential among i |
| 1271 |
task->parallel_id = j; // parallel among j |
| 1272 |
int ipos; |
| 1273 |
if (i == 0) { |
| 1274 |
task->parents->push_back(tasks_de[level][dd0][0]); |
| 1275 |
} |
| 1276 |
else { |
| 1277 |
ipos = 2 + num_block_r * (i - 1) - ((i - 1) * i) / 2 + i - 1; |
| 1278 |
task->parents->push_back(tasks_de[level][dd0][ipos]); |
| 1279 |
ipos = (i - 1) * num_block_c + j; |
| 1280 |
task->parents->push_back(tasks_k[level][dd0][ipos]); |
| 1281 |
} |
| 1282 |
ipos = i * num_block_c + j; |
| 1283 |
tasks_k[level][dd0][ipos] = task; |
| 1284 |
} // loop : j |
| 1285 |
} // loop : i |
| 1286 |
} |
| 1287 |
} // if (level > 0) |
| 1288 |
// solving D y = x |
| 1289 |
} // loop : d |
| 1290 |
// updating RHS vector from level to all levels less than level |
| 1291 |
{ |
| 1292 |
const unsigned begdom = 1U; |
| 1293 |
const unsigned enddom = 1U << level; |
| 1294 |
tasks_j[level].resize(enddom - 1); |
| 1295 |
for (int d = begdom; d < enddom; d++) { // to be parallelized |
| 1296 |
const int dd0 = d - begdom; |
| 1297 |
const int d0 = _btree->selfIndex(d); |
| 1298 |
const int n_diag = _btree->sizeOfDomain(d); |
| 1299 |
if (n_diag == 0) { |
| 1300 |
string task_name = ("j dummy : " + to_string(d)); |
| 1301 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1302 |
tasks_j[level][dd0] = new C_task(C_DUMMY, |
| 1303 |
task_name, |
| 1304 |
(void *)arg, |
| 1305 |
C_dummy, |
| 1306 |
1, // atomic_size, |
| 1307 |
0, // atomic_id, |
| 1308 |
arg->ops_complexity); |
| 1309 |
} |
| 1310 |
else { |
| 1311 |
C_Dsub_FwBw_arg<T> *arg = |
| 1312 |
new C_Dsub_FwBw_arg<T>(dim, |
| 1313 |
_nrhs, |
| 1314 |
-1, // n_diag |
| 1315 |
false, // access_global |
| 1316 |
level, |
| 1317 |
_btree, |
| 1318 |
&_diag_contribs[d0], |
| 1319 |
(T **)NULL, // x |
| 1320 |
_yi[d0], |
| 1321 |
_zi, |
| 1322 |
_btree->getDiagLoc2Glob(d)); |
| 1323 |
string task_name = "j : " + to_string(level) + " : " + to_string(d); |
| 1324 |
*(arg->ops_complexity) = (long)dim; |
| 1325 |
C_task *task = new C_task(C_DSUB_FWBW, |
| 1326 |
task_name, |
| 1327 |
(void *)arg, |
| 1328 |
C_Dsub_FwBw<T>, |
| 1329 |
1, |
| 1330 |
0, |
| 1331 |
arg->ops_complexity); |
| 1332 |
// task->func(task->func_arg); |
| 1333 |
task->parallel_max = enddom; |
| 1334 |
task->parallel_id = d0; |
| 1335 |
task->parents->push_back(tasks_i[dd0]); |
| 1336 |
for (list<diag_contribution>::const_iterator it = _diag_contribs[d0].begin(); |
| 1337 |
it != _diag_contribs[d0].end(); ++it) { |
| 1338 |
if ((*it).diag_strip.size() > 0) { // to avoid null contribution |
| 1339 |
const int child_id = (*it).child_id; |
| 1340 |
if (_btree->nodeLayer(child_id) == level) { |
| 1341 |
const int child_id0 = _btree->selfIndex(child_id); |
| 1342 |
RectBlockMatrix<T> *upperblock = dM[child_id0]->addrupperBlock(); |
| 1343 |
const int num_block_r = upperblock->num_blocks_r(); |
| 1344 |
const int num_block_c = upperblock->num_blocks_c(); |
| 1345 |
for (int j = 0; j < num_block_c; j++) { |
| 1346 |
int ipos = (num_block_r - 1) * num_block_c + j; |
| 1347 |
task->parents->push_back(tasks_k[0][child_id0][ipos]); |
| 1348 |
} |
| 1349 |
} // if (_btree->nodeLayer(child_id) == level) |
| 1350 |
} // (if (*it).diag_strip.size() > 0) |
| 1351 |
} // loop : it |
| 1352 |
tasks_j[level][dd0] = task; |
| 1353 |
} |
| 1354 |
} // loop : d |
| 1355 |
} |
| 1356 |
} // loop : level |
| 1357 |
vector<C_task*>* tasks_h = new vector<C_task *>[level_last]; |
| 1358 |
vector<C_task*>** tasks_l = new vector<C_task*>*[level_last]; |
| 1359 |
vector<C_task*>** tasks_fg = new vector<C_task*>*[level_last]; |
| 1360 |
tasks_l[0] = new vector<C_task*>[(1U << (level_last + 1)) - 1]; |
| 1361 |
tasks_fg[0] = new vector<C_task*>[(1U << (level_last + 1)) - 1]; |
| 1362 |
for (int level = 0; level < level_last; level++) { |
| 1363 |
const unsigned begdom = 1U << level; |
| 1364 |
const unsigned enddom = begdom * 2; |
| 1365 |
tasks_h[level].resize(enddom - 1); |
| 1366 |
if (level > 0) { |
| 1367 |
tasks_fg[level] = tasks_fg[0] + ((1U << level) - 1); |
| 1368 |
tasks_l[level] = tasks_l[0] + ((1U << level) - 1); |
| 1369 |
} |
| 1370 |
for (int d = begdom; d < enddom; d++) { // to be parallelized |
| 1371 |
const int dd0 = d - begdom; |
| 1372 |
const int d0 = _btree->selfIndex(d); |
| 1373 |
const int n_diag = _btree->sizeOfDomain(d); |
| 1374 |
const int n_offdiag = _btree->sizeOfFathersStrips(d); |
| 1375 |
SquareBlockMatrix<T> &Diag = dM[d0]->diagBlock(); |
| 1376 |
if (level > 0) { |
| 1377 |
if (n_diag == 0) { |
| 1378 |
string task_name = ("h dummy : " + to_string(d)); |
| 1379 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1380 |
tasks_h[level][dd0] = new C_task(C_DUMMY, |
| 1381 |
task_name, |
| 1382 |
(void *)arg, |
| 1383 |
C_dummy, |
| 1384 |
1, // atomic_size, |
| 1385 |
0, // atomic_id, |
| 1386 |
arg->ops_complexity); |
| 1387 |
} |
| 1388 |
else { |
| 1389 |
C_Dfill_FwBw_arg<T> *arg = |
| 1390 |
new C_Dfill_FwBw_arg<T>(_nrhs, |
| 1391 |
d, |
| 1392 |
level, |
| 1393 |
_btree, |
| 1394 |
(int)n_offdiag, |
| 1395 |
_yi, |
| 1396 |
_zi[d0]); |
| 1397 |
string task_name = "h : " + to_string(d); |
| 1398 |
*(arg->ops_complexity) = (long)n_offdiag; |
| 1399 |
C_task *task = new C_task(C_DENSE_SYMFILL, |
| 1400 |
task_name, |
| 1401 |
(void *)arg, |
| 1402 |
C_Dfill_FwBw<T>, |
| 1403 |
1, |
| 1404 |
0, |
| 1405 |
arg->ops_complexity); |
| 1406 |
task->parallel_max = enddom - 1; |
| 1407 |
task->parallel_id = dd0; |
| 1408 |
task->parents->clear(); |
| 1409 |
for (int ll = (level - 1); ll >= 0; ll--) { |
| 1410 |
const int father_id = _btree->nthfatherIndex(d, (level - ll)); |
| 1411 |
const int father_id0 = _btree->selfIndex(father_id); |
| 1412 |
const Dissection::SetOfStrips &diag = _btree->getFathersStrips(d)[ll]; |
| 1413 |
if (diag.numberOfIndices() > 0) { |
| 1414 |
const int ipos = tasks_fg[0][father_id0].size() - 1; // the last |
| 1415 |
C_task *task_parent = tasks_fg[0][father_id0][ipos]; |
| 1416 |
bool flag = false; |
| 1417 |
for (list<C_task *>::const_iterator it = task->parents->begin(); |
| 1418 |
it != task->parents->end(); ++it) { |
| 1419 |
if ((*it) == task_parent) { |
| 1420 |
flag = true; |
| 1421 |
break; |
| 1422 |
} |
| 1423 |
} // loop : it |
| 1424 |
if (flag == false) { |
| 1425 |
task->parents->push_back(task_parent); |
| 1426 |
} |
| 1427 |
} |
| 1428 |
} |
| 1429 |
tasks_h[level][dd0] = task; |
| 1430 |
} |
| 1431 |
const int num_block_r = Diag.num_blocks(); |
| 1432 |
if (n_diag == 0) { |
| 1433 |
tasks_l[level][dd0].resize(1); |
| 1434 |
string task_name = ("l dummy : " + to_string(d)); |
| 1435 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1436 |
tasks_l[level][dd0][0] = new C_task(C_DUMMY, |
| 1437 |
task_name, |
| 1438 |
(void *)arg, |
| 1439 |
C_dummy, |
| 1440 |
1, // atomic_size, |
| 1441 |
0, // atomic_id, |
| 1442 |
arg->ops_complexity); |
| 1443 |
} |
| 1444 |
else { |
| 1445 |
tasks_l[level][dd0].resize(num_block_r); |
| 1446 |
for (int i = 0; i < num_block_r; i++) { |
| 1447 |
const int ii = Diag.IndexBlock(i); |
| 1448 |
const int nrow = Diag.nrowBlock(i); |
| 1449 |
C_StripsFwBwOffdiag_arg<T> *arg = |
| 1450 |
new C_StripsFwBwOffdiag_arg<T>(false, // isLower |
| 1451 |
(int)dim, |
| 1452 |
_isTrans, |
| 1453 |
_nrhs, |
| 1454 |
(int)n_diag, |
| 1455 |
(int)n_offdiag, |
| 1456 |
(int)n_diag, |
| 1457 |
(int)nrow, |
| 1458 |
(int)n_offdiag, |
| 1459 |
_zi[d0], |
| 1460 |
0, // ii, |
| 1461 |
_xi[d0], |
| 1462 |
ii, // jj, |
| 1463 |
dM[d0]->addrupperBlock(), |
| 1464 |
dM[d0]->addrlowerBlock(), |
| 1465 |
0, |
| 1466 |
i, |
| 1467 |
_none, //alpha, |
| 1468 |
_one); // beta); |
| 1469 |
string task_name = "l : " + to_string(d) + " : " + to_string(i); |
| 1470 |
*(arg->ops_complexity) = (long)n_diag; |
| 1471 |
C_task *task = new C_task(C_STRIPS_SYMFW_OFFDIAG, |
| 1472 |
task_name, |
| 1473 |
(void *)arg, |
| 1474 |
C_StripsFwBw_offdiag<T>, |
| 1475 |
1, |
| 1476 |
0, |
| 1477 |
arg->ops_complexity); |
| 1478 |
int ipos; |
| 1479 |
task->parents->push_back(tasks_h[level][dd0]); |
| 1480 |
const int father_id = _btree->fatherIndex(d); |
| 1481 |
const int father_id0 = _btree->selfIndex(father_id); |
| 1482 |
ipos = tasks_fg[0][father_id0].size() - 1; // the last of tasks_fg |
| 1483 |
if (ipos >= 0) { |
| 1484 |
task->parents->push_back(tasks_fg[0][father_id0][ipos]); |
| 1485 |
} |
| 1486 |
tasks_l[level][dd0][i] = task; |
| 1487 |
} // loop : i |
| 1488 |
} // if (n_diag == 0) |
| 1489 |
} // if (level > 0) |
| 1490 |
{ |
| 1491 |
SquareBlockMatrix<T> &Diag = dM[d0]->diagBlock(); |
| 1492 |
const int num_block = Diag.num_blocks(); |
| 1493 |
if (n_diag == 0) { |
| 1494 |
tasks_fg[level][dd0].resize(1); |
| 1495 |
string task_name = ("d dummy : " + to_string(d)); |
| 1496 |
C_dummy_arg *arg = new C_dummy_arg(_verbose, &_fp, d); |
| 1497 |
tasks_fg[level][dd0][0] = new C_task(C_DUMMY, |
| 1498 |
task_name, |
| 1499 |
(void *)arg, |
| 1500 |
C_dummy, |
| 1501 |
1, // atomic_size, |
| 1502 |
0, // atomic_id, |
| 1503 |
arg->ops_complexity); |
| 1504 |
|
| 1505 |
} |
| 1506 |
else { |
| 1507 |
tasks_fg[level][dd0].resize((num_block * (num_block + 1)) / 2); |
| 1508 |
int k0 = 0; |
| 1509 |
for (int k = (num_block - 1); k >= 0; k--, k0++) { |
| 1510 |
const int kk = Diag.IndexBlock(k); |
| 1511 |
const int ncol = Diag.nrowBlock(k); |
| 1512 |
C_DenseFwBw_arg<T> *arg = |
| 1513 |
new C_DenseFwBw_arg<T>(_isSym, |
| 1514 |
true, // isBackward |
| 1515 |
(int)dim, |
| 1516 |
_isTrans, |
| 1517 |
_nrhs, |
| 1518 |
(int)n_diag, |
| 1519 |
(int)ncol, // |
| 1520 |
(int)k, |
| 1521 |
(int)kk, |
| 1522 |
_xi[d0], |
| 1523 |
(T **)NULL, |
| 1524 |
_yi[d0], // |
| 1525 |
(k == 0) ? _x : (T **)NULL, |
| 1526 |
dM[d0]->addrdiagBlock(), |
| 1527 |
(k == 0), // isFirstBlock |
| 1528 |
(k == (num_block - 1)), // isLastBlock |
| 1529 |
(k == 0) ? _btree->getDiagLoc2Glob(d) : (int *)NULL, |
| 1530 |
_verbose, |
| 1531 |
&_fp); |
| 1532 |
string task_name = "f : " + to_string(d) + " : " + to_string(k); |
| 1533 |
*(arg->ops_complexity) = (long)dim; |
| 1534 |
C_task *task = new C_task(C_DENSE_SYMFW_DIAG, |
| 1535 |
task_name, |
| 1536 |
(void *)arg, |
| 1537 |
C_DenseFwBw_diag<T>, |
| 1538 |
1, |
| 1539 |
0, |
| 1540 |
arg->ops_complexity); |
| 1541 |
if (k0 == 0) { |
| 1542 |
task->parallel_max = 1; |
| 1543 |
task->parallel_id = 0; |
| 1544 |
tasks_fg[level][dd0][0] = task; |
| 1545 |
if (level == 0){ |
| 1546 |
const int ipos = tasks_de[0][0].size() - 1; //the last of the fw |
| 1547 |
if (ipos >= 0) { |
| 1548 |
task->parents->push_back(tasks_de[0][0][ipos]); |
| 1549 |
} |
| 1550 |
} |
| 1551 |
else { |
| 1552 |
task->parents->push_back(tasks_l[0][d0][k]); |
| 1553 |
} |
| 1554 |
} |
| 1555 |
else { |
| 1556 |
task->parallel_max = num_block - k0; |
| 1557 |
task->parallel_id = 0; |
| 1558 |
task->atomic_size = 2; |
| 1559 |
task->atomic_id = 1; |
| 1560 |
int ipos; |
| 1561 |
ipos = 2 + num_block * (k0 - 1) - ((k0 - 1) * k0) / 2 + k0 - 1; |
| 1562 |
task->parents->push_back(tasks_fg[level][dd0][ipos - 1]); // |
| 1563 |
tasks_fg[level][dd0][ipos] = task; |
| 1564 |
for (int m = 0; m < (k0 - 1); m++) { |
| 1565 |
ipos = num_block * m + k0 + 1 - (m * (m + 1)) / 2; |
| 1566 |
task->parents->push_back(tasks_fg[level][dd0][ipos]); // |
| 1567 |
} |
| 1568 |
} |
| 1569 |
int i0 = k0 + 1; // a trick to use the same formula to count ipos |
| 1570 |
for (int i = (k - 1); i >= 0; i--, i0++) { |
| 1571 |
const int ii = Diag.IndexBlock(i); |
| 1572 |
const int nrow = Diag.nrowBlock(i); // SIZE_B1; // ? |
| 1573 |
C_DenseFwBwOffdiag_arg<T> *arg = |
| 1574 |
new C_DenseFwBwOffdiag_arg<T>(false, // trans |
| 1575 |
false, // isLower |
| 1576 |
(int)dim, |
| 1577 |
_isTrans, |
| 1578 |
_nrhs, |
| 1579 |
(int)n_diag, |
| 1580 |
(int)n_diag, |
| 1581 |
(int)n_diag, |
| 1582 |
(int)nrow, |
| 1583 |
(int)ncol, |
| 1584 |
_xi[d0], |
| 1585 |
kk, // ii |
| 1586 |
_xi[d0], |
| 1587 |
_xi[d0], // (double **)NULL, |
| 1588 |
ii, // jj |
| 1589 |
dM[d0]->addrdiagBlock(), |
| 1590 |
i, // i_block |
| 1591 |
k, // j_block |
| 1592 |
_none, // alpha, |
| 1593 |
_one); //beta); |
| 1594 |
string task_name = ("g : " + to_string(d) + " : " + to_string(k) |
| 1595 |
+ " " + to_string(i)); |
| 1596 |
*(arg->ops_complexity) = (long)dim; |
| 1597 |
C_task *task = new C_task(C_DENSE_SYMFW_OFFDIAG, |
| 1598 |
task_name, |
| 1599 |
(void *)arg, |
| 1600 |
C_DenseFwBw_offdiag<T>, |
| 1601 |
1, |
| 1602 |
0, |
| 1603 |
arg->ops_complexity); |
| 1604 |
if (level > 0) { |
| 1605 |
task->parents->push_back(tasks_l[0][d0][i]); |
| 1606 |
} |
| 1607 |
task->parallel_max = num_block - (k0 + 1); |
| 1608 |
int ipos; |
| 1609 |
if (k0 > 0) { |
| 1610 |
ipos = num_block * (k0 - 1) + i0 + 1 - ((k0 - 1) * k0) / 2; |
| 1611 |
task->parents->push_back(tasks_fg[level][dd0][ipos]); |
| 1612 |
} |
| 1613 |
if (k0 > 0) { |
| 1614 |
ipos = 2 + num_block * (k0 - 1) - ((k0 - 1) * k0) / 2 + k0 - 1; |
| 1615 |
} |
| 1616 |
else { |
| 1617 |
ipos = 0; |
| 1618 |
} |
| 1619 |
task->parents->push_back(tasks_fg[level][dd0][ipos]); |
| 1620 |
if (i0 == (k0 + 1)) { |
| 1621 |
task->parallel_id = 0; |
| 1622 |
task->atomic_size = 2; // |
| 1623 |
task->atomic_id = 0; // |
| 1624 |
ipos = 2 + num_block * k0 - (k0 * (k0 + 1)) / 2 + k0 - 1; |
| 1625 |
} |
| 1626 |
else { // i0 > (k0 + 1) |
| 1627 |
task->parallel_id = i - (k0 + 1); |
| 1628 |
ipos = num_block * k0 + i0 + 1 - (k0 * (k0 + 1)) / 2; |
| 1629 |
} |
| 1630 |
tasks_fg[level][dd0][ipos] = task; |
| 1631 |
} // loop : i |
| 1632 |
} // loop : k |
| 1633 |
} // if (n_diag == 0) |
| 1634 |
} |
| 1635 |
} // loop : d |
| 1636 |
} // loop : level |
| 1637 |
vector<C_task*> tasks_b(1U << level_last); |
| 1638 |
{ // begin : sparse |
| 1639 |
const unsigned begdom = 1U << level_last; |
| 1640 |
const unsigned enddom = begdom * 2; |
| 1641 |
for (int d = begdom; d < enddom; d++) { // to be parallelized |
| 1642 |
const int dd0 = d - begdom; |
| 1643 |
const int d0 = _btree->selfIndex(d); |
| 1644 |
const CSR_indirect &offdiag = _btree->getOffdiagCSR(d); |
| 1645 |
const int colors = dM[d0]->ColorTridiagBlockMatrix(); |
| 1646 |
C_SparseBw_arg<T, U> *arg = |
| 1647 |
new C_SparseBw_arg<T, U>(colors, |
| 1648 |
d, |
| 1649 |
_isSym, |
| 1650 |
(int)dim, |
| 1651 |
_isTrans, |
| 1652 |
_nrhs, |
| 1653 |
_btree, |
| 1654 |
(int)level_last, |
| 1655 |
dM[d0]->addrtridiagBlock(), |
| 1656 |
_x, |
| 1657 |
_yi, |
| 1658 |
_xi[d0], |
| 1659 |
_yi[d0], |
| 1660 |
_zi[d0], |
| 1661 |
coefs, |
| 1662 |
offdiag.ptRows, |
| 1663 |
offdiag.indCols, |
| 1664 |
offdiag.indVals, |
| 1665 |
offdiag.indVals_unsym); |
| 1666 |
string task_name = "b : " + to_string(d); |
| 1667 |
*(arg->ops_complexity) = (long)dim; |
| 1668 |
C_task *task = new C_task(C_SPARSESYMBW, |
| 1669 |
task_name, |
| 1670 |
(void *)arg, |
| 1671 |
C_SparseBw<T, U>, |
| 1672 |
1, |
| 1673 |
0, |
| 1674 |
arg->ops_complexity); |
| 1675 |
task->parallel_max = begdom; |
| 1676 |
task->parallel_id = dd0; |
| 1677 |
for (int ll = (level_last - 1); ll >= 0; ll--) { |
| 1678 |
const int father_id = _btree->nthfatherIndex(d, (level_last - ll)); |
| 1679 |
const int father_id0 = _btree->selfIndex(father_id); |
| 1680 |
const Dissection::SetOfStrips &diag = _btree->getFathersStrips(d)[ll]; |
| 1681 |
const int ipos = tasks_fg[0][father_id0].size() - 1; |
| 1682 |
if ((diag.numberOfIndices() > 0) && (ipos >= 0)) { |
| 1683 |
task->parents->push_back(tasks_fg[0][father_id0][ipos]); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
tasks_b[dd0] = task; |
| 1687 |
} // loop : d |
| 1688 |
} // end : sparse |
| 1689 |
|
| 1690 |
int count_tasks = 0; |
| 1691 |
for (int i = 0; i < (1U << level_last); i++) { |
| 1692 |
count_tasks++; |
| 1693 |
} |
| 1694 |
for (int i = 0; i < ((1U << level_last) - 1); i++) { |
| 1695 |
count_tasks++; |
| 1696 |
} |
| 1697 |
for (int level = (level_last - 1); level >= 0; level--) { |
| 1698 |
const int begdom = (int)(1U << level); |
| 1699 |
const int enddom = begdom * 2; |
| 1700 |
for (int d = begdom; d < enddom; d++) { |
| 1701 |
const int dd0 = d - begdom; |
| 1702 |
for (int i = 0; i < tasks_de[level][dd0].size(); i++) { |
| 1703 |
count_tasks++; |
| 1704 |
} |
| 1705 |
if (level > 0) { |
| 1706 |
for (int i = 0; i < tasks_k[level][dd0].size(); i++) { |
| 1707 |
count_tasks++; |
| 1708 |
} |
| 1709 |
} |
| 1710 |
} // loop : d |
| 1711 |
for (int d = 1; d < begdom; d++) { // to be parallelized |
| 1712 |
count_tasks++; |
| 1713 |
} |
| 1714 |
} |
| 1715 |
for (int level = 0; level < level_last; level++) { |
| 1716 |
const int begdom = (int)1U << level; |
| 1717 |
const int enddom = begdom * 2; |
| 1718 |
for (int d = begdom; d < enddom; d++) { |
| 1719 |
const int dd0 = d - begdom; |
| 1720 |
if (level > 0) { |
| 1721 |
count_tasks++; |
| 1722 |
for (int i = 0; i < tasks_l[level][dd0].size(); i++) { |
| 1723 |
count_tasks++; |
| 1724 |
} |
| 1725 |
} |
| 1726 |
for (int i = 0; i < tasks_fg[level][dd0].size(); i++) { |
| 1727 |
count_tasks++; |
| 1728 |
} |
| 1729 |
} // loop : d |
| 1730 |
} |
| 1731 |
for (int i = 0; i < (1U << level_last); i++) { |
| 1732 |
count_tasks++; |
| 1733 |
} |
| 1734 |
|
| 1735 |
vector<C_task *> *tasks_tmp = new vector<C_task *>; |
| 1736 |
tasks_tmp->resize(count_tasks); |
| 1737 |
count_tasks = 0; |
| 1738 |
for (int i = 0; i < (1U << level_last); i++) { |
| 1739 |
(*tasks_tmp)[count_tasks++] = tasks_a[i]; |
| 1740 |
} |
| 1741 |
for (int i = 0; i < ((1U << level_last) - 1); i++) { |
| 1742 |
(*tasks_tmp)[count_tasks++] = tasks_i[i]; |
| 1743 |
} |
| 1744 |
for (int level = (level_last - 1); level >= 0; level--) { |
| 1745 |
const int begdom = (int)(1U << level); |
| 1746 |
const int enddom = begdom * 2; |
| 1747 |
for (int d = begdom; d < enddom; d++) { |
| 1748 |
const int dd0 = d - begdom; |
| 1749 |
for (int i = 0; i < tasks_de[level][dd0].size(); i++) { |
| 1750 |
(*tasks_tmp)[count_tasks++] = tasks_de[level][dd0][i]; |
| 1751 |
} |
| 1752 |
if (level > 0) { |
| 1753 |
for (int i = 0; i < tasks_k[level][dd0].size(); i++) { |
| 1754 |
(*tasks_tmp)[count_tasks++] = tasks_k[level][dd0][i]; |
| 1755 |
} |
| 1756 |
} |
| 1757 |
} // loop : d |
| 1758 |
for (int d = 1; d < begdom; d++) { // to be parallelized |
| 1759 |
const int dd0 = d - 1; |
| 1760 |
(*tasks_tmp)[count_tasks++] = tasks_j[level][dd0]; |
| 1761 |
} |
| 1762 |
} |
| 1763 |
for (int level = 0; level < level_last; level++) { |
| 1764 |
const int begdom = (int)(1U << level); |
| 1765 |
const int enddom = begdom * 2; |
| 1766 |
for (int d = begdom; d < enddom; d++) { |
| 1767 |
const int dd0 = d - begdom; |
| 1768 |
if (level > 0) { |
| 1769 |
(*tasks_tmp)[count_tasks++] = tasks_h[level][dd0]; |
| 1770 |
for (int i = 0; i < tasks_l[level][dd0].size(); i++) { |
| 1771 |
(*tasks_tmp)[count_tasks++] = tasks_l[level][dd0][i]; |
| 1772 |
} |
| 1773 |
} |
| 1774 |
for (int i = 0; i < tasks_fg[level][dd0].size(); i++) { |
| 1775 |
(*tasks_tmp)[count_tasks++] = tasks_fg[level][dd0][i]; |
| 1776 |
} |
| 1777 |
} // loop : d |
| 1778 |
} |
| 1779 |
for (int i = 0; i < (1U << level_last); i++) { |
| 1780 |
(*tasks_tmp)[count_tasks++] = tasks_b[i]; |
| 1781 |
} |
| 1782 |
string task_name = "fwbw whole"; |
| 1783 |
_queue_fwbw = new C_task_seq(C_FWBW, |
| 1784 |
task_name, // dummy |
| 1785 |
(-1), // mutex_id |
| 1786 |
TASK_SINGLE, //TASK_SINGLE, |
| 1787 |
_num_threads, |
| 1788 |
-1, // level |
| 1789 |
-1, // phase |
| 1790 |
tasks_tmp, |
| 1791 |
0, |
| 1792 |
//itmp, |
| 1793 |
count_tasks, |
| 1794 |
0); // dummy |
| 1795 |
|
| 1796 |
_dissectionRuntime->set_queue_fwbw(_queue_fwbw); |
| 1797 |
diss_printf(_verbose, _fp, |
| 1798 |
"%s %d : void DissectionQueue::generate_queue_fwbw\n", |
| 1799 |
__FILE__, __LINE__); |
| 1800 |
|
| 1801 |
delete [] tasks_de[0]; // |
| 1802 |
delete [] tasks_de; // vector<C_task*>** |
| 1803 |
delete [] tasks_k[0]; // |
| 1804 |
delete [] tasks_k; // vector<C_task*>** |
| 1805 |
delete [] tasks_j; // vector<C_task*>* |
| 1806 |
delete [] tasks_h; // vector<C_task*>* |
| 1807 |
delete [] tasks_l[0]; // |
| 1808 |
delete [] tasks_l; // vector<C_task*>** |
| 1809 |
delete [] tasks_fg[0]; |
| 1810 |
delete [] tasks_fg; // vector<C_task*>** |
| 1811 |
// vector<C_task*> tasks_a, tasks_b, and tasks_i are deallocated automatically |
| 1812 |
_queue_fwbw_allocated = true; |
| 1813 |
} |
| 1814 |
|
| 1815 |
template |
| 1816 |
void DissectionQueue<double>:: |
| 1817 |
generate_queue_fwbw(vector<DissectionMatrix<double>*>& dissectionMatrix, |
| 1818 |
int dim, int nnz, double *coefs); |
| 1819 |
|
| 1820 |
template |
| 1821 |
void DissectionQueue<quadruple>:: |
| 1822 |
generate_queue_fwbw(vector<DissectionMatrix<quadruple>*>& dissectionMatrix, |
| 1823 |
int dim, int nnz, quadruple *coefs); |
| 1824 |
|
| 1825 |
template |
| 1826 |
void DissectionQueue<complex<double>, double>:: |
| 1827 |
generate_queue_fwbw(vector<DissectionMatrix<complex<double>, double>*>& dissectionMatrix, |
| 1828 |
int dim, int nnz, complex<double> *coefs); |
| 1829 |
|
| 1830 |
template |
| 1831 |
void DissectionQueue<complex<quadruple>, quadruple>:: |
| 1832 |
generate_queue_fwbw(vector<DissectionMatrix<complex<quadruple>, quadruple>*>& dissectionMatrix, |
| 1833 |
int dim, int nnz, complex<quadruple> *coefs); |
| 1834 |
|
| 1835 |
template |
| 1836 |
void DissectionQueue<float>:: |
| 1837 |
generate_queue_fwbw(vector<DissectionMatrix<float>*>& dissectionMatrix, |
| 1838 |
int dim, int nnz, float *coefs); |
| 1839 |
|
| 1840 |
template |
| 1841 |
void DissectionQueue<complex<float>, float>:: |
| 1842 |
generate_queue_fwbw(vector<DissectionMatrix<complex<float>, float>*>& dissectionMatrix, |
| 1843 |
int dim, int nnz, complex<float> *coefs); |
| 1844 |
|
| 1845 |
// |
| 1846 |
|
| 1847 |
template<typename T, typename U> |
| 1848 |
void DissectionQueue<T, U>::exec_symb_fact(void) |
| 1849 |
{ |
| 1850 |
_dissectionRuntime->exec_symb_fact(); |
| 1851 |
} |
| 1852 |
|
| 1853 |
template |
| 1854 |
void DissectionQueue<double>::exec_symb_fact(); |
| 1855 |
|
| 1856 |
template |
| 1857 |
void DissectionQueue<quadruple>::exec_symb_fact(); |
| 1858 |
|
| 1859 |
template |
| 1860 |
void DissectionQueue<complex<double>, double>::exec_symb_fact(); |
| 1861 |
|
| 1862 |
template |
| 1863 |
void DissectionQueue<complex<quadruple>, quadruple>::exec_symb_fact(); |
| 1864 |
|
| 1865 |
template |
| 1866 |
void DissectionQueue<float>::exec_symb_fact(); |
| 1867 |
|
| 1868 |
template |
| 1869 |
void DissectionQueue<complex<float>, float>::exec_symb_fact(); |
| 1870 |
|
| 1871 |
|
| 1872 |
// |
| 1873 |
|
| 1874 |
template<typename T, typename U> |
| 1875 |
void DissectionQueue<T, U>::exec_num_fact(const int called, |
| 1876 |
const double eps_piv, |
| 1877 |
const bool kernel_detection, |
| 1878 |
const int aug_dim, |
| 1879 |
const U eps_machine, |
| 1880 |
const bool higher_precision) |
| 1881 |
{ |
| 1882 |
_kernel_detection = kernel_detection; |
| 1883 |
_aug_dim = aug_dim; |
| 1884 |
#if 0 |
| 1885 |
if (higher_precision) { |
| 1886 |
_eps_piv = eps_machine; |
| 1887 |
} |
| 1888 |
else { |
| 1889 |
_eps_piv = eps_piv; |
| 1890 |
} |
| 1891 |
#else |
| 1892 |
_eps_piv = eps_piv; |
| 1893 |
#endif |
| 1894 |
_eps_machine = eps_machine; |
| 1895 |
_higher_precision = higher_precision; |
| 1896 |
_dissectionRuntime->exec_num_fact(called); |
| 1897 |
} |
| 1898 |
|
| 1899 |
template |
| 1900 |
void DissectionQueue<double>:: |
| 1901 |
exec_num_fact(const int called, |
| 1902 |
const double eps_piv, |
| 1903 |
const bool kernel_detection, |
| 1904 |
const int aug_dim, |
| 1905 |
const double eps_machine, |
| 1906 |
const bool higher_precision); |
| 1907 |
template |
| 1908 |
void DissectionQueue<quadruple>:: |
| 1909 |
exec_num_fact(const int called, |
| 1910 |
const double eps_piv, |
| 1911 |
const bool kernel_detection, |
| 1912 |
const int aug_dim, |
| 1913 |
const quadruple eps_machine, |
| 1914 |
const bool higher_precision); |
| 1915 |
template |
| 1916 |
void DissectionQueue<complex<double>, double>:: |
| 1917 |
exec_num_fact(const int called, |
| 1918 |
const double eps_piv, |
| 1919 |
const bool kernel_detection, |
| 1920 |
const int aug_dim, |
| 1921 |
const double eps_machine, |
| 1922 |
const bool higher_precision); |
| 1923 |
|
| 1924 |
template |
| 1925 |
void DissectionQueue<complex<quadruple>, quadruple>:: |
| 1926 |
exec_num_fact(const int called, |
| 1927 |
const double eps_piv, |
| 1928 |
const bool kernel_detection, |
| 1929 |
const int aug_dim, |
| 1930 |
const quadruple eps_machine, |
| 1931 |
const bool higher_precision); |
| 1932 |
|
| 1933 |
template |
| 1934 |
void DissectionQueue<float>:: |
| 1935 |
exec_num_fact(const int called, |
| 1936 |
const double eps_piv, |
| 1937 |
const bool kernel_detection, |
| 1938 |
const int aug_dim, |
| 1939 |
const float eps_machine, |
| 1940 |
const bool higher_precision); |
| 1941 |
|
| 1942 |
template |
| 1943 |
void DissectionQueue<complex<float>, float>:: |
| 1944 |
exec_num_fact(const int called, |
| 1945 |
const double eps_piv, |
| 1946 |
const bool kernel_detection, |
| 1947 |
const int aug_dim, |
| 1948 |
const float eps_machine, |
| 1949 |
const bool higher_precision); |
| 1950 |
// |
| 1951 |
|
| 1952 |
template<typename T, typename U> |
| 1953 |
void DissectionQueue<T, U>::exec_fwbw_seq(T *x, const int nrhs, bool isTrans) |
| 1954 |
{ |
| 1955 |
const int nb_doms = _btree->NumberOfSubdomains(); |
| 1956 |
int ntmp; |
| 1957 |
|
| 1958 |
*_x = x; |
| 1959 |
*_nrhs = (int *)&nrhs; |
| 1960 |
*_isTrans = &isTrans; |
| 1961 |
|
| 1962 |
ntmp = 0; |
| 1963 |
for (int d = 1; d <= nb_doms; d++) { |
| 1964 |
ntmp += _btree->sizeOfDomain(d); |
| 1965 |
} |
| 1966 |
ColumnMatrix<T> xxi(ntmp, nrhs); |
| 1967 |
ColumnMatrix<T> yyi(ntmp, nrhs); |
| 1968 |
ColumnMatrix<T> wwi(ntmp, nrhs); |
| 1969 |
ntmp = 0; |
| 1970 |
for (int d = 1; d <= nb_doms; d++) { |
| 1971 |
const int d0 = _btree->selfIndex(d); |
| 1972 |
*_xi[d0] = xxi.addrCoefs() + ntmp * nrhs; |
| 1973 |
*_yi[d0] = yyi.addrCoefs() + ntmp * nrhs; |
| 1974 |
*_wi[d0] = wwi.addrCoefs() + ntmp * nrhs; |
| 1975 |
ntmp += _btree->sizeOfDomain(d); |
| 1976 |
} |
| 1977 |
ntmp = 0; |
| 1978 |
for (int d = 1; d <= nb_doms; d++) { |
| 1979 |
ntmp += _btree->sizeOfFathersStrips(d); |
| 1980 |
} |
| 1981 |
ColumnMatrix<T> zzi(ntmp, nrhs); |
| 1982 |
ntmp = 0; |
| 1983 |
for (int d = 1; d <= nb_doms; d++) { |
| 1984 |
const int d0 = _btree->selfIndex(d); |
| 1985 |
*_zi[d0] = zzi.addrCoefs() + ntmp * nrhs; |
| 1986 |
ntmp += _btree->sizeOfFathersStrips(d); |
| 1987 |
} |
| 1988 |
diss_printf(_verbose, _fp, "exec_fwbw_seq for nrhs = %d \n", nrhs); |
| 1989 |
_dissectionRuntime->exec_fwbw_seq(); |
| 1990 |
|
| 1991 |
xxi.free(); |
| 1992 |
yyi.free(); |
| 1993 |
wwi.free(); |
| 1994 |
zzi.free(); |
| 1995 |
} |
| 1996 |
|
| 1997 |
template |
| 1998 |
void DissectionQueue<double>::exec_fwbw_seq(double *x, const int nrhs, |
| 1999 |
bool isTrans); |
| 2000 |
|
| 2001 |
template |
| 2002 |
void DissectionQueue<quadruple>::exec_fwbw_seq(quadruple *x, |
| 2003 |
const int nrhs, |
| 2004 |
bool isTrans); |
| 2005 |
template |
| 2006 |
void DissectionQueue<complex<double>, double>:: |
| 2007 |
exec_fwbw_seq(complex<double> *x, |
| 2008 |
const int nrhs, |
| 2009 |
bool isTrans); |
| 2010 |
|
| 2011 |
template |
| 2012 |
void DissectionQueue<complex<quadruple>, quadruple>:: |
| 2013 |
exec_fwbw_seq(complex<quadruple> *x, |
| 2014 |
const int nrhs, |
| 2015 |
bool isTrans); |
| 2016 |
|
| 2017 |
template |
| 2018 |
void DissectionQueue<float>::exec_fwbw_seq(float *x, const int nrhs, |
| 2019 |
bool isTrans); |
| 2020 |
|
| 2021 |
template |
| 2022 |
void DissectionQueue<complex<float>, float>:: |
| 2023 |
exec_fwbw_seq(complex<float> *x, |
| 2024 |
const int nrhs, |
| 2025 |
bool isTrans); |
| 2026 |
|
| 2027 |
// |
| 2028 |
|
| 2029 |
template<typename T, typename U> |
| 2030 |
void DissectionQueue<T, U>::exec_fwbw(T *x, const int nrhs, bool isTrans) |
| 2031 |
{ |
| 2032 |
const int num_threads = _num_threads; //_num_threads_symb; |
| 2033 |
|
| 2034 |
// struct timespec ts0, ts1; |
| 2035 |
const int nb_doms = _btree->NumberOfSubdomains(); |
| 2036 |
int ntmp; |
| 2037 |
diss_printf(_verbose, _fp, |
| 2038 |
"fwbw for nrhs = %d with %d threads\n", nrhs, num_threads); |
| 2039 |
*_x = x; |
| 2040 |
*_nrhs = (int *)&nrhs; |
| 2041 |
*_isTrans = &isTrans; |
| 2042 |
|
| 2043 |
ntmp = 0; |
| 2044 |
for (int d = 1; d <= nb_doms; d++) { |
| 2045 |
ntmp += _btree->sizeOfDomain(d); |
| 2046 |
} |
| 2047 |
ColumnMatrix<T> xxi(ntmp, nrhs); |
| 2048 |
ColumnMatrix<T> yyi(ntmp, nrhs); |
| 2049 |
ColumnMatrix<T> wwi(ntmp, nrhs); |
| 2050 |
ntmp = 0; |
| 2051 |
for (int d = 1; d <= nb_doms; d++) { |
| 2052 |
const int d0 = _btree->selfIndex(d); |
| 2053 |
*_xi[d0] = xxi.addrCoefs() + ntmp * nrhs; |
| 2054 |
*_yi[d0] = yyi.addrCoefs() + ntmp * nrhs; |
| 2055 |
*_wi[d0] = wwi.addrCoefs() + ntmp * nrhs; |
| 2056 |
ntmp += _btree->sizeOfDomain(d); |
| 2057 |
} |
| 2058 |
ntmp = 0; |
| 2059 |
for (int d = 1; d <= nb_doms; d++) { |
| 2060 |
ntmp += _btree->sizeOfFathersStrips(d); |
| 2061 |
} |
| 2062 |
ColumnMatrix<T> zzi(ntmp, nrhs); |
| 2063 |
ntmp = 0; |
| 2064 |
for (int d = 1; d <= nb_doms; d++) { |
| 2065 |
const int d0 = _btree->selfIndex(d); |
| 2066 |
// *_zi[d0] = &zzi[ntmp * nrhs]; |
| 2067 |
*_zi[d0] = zzi.addrCoefs()+ ntmp * nrhs; |
| 2068 |
ntmp += _btree->sizeOfFathersStrips(d); |
| 2069 |
} |
| 2070 |
|
| 2071 |
_dissectionRuntime->exec_fwbw(); |
| 2072 |
|
| 2073 |
xxi.free(); |
| 2074 |
yyi.free(); |
| 2075 |
wwi.free(); |
| 2076 |
zzi.free(); |
| 2077 |
} |
| 2078 |
|
| 2079 |
template |
| 2080 |
void DissectionQueue<double>::exec_fwbw(double *x, const int nrhs, |
| 2081 |
bool isTrans); |
| 2082 |
template |
| 2083 |
void DissectionQueue<quadruple>::exec_fwbw(quadruple *x, |
| 2084 |
const int nrhs, |
| 2085 |
bool isTrans); |
| 2086 |
|
| 2087 |
template |
| 2088 |
void DissectionQueue<complex<double>, double>::exec_fwbw(complex<double> *x, |
| 2089 |
const int nrhs, |
| 2090 |
bool isTrans); |
| 2091 |
|
| 2092 |
template |
| 2093 |
void DissectionQueue<float>::exec_fwbw(float *x, const int nrhs, |
| 2094 |
bool isTrans); |
| 2095 |
|
| 2096 |
template |
| 2097 |
void DissectionQueue<complex<float>, float>::exec_fwbw(complex<float> *x, |
| 2098 |
const int nrhs, |
| 2099 |
bool isTrans); |
| 2100 |
|
| 2101 |
template |
| 2102 |
void DissectionQueue<complex<quadruple>, quadruple>:: |
| 2103 |
exec_fwbw(complex<quadruple> *x, |
| 2104 |
const int nrhs, bool isTrans); |
| 2105 |
// |
| 2106 |
// #define DEBUG_ERASE |
| 2107 |
|
| 2108 |
template<typename T, typename U> |
| 2109 |
void DissectionQueue<T, U>::erase_queue(void) |
| 2110 |
{ |
| 2111 |
const int num_threads = _num_threads; |
| 2112 |
diss_printf(_verbose, _fp, "%s %d : void QueueRuntime::erase_queue(void)", |
| 2113 |
__FILE__, __LINE__); |
| 2114 |
if (_queue_symb_allocated) { |
| 2115 |
#ifdef DEBUG_ERASE |
| 2116 |
cerr << "symbolic "; |
| 2117 |
#endif |
| 2118 |
// vector<C_task *> &queue = *(_queue_symb->queue); |
| 2119 |
for (int j = _queue_symb->begin; j < _queue_symb->end; j++) { |
| 2120 |
// C_task *task = queue[j]; |
| 2121 |
C_task *task = (*(_queue_symb->queue))[j]; |
| 2122 |
#ifdef DEBUG_ERASE |
| 2123 |
cerr << task->task_name << " "; |
| 2124 |
#endif |
| 2125 |
// delete [] task->task_name; // char *task_name_cstr = new char [] |
| 2126 |
erase_task<T, U>(task); |
| 2127 |
} // loop : j |
| 2128 |
#ifdef DEBUG_ERASE |
| 2129 |
cerr << _queue_symb->task_name << " " << endl; |
| 2130 |
#endif |
| 2131 |
// delete [] _queue_symb->task_name; |
| 2132 |
delete _queue_symb->queue; |
| 2133 |
delete _queue_symb; |
| 2134 |
} |
| 2135 |
|
| 2136 |
#ifdef DEBUG_ERASE |
| 2137 |
cerr << "zero reset" << endl; |
| 2138 |
#endif |
| 2139 |
if (_queue_numrc_allocated) { |
| 2140 |
// zero reset could be done redundantly |
| 2141 |
for (int p = 0; p < num_threads; p++) { |
| 2142 |
for (list<C_task_seq *>::const_iterator it = _queue_static[p].begin(); |
| 2143 |
it != _queue_static[p].end(); ++it) { |
| 2144 |
(*it)->referred = 0; |
| 2145 |
vector<C_task *> &queue = *((*it)->queue); |
| 2146 |
for (int j = (*it)->begin; j < (*it)->end; j++) { |
| 2147 |
queue[j]->referred = 0; |
| 2148 |
} // loop : j |
| 2149 |
} // loop : it |
| 2150 |
} // loop : p |
| 2151 |
for (vector<C_task_seq *>::const_iterator it = _queue_dynamic->begin(); |
| 2152 |
it != _queue_dynamic->end(); ++it) { |
| 2153 |
(*it)->referred = 0; |
| 2154 |
for (int j = (*it)->begin; j < (*it)->end; j++) { |
| 2155 |
(*(*it)->queue)[j]->referred = 0; |
| 2156 |
} |
| 2157 |
} |
| 2158 |
#ifdef DEBUG_ERASE |
| 2159 |
cerr << "increment referred counter" << endl; |
| 2160 |
#endif |
| 2161 |
// increment referred counter |
| 2162 |
for (int p = 0; p < num_threads; p++) { |
| 2163 |
for (list<C_task_seq *>::const_iterator it = _queue_static[p].begin(); |
| 2164 |
it != _queue_static[p].end(); ++it) { |
| 2165 |
(*it)->referred++; |
| 2166 |
vector<C_task *> &queue = *((*it)->queue); |
| 2167 |
for (int j = (*it)->begin; j < (*it)->end; j++) { |
| 2168 |
queue[j]->referred++; |
| 2169 |
} // loop : j |
| 2170 |
} // loop : it |
| 2171 |
} // loop : p |
| 2172 |
for (vector<C_task_seq *>::const_iterator it = _queue_dynamic->begin(); |
| 2173 |
it != _queue_dynamic->end(); ++it) { |
| 2174 |
(*it)->referred++; |
| 2175 |
for (int j = (*it)->begin; j < (*it)->end; j++) { |
| 2176 |
(*(*it)->queue)[j]->referred++; |
| 2177 |
} |
| 2178 |
} |
| 2179 |
// delete task |
| 2180 |
#ifdef DEBUG_ERASE |
| 2181 |
cerr << "delete task" << endl; |
| 2182 |
#endif |
| 2183 |
for (int p = 0; p < num_threads; p++) { |
| 2184 |
for (list<C_task_seq *>::const_iterator it = _queue_static[p].begin(); |
| 2185 |
it != _queue_static[p].end(); ++it) { |
| 2186 |
vector<C_task *> &queue = *((*it)->queue); |
| 2187 |
for (int j = (*it)->begin; j < (*it)->end; j++) { |
| 2188 |
C_task *task = queue[j]; |
| 2189 |
task->referred--; |
| 2190 |
if (task->referred == 0) { |
| 2191 |
erase_task<T, U>(task); // |
| 2192 |
} |
| 2193 |
} // loop : j |
| 2194 |
} // loop : it |
| 2195 |
} // loop : p |
| 2196 |
|
| 2197 |
for (vector<C_task_seq *>::const_iterator it = _queue_dynamic->begin(); |
| 2198 |
it != _queue_dynamic->end(); ++it) { |
| 2199 |
for (int j = (*it)->begin; j < (*it)->end; j++) { |
| 2200 |
C_task *task = (*(*it)->queue)[j]; |
| 2201 |
task->referred--; |
| 2202 |
if (task->referred == 0) { |
| 2203 |
erase_task<T, U>(task); // |
| 2204 |
} |
| 2205 |
} |
| 2206 |
} |
| 2207 |
// delete task_seq |
| 2208 |
#ifdef DEBUG_ERASE |
| 2209 |
cerr << "static : C_task_seq" << endl; |
| 2210 |
#endif |
| 2211 |
// _queue_static[] share tasks in _queue_dynamic |
| 2212 |
for (int p = 0; p < num_threads; p++) { |
| 2213 |
for (list<C_task_seq *>::iterator it = _queue_static[p].begin(); |
| 2214 |
it != _queue_static[p].end(); ++it) { |
| 2215 |
(*it)->referred--; |
| 2216 |
if ((*it)->referred == 0) { |
| 2217 |
#ifdef DEBUG_ERASE |
| 2218 |
fprintf(stderr, "%x %s\n", (*it), (*it)->task_name); |
| 2219 |
#endif |
| 2220 |
delete (*it)->queue; |
| 2221 |
(*it)->queue = NULL; |
| 2222 |
delete (*it); |
| 2223 |
(*it) = NULL; |
| 2224 |
} |
| 2225 |
} // loop : it |
| 2226 |
} // loop : p |
| 2227 |
#ifdef DEBUG_ERASE |
| 2228 |
cerr << "dynamic : C_task_seq" << endl; |
| 2229 |
#endif |
| 2230 |
for (vector<C_task_seq *>::iterator it = _queue_dynamic->begin(); |
| 2231 |
it != _queue_dynamic->end(); ++it) { |
| 2232 |
(*it)->referred--; |
| 2233 |
if ((*it)->referred == 0) { |
| 2234 |
#ifdef DEBUG_ERASE |
| 2235 |
fprintf(stderr, "%x %s\n", (*it), (*it)->task_name); |
| 2236 |
#endif |
| 2237 |
delete (*it)->queue; |
| 2238 |
(*it)->queue = NULL; |
| 2239 |
delete (*it); |
| 2240 |
(*it) = NULL; |
| 2241 |
} |
| 2242 |
} // loop : it |
| 2243 |
|
| 2244 |
delete _queue_dynamic; |
| 2245 |
// Here all queues are deallocated. |
| 2246 |
for (int p = 0; p < num_threads; p++) { |
| 2247 |
_queue_static[p].clear(); |
| 2248 |
} |
| 2249 |
delete [] _queue_static; |
| 2250 |
#ifdef DEBUG_ERASE |
| 2251 |
cerr << "queues are deallocated" << endl; |
| 2252 |
#endif |
| 2253 |
} |
| 2254 |
_queue_symb_allocated = false; |
| 2255 |
_queue_numrc_allocated = false; |
| 2256 |
} |
| 2257 |
|
| 2258 |
template |
| 2259 |
void DissectionQueue<double>::erase_queue(void); |
| 2260 |
|
| 2261 |
template |
| 2262 |
void DissectionQueue<quadruple>::erase_queue(void); |
| 2263 |
|
| 2264 |
template |
| 2265 |
void DissectionQueue<complex<double>, double>::erase_queue(void); |
| 2266 |
|
| 2267 |
template |
| 2268 |
void DissectionQueue<complex<quadruple>, quadruple>::erase_queue(void); |
| 2269 |
|
| 2270 |
template |
| 2271 |
void DissectionQueue<float>::erase_queue(void); |
| 2272 |
|
| 2273 |
template |
| 2274 |
void DissectionQueue<complex<float>, float>::erase_queue(void); |
| 2275 |
|
| 2276 |
// |
| 2277 |
|
| 2278 |
template<typename T, typename U> |
| 2279 |
void DissectionQueue<T, U>::erase_queue_fwbw(void) |
| 2280 |
{ |
| 2281 |
diss_printf(_verbose, _fp, |
| 2282 |
"%s %d : void QueueRuntime::erase_queue_fwbw(void)", |
| 2283 |
__FILE__, __LINE__); |
| 2284 |
if (_queue_fwbw_allocated) { |
| 2285 |
delete [] _diag_contribs; |
| 2286 |
delete _x; |
| 2287 |
for (int d = 1; d <= _nb_doms; d++) { |
| 2288 |
const int d0 = _btree->selfIndex(d); |
| 2289 |
delete _xi[d0]; |
| 2290 |
delete _yi[d0]; |
| 2291 |
delete _wi[d0]; |
| 2292 |
delete _zi[d0]; |
| 2293 |
} |
| 2294 |
|
| 2295 |
delete [] _xi; |
| 2296 |
delete [] _yi; |
| 2297 |
delete [] _zi; |
| 2298 |
delete [] _wi; |
| 2299 |
|
| 2300 |
for (vector<C_task *>::iterator it = _queue_fwbw->queue->begin(); |
| 2301 |
it != _queue_fwbw->queue->end(); ++it) { |
| 2302 |
erase_task<T, U>(*it); |
| 2303 |
} |
| 2304 |
_queue_fwbw->queue->clear(); |
| 2305 |
delete _queue_fwbw->queue; |
| 2306 |
delete _queue_fwbw; |
| 2307 |
|
| 2308 |
delete _nrhs; // added 01 Oct.2013 Atsushi |
| 2309 |
delete _isTrans; |
| 2310 |
} |
| 2311 |
_queue_fwbw_allocated = false; |
| 2312 |
} |
| 2313 |
|
| 2314 |
template |
| 2315 |
void DissectionQueue<double>::erase_queue_fwbw(void); |
| 2316 |
|
| 2317 |
template |
| 2318 |
void DissectionQueue<quadruple>::erase_queue_fwbw(void); |
| 2319 |
|
| 2320 |
template |
| 2321 |
void DissectionQueue<complex<double>, double>::erase_queue_fwbw(void); |
| 2322 |
|
| 2323 |
template |
| 2324 |
void DissectionQueue<complex<quadruple>, quadruple>::erase_queue_fwbw(void); |
| 2325 |
|
| 2326 |
template |
| 2327 |
void DissectionQueue<float>::erase_queue_fwbw(void); |
| 2328 |
|
| 2329 |
template |
| 2330 |
void DissectionQueue<complex<float>, float>::erase_queue_fwbw(void); |