| 1 |
/*! \file DissectionSolver.cpp |
| 2 |
\brief task mangemanet of dissection algorithm |
| 3 |
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions |
| 4 |
\date Mar. 30th 2012 |
| 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 <float.h> |
| 52 |
#include <vector> |
| 53 |
#include <algorithm> |
| 54 |
|
| 55 |
#include "Driver/DissectionSolver.hpp" |
| 56 |
#include "Driver/C_BlasRoutines.hpp" |
| 57 |
#include "Driver/C_KernDetect.hpp" |
| 58 |
#include "Driver/CopyMatrix.hpp" |
| 59 |
#include "Driver/TridiagBlockMatrix.hpp" |
| 60 |
#include "Splitters/MetisSplitter.hpp" |
| 61 |
#include "Algebra/SparseRenumbering.hpp" |
| 62 |
#include "Algebra/VectorArray.hpp" |
| 63 |
#include "Compiler/DissectionIO.hpp" |
| 64 |
|
| 65 |
#define NORMALIZE_KERNEL_BASIS |
| 66 |
|
| 67 |
template<typename T, typename U, typename W, typename Z> |
| 68 |
const T DissectionSolver<T, U, W, Z>::_one = T(1.0); |
| 69 |
template<typename T, typename U, typename W, typename Z> |
| 70 |
const T DissectionSolver<T, U, W, Z>::_none = T(-1.0); |
| 71 |
template<typename T, typename U, typename W, typename Z> |
| 72 |
const T DissectionSolver<T, U, W, Z>::_zero = T(0.0); |
| 73 |
|
| 74 |
template<typename T, typename U, typename W, typename Z> |
| 75 |
void DissectionSolver<T, U, W, Z>:: |
| 76 |
Destroy(void) |
| 77 |
{ |
| 78 |
for (int m = 0; m < _graph_colors;m++) { |
| 79 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 80 |
delete _dissectionQueue[m]; |
| 81 |
for (typename vector<DissectionMatrix<T, U>* >::const_iterator it = |
| 82 |
_dissectionMatrix[m].begin(); |
| 83 |
it != _dissectionMatrix[m].end(); ++it) { |
| 84 |
delete (*it); |
| 85 |
} |
| 86 |
} |
| 87 |
else { |
| 88 |
delete _tridiagMatrix[m]; |
| 89 |
} |
| 90 |
} |
| 91 |
delete [] _dissectionQueue; |
| 92 |
delete [] _dissectionMatrix; |
| 93 |
delete [] _tridiagMatrix; |
| 94 |
|
| 95 |
delete _ptDA; |
| 96 |
delete[] _precDiag; |
| 97 |
|
| 98 |
NumericFree(); |
| 99 |
delete [] _Schur; |
| 100 |
delete [] _kernel; |
| 101 |
delete [] _singIdx; // added 01 Oct.2013 Atsushi |
| 102 |
for (int m = 0; m < _graph_colors;m++) { |
| 103 |
if (_with_btree && !_tridiagQueue[m]->tridiagSolver()) { |
| 104 |
delete _btree[m]; // added 01 Oct.2013 Atsushi |
| 105 |
} |
| 106 |
delete _tridiagQueue[m]; |
| 107 |
} |
| 108 |
delete [] _tridiagQueue; |
| 109 |
delete [] _btree; |
| 110 |
_index_isolated.clear(); |
| 111 |
} |
| 112 |
|
| 113 |
template |
| 114 |
void DissectionSolver<double>::Destroy(void); |
| 115 |
|
| 116 |
template |
| 117 |
void DissectionSolver<quadruple>::Destroy(void); |
| 118 |
|
| 119 |
template |
| 120 |
void DissectionSolver<quadruple, quadruple, double, double>::Destroy(void); |
| 121 |
|
| 122 |
template |
| 123 |
void DissectionSolver<double, double, quadruple, quadruple>::Destroy(void); |
| 124 |
|
| 125 |
template |
| 126 |
void DissectionSolver<complex<double>, double>::Destroy(void); |
| 127 |
|
| 128 |
template |
| 129 |
void DissectionSolver<complex<quadruple>, quadruple>::Destroy(void); |
| 130 |
|
| 131 |
template |
| 132 |
void DissectionSolver<complex<quadruple>, quadruple, |
| 133 |
complex<double>, double>::Destroy(void); |
| 134 |
|
| 135 |
template |
| 136 |
void DissectionSolver<complex<double>, double, |
| 137 |
complex<quadruple>, quadruple>::Destroy(void); |
| 138 |
|
| 139 |
template |
| 140 |
void DissectionSolver<float>::Destroy(void); |
| 141 |
|
| 142 |
template |
| 143 |
void DissectionSolver<complex<float>, float>::Destroy(void); |
| 144 |
|
| 145 |
// |
| 146 |
|
| 147 |
template<typename T, typename U, typename W, typename Z> |
| 148 |
void DissectionSolver<T, U, W, Z>:: |
| 149 |
NumericFree(void) |
| 150 |
{ |
| 151 |
diss_printf(_verbose, _fp, |
| 152 |
"%s %d : void DissectionSolver::NumericFree()", |
| 153 |
__FILE__, __LINE__ ); |
| 154 |
if (_status_factorized) { |
| 155 |
diss_printf(_verbose, _fp, "start "); |
| 156 |
for (int m = 0; m < _graph_colors; m++) { |
| 157 |
_Schur[m].free(); |
| 158 |
_kernel[m].free(); |
| 159 |
_singIdx[m].clear(); // added 01 Oct.2013 Atsushi |
| 160 |
} |
| 161 |
diss_printf(_verbose, _fp, "end"); |
| 162 |
} |
| 163 |
_status_factorized = false; |
| 164 |
diss_printf(_verbose, _fp, ".\n"); |
| 165 |
} |
| 166 |
|
| 167 |
template |
| 168 |
void DissectionSolver<double>::NumericFree(void); |
| 169 |
|
| 170 |
template |
| 171 |
void DissectionSolver<quadruple>::NumericFree(void); |
| 172 |
|
| 173 |
template |
| 174 |
void DissectionSolver<quadruple, quadruple, double, double>::NumericFree(void); |
| 175 |
|
| 176 |
template |
| 177 |
void DissectionSolver<double, double, quadruple, quadruple>::NumericFree(void); |
| 178 |
|
| 179 |
template |
| 180 |
void DissectionSolver<complex<double>, double>::NumericFree(void); |
| 181 |
|
| 182 |
template |
| 183 |
void DissectionSolver<complex<quadruple>, quadruple>::NumericFree(void); |
| 184 |
// |
| 185 |
|
| 186 |
template |
| 187 |
void DissectionSolver<complex<quadruple>, quadruple, complex<double>, double>::NumericFree(void); |
| 188 |
|
| 189 |
template |
| 190 |
void DissectionSolver<complex<double>, double, complex<quadruple>, quadruple>::NumericFree(void); |
| 191 |
|
| 192 |
template |
| 193 |
void DissectionSolver<float>::NumericFree(void); |
| 194 |
|
| 195 |
template |
| 196 |
void DissectionSolver<complex<float>, float>::NumericFree(void); |
| 197 |
|
| 198 |
// |
| 199 |
|
| 200 |
template<typename T, typename U, typename W, typename Z> |
| 201 |
void DissectionSolver<T, U, W, Z>:: |
| 202 |
SaveCSRMatrix(const int called, const T *coefs_) |
| 203 |
{ |
| 204 |
diss_printf(true, stderr, |
| 205 |
"%s %d : specialized template is not yet defined.\n", |
| 206 |
__FILE__, __LINE__); |
| 207 |
} |
| 208 |
|
| 209 |
template |
| 210 |
void DissectionSolver<double>::SaveCSRMatrix(const int called, |
| 211 |
const double *coefs); |
| 212 |
|
| 213 |
template |
| 214 |
void DissectionSolver<complex<double>, double>:: |
| 215 |
SaveCSRMatrix(const int called, |
| 216 |
const complex<double> *coefs); |
| 217 |
|
| 218 |
template |
| 219 |
void DissectionSolver<quadruple>:: |
| 220 |
SaveCSRMatrix(const int called, |
| 221 |
const quadruple *coefs); |
| 222 |
|
| 223 |
template |
| 224 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 225 |
SaveCSRMatrix(const int called, |
| 226 |
const complex<quadruple> *coefs); |
| 227 |
|
| 228 |
template |
| 229 |
void DissectionSolver<float>::SaveCSRMatrix(const int called, |
| 230 |
const float *coefs); |
| 231 |
|
| 232 |
template |
| 233 |
void DissectionSolver<complex<float>, float>:: |
| 234 |
SaveCSRMatrix(const int called, |
| 235 |
const complex<float> *coefs); |
| 236 |
// |
| 237 |
|
| 238 |
template<typename T, typename U, typename W, typename Z> |
| 239 |
void DissectionSolver<T, U, W, Z>:: |
| 240 |
SaveMMMatrix(const int called, const T *coefs_) |
| 241 |
{ |
| 242 |
diss_printf(true, stderr, |
| 243 |
"%s %d : specialized template is not yet defined.\n", |
| 244 |
__FILE__, __LINE__); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
template<> |
| 249 |
void DissectionSolver<double>::SaveMMMatrix(const int called, |
| 250 |
const double *coefs_) |
| 251 |
{ |
| 252 |
SaveMMMatrix_(_dim, |
| 253 |
_ptDA->nnz(), |
| 254 |
_ptDA->isSymmetric(), |
| 255 |
_ptDA->isUpper(), |
| 256 |
_ptDA->getRows(), |
| 257 |
_ptDA->getIndCols(), |
| 258 |
called, coefs_); |
| 259 |
|
| 260 |
} |
| 261 |
|
| 262 |
template<> |
| 263 |
void DissectionSolver<complex<double>, double>:: |
| 264 |
SaveMMMatrix(const int called, |
| 265 |
const complex<double> *coefs_) |
| 266 |
{ |
| 267 |
SaveMMMatrix_(_dim, |
| 268 |
_ptDA->nnz(), |
| 269 |
_ptDA->isWhole() ? false : _ptDA->isSymmetric(), |
| 270 |
_ptDA->isUpper(), |
| 271 |
_ptDA->getRows(), |
| 272 |
_ptDA->getIndCols(), |
| 273 |
called, coefs_); |
| 274 |
} |
| 275 |
|
| 276 |
template |
| 277 |
void DissectionSolver<quadruple>:: |
| 278 |
SaveMMMatrix(const int called, |
| 279 |
const quadruple *coefs_); |
| 280 |
template |
| 281 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 282 |
SaveMMMatrix(const int called, |
| 283 |
const complex<quadruple> *coefs_); |
| 284 |
// |
| 285 |
|
| 286 |
void SaveMMMatrix_(const int dim, |
| 287 |
const int nnz, |
| 288 |
const bool isSymmetric, |
| 289 |
const bool isUpper, |
| 290 |
const int *ptrows, |
| 291 |
const int *indcols, |
| 292 |
const int called, |
| 293 |
const double *coefs_) |
| 294 |
|
| 295 |
{ |
| 296 |
// MatrixMarket format : one-based index, lower part stored for symmetric |
| 297 |
char fname[256]; |
| 298 |
int pid = get_process_id(); |
| 299 |
FILE *fp; |
| 300 |
sprintf(fname, "matrix.%04d.%06d.data", called, pid); |
| 301 |
if ((fp = fopen(fname, "w")) != NULL) { |
| 302 |
fprintf(fp, "%%%%MatrixMarket matrix coordinate real %s\n%d %d %d\n", |
| 303 |
|
| 304 |
isSymmetric? "symmetric" : "general", |
| 305 |
dim, dim, nnz); |
| 306 |
if (isUpper) { |
| 307 |
for (int i = 0; i < dim; i++) { |
| 308 |
for (int k = ptrows[i]; k < ptrows[i + 1]; k++) { |
| 309 |
const int jj = indcols[k] + 1; |
| 310 |
fprintf(fp, "%d %d %.16e\n", jj, (i + 1), coefs_[k]); |
| 311 |
} |
| 312 |
} |
| 313 |
} |
| 314 |
else { |
| 315 |
for (int i = 0; i < dim; i++) { |
| 316 |
for (int k = ptrows[i]; k < ptrows[i + 1]; k++) { |
| 317 |
const int jj = indcols[k] + 1; |
| 318 |
fprintf(fp, "%d %d %.16e\n", (i + 1), jj, coefs_[k]); |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
fclose(fp); |
| 323 |
} |
| 324 |
else { |
| 325 |
fprintf(stderr, |
| 326 |
"%s %d : fail to open %s\n", |
| 327 |
__FILE__, __LINE__, fname); |
| 328 |
exit(-1); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
void SaveMMMatrix_(const int dim, |
| 334 |
const int nnz, |
| 335 |
const bool isSymmetric, |
| 336 |
const bool isUpper, |
| 337 |
const int *ptrows, |
| 338 |
const int *indcols, |
| 339 |
const int called, |
| 340 |
const complex<double> *coefs_) |
| 341 |
{ |
| 342 |
// MatrixMarket format : one-based index, lower part stored for symmetric |
| 343 |
char fname[256]; |
| 344 |
int pid = get_process_id(); |
| 345 |
FILE *fp; |
| 346 |
sprintf(fname, "matrix.%04d.%06d.data", called, pid); |
| 347 |
if ((fp = fopen(fname, "w")) != NULL) { |
| 348 |
fprintf(fp, "%%%%MatrixMarket matrix coordinate complex %s\n%d %d %d\n", |
| 349 |
|
| 350 |
isSymmetric? "symmetric" : "general", |
| 351 |
dim, dim, nnz); |
| 352 |
if (isUpper) { |
| 353 |
for (int i = 0; i < dim; i++) { |
| 354 |
for (int k = ptrows[i]; k < ptrows[i + 1]; k++) { |
| 355 |
const int jj = indcols[k] + 1; |
| 356 |
fprintf(fp, "%d %d %.16e %.16e\n", jj, (i + 1), |
| 357 |
coefs_[k].real(), coefs_[k].imag()); |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
else { |
| 362 |
for (int i = 0; i < dim; i++) { |
| 363 |
for (int k = ptrows[i]; k < ptrows[i + 1]; k++) { |
| 364 |
const int jj = indcols[k] + 1; |
| 365 |
fprintf(fp, "%d %d %.16e %.16e\n", (i + 1), jj, |
| 366 |
coefs_[k].real(), coefs_[k].imag()); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
fclose(fp); |
| 371 |
} |
| 372 |
else { |
| 373 |
fprintf(stderr, |
| 374 |
"%s %d : fail to open %s\n", |
| 375 |
__FILE__, __LINE__, fname); |
| 376 |
exit(-1); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
// copy from higher precision than T and U : quadruple <- T = double |
| 381 |
template<typename T, typename U, typename W, typename Z> |
| 382 |
void DissectionSolver<T, U, W, Z>:: |
| 383 |
CopyQueueFwBw(DissectionSolver<W, Z, T, U> &qdslv) |
| 384 |
{ |
| 385 |
bool isSym = qdslv.ptDA()->isSymmetric(); |
| 386 |
bool isUpper = qdslv.ptDA()->isUpper(); |
| 387 |
bool isWhole = qdslv.ptDA()->isWhole(); |
| 388 |
_dim = qdslv.dimension(); |
| 389 |
_graph_colors = qdslv.graph_colors(); |
| 390 |
_scaling = qdslv.scaling(); |
| 391 |
_verbose = qdslv.verbose(); |
| 392 |
_num_threads = qdslv.num_threads(); |
| 393 |
_nsing = qdslv.nsing(); |
| 394 |
_fp = qdslv.get_filedescriptor(); |
| 395 |
bool verbose = qdslv.verbose(); |
| 396 |
// T *coefs; |
| 397 |
_dissectionQueue = new DissectionQueue<T, U>*[_graph_colors]; |
| 398 |
_tridiagQueue = new TridiagQueue<T, U>*[_graph_colors]; |
| 399 |
_dissectionMatrix = |
| 400 |
new vector<DissectionMatrix<T, U>* >[_graph_colors]; |
| 401 |
_tridiagMatrix = new TridiagBlockMatrix<T, U>*[_graph_colors]; |
| 402 |
|
| 403 |
_Schur = new SchurMatrix<T>[_graph_colors]; |
| 404 |
_kernel = new KernelMatrix<T>[_graph_colors]; |
| 405 |
_singIdx = new vector<int>[_graph_colors]; |
| 406 |
for (int m = 0; m < _graph_colors; m++) { |
| 407 |
_Schur[m].getAcol() = new SparseMatrix<T>(); // dummy allocation |
| 408 |
_Schur[m].getArow() = new SparseMatrix<T>(); // dummy allocation |
| 409 |
} |
| 410 |
DissectionQueue<W, Z>** dQ = qdslv.getDissectionQueue(); |
| 411 |
TridiagQueue<W, Z>** tQ = qdslv.getTridiagQueue(); |
| 412 |
_precDiag = new U[_dim]; |
| 413 |
for (int i = 0; i < _dim; i++) { |
| 414 |
_precDiag[i] = conv_prec<U, Z>(qdslv.addrPrecDiag()[i]); |
| 415 |
} |
| 416 |
|
| 417 |
_ptDA = new SparseMatrix<T>(isSym, isUpper, isWhole); |
| 418 |
|
| 419 |
CopySparseMatrix(_ptDA, qdslv.ptDA()); |
| 420 |
// coefs = _ptDA->getCoef(); |
| 421 |
for (int m = 0; m < _graph_colors; m++) { |
| 422 |
if (tQ[m]->tridiagSolver()) { |
| 423 |
const int dim = tQ[m]->dimension(); |
| 424 |
_tridiagMatrix[m] = new TridiagBlockMatrix<T, U>(dim, |
| 425 |
SIZE_B1, |
| 426 |
isSym, |
| 427 |
0, // no other Tridiag |
| 428 |
verbose, |
| 429 |
_fp); |
| 430 |
CopyTridiagBlockMatrix(*_tridiagMatrix[m], |
| 431 |
*qdslv.getTridiagBlockMatrix()[m], |
| 432 |
_ptDA->getCoef()); |
| 433 |
|
| 434 |
_tridiagQueue[m] = new TridiagQueue<T, U>(true, verbose, _fp); |
| 435 |
_tridiagQueue[m]->generate_queue(_tridiagMatrix[m], |
| 436 |
tQ[m]->dimension(), |
| 437 |
tQ[m]->nnz(), |
| 438 |
tQ[m]->isMapped(), |
| 439 |
tQ[m]->remap_eqn(), |
| 440 |
tQ[m]->ptRows(), |
| 441 |
tQ[m]->indCols(), |
| 442 |
tQ[m]->indVals(), |
| 443 |
_ptDA->getCoef()); |
| 444 |
} |
| 445 |
else { // if (tQ[m]->tridiagSolver()) |
| 446 |
Dissection::Tree* btree = qdslv.btree()[m]; |
| 447 |
_tridiagQueue[m] = new TridiagQueue<T, U>(false, verbose, _fp); |
| 448 |
const int nb_doms = btree->NumberOfSubdomains(); |
| 449 |
_dissectionMatrix[m].resize(nb_doms); |
| 450 |
_dissectionQueue[m] = new DissectionQueue<T, U>(btree, |
| 451 |
_dissectionMatrix[m], |
| 452 |
_num_threads, |
| 453 |
isSym, |
| 454 |
verbose, |
| 455 |
_fp); |
| 456 |
|
| 457 |
typename vector<DissectionMatrix<W, Z>* >::const_iterator it = qdslv.getDissectionMatrix()[m].begin(); |
| 458 |
typename vector<DissectionMatrix<T, U>* >::const_iterator jt = _dissectionMatrix[m].begin(); |
| 459 |
for ( ; it != qdslv.getDissectionMatrix()[m].end(); ++it, ++jt) { |
| 460 |
if ((*it)->islast()) { |
| 461 |
int color = (*it)->ColorTridiagBlockMatrix(); |
| 462 |
for (int i = 0; i < color; i++) { |
| 463 |
CopyTridiagBlockMatrix(*(*jt)->addrtridiagBlock()[i], |
| 464 |
*(*it)->addrtridiagBlock()[i], |
| 465 |
_ptDA->getCoef()); |
| 466 |
} // loop : i |
| 467 |
} // if ((*it)->islast()) |
| 468 |
else { |
| 469 |
CopySquareBlockMatrix((*jt)->diagBlock(), (*it)->diagBlock()); |
| 470 |
} |
| 471 |
SquareBlockMatrix<T>* diag = (*jt)->addrdiagBlock(); |
| 472 |
RectBlockMatrix<T>* lower = (*jt)->addrlowerBlock(); |
| 473 |
if (!isSym) { |
| 474 |
CopyRectBlockMatrix(*lower, (*it)->lowerBlock()); |
| 475 |
} |
| 476 |
RectBlockMatrix<T>* upper = (*jt)->addrupperBlock(); |
| 477 |
CopyRectBlockMatrix(*upper, (*it)->upperBlock()); |
| 478 |
|
| 479 |
CopyDissectionMatrix((*jt), |
| 480 |
(*it), |
| 481 |
diag, |
| 482 |
lower, |
| 483 |
upper); |
| 484 |
} // loop : it, jt |
| 485 |
|
| 486 |
_dissectionQueue[m]->generate_queue_fwbw(_dissectionMatrix[m], |
| 487 |
dQ[m]->dimension(), |
| 488 |
dQ[m]->nnz(), _ptDA->getCoef()); |
| 489 |
} // if (tQ[m]->tridiagSolver()) |
| 490 |
CopyKernelMatrix(_kernel[m], qdslv.getKernelMatrix()[m]); |
| 491 |
_singIdx[m] = qdslv.getSingVal()[m]; |
| 492 |
} // loop : m |
| 493 |
// qdslv.GetMatrixScaling(_precDiag); |
| 494 |
_index_isolated = qdslv.getIndexIsolated(); |
| 495 |
_status_factorized = true; |
| 496 |
_btree = new Dissection::Tree*[_graph_colors]; // dummy allocation |
| 497 |
_with_btree = false; |
| 498 |
} |
| 499 |
|
| 500 |
template |
| 501 |
void DissectionSolver<double, double, quadruple, quadruple>:: |
| 502 |
CopyQueueFwBw(DissectionSolver<quadruple, quadruple, double, double> &qdslv); |
| 503 |
|
| 504 |
template |
| 505 |
void DissectionSolver<complex<double>, double, complex<quadruple>, quadruple>:: |
| 506 |
CopyQueueFwBw(DissectionSolver<complex<quadruple>, quadruple, |
| 507 |
complex<double>, double> &qdslv); |
| 508 |
|
| 509 |
template |
| 510 |
void DissectionSolver<quadruple, quadruple, double, double>:: |
| 511 |
CopyQueueFwBw(DissectionSolver<double, double, quadruple, quadruple> &qdslv); |
| 512 |
|
| 513 |
template |
| 514 |
void DissectionSolver<complex<quadruple>, quadruple, complex<double>, double>:: |
| 515 |
CopyQueueFwBw(DissectionSolver<complex<double>, double, complex<quadruple>, quadruple> &qdslv); |
| 516 |
|
| 517 |
template |
| 518 |
void DissectionSolver<float, float, double, double>:: |
| 519 |
CopyQueueFwBw(DissectionSolver<double, double, float, float> &qdslv); |
| 520 |
|
| 521 |
template |
| 522 |
void DissectionSolver<complex<float>, float, complex<double>, double>:: |
| 523 |
CopyQueueFwBw(DissectionSolver<complex<double>, double, complex<float>, float> &qdslv); |
| 524 |
|
| 525 |
|
| 526 |
template<typename T, typename U, typename W, typename Z> |
| 527 |
void DissectionSolver<T, U, W, Z>:: |
| 528 |
SymbolicFact(const int dim_, |
| 529 |
const int *ptRows, |
| 530 |
const int *indCols, |
| 531 |
const bool isSym, |
| 532 |
const bool isUpper, |
| 533 |
const bool isWhole, |
| 534 |
const int decomposer_, |
| 535 |
const int nbLevels_, |
| 536 |
const int minNodes) |
| 537 |
{ |
| 538 |
SymbolicFact_(dim_, |
| 539 |
ptRows[dim_], |
| 540 |
false, |
| 541 |
ptRows, |
| 542 |
indCols, |
| 543 |
(long long int *)NULL, // const long long int *ptRows, |
| 544 |
(long long int *)NULL, // const long long int *indCols, |
| 545 |
isSym, |
| 546 |
isUpper, |
| 547 |
isWhole, |
| 548 |
decomposer_, |
| 549 |
nbLevels_, |
| 550 |
minNodes); |
| 551 |
} |
| 552 |
|
| 553 |
template |
| 554 |
void DissectionSolver<double>::SymbolicFact(const int dim_, |
| 555 |
const int *ptRows, |
| 556 |
const int *indCols, |
| 557 |
const bool isSym, |
| 558 |
const bool isUpper, |
| 559 |
const bool isWhole, |
| 560 |
const int decomposer, |
| 561 |
const int nbLevels_, |
| 562 |
const int minNodes); |
| 563 |
|
| 564 |
template |
| 565 |
void DissectionSolver<quadruple>::SymbolicFact(const int dim_, |
| 566 |
const int *ptRows, |
| 567 |
const int *indCols, |
| 568 |
const bool isSym, |
| 569 |
const bool isUpper, |
| 570 |
const bool isWhole, |
| 571 |
const int decomposer, |
| 572 |
const int nbLevels_, |
| 573 |
const int minNodes); |
| 574 |
|
| 575 |
template |
| 576 |
void DissectionSolver<complex<double>, double>:: |
| 577 |
SymbolicFact(const int dim_, |
| 578 |
const int *ptRows, |
| 579 |
const int *indCols, |
| 580 |
const bool isSym, |
| 581 |
const bool isUpper, |
| 582 |
const bool isWhole, |
| 583 |
const int decomposer, |
| 584 |
const int nbLevels_, |
| 585 |
const int minNodes); |
| 586 |
|
| 587 |
template |
| 588 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 589 |
SymbolicFact(const int dim_, |
| 590 |
const int *ptRows, |
| 591 |
const int *indCols, |
| 592 |
const bool isSym, |
| 593 |
const bool isUpper, |
| 594 |
const bool isWhole, |
| 595 |
const int decomposer, |
| 596 |
const int nbLevels_, |
| 597 |
const int minNodes); |
| 598 |
|
| 599 |
template |
| 600 |
void DissectionSolver<double, double, |
| 601 |
quadruple, quadruple>::SymbolicFact(const int dim_, |
| 602 |
const int *ptRows, |
| 603 |
const int *indCols, |
| 604 |
const bool isSym, |
| 605 |
const bool isUpper, |
| 606 |
const bool isWhole, |
| 607 |
const int decomposer, |
| 608 |
const int nbLevels_, |
| 609 |
const int minNodes); |
| 610 |
template |
| 611 |
void DissectionSolver<quadruple, quadruple, |
| 612 |
double, double>::SymbolicFact(const int dim_, |
| 613 |
const int *ptRows, |
| 614 |
const int *indCols, |
| 615 |
const bool isSym, |
| 616 |
const bool isUpper, |
| 617 |
const bool isWhole, |
| 618 |
const int decomposer, |
| 619 |
const int nbLevels_, |
| 620 |
const int minNodes); |
| 621 |
|
| 622 |
template |
| 623 |
void DissectionSolver<complex<double>, double, complex<quadruple>, quadruple>:: |
| 624 |
SymbolicFact(const int dim_, |
| 625 |
const int *ptRows, |
| 626 |
const int *indCols, |
| 627 |
const bool isSym, |
| 628 |
const bool isUpper, |
| 629 |
const bool isWhole, |
| 630 |
const int decomposer, |
| 631 |
const int nbLevels_, |
| 632 |
const int minNodes); |
| 633 |
|
| 634 |
template |
| 635 |
void DissectionSolver<complex<quadruple>, quadruple, complex<double>, double>:: |
| 636 |
SymbolicFact(const int dim_, |
| 637 |
const int *ptRows, |
| 638 |
const int *indCols, |
| 639 |
const bool isSym, |
| 640 |
const bool isUpper, |
| 641 |
const bool isWhole, |
| 642 |
const int decomposer, |
| 643 |
const int nbLevels_, |
| 644 |
const int minNodes); |
| 645 |
|
| 646 |
template |
| 647 |
void DissectionSolver<float>::SymbolicFact(const int dim_, |
| 648 |
const int *ptRows, |
| 649 |
const int *indCols, |
| 650 |
const bool isSym, |
| 651 |
const bool isUpper, |
| 652 |
const bool isWhole, |
| 653 |
const int decomposer, |
| 654 |
const int nbLevels_, |
| 655 |
const int minNodes); |
| 656 |
|
| 657 |
template |
| 658 |
void DissectionSolver<complex<float>, float>::SymbolicFact(const int dim_, |
| 659 |
const int *ptRows, |
| 660 |
const int *indCols, |
| 661 |
const bool isSym, |
| 662 |
const bool isUpper, |
| 663 |
const bool isWhole, |
| 664 |
const int decomposer, |
| 665 |
const int nbLevels_, |
| 666 |
const int minNodes); |
| 667 |
// |
| 668 |
|
| 669 |
template<typename T, typename U, typename W, typename Z> |
| 670 |
void DissectionSolver<T, U, W, Z>:: |
| 671 |
SymbolicFact(const int dim_, |
| 672 |
const long long int *ptRows, |
| 673 |
const long long int *indCols, |
| 674 |
const bool isSym, |
| 675 |
const bool isUpper, |
| 676 |
const bool isWhole, |
| 677 |
const int decomposer_, |
| 678 |
const int nbLevels_, |
| 679 |
const int minNodes) |
| 680 |
{ |
| 681 |
SymbolicFact_(dim_, |
| 682 |
(int)ptRows[dim_], |
| 683 |
true, |
| 684 |
(int *)NULL, // const int *ptRows, |
| 685 |
(int *)NULL, // const int *indCols, |
| 686 |
ptRows, |
| 687 |
indCols, |
| 688 |
isSym, |
| 689 |
isUpper, |
| 690 |
isWhole, |
| 691 |
decomposer_, |
| 692 |
nbLevels_, |
| 693 |
minNodes); |
| 694 |
} |
| 695 |
|
| 696 |
template |
| 697 |
void DissectionSolver<double>::SymbolicFact(const int dim_, |
| 698 |
const long long int *ptRows, |
| 699 |
const long long int *indCols, |
| 700 |
const bool isSym, |
| 701 |
const bool isUpper, |
| 702 |
const bool isWhole, |
| 703 |
const int decomposer, |
| 704 |
const int nbLevels_, |
| 705 |
const int minNodes); |
| 706 |
template |
| 707 |
void DissectionSolver<quadruple>::SymbolicFact(const int dim_, |
| 708 |
const long long int *ptRows, |
| 709 |
const long long int *indCols, |
| 710 |
const bool isSym, |
| 711 |
const bool isUpper, |
| 712 |
const bool isWhole, |
| 713 |
const int decomposer, |
| 714 |
const int nbLevels_, |
| 715 |
const int minNodes); |
| 716 |
|
| 717 |
template |
| 718 |
void DissectionSolver<complex<double>, double>:: |
| 719 |
SymbolicFact(const int dim_, |
| 720 |
const long long int *ptRows, |
| 721 |
const long long int *indCols, |
| 722 |
const bool isSym, |
| 723 |
const bool isUpper, |
| 724 |
const bool isWhole, |
| 725 |
const int decomposer, |
| 726 |
const int nbLevels_, |
| 727 |
const int minNodes); |
| 728 |
|
| 729 |
template |
| 730 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 731 |
SymbolicFact(const int dim_, |
| 732 |
const long long int *ptRows, |
| 733 |
const long long int *indCols, |
| 734 |
const bool isSym, |
| 735 |
const bool isUpper, |
| 736 |
const bool isWhole, |
| 737 |
const int decomposer, |
| 738 |
const int nbLevels_, |
| 739 |
const int minNodes); |
| 740 |
|
| 741 |
template |
| 742 |
void DissectionSolver<float>::SymbolicFact(const int dim_, |
| 743 |
const long long int *ptRows, |
| 744 |
const long long int *indCols, |
| 745 |
const bool isSym, |
| 746 |
const bool isUpper, |
| 747 |
const bool isWhole, |
| 748 |
const int decomposer, |
| 749 |
const int nbLevels_, |
| 750 |
const int minNodes); |
| 751 |
|
| 752 |
template |
| 753 |
void DissectionSolver<complex<float>, float>::SymbolicFact(const int dim_, |
| 754 |
const long long int *ptRows, |
| 755 |
const long long int *indCols, |
| 756 |
const bool isSym, |
| 757 |
const bool isUpper, |
| 758 |
const bool isWhole, |
| 759 |
const int decomposer, |
| 760 |
const int nbLevels_, |
| 761 |
const int minNodes); |
| 762 |
|
| 763 |
// |
| 764 |
template<typename T, typename U, typename W, typename Z> |
| 765 |
void DissectionSolver<T, U, W, Z>:: |
| 766 |
SymbolicFact_(const int dim_, |
| 767 |
const int nz_, |
| 768 |
const bool flagint64, |
| 769 |
const int *ptRows, |
| 770 |
const int *indCols, |
| 771 |
const long long int *ptRows64, |
| 772 |
const long long int *indCols64, |
| 773 |
const bool isSym, |
| 774 |
const bool isUpper, |
| 775 |
const bool isWhole, |
| 776 |
const int decomposer_, |
| 777 |
const int nbLevels_, |
| 778 |
const int minNodes) |
| 779 |
{ |
| 780 |
// decomposer = 0: SCOTCH, 1 : METIS, 2 : TRIDIAG(Cuthill-McKee) |
| 781 |
int dim = dim_; |
| 782 |
clock_t t0_cpu, t1_cpu, t2_cpu; |
| 783 |
elapsed_t t0_elapsed, t1_elapsed, t2_elapsed; |
| 784 |
|
| 785 |
_dim = dim_; |
| 786 |
const int nz = nz_; |
| 787 |
int nbLevels, decomposer; |
| 788 |
bool flag, berr; |
| 789 |
int *map_eqn, *remap_eqn; |
| 790 |
int num_threads; |
| 791 |
|
| 792 |
t0_cpu = clock(); |
| 793 |
get_realtime(&t0_elapsed); |
| 794 |
|
| 795 |
if (flagint64) { |
| 796 |
_ptDA = new SparseMatrix<T>(dim, nz, ptRows64, indCols64, |
| 797 |
isSym, isUpper, isWhole); |
| 798 |
} |
| 799 |
else { |
| 800 |
_ptDA = new SparseMatrix<T>(dim, nz, ptRows, indCols, |
| 801 |
isSym, isUpper, isWhole); |
| 802 |
} |
| 803 |
|
| 804 |
diss_printf(_verbose, _fp, |
| 805 |
"%s %d : isSym = %s isUpper = %s isWhole = %s decomposer = %d\n", |
| 806 |
__FILE__, __LINE__, |
| 807 |
isSym ? "ture" : "false", |
| 808 |
isUpper ? "ture" : "false", |
| 809 |
isWhole ? "ture" : "false", |
| 810 |
decomposer_); |
| 811 |
switch(nbLevels_) { |
| 812 |
case 1 : |
| 813 |
diss_printf(_verbose, _fp, |
| 814 |
"%s %d : Dissection :: not activated, switch to tridiag\n", |
| 815 |
__FILE__, __LINE__); |
| 816 |
decomposer = TRIDIAG_DECOMPOSER; |
| 817 |
break; |
| 818 |
case (-1): |
| 819 |
nbLevels = (int)log2((double)dim_ / (double)minNodes); |
| 820 |
if (nbLevels < 2) { |
| 821 |
decomposer = TRIDIAG_DECOMPOSER; |
| 822 |
} |
| 823 |
else { |
| 824 |
decomposer = decomposer_; |
| 825 |
} |
| 826 |
break; |
| 827 |
default: |
| 828 |
nbLevels = nbLevels_; |
| 829 |
decomposer = decomposer_; |
| 830 |
break; |
| 831 |
} |
| 832 |
|
| 833 |
map_eqn = new int[dim]; // delete [] in DissectionSolver::Destroy(void) |
| 834 |
remap_eqn = new int[dim]; // delete [] in DissectionSolver::Destroy(void) |
| 835 |
for (int i = 0; i < dim; i++) { |
| 836 |
map_eqn[i] = i; |
| 837 |
remap_eqn[i] = i; |
| 838 |
} |
| 839 |
|
| 840 |
CSR_indirect *unsym_csr = new CSR_indirect; |
| 841 |
bool unsym_csr_alloc = false; |
| 842 |
// int *ptUnsymRows, *indUnsymCols, *indVals, *indSymVals; |
| 843 |
|
| 844 |
if (isSym) { |
| 845 |
if (isWhole) { |
| 846 |
unsym_csr->n = dim; |
| 847 |
unsym_csr->nnz = nz; |
| 848 |
unsym_csr->ptRows = _ptDA->getRows(); // (int *)ptRows; |
| 849 |
unsym_csr->indCols = _ptDA->getIndCols(); //(int *)indCols; |
| 850 |
unsym_csr->indVals = new int[nz]; |
| 851 |
unsym_csr->indVals_unsym = new int[nz]; // for safe use of delete [] |
| 852 |
} |
| 853 |
else { |
| 854 |
const int nnz0 = nz * 2 - dim; |
| 855 |
unsym_csr->n = dim; |
| 856 |
unsym_csr->nnz = nnz0; |
| 857 |
unsym_csr->ptRows = new int[dim + 1]; |
| 858 |
unsym_csr->indCols = new int[nnz0]; |
| 859 |
unsym_csr_alloc = true; |
| 860 |
unsym_csr->indVals = new int[nnz0]; |
| 861 |
unsym_csr->indVals_unsym = (int *)NULL; // for safe use of delete [] |
| 862 |
// only used as extend symmetric symbolic structure to unsymmetric |
| 863 |
int nnz1; |
| 864 |
nnz1 = CSR_sym2unsym(unsym_csr, |
| 865 |
_ptDA->getRows(), _ptDA->getIndCols(), |
| 866 |
map_eqn, remap_eqn, // |
| 867 |
dim, isUpper); |
| 868 |
if (nnz1 != nnz0) { |
| 869 |
fprintf(stderr, |
| 870 |
"%s %d : symmetric matrix has no diagonal entry %d != %d\n", |
| 871 |
__FILE__, __LINE__, nnz0, nnz1); |
| 872 |
exit(-1); |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
else { |
| 877 |
unsym_csr->n = dim; |
| 878 |
unsym_csr->nnz = nz; |
| 879 |
unsym_csr->indVals = new int[nz]; |
| 880 |
unsym_csr->indVals_unsym = new int[nz]; |
| 881 |
unsym_csr->ptRows = _ptDA->getRows(); //(int *)ptRows; |
| 882 |
unsym_csr->indCols = _ptDA->getIndCols(); //(int *)indCols; |
| 883 |
} |
| 884 |
int* graph_mask = new int[dim]; |
| 885 |
|
| 886 |
{ |
| 887 |
_graph_colors = getColorMaskCSR(graph_mask, unsym_csr, _verbose, _fp); |
| 888 |
int count = 0; |
| 889 |
for (int i = 0; i < dim; i++) { |
| 890 |
if (graph_mask[i] == 0) { |
| 891 |
count++; |
| 892 |
} |
| 893 |
} |
| 894 |
_index_isolated.resize(count); |
| 895 |
count = 0; |
| 896 |
for (int i = 0; i < dim; i++) { |
| 897 |
if (graph_mask[i] == 0) { |
| 898 |
_index_isolated[count] = i; |
| 899 |
count++; |
| 900 |
} |
| 901 |
} |
| 902 |
} |
| 903 |
_btree = new Dissection::Tree*[_graph_colors]; |
| 904 |
_with_btree = true; |
| 905 |
_dissectionMatrix = new vector<DissectionMatrix<T, U>* >[_graph_colors]; |
| 906 |
_dissectionQueue = new DissectionQueue<T, U>*[_graph_colors]; |
| 907 |
_tridiagMatrix = new TridiagBlockMatrix<T, U>*[_graph_colors]; |
| 908 |
_tridiagQueue = new TridiagQueue<T, U>*[_graph_colors]; |
| 909 |
// loop over each connected graph |
| 910 |
for (int m = 0; m < _graph_colors; m++) { |
| 911 |
bool flag_dissection = false; |
| 912 |
int i0, i1, i2; |
| 913 |
const int color = m + 1; |
| 914 |
int count = 0; |
| 915 |
int dim1, dim2; |
| 916 |
dim1 = 0; |
| 917 |
dim2 = 0; |
| 918 |
for (int i = 0; i < dim; i++) { |
| 919 |
if (graph_mask[i] == color) { |
| 920 |
dim1++; |
| 921 |
} |
| 922 |
else if (graph_mask[i] == (-color)) { |
| 923 |
dim2++; |
| 924 |
} |
| 925 |
} |
| 926 |
count = dim1 + dim2; |
| 927 |
i0 = 0; |
| 928 |
i1 = dim1; |
| 929 |
i2 = count; |
| 930 |
for (int i = 0; i < dim; i++) { |
| 931 |
if (graph_mask[i] == color) { |
| 932 |
remap_eqn[i0++] = i; // remap : new(mapped) to old(original) index |
| 933 |
} |
| 934 |
else if (graph_mask[i] == (-color)) { |
| 935 |
remap_eqn[i1++] = i; // remap : new(mapped) to old(original) index |
| 936 |
} |
| 937 |
else { |
| 938 |
remap_eqn[i2++] = i; |
| 939 |
} |
| 940 |
} |
| 941 |
for (int i = 0; i < dim; i++) { |
| 942 |
map_eqn[remap_eqn[i]] = i; // map : old(original) to new (mapped) index |
| 943 |
} |
| 944 |
if (isSym) { |
| 945 |
if (isWhole) { |
| 946 |
if (m == 0) { //reconnect to newly allocated array |
| 947 |
unsym_csr->ptRows = new int[dim + 1]; |
| 948 |
unsym_csr->indCols = new int[nz]; |
| 949 |
unsym_csr_alloc = true; |
| 950 |
} |
| 951 |
CSR_unsym2unsym(unsym_csr, |
| 952 |
_ptDA->getRows(), _ptDA->getIndCols(), |
| 953 |
map_eqn, remap_eqn, // |
| 954 |
dim, _verbose, _fp); |
| 955 |
} |
| 956 |
else { |
| 957 |
CSR_sym2unsym(unsym_csr, |
| 958 |
_ptDA->getRows(), _ptDA->getIndCols(), |
| 959 |
map_eqn, remap_eqn, // |
| 960 |
dim, isUpper, _verbose, _fp); |
| 961 |
} |
| 962 |
} |
| 963 |
else { |
| 964 |
if (m == 0) { //reconnect to newly allocated array |
| 965 |
unsym_csr->ptRows = new int[dim + 1]; |
| 966 |
unsym_csr->indCols = new int[nz]; |
| 967 |
unsym_csr_alloc = true; |
| 968 |
} |
| 969 |
CSR_unsym2unsym(unsym_csr, |
| 970 |
_ptDA->getRows(), _ptDA->getIndCols(), |
| 971 |
map_eqn, remap_eqn, // |
| 972 |
dim, _verbose, _fp); |
| 973 |
} |
| 974 |
|
| 975 |
flag = false; |
| 976 |
|
| 977 |
if (_graph_colors > 1) { |
| 978 |
const int level_tmp = (int)log2((double)count / (double)minNodes); |
| 979 |
nbLevels = nbLevels < level_tmp ? nbLevels : level_tmp; |
| 980 |
nbLevels = nbLevels < 2 ? 2 : nbLevels; // |
| 981 |
} |
| 982 |
diss_printf(_verbose, _fp, |
| 983 |
"%s %d : count = %d decomposer = %d\n", __FILE__, __LINE__, |
| 984 |
count, decomposer); |
| 985 |
|
| 986 |
if ((count > SIZE_TRIDIAG) && ((decomposer == SCOTCH_DECOMPOSER) || |
| 987 |
(decomposer == METIS_DECOMPOSER))) { |
| 988 |
flag_dissection = true; |
| 989 |
diss_printf(_verbose, _fp, |
| 990 |
"%s %d : %s applied to color %d neq = %d with %d levels\n", |
| 991 |
__FILE__, __LINE__, |
| 992 |
(decomposer == METIS_DECOMPOSER) ? "METIS" : "SCOTCH", |
| 993 |
color, count, |
| 994 |
nbLevels); |
| 995 |
while (flag == false) { |
| 996 |
_btree[m] = |
| 997 |
new Dissection::Tree(_fp, |
| 998 |
berr, |
| 999 |
(unsigned)count, |
| 1000 |
unsym_csr, |
| 1001 |
isSym, |
| 1002 |
remap_eqn, |
| 1003 |
nbLevels, |
| 1004 |
minNodes, |
| 1005 |
#ifdef NO_METIS |
| 1006 |
NULL, |
| 1007 |
#else |
| 1008 |
((decomposer == METIS_DECOMPOSER) ? MetisSplitter : NULL), |
| 1009 |
#endif |
| 1010 |
true, _verbose); |
| 1011 |
diss_printf(_verbose, _fp, |
| 1012 |
"%s %d : Dissection::Tree %s decomposition\n", |
| 1013 |
__FILE__, __LINE__, |
| 1014 |
(decomposer == METIS_DECOMPOSER) ? "METIS" : "SCOTCH"); |
| 1015 |
flag = true; |
| 1016 |
for (int d = 1; d <= _btree[m]->NumberOfSubdomains(); d++) { |
| 1017 |
// if (_btree[m]->sizeOfDomain(d) == 0) { |
| 1018 |
const int isd = _btree[m]->sizeOfDomain(d); |
| 1019 |
if (isd <= DIM_AUG_KERN) { |
| 1020 |
if (d > 1) { |
| 1021 |
diss_printf(_verbose, _fp, |
| 1022 |
"%s %d : Dissection:: %d-th too small nrow = %d\n", |
| 1023 |
__FILE__, __LINE__, d, isd); |
| 1024 |
} |
| 1025 |
else { |
| 1026 |
fprintf(stderr, |
| 1027 |
"%s %d : too small first bisector %d not yet accepted\n", |
| 1028 |
__FILE__, __LINE__, isd); |
| 1029 |
exit(-1); |
| 1030 |
} |
| 1031 |
} // if (isd == 0) |
| 1032 |
} // loop : d |
| 1033 |
if (flag) { |
| 1034 |
break; |
| 1035 |
} |
| 1036 |
else { |
| 1037 |
if (berr == true) { |
| 1038 |
delete _btree[m]; // for retry of graph partitioning |
| 1039 |
} |
| 1040 |
} |
| 1041 |
} // while |
| 1042 |
// _nbLevels = _btree[m]->NumberOfLevels(); |
| 1043 |
diss_printf(_verbose, _fp, |
| 1044 |
"%s %d : Tree strategy = 0 : nblevels = %d -> %d\n", |
| 1045 |
__FILE__, __LINE__, |
| 1046 |
nbLevels, _btree[m]->NumberOfLevels()); |
| 1047 |
|
| 1048 |
if ((_btree[m]->NumberOfLevels() == 1) |
| 1049 |
|| ((nbLevels - _btree[m]->NumberOfLevels()) > 3) || berr == false) { |
| 1050 |
#ifdef NO_METIS |
| 1051 |
flag_dissection = false; |
| 1052 |
#else |
| 1053 |
flag_dissection = true; |
| 1054 |
diss_printf(_verbose, _fp, |
| 1055 |
"%s %d :: retry partitioning by METIS : %d\n", |
| 1056 |
__FILE__, __LINE__, nbLevels); |
| 1057 |
nbLevels = nbLevels > 4 ? (nbLevels - 3) : 2; |
| 1058 |
flag = false; |
| 1059 |
while (flag == false) { |
| 1060 |
_btree[m] = |
| 1061 |
new Dissection::Tree(_fp, berr, (unsigned)count, |
| 1062 |
unsym_csr, |
| 1063 |
isSym, |
| 1064 |
remap_eqn, |
| 1065 |
nbLevels, minNodes, |
| 1066 |
MetisSplitter, |
| 1067 |
true, _verbose); |
| 1068 |
diss_printf(_verbose, _fp, |
| 1069 |
"%s %d :: Tree METIS decomposition **\n", |
| 1070 |
__FILE__, __LINE__ ); |
| 1071 |
flag = true; |
| 1072 |
for (int d = 1; d <= _btree[m]->NumberOfSubdomains(); d++) { |
| 1073 |
if (_btree[m]->sizeOfDomain(d) == 0) { |
| 1074 |
flag = false; |
| 1075 |
} |
| 1076 |
} |
| 1077 |
if (flag) { |
| 1078 |
break; |
| 1079 |
} |
| 1080 |
else { |
| 1081 |
delete _btree[m]; |
| 1082 |
nbLevels--; |
| 1083 |
} |
| 1084 |
} // while (flag == flase) |
| 1085 |
#endif |
| 1086 |
} // if |
| 1087 |
} // if ((count > SIZE_TRIDIAG) && ((decomposer == SCOTCH_DECOMPOSER)... |
| 1088 |
|
| 1089 |
if (flag_dissection) { |
| 1090 |
bool verify_root = (_btree[m]->sizeOfDomain(1) <= SIZE_B1); |
| 1091 |
int nb_doms = _btree[m]->NumberOfSubdomains(); |
| 1092 |
_dissectionMatrix[m].resize(nb_doms); |
| 1093 |
diss_printf(_verbose, _fp, |
| 1094 |
"%s %d : ", __FILE__, __LINE__); |
| 1095 |
diss_printf(_verbose, _fp, |
| 1096 |
"num_threads = %d dim = %d dim_diss. = %d nbLevels = %d\n", |
| 1097 |
_num_threads, _dim, count, _btree[m]->NumberOfLevels()); |
| 1098 |
for (int d = 1; d <= _btree[m]->NumberOfSubdomains(); d++) { |
| 1099 |
diss_printf(_verbose, _fp, |
| 1100 |
"( %d % d) ", d, _btree[m]->sizeOfDomain(d)); |
| 1101 |
} |
| 1102 |
diss_printf(_verbose, _fp, "\n"); |
| 1103 |
const int level_last = _btree[m]->NumberOfLevels(); |
| 1104 |
const int nb_doms_dense0 = (1U << (level_last - 1)); |
| 1105 |
if (_num_threads > nb_doms_dense0 || verify_root) { |
| 1106 |
diss_printf(_verbose, _fp, |
| 1107 |
"%s %d : ", __FILE__, __LINE__); |
| 1108 |
diss_printf(_verbose, _fp, |
| 1109 |
"thread number reduced : %d -> %d\n", |
| 1110 |
_num_threads, 1); |
| 1111 |
diss_printf(_verbose, _fp, |
| 1112 |
"which is used as number of threads for computation\n"); |
| 1113 |
// num_threads = nb_doms_dense0; |
| 1114 |
num_threads = 1; |
| 1115 |
} |
| 1116 |
else { |
| 1117 |
num_threads = _num_threads; |
| 1118 |
} |
| 1119 |
_dissectionQueue[m] = new DissectionQueue<T, U>(_btree[m], |
| 1120 |
_dissectionMatrix[m], |
| 1121 |
num_threads, |
| 1122 |
isSym, |
| 1123 |
_verbose, |
| 1124 |
_fp); |
| 1125 |
// generation of queue for numerical factorization is treated as a part of |
| 1126 |
// symbolic factorization : _queue_symb, {_queue_static, _queue_dynamic} |
| 1127 |
_dissectionQueue[m]->generate_queue(_dissectionMatrix[m], |
| 1128 |
_ptDA->nnz(), _ptDA->getCoef()); |
| 1129 |
_dissectionQueue[m]->generate_queue_fwbw(_dissectionMatrix[m], |
| 1130 |
_ptDA->dimension(), |
| 1131 |
_ptDA->nnz(), _ptDA->getCoef()); |
| 1132 |
_tridiagQueue[m] = new TridiagQueue<T, U>(false, _verbose, _fp); |
| 1133 |
} // if (flag_dissection) |
| 1134 |
else { |
| 1135 |
diss_printf(_verbose, _fp, |
| 1136 |
"%s %d : TridiagSolver : m = %d count = %d\n", |
| 1137 |
__FILE__, __LINE__, m, count); |
| 1138 |
const int nnz = unsym_csr->ptRows[count]; |
| 1139 |
bool isMapped = ((_graph_colors > 1) || (_index_isolated.size() > 0)); |
| 1140 |
_tridiagMatrix[m] = new TridiagBlockMatrix<T, U>(count, SIZE_B1, isSym, |
| 1141 |
0, // no other Tridiag |
| 1142 |
_verbose, _fp); |
| 1143 |
_tridiagQueue[m] = new TridiagQueue<T, U>(true, _verbose, _fp); |
| 1144 |
_tridiagQueue[m]->generate_queue(_tridiagMatrix[m], count, nnz, |
| 1145 |
isMapped, remap_eqn, |
| 1146 |
unsym_csr->ptRows, |
| 1147 |
unsym_csr->indCols, |
| 1148 |
unsym_csr->indVals, |
| 1149 |
_ptDA->getCoef()); |
| 1150 |
} |
| 1151 |
} // loop : m |
| 1152 |
if (unsym_csr_alloc) { |
| 1153 |
delete [] unsym_csr->ptRows; |
| 1154 |
delete [] unsym_csr->indCols; |
| 1155 |
} |
| 1156 |
delete [] unsym_csr->indVals; |
| 1157 |
delete [] unsym_csr->indVals_unsym; // isSym == (int *)NULL |
| 1158 |
delete unsym_csr; |
| 1159 |
delete [] map_eqn; |
| 1160 |
delete [] remap_eqn; |
| 1161 |
|
| 1162 |
delete [] graph_mask; // added 01 Oct.2013 Atsushi |
| 1163 |
t1_cpu = clock(); |
| 1164 |
get_realtime(&t1_elapsed); |
| 1165 |
|
| 1166 |
for (int m = 0; m < _graph_colors; m++) { |
| 1167 |
if (_tridiagQueue[m]->tridiagSolver()) { |
| 1168 |
_tridiagQueue[m]->exec_symb_fact(); |
| 1169 |
} |
| 1170 |
else { |
| 1171 |
_dissectionQueue[m]->exec_symb_fact(); |
| 1172 |
} |
| 1173 |
} |
| 1174 |
|
| 1175 |
_precDiag = new U[_dim]; // preparation for numerical fact. |
| 1176 |
|
| 1177 |
_Schur = new SchurMatrix<T>[_graph_colors]; |
| 1178 |
_kernel = new KernelMatrix<T>[_graph_colors]; |
| 1179 |
_singIdx = new vector<int>[_graph_colors]; |
| 1180 |
_status_factorized = false; |
| 1181 |
t2_cpu = clock(); |
| 1182 |
get_realtime(&t2_elapsed); |
| 1183 |
diss_printf(_verbose, _fp, |
| 1184 |
"graph paritioner. : cpu time = %.4e elapsed time = %.4e\n", |
| 1185 |
(double)(t1_cpu - t0_cpu) / (double)CLOCKS_PER_SEC, |
| 1186 |
convert_time(t1_elapsed, t0_elapsed)); |
| 1187 |
|
| 1188 |
diss_printf(_verbose, _fp, |
| 1189 |
"queue symb. fact. : cpu time = %.4e elapsed time = %.4e\n", |
| 1190 |
(double)(t2_cpu - t1_cpu) / (double)CLOCKS_PER_SEC, |
| 1191 |
convert_time(t2_elapsed, t1_elapsed)); |
| 1192 |
} |
| 1193 |
|
| 1194 |
|
| 1195 |
template<typename T, typename U, typename W, typename Z> |
| 1196 |
void DissectionSolver<T, U, W, Z>:: |
| 1197 |
NumericFact(const int called, |
| 1198 |
T *coefs, |
| 1199 |
const int scaling, |
| 1200 |
const double eps_pivot, |
| 1201 |
const bool kernel_detection_all, |
| 1202 |
const int dim_augkern, |
| 1203 |
const double machine_eps_, |
| 1204 |
const bool assume_invertible, |
| 1205 |
const bool higher_precision) |
| 1206 |
{ |
| 1207 |
clock_t t0_cpu, t1_cpu, t2_cpu, t3_cpu; |
| 1208 |
elapsed_t t0_elapsed, t1_elapsed, t2_elapsed, t3_elapsed; |
| 1209 |
const U eps_machine = machine_eps_ < 0.0 ? machine_epsilon<U, Z>() : U(machine_eps_); |
| 1210 |
t0_cpu = clock(); |
| 1211 |
_assume_invertible = assume_invertible; |
| 1212 |
_dim_augkern = dim_augkern; |
| 1213 |
get_realtime(&t0_elapsed); |
| 1214 |
|
| 1215 |
diss_printf(_verbose, _fp, "%s %d : eps_machine = %s scaling = %d\n", |
| 1216 |
__FILE__, __LINE__, |
| 1217 |
tostring<U>(eps_machine).c_str(), scaling); |
| 1218 |
|
| 1219 |
_scaling = scaling; |
| 1220 |
|
| 1221 |
// _ptDA->normalize(_scaling, coefs, _precDiag); |
| 1222 |
normalize<T, U>(_scaling, coefs, _ptDA, _precDiag); |
| 1223 |
t1_cpu = clock(); |
| 1224 |
get_realtime(&t1_elapsed); |
| 1225 |
for (int m = 0; m < _graph_colors; m++) { |
| 1226 |
if (_tridiagQueue[m]->tridiagSolver()) { |
| 1227 |
_tridiagQueue[m]->exec_num_fact(called, |
| 1228 |
eps_pivot, |
| 1229 |
true, // matrix will not be decomposed |
| 1230 |
dim_augkern, |
| 1231 |
eps_machine, |
| 1232 |
higher_precision); |
| 1233 |
} |
| 1234 |
else { |
| 1235 |
_dissectionQueue[m]->exec_num_fact(called, |
| 1236 |
eps_pivot, |
| 1237 |
kernel_detection_all, |
| 1238 |
dim_augkern, |
| 1239 |
eps_machine, |
| 1240 |
higher_precision); |
| 1241 |
} |
| 1242 |
} |
| 1243 |
t2_cpu = clock(); |
| 1244 |
get_realtime(&t2_elapsed); |
| 1245 |
|
| 1246 |
// dense {0 [1 2] [3 4 5 6] .... } + sparse {[2^(_nbLevels-1)-1... ]} |
| 1247 |
int sz_total = 0; |
| 1248 |
VectorArray<T> work(_dim); |
| 1249 |
for (int m = 0; m < _graph_colors; m++) { |
| 1250 |
if (_tridiagQueue[m]->tridiagSolver()) { |
| 1251 |
const int nrow = _tridiagMatrix[m]->nrow(); |
| 1252 |
const int nn0 = nrow - _tridiagMatrix[m]->rank(); |
| 1253 |
if (nn0 > 0) { |
| 1254 |
_tridiagMatrix[m]->SingularNode(_kernel[m].getKernListEq()); |
| 1255 |
// _ptDA_kern_list_eq[m]); |
| 1256 |
_kernel[m].set_dimension(nn0); |
| 1257 |
_kernel[m].getKernProj().init(nn0); |
| 1258 |
//_ptDA_kern_proj[m].init(nn0); |
| 1259 |
_tridiagMatrix[m]->KernelBasis(false, _kernel[m].getKernBasis()); |
| 1260 |
//_ptDA_kern_basis[m]); // isTrans |
| 1261 |
if (_tridiagQueue[m]->isMapped()) { |
| 1262 |
int *remap_eqn = _tridiagQueue[m]->remap_eqn(); |
| 1263 |
ColumnMatrix<T> kernel_tmp; |
| 1264 |
kernel_tmp.init(_dim, nn0); |
| 1265 |
for (int n = 0; n < nn0; n++) { |
| 1266 |
for (int i = 0; i < _dim; i++) { |
| 1267 |
kernel_tmp(i, n) = _zero; |
| 1268 |
} |
| 1269 |
for (int i = 0; i < nrow; i++) { |
| 1270 |
kernel_tmp(remap_eqn[i], n) = _kernel[m].getKernBasis()(i, n); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
_kernel[m].getKernBasis().free(); |
| 1274 |
_kernel[m].getKernBasis().init(_dim, nn0); |
| 1275 |
for (int n = 0; n < nn0; n++) { |
| 1276 |
for (int i = 0; i < _dim; i++) { |
| 1277 |
_kernel[m].getKernBasis()(i, n) = kernel_tmp(i, n); |
| 1278 |
} |
| 1279 |
} |
| 1280 |
kernel_tmp.free(); |
| 1281 |
} // if (_tridiagQueue[m]->isMapped()) |
| 1282 |
T *kern_basis = _kernel[m].getKernBasis().addrCoefs(); |
| 1283 |
//_ptDA_kern_basis[m].addrCoefs(); |
| 1284 |
diss_printf(_verbose, _fp, |
| 1285 |
"%s %d : residual of kernel vertors : %d\n", |
| 1286 |
__FILE__, __LINE__, nn0); |
| 1287 |
for (int i = 0; i < nn0; i++) { |
| 1288 |
_ptDA->prod((kern_basis + (i * _dim)), work.addrCoefs()); |
| 1289 |
U stmp = blas_l2norm<T, U>(_dim, work.addrCoefs(), 1); |
| 1290 |
diss_printf(_verbose, _fp, "%d %s\n", i, tostring<U>(stmp).c_str()); |
| 1291 |
} |
| 1292 |
if(_scaling) { |
| 1293 |
for (int j = 0; j < nn0; j++) { |
| 1294 |
const int jtmp = j * _dim; |
| 1295 |
for (int i = 0; i < _dim; i++) { |
| 1296 |
kern_basis[i + jtmp] *= _precDiag[i]; |
| 1297 |
} |
| 1298 |
} |
| 1299 |
} |
| 1300 |
_kernel[m].getTKernBasis().init(_dim, nn0); |
| 1301 |
|
| 1302 |
// normalize each kernel_basis |
| 1303 |
for (int j = 0; j < nn0; j++) { |
| 1304 |
U stmp(0.0); |
| 1305 |
U one(1.0); |
| 1306 |
stmp = blas_l2norm<T, U>(_dim, kern_basis + (j * _dim), 1); |
| 1307 |
stmp = one / stmp; |
| 1308 |
blas_scal2<T, U>(_dim, stmp, (kern_basis + (j * _dim)), 1); |
| 1309 |
} |
| 1310 |
|
| 1311 |
for (int i = 0; i < nn0; i++) { |
| 1312 |
for(int j = i; j < nn0; j++) { |
| 1313 |
// _ptDA_kern_proj[m](i, j) = |
| 1314 |
_kernel[m].getKernProj()(i,j) = |
| 1315 |
blas_dot<T>(_dim, |
| 1316 |
(kern_basis + (i * _dim)), 1, |
| 1317 |
(kern_basis + (j * _dim)), 1); |
| 1318 |
} |
| 1319 |
// symmetrize |
| 1320 |
for (int j = (i + 1); j < nn0; j++) { |
| 1321 |
_kernel[m].getKernProj()(j,i) = _kernel[m].getKernProj()(i,j); |
| 1322 |
// _ptDA_kern_proj[m](j, i) = _ptDA_kern_proj[m](i, j); |
| 1323 |
} |
| 1324 |
} |
| 1325 |
full_ldlh<T>(nn0, _kernel[m].getKernProj().addrCoefs(), nn0); |
| 1326 |
if (!_tridiagMatrix[m]->isSym()) { |
| 1327 |
T *kernt_basis = _kernel[m].getTKernBasis().addrCoefs(); |
| 1328 |
_tridiagMatrix[m]->KernelBasis(true, _kernel[m].getTKernBasis()); |
| 1329 |
if (_tridiagQueue[m]->isMapped()) { |
| 1330 |
int *remap_eqn = _tridiagQueue[m]->remap_eqn(); |
| 1331 |
ColumnMatrix<T> kernel_tmp; |
| 1332 |
kernel_tmp.init(_dim, nn0); |
| 1333 |
for (int n = 0; n < nn0; n++) { |
| 1334 |
for (int i = 0; i < _dim; i++) { |
| 1335 |
kernel_tmp(i, n) = _zero; |
| 1336 |
} |
| 1337 |
for (int i = 0; i < nrow; i++) { |
| 1338 |
kernel_tmp(remap_eqn[i], n) = _kernel[m].getTKernBasis()(i, n); |
| 1339 |
} |
| 1340 |
} |
| 1341 |
_kernel[m].getTKernBasis().free(); |
| 1342 |
_kernel[m].getTKernBasis().init(_dim, nn0); |
| 1343 |
for (int n = 0; n < nn0; n++) { |
| 1344 |
for (int i = 0; i < _dim; i++) { |
| 1345 |
_kernel[m].getTKernBasis()(i, n) = kernel_tmp(i, n); |
| 1346 |
} |
| 1347 |
} |
| 1348 |
kernel_tmp.free(); |
| 1349 |
} // if (_tridiagQueue[m]->isMapped()) |
| 1350 |
diss_printf(_verbose, _fp, |
| 1351 |
"%s %d : residual of transposed kernel vertors : %d\n", |
| 1352 |
__FILE__, __LINE__, nn0); |
| 1353 |
for (int i = 0; i < nn0; i++) { |
| 1354 |
_ptDA->prodt((kernt_basis + (i * _dim)), work.addrCoefs()); |
| 1355 |
U stmp = blas_l2norm<T, U>(_dim, work.addrCoefs(), 1); |
| 1356 |
diss_printf(_verbose, _fp, "%d %s\n", i, tostring<U>(stmp).c_str()); |
| 1357 |
} |
| 1358 |
if(_scaling) { |
| 1359 |
for (int j = 0; j < nn0; j++) { |
| 1360 |
const int jtmp = j * _dim; |
| 1361 |
for (int i = 0; i < _dim; i++) { |
| 1362 |
kernt_basis[i + jtmp] *= _precDiag[i]; |
| 1363 |
} |
| 1364 |
} |
| 1365 |
} |
| 1366 |
} // if (!_tridiagMatrix[m]->isSym()) |
| 1367 |
} // if (nn0 > 0) |
| 1368 |
else { |
| 1369 |
_kernel[m].set_dimension(0); |
| 1370 |
_kernel[m].getKernProj().init(0); |
| 1371 |
// _ptDA_kern_proj[m].init(0); // = new SquareMatrix<double>(); |
| 1372 |
_kernel[m].getKernBasis().init(0, 0); // = new ColumnMatrix<double>(); |
| 1373 |
_kernel[m].getKernListEq().clear(); |
| 1374 |
_kernel[m].getKernListEqLeft().clear(); |
| 1375 |
} |
| 1376 |
_singIdx[m].resize(0); |
| 1377 |
_Schur[m].getAcol() = new SparseMatrix<T>(); // dummy allocation |
| 1378 |
_Schur[m].getArow() = new SparseMatrix<T>(); // dummy allocation |
| 1379 |
// if (_status_factorized) { // for safty of second call |
| 1380 |
_Schur[m].getSlduList().clear(); // |
| 1381 |
_Schur[m].getSlduListLeft().clear(); // |
| 1382 |
_Schur[m].getSldu().free(); |
| 1383 |
} // if (_tridiagQueue[m]->tridiagSolver()) |
| 1384 |
else { |
| 1385 |
int sz = 0, sz1 = 0; |
| 1386 |
bool kernel_detected = true; |
| 1387 |
vector<int> kernel_found; |
| 1388 |
// int id_dom = 1; |
| 1389 |
for (int j = 0; j < _dissectionMatrix[m].size(); j++ ) { |
| 1390 |
vector<int>& singIdx = _dissectionMatrix[m][j]->singIdxPermute(); |
| 1391 |
if (singIdx.size() > 0) { |
| 1392 |
diss_printf(_verbose, _fp, |
| 1393 |
"%s %d : ", __FILE__, __LINE__); |
| 1394 |
diss_printf(_verbose, _fp, |
| 1395 |
"%d : %s : %d :: %d [ ", (j + 1), // selfIndex() == j |
| 1396 |
_dissectionMatrix[m][j]->KernelDetected() ? "true" : "false", |
| 1397 |
_dissectionMatrix[m][j]->nrow(), |
| 1398 |
(int)singIdx.size()); |
| 1399 |
vector<int>::const_iterator it = singIdx.begin(); |
| 1400 |
for ( ;it != singIdx.end(); ++it) { |
| 1401 |
diss_printf(_verbose, _fp, "%d ", *it); |
| 1402 |
} |
| 1403 |
diss_printf(_verbose, _fp, "]\n"); |
| 1404 |
} // if (singIdx.size() > 0) |
| 1405 |
if (singIdx.size() > 0) { |
| 1406 |
// id_dom = j + 1; |
| 1407 |
kernel_found.push_back(j); |
| 1408 |
sz += singIdx.size(); |
| 1409 |
if (!_dissectionMatrix[m][j]->KernelDetected()) { |
| 1410 |
//if (true) { // 29 Oct.2014 debug |
| 1411 |
sz1 += singIdx.size(); |
| 1412 |
diss_printf(_verbose, _fp, |
| 1413 |
"%s %d : ", __FILE__, __LINE__); |
| 1414 |
diss_printf(_verbose, _fp, "domain %d kernel is not detected\n", j); |
| 1415 |
kernel_detected = false; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
} // loop : j |
| 1419 |
sz_total += sz; |
| 1420 |
if (sz > 0) { |
| 1421 |
if (kernel_detected && (!_assume_invertible)) { |
| 1422 |
_singIdx[m].resize(sz); |
| 1423 |
int k = 0; |
| 1424 |
for (int j = 0; j < _dissectionMatrix[m].size(); j++ ) { |
| 1425 |
const int *loc2glob = _btree[m]->getDiagLoc2Glob(j + 1); |
| 1426 |
for (vector<int>::const_iterator it = |
| 1427 |
_dissectionMatrix[m][j]->singIdxPermute().begin(); |
| 1428 |
it != _dissectionMatrix[m][j]->singIdxPermute().end(); |
| 1429 |
++it, k++) { |
| 1430 |
_singIdx[m][k] = loc2glob[*it]; |
| 1431 |
} // loop : d |
| 1432 |
} |
| 1433 |
#if 0 |
| 1434 |
if (_verbose) { |
| 1435 |
std::sort(_singIdx[m].begin(), _singIdx[m].end()); |
| 1436 |
char fname[256]; |
| 1437 |
FILE *fp; |
| 1438 |
int pid = get_process_id(); |
| 1439 |
sprintf(fname, "singularindex.%06d.data", pid); |
| 1440 |
if ((fp = fopen(fname, "w")) != NULL) { |
| 1441 |
fprintf(fp, "# %d \n", (int)_singIdx[m].size()); |
| 1442 |
for (int i = 0; i < _singIdx[m].size(); i++) { |
| 1443 |
fprintf(fp, "%d\n", _singIdx[m][i]); |
| 1444 |
} |
| 1445 |
fclose(fp); |
| 1446 |
} |
| 1447 |
else { |
| 1448 |
fprintf(stderr, |
| 1449 |
"%s %d : fail to open %s\n", |
| 1450 |
__FILE__, __LINE__, fname); |
| 1451 |
exit(-1); |
| 1452 |
} |
| 1453 |
} // if (_verbose) |
| 1454 |
|
| 1455 |
BuildKernels(_singIdx[m], |
| 1456 |
sz, |
| 1457 |
_Schur[m], _kernel[m]); |
| 1458 |
#else |
| 1459 |
vector<SquareBlockMatrix<T>* > diags; // dummy |
| 1460 |
vector<vector<int> >augkern_indexes; // dummy |
| 1461 |
|
| 1462 |
BuildKernelsDetection(sz, |
| 1463 |
_singIdx[m], |
| 1464 |
augkern_indexes, |
| 1465 |
diags, |
| 1466 |
eps_pivot, |
| 1467 |
dim_augkern, |
| 1468 |
_Schur[m], |
| 1469 |
_kernel[m], false); |
| 1470 |
#endif |
| 1471 |
// need to copy kern basis projection matrix from global to m-th array |
| 1472 |
} // if (kernel_detected) |
| 1473 |
else { |
| 1474 |
diss_printf(_verbose, _fp, |
| 1475 |
"%s %d : candidates of null pivots = %d, to be fixed\n", |
| 1476 |
__FILE__, __LINE__, sz); |
| 1477 |
_singIdx[m].resize(sz + dim_augkern); //= vector<int> |
| 1478 |
int k = 0; |
| 1479 |
for (int d = 1; d <= _btree[m]->NumberOfSubdomains(); d++) { |
| 1480 |
const int j = _btree[m]->selfIndex(d); |
| 1481 |
if (_dissectionMatrix[m][j]->KernelDetected() && |
| 1482 |
(_dissectionMatrix[m][j]->diagBlock().dim_kern() > 0)) { |
| 1483 |
_dissectionMatrix[m][j]->diagBlock().set_KernelDetected(false); |
| 1484 |
} |
| 1485 |
const int *loc2glob = _btree[m]->getDiagLoc2Glob(d); |
| 1486 |
for (vector<int>::const_iterator it = |
| 1487 |
_dissectionMatrix[m][j]->singIdxPermute().begin(); |
| 1488 |
it != _dissectionMatrix[m][j]->singIdxPermute().end(); |
| 1489 |
++it, k++) { |
| 1490 |
_singIdx[m][k] = loc2glob[*it]; |
| 1491 |
} |
| 1492 |
} // loop : d |
| 1493 |
// selecting dim_augkern indices for comparison in the kernel detection |
| 1494 |
diss_printf(_verbose, _fp, |
| 1495 |
"%s %d : size = %d : ", __FILE__, __LINE__, |
| 1496 |
(int)_singIdx[m].size()); |
| 1497 |
for (int i = 0; i < _singIdx[m].size(); i++) { |
| 1498 |
diss_printf(_verbose, _fp, "%d ", _singIdx[m][i]); |
| 1499 |
} |
| 1500 |
diss_printf(_verbose, _fp, "\n"); |
| 1501 |
vector<SquareBlockMatrix<T>* > diags; |
| 1502 |
vector<vector<int> >augkern_indexes; |
| 1503 |
int nn = 1; // level of dense part with 1 indexing |
| 1504 |
k = 0; |
| 1505 |
while (nn <= dim_augkern) { |
| 1506 |
SquareBlockMatrix<T>* diag = |
| 1507 |
&_dissectionMatrix[m][_btree[m]->selfIndex(nn)]->diagBlock(); |
| 1508 |
const int *loc2glob = _btree[m]->getDiagLoc2Glob(nn); |
| 1509 |
vector<int> &permute = diag->getPermute(); |
| 1510 |
vector<int> augkern_index; |
| 1511 |
// augkern_index.resize(dim_augkern); |
| 1512 |
int n = diag->dimension() - 1; //diag.dimension() == permute.size() |
| 1513 |
int k0 = 0; |
| 1514 |
while ((k < dim_augkern) && (n >= 0)) { |
| 1515 |
const int itmp = loc2glob[permute[n]]; |
| 1516 |
bool flag = true; |
| 1517 |
for (int i = 0; i < sz; i++) { |
| 1518 |
if(_singIdx[m][i] == itmp) { |
| 1519 |
flag = false; |
| 1520 |
break; |
| 1521 |
} |
| 1522 |
} |
| 1523 |
if (flag) { |
| 1524 |
_singIdx[m][sz + k0] = itmp; |
| 1525 |
augkern_index.push_back(n); |
| 1526 |
k0++; |
| 1527 |
k++; |
| 1528 |
} |
| 1529 |
n--; |
| 1530 |
} // while |
| 1531 |
diags.push_back(diag); |
| 1532 |
augkern_indexes.push_back(augkern_index); |
| 1533 |
if (k == dim_augkern) { |
| 1534 |
break; |
| 1535 |
} |
| 1536 |
nn++; // |
| 1537 |
} // while (nn <= dim_augkern) |
| 1538 |
diss_printf(_verbose, _fp, |
| 1539 |
"%s %d : adding local node using %d diag matrices ", |
| 1540 |
__FILE__, __LINE__, (int)augkern_indexes.size()); |
| 1541 |
for (vector<vector<int> >::const_iterator it = augkern_indexes.begin(); |
| 1542 |
it != augkern_indexes.end(); ++it) { |
| 1543 |
for (vector<int>::const_iterator jt = (*it).begin(); |
| 1544 |
jt != (*it).end(); |
| 1545 |
++jt) { |
| 1546 |
diss_printf(_verbose, _fp, "%d ", (*jt)); |
| 1547 |
} |
| 1548 |
} |
| 1549 |
diss_printf(_verbose, _fp, "to the last level.\n"); |
| 1550 |
diss_printf(_verbose, _fp, |
| 1551 |
"%s %d : singIdx = %d : ", |
| 1552 |
__FILE__, __LINE__, (int)_singIdx[m].size()); |
| 1553 |
for (int i = 0; i < _singIdx[m].size(); i++) { |
| 1554 |
diss_printf(_verbose, _fp, "%d ", _singIdx[m][i]); |
| 1555 |
} |
| 1556 |
diss_printf(_verbose, _fp, "\n"); |
| 1557 |
std::sort(_singIdx[m].begin(), _singIdx[m].end()); |
| 1558 |
diss_printf(_verbose, _fp, |
| 1559 |
"%s %d : singIdx sorted = %d : ", |
| 1560 |
__FILE__, __LINE__, (int)_singIdx[m].size()); |
| 1561 |
for (int i = 0; i < _singIdx[m].size(); i++) { |
| 1562 |
diss_printf(_verbose,_fp, "%d ", _singIdx[m][i]); |
| 1563 |
} |
| 1564 |
diss_printf(_verbose, _fp, "\n"); |
| 1565 |
int kern_dim = 0; |
| 1566 |
BuildKernelsDetection(kern_dim, |
| 1567 |
_singIdx[m], |
| 1568 |
augkern_indexes, |
| 1569 |
diags, |
| 1570 |
eps_pivot, |
| 1571 |
dim_augkern, |
| 1572 |
_Schur[m], |
| 1573 |
_kernel[m], |
| 1574 |
true); |
| 1575 |
if (kern_dim == (-1)) { |
| 1576 |
int pid = get_process_id(); |
| 1577 |
SaveCSRMatrix(_called, coefs); |
| 1578 |
fprintf(stderr, |
| 1579 |
"%s %d : DissectionSolver CSR matrix dumped : %d %d\n", |
| 1580 |
__FILE__, __LINE__, _called, pid); |
| 1581 |
exit(-1); |
| 1582 |
} |
| 1583 |
} // if (kernel_detected) |
| 1584 |
} // if (sz > 0) |
| 1585 |
else { |
| 1586 |
_singIdx[m].resize(0); |
| 1587 |
_Schur[m].getAcol() = new SparseMatrix<T>(); // dummy allocation |
| 1588 |
_Schur[m].getArow() = new SparseMatrix<T>(); // dummy allocation |
| 1589 |
// _ptDA_arow[m] = new SparseMatrix<T, W, Z>(true); |
| 1590 |
_kernel[m].set_dimension(0); |
| 1591 |
_kernel[m].getKernProj().init(0); // _ptDA_kern_proj[m].init(0); // |
| 1592 |
_kernel[m].getKernBasis().init(0, 0); // |
| 1593 |
_kernel[m].getKernListEq().clear(); |
| 1594 |
_kernel[m].getKernListEqLeft().clear(); |
| 1595 |
// if (_status_factorized) { // for safty of second call |
| 1596 |
_Schur[m].getSlduList().clear(); // _ptDA_sldu_list[m].clear(); |
| 1597 |
_Schur[m].getSlduListLeft().clear(); // _ptDA_sldu_list[m].clear(); |
| 1598 |
_Schur[m].getSldu().free(); // _ptDA_sldu[m].free(); |
| 1599 |
} |
| 1600 |
} // if (_tridiagQueue[m]->tridiagSolver()) |
| 1601 |
} // loop : _graph_colors |
| 1602 |
work.free(); |
| 1603 |
{ |
| 1604 |
int itmp = 0; |
| 1605 |
for (int m = 0; m < _graph_colors; m++) { |
| 1606 |
itmp += _singIdx[m].size(); |
| 1607 |
} |
| 1608 |
_nsing = itmp; // keep total dimension of kernel of singluar blocks |
| 1609 |
} |
| 1610 |
t3_cpu = clock(); |
| 1611 |
get_realtime(&t3_elapsed); |
| 1612 |
|
| 1613 |
//clock_gettime(CLOCK_REALTIME, &ts3); |
| 1614 |
diss_printf(_verbose, _fp, |
| 1615 |
"queue num. fact. : cpu time = %.4e elapsed time = %.4e\n", |
| 1616 |
(double)(t2_cpu - t1_cpu) / (double)CLOCKS_PER_SEC, |
| 1617 |
convert_time(t2_elapsed, t1_elapsed)); |
| 1618 |
diss_printf(_verbose, _fp, |
| 1619 |
"total num. fact. : cpu time = %.4e elapsed time = %.4e\n", |
| 1620 |
(double)(t3_cpu - t0_cpu) / (double)CLOCKS_PER_SEC, |
| 1621 |
convert_time(t2_elapsed, t0_elapsed)); |
| 1622 |
diss_printf(_verbose, _fp, |
| 1623 |
"scaling matrix : cpu time = %.4e elapsed time = %.4e\n", |
| 1624 |
(double)(t1_cpu - t0_cpu) / (double)CLOCKS_PER_SEC, |
| 1625 |
convert_time(t1_elapsed, t0_elapsed)); |
| 1626 |
if (sz_total > 0) { |
| 1627 |
diss_printf(_verbose, _fp, |
| 1628 |
"kernel vec. gen : cpu time = %.4e elapsed time = %.4e\n", |
| 1629 |
(double)(t3_cpu - t2_cpu) / (double)CLOCKS_PER_SEC, |
| 1630 |
convert_time(t3_elapsed, t2_elapsed)); |
| 1631 |
} // (sz_total > 0) { |
| 1632 |
// check error |
| 1633 |
// this should be a function with specialized template |
| 1634 |
if (_verbose) { |
| 1635 |
int count = 0; |
| 1636 |
for (int m = 0; m < _graph_colors; m++) { |
| 1637 |
diss_printf(_verbose, _fp, |
| 1638 |
"%s %d :negative diagnol entries : color = %d\n", |
| 1639 |
__FILE__, __LINE__, m); |
| 1640 |
if (_tridiagQueue[m]->tridiagSolver()) { |
| 1641 |
int count0; |
| 1642 |
count0 = _tridiagMatrix[m]->NumNegativeDiags(); |
| 1643 |
if (count0 > 0) { |
| 1644 |
diss_printf(_verbose, _fp, |
| 1645 |
"%d / %d\n", count0, _tridiagMatrix[m]->nrow()); |
| 1646 |
} |
| 1647 |
count += count0; |
| 1648 |
} |
| 1649 |
else { |
| 1650 |
int level; |
| 1651 |
level = (_btree[m]->NumberOfLevels() - 1); |
| 1652 |
const unsigned begdom = 1U << level; |
| 1653 |
const unsigned enddom = begdom * 2; |
| 1654 |
|
| 1655 |
for (int d = begdom; d < enddom; d++) { |
| 1656 |
const int d0 = _btree[m]->selfIndex(d); |
| 1657 |
// const void *diagsparse = _dissectionMatrix[m][d0]->diagSparse(); |
| 1658 |
TridiagBlockMatrix<T, U> **tridiag = _dissectionMatrix[m][d0]->addrtridiagBlock(); |
| 1659 |
int colors = _dissectionMatrix[m][d0]->ColorTridiagBlockMatrix(); |
| 1660 |
int count0 = 0; |
| 1661 |
for (int i = 0; i < colors; i++) { |
| 1662 |
count0 += tridiag[i]->NumNegativeDiags(); |
| 1663 |
} |
| 1664 |
if (count0 > 0) { |
| 1665 |
diss_printf(_verbose, _fp, "%d : %d / %d\n", |
| 1666 |
d0, count0, _dissectionMatrix[m][d0]->nrow()); |
| 1667 |
} |
| 1668 |
count += count0; |
| 1669 |
} |
| 1670 |
for (int level = (_btree[m]->NumberOfLevels() - 2); level >= 0; level--) { |
| 1671 |
const unsigned begdom = 1U << level; |
| 1672 |
const unsigned enddom = begdom * 2; |
| 1673 |
|
| 1674 |
for (int d = begdom; d < enddom; d++) { |
| 1675 |
const int d0 = _btree[m]->selfIndex(d); |
| 1676 |
int count0; |
| 1677 |
SquareBlockMatrix<T>& diag = _dissectionMatrix[m][d0]->diagBlock(); |
| 1678 |
count0 = count_diag_negative<T>(diag); |
| 1679 |
if (count0 > 0) { |
| 1680 |
diss_printf(_verbose, _fp, "%d : %d / %d\n", |
| 1681 |
d0, count0, _dissectionMatrix[m][d0]->nrow()); |
| 1682 |
} |
| 1683 |
count += count0; |
| 1684 |
} |
| 1685 |
} |
| 1686 |
} // (_tridiagQueue[m]->tridiagSolver()) { |
| 1687 |
{ |
| 1688 |
int count0; |
| 1689 |
SubSquareMatrix<T>& diag = _Schur[m].getSldu(); |
| 1690 |
count0 = count_diag_negative<T>(diag); |
| 1691 |
if (count0 > 0) { |
| 1692 |
diss_printf(_verbose, _fp, |
| 1693 |
"-1 : %d / %d\n", count0, diag.dimension()); |
| 1694 |
} |
| 1695 |
count += count0; |
| 1696 |
} |
| 1697 |
} // loop : m |
| 1698 |
if (count > 0) { |
| 1699 |
diss_printf(_verbose, _fp, |
| 1700 |
"%s %d :negative diagonal entries = %d / %d\n", |
| 1701 |
__FILE__, __LINE__, count, _dim); |
| 1702 |
} |
| 1703 |
} // if (_verbose) |
| 1704 |
// |
| 1705 |
bool kernel_flag = false; |
| 1706 |
for (int m = 0; m < _graph_colors; m++) { |
| 1707 |
if (_kernel[m].dimension() != 0) { |
| 1708 |
kernel_flag = true; |
| 1709 |
break; |
| 1710 |
} |
| 1711 |
} |
| 1712 |
#if 0 |
| 1713 |
if (kernel_flag && (!_ptDA->isSymmetric())) { |
| 1714 |
ComputeTransposedKernels(); |
| 1715 |
} |
| 1716 |
#endif |
| 1717 |
if(_verbose) { |
| 1718 |
int n1 = 0; |
| 1719 |
for (int m = 0; m < _graph_colors; m++) { |
| 1720 |
n1 += _Schur[m].getSlduList().size(); |
| 1721 |
} |
| 1722 |
VectorArray<T> xx(_dim); |
| 1723 |
VectorArray<T> yy(_dim); |
| 1724 |
VectorArray<T> ww(_dim); |
| 1725 |
for (int i = 0; i < _dim; i++) { |
| 1726 |
ww[i] = T(2.0 * ((double)rand() / (double)RAND_MAX) - 1.0); |
| 1727 |
// ww[i] = T((double)(i % 11)); |
| 1728 |
} |
| 1729 |
VectorArray<T> bb(_dim); |
| 1730 |
bb.ZeroClear(); |
| 1731 |
diss_printf(_verbose, _fp, "%s %d : compute error in (Ker A)^\\perp\n", |
| 1732 |
__FILE__, __LINE__); |
| 1733 |
SpMV(ww.addrCoefs(), xx.addrCoefs(), true); // isScaling = true |
| 1734 |
if (kernel_flag) { |
| 1735 |
ProjectionKernelOrthSingle(xx.addrCoefs(), "creating solution", false); |
| 1736 |
} |
| 1737 |
SpMV(xx.addrCoefs(), bb.addrCoefs(), true); // isScaling = true |
| 1738 |
if (kernel_flag) { |
| 1739 |
ProjectionKernelOrthSingle(bb.addrCoefs(), "RHS", true); |
| 1740 |
// ProjectionImageSingle(bb.addrCoefs(), "RHS", false); |
| 1741 |
} |
| 1742 |
blas_copy<T>(_dim, bb.addrCoefs(), 1, yy.addrCoefs(), 1); |
| 1743 |
SolveSingle(yy.addrCoefs(), false, false, true); // isScaling = true |
| 1744 |
if (kernel_flag) { |
| 1745 |
ProjectionKernelOrthSingle(yy.addrCoefs(), "computed solution", false); |
| 1746 |
} |
| 1747 |
SpMV(yy.addrCoefs(), ww.addrCoefs(), true); |
| 1748 |
U norm0, norm1; |
| 1749 |
norm0 = blas_l2norm<T, U>(_dim, xx.addrCoefs(), 1); |
| 1750 |
blas_axpy<T>(_dim, _none, xx.addrCoefs(), 1, yy.addrCoefs(), 1); |
| 1751 |
norm1 = blas_l2norm<T, U>(_dim, yy.addrCoefs(), 1); |
| 1752 |
diss_printf(_verbose, _fp, "%s %d : error = %s / %s = %s\n", |
| 1753 |
__FILE__, __LINE__, |
| 1754 |
tostring<U>(norm1).c_str(), tostring<U>(norm0).c_str(), |
| 1755 |
tostring<U>(norm1 / norm0).c_str()); |
| 1756 |
if (todouble<U>(norm1 / norm0) > 1.0e-5) { |
| 1757 |
int pid = get_process_id(); |
| 1758 |
int nnz = _ptDA->nnz(); |
| 1759 |
diss_printf(_verbose, stderr, "%s %d : too large error = %s / %s = %s\n", |
| 1760 |
__FILE__, __LINE__, |
| 1761 |
tostring<U>(norm1).c_str(), tostring<U>(norm0).c_str(), |
| 1762 |
tostring<U>(norm1 / norm0).c_str()); |
| 1763 |
// SaveMMMatrix(_called, coefs); |
| 1764 |
// _status_factorized = false; |
| 1765 |
// return; |
| 1766 |
} |
| 1767 |
norm0 = blas_l2norm<T, U>(_dim, bb.addrCoefs(), 1); |
| 1768 |
blas_axpy<T>(_dim, _none, bb.addrCoefs(), 1, ww.addrCoefs(), 1); |
| 1769 |
norm1 = blas_l2norm<T, U>(_dim, ww.addrCoefs(), 1); |
| 1770 |
diss_printf(_verbose, _fp, "%s %d : residual = %s / %s = %s\n", |
| 1771 |
__FILE__, __LINE__, |
| 1772 |
tostring<U>(norm1).c_str(), tostring<U>(norm0).c_str(), |
| 1773 |
tostring<U>(norm1 / norm0).c_str()); |
| 1774 |
|
| 1775 |
} // if (_verbose) |
| 1776 |
_status_factorized = true; |
| 1777 |
} |
| 1778 |
|
| 1779 |
template |
| 1780 |
void DissectionSolver<double>::NumericFact(const int called, |
| 1781 |
double *coefs, |
| 1782 |
const int scaling, |
| 1783 |
const double eps_pivot, |
| 1784 |
const bool kernel_detection_all, |
| 1785 |
const int dim_augkern, |
| 1786 |
const double machine_eps_, |
| 1787 |
const bool assume_invertible, |
| 1788 |
const bool higher_precision); |
| 1789 |
|
| 1790 |
template |
| 1791 |
void DissectionSolver<complex<double>, double>:: |
| 1792 |
NumericFact(const int called, |
| 1793 |
complex<double> *coefs, |
| 1794 |
const int scaling, |
| 1795 |
const double eps_pivot, |
| 1796 |
const bool kernel_detection_all, |
| 1797 |
const int dim_augkern, |
| 1798 |
const double machine_eps_, |
| 1799 |
const bool assume_invertible, |
| 1800 |
const bool higher_precision); |
| 1801 |
|
| 1802 |
template |
| 1803 |
void DissectionSolver<quadruple>::NumericFact(const int called, |
| 1804 |
quadruple *coefs, |
| 1805 |
const int scaling, |
| 1806 |
const double eps_pivot, |
| 1807 |
const bool kernel_detection_all, |
| 1808 |
const int dim_augkern, |
| 1809 |
const double machine_eps_, |
| 1810 |
const bool assume_invertible, |
| 1811 |
const bool higher_precision); |
| 1812 |
template |
| 1813 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 1814 |
NumericFact(const int called, |
| 1815 |
complex<quadruple> *coefs, |
| 1816 |
const int scaling, |
| 1817 |
const double eps_pivot, |
| 1818 |
const bool kernel_detection_all, |
| 1819 |
const int dim_augkern, |
| 1820 |
const double machine_eps_, |
| 1821 |
const bool assume_invertible, |
| 1822 |
const bool higher_precision); |
| 1823 |
|
| 1824 |
template |
| 1825 |
void DissectionSolver<double, double, quadruple, quadruple>:: |
| 1826 |
NumericFact(const int called, |
| 1827 |
double *coefs, |
| 1828 |
const int scaling, |
| 1829 |
const double eps_pivot, |
| 1830 |
const bool kernel_detection_all, |
| 1831 |
const int dim_augkern, |
| 1832 |
const double machine_eps_, |
| 1833 |
const bool assume_invertible, |
| 1834 |
const bool higher_precision); |
| 1835 |
|
| 1836 |
template |
| 1837 |
void DissectionSolver<complex<double>, double, complex<quadruple>, quadruple>:: |
| 1838 |
NumericFact(const int called, |
| 1839 |
complex<double> *coefs, |
| 1840 |
const int scaling, |
| 1841 |
const double eps_pivot, |
| 1842 |
const bool kernel_detection_all, |
| 1843 |
const int dim_augkern, |
| 1844 |
const double machine_eps_, |
| 1845 |
const bool assume_invertible, |
| 1846 |
const bool higher_precision); |
| 1847 |
|
| 1848 |
template |
| 1849 |
void DissectionSolver<quadruple, quadruple, double, double>:: |
| 1850 |
NumericFact(const int called, |
| 1851 |
quadruple *coefs, |
| 1852 |
const int scaling, |
| 1853 |
const double eps_pivot, |
| 1854 |
const bool kernel_detection_all, |
| 1855 |
const int dim_augkern, |
| 1856 |
const double machine_eps_, |
| 1857 |
const bool assume_invertible, |
| 1858 |
const bool higher_precision); |
| 1859 |
template |
| 1860 |
void DissectionSolver<complex<quadruple>, quadruple, complex<double>, double>:: |
| 1861 |
NumericFact(const int called, |
| 1862 |
complex<quadruple> *coefs, |
| 1863 |
const int scaling, |
| 1864 |
const double eps_pivot, |
| 1865 |
const bool kernel_detection_all, |
| 1866 |
const int dim_augkern, |
| 1867 |
const double machine_eps_, |
| 1868 |
const bool assume_invertible, |
| 1869 |
const bool higher_precision); |
| 1870 |
|
| 1871 |
template |
| 1872 |
void DissectionSolver<float>::NumericFact(const int called, |
| 1873 |
float *coefs, |
| 1874 |
const int scaling, |
| 1875 |
const double eps_pivot, |
| 1876 |
const bool kernel_detection_all, |
| 1877 |
const int dim_augkern, |
| 1878 |
const double machine_eps_, |
| 1879 |
const bool assume_invertible, |
| 1880 |
const bool higher_precision); |
| 1881 |
template |
| 1882 |
void DissectionSolver<complex<float>, float>:: |
| 1883 |
NumericFact(const int called, |
| 1884 |
complex<float> *coefs, |
| 1885 |
const int scaling, |
| 1886 |
const double eps_pivot, |
| 1887 |
const bool kernel_detection_all, |
| 1888 |
const int dim_augkern, |
| 1889 |
const double machine_eps_, |
| 1890 |
const bool assume_invertible, |
| 1891 |
const bool higher_precision); |
| 1892 |
|
| 1893 |
// |
| 1894 |
|
| 1895 |
template<typename T, typename U, typename W, typename Z> |
| 1896 |
void DissectionSolver<T, U, W, Z>:: |
| 1897 |
GetNullPivotIndices(int *pivots) |
| 1898 |
{ |
| 1899 |
int i0 = 0; |
| 1900 |
for (int m = 0; m < _graph_colors; m++) { |
| 1901 |
const int n0 = _kernel[m].dimension(); //_ptDA_kern_proj[m].dimension(); |
| 1902 |
// should be optimized : replaced by memcopy()? |
| 1903 |
for (int i = 0; i < n0; i++, i0++) { |
| 1904 |
pivots[i0] = _kernel[m].getKernListEq()[i]; //_ptDA_kern_list_eq[m][i]; |
| 1905 |
} |
| 1906 |
} // loop : _graph_colors : m |
| 1907 |
} |
| 1908 |
|
| 1909 |
template |
| 1910 |
void DissectionSolver<double>::GetNullPivotIndices(int *pivots); |
| 1911 |
|
| 1912 |
template |
| 1913 |
void DissectionSolver<quadruple>::GetNullPivotIndices(int *pivots); |
| 1914 |
|
| 1915 |
template |
| 1916 |
void DissectionSolver<complex<double>, double>::GetNullPivotIndices(int *pivots); |
| 1917 |
|
| 1918 |
template |
| 1919 |
void DissectionSolver<complex<quadruple>, quadruple>::GetNullPivotIndices(int *pivots); |
| 1920 |
|
| 1921 |
template |
| 1922 |
void DissectionSolver<double, double, quadruple, quadruple>::GetNullPivotIndices(int *pivots); |
| 1923 |
|
| 1924 |
template |
| 1925 |
void DissectionSolver<quadruple, quadruple, double, double>::GetNullPivotIndices(int *pivots); |
| 1926 |
|
| 1927 |
template |
| 1928 |
void DissectionSolver<float>::GetNullPivotIndices(int *pivots); |
| 1929 |
|
| 1930 |
template |
| 1931 |
void DissectionSolver<complex<float>, float>::GetNullPivotIndices(int *pivots); |
| 1932 |
|
| 1933 |
template |
| 1934 |
void DissectionSolver<float, float, double, double>::GetNullPivotIndices(int *pivots); |
| 1935 |
|
| 1936 |
// |
| 1937 |
|
| 1938 |
template<typename T, typename U, typename W, typename Z> |
| 1939 |
int DissectionSolver<T, U, W, Z>:: |
| 1940 |
GetMaxColors() |
| 1941 |
{ |
| 1942 |
int nn = 0; |
| 1943 |
for (int m = 0; m < _graph_colors; m++) { |
| 1944 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 1945 |
nn++; |
| 1946 |
} |
| 1947 |
} |
| 1948 |
return nn; |
| 1949 |
} |
| 1950 |
|
| 1951 |
template |
| 1952 |
int DissectionSolver<double>::GetMaxColors(); |
| 1953 |
|
| 1954 |
template |
| 1955 |
int DissectionSolver<quadruple>::GetMaxColors(); |
| 1956 |
|
| 1957 |
template |
| 1958 |
int DissectionSolver<complex<double>, double>::GetMaxColors(); |
| 1959 |
|
| 1960 |
template |
| 1961 |
int DissectionSolver<complex<quadruple>, quadruple>::GetMaxColors(); |
| 1962 |
|
| 1963 |
template |
| 1964 |
int DissectionSolver<double, double, quadruple, quadruple>::GetMaxColors(); |
| 1965 |
|
| 1966 |
template |
| 1967 |
int DissectionSolver<quadruple, quadruple, double, double>::GetMaxColors(); |
| 1968 |
|
| 1969 |
template |
| 1970 |
int DissectionSolver<float>::GetMaxColors(); |
| 1971 |
|
| 1972 |
template |
| 1973 |
int DissectionSolver<complex<float>, float>::GetMaxColors(); |
| 1974 |
// |
| 1975 |
|
| 1976 |
template<typename T, typename U, typename W, typename Z> |
| 1977 |
void DissectionSolver<T, U, W, Z>:: |
| 1978 |
GetSmallestPivotIndices(const int n, int *pivots) |
| 1979 |
{ |
| 1980 |
int nn = 0; |
| 1981 |
for (int m = 0; m < _graph_colors; m++) { |
| 1982 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 1983 |
SquareBlockMatrix<T>* diag = |
| 1984 |
&_dissectionMatrix[m][_btree[m]->selfIndex(1)]->diagBlock(); |
| 1985 |
const int *loc2glob = _btree[m]->getDiagLoc2Glob(1); |
| 1986 |
vector<int> &permute = diag->getPermute(); |
| 1987 |
int ndiag = diag->dimension(); |
| 1988 |
if (n > ndiag) { |
| 1989 |
diss_printf(_verbose, _fp, "%s %d : GetSmallestPivotIndices %d > %d\n", |
| 1990 |
__FILE__, __LINE__, n, ndiag); |
| 1991 |
} |
| 1992 |
for (int k = (ndiag - 1); k >= (ndiag - n); k--, nn++) { |
| 1993 |
pivots[nn] = loc2glob[permute[k]]; |
| 1994 |
} |
| 1995 |
} |
| 1996 |
} // loop : m |
| 1997 |
} |
| 1998 |
|
| 1999 |
template |
| 2000 |
void DissectionSolver<double>::GetSmallestPivotIndices(const int n, |
| 2001 |
int *pivots); |
| 2002 |
|
| 2003 |
template |
| 2004 |
void DissectionSolver<quadruple>::GetSmallestPivotIndices(const int n, int *pivots); |
| 2005 |
|
| 2006 |
template |
| 2007 |
void DissectionSolver<complex<double>, double>::GetSmallestPivotIndices(const int n, int *pivots); |
| 2008 |
|
| 2009 |
template |
| 2010 |
void DissectionSolver<complex<quadruple>, quadruple>::GetSmallestPivotIndices(const int n, int *pivots); |
| 2011 |
|
| 2012 |
template |
| 2013 |
void DissectionSolver<double, double, quadruple, quadruple>::GetSmallestPivotIndices(const int n, int *pivots); |
| 2014 |
|
| 2015 |
template |
| 2016 |
void DissectionSolver<quadruple, quadruple, double, double>::GetSmallestPivotIndices(const int n, int *pivots); |
| 2017 |
|
| 2018 |
template |
| 2019 |
void DissectionSolver<float>::GetSmallestPivotIndices(const int n, |
| 2020 |
int *pivots); |
| 2021 |
|
| 2022 |
template |
| 2023 |
void DissectionSolver<complex<float>, float>::GetSmallestPivotIndices(const int n, int *pivots); |
| 2024 |
|
| 2025 |
// |
| 2026 |
template<typename T, typename U, typename W, typename Z> |
| 2027 |
void DissectionSolver<T, U, W, Z>:: |
| 2028 |
GetKernelVectors(T *kern_basis) |
| 2029 |
{ |
| 2030 |
int ii = 0; |
| 2031 |
for (int m = 0; m < _graph_colors; m++) { |
| 2032 |
const int n0 = _kernel[m].dimension(); //_ptDA_kern_proj[m].dimension(); |
| 2033 |
// should be optimized : replaced by memcopy()? |
| 2034 |
for (int j = 0; j < n0; j++) { |
| 2035 |
for (int i = 0; i < _dim; i++, ii++) { |
| 2036 |
kern_basis[ii] = _kernel[m].getKernBasis().addrCoefs()[ii]; |
| 2037 |
} |
| 2038 |
} |
| 2039 |
} // loop : _graph_colors : m |
| 2040 |
} |
| 2041 |
|
| 2042 |
template |
| 2043 |
void DissectionSolver<double>::GetKernelVectors(double *kern_basis); |
| 2044 |
|
| 2045 |
template |
| 2046 |
void DissectionSolver<quadruple>::GetKernelVectors(quadruple *kern_basis); |
| 2047 |
|
| 2048 |
template |
| 2049 |
void DissectionSolver<complex<double>, double>::GetKernelVectors(complex<double> *kern_basis); |
| 2050 |
|
| 2051 |
template |
| 2052 |
void DissectionSolver<complex<quadruple>, quadruple>::GetKernelVectors(complex<quadruple> *kern_basis); |
| 2053 |
|
| 2054 |
template |
| 2055 |
void DissectionSolver<double, double, quadruple, quadruple>::GetKernelVectors(double *kern_basis); |
| 2056 |
|
| 2057 |
template |
| 2058 |
void DissectionSolver<quadruple, quadruple, double, double>::GetKernelVectors(quadruple *kern_basis); |
| 2059 |
|
| 2060 |
template |
| 2061 |
void DissectionSolver<float>::GetKernelVectors(float *kern_basis); |
| 2062 |
|
| 2063 |
template |
| 2064 |
void DissectionSolver<complex<float>, float>::GetKernelVectors(complex<float> *kern_basis); |
| 2065 |
// |
| 2066 |
|
| 2067 |
template<typename T, typename U, typename W, typename Z> |
| 2068 |
void DissectionSolver<T, U, W, Z>:: |
| 2069 |
GetTransKernelVectors(T *kernt_basis) |
| 2070 |
{ |
| 2071 |
int ii = 0; |
| 2072 |
for (int m = 0; m < _graph_colors; m++) { |
| 2073 |
const int n0 = _kernel[m].dimension(); //_ptDA_kern_proj[m].dimension(); |
| 2074 |
// should be optimized : replaced by memcopy()? |
| 2075 |
for (int j = 0; j < n0; j++) { |
| 2076 |
for (int i = 0; i < _dim; i++, ii++) { |
| 2077 |
kernt_basis[ii] = _kernel[m].getTKernBasis().addrCoefs()[ii]; |
| 2078 |
} |
| 2079 |
} |
| 2080 |
} // loop : _graph_colors : m |
| 2081 |
} |
| 2082 |
|
| 2083 |
template |
| 2084 |
void DissectionSolver<double>::GetTransKernelVectors(double *kernt_basis); |
| 2085 |
|
| 2086 |
|
| 2087 |
template |
| 2088 |
void DissectionSolver<quadruple>::GetTransKernelVectors(quadruple *kernt_basis); |
| 2089 |
|
| 2090 |
template |
| 2091 |
void DissectionSolver<complex<double>, double>::GetTransKernelVectors(complex<double> *kernt_basis); |
| 2092 |
|
| 2093 |
template |
| 2094 |
void DissectionSolver<complex<quadruple>, quadruple>::GetTransKernelVectors(complex<quadruple> *kernt_basis); |
| 2095 |
|
| 2096 |
template |
| 2097 |
void DissectionSolver<double, double, quadruple, quadruple>::GetTransKernelVectors(double *kernt_basis); |
| 2098 |
|
| 2099 |
template |
| 2100 |
void DissectionSolver<quadruple, quadruple, double, double>::GetTransKernelVectors(quadruple *kernt_basis); |
| 2101 |
|
| 2102 |
template |
| 2103 |
void DissectionSolver<float>::GetTransKernelVectors(float *kernt_basis); |
| 2104 |
|
| 2105 |
template |
| 2106 |
void DissectionSolver<complex<float>, float>::GetTransKernelVectors(complex<float> *kernt_basis); |
| 2107 |
|
| 2108 |
// |
| 2109 |
|
| 2110 |
template<typename T, typename U, typename W, typename Z> |
| 2111 |
void DissectionSolver<T, U, W, Z>:: |
| 2112 |
GetMatrixScaling(Z *weight) |
| 2113 |
{ |
| 2114 |
for (int i = 0; i < _dim; i++) { |
| 2115 |
weight[i] = _precDiag[i]; |
| 2116 |
} |
| 2117 |
} |
| 2118 |
|
| 2119 |
template |
| 2120 |
void DissectionSolver<double>::GetMatrixScaling(double *weight); |
| 2121 |
|
| 2122 |
template |
| 2123 |
void DissectionSolver<complex<double>, double>:: |
| 2124 |
GetMatrixScaling(double *weight); |
| 2125 |
|
| 2126 |
template |
| 2127 |
void DissectionSolver<quadruple>::GetMatrixScaling(quadruple *weight); |
| 2128 |
|
| 2129 |
template |
| 2130 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2131 |
GetMatrixScaling(quadruple *weight); |
| 2132 |
|
| 2133 |
template |
| 2134 |
void DissectionSolver<float>::GetMatrixScaling(float *weight); |
| 2135 |
|
| 2136 |
template |
| 2137 |
void DissectionSolver<complex<float>, float>:: |
| 2138 |
GetMatrixScaling(float *weight); |
| 2139 |
// |
| 2140 |
|
| 2141 |
template<typename T, typename U, typename W, typename Z> |
| 2142 |
void DissectionSolver<T, U, W, Z>:: |
| 2143 |
ProjectionImageSingle(T *x, string name) |
| 2144 |
{ |
| 2145 |
for (int m = 0; m < _graph_colors; m++) { |
| 2146 |
T *kern_basis0 = _kernel[m].getKernBasis().addrCoefs(); |
| 2147 |
T *kern_basis1 = (_ptDA->isSymmetric() ? |
| 2148 |
_kernel[m].getKernBasis().addrCoefs() : |
| 2149 |
_kernel[m].getTKernBasis().addrCoefs()); |
| 2150 |
T *kern_proj = (_ptDA->isSymmetric() ? |
| 2151 |
_kernel[m].getKernProj().addrCoefs() : |
| 2152 |
_kernel[m].getNTKernProj().addrCoefs()); |
| 2153 |
|
| 2154 |
const int n0 = _kernel[m].dimension(); |
| 2155 |
|
| 2156 |
VectorArray<T> xx(n0); |
| 2157 |
for (int j = 0; j < n0; j++) { |
| 2158 |
xx[j] = blas_dot<T>(_dim, |
| 2159 |
(kern_basis1 + j * _dim), |
| 2160 |
1, |
| 2161 |
x, 1); |
| 2162 |
} |
| 2163 |
diss_printf(_verbose, _fp, |
| 2164 |
"%s %d : %s : check orthogonality of the given vector \n", |
| 2165 |
__FILE__, __LINE__, |
| 2166 |
name.c_str()); |
| 2167 |
for (int j = 0; j < n0; j++) { |
| 2168 |
diss_printf(_verbose, _fp, "%.6e ", blas_abs<T, double>(xx[j])); |
| 2169 |
} |
| 2170 |
diss_printf(_verbose, _fp, "\n"); |
| 2171 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, |
| 2172 |
n0, kern_proj, |
| 2173 |
n0, xx.addrCoefs(), 1); |
| 2174 |
{ |
| 2175 |
int itmp = 0; |
| 2176 |
for (int j = 0; j < n0; j++, itmp += (n0 + 1)) { |
| 2177 |
xx[j] *= kern_proj[itmp]; |
| 2178 |
} |
| 2179 |
} |
| 2180 |
|
| 2181 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, |
| 2182 |
n0, kern_proj, |
| 2183 |
n0, xx.addrCoefs(), 1); |
| 2184 |
diss_printf(_verbose, _fp, |
| 2185 |
"%s %d : %s : solution of kernel adjustment : ", |
| 2186 |
__FILE__, __LINE__, name.c_str()); |
| 2187 |
for (int j = 0; j < n0; j++) { |
| 2188 |
diss_printf(_verbose, _fp, "%.6e ", blas_abs<T, double>(xx[j])); |
| 2189 |
} |
| 2190 |
diss_printf(_verbose, _fp, "\n"); |
| 2191 |
|
| 2192 |
for (int i = 0; i < _dim; i++) { |
| 2193 |
for (int j = 0; j < n0; j++) { |
| 2194 |
x[i] -= xx[j] * kern_basis0[i + j * _dim]; |
| 2195 |
} |
| 2196 |
} |
| 2197 |
|
| 2198 |
for (int j = 0; j < n0; j++) { |
| 2199 |
xx[j] = blas_dot<T>(_dim, |
| 2200 |
(kern_basis1 + j * _dim), 1, |
| 2201 |
x, 1); |
| 2202 |
} |
| 2203 |
diss_printf(_verbose, _fp, |
| 2204 |
"%s %d : %s : after projection, component of each kernel \n", |
| 2205 |
__FILE__, __LINE__, name.c_str()); |
| 2206 |
for (int j = 0; j < n0; j++) { |
| 2207 |
diss_printf(_verbose, _fp, "%.6e ", blas_abs<T, double>(xx[j])); |
| 2208 |
} |
| 2209 |
diss_printf(_verbose, _fp, "\n"); |
| 2210 |
xx.free(); |
| 2211 |
} // loop : _graph_colors : m |
| 2212 |
} |
| 2213 |
|
| 2214 |
template |
| 2215 |
void DissectionSolver<double>::ProjectionImageSingle(double *x, string name); |
| 2216 |
|
| 2217 |
template |
| 2218 |
void DissectionSolver<quadruple>::ProjectionImageSingle(quadruple *x, |
| 2219 |
string name); |
| 2220 |
template |
| 2221 |
void DissectionSolver<complex<double>, double>:: |
| 2222 |
ProjectionImageSingle(complex<double> *x, string name); |
| 2223 |
|
| 2224 |
template |
| 2225 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2226 |
ProjectionImageSingle(complex<quadruple> *x, string name); |
| 2227 |
|
| 2228 |
template |
| 2229 |
void DissectionSolver<float>::ProjectionImageSingle(float *x, string name); |
| 2230 |
|
| 2231 |
template |
| 2232 |
void DissectionSolver<complex<float>, float>:: |
| 2233 |
ProjectionImageSingle(complex<float> *x, string name); |
| 2234 |
|
| 2235 |
template |
| 2236 |
void DissectionSolver<double, double, quadruple, quadruple>::ProjectionImageSingle(double *x, string name); |
| 2237 |
|
| 2238 |
template |
| 2239 |
void DissectionSolver<quadruple, quadruple, double, double>::ProjectionImageSingle(quadruple *x, string name); |
| 2240 |
|
| 2241 |
// |
| 2242 |
template<typename T, typename U, typename W, typename Z> |
| 2243 |
void DissectionSolver<T, U, W, Z>:: |
| 2244 |
ProjectionKernelOrthSingle(T *x, string name, bool isTrans) |
| 2245 |
{ |
| 2246 |
for (int m = 0; m < _graph_colors; m++) { |
| 2247 |
const bool flag_trans = isTrans && (!_ptDA->isSymmetric()); |
| 2248 |
|
| 2249 |
T *kern_basis = flag_trans ? _kernel[m].getTKernBasis().addrCoefs() : |
| 2250 |
_kernel[m].getKernBasis().addrCoefs(); |
| 2251 |
T *kern_proj = flag_trans ? _kernel[m].getTKernProj().addrCoefs() : |
| 2252 |
_kernel[m].getKernProj().addrCoefs(); |
| 2253 |
const int n0 = _kernel[m].dimension(); |
| 2254 |
|
| 2255 |
VectorArray<T> xx(n0); |
| 2256 |
for (int j = 0; j < n0; j++) { |
| 2257 |
xx[j] = blas_dot<T>(_dim, |
| 2258 |
(kern_basis + j * _dim), |
| 2259 |
1, |
| 2260 |
x, 1); |
| 2261 |
} |
| 2262 |
diss_printf(_verbose, _fp, |
| 2263 |
"%s %d : %s : check orthogonality of the given vector\n", |
| 2264 |
__FILE__, __LINE__, name.c_str()); |
| 2265 |
for (int j = 0; j < n0; j++) { |
| 2266 |
diss_printf(_verbose, _fp, "%.6e ", blas_abs<T, double>(xx[j])); |
| 2267 |
} |
| 2268 |
diss_printf(_verbose, _fp, "\n"); |
| 2269 |
|
| 2270 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, |
| 2271 |
n0, kern_proj, |
| 2272 |
n0, xx.addrCoefs(), 1); |
| 2273 |
{ |
| 2274 |
int itmp = 0; |
| 2275 |
for (int j = 0; j < n0; j++, itmp += (n0 + 1)) { |
| 2276 |
xx[j] *= kern_proj[itmp]; |
| 2277 |
} |
| 2278 |
} |
| 2279 |
|
| 2280 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, |
| 2281 |
n0, kern_proj, |
| 2282 |
n0, xx.addrCoefs(), 1); |
| 2283 |
diss_printf(_verbose, _fp, |
| 2284 |
"%s %d : %s : solution of kernel adjustment\n", |
| 2285 |
__FILE__, __LINE__, name.c_str()); |
| 2286 |
for (int j = 0; j < n0; j++) { |
| 2287 |
diss_printf(_verbose, _fp, "%.6e ", blas_abs<T, double>(xx[j])); |
| 2288 |
} |
| 2289 |
diss_printf(_verbose, _fp, "\n"); |
| 2290 |
|
| 2291 |
for (int i = 0; i < _dim; i++) { |
| 2292 |
for (int j = 0; j < n0; j++) { |
| 2293 |
x[i] -= xx[j] * kern_basis[i + j * _dim]; |
| 2294 |
} |
| 2295 |
} |
| 2296 |
|
| 2297 |
for (int j = 0; j < n0; j++) { |
| 2298 |
xx[j] = blas_dot<T>(_dim, |
| 2299 |
(kern_basis + j * _dim), 1, |
| 2300 |
x, 1); |
| 2301 |
} |
| 2302 |
diss_printf(_verbose, _fp, |
| 2303 |
"%s %d : %s : after projection, component of each kernel\n", |
| 2304 |
__FILE__, __LINE__, name.c_str()); |
| 2305 |
for (int j = 0; j < n0; j++) { |
| 2306 |
diss_printf(_verbose, _fp, "%.6e ", blas_abs<T, double>(xx[j])); |
| 2307 |
} |
| 2308 |
diss_printf(_verbose, _fp, "\n"); |
| 2309 |
xx.free(); |
| 2310 |
} // loop : _graph_colors : m |
| 2311 |
} |
| 2312 |
|
| 2313 |
template |
| 2314 |
void DissectionSolver<double>::ProjectionKernelOrthSingle(double *x, |
| 2315 |
string name, |
| 2316 |
bool isTrans); |
| 2317 |
template |
| 2318 |
void DissectionSolver<quadruple>::ProjectionKernelOrthSingle(quadruple *x, |
| 2319 |
string name, |
| 2320 |
bool isTrans); |
| 2321 |
|
| 2322 |
template |
| 2323 |
void DissectionSolver<complex<double>, double>:: |
| 2324 |
ProjectionKernelOrthSingle(complex<double> *x, string name, bool isTrans); |
| 2325 |
|
| 2326 |
template |
| 2327 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2328 |
ProjectionKernelOrthSingle(complex<quadruple> *x, string name, bool isTrans); |
| 2329 |
|
| 2330 |
template |
| 2331 |
void DissectionSolver<float>::ProjectionKernelOrthSingle(float *x, |
| 2332 |
string name, |
| 2333 |
bool isTrans); |
| 2334 |
|
| 2335 |
template |
| 2336 |
void DissectionSolver<complex<float>, float>:: |
| 2337 |
ProjectionKernelOrthSingle(complex<float> *x, string name, bool isTrans); |
| 2338 |
|
| 2339 |
// |
| 2340 |
// |
| 2341 |
|
| 2342 |
template<typename T, typename U, typename W, typename Z> |
| 2343 |
void DissectionSolver<T, U, W, Z>:: |
| 2344 |
SpMV(const T *x, T *y, bool scaling_flag) |
| 2345 |
{ |
| 2346 |
if (_scaling && scaling_flag) { |
| 2347 |
VectorArray<T> w(_dim); |
| 2348 |
for (int i = 0; i < _dim; i++) { |
| 2349 |
// w[i] = x[i] / fromreal(_precDiag[i]); // conversion if T == complex<U> |
| 2350 |
w[i] = x[i] / _precDiag[i]; // without conversion when complex |
| 2351 |
} |
| 2352 |
_ptDA->prod(w.addrCoefs(), y); |
| 2353 |
for (int i = 0; i < _dim; i++) { |
| 2354 |
// y[i] /= fromreal(_precDiag[i]); |
| 2355 |
y[i] /= _precDiag[i]; |
| 2356 |
} |
| 2357 |
w.free(); |
| 2358 |
} |
| 2359 |
else { |
| 2360 |
_ptDA->prod(x, y); |
| 2361 |
} |
| 2362 |
} |
| 2363 |
|
| 2364 |
template |
| 2365 |
void DissectionSolver<double>::SpMV(const double *x, double *y, bool scaling_flag); |
| 2366 |
|
| 2367 |
template |
| 2368 |
void DissectionSolver<quadruple>::SpMV(const quadruple *x, quadruple *y, bool scaling_flag); |
| 2369 |
|
| 2370 |
template |
| 2371 |
void DissectionSolver<complex<double>, double>:: |
| 2372 |
SpMV(const complex<double> *x, complex<double> *y, bool scaling_flag); |
| 2373 |
|
| 2374 |
template |
| 2375 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2376 |
SpMV(const complex<quadruple> *x, complex<quadruple> *y, bool scaling_flag); |
| 2377 |
|
| 2378 |
template |
| 2379 |
void DissectionSolver<double, double, quadruple, quadruple>::SpMV(const double *x, double *y, bool scaling_flag); |
| 2380 |
|
| 2381 |
template |
| 2382 |
void DissectionSolver<quadruple, quadruple, double, double>::SpMV(const quadruple *x, quadruple *y, bool scaling_flag); |
| 2383 |
|
| 2384 |
template |
| 2385 |
void DissectionSolver<complex<double>, double, complex<quadruple>, quadruple>:: |
| 2386 |
SpMV(const complex<double> *x, complex<double> *y, bool scaling_flag); |
| 2387 |
|
| 2388 |
template |
| 2389 |
void DissectionSolver<complex<quadruple>, quadruple, complex<double>, double>:: |
| 2390 |
SpMV(const complex<quadruple> *x, complex<quadruple> *y, bool scaling_flag); |
| 2391 |
|
| 2392 |
template |
| 2393 |
void DissectionSolver<float>::SpMV(const float *x, float *y, bool scaling_flag); |
| 2394 |
|
| 2395 |
template |
| 2396 |
void DissectionSolver<complex<float>, float>:: |
| 2397 |
SpMV(const complex<float> *x, complex<float> *y, bool scaling_flag); |
| 2398 |
// |
| 2399 |
|
| 2400 |
template<typename T, typename U, typename W, typename Z> |
| 2401 |
void DissectionSolver<T, U, W, Z>:: |
| 2402 |
SpMtV(const T *x, T *y, bool scaling_flag) |
| 2403 |
{ |
| 2404 |
if (_scaling && scaling_flag) { |
| 2405 |
VectorArray<T> w(_dim); |
| 2406 |
for (int i = 0; i < _dim; i++) { |
| 2407 |
// w[i] = x[i] / fromreal(_precDiag[i]); |
| 2408 |
w[i] = x[i] / _precDiag[i]; |
| 2409 |
} |
| 2410 |
_ptDA->prodt(w.addrCoefs(), y); |
| 2411 |
for (int i = 0; i < _dim; i++) { |
| 2412 |
// y[i] /= fromreal(_precDiag[i]); |
| 2413 |
y[i] /= _precDiag[i]; |
| 2414 |
} |
| 2415 |
w.free(); |
| 2416 |
} |
| 2417 |
else { |
| 2418 |
_ptDA->prodt(x, y); |
| 2419 |
} |
| 2420 |
} |
| 2421 |
|
| 2422 |
template |
| 2423 |
void DissectionSolver<double>::SpMtV(const double *x, double *y, bool scaling_flag); |
| 2424 |
|
| 2425 |
template |
| 2426 |
void DissectionSolver<quadruple>::SpMtV(const quadruple *x, quadruple *y, bool scaling_flag); |
| 2427 |
|
| 2428 |
template |
| 2429 |
void DissectionSolver<complex<double>, double>:: |
| 2430 |
SpMtV(const complex<double> *x, complex<double> *y, bool scaling_flag); |
| 2431 |
|
| 2432 |
template |
| 2433 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2434 |
SpMtV(const complex<quadruple> *x, complex<quadruple> *y, bool scaling_flag); |
| 2435 |
|
| 2436 |
template |
| 2437 |
void DissectionSolver<float>::SpMtV(const float *x, float *y, bool scaling_flag); |
| 2438 |
|
| 2439 |
template |
| 2440 |
void DissectionSolver<complex<float>, float>:: |
| 2441 |
SpMtV(const complex<float> *x, complex<float> *y, bool scaling_flag); |
| 2442 |
|
| 2443 |
// |
| 2444 |
|
| 2445 |
template<typename T, typename U, typename W, typename Z> |
| 2446 |
void DissectionSolver<T, U, W, Z>:: |
| 2447 |
SolveSingle(T *x, bool projection, |
| 2448 |
bool isTrans, |
| 2449 |
bool isScaling, |
| 2450 |
const int nexcls) |
| 2451 |
{ |
| 2452 |
int n0, n1; |
| 2453 |
n0 = 0; |
| 2454 |
for (int m = 0; m < _graph_colors; m++) { |
| 2455 |
n0 += _kernel[m].dimension(); |
| 2456 |
} |
| 2457 |
n1 = 0; |
| 2458 |
for (int m = 0; m < _graph_colors; m++) { |
| 2459 |
n1 += _Schur[m].getSlduList().size(); |
| 2460 |
} |
| 2461 |
diss_printf(_verbose, _fp, "%s %d : colors = %d n1 = %d nexcls = %d\n", |
| 2462 |
__FILE__, __LINE__, _graph_colors, n1, nexcls); |
| 2463 |
|
| 2464 |
VectorArray<T> yy(n1); // allocation with size 0 is defined in PlainMatirx.hpp |
| 2465 |
elapsed_t t0_elapsed, t1_elapsed; |
| 2466 |
get_realtime(&t0_elapsed); |
| 2467 |
|
| 2468 |
if (n0 > 0 && projection) { |
| 2469 |
diss_printf(_verbose, _fp, |
| 2470 |
"%s %d : projection of the scaled RHS onto the image\n", |
| 2471 |
__FILE__, __LINE__); |
| 2472 |
ProjectionKernelOrthSingle(x, "scaled RHS", true); // orthogonal to ker A^T |
| 2473 |
} |
| 2474 |
if (isScaling) { |
| 2475 |
for (int i = 0; i < _dim; i++) { |
| 2476 |
x[i] *= _precDiag[i]; |
| 2477 |
} |
| 2478 |
} |
| 2479 |
if (isTrans) { |
| 2480 |
if (n1 > 0) { |
| 2481 |
int i0 = 0; |
| 2482 |
for (int m = 0; m < _graph_colors; m++) { |
| 2483 |
int nn1 = _Schur[m].getSlduList().size(); |
| 2484 |
for (int i = 0; i < nn1; i++, i0++) { |
| 2485 |
const int ii = _Schur[m].getSldu().loc2glob()[i]; |
| 2486 |
yy[i0] = x[ii]; |
| 2487 |
x[ii] = _zero; // the matrix is factorized only regular node, |
| 2488 |
// elements for suspicious pivots are set to be 0 |
| 2489 |
} // loop : i |
| 2490 |
} // loop : m |
| 2491 |
diss_printf(_verbose, _fp, |
| 2492 |
"%s %d : _ptDA_sldu[] are solved with n1=%d\n", |
| 2493 |
__FILE__, __LINE__, n1); |
| 2494 |
int mm0 = 0; |
| 2495 |
for (int m = 0; m < _graph_colors; m++) { |
| 2496 |
const int nnn1 = _Schur[m].getSlduList().size(); |
| 2497 |
if (nnn1 > nexcls) { |
| 2498 |
const int nn1 = nnn1 - nexcls; |
| 2499 |
// y2 = A32^T - (A_11^-1 A_12)^T A_31^T |
| 2500 |
blas_gemv<T>(CblasTrans, _dim, nn1, _none, |
| 2501 |
_Schur[m].getScol().addrCoefs(), _dim, |
| 2502 |
x, 1, _one, yy.addrCoefs() + mm0, 1); |
| 2503 |
// S22 x2 = y2 |
| 2504 |
blas_trsv<T>(CblasUpper, CblasTrans, CblasUnit, |
| 2505 |
nn1, |
| 2506 |
_Schur[m].getSldu().addrCoefs(), |
| 2507 |
nn1, |
| 2508 |
yy.addrCoefs() + mm0, 1); |
| 2509 |
for (int i = 0; i < nn1; i++) { |
| 2510 |
yy[mm0 + i] *= _Schur[m].getSldu()(i, i); // should be optimized |
| 2511 |
} |
| 2512 |
blas_trsv<T>(CblasLower, CblasTrans, CblasUnit, |
| 2513 |
nn1, |
| 2514 |
_Schur[m].getSldu().addrCoefs(), |
| 2515 |
nn1, |
| 2516 |
yy.addrCoefs() + mm0, 1); |
| 2517 |
// A_11^T x_1 = A_31^T - A_21^T x_2 |
| 2518 |
for (int i = 0; i < nn1; i++) { |
| 2519 |
const int ii = _Schur[m].getSlduList()[i]; |
| 2520 |
const SparseMatrix<T> * const arow = _Schur[m].getArow(); |
| 2521 |
for (int k = arow->ptRow(ii); k < arow->ptRow(ii + 1); k++) { |
| 2522 |
const int j = arow->indCol(k); |
| 2523 |
x[j] -= arow->Coef(k) * yy[mm0 + i]; |
| 2524 |
} |
| 2525 |
} // loop : i |
| 2526 |
} |
| 2527 |
else { |
| 2528 |
// change singIdx0 |
| 2529 |
} |
| 2530 |
mm0 += nnn1; // move to the next block |
| 2531 |
} // loop : _graph_colors : m |
| 2532 |
} // if (n1 > 0) |
| 2533 |
SolveScaled(x, 1, true); |
| 2534 |
if (n1 > 0) { |
| 2535 |
int mm0 = 0; |
| 2536 |
for (int m = 0; m < _graph_colors; m++) { |
| 2537 |
const int nn1 = _Schur[m].getSlduList().size(); |
| 2538 |
for (int i = 0; i < nn1; i++) { |
| 2539 |
const int ii = _Schur[m].getSldu().loc2glob()[i]; |
| 2540 |
x[ii] = yy[mm0 + i]; |
| 2541 |
} |
| 2542 |
mm0 += nn1; // move to the next block |
| 2543 |
} // loop : m |
| 2544 |
} // if (n1 > 0) |
| 2545 |
} // if (isTrans) |
| 2546 |
else { |
| 2547 |
if (n1 > 0) { |
| 2548 |
int i0 = 0; |
| 2549 |
for (int m = 0; m < _graph_colors; m++) { |
| 2550 |
int nn1 = _Schur[m].getSlduList().size(); |
| 2551 |
for (int i = 0; i < nn1; i++, i0++) { |
| 2552 |
const int ii = _Schur[m].getSldu().loc2glob_left()[i]; |
| 2553 |
yy[i0] = x[ii]; |
| 2554 |
x[ii] = _zero; // the matrix is factorized only regular node, |
| 2555 |
// elements for suspicious pivots are set to be 0 |
| 2556 |
} // loop : i |
| 2557 |
for (int i = 0; i < _kernel[m].getKernListEqLeft().size(); i++) { |
| 2558 |
const int ii = _kernel[m].getKernListEqLeft()[i]; |
| 2559 |
x[ii] = _zero; |
| 2560 |
} |
| 2561 |
} // loop : m |
| 2562 |
} |
| 2563 |
for (int m = 0; m < _graph_colors; m++) { |
| 2564 |
const int nnn1 = _Schur[m].getSlduList().size(); |
| 2565 |
diss_printf(_verbose, _fp, "%s %d : color = %d %d\n", |
| 2566 |
__FILE__, __LINE__, m, nnn1); |
| 2567 |
if (nnn1 < nexcls) { |
| 2568 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 2569 |
SquareBlockMatrix<T>* diag = |
| 2570 |
&_dissectionMatrix[m][_btree[m]->selfIndex(1)]->diagBlock(); |
| 2571 |
vector<int> &singIdx0 = diag->getSingIdx0(); |
| 2572 |
int pseudosing; |
| 2573 |
if (singIdx0.size() > 0) { |
| 2574 |
pseudosing = std::min<int>((int)singIdx0.front(), |
| 2575 |
(int)singIdx0.back()) - 1; |
| 2576 |
} |
| 2577 |
else { |
| 2578 |
pseudosing = diag->dimension() - 1; |
| 2579 |
} |
| 2580 |
for (int i = nnn1; i < nexcls; i++, pseudosing--) { |
| 2581 |
singIdx0.push_back(pseudosing); |
| 2582 |
} |
| 2583 |
} |
| 2584 |
} |
| 2585 |
} |
| 2586 |
for (int m = 0; m < _graph_colors; m++) { |
| 2587 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 2588 |
SquareBlockMatrix<T>* diag = |
| 2589 |
&_dissectionMatrix[m][_btree[m]->selfIndex(1)]->diagBlock(); |
| 2590 |
vector<int> &singIdx0 = diag->getSingIdx0(); |
| 2591 |
if (singIdx0.size() > 0) { |
| 2592 |
diss_printf(_verbose, _fp, "%s %d : color = %d modify dim = %d : ", |
| 2593 |
__FILE__, __LINE__, m, diag->dimension()); |
| 2594 |
for (vector<int>::const_iterator it = singIdx0.begin(); |
| 2595 |
it != singIdx0.end(); ++it) { |
| 2596 |
diss_printf(_verbose, _fp, " %d", *it); |
| 2597 |
} |
| 2598 |
diss_printf(_verbose, _fp, "\n"); |
| 2599 |
} //if (_verbose && (singIdx0.size() > 0)) |
| 2600 |
} |
| 2601 |
} |
| 2602 |
SolveScaled(x, 1, false); |
| 2603 |
if (n1 > 0) { |
| 2604 |
diss_printf(_verbose, _fp, |
| 2605 |
"%s %d : _ptDA_sldu[] are solved with n1=%d\n", |
| 2606 |
__FILE__, __LINE__, n1); |
| 2607 |
int mm0 = 0; |
| 2608 |
for (int m = 0; m < _graph_colors; m++) { |
| 2609 |
const int nnn1 = _Schur[m].getSlduList().size(); |
| 2610 |
if (nnn1 > nexcls) { |
| 2611 |
const int nn1 = nnn1 - nexcls; |
| 2612 |
diss_printf(_verbose, _fp, "%s %d : sldu %d\n", __FILE__, __LINE__, |
| 2613 |
nn1); |
| 2614 |
for (int i = 0; i < nn1; i++) { |
| 2615 |
T stmp(0.0); |
| 2616 |
const int ii = _Schur[m].getSlduListLeft()[i]; |
| 2617 |
const SparseMatrix<T> * const arow = _Schur[m].getArow(); |
| 2618 |
for (int k = arow->ptRow(ii); k < arow->ptRow(ii + 1); k++) { |
| 2619 |
const int j = arow->indCol(k); |
| 2620 |
stmp += arow->Coef(k) * x[j]; |
| 2621 |
} |
| 2622 |
yy[mm0 + i] -= stmp; |
| 2623 |
} |
| 2624 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, |
| 2625 |
nn1, _Schur[m].getSldu().addrCoefs(), nn1, |
| 2626 |
yy.addrCoefs() + mm0, 1); |
| 2627 |
for (int i = 0; i < nn1; i++) { |
| 2628 |
yy[mm0 + i] *= _Schur[m].getSldu()(i, i); // should be optimized |
| 2629 |
} |
| 2630 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, |
| 2631 |
nn1, _Schur[m].getSldu().addrCoefs(), nn1, |
| 2632 |
yy.addrCoefs() + mm0, 1); |
| 2633 |
for (int i = 0; i < nn1; i++) { |
| 2634 |
const int ii = _Schur[m].getSldu().loc2glob()[i]; |
| 2635 |
x[ii] = yy[mm0 + i]; |
| 2636 |
} |
| 2637 |
} |
| 2638 |
} // loop : m |
| 2639 |
{ |
| 2640 |
int mm0 = 0; |
| 2641 |
for (int m = 0; m < _graph_colors; m++) { |
| 2642 |
const int nnn1 = _Schur[m].getSlduList().size(); |
| 2643 |
if (nnn1 > nexcls) { |
| 2644 |
const int nn1 = nnn1 - nexcls; |
| 2645 |
blas_gemv<T>(CblasNoTrans, _dim, nn1, _none, |
| 2646 |
_Schur[m].getScol().addrCoefs(), _dim, |
| 2647 |
yy.addrCoefs() + mm0, 1, _one, x, 1); |
| 2648 |
mm0 += nnn1; // move to the next block |
| 2649 |
} |
| 2650 |
for (int i = 0; i < _kernel[m].getKernListEq().size(); i++) { |
| 2651 |
const int ii = _kernel[m].getKernListEq()[i]; |
| 2652 |
x[ii] = _zero; |
| 2653 |
} |
| 2654 |
} // loop : _graph_colors : m |
| 2655 |
} // scope of mm0 |
| 2656 |
} // if (n1 > 0) |
| 2657 |
else { |
| 2658 |
for (int m = 0; m < _graph_colors; m++) { |
| 2659 |
const int nnn1 = _Schur[m].getSlduList().size(); |
| 2660 |
if (nnn1 < nexcls) { |
| 2661 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 2662 |
SquareBlockMatrix<T>* diag = |
| 2663 |
&_dissectionMatrix[m][_btree[m]->selfIndex(1)]->diagBlock(); |
| 2664 |
vector<int> &singIdx0 = diag->getSingIdx0(); |
| 2665 |
if (singIdx0.size() > 0) { |
| 2666 |
diss_printf(_verbose, _fp, "%s %d : restore ", |
| 2667 |
__FILE__, __LINE__); |
| 2668 |
for (vector<int>::const_iterator it = singIdx0.begin(); |
| 2669 |
it != singIdx0.end(); ++it) { |
| 2670 |
diss_printf(_verbose, _fp, " %d", *it); |
| 2671 |
} |
| 2672 |
diss_printf(_verbose, _fp, "\n"); |
| 2673 |
for (int i = nnn1; i < nexcls; i++) { |
| 2674 |
singIdx0.pop_back(); |
| 2675 |
} |
| 2676 |
} |
| 2677 |
} |
| 2678 |
} // if (nn1 < nexcls) |
| 2679 |
} // loop : m |
| 2680 |
} // if (n1 > 0) |
| 2681 |
} // if (isTrans) |
| 2682 |
// adjust the kernel : x = x - N (N{^T} N)^-1 N^{T} x |
| 2683 |
if (isScaling) { |
| 2684 |
for (int i = 0; i < _dim; i++) { |
| 2685 |
x[i] *= _precDiag[i]; |
| 2686 |
} |
| 2687 |
} |
| 2688 |
// |
| 2689 |
if (_index_isolated.size() > 0) { |
| 2690 |
for (vector<int>::const_iterator it = _index_isolated.begin(); |
| 2691 |
it != _index_isolated.end(); ++it) { |
| 2692 |
T atmp(1.0); |
| 2693 |
for (int k = _ptDA->ptRow((*it)); k < _ptDA->ptRow((*it) + 1); k++) { |
| 2694 |
if (_ptDA->indCol(k) == (*it)) { |
| 2695 |
atmp = _one / _ptDA->Coef(k); |
| 2696 |
break; |
| 2697 |
} |
| 2698 |
} |
| 2699 |
x[(*it)] *= atmp; |
| 2700 |
} // loop : it |
| 2701 |
} // if (_index_isolated.size() > 0) |
| 2702 |
if (n0 > 0 && projection) { |
| 2703 |
diss_printf(_verbose, _fp, |
| 2704 |
"%s %d : projection orthogonal to the kernel\n", |
| 2705 |
__FILE__, __LINE__); |
| 2706 |
ProjectionKernelOrthSingle(x, "scaled RHS", false); // orthogonal to ker A |
| 2707 |
} |
| 2708 |
get_realtime(&t1_elapsed); |
| 2709 |
} |
| 2710 |
|
| 2711 |
template |
| 2712 |
void DissectionSolver<double>::SolveSingle(double *x, bool projection, |
| 2713 |
bool isTrans, bool isScaling, |
| 2714 |
const int nexcls); |
| 2715 |
|
| 2716 |
template |
| 2717 |
void DissectionSolver<quadruple>::SolveSingle(quadruple *x, bool projection, |
| 2718 |
bool isTrans, bool isScaling, |
| 2719 |
const int nexcls); |
| 2720 |
|
| 2721 |
template |
| 2722 |
void DissectionSolver<complex<double>, double>:: |
| 2723 |
SolveSingle(complex<double> *x, bool projection, bool isTrans, bool isScaling, |
| 2724 |
const int nexcls); |
| 2725 |
|
| 2726 |
template |
| 2727 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2728 |
SolveSingle(complex<quadruple> *x, bool projection, bool isTrans, |
| 2729 |
bool isScaling, const int nexcls); |
| 2730 |
// |
| 2731 |
template |
| 2732 |
void DissectionSolver<double, double, quadruple, quadruple>::SolveSingle(double *x, bool projection, |
| 2733 |
bool isTrans, bool isScaling, |
| 2734 |
const int nexcls); |
| 2735 |
|
| 2736 |
template |
| 2737 |
void DissectionSolver<quadruple, quadruple, double, double>::SolveSingle(quadruple *x, bool projection, |
| 2738 |
bool isTrans, bool isScaling, |
| 2739 |
const int nexcls); |
| 2740 |
|
| 2741 |
template |
| 2742 |
void DissectionSolver<complex<double>, double, complex<quadruple>, quadruple>:: |
| 2743 |
SolveSingle(complex<double> *x, bool projection, bool isTrans, bool isScaling, |
| 2744 |
const int nexcls); |
| 2745 |
|
| 2746 |
template |
| 2747 |
void DissectionSolver<complex<quadruple>, quadruple, complex<double>, double>:: |
| 2748 |
SolveSingle(complex<quadruple> *x, bool projection, bool isTrans, |
| 2749 |
bool isScaling, const int nexcls); |
| 2750 |
|
| 2751 |
template |
| 2752 |
void DissectionSolver<float>::SolveSingle(float *x, bool projection, |
| 2753 |
bool isTrans, bool isScaling, |
| 2754 |
const int nexcls); |
| 2755 |
|
| 2756 |
template |
| 2757 |
void DissectionSolver<complex<float>, float>:: |
| 2758 |
SolveSingle(complex<float> *x, bool projection, bool isTrans, bool isScaling, |
| 2759 |
const int nexcls); |
| 2760 |
|
| 2761 |
// |
| 2762 |
template<typename T, typename U, typename W, typename Z> |
| 2763 |
void DissectionSolver<T, U, W, Z>:: |
| 2764 |
SolveScaled(T *x, int nrhs, bool isTrans) |
| 2765 |
{ |
| 2766 |
for (int m = 0; m < _graph_colors; m++) { |
| 2767 |
if (_tridiagQueue[m]->tridiagSolver()) { |
| 2768 |
_tridiagQueue[m]->exec_fwbw(x, nrhs, isTrans); |
| 2769 |
} |
| 2770 |
else { |
| 2771 |
//if (false) { |
| 2772 |
if (nrhs == 1) { |
| 2773 |
_dissectionQueue[m]->exec_fwbw_seq(x, nrhs, isTrans); |
| 2774 |
} |
| 2775 |
else { |
| 2776 |
_dissectionQueue[m]->exec_fwbw(x, nrhs, isTrans); |
| 2777 |
} |
| 2778 |
} |
| 2779 |
} // loop : m |
| 2780 |
} |
| 2781 |
|
| 2782 |
template |
| 2783 |
void DissectionSolver<double>::SolveScaled(double *x, int nrhs, bool isTrans); |
| 2784 |
|
| 2785 |
template |
| 2786 |
void DissectionSolver<complex<double>, double>:: |
| 2787 |
SolveScaled(complex<double> *x, |
| 2788 |
int nrhs, bool isTrans); |
| 2789 |
|
| 2790 |
template |
| 2791 |
void DissectionSolver<quadruple>::SolveScaled(quadruple *x, int nrhs, |
| 2792 |
bool isTrans); |
| 2793 |
|
| 2794 |
template |
| 2795 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 2796 |
SolveScaled(complex<quadruple> *x, |
| 2797 |
int nrhs, bool isTrans); |
| 2798 |
|
| 2799 |
template |
| 2800 |
void DissectionSolver<float>::SolveScaled(float *x, int nrhs, bool isTrans); |
| 2801 |
|
| 2802 |
|
| 2803 |
template |
| 2804 |
void DissectionSolver<complex<float>, float>:: |
| 2805 |
SolveScaled(complex<float> *x, |
| 2806 |
int nrhs, bool isTrans); |
| 2807 |
// |
| 2808 |
|
| 2809 |
template<typename T, typename U, typename W, typename Z> |
| 2810 |
void DissectionSolver<T, U, W, Z>:: |
| 2811 |
SolveMulti(T *x, int nrhs, bool projection, |
| 2812 |
bool isTrans, bool isScaling, const int nexcls) |
| 2813 |
{ |
| 2814 |
const int nsing = _nsing; //_singIdx.size(); |
| 2815 |
VectorArray<T> vtmp(nrhs); |
| 2816 |
vector<int> nn1(_graph_colors); |
| 2817 |
// nn1.resize(_graph_colors); |
| 2818 |
int i0, mm0, n0, n1; |
| 2819 |
|
| 2820 |
int itmp; |
| 2821 |
ColumnMatrix<T> xx; |
| 2822 |
ColumnMatrix<T> yy; |
| 2823 |
|
| 2824 |
elapsed_t t0_elapsed, t1_elapsed; |
| 2825 |
|
| 2826 |
n0 = 0; |
| 2827 |
for (int m = 0; m < _graph_colors; m++) { |
| 2828 |
n0 += _kernel[m].dimension(); |
| 2829 |
} |
| 2830 |
|
| 2831 |
n1 = 0; |
| 2832 |
if (nsing > 0) { |
| 2833 |
for (int m = 0; m < _graph_colors; m++) { |
| 2834 |
nn1[m] = _Schur[m].getSlduList().size(); |
| 2835 |
n1 += nn1[m]; |
| 2836 |
} |
| 2837 |
} |
| 2838 |
get_realtime(&t0_elapsed); |
| 2839 |
|
| 2840 |
itmp = 0; |
| 2841 |
xx.init(_dim, nrhs, x, false); |
| 2842 |
if (isScaling) { |
| 2843 |
for (int i = 0; i < _dim; i++) { |
| 2844 |
for (int n = 0; n < nrhs; n++) { |
| 2845 |
xx(i, n) *= _precDiag[i]; |
| 2846 |
} |
| 2847 |
} // loop : n |
| 2848 |
} |
| 2849 |
if (n0 > 0 && projection) { |
| 2850 |
diss_printf(_verbose, _fp, |
| 2851 |
"%s %d : projection of the scaled RHS onto the image\n", |
| 2852 |
__FILE__, __LINE__); |
| 2853 |
for (int n = 0; n < nrhs; n++) { |
| 2854 |
ProjectionKernelOrthSingle(xx.addrCoefs() + (n * _dim), |
| 2855 |
"scaled RHS", true); // orthogonal to ker A^T |
| 2856 |
} |
| 2857 |
} |
| 2858 |
if (n1 > 0) { |
| 2859 |
yy.init(n1, nrhs); |
| 2860 |
} // if (n1 > 0) |
| 2861 |
if (isTrans) { |
| 2862 |
if (n1 > 0) { // if (nsing > 0) { |
| 2863 |
i0 = 0; |
| 2864 |
for (int m = 0; m < _graph_colors; m++) { |
| 2865 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 2866 |
for (int n = 0; n < nrhs; n++) { |
| 2867 |
const int ii = _Schur[m].getSldu().loc2glob()[i]; |
| 2868 |
yy(i0, n) = xx(ii, n); // yy[n][i0] = xx[n][ii]; |
| 2869 |
xx(ii, n) = _zero; |
| 2870 |
} // loop : n |
| 2871 |
} // loop : i |
| 2872 |
} // loop : m |
| 2873 |
mm0 = 0; |
| 2874 |
for (int m = 0; m < _graph_colors; m++) { |
| 2875 |
if (nn1[m] > 0) { |
| 2876 |
blas_gemm<T>(CblasTrans, CblasNoTrans, nn1[m], nrhs, _dim, _none, |
| 2877 |
_Schur[m].getScol().addrCoefs(), _dim, |
| 2878 |
xx.addrCoefs(), _dim, _one, yy.addrCoefs() + mm0, n1); |
| 2879 |
mm0 += nn1[m]; |
| 2880 |
} |
| 2881 |
} |
| 2882 |
mm0 = 0; |
| 2883 |
i0 = 0; |
| 2884 |
for (int m = 0; m < _graph_colors; m++) { |
| 2885 |
if (nn1[m] > 0) { |
| 2886 |
blas_trsm<T>(CblasLeft, |
| 2887 |
CblasUpper, CblasTrans, CblasUnit, |
| 2888 |
nn1[m], nrhs, _one, // alpha |
| 2889 |
_Schur[m].getSldu().addrCoefs(), nn1[m], |
| 2890 |
yy.addrCoefs() + mm0, n1); // yy[i] = &y[i * n1] |
| 2891 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 2892 |
for (int n = 0; n < nrhs; n++) { |
| 2893 |
//yy[n][i0] *= _Schur[m].getSldu()(i, i); // should be optimized |
| 2894 |
yy(i0, n) *= _Schur[m].getSldu()(i, i); // should be optimized |
| 2895 |
} |
| 2896 |
} |
| 2897 |
blas_trsm<T>(CblasLeft, |
| 2898 |
CblasLower, CblasTrans, CblasUnit, |
| 2899 |
nn1[m], nrhs, _one, // alpha |
| 2900 |
_Schur[m].getSldu().addrCoefs(), nn1[m], |
| 2901 |
yy.addrCoefs() + mm0, n1); |
| 2902 |
mm0 += _Schur[m].getSlduList().size(); |
| 2903 |
} |
| 2904 |
} |
| 2905 |
i0 = 0; |
| 2906 |
for (int m = 0; m < _graph_colors; m++) { |
| 2907 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 2908 |
const int ii = _Schur[m].getSlduList()[i]; |
| 2909 |
const SparseMatrix<T> * const arow = _Schur[m].getArow(); |
| 2910 |
for (int k = arow->ptRow(ii); k < arow->ptRow(ii + 1); k++) { |
| 2911 |
const int j = arow->indCol(k); |
| 2912 |
const T xtmp = arow->Coef(k); |
| 2913 |
for (int n = 0; n < nrhs; n++) { |
| 2914 |
xx(j, n) -= xtmp * yy(i0, n); // xx[n][j] -= xtmp * yy[n][i0]; |
| 2915 |
} |
| 2916 |
} // loop : n |
| 2917 |
} // loop : i |
| 2918 |
} // loop : m |
| 2919 |
} // if (nsing > 0) |
| 2920 |
SolveScaled(xx.addrCoefs(), nrhs, true); |
| 2921 |
if (nsing > 0) { |
| 2922 |
i0 = 0; |
| 2923 |
for (int m = 0; m < _graph_colors; m++) { |
| 2924 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 2925 |
for (int n = 0; n < nrhs; n++) { |
| 2926 |
const int ii = _Schur[m].getSldu().loc2glob()[i]; |
| 2927 |
xx(ii, n) = yy(i0, n); // xx[n][ii] = yy[n][i0]; |
| 2928 |
} |
| 2929 |
} // loop : i |
| 2930 |
} // loop : m |
| 2931 |
} // if (nsing > 0) |
| 2932 |
} |
| 2933 |
else { |
| 2934 |
if (n1 > 0) { // if (nsing > 0) { |
| 2935 |
i0 = 0; |
| 2936 |
for (int m = 0; m < _graph_colors; m++) { |
| 2937 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 2938 |
for (int n = 0; n < nrhs; n++) { |
| 2939 |
const int ii = _Schur[m].getSldu().loc2glob_left()[i]; |
| 2940 |
yy(i0, n) = xx(ii, n); // yy[n][i0] = xx[n][ii]; |
| 2941 |
xx(ii, n) = _zero; |
| 2942 |
} // loop : n |
| 2943 |
} // loop : i |
| 2944 |
} |
| 2945 |
} |
| 2946 |
for (int m = 0; m < _graph_colors; m++) { |
| 2947 |
const int nnn1 = _Schur[m].getSlduList().size(); |
| 2948 |
diss_printf(_verbose, _fp, "%s %d : color = %d %d\n", |
| 2949 |
__FILE__, __LINE__, m, nnn1); |
| 2950 |
if (nnn1 < nexcls) { |
| 2951 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 2952 |
SquareBlockMatrix<T>* diag = |
| 2953 |
&_dissectionMatrix[m][_btree[m]->selfIndex(1)]->diagBlock(); |
| 2954 |
vector<int> &singIdx0 = diag->getSingIdx0(); |
| 2955 |
int pseudosing; |
| 2956 |
if (singIdx0.size() > 0) { |
| 2957 |
pseudosing = std::min<int>((int)singIdx0.front(), |
| 2958 |
(int)singIdx0.back()) - 1; |
| 2959 |
} |
| 2960 |
else { |
| 2961 |
pseudosing = diag->dimension() - 1; |
| 2962 |
} |
| 2963 |
for (int i = nnn1; i < nexcls; i++, pseudosing--) { |
| 2964 |
singIdx0.push_back(pseudosing); |
| 2965 |
} |
| 2966 |
} |
| 2967 |
} |
| 2968 |
} |
| 2969 |
for (int m = 0; m < _graph_colors; m++) { |
| 2970 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 2971 |
SquareBlockMatrix<T>* diag = |
| 2972 |
&_dissectionMatrix[m][_btree[m]->selfIndex(1)]->diagBlock(); |
| 2973 |
vector<int> &singIdx0 = diag->getSingIdx0(); |
| 2974 |
if (singIdx0.size() > 0) { |
| 2975 |
diss_printf(_verbose, _fp, "%s %d : color = %d modify dim = %d : ", |
| 2976 |
__FILE__, __LINE__, m, diag->dimension()); |
| 2977 |
for (vector<int>::const_iterator it = singIdx0.begin(); |
| 2978 |
it != singIdx0.end(); ++it) { |
| 2979 |
diss_printf(_verbose, _fp, " %d", *it); |
| 2980 |
} |
| 2981 |
diss_printf(_verbose, _fp, "\n"); |
| 2982 |
} //if (singIdx0.size() > 0) |
| 2983 |
} |
| 2984 |
} |
| 2985 |
SolveScaled(xx.addrCoefs(), nrhs, false); |
| 2986 |
if (nsing > 0) { |
| 2987 |
i0 = 0; |
| 2988 |
for (int m = 0; m < _graph_colors; m++) { |
| 2989 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 2990 |
vtmp.ZeroClear(); |
| 2991 |
const int ii = _Schur[m].getSlduListLeft()[i]; |
| 2992 |
const SparseMatrix<T> * const arow = _Schur[m].getArow(); |
| 2993 |
for (int k = arow->ptRow(ii); k < arow->ptRow(ii + 1); k++) { |
| 2994 |
const int j = arow->indCol(k); |
| 2995 |
const T xtmp = arow->Coef(k); |
| 2996 |
for (int n = 0; n < nrhs; n++) { |
| 2997 |
vtmp[n] += xtmp * xx(j, n); //xx[n][j]; |
| 2998 |
} |
| 2999 |
} // loop : n |
| 3000 |
for (int n = 0; n < nrhs; n++) { |
| 3001 |
yy(i0, n) -= vtmp[n]; // yy[n][i0] -= vtmp[n]; |
| 3002 |
} // loop : n |
| 3003 |
} // loop : i |
| 3004 |
} // loop : m |
| 3005 |
mm0 = 0; |
| 3006 |
i0 = 0; |
| 3007 |
for (int m = 0; m < _graph_colors; m++) { |
| 3008 |
if (nn1[m] > 0) { |
| 3009 |
blas_trsm<T>(CblasLeft, |
| 3010 |
CblasLower, CblasNoTrans, CblasUnit, |
| 3011 |
nn1[m], nrhs, _one, // alpha |
| 3012 |
_Schur[m].getSldu().addrCoefs(), nn1[m], |
| 3013 |
yy.addrCoefs() + mm0, n1); // yy[i] = &y[i * n1] |
| 3014 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 3015 |
for (int n = 0; n < nrhs; n++) { |
| 3016 |
// yy[n][i0] *= _Schur[m].getSldu()(i, i); // should be optimized |
| 3017 |
yy(i0, n) *= _Schur[m].getSldu()(i, i); // should be optimized |
| 3018 |
} |
| 3019 |
} |
| 3020 |
blas_trsm<T>(CblasLeft, |
| 3021 |
CblasUpper, CblasNoTrans, CblasUnit, |
| 3022 |
nn1[m], nrhs, _one, _Schur[m].getSldu().addrCoefs(), |
| 3023 |
nn1[m], |
| 3024 |
yy.addrCoefs() + mm0, n1); |
| 3025 |
mm0 += _Schur[m].getSlduList().size(); |
| 3026 |
} // if (nn1[m] > 0) |
| 3027 |
} // loop : m |
| 3028 |
i0 = 0; |
| 3029 |
for (int m = 0; m < _graph_colors; m++) { |
| 3030 |
for (int i = 0; i < nn1[m]; i++, i0++) { |
| 3031 |
for (int n = 0; n < nrhs; n++) { |
| 3032 |
const int ii = _Schur[m].getSldu().loc2glob()[i]; |
| 3033 |
xx(ii, n)= yy(i0, n); // xx[n][ii] = yy[n][i0]; |
| 3034 |
} |
| 3035 |
} |
| 3036 |
} // loop : m |
| 3037 |
mm0 = 0; |
| 3038 |
for (int m = 0; m < _graph_colors; m++) { |
| 3039 |
if (nn1[m] > 0) { |
| 3040 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, _dim, nrhs, nn1[m], _none, |
| 3041 |
_Schur[m].getScol().addrCoefs(), _dim, |
| 3042 |
yy.addrCoefs() + mm0, n1, _one, xx.addrCoefs(), _dim); |
| 3043 |
mm0 += nn1[m]; |
| 3044 |
} |
| 3045 |
} |
| 3046 |
} |
| 3047 |
} // if (isTrans) |
| 3048 |
// adjust the kernel : x = x - N (N{^T} N)^-1 N^{T} x |
| 3049 |
if (isScaling) { |
| 3050 |
for (int n = 0; n < nrhs; n++) { |
| 3051 |
for (int i = 0; i < _dim; i++) { |
| 3052 |
xx(i, n) *= _precDiag[i]; // xx[n][i] *= _precDiag[i]; |
| 3053 |
} |
| 3054 |
} |
| 3055 |
} |
| 3056 |
else { // inversion of isolated diagonal entries |
| 3057 |
for (vector<int>::const_iterator it = _index_isolated.begin(); |
| 3058 |
it != _index_isolated.end(); ++it) { |
| 3059 |
T atmp(1.0); |
| 3060 |
for (int k = _ptDA->ptRow((*it)); k < _ptDA->ptRow((*it) + 1); k++) { |
| 3061 |
if (_ptDA->indCol(k) == (*it)) { |
| 3062 |
atmp = _one / _ptDA->Coef(k); |
| 3063 |
break; |
| 3064 |
} |
| 3065 |
} |
| 3066 |
for (int n = 0; n < nrhs; n++) { |
| 3067 |
xx((*it), n) *= atmp; // xx[n][(*it)] *= atmp; |
| 3068 |
} |
| 3069 |
} // loop : it |
| 3070 |
} // if (nsing > 0) |
| 3071 |
if (n0 > 0 && projection) { |
| 3072 |
diss_printf(_verbose, _fp, |
| 3073 |
"%s %d : projection of the scaled solution onto the image\n", |
| 3074 |
__FILE__, __LINE__); |
| 3075 |
for (int n = 0; n < nrhs; n++) { |
| 3076 |
ProjectionKernelOrthSingle(xx.addrCoefs() + (n * _dim), |
| 3077 |
"scaled solution", |
| 3078 |
false); // orthogonal to ker A |
| 3079 |
} |
| 3080 |
} |
| 3081 |
// if (n1 > 0) { |
| 3082 |
// delete [] y; |
| 3083 |
//yy.free(); |
| 3084 |
// } |
| 3085 |
// delete [] yy; |
| 3086 |
// delete [] xx; |
| 3087 |
xx.free(); |
| 3088 |
yy.free(); |
| 3089 |
// delete [] vtmp; |
| 3090 |
// delete [] nn1; |
| 3091 |
get_realtime(&t1_elapsed); |
| 3092 |
} |
| 3093 |
|
| 3094 |
template |
| 3095 |
void DissectionSolver<double>::SolveMulti(double *x, int nrhs, |
| 3096 |
bool projection, |
| 3097 |
bool isTrans, bool isScaling, |
| 3098 |
const int nexcls); |
| 3099 |
|
| 3100 |
template |
| 3101 |
void DissectionSolver<quadruple>::SolveMulti(quadruple *x, int nrhs, |
| 3102 |
bool projection, |
| 3103 |
bool isTrans, |
| 3104 |
bool isScaling, |
| 3105 |
const int nexcls); |
| 3106 |
|
| 3107 |
template |
| 3108 |
void DissectionSolver<complex<double>, double>:: |
| 3109 |
SolveMulti(complex<double> *x, int nrhs, bool projection, |
| 3110 |
bool isTrans, bool isScaling, |
| 3111 |
const int nexcls); |
| 3112 |
|
| 3113 |
template |
| 3114 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 3115 |
SolveMulti(complex<quadruple> *x, int nrhs, bool projection, |
| 3116 |
bool isTrans, bool isScaling, |
| 3117 |
const int nexcls); |
| 3118 |
|
| 3119 |
template |
| 3120 |
void DissectionSolver<double, double, quadruple, quadruple>:: |
| 3121 |
SolveMulti(double *x, int nrhs, |
| 3122 |
bool projection, |
| 3123 |
bool isTrans, bool isScaling, |
| 3124 |
const int nexcls); |
| 3125 |
|
| 3126 |
template |
| 3127 |
void DissectionSolver<complex<double>, double, |
| 3128 |
complex<quadruple>, quadruple>:: |
| 3129 |
SolveMulti(complex<double> *x, int nrhs, |
| 3130 |
bool projection, |
| 3131 |
bool isTrans, |
| 3132 |
bool isScaling, |
| 3133 |
const int nexcls); |
| 3134 |
|
| 3135 |
template |
| 3136 |
void DissectionSolver<float>::SolveMulti(float *x, int nrhs, |
| 3137 |
bool projection, |
| 3138 |
bool isTrans, bool isScaling, |
| 3139 |
const int nexcls); |
| 3140 |
template |
| 3141 |
void DissectionSolver<complex<float>, float>:: |
| 3142 |
SolveMulti(complex<float> *x, int nrhs, bool projection, |
| 3143 |
bool isTrans, bool isScaling, |
| 3144 |
const int nexcls); |
| 3145 |
// |
| 3146 |
|
| 3147 |
template<typename T, typename U, typename W, typename Z> |
| 3148 |
void DissectionSolver<T, U, W, Z>:: |
| 3149 |
BuildSingCoefs(T *DSsingCoefs, |
| 3150 |
SparseMatrix<T> *DCsCoefs, |
| 3151 |
T *DBsCoefs, |
| 3152 |
vector<int>& singIdx, |
| 3153 |
const bool isTrans) |
| 3154 |
{ |
| 3155 |
const bool flag_trans = isTrans && (!_ptDA->isSymmetric()); |
| 3156 |
T *DSsingCoefs0; |
| 3157 |
const int nsing = singIdx.size(); |
| 3158 |
|
| 3159 |
if (flag_trans) { |
| 3160 |
DSsingCoefs0 = new T [nsing * nsing]; |
| 3161 |
} |
| 3162 |
else { |
| 3163 |
DSsingCoefs0 = DSsingCoefs; |
| 3164 |
} |
| 3165 |
_ptDA->extractSquareMatrix(DSsingCoefs0, singIdx); |
| 3166 |
if (flag_trans) { |
| 3167 |
for (int i = 0; i < nsing; i++) { |
| 3168 |
for (int j = 0; j < nsing;j++) { |
| 3169 |
DSsingCoefs[i + j * nsing] = DSsingCoefs0[j + i * nsing]; |
| 3170 |
} |
| 3171 |
} |
| 3172 |
} |
| 3173 |
|
| 3174 |
if ( _ptDA->isSymmetric() ) { |
| 3175 |
// singIdx[] is sorted in increasing order |
| 3176 |
// col_ind[] of symmetric matrix with CSR also in increasing order |
| 3177 |
|
| 3178 |
// Ssing = Asing - Cs*Am-1*(Bs) |
| 3179 |
// ?? (*it == 0) where it.column() == singIdx[k] ?? |
| 3180 |
for (int i = 0; i < nsing; i++) { |
| 3181 |
for (int j = i; j < nsing;j++) { |
| 3182 |
// [dense matrix As] - [sparse matrix Cs] * [dense matrix Am^-1 (Bs)] |
| 3183 |
T stmp(0.0); |
| 3184 |
for (int k = DCsCoefs->ptRow(i); k < DCsCoefs->ptRow(i + 1); k++) { |
| 3185 |
const int icol = DCsCoefs->indCol(k); |
| 3186 |
stmp += DCsCoefs->Coef(k) * DBsCoefs[icol + j * _dim]; |
| 3187 |
} |
| 3188 |
DSsingCoefs[i + j * nsing] -= stmp; |
| 3189 |
} |
| 3190 |
// symmetrize |
| 3191 |
for (int j = i + 1; j < nsing;j++) { |
| 3192 |
DSsingCoefs[j + i * nsing] = DSsingCoefs[i + j * nsing]; |
| 3193 |
} |
| 3194 |
} |
| 3195 |
} // if ( _ptDA->isSymmetric() ) { |
| 3196 |
else { |
| 3197 |
for (int i = 0; i < nsing; i++) { |
| 3198 |
for (int j = 0; j < nsing;j++) { |
| 3199 |
// [dense matrix As] - [sparse matrix Cs] * [dense matrix Am^-1 (Bs)] |
| 3200 |
T stmp(0.0); |
| 3201 |
for (int k = DCsCoefs->ptRow(i); k < DCsCoefs->ptRow(i + 1); k++) { |
| 3202 |
const int icol = DCsCoefs->indCol(k); |
| 3203 |
stmp += DCsCoefs->Coef(k) * DBsCoefs[icol + j * _dim]; |
| 3204 |
} |
| 3205 |
DSsingCoefs[i + j * nsing] -= stmp; |
| 3206 |
} |
| 3207 |
} |
| 3208 |
} // if ( _ptDA->isSymmetric() ) { |
| 3209 |
diss_printf(_verbose, _fp, |
| 3210 |
"%s %d : Schur complement on the singular dofs set %d x %d\n", |
| 3211 |
__FILE__, __LINE__, |
| 3212 |
nsing, nsing); |
| 3213 |
if (flag_trans) { |
| 3214 |
delete [] DSsingCoefs0; |
| 3215 |
} |
| 3216 |
} |
| 3217 |
|
| 3218 |
template |
| 3219 |
void DissectionSolver<double>:: |
| 3220 |
BuildSingCoefs(double *DSsingCoefs, |
| 3221 |
SparseMatrix<double> *DCsCoefs, |
| 3222 |
double *DBsCoefs, |
| 3223 |
vector<int>& singIdx, |
| 3224 |
const bool isTrans); |
| 3225 |
template |
| 3226 |
void DissectionSolver<complex<double>, double>:: |
| 3227 |
BuildSingCoefs(complex<double> *DSsingCoefs, |
| 3228 |
SparseMatrix<complex<double> > *DCsCoefs, |
| 3229 |
complex<double> *DBsCoefs, |
| 3230 |
vector<int>& singIdx, |
| 3231 |
const bool isTrans); |
| 3232 |
|
| 3233 |
template |
| 3234 |
void DissectionSolver<quadruple>:: |
| 3235 |
BuildSingCoefs(quadruple *DSsingCoefs, |
| 3236 |
SparseMatrix<quadruple> *DCsCoefs, |
| 3237 |
quadruple *DBsCoefs, |
| 3238 |
vector<int>& singIdx, |
| 3239 |
const bool isTrans); |
| 3240 |
template |
| 3241 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 3242 |
BuildSingCoefs(complex<quadruple> *DSsingCoefs, |
| 3243 |
SparseMatrix<complex<quadruple> > *DCsCoefs, |
| 3244 |
complex<quadruple> *DBsCoefs, |
| 3245 |
vector<int>& singIdx, |
| 3246 |
const bool isTrans); |
| 3247 |
|
| 3248 |
template |
| 3249 |
void DissectionSolver<float>:: |
| 3250 |
BuildSingCoefs(float *DSsingCoefs, |
| 3251 |
SparseMatrix<float> *DCsCoefs, |
| 3252 |
float *DBsCoefs, |
| 3253 |
vector<int>& singIdx, |
| 3254 |
const bool isTrans); |
| 3255 |
template |
| 3256 |
void DissectionSolver<complex<float>, float>:: |
| 3257 |
BuildSingCoefs(complex<float> *DSsingCoefs, |
| 3258 |
SparseMatrix<complex<float> > *DCsCoefs, |
| 3259 |
complex<float> *DBsCoefs, |
| 3260 |
vector<int>& singIdx, |
| 3261 |
const bool isTrans); |
| 3262 |
// |
| 3263 |
|
| 3264 |
template<typename T, typename U, typename W, typename Z> |
| 3265 |
void DissectionSolver<T, U, W, Z>:: |
| 3266 |
BuildKernels(vector<int> &singIdx_, |
| 3267 |
int n2, |
| 3268 |
SchurMatrix<T> &Schur, |
| 3269 |
KernelMatrix<T> &kernel) |
| 3270 |
{ |
| 3271 |
elapsed_t t0_elapsed, t1_elapsed; |
| 3272 |
// struct timespec ts0, ts1; |
| 3273 |
const int n0 = singIdx_.size(); |
| 3274 |
const int n1 = n0 - n2; // regular nodes |
| 3275 |
const int nsing = n2; // singIdx.size(); |
| 3276 |
ColumnMatrix<T> DBsCoefs(_dim, nsing); |
| 3277 |
diss_printf(_verbose, _fp, |
| 3278 |
"%s %d : BuildKernels n0 = %d n1 = %d n2 = %d\n", |
| 3279 |
__FILE__, __LINE__, n0, n1, n2); |
| 3280 |
if (n1 > 0) { |
| 3281 |
//IndiceArray regularVal(n1); |
| 3282 |
vector<int> regularVal; |
| 3283 |
regularVal.resize(n1); |
| 3284 |
// SparseMatrix<T>* ptDA_acol; |
| 3285 |
for (int i = 0; i < n1; i++) { |
| 3286 |
regularVal[i] = singIdx_[i]; |
| 3287 |
} |
| 3288 |
// to sort by increasing-order |
| 3289 |
std::sort(regularVal.begin(), regularVal.end()); //regularVal.renumber(); |
| 3290 |
Schur.getAcol() = _ptDA->PartialCopyCSR(regularVal, n1, true); |
| 3291 |
Schur.getArow() = _ptDA->PartialCopyCSR(regularVal, n1, false); |
| 3292 |
// nullify [ A_12 / A_22 / A_23 ] -> [ A_12 / 0 / 0 ] |
| 3293 |
for (int i = 0; i < n1; i++) { |
| 3294 |
for (int k = Schur.getAcol()->ptRow(i); |
| 3295 |
k < Schur.getAcol()->ptRow(i + 1); k++) { |
| 3296 |
// elimination from the CSR foramt is best for performance |
| 3297 |
for (int m = 0; m < n0; m++) { |
| 3298 |
if (Schur.getAcol()->indCol(k) == singIdx_[m]) { |
| 3299 |
Schur.getAcol()->Coef(k) = _zero; |
| 3300 |
} |
| 3301 |
} |
| 3302 |
} |
| 3303 |
} |
| 3304 |
|
| 3305 |
Schur.getScol().init(_dim, n1); |
| 3306 |
for (int j = 0; j < n1; j++) { |
| 3307 |
for (int i = 0; i < _dim; i++) { |
| 3308 |
Schur.getScol()(i, j) = _zero; // ZeroClear() |
| 3309 |
} |
| 3310 |
for (int k = Schur.getAcol()->ptRow(j); |
| 3311 |
k < Schur.getAcol()->ptRow(j + 1); k++) { |
| 3312 |
const int icol = Schur.getAcol()->indCol(k); |
| 3313 |
Schur.getScol()(icol, j) = Schur.getAcol()->Coef(k); |
| 3314 |
} |
| 3315 |
} |
| 3316 |
//IndiceArray s_list_eq(n1); // local -> global mapping |
| 3317 |
vector<int> s_list_eq; |
| 3318 |
s_list_eq.resize(n1); |
| 3319 |
for (int i = 0; i < n1; i++) { |
| 3320 |
s_list_eq[i] = regularVal[i]; |
| 3321 |
} |
| 3322 |
Schur.getSldu().init(s_list_eq); // ptDA_sldu.init |
| 3323 |
// _Schur.getScol() = [ A_11^-1 A_12 / 0 / 0 ] |
| 3324 |
SolveScaled(Schur.getScol().addrCoefs(), n1, false); |
| 3325 |
//Schur.getScol().addrCoefs(), n1, false); |
| 3326 |
|
| 3327 |
BuildSingCoefs(Schur.getSldu().addrCoefs(), //ptDA_sldu.addrCoefs(), |
| 3328 |
Schur.getArow(), |
| 3329 |
Schur.getScol().addrCoefs(), //Schur.getScol().addrCoefs(), |
| 3330 |
regularVal); |
| 3331 |
int *pivot_width = &(Schur.getSldu().getPivotWidth()[0]); //&ptDA_sldu.getPivotWidth()[0]; |
| 3332 |
T *d1 = Schur.getSldu().addr2x2(); |
| 3333 |
int *permute = &Schur.getSldu().getPermute()[0]; |
| 3334 |
#if 0 |
| 3335 |
full_sym_2x2BK<T>(n1, Schur.getSldu().addrCoefs(), d1, pivot_width, |
| 3336 |
permute); |
| 3337 |
// fprintf(_fp, "Bunch-Kaufman permutation : "); |
| 3338 |
diss_printf(_verbose, _fp, "%s %d : permutation for Schur complement: ", |
| 3339 |
__FILE__, __LINE__); |
| 3340 |
for (int i = 0; i < n1; i++) { |
| 3341 |
diss_printf(_verbose, _fp, "%3d ", pivot_width[i]); |
| 3342 |
} |
| 3343 |
diss_printf(_verbose, _fp, "\n"); |
| 3344 |
for (int i = 0; i < n1; i++) { |
| 3345 |
diss_printf(_verbose, _fp, "%3d ", permute[i]); |
| 3346 |
} |
| 3347 |
diss_printf(_verbose, _fp, "\n"); |
| 3348 |
Schur.getSlduList().resize(n1); |
| 3349 |
for (int i = 0; i < n1; i++) { |
| 3350 |
Schur.getSlduList()[i] = permute[i]; // ?? 20 Apr.2016 ?? |
| 3351 |
} |
| 3352 |
int itmp2x2 = 0; |
| 3353 |
for (int i = 0; i < n1; i++) { |
| 3354 |
if (pivot_width[i] == 20) { |
| 3355 |
itmp2x2++; |
| 3356 |
} |
| 3357 |
} |
| 3358 |
Schur.getSldu().getPivot2x2().resize(itmp2x2); |
| 3359 |
itmp2x2 = 0; |
| 3360 |
for (int i = 0; i < n1; i++) { |
| 3361 |
if (pivot_width[i] == 20) { |
| 3362 |
Schur.getSldu().getPivot2x2()[itmp2x2] = i; |
| 3363 |
itmp2x2++; |
| 3364 |
} |
| 3365 |
} |
| 3366 |
// 1x1 + 2x2 |
| 3367 |
// delete ptDA_acol; |
| 3368 |
#else |
| 3369 |
{ |
| 3370 |
int nn0, n0 = 0; |
| 3371 |
double fop, pivot_ref = 1.0; // should be automatically defined in ldlt/ldu |
| 3372 |
double eps_piv = machine_epsilon<double, double>(); |
| 3373 |
if (_ptDA->isSymmetric()) { |
| 3374 |
full_ldlt_permute<T, U>(&nn0, n0, n1, |
| 3375 |
Schur.getSldu().addrCoefs(), n1, |
| 3376 |
&pivot_ref, |
| 3377 |
permute, eps_piv, &fop); |
| 3378 |
} |
| 3379 |
else { |
| 3380 |
full_ldu_permute<T, U>(&nn0, n0, n1, |
| 3381 |
Schur.getSldu().addrCoefs(), n1, |
| 3382 |
&pivot_ref, |
| 3383 |
permute, eps_piv, &fop); |
| 3384 |
} |
| 3385 |
diss_printf(_verbose, _fp, |
| 3386 |
"%s %d : factorization with eps_piv = %g : dim kern = %d\n", |
| 3387 |
__FILE__, __LINE__, eps_piv, nn0); |
| 3388 |
diss_printf(_verbose, _fp, "permute[] = "); |
| 3389 |
for (int i = 0; i < n1; i++) { |
| 3390 |
diss_printf(_verbose, _fp, "%d ", permute[i]); |
| 3391 |
} |
| 3392 |
diss_printf(_verbose, _fp, "\n"); |
| 3393 |
} |
| 3394 |
Schur.getSlduList().resize(n1); |
| 3395 |
for (int i = 0; i < n1; i++) { |
| 3396 |
Schur.getSlduList()[i] = permute[i]; |
| 3397 |
} |
| 3398 |
#endif |
| 3399 |
} // if (n1 > 0) |
| 3400 |
else { // if (n1 == 0) |
| 3401 |
Schur.getAcol() = new SparseMatrix<T>(); // dummy allocation |
| 3402 |
Schur.getArow() = new SparseMatrix<T>(); // dummy allocation |
| 3403 |
Schur.getSlduList().clear(); |
| 3404 |
} // if (n1 > 0) |
| 3405 |
|
| 3406 |
if (n2 == 0) { |
| 3407 |
kernel.set_dimension(0); |
| 3408 |
kernel.getKernProj().init(0); |
| 3409 |
kernel.getKernBasis().init(0, 0); |
| 3410 |
} |
| 3411 |
else { |
| 3412 |
SparseMatrix<T> *DCsCoefs; |
| 3413 |
vector<int> singIdx; |
| 3414 |
singIdx.resize(n2); |
| 3415 |
for (int i = 0; i < n2; i++) { |
| 3416 |
singIdx[i] = singIdx_[n0 - n2 + i]; |
| 3417 |
} |
| 3418 |
// to sort by increasing-order |
| 3419 |
std::sort(singIdx.begin(), singIdx.end()); // singIdx.renumber(); |
| 3420 |
//DCsCoefs = PartialCopyCSR(_ptDA, singIdx, nsing, true); |
| 3421 |
DCsCoefs = _ptDA->PartialCopyCSR(singIdx, nsing, true); // 28 Dec.2015 |
| 3422 |
// clear element of DBsCoefs belonging to diagnal block |
| 3423 |
for (int i = 0; i < nsing; i++) { |
| 3424 |
for (int k = DCsCoefs->ptRow(i); k < DCsCoefs->ptRow(i + 1); k++) { |
| 3425 |
// elimination from the CSR foramt is best for performance |
| 3426 |
for (int m = 0; m < nsing; m++) { |
| 3427 |
if (DCsCoefs->indCol(k) == singIdx[m]) { |
| 3428 |
DCsCoefs->Coef(k) = _zero; |
| 3429 |
} |
| 3430 |
} |
| 3431 |
} |
| 3432 |
} |
| 3433 |
diss_printf(_verbose, _fp, |
| 3434 |
"%s %d : Cs matrix: row = %d\n", |
| 3435 |
__FILE__, __LINE__, nsing); |
| 3436 |
// generate DBsCoefs[] |
| 3437 |
// copy from lower part (sparse) with transporse to upper part (dense) |
| 3438 |
DBsCoefs.ZeroClear(); |
| 3439 |
for (int j = 0; j < nsing; j++) { |
| 3440 |
for (int k = DCsCoefs->ptRow(j); k < DCsCoefs->ptRow(j + 1); k++) { |
| 3441 |
const int icol = DCsCoefs->indCol(k); |
| 3442 |
DBsCoefs(icol, j) = DCsCoefs->Coef(k); |
| 3443 |
} |
| 3444 |
} |
| 3445 |
// access with stride size _dim |
| 3446 |
for (int i = 0; i < nsing; i++) { |
| 3447 |
for (int j = 0; j < nsing; j++) { |
| 3448 |
DBsCoefs(singIdx[i], j) = _zero; |
| 3449 |
} |
| 3450 |
} |
| 3451 |
diss_printf(_verbose, _fp, |
| 3452 |
"%s %d Bs matrix: singular columns of global matrix %d x %d\n", |
| 3453 |
__FILE__, __LINE__, |
| 3454 |
_dim, nsing); |
| 3455 |
// Compute Am-1*Bs |
| 3456 |
// scaling flag is off : internal solver A_11^-1 [A^12 A^13] |
| 3457 |
if (n1 > 0) { |
| 3458 |
ColumnMatrix<T> yy(n1, nsing); |
| 3459 |
ColumnMatrix<T> yy1(n1, nsing); |
| 3460 |
for (int m = 0; m < nsing; m++) { |
| 3461 |
for (int i = 0; i < n1; i++) { |
| 3462 |
int ii = Schur.getSldu().loc2glob()[i]; |
| 3463 |
// yy[i + m * n1] = DBsCoefs[ii + m * _dim]; save data of singular nds |
| 3464 |
// DBsCoefs[ii + m * _dim] = zero; SolveScaled works for regular nodes |
| 3465 |
yy(i, m) = DBsCoefs(ii, m); |
| 3466 |
DBsCoefs(ii, m) = _zero; |
| 3467 |
} |
| 3468 |
} // loop : j |
| 3469 |
get_realtime(&t0_elapsed); |
| 3470 |
SolveScaled(DBsCoefs.addrCoefs(), nsing, false); |
| 3471 |
get_realtime(&t1_elapsed); |
| 3472 |
diss_printf(_verbose, _fp, |
| 3473 |
"%s %d : dissection solve : %d RHS (sec.) = %.6f\n", |
| 3474 |
__FILE__, __LINE__, nsing, |
| 3475 |
convert_time(t1_elapsed, t0_elapsed)); |
| 3476 |
for (int m = 0; m < nsing; m++) { // Block SpMV |
| 3477 |
for (int i = 0; i < n1; i++) { |
| 3478 |
T stmp(0.0); // = _zero; |
| 3479 |
const int ii = Schur.getSlduList()[i]; |
| 3480 |
for (int k = Schur.getArow()->ptRow(ii); |
| 3481 |
k < Schur.getArow()->ptRow(ii + 1); |
| 3482 |
k++) { |
| 3483 |
const int j = Schur.getArow()->indCol(k); |
| 3484 |
stmp += Schur.getArow()->Coef(k) * DBsCoefs(j, m); |
| 3485 |
} |
| 3486 |
yy(i, m) -= stmp; |
| 3487 |
} |
| 3488 |
} // loop : m |
| 3489 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 3490 |
n1, nsing, _one, // alpha |
| 3491 |
Schur.getSldu().addrCoefs(), n1, |
| 3492 |
yy.addrCoefs(), n1); |
| 3493 |
|
| 3494 |
for (int i = 0; i < n1; i++) { |
| 3495 |
T stmp = Schur.getSldu()(i, i); |
| 3496 |
for (int m = 0; m < nsing; m++) { |
| 3497 |
yy1(i, m) = yy(i, m) * stmp; // should be optimized |
| 3498 |
} // loop : m |
| 3499 |
} |
| 3500 |
for (int i = 0; i < Schur.getSldu().getPivot2x2().size(); i++) { |
| 3501 |
const int ii = Schur.getSldu().getPivot2x2()[i]; |
| 3502 |
T *d1 = Schur.getSldu().addr2x2(); |
| 3503 |
for (int m = 0; m < nsing; m++) { |
| 3504 |
yy1(ii, m) += d1[m] * yy((i + 1), m); |
| 3505 |
yy1((ii + 1), m) += d1[m + 1] * yy(i, m); |
| 3506 |
} |
| 3507 |
} |
| 3508 |
yy.copy(yy1); |
| 3509 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 3510 |
n1, nsing, _one, |
| 3511 |
Schur.getSldu().addrCoefs(), n1, |
| 3512 |
yy.addrCoefs(), n1); |
| 3513 |
for (int i = 0; i < n1; i++) { |
| 3514 |
const int ii = Schur.getSldu().loc2glob()[i]; |
| 3515 |
for (int m = 0; m < nsing; m++) { |
| 3516 |
DBsCoefs(ii, m) = yy(i, m); |
| 3517 |
} // loop : m |
| 3518 |
} |
| 3519 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 3520 |
_dim, nsing, n1, |
| 3521 |
_none, // alpha |
| 3522 |
Schur.getScol().addrCoefs(), _dim, |
| 3523 |
yy.addrCoefs(), n1, |
| 3524 |
_one, // beta |
| 3525 |
DBsCoefs.addrCoefs(), _dim); |
| 3526 |
} // if (n1 > 0) |
| 3527 |
else { |
| 3528 |
get_realtime(&t0_elapsed); |
| 3529 |
SolveScaled(DBsCoefs.addrCoefs(), nsing, false); |
| 3530 |
get_realtime(&t1_elapsed); |
| 3531 |
diss_printf(_verbose, _fp, |
| 3532 |
"%s %d : dissection solve : %d RHS (sec.) = %.6f\n", |
| 3533 |
__FILE__, __LINE__, nsing, |
| 3534 |
convert_time(t1_elapsed, t0_elapsed)); |
| 3535 |
} |
| 3536 |
// clear diagonal blocks of Bs in the place of Schur complement |
| 3537 |
for (int i = 0; i < nsing; i++) { |
| 3538 |
DBsCoefs(singIdx[i], i) = _none; |
| 3539 |
} |
| 3540 |
|
| 3541 |
kernel.getKernListEq().resize(nsing); // = IndiceArray(nsing); |
| 3542 |
for (int i = 0; i < nsing; i++) { |
| 3543 |
kernel.getKernListEq()[i]= singIdx[i]; |
| 3544 |
} |
| 3545 |
diss_printf(_verbose, _fp, |
| 3546 |
"%s %d : kern_list_eq[] = ", |
| 3547 |
__FILE__, __LINE__); |
| 3548 |
for (int i = 0; i < kernel.getKernListEq().size(); i++) { |
| 3549 |
diss_printf(_verbose, _fp, "%d ", kernel.getKernListEq()[i]); |
| 3550 |
} |
| 3551 |
diss_printf(_verbose, _fp, "\n"); |
| 3552 |
|
| 3553 |
kernel.getKernBasis().init(_dim, nsing); |
| 3554 |
T *kern_basis = kernel.getKernBasis().addrCoefs(); |
| 3555 |
kernel.getKernBasis().copy(DBsCoefs); |
| 3556 |
// normalize each kernel_basis |
| 3557 |
for (int j = 0; j < nsing; j++) { |
| 3558 |
U stmp(0.0); |
| 3559 |
const U one(1.0); |
| 3560 |
stmp = one / blas_l2norm<T, U>(_dim, (kern_basis + (j * _dim)), 1); |
| 3561 |
blas_scal2<T, U>(_dim, stmp, (kern_basis + (j * _dim)), 1); |
| 3562 |
} |
| 3563 |
diss_printf(_verbose, _fp, |
| 3564 |
"%s %d : check kern_basis belonging to the kernel of A\n", |
| 3565 |
__FILE__, __LINE__); |
| 3566 |
VectorArray<T> v(_dim); |
| 3567 |
diss_printf(_verbose, _fp, |
| 3568 |
"%s %d : orthogonality of the kernel vectors\n", |
| 3569 |
__FILE__, __LINE__); |
| 3570 |
for (int j = 0; j < nsing; j++) { |
| 3571 |
_ptDA->prod((kern_basis + (j * _dim)), v.addrCoefs()); |
| 3572 |
double norm_l2, norm_infty; |
| 3573 |
calc_relative_norm<T>(&norm_l2, &norm_infty, v.addrCoefs(), |
| 3574 |
kern_basis + (j * _dim), _dim); |
| 3575 |
diss_printf(_verbose, _fp, |
| 3576 |
"%d-th kernel scaled : l2_norm = %.6e, infty_norm = %.6e / ", |
| 3577 |
j, norm_l2, norm_infty); |
| 3578 |
if(_scaling) { |
| 3579 |
calc_relative_normscaled<T, U>(&norm_l2, &norm_infty, |
| 3580 |
v.addrCoefs(), |
| 3581 |
kern_basis + (j * _dim), |
| 3582 |
&_precDiag[0], _dim); |
| 3583 |
diss_printf(_verbose, _fp, |
| 3584 |
"original : l2_norm = %.6e, infty_norm = %.6e\n", |
| 3585 |
norm_l2, norm_infty); |
| 3586 |
} // if (_scaling) |
| 3587 |
diss_printf(_verbose, _fp, "\n"); |
| 3588 |
} |
| 3589 |
#ifdef DEBUG_DATA |
| 3590 |
fout.close(); |
| 3591 |
#endif |
| 3592 |
|
| 3593 |
if(_scaling) { |
| 3594 |
for (int j = 0; j < nsing; j++) { |
| 3595 |
const int jtmp = j * _dim; |
| 3596 |
for (int i = 0; i < _dim; i++) { |
| 3597 |
kern_basis[i + jtmp] *= _precDiag[i]; |
| 3598 |
} |
| 3599 |
} |
| 3600 |
} |
| 3601 |
#ifdef NORMALIZE_KERNEL_BASIS |
| 3602 |
// normalize each kernel_basis |
| 3603 |
for (int j = 0; j < nsing; j++) { |
| 3604 |
U stmp(0.0); |
| 3605 |
const U one(1.0); |
| 3606 |
stmp = one / blas_l2norm<T, U>(_dim, (kern_basis + (j * _dim)), 1); |
| 3607 |
blas_scal2<T, U>(_dim, stmp, (kern_basis + (j * _dim)), 1); |
| 3608 |
} |
| 3609 |
#endif |
| 3610 |
kernel.set_dimension(nsing); |
| 3611 |
kernel.getKernProj().init(nsing); |
| 3612 |
|
| 3613 |
for (int i = 0; i < nsing; i++) { |
| 3614 |
for(int j = i; j < nsing; j++) { |
| 3615 |
kernel.getKernProj()(i, j) = blas_dot<T>(_dim, |
| 3616 |
(kern_basis + (i * _dim)), 1, |
| 3617 |
(kern_basis + (j * _dim)), 1); |
| 3618 |
} |
| 3619 |
// symmetrize |
| 3620 |
for (int j = (i + 1); j < nsing; j++) { |
| 3621 |
kernel.getKernProj()(j, i) = kernel.getKernProj()(i, j); |
| 3622 |
} |
| 3623 |
} |
| 3624 |
full_ldlh<T>(nsing, kernel.getKernProj().addrCoefs(), nsing); |
| 3625 |
// inverse of diagonal part is also storead in the factorized matrix |
| 3626 |
delete DCsCoefs; |
| 3627 |
} // if (n2 == 0) |
| 3628 |
// delete [] DBsCoefs; |
| 3629 |
} |
| 3630 |
|
| 3631 |
template |
| 3632 |
void DissectionSolver<double>:: |
| 3633 |
BuildKernels(vector<int> &singIdx_, |
| 3634 |
int n2, |
| 3635 |
SchurMatrix<double> &Schur, |
| 3636 |
KernelMatrix<double> &kernel); |
| 3637 |
|
| 3638 |
template |
| 3639 |
void DissectionSolver<complex<double>, double>:: |
| 3640 |
BuildKernels(vector<int> &singIdx_, |
| 3641 |
int n2, |
| 3642 |
SchurMatrix<complex<double> > &Schur, |
| 3643 |
KernelMatrix<complex<double> > &kernel); |
| 3644 |
|
| 3645 |
template |
| 3646 |
void DissectionSolver<quadruple>:: |
| 3647 |
BuildKernels(vector<int> &singIdx_, |
| 3648 |
int n2, |
| 3649 |
SchurMatrix<quadruple> &Schur, |
| 3650 |
KernelMatrix<quadruple> &kernel); |
| 3651 |
|
| 3652 |
template |
| 3653 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 3654 |
BuildKernels(vector<int> &singIdx_, |
| 3655 |
int n2, |
| 3656 |
SchurMatrix<complex<quadruple> > &Schur, |
| 3657 |
KernelMatrix<complex<quadruple> > &kernel); |
| 3658 |
|
| 3659 |
template |
| 3660 |
void DissectionSolver<float>:: |
| 3661 |
BuildKernels(vector<int> &singIdx_, |
| 3662 |
int n2, |
| 3663 |
SchurMatrix<float> &Schur, |
| 3664 |
KernelMatrix<float> &kernel); |
| 3665 |
|
| 3666 |
template |
| 3667 |
void DissectionSolver<complex<float>, float>:: |
| 3668 |
BuildKernels(vector<int> &singIdx_, |
| 3669 |
int n2, |
| 3670 |
SchurMatrix<complex<float> > &Schur, |
| 3671 |
KernelMatrix<complex<float> > &kernel); |
| 3672 |
|
| 3673 |
// |
| 3674 |
|
| 3675 |
template<typename T, typename U, typename W, typename Z> |
| 3676 |
void DissectionSolver<T, U, W, Z>:: |
| 3677 |
BuildKernelsDetection(int &n0, |
| 3678 |
vector<int> &singIdx, |
| 3679 |
vector<vector<int> >& augkern_indexes, |
| 3680 |
vector<SquareBlockMatrix<T>* >& diags, |
| 3681 |
const double eps_piv, |
| 3682 |
const int dim_augkern, |
| 3683 |
SchurMatrix<T> &Schur, |
| 3684 |
KernelMatrix<T> &kernel, |
| 3685 |
const bool enableDetection) |
| 3686 |
{ |
| 3687 |
elapsed_t t0_elapsed, t1_elapsed, t2_elapsed, t3_elapsed; |
| 3688 |
// struct timespec ts0, ts1, ts2, ts3; |
| 3689 |
|
| 3690 |
// vector<int>& singIdx = singIdx; // singIdx is inherited from older version |
| 3691 |
const int nsing = singIdx.size(); |
| 3692 |
ColumnMatrix<T> DBsCoefs(_dim, nsing); |
| 3693 |
ColumnMatrix<T> DCsCoefs(_dim, nsing); |
| 3694 |
ColumnMatrix<T> DSsingCoefs(nsing, nsing); |
| 3695 |
ColumnMatrix<T> DSsingCoefs0(nsing, nsing); |
| 3696 |
ColumnMatrix<T> DSsingCoefs1; |
| 3697 |
ColumnMatrix<T> DSsingCoefs2(nsing, nsing); |
| 3698 |
ColumnMatrix<T> DSsingCoefs3(nsing, nsing); |
| 3699 |
ColumnMatrix<T> DS0(nsing, nsing); |
| 3700 |
ColumnMatrix<T> DS2(nsing, nsing); |
| 3701 |
double pivot_ref; |
| 3702 |
int *permute0 = new int[nsing]; |
| 3703 |
VectorArray<T> u(_dim); |
| 3704 |
VectorArray<T> v(_dim); |
| 3705 |
// |
| 3706 |
VectorArray<T> save_diag(dim_augkern); |
| 3707 |
{ |
| 3708 |
int i = 0; |
| 3709 |
diss_printf(_verbose, _fp, |
| 3710 |
"%s %d : nullifying diagonal entries\n", |
| 3711 |
__FILE__, __LINE__); |
| 3712 |
typename vector<SquareBlockMatrix<T>* >::const_iterator kt = diags.begin(); |
| 3713 |
for (vector<vector<int> >::const_iterator it = augkern_indexes.begin(); |
| 3714 |
it != augkern_indexes.end(); ++it, ++kt) { |
| 3715 |
SquareBlockMatrix<T> &diag = *(*kt); |
| 3716 |
const int n0_diag = diag.rank(); |
| 3717 |
diss_printf(_verbose, _fp, "diagonal entries modifed : %d -> %d\n", |
| 3718 |
n0_diag, n0_diag - (int)(*it).size()); |
| 3719 |
for (vector<int>::const_iterator jt = (*it).begin(); jt != (*it).end(); |
| 3720 |
++jt) { |
| 3721 |
diss_printf(_verbose, _fp, "%d : %s\n", |
| 3722 |
*jt, tostring<T>(diag.diag(*jt)).c_str()); |
| 3723 |
save_diag[i++] = diag.diag((*jt)); |
| 3724 |
diag.diag((*jt)) = _zero; |
| 3725 |
} |
| 3726 |
diag.set_rank(n0_diag - (*it).size()); |
| 3727 |
} |
| 3728 |
} |
| 3729 |
// singIdx is sorted with increasing-order |
| 3730 |
Schur.getAcol() = _ptDA->PartialCopyCSR(singIdx, nsing, true); // 28 Dec.2015 |
| 3731 |
Schur.getArow() = _ptDA->PartialCopyCSR(singIdx, nsing, false); // 28 Dec.2015 |
| 3732 |
// nullify diagonal blocks of singular nodes |
| 3733 |
// [A_21 A_22 A_23 / A_31 A_32 A_33 ] -> [A_21 0 0 / A_31 0 0 ] |
| 3734 |
// elimination of CSR entries is best for performance, but now replacing by 0 |
| 3735 |
{ // scope of acol |
| 3736 |
SparseMatrix<T> *acol = Schur.getAcol(); |
| 3737 |
SparseMatrix<T> *arow = Schur.getArow(); |
| 3738 |
for (int i = 0; i < nsing; i++) { |
| 3739 |
for (int k = acol->ptRow(i); k < acol->ptRow(i + 1); k++) { |
| 3740 |
for (int n = 0; n < nsing; n++) { |
| 3741 |
if (acol->indCol(k) == singIdx[n]) { |
| 3742 |
acol->Coef(k) = _zero; |
| 3743 |
} |
| 3744 |
} |
| 3745 |
} |
| 3746 |
for (int k = arow->ptRow(i); k < arow->ptRow(i + 1); k++) { |
| 3747 |
for (int n = 0; n < nsing; n++) { |
| 3748 |
if (arow->indCol(k) == singIdx[n]) { |
| 3749 |
arow->Coef(k) = _zero; |
| 3750 |
} |
| 3751 |
} |
| 3752 |
} |
| 3753 |
} |
| 3754 |
diss_printf(_verbose, _fp, |
| 3755 |
"%s %d : Cs matrix: from global sparse matrix : row = %d\n", |
| 3756 |
__FILE__, __LINE__, nsing); |
| 3757 |
// generate DBsCoefs[] |
| 3758 |
// copy from lower part (sparse) with transporse to upper part (dense) |
| 3759 |
DBsCoefs.ZeroClear(); |
| 3760 |
for (int j = 0; j < nsing; j++) { |
| 3761 |
for (int k = acol->ptRow(j); k < acol->ptRow(j + 1); k++) { |
| 3762 |
const int icol = acol->indCol(k); |
| 3763 |
DBsCoefs(icol, j) = acol->Coef(k); |
| 3764 |
} |
| 3765 |
} |
| 3766 |
DCsCoefs.ZeroClear(); |
| 3767 |
for (int j = 0; j < nsing; j++) { |
| 3768 |
for (int k = arow->ptRow(j); k < arow->ptRow(j + 1); k++) { |
| 3769 |
const int icol = arow->indCol(k); |
| 3770 |
DCsCoefs(icol, j) = arow->Coef(k); |
| 3771 |
} |
| 3772 |
} |
| 3773 |
} // scope of acol |
| 3774 |
diss_printf(_verbose, _fp, |
| 3775 |
"%s %d : Bs matrix: from global sparse matrix %d x %d\n", |
| 3776 |
__FILE__, __LINE__, _dim, nsing); |
| 3777 |
|
| 3778 |
// Compute Am-1*Bs |
| 3779 |
// scaling flag is off : internal solver A_11^-1 [A^12 A^13] |
| 3780 |
get_realtime(&t0_elapsed); |
| 3781 |
// clock_gettime(CLOCK_REALdoubleIME, &ts0); |
| 3782 |
SolveScaled(DBsCoefs.addrCoefs(), nsing, false); |
| 3783 |
if (!_ptDA->isSymmetric()) { |
| 3784 |
SolveScaled(DCsCoefs.addrCoefs(), nsing, true); |
| 3785 |
} |
| 3786 |
get_realtime(&t1_elapsed); |
| 3787 |
// clock_gettime(CLOCK_REALTIME, &ts1); |
| 3788 |
diss_printf(_verbose, _fp, |
| 3789 |
"%s %d : dissection solve : %d RHS (sec.) = %.6f\n", |
| 3790 |
__FILE__, __LINE__, |
| 3791 |
nsing, convert_time(t1_elapsed, t0_elapsed)); |
| 3792 |
|
| 3793 |
BuildSingCoefs(DSsingCoefs.addrCoefs(), |
| 3794 |
Schur.getArow(), DBsCoefs.addrCoefs(), singIdx); |
| 3795 |
if (!_ptDA->isSymmetric()) { |
| 3796 |
BuildSingCoefs(DSsingCoefs2.addrCoefs(), |
| 3797 |
Schur.getAcol(), DCsCoefs.addrCoefs(), singIdx, true); |
| 3798 |
} |
| 3799 |
// copy DSsingCoefs |
| 3800 |
DS0.copy(DSsingCoefs); |
| 3801 |
DS2.copy(DSsingCoefs2); |
| 3802 |
// set candidate of kernel vectors before applying Schur complement on |
| 3803 |
// regular part of suspicious pivots |
| 3804 |
for (int i = 0; i < nsing; i++) { |
| 3805 |
DBsCoefs(singIdx[i], i) = _none; |
| 3806 |
DCsCoefs(singIdx[i], i) = _none; |
| 3807 |
} |
| 3808 |
get_realtime(&t2_elapsed); |
| 3809 |
DSsingCoefs0.copy(DSsingCoefs); |
| 3810 |
|
| 3811 |
diss_printf(_verbose, _fp, |
| 3812 |
"%s %d : DSsingCoefs0[]\n", |
| 3813 |
__FILE__, __LINE__); |
| 3814 |
for (int i = 0; i < nsing; i++) { |
| 3815 |
for (int j = 0; j < nsing; j++) { |
| 3816 |
diss_printf(_verbose, _fp, "%s ", |
| 3817 |
tostring<T>(DSsingCoefs0(i, j)).c_str()); |
| 3818 |
} |
| 3819 |
diss_printf(_verbose, _fp, "\n"); |
| 3820 |
} |
| 3821 |
if (!_ptDA->isSymmetric()) { |
| 3822 |
diss_printf(_verbose, _fp, |
| 3823 |
"%s %d : transposed DSsingCoefs2[]\n", |
| 3824 |
__FILE__, __LINE__); |
| 3825 |
for (int i = 0; i < nsing; i++) { |
| 3826 |
for (int j = 0; j < nsing; j++) { |
| 3827 |
diss_printf(_verbose, _fp, "%s ", |
| 3828 |
tostring<T>(DSsingCoefs2(j, i)).c_str()); |
| 3829 |
} |
| 3830 |
diss_printf(_verbose, _fp, "\n"); |
| 3831 |
} |
| 3832 |
diss_printf(_verbose, _fp, |
| 3833 |
"%s %d : unsymmetry\n", |
| 3834 |
__FILE__, __LINE__); |
| 3835 |
for (int i = 0; i < nsing; i++) { |
| 3836 |
for (int j = 0; j < nsing; j++) { |
| 3837 |
diss_printf(_verbose, _fp, "%s ", |
| 3838 |
tostring<T>(DSsingCoefs0(i, j) - DSsingCoefs2(j, i)).c_str()); |
| 3839 |
} |
| 3840 |
diss_printf(_verbose, _fp, "\n"); |
| 3841 |
} |
| 3842 |
} |
| 3843 |
bool flag_unsym_permute = false; |
| 3844 |
if (enableDetection) { |
| 3845 |
pivot_ref = 0.0; |
| 3846 |
for (int i = 0; i < nsing; i++) { // find maximum of abs value of diagonal |
| 3847 |
const double stmp = blas_abs<T, double>(DSsingCoefs0(i, i)); |
| 3848 |
pivot_ref = stmp > pivot_ref ? stmp : pivot_ref; |
| 3849 |
} |
| 3850 |
|
| 3851 |
diss_printf(_verbose, _fp, |
| 3852 |
"%s %d : pviot_ref = %.8e\n", |
| 3853 |
__FILE__, __LINE__, pivot_ref); |
| 3854 |
|
| 3855 |
// permute0[] is initialized in ddfull_sym_gauss_part |
| 3856 |
int nn = 0; |
| 3857 |
{ |
| 3858 |
int nn0; |
| 3859 |
double fop; |
| 3860 |
if (_ptDA->isSymmetric()) { |
| 3861 |
full_ldlt_permute<T, U>(&nn0, nn, nsing, |
| 3862 |
DSsingCoefs0.addrCoefs(), nsing, |
| 3863 |
&pivot_ref, |
| 3864 |
permute0, eps_piv, &fop); |
| 3865 |
} |
| 3866 |
else { |
| 3867 |
full_ldu_permute<T, U>(&nn0, nn, nsing, |
| 3868 |
DSsingCoefs0.addrCoefs(), nsing, |
| 3869 |
&pivot_ref, |
| 3870 |
permute0, eps_piv, &fop); |
| 3871 |
} |
| 3872 |
nn = nn0; |
| 3873 |
} |
| 3874 |
diss_printf(_verbose, _fp, |
| 3875 |
"%s %d : factorization with eps_piv = %g : dim kern = %d\n", |
| 3876 |
__FILE__, __LINE__, eps_piv, nn); |
| 3877 |
diss_printf(_verbose, _fp, "permute[] = "); |
| 3878 |
for (int i = 0; i < nsing; i++) { |
| 3879 |
diss_printf(_verbose, _fp, "%d ", permute0[i]); |
| 3880 |
} |
| 3881 |
diss_printf(_verbose, _fp, "\n"); |
| 3882 |
#if 0 |
| 3883 |
diss_printf(_verbose, _fp, |
| 3884 |
"%s %d : DSsingCoefs0[]\n", |
| 3885 |
__FILE__, __LINE__); |
| 3886 |
for (int i = 0; i < nsing; i++) { |
| 3887 |
for (int j = 0; j < nsing; j++) { |
| 3888 |
diss_printf(_verbose, _fp, "%s ", |
| 3889 |
tostring<T>(DSsingCoefs0(i, j)).c_str()); |
| 3890 |
} |
| 3891 |
diss_printf(_verbose, _fp, "\n"); |
| 3892 |
} |
| 3893 |
#endif |
| 3894 |
if (nn == 0) { |
| 3895 |
n0 = 0; |
| 3896 |
} |
| 3897 |
else { |
| 3898 |
const int nsing1 = nn + dim_augkern; |
| 3899 |
const int nsing0 = nsing - nsing1; |
| 3900 |
DSsingCoefs1.init(nsing1, nsing1); |
| 3901 |
if (nsing0 == 0) { |
| 3902 |
DSsingCoefs1.copy(DSsingCoefs); |
| 3903 |
} |
| 3904 |
else{ // recompute smaller Schur complement with size nsing1 |
| 3905 |
|
| 3906 |
// nullify rows and columns |
| 3907 |
for (int j = nsing0; j < nsing; j++) { |
| 3908 |
for (int i = 0; i < nsing; i++) { |
| 3909 |
DSsingCoefs0(i, j) = _zero; |
| 3910 |
DSsingCoefs0(j, i) = _zero; |
| 3911 |
} |
| 3912 |
} |
| 3913 |
// copy upper block |
| 3914 |
for (int j = nsing0; j < nsing; j++) { |
| 3915 |
for (int i = 0; i < nsing0; i++) { |
| 3916 |
DSsingCoefs0(i, j) = DSsingCoefs(permute0[i], permute0[j]); |
| 3917 |
} |
| 3918 |
} |
| 3919 |
if (_ptDA->isSymmetric()) { |
| 3920 |
int ii = nsing0; |
| 3921 |
for (int i = 0; i < nsing1; i++, ii++) { |
| 3922 |
int jj = nsing0; |
| 3923 |
for (int j = 0; j <= i; j++, jj++) { |
| 3924 |
DSsingCoefs1(i, j) = DSsingCoefs(permute0[ii], permute0[jj]); |
| 3925 |
} |
| 3926 |
// symmetrize |
| 3927 |
for (int j = 0; j < i; j++) { |
| 3928 |
DSsingCoefs1(j, i) = DSsingCoefs1(i, j); |
| 3929 |
} |
| 3930 |
} |
| 3931 |
} |
| 3932 |
else { |
| 3933 |
int ii = nsing0; |
| 3934 |
for (int i = 0; i < nsing1; i++, ii++) { |
| 3935 |
int jj = nsing0; |
| 3936 |
for (int j = 0; j < nsing1; j++, jj++) { |
| 3937 |
DSsingCoefs1(i, j) = DSsingCoefs(permute0[ii], permute0[jj]); |
| 3938 |
} |
| 3939 |
} |
| 3940 |
// copy lower block |
| 3941 |
for (int j = 0; j < nsing0; j++) { |
| 3942 |
for (int i = nsing0; i < nsing; i++) { |
| 3943 |
DSsingCoefs0(i, j) = DSsingCoefs(permute0[i], permute0[j]); |
| 3944 |
} |
| 3945 |
} |
| 3946 |
} |
| 3947 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 3948 |
nsing0, nsing1, |
| 3949 |
_one, // alpha |
| 3950 |
DSsingCoefs0.addrCoefs(), nsing, |
| 3951 |
DSsingCoefs0.addrCoefs() + (nsing0 * nsing), nsing); |
| 3952 |
if (_ptDA->isSymmetric()) { |
| 3953 |
for (int j = nsing0; j < nsing; j++) { |
| 3954 |
for (int i = 0; i < nsing0; i++) { |
| 3955 |
DSsingCoefs0(j, i) = DSsingCoefs0(i, j); |
| 3956 |
} |
| 3957 |
} |
| 3958 |
} |
| 3959 |
else { |
| 3960 |
blas_trsm<T>(CblasRight, CblasUpper, CblasNoTrans, CblasUnit, |
| 3961 |
nsing1, nsing0, |
| 3962 |
_one, // alpha |
| 3963 |
DSsingCoefs0.addrCoefs(), nsing, |
| 3964 |
DSsingCoefs0.addrCoefs() + nsing0, nsing); |
| 3965 |
} // if (_ptDA->isSymmetric()) |
| 3966 |
// scaling upper block by diagonal |
| 3967 |
for (int j = nsing0; j < nsing; j++) { |
| 3968 |
for (int i = 0; i < nsing0; i++) { |
| 3969 |
DSsingCoefs0(i, j) *= DSsingCoefs0(i, i); |
| 3970 |
} |
| 3971 |
} |
| 3972 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 3973 |
nsing1, nsing1, nsing0, |
| 3974 |
_none, // alpha |
| 3975 |
DSsingCoefs0.addrCoefs() + nsing0, nsing, |
| 3976 |
DSsingCoefs0.addrCoefs() + (nsing0 * nsing), nsing, |
| 3977 |
_one, // beta |
| 3978 |
DSsingCoefs1.addrCoefs(), nsing1); |
| 3979 |
if (_ptDA->isSymmetric()) { // symmetrize |
| 3980 |
for (int j = 0; j < nsing1; j++) { |
| 3981 |
for (int i = 0; i < j; i++) { |
| 3982 |
// DSsingCoefs1[j + i * nsing1] = DSsingCoefs1[i + j * nsing1]; |
| 3983 |
DSsingCoefs1(j, i) = DSsingCoefs1(i, j); |
| 3984 |
} |
| 3985 |
} |
| 3986 |
} |
| 3987 |
diss_printf(_verbose, _fp, |
| 3988 |
"%s %d : DSsingCoefs1[]\n", |
| 3989 |
__FILE__, __LINE__); |
| 3990 |
for (int i = 0; i < nsing1; i++) { |
| 3991 |
for (int j = 0; j < nsing1; j++) { |
| 3992 |
diss_printf(_verbose,_fp, "%s ", |
| 3993 |
tostring<T>(DSsingCoefs1(i, j)).c_str()); |
| 3994 |
} |
| 3995 |
diss_printf(_verbose, _fp, "\n"); |
| 3996 |
} |
| 3997 |
} // if (nsing0 <= 0) |
| 3998 |
bool flag; |
| 3999 |
const U eps_machine = machine_epsilon<U, Z>(); |
| 4000 |
DSsingCoefs3.copy(DSsingCoefs2); |
| 4001 |
int n0n, n0t; |
| 4002 |
flag = ComputeDimKernel<T, U>(&n0n, &flag_unsym_permute, |
| 4003 |
DSsingCoefs1.addrCoefs(), nsing1, |
| 4004 |
_ptDA->isSymmetric(), |
| 4005 |
dim_augkern, |
| 4006 |
eps_machine, |
| 4007 |
eps_piv, |
| 4008 |
_verbose, |
| 4009 |
_fp); |
| 4010 |
|
| 4011 |
flag = ComputeDimKernel<T, U>(&n0t, &flag_unsym_permute, |
| 4012 |
DSsingCoefs3.addrCoefs(), nsing1, |
| 4013 |
_ptDA->isSymmetric(), |
| 4014 |
dim_augkern, |
| 4015 |
eps_machine, |
| 4016 |
eps_piv, |
| 4017 |
_verbose, |
| 4018 |
_fp); |
| 4019 |
|
| 4020 |
n0 = n0t > n0n ? n0t : n0n; |
| 4021 |
// n0 = n0n; |
| 4022 |
if (flag == false) { |
| 4023 |
fprintf(stderr, |
| 4024 |
"%s %d : ERROR: kernel detection failed!\n", |
| 4025 |
__FILE__, __LINE__); |
| 4026 |
//exit(-1); |
| 4027 |
} |
| 4028 |
if (_assume_invertible) { |
| 4029 |
n0 = 0; |
| 4030 |
} |
| 4031 |
} // if (nn > 0) |
| 4032 |
|
| 4033 |
delete [] permute0; |
| 4034 |
get_realtime(&t3_elapsed); |
| 4035 |
// clock_gettime(CLOCK_REALTIME, &ts3); |
| 4036 |
diss_printf(_verbose, _fp, |
| 4037 |
"%s %d : detection of the _dim. of the kernel (sec.) = %.6f\n", |
| 4038 |
__FILE__, __LINE__, |
| 4039 |
convert_time(t3_elapsed, t2_elapsed)); |
| 4040 |
} // if (enableDetection) |
| 4041 |
|
| 4042 |
// LDLt factorization of DS0(i,j) |
| 4043 |
vector<int> permute, permute_left, permute_tright, permute_tleft; |
| 4044 |
permute.resize(nsing); |
| 4045 |
|
| 4046 |
|
| 4047 |
const double machine_eps_double = machine_epsilon<double, double>(); |
| 4048 |
const int n1 = nsing - n0; |
| 4049 |
|
| 4050 |
// flag_unsym_permute = false; |
| 4051 |
Schur.setFullPivoting(flag_unsym_permute); |
| 4052 |
|
| 4053 |
if (flag_unsym_permute) { |
| 4054 |
int nn0; |
| 4055 |
double fop; |
| 4056 |
double last_pivot = 1.0; |
| 4057 |
permute_left.resize(nsing); |
| 4058 |
ldu_full_permute<T, U>(&nn0, n0, nsing, |
| 4059 |
DSsingCoefs.addrCoefs(), nsing, &last_pivot, |
| 4060 |
&permute[0], &permute_left[0], |
| 4061 |
machine_eps_double, &fop); |
| 4062 |
#if 0 |
| 4063 |
last_pivot = 1.0; |
| 4064 |
permute_tright.resize(nsing); |
| 4065 |
permute_tleft.resize(nsing); |
| 4066 |
ldu_full_permute<T, U>(&nn0, n0, nsing, |
| 4067 |
DSsingCoefs2.addrCoefs(), nsing, &last_pivot, |
| 4068 |
&permute_tright[0], &permute_tleft[0], |
| 4069 |
machine_eps_double, &fop); |
| 4070 |
#endif |
| 4071 |
n0 = nn0; |
| 4072 |
} |
| 4073 |
else { |
| 4074 |
int nn0; |
| 4075 |
double fop; |
| 4076 |
double last_pivot = 1.0; |
| 4077 |
if (_ptDA->isSymmetric()) { |
| 4078 |
full_ldlt_permute<T, U>(&nn0, n0, nsing, |
| 4079 |
DSsingCoefs.addrCoefs(), nsing, &last_pivot, |
| 4080 |
&permute[0], machine_eps_double, &fop); |
| 4081 |
} |
| 4082 |
else { |
| 4083 |
full_ldu_permute<T, U>(&nn0, n0, nsing, |
| 4084 |
DSsingCoefs.addrCoefs(), nsing, &last_pivot, |
| 4085 |
&permute[0], machine_eps_double, &fop); |
| 4086 |
} |
| 4087 |
n0 = nn0; |
| 4088 |
permute_left = permute; |
| 4089 |
} |
| 4090 |
|
| 4091 |
if (n0 != (nsing - n1)) { |
| 4092 |
diss_printf(_verbose, _fp, |
| 4093 |
"%s %d : factroization of suspicious pivots fails : %d -> %d\n", |
| 4094 |
__FILE__, __LINE__, (nsing - n1), n0); |
| 4095 |
} |
| 4096 |
else { |
| 4097 |
diss_printf(_verbose, _fp, |
| 4098 |
"%s %d : pivot = %s after n0 = %d\n", |
| 4099 |
__FILE__, __LINE__, |
| 4100 |
flag_unsym_permute ? "full" : "symmetric", n0); |
| 4101 |
} |
| 4102 |
// keep offdiagonal part corresponding to the last Schur complement |
| 4103 |
Schur.getScol().init(_dim, n1); |
| 4104 |
for (int j = 0; j < n1; j++) { |
| 4105 |
blas_copy<T>(_dim, DBsCoefs.addrCoefs() + (permute[j] * _dim), 1, |
| 4106 |
Schur.getScol().addrCoefs() + (j * _dim), 1); |
| 4107 |
} |
| 4108 |
if (n0 > 0) { |
| 4109 |
Schur.getSchur().init(n1, n1); // copy with permutation for debugging |
| 4110 |
for (int j = 0; j < n1; j++) { |
| 4111 |
for (int i = 0; i < n1; i++) { |
| 4112 |
Schur.getSchur()(i, j) = DS0(permute_left[i], permute[j]); |
| 4113 |
} |
| 4114 |
} |
| 4115 |
// d23 = (S_22)^{-1} (-S_23) |
| 4116 |
ColumnMatrix<T> d23(nsing, n0); |
| 4117 |
ColumnMatrix<T> d32(nsing, n0); |
| 4118 |
|
| 4119 |
d23.ZeroClear(); |
| 4120 |
for (int j = 0; j < n0; j++) { |
| 4121 |
for (int i = 0; i < n1; i++) { |
| 4122 |
d23(i, j) = DS0(permute_left[i], permute[j + n1]); |
| 4123 |
} |
| 4124 |
} |
| 4125 |
d32.ZeroClear(); |
| 4126 |
for (int j = 0; j < n0; j++) { |
| 4127 |
for (int i = 0; i < n1; i++) { |
| 4128 |
d32(i, j) = DS0(permute_left[j + n1], permute[i]); |
| 4129 |
//d32(i, j) = DS2(permute_tleft[i], permute_tright[j + n1]); |
| 4130 |
} |
| 4131 |
} |
| 4132 |
// alpha = 1.0; |
| 4133 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 4134 |
n1, n0, _one, DSsingCoefs.addrCoefs(), nsing, |
| 4135 |
d23.addrCoefs(), nsing); |
| 4136 |
{ |
| 4137 |
for (int i = 0; i < n1; i++) { |
| 4138 |
const T stmp = DSsingCoefs(i, i); |
| 4139 |
for (int j = 0; j < n0; j++) { |
| 4140 |
d23(i, j) *= stmp; |
| 4141 |
} |
| 4142 |
} |
| 4143 |
} |
| 4144 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 4145 |
n1, n0, _one, DSsingCoefs.addrCoefs(), nsing, |
| 4146 |
d23.addrCoefs(), nsing); |
| 4147 |
for (int i = 0; i < n0; i++) { |
| 4148 |
const int ii = i + n1; |
| 4149 |
d23(ii, i) = _none; |
| 4150 |
} |
| 4151 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasTrans, CblasUnit, |
| 4152 |
n1, n0, _one, DSsingCoefs.addrCoefs(), nsing, |
| 4153 |
//blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 4154 |
//n1, n0, _one, DSsingCoefs2.addrCoefs(), nsing, |
| 4155 |
d32.addrCoefs(), nsing); |
| 4156 |
{ |
| 4157 |
for (int i = 0; i < n1; i++) { |
| 4158 |
const T stmp = DSsingCoefs(i, i); |
| 4159 |
//const T stmp = DSsingCoefs2(i, i); |
| 4160 |
for (int j = 0; j < n0; j++) { |
| 4161 |
d32(i, j) *= stmp; |
| 4162 |
} |
| 4163 |
} |
| 4164 |
} |
| 4165 |
blas_trsm<T>(CblasLeft, CblasLower, CblasTrans, CblasUnit, |
| 4166 |
n1, n0, _one, DSsingCoefs.addrCoefs(), nsing, |
| 4167 |
// blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 4168 |
// n1, n0, _one, DSsingCoefs2.addrCoefss(), nsing, |
| 4169 |
d32.addrCoefs(), nsing); |
| 4170 |
|
| 4171 |
for (int i = 0; i < n0; i++) { |
| 4172 |
const int ii = i + n1; |
| 4173 |
d32(ii, i) = _none; |
| 4174 |
} |
| 4175 |
// generating the kernel vectors |
| 4176 |
// keep the vectors from suspicious pivots |
| 4177 |
kernel.getKernBasis().free(); // the 2nd allocation _dim * nsing -> _dim * n |
| 4178 |
kernel.getKernBasis().init(_dim, n0); |
| 4179 |
kernel.getTKernBasis().free(); // |
| 4180 |
kernel.getTKernBasis().init(_dim, n0); |
| 4181 |
T *kern_basis = kernel.getKernBasis().addrCoefs(); |
| 4182 |
T *kernt_basis = kernel.getTKernBasis().addrCoefs(); |
| 4183 |
ColumnMatrix<T> d23_permuted(nsing, n0); |
| 4184 |
#if 1 |
| 4185 |
ColumnMatrix<T> dtest(nsing, n0); |
| 4186 |
// for debugging |
| 4187 |
d23_permuted.ZeroClear(); |
| 4188 |
for (int j = 0; j < n0; j++) { |
| 4189 |
for (int i = 0; i < nsing; i++) { |
| 4190 |
d23_permuted(permute[i], j) = d23(i, j); |
| 4191 |
} |
| 4192 |
} |
| 4193 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 4194 |
nsing, n0, nsing, _one, |
| 4195 |
DS0.addrCoefs(), nsing, |
| 4196 |
d23_permuted.addrCoefs(), nsing, _zero, |
| 4197 |
dtest.addrCoefs(), nsing); |
| 4198 |
diss_printf(_verbose, _fp, "%s %d verify kernel : %d\n", |
| 4199 |
__FILE__, __LINE__, n0); |
| 4200 |
for (int j = 0; j < n0; j++) { |
| 4201 |
U stmp = blas_l2norm<T, U>(nsing, dtest.addrCoefs() + j * nsing, 1); |
| 4202 |
for (int i = 0; i < nsing; i++) { |
| 4203 |
diss_printf(_verbose, _fp, "%d : %d %s %s\n", |
| 4204 |
i, permute[i], |
| 4205 |
tostring<T>(d23_permuted(i, j)).c_str(), |
| 4206 |
tostring<T>(dtest[i + j * nsing]).c_str()); |
| 4207 |
} |
| 4208 |
diss_printf(_verbose, _fp, "%d %s\n", j, tostring<U>(stmp).c_str()); |
| 4209 |
} |
| 4210 |
if (!_ptDA->isSymmetric()) { |
| 4211 |
d23_permuted.ZeroClear(); |
| 4212 |
for (int j = 0; j < n0; j++) { |
| 4213 |
for (int i = 0; i < nsing; i++) { |
| 4214 |
d23_permuted(permute_left[i], j) = d32(i, j); |
| 4215 |
//d23_permuted(permute_tright[i], j) = d32(i, j); |
| 4216 |
} |
| 4217 |
} |
| 4218 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 4219 |
nsing, n0, nsing, _one, |
| 4220 |
DS0.addrCoefs(), nsing, |
| 4221 |
//DS2.addrCoefs(), nsing, |
| 4222 |
d23_permuted.addrCoefs(), nsing, _zero, |
| 4223 |
dtest.addrCoefs(), nsing); |
| 4224 |
diss_printf(_verbose, _fp, "%s %d verify transposed kernel : %d\n", |
| 4225 |
__FILE__, __LINE__, n0); |
| 4226 |
for (int j = 0; j < n0; j++) { |
| 4227 |
U stmp = blas_l2norm<T, U>(nsing, dtest.addrCoefs() + j * nsing, 1); |
| 4228 |
for (int i = 0; i < nsing; i++) { |
| 4229 |
diss_printf(_verbose, _fp, "%d : %d %s %s\n", |
| 4230 |
i, permute_left[i], |
| 4231 |
//i, permute_tright[i], |
| 4232 |
tostring<T>(d23_permuted(i, j)).c_str(), |
| 4233 |
tostring<T>(dtest[i + j * nsing]).c_str()); |
| 4234 |
} |
| 4235 |
diss_printf(_verbose, _fp, "%d %s\n", j, tostring<U>(stmp).c_str()); |
| 4236 |
} |
| 4237 |
} |
| 4238 |
#endif |
| 4239 |
// |
| 4240 |
d23_permuted.ZeroClear(); |
| 4241 |
if (flag_unsym_permute) { |
| 4242 |
for (int j = 0; j < n0; j++) { |
| 4243 |
for (int i = 0; i < nsing; i++) { |
| 4244 |
d23_permuted(permute[i], j) = d23(i, j); |
| 4245 |
} |
| 4246 |
} |
| 4247 |
// A11^-1 [ A_13 A_12] permute_right [S22^-1 S_23] - p_r [S22^-1 S_23] |
| 4248 |
// [ -I ] [ -I ] |
| 4249 |
kernel.getKernBasis().ZeroClear(); |
| 4250 |
for (int i = 0; i < nsing; i++) { |
| 4251 |
DBsCoefs(singIdx[i], i) = _zero; |
| 4252 |
} |
| 4253 |
|
| 4254 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 4255 |
_dim, n0, nsing, _one, // alpha |
| 4256 |
DBsCoefs.addrCoefs(), _dim, // |
| 4257 |
d23_permuted.addrCoefs(), nsing, _zero, // beta |
| 4258 |
kern_basis, _dim); |
| 4259 |
for (int j = 0; j < n0; j++) { |
| 4260 |
for (int i = 0; i < nsing; i++) { |
| 4261 |
kernel.getKernBasis()(singIdx[i], j) = -d23_permuted(i, j); |
| 4262 |
} |
| 4263 |
} |
| 4264 |
// compute transposed kernel |
| 4265 |
d23_permuted.ZeroClear(); |
| 4266 |
for (int j = 0; j < n0; j++) { |
| 4267 |
for (int i = 0; i < nsing; i++) { |
| 4268 |
d23_permuted(permute_left[i], j) = d32(i, j); |
| 4269 |
//d23_permuted(permute_tright[i], j) = d32(i, j); |
| 4270 |
} |
| 4271 |
} |
| 4272 |
// A11^-T [ A_31^T A_12^T] permute_l [S22^-T S_32^T] - p_l [S22^-T S_23^T] |
| 4273 |
// [ -I ] [ -I ] |
| 4274 |
kernel.getTKernBasis().ZeroClear(); |
| 4275 |
for (int i = 0; i < nsing; i++) { |
| 4276 |
DCsCoefs(singIdx[i], i) = _zero; |
| 4277 |
} |
| 4278 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 4279 |
_dim, n0, nsing, _one, // alpha |
| 4280 |
DCsCoefs.addrCoefs(), _dim, // |
| 4281 |
d23_permuted.addrCoefs(), nsing, _zero, // beta |
| 4282 |
kernt_basis, _dim); |
| 4283 |
for (int j = 0; j < n0; j++) { |
| 4284 |
for (int i = 0; i < nsing; i++) { |
| 4285 |
kernel.getTKernBasis()(singIdx[i], j) = -d23_permuted(i, j); |
| 4286 |
} |
| 4287 |
} |
| 4288 |
// d23_permuted.free(); |
| 4289 |
} |
| 4290 |
else { // if (flag_unsym_permute) |
| 4291 |
for (int i = 0; i < nsing; i++) { |
| 4292 |
DBsCoefs(singIdx[i], i) = _none; |
| 4293 |
} |
| 4294 |
for (int j = 0; j < n0; j++) { |
| 4295 |
for (int i = 0; i < _dim; i++) { |
| 4296 |
kernel.getKernBasis()(i, j) = DBsCoefs(i, permute[j + n1]); |
| 4297 |
} |
| 4298 |
} |
| 4299 |
// update the kernel using singular part of the Schur complement, d23 |
| 4300 |
// kern_basis = - kern_basis - scol * d23 |
| 4301 |
// - [ A11^-1 A_13] + [A_11^-1 A_12] [S22^-1 S_23] |
| 4302 |
// [ 0 ] [ -I ] |
| 4303 |
// [ -I ] [ 0 ] |
| 4304 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 4305 |
_dim, n0, n1, _one, // alpha |
| 4306 |
Schur.getScol().addrCoefs(), _dim, // none |
| 4307 |
d23.addrCoefs(), nsing, _none, // beta |
| 4308 |
kern_basis, _dim); |
| 4309 |
|
| 4310 |
// kernel of the transposed matrix |
| 4311 |
ColumnMatrix<T> DCsCoefs12(_dim, n1); |
| 4312 |
for (int i = 0; i < nsing; i++) { |
| 4313 |
DCsCoefs(singIdx[i], i) = _none; |
| 4314 |
} |
| 4315 |
for (int j = 0; j < n1; j++) { |
| 4316 |
blas_copy<T>(_dim, DCsCoefs.addrCoefs() + (permute[j] * _dim), 1, |
| 4317 |
DCsCoefs12.addrCoefs() + (j * _dim), 1); |
| 4318 |
} |
| 4319 |
for (int j = 0; j < n0; j++) { |
| 4320 |
for (int i = 0; i < _dim; i++) { |
| 4321 |
kernel.getTKernBasis()(i, j) = DCsCoefs(i, permute[j + n1]); |
| 4322 |
} |
| 4323 |
} |
| 4324 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, |
| 4325 |
_dim, n0, n1, _one, // alpha |
| 4326 |
DCsCoefs12.addrCoefs(), _dim, // none |
| 4327 |
d32.addrCoefs(), nsing, _none, // beta |
| 4328 |
kernt_basis, _dim); |
| 4329 |
DCsCoefs12.free(); |
| 4330 |
} // if (flag_unsym_permute) |
| 4331 |
// normalize each kernel_basis |
| 4332 |
for (int j = 0; j < n0; j++) { |
| 4333 |
U stmp(0.0); |
| 4334 |
const U one(1.0); |
| 4335 |
stmp = one / blas_l2norm<T, U>(_dim, (kern_basis + (j * _dim)), 1); |
| 4336 |
blas_scal2<T, U>(_dim, stmp, (kern_basis + (j * _dim)), 1); |
| 4337 |
} |
| 4338 |
diss_printf(_verbose, _fp, |
| 4339 |
"%s %d : == ptDA * kernel\n", __FILE__, __LINE__); |
| 4340 |
|
| 4341 |
for (int j = 0; j < n0; j++) { |
| 4342 |
_ptDA->prod((kern_basis + (j * _dim)), v.addrCoefs()); |
| 4343 |
|
| 4344 |
double norm_l2, norm_infty; |
| 4345 |
calc_relative_norm<T>(&norm_l2, &norm_infty, |
| 4346 |
v.addrCoefs(), (kern_basis + (j * _dim)), _dim); |
| 4347 |
diss_printf(_verbose, _fp, |
| 4348 |
"%d -th kernel scaled : norm_l2 = %.6e, norm_infty = %.6e / ", |
| 4349 |
j, norm_l2, norm_infty); |
| 4350 |
if(_scaling) { |
| 4351 |
calc_relative_normscaled<T, U>(&norm_l2, &norm_infty, |
| 4352 |
v.addrCoefs(), kern_basis + (j * _dim), |
| 4353 |
&_precDiag[0], _dim); |
| 4354 |
diss_printf(_verbose, _fp, |
| 4355 |
"original : norm_l2 = %.6e, norm_infty = %.6e\n", |
| 4356 |
norm_l2, norm_infty); |
| 4357 |
} |
| 4358 |
else { |
| 4359 |
diss_printf(_verbose, _fp, "\n"); |
| 4360 |
}// if (_scaling) |
| 4361 |
for (int i = 0; i < nsing; i++) { |
| 4362 |
diss_printf(_verbose, _fp, "%d %d %s\n", |
| 4363 |
i, singIdx[i], |
| 4364 |
tostring<T>(v(singIdx[i], j)).c_str()); |
| 4365 |
} |
| 4366 |
} |
| 4367 |
if (!_ptDA->isSymmetric()) { |
| 4368 |
for (int j = 0; j < n0; j++) { |
| 4369 |
U stmp(0.0); |
| 4370 |
const U one(1.0); |
| 4371 |
stmp = one / blas_l2norm<T, U>(_dim, (kernt_basis + (j * _dim)), 1); |
| 4372 |
blas_scal2<T, U>(_dim, stmp, (kernt_basis + (j * _dim)), 1); |
| 4373 |
} |
| 4374 |
diss_printf(_verbose, _fp, |
| 4375 |
"%s %d : == ptDA^T * transposed kernel\n", |
| 4376 |
__FILE__, __LINE__); |
| 4377 |
|
| 4378 |
for (int j = 0; j < n0; j++) { |
| 4379 |
_ptDA->prodt((kernt_basis + (j * _dim)), v.addrCoefs()); |
| 4380 |
|
| 4381 |
double norm_l2, norm_infty; |
| 4382 |
calc_relative_norm<T>(&norm_l2, &norm_infty, |
| 4383 |
v.addrCoefs(), (kernt_basis + (j * _dim)), _dim); |
| 4384 |
diss_printf(_verbose, _fp, |
| 4385 |
"%d -th scaled : norm_l2 = %.6e, norm_infty = %.6e / ", |
| 4386 |
j, norm_l2, norm_infty); |
| 4387 |
if(_scaling) { |
| 4388 |
calc_relative_normscaled<T, U>(&norm_l2, &norm_infty, |
| 4389 |
v.addrCoefs(), |
| 4390 |
kernt_basis + (j * _dim), |
| 4391 |
&_precDiag[0], _dim); |
| 4392 |
diss_printf(_verbose, _fp, |
| 4393 |
"original : norm_l2 = %.6e, norm_infty = %.6e\n", |
| 4394 |
norm_l2, norm_infty); |
| 4395 |
} |
| 4396 |
else { |
| 4397 |
diss_printf(_verbose, _fp, "\n"); |
| 4398 |
} |
| 4399 |
diss_printf(_verbose, _fp, "%s %d\n", __FILE__, __LINE__); |
| 4400 |
for (int i = 0; i < nsing; i++) { |
| 4401 |
diss_printf(_verbose, _fp, "%d %d %s\n", |
| 4402 |
i, singIdx[i], |
| 4403 |
tostring<T>(v(singIdx[i], j)).c_str()); |
| 4404 |
} |
| 4405 |
} |
| 4406 |
} // if (!_ptDA->isSymmetric()) |
| 4407 |
if(_scaling) { |
| 4408 |
for (int j = 0; j < n0; j++) { |
| 4409 |
const int jtmp = j * _dim; |
| 4410 |
for (int i = 0; i < _dim; i++) { |
| 4411 |
kern_basis[i + jtmp] *= _precDiag[i]; |
| 4412 |
} |
| 4413 |
} |
| 4414 |
for (int j = 0; j < n0; j++) { |
| 4415 |
const int jtmp = j * _dim; |
| 4416 |
for (int i = 0; i < _dim; i++) { |
| 4417 |
kernt_basis[i + jtmp] *= _precDiag[i]; |
| 4418 |
} |
| 4419 |
} |
| 4420 |
} |
| 4421 |
#ifdef NORMALIZE_KERNEL_BASIS |
| 4422 |
// normalize each kernel_basis |
| 4423 |
for (int j = 0; j < n0; j++) { |
| 4424 |
U stmp(0.0); |
| 4425 |
const U one(1.0); |
| 4426 |
stmp = one / blas_l2norm<T, U>(_dim, (kern_basis + (j * _dim)), 1); |
| 4427 |
blas_scal2<T, U>(_dim, stmp, (kern_basis + (j * _dim)), 1); |
| 4428 |
stmp = one / blas_l2norm<T, U>(_dim, (kernt_basis + (j * _dim)), 1); |
| 4429 |
blas_scal2<T, U>(_dim, stmp, (kernt_basis + (j * _dim)), 1); |
| 4430 |
|
| 4431 |
} |
| 4432 |
#endif |
| 4433 |
kernel.getKernProj().free(); // second alloctation : nsing -> n0 |
| 4434 |
kernel.set_dimension(n0); |
| 4435 |
kernel.getKernProj().init(n0); |
| 4436 |
kernel.getTKernProj().free(); // second alloctation : nsing -> n0 |
| 4437 |
if (!_ptDA->isSymmetric()) { |
| 4438 |
kernel.getTKernProj().init(n0); |
| 4439 |
kernel.getNTKernProj().init(n0); |
| 4440 |
} |
| 4441 |
for (int i = 0; i < n0; i++) { |
| 4442 |
for(int j = i; j < n0; j++) { |
| 4443 |
kernel.getKernProj()(i, j) = blas_dot<T>(_dim, |
| 4444 |
(kern_basis + (i * _dim)), 1, |
| 4445 |
(kern_basis + (j * _dim)), 1); |
| 4446 |
} |
| 4447 |
// symmetrize |
| 4448 |
for (int j = (i + 1); j < n0; j++) { |
| 4449 |
kernel.getKernProj()(j, i) = kernel.getKernProj()(i, j); |
| 4450 |
} |
| 4451 |
} |
| 4452 |
full_ldlh<T>(n0, kernel.getKernProj().addrCoefs(), n0); |
| 4453 |
// inverse of diagonal part is also storead in the factorized matrix |
| 4454 |
if (!_ptDA->isSymmetric()) { |
| 4455 |
for (int i = 0; i < n0; i++) { |
| 4456 |
for(int j = i; j < n0; j++) { |
| 4457 |
kernel.getTKernProj()(i, j) = |
| 4458 |
blas_dot<T>(_dim, |
| 4459 |
(kernt_basis + (i * _dim)), 1, |
| 4460 |
(kernt_basis + (j * _dim)), 1); |
| 4461 |
} |
| 4462 |
// symmetrize |
| 4463 |
for (int j = (i + 1); j < n0; j++) { |
| 4464 |
kernel.getTKernProj()(j, i) = kernel.getTKernProj()(i, j); |
| 4465 |
} |
| 4466 |
} |
| 4467 |
full_ldlh<T>(n0, kernel.getTKernProj().addrCoefs(), n0); |
| 4468 |
// for oblique projection |
| 4469 |
for (int i = 0; i < n0; i++) { |
| 4470 |
for(int j = 0; j < n0; j++) { |
| 4471 |
kernel.getNTKernProj()(i, j) = |
| 4472 |
blas_dot<T>(_dim, |
| 4473 |
(kernt_basis + (i * _dim)), 1, |
| 4474 |
(kern_basis + (j * _dim)), 1); |
| 4475 |
} |
| 4476 |
} |
| 4477 |
diss_printf(_verbose, _fp, |
| 4478 |
"%s %d : orthogonality matrix kernels of A and A^T\n", |
| 4479 |
__FILE__, __LINE__); |
| 4480 |
for (int i = 0; i < n0; i++) { |
| 4481 |
diss_printf(_verbose, _fp, "%d : ", i); |
| 4482 |
for(int j = 0; j < n0; j++) { |
| 4483 |
diss_printf(_verbose, _fp, "%.16e ", |
| 4484 |
blas_abs<T, double>(kernel.getNTKernProj()(i, j))); |
| 4485 |
} |
| 4486 |
diss_printf(_verbose, _fp, "\n"); |
| 4487 |
} |
| 4488 |
full_ldu<T>(n0, kernel.getNTKernProj().addrCoefs(), n0); |
| 4489 |
} |
| 4490 |
} // if (n0 > 0) |
| 4491 |
else { |
| 4492 |
kernel.set_dimension(0); |
| 4493 |
} |
| 4494 |
// |
| 4495 |
diss_printf(_verbose, _fp, |
| 4496 |
"%s %d : nsing = %d dim_augkern = %d n1 = %d n0 = %d\n", |
| 4497 |
__FILE__, __LINE__, nsing, dim_augkern, n1, n0); |
| 4498 |
|
| 4499 |
// for some applications which need index of singular entries |
| 4500 |
kernel.setFullPivoting(flag_unsym_permute); |
| 4501 |
kernel.getKernListEq().resize(n0); |
| 4502 |
kernel.getKernListEqLeft().resize(n0); |
| 4503 |
for (int i = 0; i < n0; i++) { |
| 4504 |
kernel.getKernListEq()[i]= singIdx[permute[i + n1]]; |
| 4505 |
kernel.getKernListEqLeft()[i]= singIdx[permute_left[i + n1]]; |
| 4506 |
} |
| 4507 |
diss_printf(_verbose, _fp, "%s %d : kern_list_eq[] = ", __FILE__, __LINE__); |
| 4508 |
for (int i = 0; i < kernel.getKernListEq().size(); i++) { |
| 4509 |
diss_printf(_verbose,_fp, "%d ", kernel.getKernListEq()[i]); |
| 4510 |
} |
| 4511 |
diss_printf(_verbose, _fp, "\n"); |
| 4512 |
if (flag_unsym_permute) { |
| 4513 |
diss_printf(_verbose, _fp, "%s %d : kern_list_eq_left[] = ", |
| 4514 |
__FILE__, __LINE__); |
| 4515 |
for (int i = 0; i < kernel.getKernListEqLeft().size(); i++) { |
| 4516 |
diss_printf(_verbose,_fp, "%d ", kernel.getKernListEqLeft()[i]); |
| 4517 |
} |
| 4518 |
diss_printf(_verbose, _fp, "\n"); |
| 4519 |
} |
| 4520 |
if (n1 == dim_augkern && (!flag_unsym_permute)) { |
| 4521 |
diss_printf(_verbose, _fp, |
| 4522 |
"%s %d dimension of detected kernel == suspicous one = %d\n", |
| 4523 |
__FILE__, __LINE__, n0); |
| 4524 |
{ |
| 4525 |
int i = 0; |
| 4526 |
typename vector<SquareBlockMatrix<T>* >::const_iterator kt = diags.begin(); |
| 4527 |
for (vector<vector<int> >::const_iterator it = augkern_indexes.begin(); |
| 4528 |
it != augkern_indexes.end(); ++it, ++kt) { |
| 4529 |
SquareBlockMatrix<T> &diag = *(*kt); |
| 4530 |
const int n0_diag = diag.rank(); |
| 4531 |
for (vector<int>::const_iterator jt = (*it).begin(); jt != (*it).end(); |
| 4532 |
++jt, i++) { |
| 4533 |
diag.diag((*jt)) = save_diag[i]; // i++ |
| 4534 |
} |
| 4535 |
diag.set_rank(n0_diag + (*it).size()); // restore |
| 4536 |
} |
| 4537 |
} |
| 4538 |
Schur.getSlduList().resize(0); |
| 4539 |
} |
| 4540 |
else { // if (n1 == dim_augkern) { |
| 4541 |
Schur.getSlduList().resize(n1); |
| 4542 |
Schur.getSlduListLeft().resize(n1); |
| 4543 |
for (int i = 0; i < n1; i++) { |
| 4544 |
Schur.getSlduList()[i] = permute[i]; |
| 4545 |
Schur.getSlduListLeft()[i] = permute_left[i]; |
| 4546 |
} |
| 4547 |
vector<int> s_list_eq, s_list_eq_left; |
| 4548 |
s_list_eq.resize(n1); |
| 4549 |
s_list_eq_left.resize(n1); |
| 4550 |
// local2global index for the last Schur complement |
| 4551 |
for (int i = 0; i < n1; i++) { |
| 4552 |
s_list_eq[i] = singIdx[permute[i]]; |
| 4553 |
s_list_eq_left[i] = singIdx[permute_left[i]]; |
| 4554 |
} |
| 4555 |
diss_printf(_verbose, _fp, "%s %d : s_list_eq[] = ", __FILE__, __LINE__); |
| 4556 |
for (int i = 0; i < s_list_eq.size(); i++) { |
| 4557 |
diss_printf(_verbose, _fp, "%d ", s_list_eq[i]); |
| 4558 |
} |
| 4559 |
diss_printf(_verbose, _fp, "\n"); |
| 4560 |
if (flag_unsym_permute) { |
| 4561 |
diss_printf(_verbose, _fp, "%s %d : s_list_eq_left[] = ", |
| 4562 |
__FILE__, __LINE__); |
| 4563 |
for (int i = 0; i < s_list_eq_left.size(); i++) { |
| 4564 |
diss_printf(_verbose, _fp, "%d ", s_list_eq_left[i]); |
| 4565 |
} |
| 4566 |
diss_printf(_verbose, _fp, "\n"); |
| 4567 |
} |
| 4568 |
Schur.getSldu().init(flag_unsym_permute, s_list_eq, s_list_eq_left); |
| 4569 |
|
| 4570 |
// copy regular part n1*n1 from nsing*nsing matrix DSsingCoefs[] |
| 4571 |
for (int j = 0; j < n1; j++) { |
| 4572 |
blas_copy<T>(n1, DSsingCoefs.addrCoefs() + j * nsing, 1, |
| 4573 |
Schur.getSldu().addrCoefs() + j * n1, 1); |
| 4574 |
} |
| 4575 |
// <---- n1 ----> : given by pemrute[j] |
| 4576 |
// [ A_11^-1 A_12 ] -> [ A_11^-1 A_12 ] |
| 4577 |
// [ -I ] [ 0 ] : singIdx[permute[i]] |
| 4578 |
// [ 0 ] [ 0 ] : 0<= i < nsing |
| 4579 |
for (int i = 0; i < n1; i++) { |
| 4580 |
Schur.getScol()(s_list_eq[i], i) = _zero; |
| 4581 |
} |
| 4582 |
} // if (n1 == dim_augkern) { |
| 4583 |
|
| 4584 |
// delete ptDA_acol; // 28 Dec.2015 |
| 4585 |
// delete [] save_diag; |
| 4586 |
// delete [] DBsCoefs; |
| 4587 |
// delete [] DBsCoefs0; |
| 4588 |
// delete [] DSsingCoefs; |
| 4589 |
// delete [] DSsingCoefs0; |
| 4590 |
// delete [] DS0; |
| 4591 |
// delete [] DS2; |
| 4592 |
} |
| 4593 |
|
| 4594 |
template |
| 4595 |
void DissectionSolver<double>:: |
| 4596 |
BuildKernelsDetection(int &n0, |
| 4597 |
vector<int> &singIdx, |
| 4598 |
vector<vector<int> > &augkern_indexes, |
| 4599 |
vector<SquareBlockMatrix<double>* >& diags, |
| 4600 |
const double eps_piv, |
| 4601 |
const int dim_augkern, |
| 4602 |
SchurMatrix<double> &Schur, |
| 4603 |
KernelMatrix<double> &kernel, |
| 4604 |
const bool enableDetection); |
| 4605 |
|
| 4606 |
template |
| 4607 |
void DissectionSolver<complex<double>, double>:: |
| 4608 |
BuildKernelsDetection(int &n0, |
| 4609 |
vector<int> &singIdx, |
| 4610 |
vector<vector<int> >& augkern_indexes, |
| 4611 |
vector<SquareBlockMatrix<complex<double> >* >& diags, |
| 4612 |
const double eps_piv, |
| 4613 |
const int dim_augkern, |
| 4614 |
SchurMatrix<complex<double> > &Schur, |
| 4615 |
KernelMatrix<complex<double> > &kernel, |
| 4616 |
const bool enableDetection); |
| 4617 |
|
| 4618 |
template |
| 4619 |
void DissectionSolver<quadruple>:: |
| 4620 |
BuildKernelsDetection(int &n0, |
| 4621 |
vector<int> &singIdx, |
| 4622 |
vector<vector<int> > &augkern_indexes, |
| 4623 |
vector<SquareBlockMatrix<quadruple>* >& diags, |
| 4624 |
const double eps_piv, |
| 4625 |
const int dim_augkern, |
| 4626 |
SchurMatrix<quadruple> &Schur, |
| 4627 |
KernelMatrix<quadruple> &kernel, |
| 4628 |
const bool enableDetection); |
| 4629 |
|
| 4630 |
template |
| 4631 |
void DissectionSolver<complex<quadruple>, quadruple>:: |
| 4632 |
BuildKernelsDetection(int &n0, |
| 4633 |
vector<int> &singIdx, |
| 4634 |
vector<vector<int> >& augkern_indexes, |
| 4635 |
vector<SquareBlockMatrix<complex<quadruple> >* >& diags, |
| 4636 |
const double eps_piv, |
| 4637 |
const int dim_augkern, |
| 4638 |
SchurMatrix<complex<quadruple> > &Schur, |
| 4639 |
KernelMatrix<complex<quadruple> > &kernel, |
| 4640 |
const bool enableDetection); |
| 4641 |
template |
| 4642 |
void DissectionSolver<float>:: |
| 4643 |
BuildKernelsDetection(int &n0, |
| 4644 |
vector<int> &singIdx, |
| 4645 |
vector<vector<int> > &augkern_indexes, |
| 4646 |
vector<SquareBlockMatrix<float>* >& diags, |
| 4647 |
const double eps_piv, |
| 4648 |
const int dim_augkern, |
| 4649 |
SchurMatrix<float> &Schur, |
| 4650 |
KernelMatrix<float> &kernel, |
| 4651 |
const bool enableDetection); |
| 4652 |
|
| 4653 |
template |
| 4654 |
void DissectionSolver<complex<float>, float>:: |
| 4655 |
BuildKernelsDetection(int &n0, |
| 4656 |
vector<int> &singIdx, |
| 4657 |
vector<vector<int> >& augkern_indexes, |
| 4658 |
vector<SquareBlockMatrix<complex<float> >* >& diags, |
| 4659 |
const double eps_piv, |
| 4660 |
const int dim_augkern, |
| 4661 |
SchurMatrix<complex<float> > &Schur, |
| 4662 |
KernelMatrix<complex<float> > &kernel, |
| 4663 |
const bool enableDetection); |
| 4664 |
|
| 4665 |
// |
| 4666 |
|
| 4667 |
template<typename T, typename U, typename W, typename Z> |
| 4668 |
int DissectionSolver<T, U, W, Z>:: |
| 4669 |
kern_dimension(void) |
| 4670 |
{ |
| 4671 |
int itmp = 0; |
| 4672 |
for (int m = 0; m < _graph_colors; m++) { |
| 4673 |
itmp += _kernel[m].dimension(); |
| 4674 |
} |
| 4675 |
return itmp; |
| 4676 |
} |
| 4677 |
|
| 4678 |
// |
| 4679 |
template |
| 4680 |
int DissectionSolver<double>::kern_dimension(void); |
| 4681 |
|
| 4682 |
template |
| 4683 |
int DissectionSolver<quadruple>::kern_dimension(void); |
| 4684 |
|
| 4685 |
template |
| 4686 |
int DissectionSolver<complex<double>, double>::kern_dimension(void); |
| 4687 |
|
| 4688 |
template |
| 4689 |
int DissectionSolver<complex<quadruple>, quadruple>::kern_dimension(void); |
| 4690 |
|
| 4691 |
template |
| 4692 |
int DissectionSolver<double, double, quadruple, quadruple>::kern_dimension(void); |
| 4693 |
|
| 4694 |
template |
| 4695 |
int DissectionSolver<quadruple, quadruple, double, double>::kern_dimension(void); |
| 4696 |
|
| 4697 |
template |
| 4698 |
int DissectionSolver<float>::kern_dimension(void); |
| 4699 |
|
| 4700 |
template |
| 4701 |
int DissectionSolver<complex<float>, float>::kern_dimension(void); |
| 4702 |
|
| 4703 |
// |
| 4704 |
|
| 4705 |
// |
| 4706 |
template<typename T, typename U, typename W, typename Z> |
| 4707 |
int DissectionSolver<T, U, W, Z>:: |
| 4708 |
postponed_pivots(void) |
| 4709 |
{ |
| 4710 |
int itmp = 0; |
| 4711 |
for (int m = 0; m < _graph_colors; m++) { |
| 4712 |
itmp += _singIdx[m].size(); |
| 4713 |
} |
| 4714 |
return itmp; |
| 4715 |
} |
| 4716 |
|
| 4717 |
// |
| 4718 |
template |
| 4719 |
int DissectionSolver<double>::postponed_pivots(void); |
| 4720 |
|
| 4721 |
template |
| 4722 |
int DissectionSolver<quadruple>::postponed_pivots(void); |
| 4723 |
|
| 4724 |
template |
| 4725 |
int DissectionSolver<complex<double>, double>::postponed_pivots(void); |
| 4726 |
|
| 4727 |
template |
| 4728 |
int DissectionSolver<complex<quadruple>, quadruple>::postponed_pivots(void); |
| 4729 |
|
| 4730 |
template |
| 4731 |
int DissectionSolver<double, double, quadruple, quadruple>::postponed_pivots(void); |
| 4732 |
|
| 4733 |
template |
| 4734 |
int DissectionSolver<quadruple, quadruple, double, double>::postponed_pivots(void); |
| 4735 |
|
| 4736 |
template |
| 4737 |
int DissectionSolver<float>::postponed_pivots(void); |
| 4738 |
|
| 4739 |
template |
| 4740 |
int DissectionSolver<complex<float>, float>::postponed_pivots(void); |
| 4741 |
|
| 4742 |
// |
| 4743 |
|
| 4744 |
template<typename T, typename U, typename W, typename Z> |
| 4745 |
int DissectionSolver<T, U, W, Z>:: |
| 4746 |
ComputeTransposedKernels(void) |
| 4747 |
{ |
| 4748 |
// int n0_max = 0; |
| 4749 |
if (_ptDA->isSymmetric()) { |
| 4750 |
diss_printf(_verbose, _fp, |
| 4751 |
"%s %d : ComputeTransposedKernels : matrix is symmetric\n", |
| 4752 |
__FILE__, __LINE__); |
| 4753 |
return (-1); |
| 4754 |
} |
| 4755 |
|
| 4756 |
for (int m = 0; m < _graph_colors; m++) { |
| 4757 |
int n0 = _kernel[m].dimension(); |
| 4758 |
#if 0 |
| 4759 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 4760 |
_kernel[m].getTKernBasis().init(_dim, n0); |
| 4761 |
} |
| 4762 |
#endif |
| 4763 |
_kernel[m].getTKernProj().init(n0); |
| 4764 |
_kernel[m].getNTKernProj().init(n0); |
| 4765 |
} |
| 4766 |
for (int m = 0; m < _graph_colors; m++) { |
| 4767 |
int n0 = _kernel[m].dimension(); |
| 4768 |
T *kernt_basis = _kernel[m].getTKernBasis().addrCoefs(); |
| 4769 |
T *kernn_basis = _kernel[m].getKernBasis().addrCoefs(); |
| 4770 |
#if 0 |
| 4771 |
if (!_tridiagQueue[m]->tridiagSolver()) { |
| 4772 |
_kernel[m].getTKernBasis().ZeroClear(); |
| 4773 |
for (int i = 0; i < n0; i++) { |
| 4774 |
const int ii = _kernel[m].getKernListEq()[i]; |
| 4775 |
for (int k = _ptDA->ptRow(ii); k < _ptDA->ptRow(ii + 1); k++) { |
| 4776 |
_kernel[m].getTKernBasis()(_ptDA->indCol(k), i) = _ptDA->Coef(k); |
| 4777 |
} |
| 4778 |
} |
| 4779 |
for (int j = 0; j < n0; j++) { |
| 4780 |
for (int i = 0; i < n0; i++) { |
| 4781 |
_kernel[m].getTKernBasis()(_kernel[m].getKernListEq()[i], j) = _zero; |
| 4782 |
} |
| 4783 |
} |
| 4784 |
if (n0 > 1) { |
| 4785 |
SolveMulti(kernt_basis, n0, false, true, false); |
| 4786 |
} |
| 4787 |
else { |
| 4788 |
// porjection, isTrans, isScaling |
| 4789 |
SolveSingle(kernt_basis, false, true, false); |
| 4790 |
} |
| 4791 |
// nullify singular block |
| 4792 |
for (int j = 0; j < n0; j++) { |
| 4793 |
for (int i = 0; i < n0; i++) { |
| 4794 |
_kernel[m].getTKernBasis()(_kernel[m].getKernListEqLeft()[i], j) = _zero; |
| 4795 |
} |
| 4796 |
} |
| 4797 |
// set -I on the diagonal entries of singular block |
| 4798 |
for (int i = 0; i < n0; i++) { |
| 4799 |
_kernel[m].getTKernBasis()(_kernel[m].getKernListEqLeft()[i], i) = _none; |
| 4800 |
} |
| 4801 |
if(_scaling) { |
| 4802 |
for (int j = 0; j < n0; j++) { |
| 4803 |
const int jtmp = j * _dim; |
| 4804 |
for (int i = 0; i < _dim; i++) { |
| 4805 |
kernt_basis[i + jtmp] *= _precDiag[i]; |
| 4806 |
} |
| 4807 |
} |
| 4808 |
} |
| 4809 |
} // if (_tridiagQueue[m]->tridiagSolver()) |
| 4810 |
else { |
| 4811 |
diss_printf(_verbose, _fp, |
| 4812 |
"%s %d : transposed kernel from tridiag_kernelt_basis()\n", |
| 4813 |
__FILE__, __LINE__); |
| 4814 |
} |
| 4815 |
#endif |
| 4816 |
VectorArray<T> vn(_dim); |
| 4817 |
VectorArray<T> vt(_dim); |
| 4818 |
diss_printf(_verbose, _fp, |
| 4819 |
"%s %d : check kern_basis belonging to the kernel of A\n", |
| 4820 |
__FILE__, __LINE__); |
| 4821 |
for (int j = 0; j < n0; j++) { |
| 4822 |
SpMV(&kernn_basis[j * _dim], vn.addrCoefs()); //&vn[j][0]); |
| 4823 |
double norm_l2, norm_infty; |
| 4824 |
calc_relative_norm<T>(&norm_l2, &norm_infty, vn.addrCoefs(), //&vn[j][0], |
| 4825 |
&kernn_basis[j * _dim], _dim); |
| 4826 |
diss_printf(_verbose, _fp, "%s %d : %d-th : l2_norm = %.6e, infty_norm = %.6e\n", |
| 4827 |
__FILE__, __LINE__, j, norm_l2, norm_infty); |
| 4828 |
} |
| 4829 |
diss_printf(_verbose, _fp, |
| 4830 |
"%s %d : check kern_basis belonging to the kernel of A^T\n", |
| 4831 |
__FILE__, __LINE__); |
| 4832 |
for (int j = 0; j < n0; j++) { |
| 4833 |
SpMtV(&kernt_basis[j * _dim], vt.addrCoefs()); |
| 4834 |
double norm_l2, norm_infty; |
| 4835 |
calc_relative_norm<T>(&norm_l2, &norm_infty, vt.addrCoefs(), //&vt[j][0], |
| 4836 |
&kernt_basis[j * _dim], _dim); |
| 4837 |
diss_printf(_verbose, _fp, |
| 4838 |
"%s %d : %d-th : l2_norm = %.6e, infty_norm = %.6e\n", |
| 4839 |
__FILE__, __LINE__, j, norm_l2, norm_infty); |
| 4840 |
} // loop : j |
| 4841 |
vn.free(); |
| 4842 |
vt.free(); |
| 4843 |
#ifdef NORMALIZE_KERNEL_BASIS2 |
| 4844 |
// normalize each kernel_basis |
| 4845 |
for (int j = 0; j < n0; j++) { |
| 4846 |
U stmp(0.0); |
| 4847 |
const U one(1.0); |
| 4848 |
stmp = blas_l2norm<T, U>(_dim, (kernt_basis + (j * _dim)), 1); |
| 4849 |
stmp = one / stmp; |
| 4850 |
blas_scal2<T, U>(_dim, stmp, (kernt_basis + (j * _dim)), 1); |
| 4851 |
} |
| 4852 |
#endif |
| 4853 |
for (int i = 0; i < n0; i++) { |
| 4854 |
for(int j = i; j < n0; j++) { |
| 4855 |
_kernel[m].getTKernProj()(i, j) = |
| 4856 |
blas_dot<T>(_dim, |
| 4857 |
(kernt_basis + (i * _dim)), 1, |
| 4858 |
(kernt_basis + (j * _dim)), 1); |
| 4859 |
} |
| 4860 |
// symmetrize |
| 4861 |
for (int j = (i + 1); j < n0; j++) { |
| 4862 |
_kernel[m].getTKernProj()(j, i) = _kernel[m].getTKernProj()(i, j); |
| 4863 |
} |
| 4864 |
} |
| 4865 |
full_ldlh<T>(n0, _kernel[m].getTKernProj().addrCoefs(), n0); |
| 4866 |
// for oblique projection |
| 4867 |
for (int i = 0; i < n0; i++) { |
| 4868 |
for(int j = 0; j < n0; j++) { |
| 4869 |
_kernel[m].getNTKernProj()(i, j) = |
| 4870 |
blas_dot<T>(_dim, |
| 4871 |
(kernt_basis + (i * _dim)), 1, |
| 4872 |
(kernn_basis + (j * _dim)), 1); |
| 4873 |
} |
| 4874 |
} |
| 4875 |
diss_printf(_verbose, _fp, |
| 4876 |
"%s %d : orthogonality matrix kernels of A and A^T : %d\n", |
| 4877 |
__FILE__, __LINE__, m); |
| 4878 |
for (int i = 0; i < n0; i++) { |
| 4879 |
diss_printf(_verbose, _fp, "%d : ", i); |
| 4880 |
for(int j = 0; j < n0; j++) { |
| 4881 |
diss_printf(_verbose, _fp, "%.16e ", |
| 4882 |
blas_abs<T, double>(_kernel[m].getNTKernProj()(i, j))); |
| 4883 |
} |
| 4884 |
diss_printf(_verbose, _fp, "\n"); |
| 4885 |
} |
| 4886 |
full_ldu<T>(n0, _kernel[m].getNTKernProj().addrCoefs(), n0); |
| 4887 |
} // loop : m |
| 4888 |
return 1; |
| 4889 |
} |
| 4890 |
|
| 4891 |
template |
| 4892 |
int DissectionSolver<double>::ComputeTransposedKernels(void); |
| 4893 |
|
| 4894 |
template |
| 4895 |
int DissectionSolver<complex<double>, double>::ComputeTransposedKernels(void); |
| 4896 |
|
| 4897 |
|
| 4898 |
template |
| 4899 |
int DissectionSolver<quadruple>::ComputeTransposedKernels(void); |
| 4900 |
|
| 4901 |
template |
| 4902 |
int DissectionSolver<complex<quadruple>, quadruple>:: |
| 4903 |
ComputeTransposedKernels(void); |
| 4904 |
|
| 4905 |
template |
| 4906 |
int DissectionSolver<float>::ComputeTransposedKernels(void); |
| 4907 |
|
| 4908 |
template |
| 4909 |
int DissectionSolver<complex<float>, float>::ComputeTransposedKernels(void); |
| 4910 |
|