Debian Codegraph @

3rdparty/dissection/src/Driver/C_threads_tasks.cpp

raw
1 /*! \file C_threads_tasks.hpp
2 \brief tasks executed asynchronously with threads
3 \author Atsushi Suzuki, Laboratoire Jacques-Louis Lions
4 \date Apr. 22th 2013
5 \date Jul. 12th 2015
6 \date Nov. 30th 2016
7 */
8
9 // This file is part of Dissection
10 //
11 // Dissection is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // Linking Dissection statically or dynamically with other modules is making
17 // a combined work based on Disssection. Thus, the terms and conditions of
18 // the GNU General Public License cover the whole combination.
19 //
20 // As a special exception, the copyright holders of Dissection give you
21 // permission to combine Dissection program with free software programs or
22 // libraries that are released under the GNU LGPL and with independent modules
23 // that communicate with Dissection solely through the Dissection-fortran
24 // interface. You may copy and distribute such a system following the terms of
25 // the GNU GPL for Dissection and the licenses of the other code concerned,
26 // provided that you include the source code of that other code when and as
27 // the GNU GPL requires distribution of source code and provided that you do
28 // not modify the Dissection-fortran interface.
29 //
30 // Note that people who make modified versions of Dissection are not obligated
31 // to grant this special exception for their modified versions; it is their
32 // choice whether to do so. The GNU General Public License gives permission to
33 // release a modified version without this exception; this exception also makes
34 // it possible to release a modified version which carries forward this
35 // exception. If you modify the Dissection-fortran interface, this exception
36 // does not apply to your modified version of Dissection, and you must remove
37 // this exception when you distribute your modified version.
38 //
39 // This exception is an additional permission under section 7 of the GNU
40 // General Public License, version 3 ("GPLv3")
41 //
42 // Dissection is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU General Public License for more details.
46 //
47 // You should have received a copy of the GNU General Public License
48 // along with Dissection. If not, see <http://www.gnu.org/licenses/>.
49 //
50
51 #include "Compiler/OptionLibrary.hpp"
52 #include <iostream>
53 #include <float.h>
54 #include <cmath> // for isnan()
55
56 #include "Compiler/blas.hpp"
57 #include "Driver/C_threads_tasks.hpp"
58 #include "Driver/C_KernDetect.hpp"
59 #include "Algebra/VectorArray.hpp"
60 #include "Compiler/DissectionIO.hpp"
61
62 // #define DEBUG_SVD
63 #ifdef DEBUG_SVD
64 #include "mkl_lapack.h"
65 #endif
66
67 void C_dummy(void *arg_) { };
68
69 //#define DEBUG_ERASENULLPARENTS
70 int EraseNullParents(vector<C_task *> &queue)
71 {
72 int count = 0;
73 for (vector<C_task *>::const_iterator it = queue.begin(); it != queue.end();
74 ++it) {
75 for (list<C_task *>::iterator jt = (*it)->parents->begin();
76 jt != (*it)->parents->end(); ) {
77 if (*(*jt)->ops_complexity == 0L) {
78 count++;
79 jt = (*it)->parents->erase(jt);
80 }
81 else {
82 ++jt;
83 }
84 }
85 }
86 return count;
87 }
88
89 int EraseNullParents(C_task * task)
90 {
91 int count = 0;
92 for (list<C_task *>::iterator jt = task->parents->begin();
93 jt != task->parents->end(); ) {
94 if (*(*jt)->ops_complexity == 0L) {
95 count++;
96 jt = task->parents->erase(jt);
97 }
98 else {
99 ++jt;
100 }
101 }
102 return count;
103 }
104
105 template<typename T, typename U>
106 void C_SparseSymbFact(void *arg_)
107 {
108 C_SparseSymbFact_arg<T, U> *arg = (C_SparseSymbFact_arg<T, U> *)arg_;
109 TridiagBlockMatrix<T, U>** tridiag = arg->tridiag;
110 const int colors = arg->colors;
111 int *color_mask = arg->color_mask;
112 const int nrow = arg->nrow;
113 const int nnz0 = arg->csr_diag->nnz;
114 int* prow0 = arg->csr_diag->ptRows;
115 int* indcols0 = arg->csr_diag->indCols;
116 int* indvals0 = arg->csr_diag->indVals;
117 // bool verbose = arg->verbose;
118 // FILE *fp = *(arg->fp);
119 for (int i = 0; i < colors; i++) {
120 tridiag[i]->SymbolicFact((i + 1), colors, color_mask, nrow,
121 nnz0, prow0, indcols0, indvals0); //
122 }
123 }
124
125 template
126 void C_SparseSymbFact<double, double>(void *arg_);
127
128 template
129 void C_SparseSymbFact<quadruple, quadruple>(void *arg_);
130
131 template
132 void C_SparseSymbFact<complex<double>, double>(void *arg_);
133
134 template
135 void C_SparseSymbFact<complex<quadruple>, quadruple>(void *arg_);
136
137 template
138 void C_SparseSymbFact<float, float>(void *arg_);
139
140 template
141 void C_SparseSymbFact<complex<float>, float>(void *arg_);
142
143 //
144
145 void c_getrealtime_(uint64_t &tmprofiles, const int &m)
146 {
147 elapsed_t *tmprfs = (elapsed_t *)tmprofiles;
148 get_realtime(&tmprfs[m]);
149 }
150
151 void c_fileout_(uint64_t &fp_prt, char *strgs, const int &force_stderr)
152 {
153 if (force_stderr == 1) {
154 fprintf(stderr, "%s\n", strgs);
155 }
156 else {
157 FILE *fp = (FILE *)fp_prt;
158 fprintf(fp, "%s\n", strgs);
159 }
160 }
161
162 int compare_source_dist_index(const void *_a, const void *_b)
163 {
164 source_dist_index *a = (source_dist_index *)_a;
165 source_dist_index *b = (source_dist_index *)_b;
166 if (a->global_i == b->global_i) {
167 return (int)(a->global_j - b->global_j);
168 }
169 else {
170 return (int)(a->global_i - b->global_i);
171 }
172 }
173
174 int convert_array2strip(list<index_strip> &strips,
175 const vector<int>& array)
176 {
177 const int size = array.size();
178 strips.clear();
179 int in_strip = 0;
180 int begin_dst, width;
181
182 for (int i = 0; i < size; i++) {
183 if ((in_strip == 0) && (array[i] != (-1))) {
184 in_strip = 1;
185 begin_dst = i;
186 }
187 if (i < (size - 1)) {
188 if ((in_strip == 1) &&
189 ((array[i + 1] == (-1)) || (array[i + 1] != (array[i] + 1)))) {
190 in_strip = 0;
191 width = (i + 1) - begin_dst;
192 // constructor
193 strips.push_back(index_strip(begin_dst,
194 array[begin_dst], // begin_src
195 width));
196 if (array[i + 1] != (array[i] + 1)) {
197 begin_dst = i + 1;
198 }
199 }
200 }
201 }
202 if (in_strip == 1) {
203 width = size - begin_dst;
204 strips.push_back(index_strip(begin_dst,
205 array[begin_dst], // begin_src
206 width));
207 }
208
209 return strips.size();
210 }
211
212 int combine_two_strips(list<index_strip> &stripsa,
213 list<index_strip> &stripsb,
214 list<index_strip2> &stripsc,
215 list<index_strip> &strips0,
216 list<index_strip> &strips1,
217 const int size)
218 {
219 stripsa.clear();
220 stripsb.clear();
221 stripsc.clear();
222
223 if (strips0.size() == 0 && strips1.size() == 0) {
224 return 0;
225 }
226
227 if (strips0.size() == 0) {
228 stripsa.clear();
229 stripsb.clear();
230 for (list<index_strip>::const_iterator it = strips1.begin();
231 it != strips1.end();
232 ++it) {
233 stripsc.push_back(index_strip2((*it).begin_dst,
234 -1,
235 (*it).begin_src,
236 (*it).width));
237 }
238 return strips1.size();
239 }
240
241 if (strips1.size() == 0) {
242 stripsa.clear();
243 stripsb.clear();
244 for (list<index_strip>::const_iterator it = strips0.begin();
245 it != strips0.end();
246 ++it) {
247 stripsc.push_back(index_strip2((*it).begin_dst,
248 (*it).begin_src,
249 -1,
250 (*it).width));
251 }
252 return strips0.size();
253 }
254
255 vector<int> ary0(size, (-1));
256 vector<int> ary1(size, (-1));
257 int in_strip0, in_strip;
258 int begin_dst = (-1), width;
259
260 for (list<index_strip>::const_iterator it = strips0.begin();
261 it != strips0.end();
262 ++it) {
263 int i0 = (*it).begin_dst;
264 int i1 = (*it).begin_src;
265 for (int i = 0; i < (*it).width; i++) {
266 ary0[i0++] = i1++;
267 }
268 }
269 for (list<index_strip>::const_iterator it = strips1.begin();
270 it != strips1.end();
271 ++it) {
272 int i0 = (*it).begin_dst;
273 int i1 = (*it).begin_src;
274 for (int i = 0; i < (*it).width; i++) {
275 ary1[i0++] = i1++;
276 }
277 }
278
279 in_strip0 = in_strip = 0;
280
281 for (int i = 0; i < size; i++) {
282 // save current status on strip
283 in_strip0 = in_strip;
284 if ((in_strip == 0 || in_strip == 2) && (ary0[i] != (-1))) {
285 in_strip += 1;
286 }
287 if ((in_strip == 0 || in_strip == 1) && (ary1[i] != (-1))) {
288 in_strip += 2;
289 }
290 if (in_strip > in_strip0) {
291 // strip0 or strip1 -> union of strips0 and strips1
292 if (in_strip0 > 0) {
293 width = i - begin_dst;
294 switch (in_strip0) {
295 case 1:
296 stripsa.push_back(index_strip(begin_dst, ary0[begin_dst], width));
297 break;
298 case 2:
299 stripsb.push_back(index_strip(begin_dst, ary1[begin_dst], width));
300 break;
301 }
302 }
303 begin_dst = i;
304 }
305 // save current status on strip
306 in_strip0 = in_strip;
307 //
308 if (i < (size - 1)) {
309 // decreasing into strip0 or strip1 or null
310 if ((in_strip == 1 || in_strip == 3) &&
311 ((ary0[i + 1] == (-1)) || (ary0[i + 1] != (ary0[i] + 1)))) {
312 in_strip -= 1;
313 }
314 if ((in_strip == 2 || in_strip == 3) &&
315 ((ary1[i + 1] == (-1)) || (ary1[i + 1] != (ary1[i] + 1)))) {
316 in_strip -= 2;
317 }
318 if (in_strip0 > in_strip) {
319 // output union of strip0 and strip1, strip0 or strip1
320 width = (i + 1) - begin_dst;
321 switch (in_strip0) {
322 case 1:
323 stripsa.push_back(index_strip(begin_dst, ary0[begin_dst], width));
324 break;
325 case 2:
326 stripsb.push_back(index_strip(begin_dst, ary1[begin_dst], width));
327 break;
328 case 3:
329 stripsc.push_back(index_strip2(begin_dst,
330 ary0[begin_dst],
331 ary1[begin_dst], width));
332 break;
333 }
334 // strip0 or strip1
335 if (in_strip > 0) {
336 begin_dst = i + 1;
337 }
338 in_strip0 = in_strip;
339 } // if (in_strip0 > in_strip) {
340 } // if (i < (size - 1))
341 } // loop : i
342 if (in_strip > 0) {
343 width = size - begin_dst;
344
345 switch (in_strip0) {
346 case 1:
347 stripsa.push_back(index_strip(begin_dst, ary0[begin_dst], width));
348 break;
349 case 2:
350 stripsb.push_back(index_strip(begin_dst, ary1[begin_dst], width));
351 break;
352 case 3:
353 stripsc.push_back(index_strip2(begin_dst,
354 ary0[begin_dst],
355 ary1[begin_dst], width));
356 break;
357 }
358 }
359 return (stripsa.size() + stripsb.size() + stripsc.size());
360 }
361 void copy_two_strips(list<index_strip2> &strips2,
362 list<index_strip> &strips0,
363 list<index_strip> &strips1)
364 {
365 strips2.clear();
366
367 list <index_strip>::const_iterator mt0 = strips0.begin();
368 list <index_strip>::const_iterator mt1 = strips1.begin();
369 for ( ; ((mt0 != strips0.end()) && (mt1 != strips1.end())); ++mt0, ++mt1) {
370 strips2.push_back(index_strip2((*mt0).begin_dst,
371 (*mt0).begin_src,
372 (*mt1).begin_src,
373 (*mt0).width));
374 }
375 }
376
377 void split_two_strips(list<index_strip> &strips0,
378 list<index_strip> &strips1,
379 list<index_strip2> &strips2,
380 index_strip strip0,
381 index_strip strip1)
382 {
383 // assumption : union of strip0 and strip1 is not empty
384 // strips0 = strip0 \setminus strip1
385 // strips1 = strip1 \setminus strip0
386 // strips01 = strip0 \cap strip1
387 strips0.clear();
388 strips1.clear();
389 strips2.clear();
390 int begin_dst = 0;
391 int width = 0;
392 int begin_src0 = strip0.begin_src;
393 int begin_src1 = strip1.begin_src;
394 int end_dst0 = strip0.begin_dst + strip0.width;
395 int end_dst1 = strip1.begin_dst + strip1.width;
396
397 if (strip0.begin_dst < strip1.begin_dst) {
398 width = strip1.begin_dst - strip0.begin_dst;
399 strips0.push_back(index_strip(strip0.begin_dst,
400 strip0.begin_src,
401 width));
402 begin_src0 += width;
403 }
404 else if (strip0.begin_dst > strip1.begin_dst) {
405 width = strip0.begin_dst - strip1.begin_dst;
406 strips1.push_back(index_strip(strip1.begin_dst,
407 strip1.begin_src,
408 width));
409 begin_src1 += width;
410 }
411 begin_dst += width;
412 const int end_dst = end_dst0 < end_dst1 ? end_dst0 : end_dst1;
413 const int width2 = end_dst - begin_dst;
414 strips2.push_back(index_strip2(begin_dst,
415 begin_src0,
416 begin_src1,
417 width2));
418 if (end_dst0 < end_dst1) {
419 strips1.push_back(index_strip(end_dst, // 27 Nov.2016 bug found
420 begin_src1 + width2, // begin_src0 + width
421 end_dst1 - end_dst0));
422 }
423 else if (end_dst0 > end_dst1) {
424 strips0.push_back(index_strip(end_dst,
425 begin_src0 + width2, // begin_src1 + width
426 end_dst0 - end_dst1));
427 }
428 }
429
430 void print_strips(const char *name, list<index_strip> &strips,
431 FILE *fp)
432 {
433 fprintf(fp, "%s : ", name);
434 for (list <index_strip>::const_iterator mt = strips.begin();
435 mt != strips.end(); ++mt) {
436 fprintf(fp, "[ %d %d %d ] ",
437 (*mt).begin_dst, (*mt).begin_src, (*mt).width);
438 }
439 fprintf(fp, "\n");
440 }
441
442 void print_strips(const char *name, list<index_strip2> &strips, FILE *fp)
443 {
444 fprintf(fp, "%s : ", name);
445 for (list <index_strip2>::const_iterator mt = strips.begin();
446 mt != strips.end(); ++mt) {
447 fprintf(fp, "[ %d %d %d %d ] ",
448 (*mt).begin_dst, (*mt).begin_src0, (*mt).begin_src1, (*mt).width);
449 }
450 fprintf(fp, "\n");
451 }
452
453
454 bool C_task_seq_complexity_smaller(C_task_seq *a, C_task_seq *b)
455 {
456 if (a->ops_complexity < b->ops_complexity) {
457 return true;
458 }
459 else {
460 return false;
461 }
462 }
463 bool C_task_seq_complexity_greater(C_task_seq *a, C_task_seq *b)
464 {
465 if (a->ops_complexity > b->ops_complexity) {
466 return true;
467 }
468 else {
469 return false;
470 }
471 }
472
473 bool C_task_seq_beginidx_smaller(C_task_seq *a, C_task_seq *b)
474 {
475 if (a->begin < b->begin) {
476 return true;
477 }
478 else {
479 return false;
480 }
481 }
482
483
484 void assign_tasks_statically(list<C_task_seq*> *queue_static,
485 list<C_task_seq*> &queue_dynamic,
486 long *nops_sum,
487 list<C_task_seq *> &task_seq_tmp,
488 const int task_id,
489 const char *task_name_,
490 const int level,
491 const int phase,
492 const long nops_block_total,
493 int num_threads)
494 {
495 const long nops_per_thread = nops_block_total / (long)num_threads;
496 #ifdef DEBUG_PREPARE_THREAD
497 cout << "nops_bock_total = " << nops_block_total
498 << " nops_per_thread = " << nops_per_thread << endl;
499 #endif
500 list<C_task_seq *>::const_iterator it;
501 int task_begin;
502 vector<list<C_task_seq *> > queue_divided(num_threads);
503
504 vector<int> excluding_list(num_threads, 0);
505 long *nops_sum0 = new long[num_threads]; // for debugging
506 #ifdef DEBUG_PREPARE_THREAD
507 cout << "excluded indices ";
508 #endif
509 int excluded = 0;
510 for (int i = 0; i < num_threads; i++) {
511 nops_sum0[i] = nops_sum[i]; // for debugging
512 if (nops_sum[i] >= nops_per_thread) {
513 excluding_list[i] = 1;
514 excluded++;
515 #ifdef DEBUG_PREPARE_THREAD
516 cout << i << " ";
517 #endif
518 }
519 }
520 #ifdef DEBUG_PREPARE_THREAD
521 cout << endl;
522 #endif
523 if (excluded == num_threads) {
524 for (int i = 0; i < num_threads; i++) {
525 excluding_list[i] = 0;
526 }
527 }
528 int ll = (-1);
529 while(excluding_list[++ll] == 1) {
530 #ifdef DEBUG_PREPARE_THREAD
531 if (nops_sum[ll] > 0) {
532 cout << "+ll = " << ll << " start = " << nops_sum[ll] << " " ;
533 }
534 #endif
535 }
536
537 it = task_seq_tmp.begin();
538 task_begin = (*it)->begin;
539 int flag = 0;
540 for ( ; it != task_seq_tmp.end(); ++it) {
541 long nops = 0L;
542 for (int i = (*it)->begin; i < (*it)->end; i++) {
543 flag = 0;
544 vector<C_task* >& jt = *((*it)->queue);
545 const long ltmp = *(jt[i]->ops_complexity);
546 int ii = 0; // initializing
547 if ((nops_sum[ll] < nops_per_thread) &&
548 ((nops_sum[ll] + (ltmp / 2UL)) >= nops_per_thread)) {
549 if (ll == (num_threads - 1)) { // include blocks into the last thread
550 nops_sum[ll] += ltmp;
551 nops += ltmp;
552 #if 1
553 flag = (-2);
554 ii = i;
555 #else
556 flag = 0;
557 #endif
558 }
559 else {
560 ii = i;
561 flag = 1;
562 }
563 }
564 else {
565 nops_sum[ll] += ltmp;
566 nops += ltmp;
567 if (nops_sum[ll] > nops_per_thread) {
568 if (ll == (num_threads - 1)) { // include blocks into the last thread
569 #if 1
570 flag = (-2);
571 ii = i + 1;
572 #else
573 flag = 0;
574 #endif
575 }
576 else {
577 ii = i + 1;
578 flag = (-1);
579 }
580 }
581 }
582 // 7 May 2014 : to accpet atomic_size > 1
583 if (ii < (*it)->queue->size()) {
584 ii -= (*(*it)->queue)[ii]->atomic_id;
585 }
586 if (flag != 0) {
587 if (nops > 0L) { // to avoid zero addition when nops_sum[ll] exceed
588 // the nops_per_thread at the beginning
589 string task_name = (task_name_ + to_string(level) + " : "
590 + (*it)->task_name + " :: "
591 + to_string(task_begin) + " : "
592 + to_string(ii));
593 // char *task_name_cstr = new char[task_name.str().size() + 1];
594 // strcpy(task_name_cstr, task_name.str().c_str());
595 // cout << "-ll = " << ll << " nops_sum = " << nops_sum[ll] << " "
596 // << task_name_cstr << endl;
597 C_task_seq* tmp =
598 new C_task_seq(task_id,
599 task_name,
600 (-1), // mutex_id
601 TASK_SINGLE,
602 1,
603 level,
604 phase,
605 (*it)->queue,
606 task_begin,
607 ii,
608 nops);
609 queue_divided[ll].push_back(tmp);
610 }
611 #if 1
612 if (flag == (-2)) {
613 task_begin = ii;
614 break; // loop : i
615 }
616 #endif
617 while(excluding_list[++ll] == 1) {
618 // cout << "+ll = " << ll << " start = " << nops_sum[ll] << " " ;
619 }
620 if (ii < (*it)->end) { // flag == 1
621 task_begin = ii;
622 }
623 else {
624 list<C_task_seq *>::const_iterator kt = it;
625 ++kt;
626 if (kt != task_seq_tmp.end()) { // for the next queue
627 task_begin = (*kt)->begin;
628 }
629 }
630 if (flag == 1) {
631 nops = ltmp;
632 nops_sum[ll] += ltmp;
633 }
634 else {
635 nops = 0L;
636 }
637 }
638 } // loop : i
639 #if 1
640 if (flag == (-2)) { // special case moving static to dynamic
641 break; // loop : it
642 }
643 #endif
644 if (flag >= 0) {
645 string task_name = (task_name_ + to_string(level) + " : "
646 + (*it)->task_name + " :: "
647 + to_string(task_begin) + " : "
648 + to_string((*it)->end));
649 C_task_seq* tmp =
650 new C_task_seq(task_id,
651 task_name,
652 // task_name_cstr,
653 (-1), // mutex_id
654 TASK_SINGLE,
655 1,
656 level,
657 phase,
658 (*it)->queue,
659 task_begin,
660 (*it)->end,
661 nops);
662 queue_divided[ll].push_back(tmp);
663 list<C_task_seq *>::const_iterator jt = it;
664 ++jt;
665 if (jt != task_seq_tmp.end()) { // for the next queue
666 task_begin = (*jt)->begin;
667 }
668 }
669 } // loop : it
670 #if 1
671 if (flag == (-2)) {
672 // task_begin -= (*(*it)->queue)[task_begin]->atomic_id;
673 long nops = 0L;
674 for (int i = task_begin; i < (*it)->end; i++) {
675 nops += *((*(*it)->queue)[i]->ops_complexity);
676 }
677 string task_name = (task_name_ + to_string(level) + " : "
678 + (*it)->task_name + " :: "
679 + to_string(task_begin) + " : "
680 + to_string((*it)->end));
681 C_task_seq* tmp =
682 new C_task_seq(task_id,
683 task_name,
684 0, // mutex_id
685 TASK_PARALLEL,
686 num_threads,
687 level,
688 phase,
689 (*it)->queue,
690 task_begin,
691 (*it)->end,
692 nops);
693 queue_dynamic.push_back(tmp);
694 ++it;
695 for ( ; it != task_seq_tmp.end(); ++it) {
696 for (int i = (*it)->begin; i < (*it)->end; i++) {
697 nops += *((*(*it)->queue)[i]->ops_complexity);
698 }
699 string task_name = (task_name_ + to_string(level) + " : "
700 + (*it)->task_name + " :: "
701 + to_string((*it)->begin) + " : "
702 + to_string((*it)->end));
703 C_task_seq* tmp =
704 new C_task_seq(task_id,
705 task_name,
706 0, // mutex_id
707 TASK_PARALLEL,
708 num_threads,
709 level,
710 phase,
711 (*it)->queue,
712 (*it)->begin,
713 (*it)->end,
714 nops);
715 queue_dynamic.push_back(tmp);
716 } // loop : it
717 } // flag == (-2)
718 #endif
719 #ifdef DEBUG_PREPARE_THREAD
720 cout << "-- assigned task -- per thread = "
721 << nops_per_thread << " -- ";
722 for (list<C_task_seq *>::const_iterator it = task_seq_tmp.begin();
723 it != task_seq_tmp.end(); ++it) {
724 cout << (*it)->task_name << " ; "
725 << (*it)->begin << " : "
726 << (*it)->end << " / " ;
727 }
728 cout << "-- " << endl;
729 #endif
730 for (ll = 0; ll < num_threads; ll++) {
731 #ifdef DEBUG_PREPARE_THREAD
732 cout << "thread_id " << ll
733 << " nops_sum0 = " << nops_sum0[ll]
734 << " : nops_sum = " << nops_sum[ll] << " : ";
735 #endif
736 queue_divided[ll].sort(C_task_seq_beginidx_smaller);
737 for (list<C_task_seq *>::const_iterator it = queue_divided[ll].begin();
738 it != queue_divided[ll].end(); ++it) {
739 #ifdef DEBUG_PREPARE_THREAD
740 cout << (*it)->task_name << " ";
741 #endif
742 queue_static[ll % num_threads].push_back(*it);
743 }
744 #ifdef DEBUG_PREPARE_THREAD
745 cout << endl;
746 #endif
747 } // loop : ll
748
749 for (list<C_task_seq *>::iterator it = task_seq_tmp.begin();
750 it != task_seq_tmp.end(); ++it) {
751 delete (*it); // delete [] (*it)->task_name;
752 (*it) = NULL;
753 }
754 task_seq_tmp.clear();
755
756 // unbalance in assigned tasks is to be reduced by greedy execution but
757 // unbalance from the beginning is passed to the next block
758 for (int i = 0; i < num_threads; i++) {
759 if (excluding_list[i]) {
760 nops_sum[i] -= nops_per_thread;
761 }
762 else {
763 nops_sum[i] = 0L;
764 }
765 }
766 delete [] nops_sum0;
767 }
768
769 template<typename T, typename U>
770 int dimKernDense(vector<int> &singIdx, const int n,
771 const int aug_dim,
772 const U eps_machine,
773 const double eps_piv,
774 SquareBlockMatrix<T> &D,
775 T *a,
776 const bool refactorize,
777 const bool isFullPermute,
778 const bool isSym,
779 const bool verbose,
780 FILE *fp)
781 {
782 // output == (-1) : refactorized / >= 0 : dim of the kernel
783 // check dim of factorized matrix
784 int sing_max = singIdx.size();
785 int aug_max = sing_max + aug_dim;
786 // map<int, int> aug_ind;
787 list<int> aug_ind;
788 vector<int> aug_ind0, aug_ind1;
789 aug_ind0.resize(aug_max);
790 aug_ind1.resize(aug_max);
791 VectorArray<T> a_diag(aug_max);
792 const T zero(0.0);
793 const T one(1.0);
794 const T none(-1.0);
795
796 diss_printf(verbose, fp,
797 "%s %d : Schur complement form %d x %d : block size = %d\n",
798 __FILE__, __LINE__, n, aug_max, D.block_size());
799 RectBlockMatrix<T> b(n, aug_max, D.block_size());
800 RectBlockMatrix<T> c(n, aug_max, D.block_size());
801
802 ColumnMatrix<T> s;
803 s.init(aug_max, aug_max);
804 int *permute_d = new int[sing_max];
805 vector<int> &permute = D.getPermute();
806 for (int k = 0; k < sing_max; k++) {
807 aug_ind.push_back(singIdx[k]);
808 }
809 int k0 = (n - 1);
810 int k1 = sing_max;
811 while ((k1 < aug_max) && k0 >= 0) {
812 bool flag = true;
813 for (int i = 0; i < sing_max; i++) {
814 if (singIdx[i] == k0) {
815 flag = false;
816 break;
817 }
818 }
819 if (flag) {
820 aug_ind.push_back(k0);
821 k1++;
822 }
823 k0--;
824 } // while
825 aug_ind.sort();
826 { // for scope of int i
827 int i = 0;
828 for (list<int>::const_iterator it = aug_ind.begin(); it != aug_ind.end();
829 ++it, i++) {
830 aug_ind0[i] = (*it);
831 aug_ind1[i] = permute[(*it)];
832 }
833 }
834 aug_ind.clear();
835 diss_printf(verbose, fp, "%s %d : suspicious dimension of pivots %d + %d\n",
836 __FILE__, __LINE__, sing_max, aug_dim);
837 for (int i = 0; i < aug_max; i++) {
838 diss_printf(verbose, fp, "%d : %d %d %s\n", i, aug_ind0[i], aug_ind1[i],
839 tostring<T>(D.diag(aug_ind0[i])).c_str());
840 }
841 // save diagonal entries coressponding to nullification
842 for (int i = 0; i < aug_max; i++) {
843 a_diag[i] = D.diag(aug_ind0[i]); // a[aug_ind0[j] * (n + 1)];
844 }
845
846 if (isSym) {
847 for (int j = 0; j < aug_max; j++) {
848 D.diag(aug_ind0[j]) = zero; // nullifying diagonals
849 for (int i = 0; i < n; i++) {
850 // access upper for symmetric matrix
851 const int ii = i > aug_ind1[j] ? aug_ind1[j] : i;
852 const int jj = i > aug_ind1[j] ? i : aug_ind1[j];
853 b(i, j) = a[ii + jj * n];
854 } // loop : i
855 } // loop : j
856 }
857 else {
858 for (int j = 0; j < aug_max; j++) {
859 D.diag(aug_ind0[j]) = zero;
860 for (int i = 0; i < n; i++) {
861 const int jj = aug_ind1[j];
862 b(i, j) = a[i + jj * n];
863 c(i, j) = a[jj + i * n];
864 }
865 }
866 }
867 for (int j = 0; j < aug_max; j++) {
868 for (int i = 0; i < aug_max; i++) {
869 s(i, j) = b(aug_ind1[i], j);
870 }
871 }
872
873 DTRSMScale_arg<T> *tmp_arg =
874 new DTRSMScale_arg<T>(isSym,
875 &D,
876 &b,
877 &c,
878 n, // nrow
879 aug_max, // ncol
880 (-1), // kblock
881 0, // lblock
882 (-1), // mblock
883 &aug_ind0, //singval,
884 (!isFullPermute),
885 verbose,
886 &fp,
887 -1); //dummy
888 C_DTRSMScale_solve<T>(tmp_arg);
889 delete tmp_arg;
890
891 for (int i = 0; i < b.num_blocks_c(); i++) {
892 for (int j = 0; j < b.num_blocks_c(); j++) {
893 for (int k = 0; k < b.num_blocks_r(); k++) {
894 int nrow = c.nrowBlock(k);
895 blas_gemm<T>(CblasTrans, CblasNoTrans,
896 c.ncolBlock(i), b.ncolBlock(j), nrow,
897 none, // alpha = -1
898 c.addrCoefBlock(k, i), nrow,
899 b.addrCoefBlock(k, j), nrow,
900 one, // beta = 1
901 s.addrCoefs() + (c.IndexBlock_r(i) + b.IndexBlock_c(j) * aug_max),
902 aug_max);
903 }
904 } // loop : i
905 } // loop : j
906 // symmetrize
907 if (isSym) {
908 for (int j = 0; j < aug_max; j++) {
909 for (int i = 0; i < j; i++) {
910 s[j + i * aug_max] = s[i + j * aug_max];
911 }
912 }
913 }
914 ColumnMatrix<T> ss(aug_max, aug_max);
915 ss.copy(s);
916 bool flagShrinkSchur = false;
917 int nn0 = sing_max;
918 int *permute1 = new int[aug_max];
919 #if 0
920 {
921 double pivot = 1.0;
922 double fop;
923 int n0;
924 n0 = 0;
925 if (isSym) {
926 full_ldlt_permute<T, U>(&nn0, n0, aug_max, ss.addrCoefs(), aug_max,
927 &pivot, permute1, eps_piv, &fop);
928 } // if (arg->isSym)
929 else {
930 full_ldu_permute<T, U>(&nn0, n0, aug_max, ss.addrCoefs(), aug_max,
931 &pivot, permute1, eps_piv, &fop);
932 }
933 diss_printf(verbose, fp,
934 "%s %d : %d -> %d ", __FILE__, __LINE__, sing_max, nn0);
935
936 if (nn0 < sing_max) {
937 flagShrinkSchur = true;
938 diss_printf(verbose, fp,
939 "schrink the Schur complement by recursive computing\n");
940 for (int i = 0; i < aug_max; i++) {
941 diss_printf(verbose, fp, "%d ", permute1[i]);
942 }
943 diss_printf(verbose, fp, "\n");
944 }
945 else {
946 diss_printf(verbose, fp, "\n");
947 }
948 }
949 #endif
950 int aug_max1 = aug_max;
951 if (flagShrinkSchur) {
952 aug_max1 = aug_dim + nn0;
953 int aug_max0 = aug_max - aug_max1;
954 ColumnMatrix<T> sc(aug_max1, aug_max1);
955 for (int j = 0; j < aug_max1; j++) {
956 const int jj = permute1[aug_max - aug_max1 + j];
957 for (int i = 0; i < aug_max1; i++) {
958 const int ii = permute1[aug_max - aug_max1 + i];
959 sc(i, j) = s(ii, jj);
960 }
961 }
962 ColumnMatrix<T> upper(aug_max0, aug_max1);
963 ColumnMatrix<T> lower(aug_max0, aug_max1);
964 if (!isSym) {
965 for (int j = 0; j < aug_max1; j++) {
966 const int jj = permute1[aug_max - aug_max1 + j];
967 for (int i = 0; i < aug_max0; i++) {
968 const int ii = permute1[i];
969 upper(i, j) = s(ii, jj);
970 lower(i, j) = s(jj, ii);
971 }
972 }
973 blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit,
974 aug_max0, aug_max1, one, ss.addrCoefs(), aug_max,
975 upper.addrCoefs(), aug_max0);
976 for (int i = 0; i < aug_max0; i++) {
977 const T stmp = ss(i, i);
978 for (int j = 0; j < aug_max1; j++) {
979 upper(i, j) *= stmp;
980 }
981 }
982 blas_trsm<T>(CblasLeft, CblasUpper, CblasTrans, CblasUnit,
983 aug_max0, aug_max1, one, ss.addrCoefs(), aug_max,
984 lower.addrCoefs(), aug_max0);
985 }
986 else {
987 for (int j = 0; j < aug_max1; j++) {
988 const int jj = permute1[aug_max - aug_max1 + j];
989 for (int i = 0; i < aug_max0; i++) {
990 const int ii = permute1[i];
991 lower(i, j) = s(ii, jj); // copy from upper
992 }
993 }
994 blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit,
995 aug_max0, aug_max1, one, ss.addrCoefs(), aug_max,
996 lower.addrCoefs(), aug_max0);
997 for (int i = 0; i < aug_max0; i++) {
998 const T stmp = ss(i, i);
999 for (int j = 0; j < aug_max1; j++) {
1000 upper(i, j) = lower(i, j) * stmp;
1001 }
1002 }
1003 }
1004 blas_gemm<T>(CblasTrans, CblasNoTrans, aug_max1, aug_max1, aug_max0,
1005 none, lower.addrCoefs(), aug_max0, upper.addrCoefs(),
1006 aug_max0, one,
1007 sc.addrCoefs(), aug_max1);
1008
1009 upper.free();
1010 lower.free();
1011 s.free();
1012 s.init(aug_max1, aug_max1);
1013 s.copy(sc);
1014 // blas_copy<T>((aug_max1 * aug_max1), sc, 1, s, 1);
1015 sc.free();
1016 sing_max = nn0;
1017 } // if (flagShrinkSchur) {
1018 ss.free();
1019 delete [] permute1;
1020
1021 int n2;
1022 bool flag, flag_unsym_pivot;
1023
1024 flag = ComputeDimKernel<T, U>(&n2, &flag_unsym_pivot, s.addrCoefs(), aug_max1, isSym,
1025 aug_dim, eps_machine, eps_piv, verbose, fp);
1026 diss_printf(verbose, fp, "%s %d : detected dim. of the kernel = %d %s\n",
1027 __FILE__, __LINE__, n2, flag_unsym_pivot ? "full" : "symmetric");
1028 //
1029 // restore stored diagonal entries nullified for augmented dimenison
1030 for (int i = 0; i < aug_max; i++) {
1031 D.diag(aug_ind0[i]) = a_diag[i];
1032 }
1033 if (flag_unsym_pivot) {
1034 return 0; // force kernel detection failure : 15 May 2018
1035 }
1036 if ((n2 != sing_max)) {
1037 if (refactorize) {
1038 diss_printf(verbose, fp,
1039 "%s %d : sing_max = %d n2 = %d -> refactorized\n",
1040 __FILE__, __LINE__, sing_max, n2);
1041 return (-1);
1042 }
1043 } // if (n2 != sing_max)
1044
1045 aug_ind0.clear();
1046 aug_ind1.clear();
1047 a_diag.free();
1048 b.free();
1049 c.free();
1050 s.free();
1051 delete [] permute_d;
1052
1053 return n2;
1054 }
1055
1056 template
1057 int dimKernDense<double, double>(vector<int> &singIdx,
1058 const int n,
1059 const int aug_dim,
1060 const double eps_machine,
1061 const double eps_piv,
1062 SquareBlockMatrix<double> &D,
1063 double *a,
1064 const bool refactorize,
1065 const bool isFullPermute,
1066 const bool isSym,
1067 const bool verbose,
1068 FILE *fp);
1069
1070 template
1071 int dimKernDense<quadruple,
1072 quadruple>(vector<int> &singIdx,
1073 const int n,
1074 const int aug_dim,
1075 const quadruple eps_machine,
1076 const double eps_piv,
1077 SquareBlockMatrix<quadruple> &D,
1078 quadruple *a,
1079 const bool refactorize,
1080 const bool isFullPermute,
1081 const bool isSym,
1082 const bool verbose,
1083 FILE *fp);
1084
1085 template
1086 int dimKernDense<complex<double>,
1087 double>(vector<int> &singIdx,
1088 const int n,
1089 const int aug_dim,
1090 const double eps_mahcine,
1091 const double eps_piv,
1092 SquareBlockMatrix<complex<double> > &D,
1093 complex<double> *a,
1094 const bool refactorize,
1095 const bool isFullPermute,
1096 const bool isSym,
1097 const bool verbose,
1098 FILE *fp);
1099
1100 template
1101 int dimKernDense<complex<quadruple>,
1102 quadruple>(vector<int> &singIdx,
1103 const int n,
1104 const int aug_dim,
1105 const quadruple eps_machine,
1106 const double eps_piv,
1107 SquareBlockMatrix<complex<quadruple> > &D,
1108 complex<quadruple> *a,
1109 const bool refactorize,
1110 const bool isFullPermute,
1111 const bool isSym,
1112 const bool verbose,
1113 FILE *fp);
1114
1115 template
1116 int dimKernDense<float, float>(vector<int> &singIdx,
1117 const int n,
1118 const int aug_dim,
1119 const float eps_machine,
1120 const double eps_piv,
1121 SquareBlockMatrix<float> &D,
1122 float *a,
1123 const bool refactorize,
1124 const bool isFullPermute,
1125 const bool isSym,
1126 const bool verbose,
1127 FILE *fp);
1128
1129 template
1130 int dimKernDense<complex<float>,
1131 float>(vector<int> &singIdx,
1132 const int n,
1133 const int aug_dim,
1134 const float eps_mahcine,
1135 const double eps_piv,
1136 SquareBlockMatrix<complex<float> > &D,
1137 complex<float> *a,
1138 const bool refactorize,
1139 const bool isFullPermute,
1140 const bool isSym,
1141 const bool verbose,
1142 FILE *fp);
1143 //
1144
1145 template<typename T>
1146 void calc_relative_norm(double *norm_l2, double *norm_infty,
1147 const T *v, const T *u, const int dim)
1148 {
1149 fprintf(stderr, "%s %d : specialized template is not yet defined.\n",
1150 __FILE__, __LINE__);
1151 }
1152
1153 template<>
1154 void calc_relative_norm<double>(double *norm_l2, double *norm_infty,
1155 const double *v, const double *u, const int dim)
1156 {
1157 double xtmp1 = 0.0, xtmp0 = 0.0;
1158 double ytmp1, ytmp0;
1159 double ztmp1 = 0.0, ztmp0 = 0.0;
1160 for (int i = 0; i < dim; i++) {
1161 ytmp1 = v[i];
1162 ytmp0 = u[i];
1163 if (ytmp1 < 0.0) {
1164 ytmp1 *= (-1.0);
1165 }
1166 if (ytmp0 < 0.0) {
1167 ytmp0 *= (-1.0);
1168 }
1169 xtmp0 = (ytmp0 > xtmp0) ? ytmp0 : xtmp0;
1170 ztmp0 += ytmp0 * ytmp0;
1171
1172 xtmp1 = (ytmp1 > xtmp1) ? ytmp1 : xtmp1;
1173 ztmp1 += ytmp1 * ytmp1;
1174 }
1175 *norm_l2 = sqrt(ztmp1 / ztmp0);
1176 *norm_infty = xtmp1 / xtmp0;
1177 }
1178
1179 template<>
1180 void calc_relative_norm<quadruple>(double *norm_l2, double *norm_infty,
1181 const quadruple *v,
1182 const quadruple *u, const int dim)
1183 {
1184 double xtmp1 = 0.0, xtmp0 = 0.0;
1185 double ytmp1, ytmp0;
1186 double ztmp1 = 0.0, ztmp0 = 0.0;
1187 for (int i = 0; i < dim; i++) {
1188 ytmp1 = quad2double(v[i]);
1189 ytmp0 = quad2double(u[i]);
1190 if (ytmp1 < 0.0) {
1191 ytmp1 *= (-1.0);
1192 }
1193 if (ytmp0 < 0.0) {
1194 ytmp0 *= (-1.0);
1195 }
1196 xtmp0 = (ytmp0 > xtmp0) ? ytmp0 : xtmp0;
1197 ztmp0 += ytmp0 * ytmp0;
1198
1199 xtmp1 = (ytmp1 > xtmp1) ? ytmp1 : xtmp1;
1200 ztmp1 += ytmp1 * ytmp1;
1201 }
1202 *norm_l2 = sqrt(ztmp1 / ztmp0);
1203 *norm_infty = xtmp1 / xtmp0;
1204 }
1205
1206 template<>
1207 void calc_relative_norm<complex<double> >(double *norm_l2, double *norm_infty,
1208 const complex<double> *v,
1209 const complex<double> *u,
1210 const int dim)
1211 {
1212 double xtmp1 = 0.0, xtmp0 = 0.0;
1213 double ztmp1 = 0.0, ztmp0 = 0.0;
1214 for (int i = 0; i < dim; i++) {
1215 const double ytmp1 = std::abs(v[i]);
1216 const double ytmp0 = std::abs(u[i]);
1217
1218 xtmp0 = ytmp0 > xtmp0 ? ytmp0 : xtmp0;
1219 ztmp0 += std::real(u[i] * std::conj(u[i]));
1220 xtmp1 = ytmp1 > xtmp1 ? ytmp1 : xtmp1;
1221 ztmp1 += std::real(v[i] * std::conj(v[i]));
1222 }
1223 *norm_l2 = sqrt(ztmp1 / ztmp0);
1224 *norm_infty = xtmp1 / xtmp0;
1225 }
1226
1227 template<>
1228 void calc_relative_norm<complex<quadruple> >(double *norm_l2,
1229 double *norm_infty,
1230 const complex<quadruple> *v,
1231 const complex<quadruple> *u,
1232 const int dim)
1233 {
1234 double xtmp1 = 0.0, xtmp0 = 0.0;
1235 double ztmp1 = 0.0, ztmp0 = 0.0;
1236 for (int i = 0; i < dim; i++) {
1237 quadruple vr = v[i].real();
1238 quadruple vi = v[i].imag();
1239 quadruple ur = u[i].real();
1240 quadruple ui = u[i].imag();
1241
1242 const double ytmp1 = quad2double(sqrt(vr * vr + vi * vi));
1243 const double ytmp0 = quad2double(sqrt(ur * ur + ui * ui));
1244
1245 xtmp0 = ytmp0 > xtmp0 ? ytmp0 : xtmp0;
1246 ztmp0 += quad2double(ur * ur + ui * ui);
1247 xtmp1 = ytmp1 > xtmp1 ? ytmp1 : xtmp1;
1248 ztmp1 += quad2double(vr * vr + vi * vi);
1249 }
1250 *norm_l2 = sqrt(ztmp1 / ztmp0);
1251 *norm_infty = xtmp1 / xtmp0;
1252 }
1253
1254 template
1255 void calc_relative_norm<float>(double *norm_l2, double *norm_infty,
1256 const float *v, const float *u, const int dim);
1257
1258 template
1259 void calc_relative_norm<complex<float> >(double *norm_l2, double *norm_infty,
1260 const complex<float> *v,
1261 const complex<float> *u,
1262 const int dim);
1263
1264 //
1265 template<typename T, typename Z>
1266 void calc_relative_normscaled(double *norm_l2, double *norm_infty,
1267 const T *v, const T *u, const Z *w,
1268 const int dim)
1269 {
1270 fprintf(stderr, "%s %d : specialized template is not yet defined.\n",
1271 __FILE__, __LINE__);
1272 }
1273
1274 template<>
1275 void calc_relative_normscaled<double,
1276 double>(double *norm_l2, double *norm_infty,
1277 const double *v, const double *u,
1278 const double *w, const int dim)
1279 {
1280 double xtmp1 = 0.0, xtmp0 = 0.0;
1281 double ytmp1, ytmp0;
1282 double ztmp1 = 0.0, ztmp0 = 0.0;
1283 for (int i = 0; i < dim; i++) {
1284 ytmp0 = u[i] / w[i];
1285 ytmp1 = v[i] * w[i];
1286 if (ytmp1 < 0.0) {
1287 ytmp1 *= (-1.0);
1288 }
1289 if (ytmp0 < 0.0) {
1290 ytmp0 *= (-1.0);
1291 }
1292 xtmp0 = (ytmp0 > xtmp0) ? ytmp0 : xtmp0;
1293 ztmp0 += ytmp0 * ytmp0;
1294
1295 xtmp1 = (ytmp1 > xtmp1) ? ytmp1 : xtmp1;
1296 ztmp1 += ytmp1 * ytmp1;
1297 }
1298 *norm_l2 = sqrt(ztmp1 / ztmp0);
1299 *norm_infty = xtmp1 / xtmp0;
1300 }
1301
1302 template<>
1303 void calc_relative_normscaled<quadruple,
1304 quadruple>(double *norm_l2,
1305 double *norm_infty,
1306 const quadruple *v,
1307 const quadruple *u,
1308 const quadruple *w, const int dim)
1309 {
1310 double xtmp1 = 0.0, xtmp0 = 0.0;
1311 double ytmp1, ytmp0;
1312 double ztmp1 = 0.0, ztmp0 = 0.0;
1313 for (int i = 0; i < dim; i++) {
1314 ytmp0 = quad2double(u[i] / w[i]);
1315 ytmp1 = quad2double(v[i] * w[i]);
1316 if (ytmp1 < 0.0) {
1317 ytmp1 *= (-1.0);
1318 }
1319 if (ytmp0 < 0.0) {
1320 ytmp0 *= (-1.0);
1321 }
1322 xtmp0 = (ytmp0 > xtmp0) ? ytmp0 : xtmp0;
1323 ztmp0 += ytmp0 * ytmp0;
1324
1325 xtmp1 = (ytmp1 > xtmp1) ? ytmp1 : xtmp1;
1326 ztmp1 += ytmp1 * ytmp1;
1327 }
1328 *norm_l2 = sqrt(ztmp1 / ztmp0);
1329 *norm_infty = xtmp1 / xtmp0;
1330 }
1331 template<>
1332 void calc_relative_normscaled<complex<double>, double>(double *norm_l2,
1333 double *norm_infty,
1334 const complex<double> *v,
1335 const complex<double> *u,
1336 const double *w,
1337 const int dim)
1338 {
1339 double xtmp1 = 0.0, xtmp0 = 0.0;
1340 double ztmp1 = 0.0, ztmp0 = 0.0;
1341 for (int i = 0; i < dim; i++) {
1342 const double ytmp0 = std::abs(u[i]) / w[i];
1343 const double ytmp1 = std::abs(v[i]) * w[i];
1344 const double ww = w[i] * w[i];
1345 xtmp0 = ytmp0 > xtmp0 ? ytmp0 : xtmp0;
1346 ztmp0 += std::real(u[i] * std::conj(u[i])) / ww;
1347 xtmp1 = ytmp1 > xtmp1 ? ytmp1 : xtmp1;
1348 ztmp1 += std::real(v[i] * std::conj(v[i])) * ww;
1349 }
1350 *norm_l2 = sqrt(ztmp1 / ztmp0);
1351 *norm_infty = xtmp1 / xtmp0;
1352 }
1353
1354 template<>
1355 void calc_relative_normscaled<complex<quadruple>,
1356 quadruple>(double *norm_l2,
1357 double *norm_infty,
1358 const complex<quadruple> *v,
1359 const complex<quadruple> *u,
1360 const quadruple *w,
1361 const int dim)
1362 {
1363 double xtmp1 = 0.0, xtmp0 = 0.0;
1364 double ztmp1 = 0.0, ztmp0 = 0.0;
1365 for (int i = 0; i < dim; i++) {
1366 quadruple vr = v[i].real();
1367 quadruple vi = v[i].imag();
1368 quadruple ur = u[i].real();
1369 quadruple ui = u[i].imag();
1370
1371 const double ytmp0 = quad2double(sqrt(ur * ur + ui * ui) / w[i]);
1372 const double ytmp1 = quad2double(sqrt(vr * vr + vi * vi) * w[i]);
1373 const double ww = quad2double(w[i] * w[i]);
1374 xtmp0 = ytmp0 > xtmp0 ? ytmp0 : xtmp0;
1375 ztmp0 += quad2double(ur * ur + ui * ui) / ww;
1376 xtmp1 = ytmp1 > xtmp1 ? ytmp1 : xtmp1;
1377 ztmp1 += quad2double(vr * vr + vi * vi) * ww;
1378 }
1379 *norm_l2 = sqrt(ztmp1 / ztmp0);
1380 *norm_infty = xtmp1 / xtmp0;
1381 }
1382 //
1383 template
1384 void calc_relative_normscaled<float,
1385 float>(double *norm_l2, double *norm_infty,
1386 const float *v, const float *u,
1387 const float *w, const int dim);
1388
1389 template
1390 void calc_relative_normscaled<complex<float>,
1391 float>(double *norm_l2, double *norm_infty,
1392 const complex<float> *v,
1393 const complex<float> *u,
1394 const float *w, const int dim);
1395 //
1396
1397 int CSR_sym2unsym(CSR_indirect *unsym,
1398 const int *ptSymRows, const int *indSymCols,
1399 const int *map_eqn, const int *remap_eqn,
1400 const int dim, const bool upper_flag, bool verbose, FILE *fp)
1401 {
1402 int* nbIndPerRow = new int[dim];
1403
1404 // memset(nbIndPerRow, 0, dim*sizeof(int));
1405 for (int i = 0; i < dim; i++) {
1406 nbIndPerRow[i] = 0;
1407 }
1408
1409 for (int i = 0; i < dim; i++) {
1410 const int ii = remap_eqn[i];
1411 nbIndPerRow[i] += ptSymRows[ii + 1] - ptSymRows[ii];
1412 int ibegin = ptSymRows[ii] + (upper_flag ? 1 : 0);
1413 int iend = ptSymRows[ii + 1] + (upper_flag ? 0 : (-1));
1414 for (int kk = ibegin; kk < iend; kk++) {
1415 nbIndPerRow[map_eqn[indSymCols[kk]]]++; // 3 Jan.2014
1416 }
1417 }
1418 // Build unsym->ptRows array :
1419 // ...................
1420 unsym->ptRows[0] = 0;
1421 for (int i = 0; i < dim; i++) {
1422 unsym->ptRows[i + 1] = unsym->ptRows[i] + nbIndPerRow[i];
1423 }
1424 // CHECK(unsym->ptRows[dim] == (2 * nz - dim),
1425 // "error in sym2unsym() : Wrong number of non zeros elemnts in ptRows !");
1426 // Allocate and fill indices columns :
1427 // memset(nbIndPerRow, 0, (dim * sizeof(int)));
1428 for (int i = 0; i < dim; i++) {
1429 nbIndPerRow[i] = 0;
1430 }
1431
1432 // for upper case, nbIndPerRow[i] keeps entries added by transposed operation
1433 // but for lower case counts all nonzero entries in progress
1434 for (int i = 0; i < dim; i++) {
1435 int itmp = unsym->ptRows[i] + nbIndPerRow[i];
1436 const int ii = remap_eqn[i];
1437 for (int kk = ptSymRows[ii]; kk < ptSymRows[ii + 1]; kk++) {
1438 unsym->indCols[itmp] = map_eqn[indSymCols[kk]];
1439 unsym->indVals[itmp] = kk; //map_indcols[kk];
1440 itmp++;
1441 } // loop : kk
1442 if (!upper_flag) {
1443 nbIndPerRow[i] = itmp - unsym->ptRows[i];
1444 }
1445 // memcpy(indCols + (ptRows[i] + nbIndPerRow[i]),
1446 // indSymCols + ptSymRows[i],
1447 // (ptSymRows[i + 1] - ptSymRows[i]) * sizeof(int));
1448 int ibegin = ptSymRows[ii] + (upper_flag ? 1 : 0);
1449 int iend = ptSymRows[ii + 1] + (upper_flag ? 0 : (-1));
1450 for (int kk = ibegin; kk < iend; kk++) {
1451 const int j = map_eqn[indSymCols[kk]];
1452 const int jtmp = unsym->ptRows[j] + nbIndPerRow[j];
1453 unsym->indCols[jtmp] = i;
1454 unsym->indVals[jtmp] = kk; //map_indcols[kk];
1455 nbIndPerRow[j]++;
1456 } // loop : kk
1457 } // loop : i
1458 delete [] nbIndPerRow;
1459 return unsym->ptRows[dim];
1460 }
1461
1462 bool CSR_unsym2unsym(CSR_indirect *unsym,
1463 const int *ptUnSymRows, const int *indUnSymCols,
1464 const int *map_eqn, const int *remap_eqn,
1465 //const int *map_indcols,
1466 const int dim, const bool verbose, FILE *fp)
1467 {
1468 int* nbIndPerRow = new int[dim];
1469 for (int i = 0; i < dim; i++) {
1470 const int ii = remap_eqn[i];
1471 nbIndPerRow[i] = ptUnSymRows[ii + 1] - ptUnSymRows[ii];
1472 }
1473 unsym->ptRows[0] = 0;
1474 for (int i = 0; i < dim; i++) {
1475 unsym->ptRows[i + 1] = unsym->ptRows[i] + nbIndPerRow[i];
1476 }
1477
1478 for (int i = 0; i < dim; i++) { // running over new index
1479 const int ii = remap_eqn[i]; // access to the original data of node
1480 int itmp = unsym->ptRows[i];
1481 for (int kk = ptUnSymRows[ii]; kk < ptUnSymRows[ii + 1]; kk++, itmp++) {
1482 const int jj = indUnSymCols[kk];
1483 const int j = map_eqn[jj];
1484 unsym->indCols[itmp] = j; // access to the new data
1485 unsym->indVals[itmp] = kk; // access to the orignal data of unsym->indCols
1486 bool found = false;
1487 for (int mm = ptUnSymRows[jj]; mm < ptUnSymRows[jj + 1]; mm++) {
1488 if (indUnSymCols[mm] == ii) { // based on the original CSR data
1489 unsym->indVals_unsym[itmp] = mm; // map_indcols[mm];
1490 found = true;
1491 break;
1492 }
1493 }
1494 if (!found) {
1495 diss_printf(verbose, fp,
1496 "%s %d : symmetric place of (%d, %d) -> (%d %d) not found\n",
1497 __FILE__, __LINE__, ii, jj, i, j);
1498 return false;
1499 }
1500 }
1501 }
1502 delete [] nbIndPerRow;
1503 return true;
1504 }
1505
1506
1507
1508 void swap_queues_n(vector <C_task *> &queue,
1509 vector <int> &queue_index,
1510 const int ii,
1511 const int jj,
1512 const int n,
1513 vector <C_task *> &tmp,
1514 vector <int> &tmp_index)
1515 {
1516 for (int l = 0; l < n; l++) {
1517 tmp[l] = queue[ii * n + l];
1518 tmp_index[l] = queue_index[ii * n + l];
1519 }
1520 for (int l = 0; l < n; l++) {
1521 queue[ii * n + l] = queue[(ii + 1) * n + l];
1522 queue_index[ii * n + l] = queue_index[(ii + 1) * n + l];
1523 }
1524 for (int l = 0; l < n; l++) {
1525 queue[jj * n + l] = tmp[l];
1526 queue_index[jj * n + l] = tmp_index[l];
1527 }
1528 }
1529
1530 bool compare_task_name(C_task *first, C_task *second) {
1531 // 'g', 'h', 'i', 'j' should be in higher order
1532 if (first->task_name[0] >= 'h') {
1533 if (second->task_name[0] >= 'h') {
1534 return (strcmp(first->task_name, second->task_name) >=0 ? false : true);
1535 }
1536 else {
1537 return true;
1538 }
1539 }
1540 if (second->task_name[0] >= 'h') {
1541 return false;
1542 }
1543 return (strcmp(first->task_name, second->task_name) >=0 ? false : true);
1544 }
1545
1546 // =====================================================================
1547 template<typename T>
1548 int count_diag_negative_real(SquareBlockMatrix<T>& Diag)
1549 {
1550 int count = 0;
1551 const int dim_diag = Diag.dimension();
1552 for (int i = 0; i < dim_diag; i++) {
1553 const T xtmp = Diag.diag(i);
1554 if (xtmp < T(0.0)) {
1555 count++;
1556 }
1557 }
1558 return count;
1559 }
1560
1561 template<typename T>
1562 int count_diag_negative_complex(SquareBlockMatrix<complex<T> >& Diag)
1563 {
1564 int count = 0;
1565 const int dim_diag = Diag.dimension();
1566 for (int i = 0; i < dim_diag; i++) {
1567 const complex<T> xtmp = Diag.diag(i);
1568 if ((xtmp.real() < T(0.0)) && xtmp.imag() == T(0.0)) {
1569 count++;
1570 }
1571 }
1572 return count;
1573 }
1574
1575 template<typename T>
1576 int count_diag_negative(SquareBlockMatrix<T>& Diag)
1577 {
1578 fprintf(stderr, "%s %d : specialized template is not yet defined.\n",
1579 __FILE__, __LINE__);
1580 return (-1);
1581 }
1582
1583 template<>
1584 int count_diag_negative<double>(SquareBlockMatrix<double>& Diag)
1585 {
1586 return count_diag_negative_real<double>(Diag);
1587 }
1588
1589 template<>
1590 int count_diag_negative<quadruple>(SquareBlockMatrix<quadruple>& Diag)
1591 {
1592 return count_diag_negative_real<quadruple>(Diag);
1593 }
1594
1595 template<>
1596 int count_diag_negative<complex<double> >(SquareBlockMatrix<complex<double> >& Diag)
1597 {
1598 return count_diag_negative_complex<double>(Diag);
1599 }
1600
1601 template<>
1602 int count_diag_negative<complex<quadruple> >(SquareBlockMatrix<complex<quadruple> >& Diag)
1603 {
1604 return count_diag_negative_complex<quadruple>(Diag);
1605 }
1606
1607 template<>
1608 int count_diag_negative<float>(SquareBlockMatrix<float>& Diag)
1609 {
1610 return count_diag_negative_real<float>(Diag);
1611 }
1612
1613
1614 template<>
1615 int count_diag_negative<complex<float> >(SquareBlockMatrix<complex<float> >& Diag)
1616 {
1617 return count_diag_negative_complex<float>(Diag);
1618 }
1619 //
1620 template<typename T>
1621 int count_diag_negative(SubSquareMatrix<T>& Diag)
1622 {
1623 fprintf(stderr, "%s %d : specialized template is not yet defined.\n",
1624 __FILE__, __LINE__);
1625 return (-1);
1626 }
1627
1628 template<>
1629 int count_diag_negative<double>(SubSquareMatrix<double>& Diag)
1630 {
1631 int count = 0;
1632 const int dim_diag = Diag.dimension();
1633 for (int i = 0; i < dim_diag; i++) {
1634 const double xtmp = Diag(i, i);
1635 if (xtmp < 0.0) {
1636 count++;
1637 }
1638 }
1639 return count;
1640 }
1641
1642 template<>
1643 int count_diag_negative<quadruple>(SubSquareMatrix<quadruple>& Diag)
1644 {
1645 int count = 0;
1646 const int dim_diag = Diag.dimension();
1647 for (int i = 0; i < dim_diag; i++) {
1648 const double xtmp = quad2double(Diag(i, i));
1649 if (xtmp < 0.0) {
1650 count++;
1651 }
1652 }
1653 return count;
1654 }
1655
1656 template<>
1657 int count_diag_negative<complex<quadruple> >(SubSquareMatrix<complex<quadruple> >& Diag)
1658 {
1659 int count = 0;
1660 const int dim_diag = Diag.dimension();
1661 for (int i = 0; i < dim_diag; i++) {
1662 const complex<quadruple> &xtmp = Diag(i, i);
1663 if (quad2double(xtmp.imag()) < 0.0 && quad2double(xtmp.real()) == 0.0) {
1664 count++;
1665 }
1666 }
1667 return count;
1668 }
1669
1670 template<>
1671 int count_diag_negative<complex<double> >(SubSquareMatrix<complex<double> >& Diag)
1672 {
1673 int count = 0;
1674 const int dim_diag = Diag.dimension();
1675 for (int i = 0; i < dim_diag; i++) {
1676 const complex<double> xtmp = Diag(i, i);
1677 if (xtmp.imag() < 0.0 && xtmp.real() == 0.0) {
1678 count++;
1679 }
1680 }
1681 return count;
1682 }
1683
1684 template<>
1685 int count_diag_negative<float>(SubSquareMatrix<float>& Diag)
1686 {
1687 int count = 0;
1688 const int dim_diag = Diag.dimension();
1689 for (int i = 0; i < dim_diag; i++) {
1690 const float xtmp = Diag(i, i);
1691 if (xtmp < 0.0) {
1692 count++;
1693 }
1694 }
1695 return count;
1696 }
1697
1698 template<>
1699 int count_diag_negative<complex<float> >(SubSquareMatrix<complex<float> >& Diag)
1700 {
1701 int count = 0;
1702 const int dim_diag = Diag.dimension();
1703 for (int i = 0; i < dim_diag; i++) {
1704 const complex<float> xtmp = Diag(i, i);
1705 if (xtmp.imag() < 0.0 && xtmp.real() == 0.0) {
1706 count++;
1707 }
1708 }
1709 return count;
1710 }
1711
1712 //
1713 template<typename T, typename U>
1714 void C_SparseNumFact(void *arg_)
1715 {
1716 C_SparseNumFact_arg<T, U> *arg = (C_SparseNumFact_arg<T, U> *)arg_;
1717 TridiagBlockMatrix<T, U> **tridiag = arg->tridiag;
1718 int colors = arg->colors;
1719 int nrow = arg->nrow;
1720 double eps_pivot = *(arg->eps_pivot);
1721 const bool kernel_detection = *(arg->kernel_detection);
1722 const bool higher_precision = *(arg->higher_precision);
1723 const int dim_aug_kern = *(arg->dim_aug_kern);
1724 const U eps_machine = *(arg->eps_machine);
1725 T *coefs = arg->coefs;
1726
1727 double *pivot = arg->pivot; // all diagonal entries of sparse matrices
1728 // equal to 1, set at the initialization
1729
1730 SquareBlockMatrix<T>& D = *(arg->D);
1731 vector<int> &list_sing = D.getSingIdx();
1732 double nopd;
1733 const bool verbose = arg->verbose;
1734 FILE *fp = *(arg->fp);
1735 elapsed_t t0, t1;
1736 get_realtime(&t0);
1737 int nsing = 0;
1738 bool detected = true;
1739 nopd = 0.0;
1740 *pivot = 1.0; // matrix is scaled so that the diagonal entries take 1
1741 for (int i = 0; i < colors; i++) {
1742 double pivot1;
1743 double nopd1;
1744 tridiag[i]->NumericFact(coefs, eps_pivot,
1745 &pivot1,
1746 kernel_detection,
1747 higher_precision,
1748 dim_aug_kern,
1749 eps_machine,
1750 &nopd1);
1751 nopd += nopd1;
1752 // tridiag[i0->SingularNode(list_sing);
1753 if (!tridiag[i]->detected()) {
1754 detected = false; // tridiag[i]->nsing() == (-1);
1755 }
1756 nsing += tridiag[i]->nsing();
1757 *pivot = *pivot < pivot1 ? *pivot : pivot1;
1758 }
1759 list_sing.resize(nsing);
1760 {
1761 int j = 0;
1762 for (int i = 0; i < colors; i++) {
1763 vector<int> list_sing_tmp;
1764 tridiag[i]->SingularNode(list_sing_tmp);
1765 for (vector<int>::const_iterator it = list_sing_tmp.begin();
1766 it != list_sing_tmp.end(); ++it, j++) {
1767 list_sing[j] = (*it);
1768 }
1769 }
1770 }
1771
1772 get_realtime(&t1);
1773 diss_printf(verbose, fp, "%s %d : %d : pivot = %g n0 = %d detected = %s\n",
1774 __FILE__, __LINE__,
1775 arg->nb, *pivot, nsing, detected ? "true" : "false");
1776
1777 D.set_lastPivot(*pivot);
1778 D.set_KernelDetected(detected);
1779 D.set_rank(nrow - nsing);
1780
1781 //*(arg->pivot) = pivot;
1782 *(arg->nopd) = (long)nopd; // ?? uninitialized ??
1783 }
1784
1785 template
1786 void C_SparseNumFact<double, double>(void *arg_);
1787
1788 template
1789 void C_SparseNumFact<quadruple, quadruple>(void *arg_);
1790
1791 template
1792 void C_SparseNumFact<complex<double>, double>(void *arg_);
1793
1794 template
1795 void C_SparseNumFact<complex<quadruple>, quadruple>(void *arg_);
1796
1797 template
1798 void C_SparseNumFact<float, float>(void *arg_);
1799
1800 template
1801 void C_SparseNumFact<complex<float>, float>(void *arg_);
1802 //
1803
1804
1805 template<typename T, typename U>
1806 void C_SparseLocalSchur(void *arg_)
1807 {
1808 C_SparseNumFact_arg<T, U> *arg = (C_SparseNumFact_arg<T, U> *)arg_;
1809
1810 TridiagBlockMatrix<T, U> **tridiag = arg->tridiag;
1811 int colors = arg->colors;
1812 int *color_mask = arg->color_mask;
1813 int nrow = arg->nrow;
1814 int ncol = arg->ncol;
1815 T *coefs = arg->coefs;
1816 int *prow1 = arg->csr_offdiag->ptRows;
1817 int *indcols1 = arg->csr_offdiag->indCols;
1818 int *indvals1 = arg->csr_offdiag->indVals;
1819 int *indvals2 = arg->isSym ? (int *)NULL : arg->csr_offdiag->indVals_unsym;
1820
1821 elapsed_t *tt = arg->tt;
1822 double *nops = new double[3];
1823 //
1824 SquareBlockMatrix<T> &localSchur = *(arg->localSchur);
1825 localSchur.allocate();
1826 double nopsum = 0.0;
1827 for (int i = 0; i < colors; i++) {
1828 tridiag[i]->ComputeSchur(nrow, color_mask,
1829 ncol, prow1, indcols1, indvals1, indvals2,
1830 coefs, SIZE_B1, localSchur, nops, tt);
1831 // get the excat flop by direct counting
1832 nopsum += nops[0] + nops[2];
1833 }
1834 *(arg->nops) = (long)nopsum;
1835 delete [] nops;
1836 }
1837
1838 template
1839 void C_SparseLocalSchur<double, double>(void *arg_);
1840
1841 template
1842 void C_SparseLocalSchur<quadruple, quadruple>(void *arg_);
1843
1844 template
1845 void C_SparseLocalSchur<complex<double>, double>(void *arg_);
1846
1847 template
1848 void C_SparseLocalSchur<complex<quadruple>, quadruple>(void *arg_);
1849
1850 template
1851 void C_SparseLocalSchur<float, float>(void *arg_);
1852
1853 template
1854 void C_SparseLocalSchur<complex<float>, float>(void *arg_);
1855 //
1856
1857
1858 template<>
1859 void dump_matrix<double>(FILE *fp, const int nrow, double *a)
1860 {
1861 for (int i = 0; i < nrow; i++) {
1862 fprintf(fp, "%d : ", i);
1863 for (int j = i; j < nrow; j++) {
1864 fprintf(fp, "%g ", a[i + nrow * j]);
1865 }
1866 fprintf(fp, "\n");
1867 }
1868 }
1869
1870 template<typename T>
1871 void dump_matrix(FILE *fp, const int nrow, T *a)
1872 {
1873 fprintf(stderr, "%s %d : general case is not defined\n", __FILE__, __LINE__);
1874 }
1875
1876 template
1877 void dump_matrix<quadruple>(FILE *fp, const int nrow,
1878 quadruple *a);
1879
1880 template
1881 void dump_matrix<complex<double> >(FILE *fp, const int nrow,
1882 complex<double> *a);
1883
1884 template
1885 void dump_matrix<complex<quadruple> >(FILE *fp, const int nrow,
1886 complex<quadruple> *a);
1887
1888 template
1889 void dump_matrix<complex<float> >(FILE *fp, const int nrow,
1890 complex<float> *a);
1891
1892 template<>
1893 void dump_matrix<double>(FILE *fp, const int nrow, const int ncol, double *a)
1894 {
1895 for (int i = 0; i < nrow; i++) {
1896 fprintf(fp, "%d : ", i);
1897 for (int j = 0; j < ncol; j++) {
1898 fprintf(fp, "%g ", a[i + nrow * j]);
1899 }
1900 fprintf(fp, "\n");
1901 }
1902 }
1903
1904 template<>
1905 void dump_matrix<float>(FILE *fp, const int nrow, const int ncol, float *a)
1906 {
1907 for (int i = 0; i < nrow; i++) {
1908 fprintf(fp, "%d : ", i);
1909 for (int j = 0; j < ncol; j++) {
1910 fprintf(fp, "%g ", a[i + nrow * j]);
1911 }
1912 fprintf(fp, "\n");
1913 }
1914 }
1915
1916 template<typename T>
1917 void dump_matrix(FILE *fp, const int nrow, const int ncol, T *a)
1918 {
1919 fprintf(stderr, "%s %d : general case is not defined\n", __FILE__, __LINE__);
1920 }
1921
1922 template
1923 void dump_matrix<quadruple>(FILE *fp, const int nrow, const int ncol,
1924 quadruple *a);
1925
1926 template
1927 void dump_matrix<complex<double> >(FILE *fp, const int nrow, const int ncol,
1928 complex<double> *a);
1929 template
1930 void dump_matrix<complex<quadruple> >(FILE *fp, const int nrow, const int ncol,
1931 complex<quadruple> *a);
1932
1933 template
1934 void dump_matrix<complex<float> >(FILE *fp, const int nrow, const int ncol,
1935 complex<float> *a);
1936
1937 template<>
1938 void dump_matrix<double>(FILE *fp, const int kk,
1939 const int nrow, const int ncol, const int nn,
1940 double *a)
1941 {
1942 for (int i = 0; i < nrow; i++) {
1943 fprintf(fp, "%d : ", i);
1944 for (int j = 0; j < ncol; j++) {
1945 fprintf(fp, "%g ", a[kk + i + nn * j]);
1946 }
1947 fprintf(fp, "\n");
1948 }
1949 }
1950
1951 template<>
1952 void dump_matrix<float>(FILE *fp, const int kk,
1953 const int nrow, const int ncol, const int nn,
1954 float *a)
1955 {
1956 for (int i = 0; i < nrow; i++) {
1957 fprintf(fp, "%d : ", i);
1958 for (int j = 0; j < ncol; j++) {
1959 fprintf(fp, "%g ", a[kk + i + nn * j]);
1960 }
1961 fprintf(fp, "\n");
1962 }
1963 }
1964
1965 template<typename T>
1966 void dump_matrix(FILE *fp, const int kk,
1967 const int nrow, const int ncol, const int nn, T *a)
1968 {
1969 fprintf(stderr, "%s %d : general case is not defined\n", __FILE__, __LINE__);
1970 }
1971
1972 template
1973 void dump_matrix<quadruple>(FILE *fp, const int kk,
1974 const int nrow, const int ncol, const int nn,
1975 quadruple *a);
1976 template
1977 void dump_matrix<complex<double> >(FILE *fp, const int kk,
1978 const int nrow, const int ncol, const int nn,
1979 complex<double> *a);
1980
1981 template
1982 void dump_matrix<complex<quadruple> >(FILE *fp, const int kk,
1983 const int nrow, const int ncol,
1984 const int nn,
1985 complex<quadruple> *a);
1986 template
1987 void dump_matrix<complex<float> >(FILE *fp, const int kk,
1988 const int nrow, const int ncol, const int nn,
1989 complex<float> *a);
1990
1991 template<>
1992 void dump_matrix<double>(FILE *fp,
1993 RectBlockMatrix<double> &a)
1994 {
1995 for (int i = 0; i < a.dimension_r(); i++) {
1996 fprintf(fp, "%d : ", i);
1997 for (int j = 0; j < a.dimension_c(); j++) {
1998 fprintf(fp, "%g ", a(i, j));
1999 }
2000 fprintf(fp, "\n");
2001 }
2002 }
2003
2004 template<>
2005 void dump_matrix<float>(FILE *fp,
2006 RectBlockMatrix<float> &a)
2007 {
2008 for (int i = 0; i < a.dimension_r(); i++) {
2009 fprintf(fp, "%d : ", i);
2010 for (int j = 0; j < a.dimension_c(); j++) {
2011 fprintf(fp, "%g ", a(i, j));
2012 }
2013 fprintf(fp, "\n");
2014 }
2015 }
2016
2017 template<typename T>
2018 void dump_matrix(FILE *fp,
2019 RectBlockMatrix<T> &a)
2020 {
2021 fprintf(stderr, "%s %d : general case is not defined\n", __FILE__, __LINE__);
2022 }
2023
2024 template<>
2025 void dump_matrix<double>(FILE *fp,
2026 SquareBlockMatrix<double> &a)
2027 {
2028 // if (a.isSym()) {
2029 if (1) { // 16 Jan.debug
2030 for (int i = 0; i < a.dimension(); i++) {
2031 fprintf(fp, "%d : ", i);
2032 for (int j = i; j < a.dimension() ; j++) {
2033 fprintf(fp, "%16.8e ", a(i, j));
2034 }
2035 fprintf(fp, "\n");
2036 }
2037 }
2038 else {
2039 for (int i = 0; i < a.dimension(); i++) {
2040 fprintf(fp, "%d : ", i);
2041 for (int j = 0; j < a.dimension(); j++) {
2042 fprintf(fp, "%16.8e ", a(i, j));
2043 }
2044 fprintf(fp, "\n");
2045 }
2046 }
2047 }
2048 template
2049 void dump_matrix<quadruple>(FILE *fp, RectBlockMatrix<quadruple> &a);
2050
2051 template
2052 void dump_matrix<complex<double> >(FILE *fp,
2053 RectBlockMatrix<complex<double> > &a);
2054
2055 template
2056 void dump_matrix<complex<quadruple> >(FILE *fp,
2057 RectBlockMatrix<complex<quadruple> > &a);
2058
2059 template
2060 void dump_matrix<complex<float> >(FILE *fp,
2061 RectBlockMatrix<complex<float> > &a);
2062 //
2063
2064 template<typename T>
2065 void dump_matrix(FILE *fp,
2066 SquareBlockMatrix<T> &a)
2067 {
2068 fprintf(stderr, "%s %d : general case is not defined\n", __FILE__, __LINE__);
2069 }
2070
2071 template
2072 void dump_matrix<quadruple>(FILE *fp, SquareBlockMatrix<quadruple> &a);
2073
2074 template
2075 void dump_matrix<complex<double> >(FILE *fp,
2076 SquareBlockMatrix<complex<double> > &a);
2077
2078 template
2079 void
2080 dump_matrix<complex<quadruple> >(FILE *fp,
2081 SquareBlockMatrix<complex<quadruple> > &a);
2082
2083 template
2084 void dump_matrix<complex<float> >(FILE *fp,
2085 SquareBlockMatrix<complex<float> > &a);
2086
2087 //
2088 template<>
2089 void dump_matrix<double>(FILE *fp, const int nrow, const int nnz, int *prow,
2090 int *indcols, int *indvals, double *a)
2091 {
2092 // verify_nan<double>(fp, nnz, a);
2093
2094 for (int i = 0; i < nrow; i++) {
2095 if (prow[i + 1] > prow[i]) {
2096 fprintf(fp, "%d : ", i);
2097 for (int j = prow[i]; j < prow[i + 1]; j++) {
2098 fprintf(fp, "%d:%d:%g ", indcols[j], indvals[j], a[indvals[j]]);
2099 }
2100 fprintf(fp, "\n");
2101 }
2102 }
2103 }
2104
2105 template<typename T>
2106 void dump_matrix(FILE *fp, const int nrow, const int nnz, int *prow,
2107 int *indcols, int *indvals, T *a)
2108 {
2109 fprintf(stderr, "%s %d : general case is not defined\n", __FILE__, __LINE__);
2110 }
2111
2112 template
2113 void dump_matrix<complex<double> >(FILE *fp, const int nrow, const int nnz,
2114 int *prow,
2115 int *indcols, int *indvals,
2116 complex<double> *a);
2117 //
2118
2119 template<typename T>
2120 void C_FillMatrix_diag(void *arg_)
2121 {
2122 C_FillMatrix_arg<T> *arg = (C_FillMatrix_arg<T> *)arg_;
2123
2124 SquareBlockMatrix<T>& D = *arg->D;
2125 CSR_indirect csr_diag = *arg->csr_diag;
2126 T *coefs = arg->coefs;
2127
2128 D.ZeroClear();
2129 for (int i = 0; i < csr_diag.n; i++) {
2130 for (int k = csr_diag.ptRows[i]; k < csr_diag.ptRows[i + 1]; k++) {
2131 const int j = csr_diag.indCols[k];
2132 D(i, j) = coefs[csr_diag.indVals[k]];
2133 }
2134 }
2135 //
2136 }
2137
2138 template
2139 void C_FillMatrix_diag<double>(void *arg_);
2140
2141 template
2142 void C_FillMatrix_diag<quadruple>(void *arg_);
2143
2144 template
2145 void C_FillMatrix_diag<complex<double> >(void *arg_);
2146
2147 template
2148 void C_FillMatrix_diag<complex<quadruple> >(void *arg_);
2149
2150 template
2151 void C_FillMatrix_diag<float>(void *arg_);
2152
2153 template
2154 void C_FillMatrix_diag<complex<float> >(void *arg_);
2155
2156 //
2157
2158 template<typename T>
2159 void C_FillMatrix_offdiag(void *arg_)
2160 {
2161 C_FillMatrix_arg<T> *arg = (C_FillMatrix_arg<T> *)arg_;
2162
2163 RectBlockMatrix<T>& upper = *arg->upper;
2164 CSR_indirect csr_offdiag = *arg->csr_offdiag;
2165 T *coefs = arg->coefs;
2166
2167 upper.ZeroClear();
2168 for (int i = 0; i < csr_offdiag.n; i++) {
2169 for (int k = csr_offdiag.ptRows[i]; k < csr_offdiag.ptRows[i + 1]; k++) {
2170 const int j = csr_offdiag.indCols[k];
2171 // access to (i, j) = i + j * n is not efficient
2172 upper(i, j) = coefs[csr_offdiag.indVals[k]];
2173 }
2174 }
2175 if (!arg->isSym) {
2176 RectBlockMatrix<T>& lower = *arg->lower;
2177 lower.ZeroClear();
2178 for (int i = 0; i < csr_offdiag.n; i++) {
2179 for (int k = csr_offdiag.ptRows[i]; k < csr_offdiag.ptRows[i + 1]; k++) {
2180 const int j = csr_offdiag.indCols[k];
2181 // access to (i, j) = i + j * n is not efficient
2182 lower(i, j) = coefs[csr_offdiag.indVals_unsym[k]];
2183 }
2184 }
2185 }
2186 }
2187
2188 template
2189 void C_FillMatrix_offdiag<double>(void *arg_);
2190
2191 template
2192 void C_FillMatrix_offdiag<quadruple>(void *arg_);
2193
2194 template
2195 void C_FillMatrix_offdiag<complex<double> >(void *arg_);
2196
2197 template
2198 void C_FillMatrix_offdiag<complex<quadruple> >(void *arg_);
2199
2200 template
2201 void C_FillMatrix_offdiag<float>(void *arg_);
2202
2203 template
2204 void C_FillMatrix_offdiag<complex<float> >(void *arg_);
2205 //
2206
2207 template<typename T>
2208 void DSchurGEMM_diag(void *arg_)
2209 {
2210 const T zero(0.0);
2211 const T one(1.0);
2212 DSchurGEMM_arg<T> *arg = (DSchurGEMM_arg<T> *)arg_;
2213 SquareBlockMatrix<T> *localSchur = arg->localSchur;
2214 localSchur->allocateBlock(arg->i_block, arg->i_block);
2215 T *s = localSchur->addrCoefBlock(arg->i_block, arg->i_block);
2216 const int nrow = localSchur->nrowBlock(arg->i_block, arg->i_block);
2217
2218 // alpha = 1;
2219 // to replace by symmetric dgemm which compute only upper part of the matrix
2220 if (arg->isSym) {
2221 for (int k = 0; k < arg->lower->num_blocks_r(); k++) {
2222 const T beta = ((k == 0) ? zero : one);
2223 const T *ptLt = arg->lower->addrCoefBlock(k, arg->i_block);
2224 const T *ptU = arg->upper->addrCoefBlock(k, arg->i_block);
2225 int nnrow = arg->lower->nrowBlock(k);
2226 C_gemm_symm(nrow, // arg->block_nrow,
2227 nnrow, // arg->nrow,
2228 one, // alpha
2229 ptLt,
2230 nnrow, // arg->nrow,
2231 ptU, // ptL, // arg->ptL,
2232 nnrow, // arg->nrow,
2233 beta,
2234 s, // arg->s + (arg->i_row + arg->i_row * arg->ncol),
2235 nrow);
2236 } // loop : k
2237 }
2238 else {
2239 for (int k = 0; k < arg->lower->num_blocks_r(); k++) {
2240 const T beta = ((k == 0) ? zero : one);
2241 const T *ptLt = arg->lower->addrCoefBlock(k, arg->i_block);
2242 const T *ptU = arg->upper->addrCoefBlock(k, arg->i_block);
2243 int nnrow = arg->lower->nrowBlock(k);
2244 blas_gemm<T>(CblasTrans, CblasNoTrans,
2245 // arg->block_nrow, arg->block_nrow,
2246 nrow, nrow,
2247 nnrow, // arg->nrow,
2248 one, // alpha
2249 ptLt, // ptUt, // arg->ptUt,
2250 nnrow, // arg->nrow,
2251 ptU, // ptL, // arg->ptL,
2252 nnrow, // arg->nrow,
2253 beta,
2254 s, // arg->s + (arg->i_row + arg->i_row * arg->ncol),
2255 nrow);
2256 } // loop : k
2257 }
2258 }
2259
2260 template
2261 void DSchurGEMM_diag<double>(void *arg_);
2262
2263 template
2264 void DSchurGEMM_diag<quadruple>(void *arg_);
2265
2266 template
2267 void DSchurGEMM_diag<complex<double> >(void *arg_);
2268
2269 template
2270 void DSchurGEMM_diag<complex<quadruple> >(void *arg_);
2271
2272 template
2273 void DSchurGEMM_diag<float>(void *arg_);
2274
2275 template
2276 void DSchurGEMM_diag<complex<float> >(void *arg_);
2277 //
2278
2279 template<typename T>
2280 void DSchurGEMM_diag_two(void *arg_)
2281 {
2282 DSchurGEMM_two_arg<T> *arg = (DSchurGEMM_two_arg<T> *)arg_;
2283 if (arg->isSkip) {
2284 return;
2285 }
2286
2287 SquareBlockMatrix<T> *fatherDiag = arg->localSchur;
2288 T *s = fatherDiag->addrCoefBlock(arg->i_block, arg->i_block);
2289 const int nrow = fatherDiag->nrowBlock(arg->i_block, arg->i_block);
2290 const T none(-1.0);
2291 const T one(1.0);
2292 // to replace by symmetric dgemm which compute only upper part of the matrix
2293 if (arg->isSym) {
2294 for (int k = 0; k < arg->lower0->num_blocks_r(); k++) {
2295 const T *ptLt0 = arg->lower0->addrCoefBlock(k, arg->i_block);
2296 const T *ptU0 = arg->upper0->addrCoefBlock(k, arg->i_block);
2297 int nnrow = arg->lower0->nrowBlock(k);
2298 C_gemm_symm(nrow, // arg->block_nrow,
2299 nnrow, // arg->nrow0,
2300 none, // alpha
2301 ptLt0, nnrow, // arg->nrow0,
2302 ptU0, nnrow, // arg->nrow0,
2303 one, // beta
2304 s, nrow);
2305 }
2306 for (int k = 0; k < arg->lower1->num_blocks_r(); k++) {
2307 const T *ptLt1 = arg->lower1->addrCoefBlock(k, arg->i_block);
2308 const T *ptU1 = arg->upper1->addrCoefBlock(k, arg->i_block);
2309 int nnrow = arg->lower1->nrowBlock(k);
2310 C_gemm_symm(nrow, // arg->block_nrow,
2311 nnrow, // arg->nrow1,
2312 none, // alpha
2313 ptLt1, nnrow, //arg->nrow1,
2314 ptU1, nnrow, // arg->nrow1,
2315 one, // beta
2316 s, nrow);
2317 }
2318 }
2319 else {
2320 for (int k = 0; k < arg->lower0->num_blocks_r(); k++) {
2321 const T *ptLt0 = arg->lower0->addrCoefBlock(k, arg->i_block);
2322 const T *ptU0 = arg->upper0->addrCoefBlock(k, arg->i_block);
2323 int nnrow = arg->lower0->nrowBlock(k);
2324 blas_gemm<T>(CblasTrans, CblasNoTrans,
2325 // arg->block_nrow, arg->block_nrow,
2326 nrow, nrow,
2327 nnrow, // arg->nrow0,
2328 none, // alpha
2329 ptLt0, nnrow, // arg->nrow0,
2330 ptU0, nnrow, // arg->nrow0,
2331 one, // beta,
2332 s, nrow);
2333 }
2334 for (int k = 0; k < arg->lower1->num_blocks_r(); k++) {
2335 const T *ptLt1 = arg->lower1->addrCoefBlock(k, arg->i_block);
2336 const T *ptU1 = arg->upper1->addrCoefBlock(k, arg->i_block);
2337 int nnrow = arg->lower1->nrowBlock(k);
2338 blas_gemm<T>(CblasTrans, CblasNoTrans,
2339 //arg->block_nrow, arg->block_nrow,
2340 nrow, nrow,
2341 nnrow, // arg->nrow1,
2342 none, // alpha
2343 ptLt1, nnrow, // arg->nrow1,
2344 ptU1, nnrow, //arg->nrow1,
2345 one, // beta,
2346 s, nrow);
2347 }
2348 }
2349 }
2350
2351 template
2352 void DSchurGEMM_diag_two<double>(void *arg_);
2353
2354 template
2355 void DSchurGEMM_diag_two<quadruple>(void *arg_);
2356
2357 template
2358 void DSchurGEMM_diag_two<complex<double> >(void *arg_);
2359
2360 template
2361 void DSchurGEMM_diag_two<complex<quadruple> >(void *arg_);
2362
2363 template
2364 void DSchurGEMM_diag_two<float>(void *arg_);
2365
2366 template
2367 void DSchurGEMM_diag_two<complex<float> >(void *arg_);
2368
2369 //
2370
2371 template<typename T>
2372 void DSchurGEMM_offdiag(void *arg_)
2373 {
2374 const T zero(0.0);
2375 const T one(1.0);
2376 DSchurGEMM_arg<T> *arg = (DSchurGEMM_arg<T> *)arg_;
2377 SquareBlockMatrix<T> *localSchur = arg->localSchur;
2378 localSchur->allocateBlock(arg->i_block, arg->j_block);
2379 T *s = localSchur->addrCoefBlock(arg->i_block, arg->j_block);
2380 const int nrow = localSchur->nrowBlock(arg->i_block, arg->j_block);
2381 const int ncol = localSchur->ncolBlock(arg->i_block, arg->j_block);
2382 // alpha = 1
2383 // block_nrow * block_ncol : S(i,j) = L(i)^T U(j)
2384 if (arg->isTrans) {
2385 for (int k = 0; k < arg->lower->num_blocks_r(); k++) {
2386 const T beta = ((k == 0) ? zero : one);
2387 const T *ptLt = arg->lower->addrCoefBlock(k, arg->j_block);
2388 const T *ptU = arg->upper->addrCoefBlock(k, arg->i_block);
2389 int nnrow = arg->lower->nrowBlock(k);
2390 blas_gemm<T>(CblasTrans, CblasNoTrans,
2391 nrow, ncol,
2392 nnrow, //arg->nrow,
2393 one, // alpha,
2394 ptLt,
2395 nnrow, // arg->nrow,
2396 ptU,
2397 nnrow, // arg->nrow,
2398 beta,
2399 s,
2400 nrow);
2401 }
2402 }
2403 else {
2404 for (int k = 0; k < arg->lower->num_blocks_r(); k++) {
2405 const T beta = ((k == 0) ? zero : one);
2406 const T *ptLt = arg->lower->addrCoefBlock(k, arg->i_block);
2407 const T *ptU = arg->upper->addrCoefBlock(k, arg->j_block);
2408 int nnrow = arg->lower->nrowBlock(k);
2409 blas_gemm<T>(CblasTrans, CblasNoTrans,
2410 nrow, ncol,
2411 nnrow, // arg->nrow,
2412 one, // alpha
2413 ptLt,
2414 nnrow, // arg->nrow,
2415 ptU,
2416 nnrow, // arg->nrow,
2417 beta,
2418 s,
2419 nrow);
2420 }
2421 }
2422 }
2423
2424 template
2425 void DSchurGEMM_offdiag<double>(void *arg_);
2426
2427 template
2428 void DSchurGEMM_offdiag<quadruple>(void *arg_);
2429
2430 template
2431 void DSchurGEMM_offdiag<complex<double> >(void *arg_);
2432
2433 template
2434 void DSchurGEMM_offdiag<complex<quadruple> >(void *arg_);
2435
2436 template
2437 void DSchurGEMM_offdiag<float>(void *arg_);
2438
2439 template
2440 void DSchurGEMM_offdiag<complex<float> >(void *arg_);
2441 //
2442
2443 template<typename T>
2444 void DSchurGEMM_offdiag_two(void *arg_)
2445 {
2446 DSchurGEMM_two_arg<T> *arg = (DSchurGEMM_two_arg<T> *)arg_;
2447 if (arg->isSkip) {
2448 return;
2449 }
2450 SquareBlockMatrix<T> *fatherDiag = arg->localSchur;
2451 T *s = fatherDiag->addrCoefBlock(arg->i_block, arg->j_block);
2452 const int nrow = fatherDiag->nrowBlock(arg->i_block, arg->j_block);
2453 const int ncol = fatherDiag->ncolBlock(arg->i_block, arg->j_block);
2454 const T none(-1.0);
2455 const T one(1.0);
2456 // block_nrow * block_ncol : S(i,j) = L(i)^T U(j)
2457 if (arg->isTrans) {
2458 for (int k = 0; k < arg->lower0->num_blocks_r(); k++) {
2459 const T *ptLt0 = arg->lower0->addrCoefBlock(k, arg->j_block);
2460 const T *ptU0 = arg->upper0->addrCoefBlock(k, arg->i_block);
2461 int nnrow = arg->lower0->nrowBlock(k);
2462 blas_gemm<T>(CblasTrans, CblasNoTrans,
2463 nrow, ncol,
2464 nnrow, // arg->nrow0,
2465 none, //alpha,
2466 ptLt0, nnrow, // arg->nrow0,
2467 ptU0, nnrow, // arg->nrow0,
2468 one, //beta,
2469 s, nrow);
2470 }
2471 for (int k = 0; k < arg->lower1->num_blocks_r(); k++) {
2472 const T *ptLt1 = arg->lower1->addrCoefBlock(k, arg->j_block);
2473 const T *ptU1 = arg->upper1->addrCoefBlock(k, arg->i_block);
2474 int nnrow = arg->lower1->nrowBlock(k);
2475 blas_gemm<T>(CblasTrans, CblasNoTrans,
2476 nrow, ncol,
2477 nnrow, // arg->nrow1,
2478 none, // alpha,
2479 ptLt1, nnrow, // arg->nrow1,
2480 ptU1, nnrow, // arg->nrow1,
2481 one, // beta,
2482 s, nrow);
2483 }
2484 }
2485 else {
2486 for (int k = 0; k < arg->lower0->num_blocks_r(); k++) {
2487 const T *ptLt0 = arg->lower0->addrCoefBlock(k, arg->i_block);
2488 const T *ptU0 = arg->upper0->addrCoefBlock(k, arg->j_block);
2489 int nnrow = arg->lower0->nrowBlock(k);
2490 blas_gemm<T>(CblasTrans, CblasNoTrans,
2491 nrow, ncol,
2492 nnrow, // arg->nrow0,
2493 none, //alpha,
2494 ptLt0, nnrow, // arg->nrow0,
2495 ptU0, nnrow, // arg->nrow0,
2496 one, //beta,
2497 s, nrow);
2498 }
2499 for (int k = 0; k < arg->lower1->num_blocks_r(); k++) {
2500 const T *ptLt1 = arg->lower1->addrCoefBlock(k, arg->i_block);
2501 const T *ptU1 = arg->upper1->addrCoefBlock(k, arg->j_block);
2502 int nnrow = arg->lower1->nrowBlock(k);
2503 blas_gemm<T>(CblasTrans, CblasNoTrans,
2504 nrow, ncol,
2505 nnrow, // arg->nrow1,
2506 none, // alpha,
2507 ptLt1, nnrow, // arg->nrow1,
2508 ptU1, nnrow, // arg->nrow1,
2509 one, //beta,
2510 s, nrow);
2511 }
2512 }
2513 }
2514
2515 template
2516 void DSchurGEMM_offdiag_two<double>(void *arg_);
2517
2518 template
2519 void DSchurGEMM_offdiag_two<quadruple>(void *arg_);
2520
2521 template
2522 void DSchurGEMM_offdiag_two<complex<double> >(void *arg_);
2523
2524 template
2525 void DSchurGEMM_offdiag_two<complex<quadruple> >(void *arg_);
2526
2527 template
2528 void DSchurGEMM_offdiag_two<float>(void *arg_);
2529
2530 template
2531 void DSchurGEMM_offdiag_two<complex<float> >(void *arg_);
2532 //
2533
2534 template<typename T>
2535 void C_DTRSMScale_diag_upper(void *arg_)
2536 {
2537 DTRSMScale_arg<T> *arg = (DTRSMScale_arg<T> *)arg_;
2538 int ncol = arg->ncol;
2539 vector<int> &permute = arg->LDLt->getPermute();
2540 const int k = arg->kblock;
2541 const int kk = arg->LDLt->IndexBlock(k);
2542 vector<int>* singLocNodes0 = arg->singLocNodes0;
2543 const int n0 = singLocNodes0->size();
2544 T *LDLt = arg->LDLt->addrCoefBlock(k, k);
2545 T *upper = arg->upper->addrCoefBlock(k, arg->lblock);
2546 // T *lower;
2547 const int nrow = arg->LDLt->nrowBlock(k, k);
2548 const T one(1.0);
2549 const T zero(0.0);
2550 int nn0 = 0;
2551 if (arg->isSym) {
2552 arg->lower->allocateBlock(k, arg->lblock);
2553 T *lower = arg->lower->addrCoefBlock(k, arg->lblock);
2554 if (arg->localPermute) {
2555 VectorArray<T> xtmp(arg->upper->nrowBlock(k));
2556 for (int j = 0; j < ncol; j++) {
2557 int i, ii;
2558 int jnrow = j * nrow;
2559 for (ii = kk, i = 0; i < nrow; i++, ii++) {
2560 const int ip = permute[ii] - kk;
2561 xtmp[i] = upper[ip + jnrow];
2562 }
2563 blas_copy<T>(nrow, xtmp.addrCoefs(), 1, lower + jnrow, 1);
2564 } // loop : j
2565 xtmp.free();
2566 }
2567 if (n0 > 0) {
2568 for (vector<int>::const_iterator it = singLocNodes0->begin();
2569 it != singLocNodes0->end();
2570 ++it) {
2571 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
2572 nn0++;
2573 int itmp = (*it) - kk;
2574 for (int j = 0; j < ncol; j++, itmp += nrow) {
2575 lower[itmp] = zero;
2576 }
2577 }
2578 } // loop : it
2579 }
2580 blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit,
2581 (nrow - nn0), // skip computation nullified entries
2582 ncol,
2583 one, //alpha,
2584 LDLt,
2585 nrow, //
2586 lower, nrow); //lower + kk, n
2587 for (int j = 0; j < ncol; j++) {
2588 const int jnrow = j * nrow;
2589 for (int i = 0; i < nrow; i++) {
2590 upper[i + jnrow] = lower[i + jnrow] * LDLt[i * (nrow + 1)];
2591 }
2592 }
2593 } // if (arg->isSym)
2594 else {
2595 // lower = arg->lower->addrCoefBlock(k, arg->lblock);
2596 if (arg->localPermute) {
2597 VectorArray<T> xtmp(arg->upper->nrowBlock(k));
2598 for (int j = 0; j < ncol; j++) {
2599 int i, ii;
2600 int jnrow = j * nrow;
2601 for (ii = kk, i = 0; i < nrow; i++, ii++) {
2602 const int ip = permute[ii] - kk;
2603 xtmp[i] = upper[ip + jnrow];
2604 }
2605 blas_copy<T>(nrow, xtmp.addrCoefs(), 1, upper + jnrow, 1);
2606 } // loop : j
2607 xtmp.free();
2608 }
2609 if (n0 > 0) {
2610 for (vector<int>::const_iterator it = singLocNodes0->begin();
2611 it != singLocNodes0->end();
2612 ++it) {
2613 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
2614 int itmp = (*it) - kk;
2615 nn0++;
2616 for (int j = 0; j < ncol; j++, itmp += nrow) {
2617 upper[itmp] = zero;
2618 }
2619 }
2620 } // loop : it
2621 }
2622 blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit,
2623 (nrow - nn0), // skip computation nullified entries
2624 ncol,
2625 one, //alpha,
2626 LDLt, nrow,
2627 upper, nrow); // upper + kk, n);
2628 for (int j = 0; j < ncol; j++) {
2629 const int jnrow = j * nrow;
2630 for (int i = 0; i < nrow; i++) {
2631 upper[i + jnrow] *= LDLt[i * (nrow + 1)];
2632 }
2633 }
2634 } // else if (arg->isSym)
2635 }
2636
2637 template
2638 void C_DTRSMScale_diag_upper<double>(void *arg_);
2639
2640 template
2641 void C_DTRSMScale_diag_upper<quadruple>(void *arg_);
2642
2643 template
2644 void C_DTRSMScale_diag_upper<complex<double> >(void *arg_);
2645
2646 template
2647 void C_DTRSMScale_diag_upper<complex<quadruple> >(void *arg_);
2648
2649 template
2650 void C_DTRSMScale_diag_upper<float>(void *arg_);
2651
2652 template
2653 void C_DTRSMScale_diag_upper<complex<float> >(void *arg_);
2654
2655 //
2656
2657 template<typename T>
2658 void C_DTRSMScale_offdiag_upper(void *arg_)
2659 {
2660 const T none(-1.0);
2661 const T one(1.0);
2662
2663 DTRSMScale_arg<T> *arg = (DTRSMScale_arg<T> *)arg_;
2664 int ncol = arg->ncol;
2665 const int k = arg->kblock;
2666 const int m = arg->mblock;
2667 vector<int>* singLocNodes0 = arg->singLocNodes0;
2668 const int n0 = singLocNodes0->size();
2669 const int kk = arg->LDLt->IndexBlock(k);
2670 const int nrow = arg->LDLt->nrowBlock(k, k);
2671 const int nrow1 = arg->LDLt->ncolBlock(k, m); //
2672
2673 int nn0 = 0;
2674 if (n0 > 0) {
2675 for (vector<int>::const_iterator it = singLocNodes0->begin();
2676 it != singLocNodes0->end();
2677 ++it) {
2678 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
2679 nn0++;
2680 }
2681 } // loop : it
2682 }
2683 if (arg->isSym) {
2684 blas_gemm<T>(CblasTrans, CblasNoTrans,
2685 nrow1, ncol, // based on row/column sizes of "upper"
2686 (nrow - nn0), // skip computation nullified entries
2687 none, // alpha,
2688 arg->LDLt->addrCoefBlock(k, m), // transposed upper
2689 arg->LDLt->nrowBlock(k, m),
2690 arg->lower->addrCoefBlock(k, arg->lblock),
2691 arg->lower->nrowBlock(k),
2692 one, // beta,
2693 arg->upper->addrCoefBlock(m, arg->lblock),
2694 arg->upper->nrowBlock(m));
2695 }
2696 else {
2697 blas_gemm<T>(CblasTrans, CblasNoTrans,
2698 nrow1, ncol, // based on row/column sizes of "upper"
2699 (nrow - nn0), // skip computation nullified entries
2700 none, // alpha,
2701 arg->LDLt->addrCoefBlock(m, k), // transposed lower
2702 arg->LDLt->nrowBlock(m, k),
2703 arg->upper->addrCoefBlock(k, arg->lblock),
2704 arg->upper->nrowBlock(k),
2705 one, // beta,
2706 arg->upper->addrCoefBlock(m, arg->lblock),
2707 arg->upper->nrowBlock(m));
2708 }
2709 }
2710
2711 template
2712 void C_DTRSMScale_offdiag_upper<double>(void *arg_);
2713
2714 template
2715 void C_DTRSMScale_offdiag_upper<quadruple>(void *arg_);
2716
2717 template
2718 void C_DTRSMScale_offdiag_upper<complex<double> >(void *arg_);
2719
2720 template
2721 void C_DTRSMScale_offdiag_upper<complex<quadruple> >(void *arg_);
2722
2723 template
2724 void C_DTRSMScale_offdiag_upper<float>(void *arg_);
2725
2726 template
2727 void C_DTRSMScale_offdiag_upper<complex<float> >(void *arg_);
2728 //
2729
2730 template<typename T>
2731 void C_DTRSMScale_diag_lower(void *arg_)
2732 {
2733 const T one(1.0);
2734 const T zero(0.0);
2735 DTRSMScale_arg<T> *arg = (DTRSMScale_arg<T> *)arg_;
2736 int ncol = arg->ncol;
2737 vector<int> &permute = arg->LDLt->getPermute();
2738 const int k = arg->kblock;
2739 T *lower = arg->lower->addrCoefBlock(k, arg->lblock);
2740 const int nrow = arg->LDLt->nrowBlock(k, k);
2741 const int kk = arg->LDLt->IndexBlock(k);
2742 vector<int>* singLocNodes0 = arg->singLocNodes0;
2743 const int n0 = singLocNodes0->size();
2744 // direct use of lower block matrix
2745 if (arg->localPermute) {
2746 VectorArray<T> xtmp(arg->lower->nrowBlock(k)); // SIZE_B1];
2747 for (int j = 0; j < ncol; j++) {
2748 int i, ii;
2749 int jnrow = j * nrow;
2750 for (ii = kk, i = 0; i < nrow; i++, ii++) {
2751 const int ip = permute[ii] - kk;
2752 xtmp[i] = lower[ip + jnrow];
2753 }
2754 blas_copy<T>(nrow, xtmp.addrCoefs(), 1, lower + jnrow, 1);
2755 } // loop : j
2756 xtmp.free();
2757 }
2758 // nullifying rows corresponding to singular nodes
2759 int nn0 = 0;
2760 if (n0 > 0) {
2761 for (vector<int>::const_iterator it = singLocNodes0->begin();
2762 it != singLocNodes0->end();
2763 ++it) {
2764 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
2765 nn0++;
2766 int itmp = (*it) - kk;
2767 for (int j = 0; j < ncol; j++, itmp += nrow) {
2768 lower[itmp] = zero;
2769 }
2770 }
2771 } // loop : it
2772 } // if (n0 > 0)
2773 blas_trsm<T>(CblasLeft, CblasUpper, CblasTrans, CblasUnit,
2774 (nrow - nn0), // skip computation nullified entries
2775 ncol,
2776 one, // alpha,
2777 arg->LDLt->addrCoefBlock(k, k),
2778 arg->LDLt->nrowBlock(k, k),
2779 lower,
2780 nrow);
2781 }
2782
2783 template
2784 void C_DTRSMScale_diag_lower<double>(void *arg_);
2785
2786 template
2787 void C_DTRSMScale_diag_lower<complex<double> >(void *arg_);
2788
2789 template
2790 void C_DTRSMScale_diag_lower<quadruple>(void *arg_);
2791
2792 template
2793 void C_DTRSMScale_diag_lower<complex<quadruple> >(void *arg_);
2794
2795 template
2796 void C_DTRSMScale_diag_lower<float>(void *arg_);
2797
2798 template
2799 void C_DTRSMScale_diag_lower<complex<float> >(void *arg_);
2800 //
2801
2802 template<typename T>
2803 void C_DTRSMScale_offdiag_lower(void *arg_)
2804 {
2805 DTRSMScale_arg<T> *arg = (DTRSMScale_arg<T> *)arg_;
2806 int ncol = arg->ncol;
2807 const int k = arg->kblock;
2808 const int m = arg->mblock;
2809 const int nrow = arg->LDLt->nrowBlock(k, k);
2810 const int kk = arg->LDLt->IndexBlock(k);
2811 const int nrow1 = arg->LDLt->ncolBlock(k, m);
2812 vector<int>* singLocNodes0 = arg->singLocNodes0;
2813 const int n0 = singLocNodes0->size();
2814 int nn0 = 0;
2815
2816 if (n0 > 0) {
2817 for (vector<int>::const_iterator it = singLocNodes0->begin();
2818 it != singLocNodes0->end();
2819 ++it) {
2820 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
2821 nn0++;
2822 }
2823 } // loop : it
2824 }
2825 // x -= A_21 P_1^T L_11^-1 D_11^-1 zz
2826 const T none(-1.0);
2827 const T one(1.0);
2828 blas_gemm<T>(CblasTrans, CblasNoTrans,
2829 nrow1, ncol,
2830 (nrow - nn0), // skip computation nullified entries
2831 none, // alpha,
2832 arg->LDLt->addrCoefBlock(k, m), // transposed upper
2833 arg->LDLt->nrowBlock(k, m),
2834 arg->lower->addrCoefBlock(k, arg->lblock),
2835 arg->lower->nrowBlock(k),
2836 one, // beta,
2837 arg->lower->addrCoefBlock(m, arg->lblock),
2838 arg->lower->nrowBlock(m));
2839 }
2840 template
2841 void C_DTRSMScale_offdiag_lower<double>(void *arg_);
2842
2843 template
2844 void C_DTRSMScale_offdiag_lower<quadruple>(void *arg_);
2845
2846 template
2847 void C_DTRSMScale_offdiag_lower<complex<double> >(void *arg_);
2848
2849 template
2850 void C_DTRSMScale_offdiag_lower<complex<quadruple> >(void *arg_);
2851
2852 template
2853 void C_DTRSMScale_offdiag_lower<float>(void *arg_);
2854
2855 template
2856 void C_DTRSMScale_offdiag_lower<complex<float> >(void *arg_);
2857 //
2858
2859 template<typename T>
2860 void C_DTRSMScale_solve(void *arg_)
2861 {
2862 DTRSMScale_arg<T> *arg = (DTRSMScale_arg<T> *)arg_;
2863 // should be a local array belonging to the same CPU
2864 bool verbose = arg->verbose;
2865 FILE *fp = *(arg->fp);
2866 const int num_block = arg->LDLt->num_blocks();
2867
2868 if (!arg->localPermute) {
2869 VectorArray<T> xtmp(arg->nrow);
2870 vector<int> &permute = arg->LDLt->getPermute();
2871 diss_printf(verbose, fp, "%s %d : non blocked forward substituion\n",
2872 __FILE__, __LINE__);
2873 // const int num_block = arg->LDLt->num_blocks();
2874 if (arg->isSym) {
2875 for (int k = 0; k < num_block; k++) {
2876 arg->lower->allocateBlock(k, arg->lblock);
2877 }
2878 }
2879 for (int j = 0; j < arg->ncol; j++) {
2880 for (int i = 0; i < arg->nrow; i++) {
2881 xtmp[i] = (*arg->upper)(permute[i], j);
2882 }
2883 // blas_copy<T>(arg->nrow, xtmp, 1, arg->upper, 1); // block copy
2884 // arg->nrow need to be composed into blocks : 22 Feb.2016
2885 for (int i = 0; i < arg->nrow; i++) {
2886 (*arg->upper)(i, j) = xtmp[i];
2887 }
2888 }
2889 if (arg->isSym) {
2890 for (int j = 0; j < arg->ncol; j++) {
2891 for (int i = 0; i < arg->nrow; i++) {
2892 (*arg->lower)(i, j) = (*arg->upper)(i, j);
2893 }
2894 }
2895 }
2896 else {
2897 for (int j = 0; j < arg->ncol; j++) {
2898 for (int i = 0; i < arg->nrow; i++) {
2899 xtmp[i] = (*arg->lower)(permute[i], j);
2900 }
2901 for (int i = 0; i < arg->nrow; i++) {
2902 (*arg->lower)(i, j) = xtmp[i];
2903 }
2904 }
2905 }
2906 xtmp.free();
2907 } // if (!arg->localPermute)
2908 // const int num_block = arg->LDLt->num_blocks();
2909 for (int l = 0; l < (*arg->upper).num_blocks_c(); l++) {
2910 arg->lblock = l;
2911 arg->ncol = (*arg->upper).ncolBlock(l);
2912 for (int k = 0; k < num_block; k++) {
2913 arg->kblock = k;
2914 C_DTRSMScale_diag_upper<T>(arg_);
2915 for (int m = (k + 1); m < num_block; m++) {
2916 arg->mblock = m;
2917 C_DTRSMScale_offdiag_upper<T>(arg_);
2918 }
2919 if (!arg->isSym) {
2920 C_DTRSMScale_diag_lower<T>(arg_);
2921 for (int m = (k + 1); m < num_block; m++) {
2922 arg->mblock = m;
2923 C_DTRSMScale_offdiag_lower<T>(arg_);
2924 }
2925 } // if (!arg->isSym)
2926 } // loop : k
2927 }
2928 }
2929
2930 template
2931 void C_DTRSMScale_solve<double>(void *arg_);
2932
2933 template
2934 void C_DTRSMScale_solve<quadruple>(void *arg_);
2935
2936 template
2937 void C_DTRSMScale_solve<complex<double> >(void *arg_);
2938
2939 template
2940 void C_DTRSMScale_solve<complex<quadruple> >(void *arg_);
2941
2942 template
2943 void C_DTRSMScale_solve<float>(void *arg_);
2944
2945 template
2946 void C_DTRSMScale_solve<complex<float> >(void *arg_);
2947
2948 //
2949
2950 template<typename T>
2951 void C_deallocLower(void *arg_)
2952 {
2953 C_deallocLower_arg<T> *arg = (C_deallocLower_arg<T> *)arg_;
2954 if (arg->isSym) {
2955 arg->lower->free();
2956 }
2957 }
2958 template
2959 void C_deallocLower<double>(void *arg_);
2960
2961 template
2962 void C_deallocLower<quadruple>(void *arg_);
2963
2964 template
2965 void C_deallocLower<complex<double> >(void *arg_);
2966
2967 template
2968 void C_deallocLower<complex<quadruple> >(void *arg_);
2969
2970 template
2971 void C_deallocLower<float>(void *arg_);
2972
2973 template
2974 void C_deallocLower<complex<float> >(void *arg_);
2975 //
2976
2977 template<typename T>
2978 void C_deallocLocalSchur(void *arg_)
2979 {
2980 C_deallocLocalSchur_arg<T> *arg = (C_deallocLocalSchur_arg<T> *)arg_;
2981 arg->localSchur->free(arg->i_block, arg->j_block);
2982 }
2983 template
2984 void C_deallocLocalSchur<double>(void *arg_);
2985
2986 template
2987 void C_deallocLocalSchur<quadruple>(void *arg_);
2988
2989 template
2990 void C_deallocLocalSchur<complex<double> >(void *arg_);
2991
2992 template
2993 void C_deallocLocalSchur<complex<quadruple> >(void *arg_);
2994
2995 template
2996 void C_deallocLocalSchur<float>(void *arg_);
2997
2998 template
2999 void C_deallocLocalSchur<complex<float> >(void *arg_);
3000
3001 //
3002
3003 template<typename T, typename U>
3004 void C_SparseFw(void *arg_)
3005 {
3006 const T zero(0.0);
3007 C_SparseFw_arg<T, U> *arg = (C_SparseFw_arg<T, U> *)arg_;
3008 int dim = arg->dim;
3009 const bool isTrans = **(arg->isTrans);
3010 const int nrhs = **(arg->nrhs);
3011 // const void* diag_sparse = arg->diag_sparse;
3012 int colors = arg->colors;
3013 TridiagBlockMatrix<T, U> **tridiag = arg->tridiag;
3014 T *x = *(arg->x);
3015 T *yi = *(arg->yi);
3016 T *zi = *(arg->zi);
3017 T *coef = arg->coef; // arg->ptDA->getCoef();
3018 const int n_diag = arg->n_diag;
3019 const int n_offdiag = arg->n_offdiag;
3020 const int *ptRows = arg->ptRows;
3021 const int *indCols = arg->indCols;
3022 // arg->inTrans is selected as runing time
3023 const int *indVals = **(arg->isTrans) ? arg->indVals_unsym : arg->indVals;
3024 const int *loc2glob_diag = arg->loc2glob_diag;
3025
3026 // get from the global array
3027
3028 for (int m = 0; m < nrhs; m++) {
3029 const int mn_diag = m * n_diag;
3030 const int mdim = m * dim;
3031 for (int i = 0; i < n_diag; i++) {
3032 const int ii = loc2glob_diag[i];
3033 yi[i + mn_diag] = x[ii + mdim];
3034 }
3035 } // loop : m
3036 if (nrhs == 1) {
3037 for (int i = 0; i < colors; i++) {
3038 tridiag[i]->SolveSingle(true, isTrans, yi);
3039 }
3040 }
3041 else {
3042 ColumnMatrix<T> rhs(n_diag, nrhs, yi, false);
3043 for (int i = 0; i < colors; i++) {
3044 tridiag[i]->SolveMulti(true, isTrans, nrhs, rhs);
3045 }
3046 }
3047 // zero clean
3048 for (int i = 0; i < n_offdiag * nrhs; i++) {
3049 zi[i] = zero;
3050 }
3051 // transposed Block SpMV : unsymmetric indVals is given as indVals_unsym
3052 for (int i = 0; i < n_diag; i++) {
3053 for (int k = ptRows[i]; k < ptRows[i + 1]; k++) {
3054 const int j = indCols[k];
3055 T tmp = coef[indVals[k]];
3056 for (int m = 0; m < nrhs; m++) {
3057 const int mn_diag = m * n_diag;
3058 const int mn_offdiag = m * n_offdiag;
3059 zi[j + mn_offdiag] += tmp * yi[i + mn_diag];
3060 }
3061 }
3062 }
3063 }
3064 template
3065 void C_SparseFw<double, double>(void *arg_);
3066
3067 template
3068 void C_SparseFw<quadruple, quadruple>(void *arg_);
3069
3070 template
3071 void C_SparseFw<complex<double>, double>(void *arg_);
3072
3073 template
3074 void C_SparseFw<complex<quadruple>, quadruple>(void *arg_);
3075
3076 template
3077 void C_SparseFw<float, float>(void *arg_);
3078
3079 template
3080 void C_SparseFw<complex<float>, float>(void *arg_);
3081 //
3082
3083 template<typename T, typename U>
3084 void C_SparseBw(void *arg_)
3085 {
3086 const T zero(0.0);
3087 C_SparseBw_arg<T, U> *arg = (C_SparseBw_arg<T, U> *)arg_;
3088 int d = arg->nb;
3089 int dim = arg->dim;
3090 const bool isTrans = **(arg->isTrans);
3091 const int nrhs = **(arg->nrhs);
3092 Dissection::Tree *btree = arg->btree;
3093 const int level_last = arg->level_last;
3094 // const void* diag_sparse = arg->diag_sparse;
3095 int colors = arg->colors;
3096 TridiagBlockMatrix<T, U> **tridiag = arg->tridiag;
3097 T *x = *(arg->x);
3098 T *xi = *(arg->xi);
3099 T ***yy = arg->yy;
3100 T *yi = *(arg->yi);
3101 T *zi = *(arg->zi);
3102 T *coef = arg->coef; // arg->ptDA->getCoef();
3103 const int *ptRows = arg->ptRows;
3104 const int *indCols = arg->indCols;
3105 const int *indVals = isTrans ? arg->indVals_unsym : arg->indVals;
3106
3107 const int n_diag = btree->sizeOfDomain(d);
3108 const int n_offdiag = btree->sizeOfFathersStrips(d);
3109
3110 for (int i = 0; i < (n_diag * nrhs); i++) {
3111 xi[i] = zero;
3112 }
3113 // reading data does not cause conflict between processors
3114 int offset_src = 0;
3115 for (int ll = (level_last - 1); ll >= 0; ll--) {
3116 const int father_id = btree->nthfatherIndex(d, (level_last - ll));
3117 const int father_id0 = btree->selfIndex(father_id);
3118 const Dissection::SetOfStrips &diag = btree->getFathersStrips(d)[ll];
3119 for (Dissection::SetOfStrips::const_iterator it = diag.begin();
3120 it != diag.end(); ++it) {
3121 for (int m = 0; m < nrhs; m++) {
3122 const int mn_offdiag = m * n_offdiag;
3123 const int mn_diag = m * btree->sizeOfDomain(father_id);
3124 int i, i0, i1;
3125 for (i = 0, i0 = (*it).begin_src + offset_src, i1 = (*it).begin_dst;
3126 i < (*it).width; i++, i0++, i1++) {
3127 zi[i0 + mn_offdiag] = (*yy[father_id0])[i1 + mn_diag];
3128 } // loop : i
3129 } // loop : m
3130 } // loop : it
3131 offset_src += diag.numberOfIndices();
3132 } // loop : ll
3133 // SpMV operations : y_d = A_ds y_s
3134 for (int i = 0; i < n_diag; i++) {
3135 for (int k = ptRows[i]; k < ptRows[i + 1]; k++) {
3136 const int jj = indCols[k];
3137 const T tmp = coef[indVals[k]];
3138 for (int m = 0; m < nrhs; m++) {
3139 const int mn_diag = m * n_diag;
3140 const int mn_offdiag = m * n_offdiag;
3141 xi[i + mn_diag] += tmp * zi[jj + mn_offdiag];
3142 }
3143 }
3144 }
3145 // const int idom = _btree->selfIndex(d);
3146 if (nrhs == 1) {
3147 for (int i = 0; i < colors; i++) {
3148 tridiag[i]->SolveSingle(true, isTrans, xi);
3149 }
3150 }
3151 else {
3152 ColumnMatrix<T> rhs(n_diag, nrhs, xi, false);
3153 for (int i = 0; i < colors; i++) {
3154 tridiag[i]->SolveMulti(true, isTrans, nrhs, rhs);
3155 }
3156 }
3157 for (int i = 0; i < (n_diag * nrhs); i++) {
3158 yi[i] -= xi[i]; // without permutation
3159 }
3160 // write back to the global array
3161 const int *loc2glob_diag = btree->getDiagLoc2Glob(d);
3162 for (int m = 0; m < nrhs; m++) {
3163 const int mn_diag = m * n_diag;
3164 const int mdim = m * dim;
3165 for (int i = 0; i < n_diag; i++) {
3166 const int ii = loc2glob_diag[i];
3167 x[ii + mdim] = yi[i + mn_diag];
3168 }
3169 } // loop : m
3170 }
3171
3172 template
3173 void C_SparseBw<double, double>(void *arg_);
3174
3175 template
3176 void C_SparseBw<quadruple, quadruple>(void *arg_);
3177
3178 template
3179 void C_SparseBw<complex<double>, double>(void *arg_);
3180
3181 template
3182 void C_SparseBw<complex<quadruple>, quadruple>(void *arg_);
3183
3184 template
3185 void C_SparseBw<float, float>(void *arg_);
3186
3187 template
3188 void C_SparseBw<complex<float>, float>(void *arg_);
3189 //
3190
3191 template<typename T>
3192 void C_Dsub_FwBw(void *arg_)
3193 {
3194 C_Dsub_FwBw_arg<T> *arg = (C_Dsub_FwBw_arg<T> *)arg_;
3195
3196 const int dim = arg->dim;
3197 const int nrhs = *(arg->nrhs)[0];
3198 const int level = arg->level;
3199 Dissection::Tree *btree = arg->btree;
3200 list<diag_contribution>* diag_contribs = arg->diag_contribs;
3201 T *yi = *(arg->yi);
3202 T ***zi = arg->zi;
3203 bool access_global = arg->access_global;
3204 if (access_global) {
3205 T *x = *(arg->x);
3206 // get from the global array
3207 const int n_diag = arg->n_diag;
3208 const int *loc2glob_diag = arg->loc2glob_diag;
3209 for (int m = 0; m < nrhs; m++) {
3210 const int mn_diag = m * n_diag;
3211 const int mdim = m * dim;
3212 for (int i = 0; i < n_diag; i++) {
3213 const int ii = loc2glob_diag[i];
3214 yi[i + mn_diag] = x[ii + mdim];
3215 }
3216 } // loop : m
3217 }
3218 for (list<diag_contribution>::const_iterator it = diag_contribs->begin();
3219 it != diag_contribs->end(); ++it) {
3220 const int child_id = (*it).child_id;
3221 const int child_id0 = btree->selfIndex(child_id);
3222 if ((btree->nodeLayer(child_id) == level) &&
3223 (btree->sizeOfDomain(child_id) > 0)) { // 08 Nov.2016 Atsushi
3224 for (list<index_strip>::const_iterator mt = (*it).diag_strip.begin();
3225 mt != (*it).diag_strip.end(); ++mt) {
3226 for (int m = 0; m < nrhs; m++) {
3227 const int mn_offdiag = m * (*it).child_column;
3228 const int mn_diag = m * (*it).father_row;
3229 int i, i0, i1;
3230 for (i = 0, i0 = (*mt).begin_src, i1 = (*mt).begin_dst;
3231 i < (*mt).width; i++, i0++, i1++) {
3232 yi[i1 + mn_diag] -= (*zi[child_id0])[i0 + mn_offdiag];
3233 } // loop : i
3234 } // loop : m
3235 } // loop : mt
3236 } // if (_btree->nodeLayer((*it).child_id) == level_last) {
3237 } // loop : it
3238 }
3239
3240 template
3241 void C_Dsub_FwBw<double>(void *arg_);
3242
3243 template
3244 void C_Dsub_FwBw<quadruple>(void *arg_);
3245
3246 template
3247 void C_Dsub_FwBw<complex<double> >(void *arg_);
3248
3249 template
3250 void C_Dsub_FwBw<complex<quadruple> >(void *arg_);
3251
3252 template
3253 void C_Dsub_FwBw<float>(void *arg_);
3254
3255 template
3256 void C_Dsub_FwBw<complex<float> >(void *arg_);
3257 //
3258
3259 template<typename T>
3260 void C_Dfill_FwBw(void *arg_)
3261 {
3262 C_Dfill_FwBw_arg<T> *arg = (C_Dfill_FwBw_arg<T> *)arg_;
3263
3264 const int nrhs = *(arg->nrhs)[0];
3265 const int d = arg->d;
3266 const int level = arg->level;
3267 Dissection::Tree *btree = arg->btree;
3268 const int n_offdiag = arg->n_offdiag;
3269 T ***yi = arg->yi;
3270 T *zi = *(arg->zi);
3271
3272 int offset_src = 0;
3273 for (int ll = (level - 1); ll >= 0; ll--) {
3274 const int father_id = btree->nthfatherIndex(d, (level - ll));
3275 const int father_id0 = btree->selfIndex(father_id);
3276 const Dissection::SetOfStrips &diag = btree->getFathersStrips(d)[ll];
3277 for (Dissection::SetOfStrips::const_iterator it = diag.begin();
3278 it != diag.end(); ++it) {
3279 for (int m = 0; m < nrhs; m++) {
3280 const int mn_offdiag = m * n_offdiag;
3281 const int mn_diag = m * btree->sizeOfDomain(father_id);
3282 int i, i0, i1;
3283 for (i = 0, i0 = (*it).begin_src + offset_src,
3284 i1 = (*it).begin_dst;
3285 i < (*it).width; i++, i0++, i1++) {
3286 zi[i0 + mn_offdiag] = (*yi[father_id0])[i1 + mn_diag];
3287 } // loop : i
3288 } // loop : m
3289 } // loop : it
3290 offset_src += diag.numberOfIndices();
3291 } // loop : ll
3292
3293 }
3294 template
3295 void C_Dfill_FwBw<double>(void *arg_);
3296
3297 template
3298 void C_Dfill_FwBw<quadruple>(void *arg_);
3299
3300 template
3301 void C_Dfill_FwBw<complex<double> >(void *arg_);
3302
3303 template
3304 void C_Dfill_FwBw<complex<quadruple> >(void *arg_);
3305
3306 template
3307 void C_Dfill_FwBw<float>(void *arg_);
3308
3309 template
3310 void C_Dfill_FwBw<complex<float> >(void *arg_);
3311 //
3312
3313 template<typename T>
3314 void C_DenseFwBw_diag(void *arg_)
3315 {
3316 const T one(1.0);
3317 const T zero(0.0);
3318 C_DenseFwBw_arg<T> *arg = (C_DenseFwBw_arg<T> *)arg_;
3319 const int dim = arg->dim; // global dimension, used when nrhs > 1
3320 const bool isTrans = **(arg->isTrans);
3321 const int nrhs = **(arg->nrhs);
3322 const int n_diag = arg->n_diag;
3323 const int nrow = arg->nrow;
3324 const int k_block = arg->k_block;
3325 T *xi = *(arg->xi);
3326 const bool isSym = arg->isSym;
3327 const bool isBackward = arg->isBackward;
3328 const bool isFirstBlock = arg->isFirstBlock;
3329 SquareBlockMatrix<T> &Diag = *(arg->LDLt);
3330 const bool isBlocked = Diag.isBlocked();
3331 T *LDLt = Diag.addrCoefBlock(k_block, k_block);
3332 const int LDLt_nrow = Diag.nrowBlock(k_block, k_block);
3333 const int kk = Diag.IndexBlock(k_block);
3334 vector<int> singIdx0 = Diag.getSingIdx0();
3335 const bool verbose = arg->verbose;
3336 FILE *fp = *(arg->fp);
3337 if (isBlocked) {
3338 if (!isBackward) {
3339 T *yi = *(arg->yi);
3340 vector<int> &permute = Diag.getPermute();
3341 // permutation : original index -> factorized index
3342 for (int m = 0; m < nrhs; m++) {
3343 const int mn_diag = m * n_diag;
3344 for (int i = kk; i < kk + nrow; i++) {
3345 xi[i + mn_diag] = yi[permute[i] + mn_diag];
3346 }
3347 }
3348 }
3349 }
3350 else { // if (isBlocked)
3351 // permute the whole RHS by the k == 0 block
3352 if (isFirstBlock && (isBackward == false)) {
3353 T *yi = *(arg->yi);
3354 vector<int> &permute = Diag.getPermute();
3355 // permutation : original index -> factorized index
3356 for (int m = 0; m < nrhs; m++) {
3357 const int mn_diag = m * n_diag;
3358 for (int i = 0; i < n_diag; i++) {
3359 xi[i + mn_diag] = yi[permute[i] + mn_diag];
3360 }
3361 }
3362 }
3363 } // if (isBlocked)
3364 if (nrhs == 1) {
3365 int nn0 = 0;
3366 if (singIdx0.size() > 0) {
3367 for (vector<int>::const_iterator it = singIdx0.begin();
3368 it != singIdx0.end(); ++it) {
3369 // inside of the block
3370 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
3371 xi[(*it)] = zero;
3372 nn0++;
3373 }
3374 }
3375 // if (d0 == 0) degmv for the regular part of singIdx0
3376 } // if (singIdx.size() > 0)
3377 const int nn1 = nrow - nn0; // invertible part
3378 if (isSym) {
3379 blas_trsv<T>(CblasLower, (isBackward ? CblasTrans: CblasNoTrans),
3380 CblasUnit,
3381 nn1,
3382 LDLt, LDLt_nrow, //n_diag,
3383 xi + kk, 1);
3384 }
3385 else {
3386 if (isTrans) {
3387 if (isBackward) { //Lower bocks of matrix are not scaled then scale here
3388 int itmp = 0;
3389 for (int i = kk; i < (kk + nrow); i++, itmp += (LDLt_nrow + 1)) {
3390 xi[i] *= LDLt[itmp];
3391 }
3392 }
3393 blas_trsv<T>((isBackward ? CblasLower : CblasUpper), CblasTrans,
3394 CblasUnit,
3395 nn1,
3396 LDLt, LDLt_nrow, //n_diag,
3397 xi + kk, 1);
3398 }
3399 else {
3400 blas_trsv<T>((isBackward ? CblasUpper : CblasLower), CblasNoTrans,
3401 CblasUnit,
3402 nn1,
3403 LDLt, LDLt_nrow, //n_diag,
3404 xi + kk, 1);
3405 }
3406 }
3407 // if (d0 == 0) degmv for the regular part of singIdx0
3408 // if (singIdx.size() > 0)
3409 if (!isBackward) {
3410 T *wi = *(arg->wi);
3411 if (isSym) {
3412 int itmp = 0;
3413 for (int i = kk; i < (kk + nrow); i++, itmp += (LDLt_nrow + 1)) {
3414 wi[i] = xi[i];
3415 xi[i] *= LDLt[itmp];
3416 }
3417 }
3418 else {
3419 if(isTrans) {
3420 for (int i = kk; i < (kk + nrow); i++) {
3421 wi[i] = xi[i]; // Upper bocks of matrix are scaled
3422 }
3423 }
3424 else {
3425 int itmp = 0;
3426 for (int i = kk; i < (kk + nrow); i++, itmp += (LDLt_nrow + 1)) {
3427 xi[i] *= LDLt[itmp]; // Lower bocks of matrix are not scaled
3428 wi[i] = xi[i];
3429 }
3430 }
3431 }
3432 }
3433 }
3434 else { // if (nrhs != 1)
3435 int nn0 = 0;
3436 if (singIdx0.size() > 0) {
3437 for (vector<int>::const_iterator it = singIdx0.begin();
3438 it != singIdx0.end(); ++it) {
3439 // inside of th block
3440 if (((*it) >= kk) && ((*it) < (kk + nrow))) {
3441 nn0++;
3442 int itmp = (*it);
3443 for (int m = 0; m < nrhs; m++, itmp += n_diag) {
3444 xi[itmp] = zero;
3445 }
3446 }
3447 }
3448 } // if (singIdx.size() > 0)
3449 const int nn1 = nrow - nn0; // invertible part
3450 if (isSym) {
3451 blas_trsm<T>(CblasLeft,
3452 CblasLower, (isBackward ? CblasTrans : CblasNoTrans),
3453 CblasUnit,
3454 nn1,
3455 nrhs,
3456 one, //alpha,
3457 LDLt, LDLt_nrow, //n_diag,
3458 xi + kk, n_diag);
3459 }
3460 else {
3461 if (isTrans) {
3462 if (isBackward) {
3463 int itmp = 0;
3464 for (int i = kk; i < (kk + nrow); i++, itmp += (LDLt_nrow + 1)) {
3465 for (int m = 0; m < nrhs; m++) {
3466 const int mn_diag = m * n_diag;
3467 xi[i + mn_diag] *= LDLt[itmp];
3468 }
3469 }
3470 }
3471 blas_trsm<T>(CblasLeft,
3472 (isBackward ? CblasLower : CblasUpper), CblasTrans,
3473 CblasUnit,
3474 nn1,
3475 nrhs,
3476 one, // alpha,
3477 LDLt, LDLt_nrow, //n_diag,
3478 xi + kk, n_diag);
3479 }
3480 else {
3481 blas_trsm<T>(CblasLeft,
3482 (isBackward ? CblasUpper : CblasLower), CblasNoTrans,
3483 CblasUnit,
3484 nn1,
3485 nrhs,
3486 one, //alpha,
3487 LDLt, LDLt_nrow, //n_diag,
3488 xi + kk, n_diag);
3489 }
3490 }
3491 if (!isBackward) {
3492 T *wi = *(arg->wi);
3493 if(isSym) {
3494 int itmp = 0;
3495 for (int i = kk; i < (kk + nrow); i++, itmp += (LDLt_nrow + 1)) {
3496 for (int m = 0; m < nrhs; m++) {
3497 const int mn_diag = m * n_diag;
3498 wi[i + mn_diag] = xi[i + mn_diag]; // for yl[] - A_li xi[] : l>i
3499 xi[i + mn_diag] *= LDLt[itmp];
3500 }
3501 }
3502 }
3503 else {
3504 if (isTrans) {
3505 for (int i = kk; i < (kk + nrow); i++) {
3506 for (int m = 0; m < nrhs; m++) {
3507 const int mn_diag = m * n_diag;
3508 wi[i + mn_diag] = xi[i + mn_diag]; // for yl[] - A_li xi[] : l>i
3509 }
3510 }
3511 }
3512 else {
3513 int itmp = 0;
3514 for (int i = kk; i < (kk + nrow); i++, itmp += (LDLt_nrow + 1)) {
3515 for (int m = 0; m < nrhs; m++) {
3516 const int mn_diag = m * n_diag;
3517 xi[i + mn_diag] *= LDLt[itmp];
3518 wi[i + mn_diag] = xi[i + mn_diag]; // for yl[] - A_li xi[] : l>i
3519 }
3520 }
3521 }
3522 }
3523 } // if (!isBackward)
3524 } // if (nrhs == 1)
3525 if (isBlocked) {
3526 if (isBackward) {
3527 T *yi = *(arg->yi);
3528 vector<int> &permute = Diag.getPermute();
3529 for (int m = 0; m < nrhs; m++) {
3530 const int mn_diag = m * n_diag;
3531 for (int i = kk; i < kk + nrow; i++) {
3532 yi[permute[i] + mn_diag] = xi[i + mn_diag];
3533 }
3534 for (int i = kk; i < kk + nrow; i++) {
3535 xi[i + mn_diag] = yi[i + mn_diag];
3536 }
3537 }
3538 if(isFirstBlock) {
3539 int *loc2glob_diag = arg->loc2glob;
3540 T *x = *(arg->x);
3541 for (int m = 0; m < nrhs; m++) {
3542 const int mn_diag = m * n_diag;
3543 const int mdim = m * dim;
3544 for (int i = 0; i < n_diag; i++) {
3545 const int ii = loc2glob_diag[i];
3546 x[ii + mdim] = xi[i + mn_diag];
3547 }
3548 } // loop : m
3549 } // if(isFirstBlock)
3550 } // if (isBackward)
3551 // forward substitution with block permutation : internally no permutation
3552 }
3553 else {
3554 if (isFirstBlock && isBackward) {
3555 T *yi = *(arg->yi);
3556 vector<int> &permute = Diag.getPermute();
3557 for (int m = 0; m < nrhs; m++) {
3558 const int mn_diag = m * n_diag;
3559 for (int i = 0; i < n_diag; i++) {
3560 yi[permute[i] + mn_diag] = xi[i + mn_diag];
3561 }
3562 }
3563 int *loc2glob_diag = arg->loc2glob;
3564 T *x = *(arg->x);
3565 for (int m = 0; m < nrhs; m++) {
3566 const int mn_diag = m * n_diag;
3567 const int mdim = m * dim;
3568 for (int i = 0; i < n_diag; i++) {
3569 const int ii = loc2glob_diag[i];
3570 x[ii + mdim] = yi[i + mn_diag];
3571 }
3572 } // loop : m
3573 } // if (isFirstBlock && isBackward) {
3574 } // if (isBlocked)
3575 }
3576 template
3577 void C_DenseFwBw_diag<double>(void *arg_);
3578
3579 template
3580 void C_DenseFwBw_diag<quadruple>(void *arg_);
3581
3582 template
3583 void C_DenseFwBw_diag<complex<double> >(void *arg_);
3584
3585 template
3586 void C_DenseFwBw_diag<complex<quadruple> >(void *arg_);
3587
3588 template
3589 void C_DenseFwBw_diag<float>(void *arg_);
3590
3591 template
3592 void C_DenseFwBw_diag<complex<float> >(void *arg_);
3593
3594 //
3595
3596 template<typename T>
3597 void C_DenseFwBw_offdiag(void *arg_)
3598 {
3599 C_DenseFwBwOffdiag_arg<T> *arg = (C_DenseFwBwOffdiag_arg<T> *)arg_;
3600 const bool isTrans = **(arg->isTrans);
3601 const int nrhs = **(arg->nrhs);
3602 const int ldb = arg->ldb;
3603 const int ldc = arg->ldc;
3604 const int nrow = arg->nrow;
3605 const int ncol = arg->ncol;
3606 T *xi = *(arg->xi);
3607 T *yi;
3608 const int ii = arg->ii;
3609 const int jj = arg->jj;
3610 T *a;
3611 const T alpha = arg->alpha;
3612 const T beta = arg->beta;
3613 const bool trans = arg->trans;
3614 const bool isLower = arg->isLower;
3615 int i_block, j_block;
3616 int lda;
3617 // #define DEBUG_INDEX
3618 #ifdef DEBUG_INDEX
3619 fprintf(stderr, "%s %d : nrow = %d ncol = %d %s [%d %d] [%d %d] %d : %s %s ",
3620 __FILE__, __LINE__, nrow, ncol,
3621 isLower ? "Lower" : "Upper", arg->i_block, arg->j_block, ii, jj, nrhs,
3622 trans ? "T" : "N", isTrans ? "trans" : "normal");
3623 #endif
3624 {
3625 if (arg->LDLt->isBlocked()) {
3626 yi = *(arg->yi);
3627 }
3628 else {
3629 yi = *(arg->zi);
3630 }
3631 if (trans) { // noly for _isSym == true
3632 i_block = arg->j_block;
3633 j_block = arg->i_block;
3634 }
3635 else {
3636 if (isTrans) {
3637 i_block = arg->j_block;
3638 j_block = arg->i_block;
3639 }
3640 else {
3641 i_block = arg->i_block;
3642 j_block = arg->j_block;
3643 }
3644 }
3645 a = arg->LDLt->addrCoefBlock(i_block, j_block);
3646 lda = arg->LDLt->nrowBlock(i_block, j_block);
3647 #ifdef DEBUG_INDEX
3648 fprintf(stderr, "%d x %d\n",
3649 arg->LDLt->nrowBlock(arg->j_block, arg->i_block),
3650 arg->LDLt->ncolBlock(arg->j_block, arg->i_block));
3651 #endif
3652 //
3653 if (isLower) {
3654 if (nrhs == 1) {
3655 // nrow and ncol are based on geometrical size of the block
3656 // data storage is transposed in the case of the lower block
3657 blas_gemv<T>(CblasTrans,
3658 ncol, nrow, // based on a
3659 alpha,
3660 a, lda,
3661 xi + ii, 1,
3662 beta,
3663 yi + jj, 1);
3664 }
3665 else {
3666 blas_gemm<T>(CblasTrans,
3667 CblasNoTrans,
3668 nrow, nrhs, ncol, // based on yi[]
3669 alpha,
3670 a, lda,
3671 xi + ii, ldb,
3672 beta,
3673 yi + jj, ldc);
3674 }
3675 }
3676 else {
3677 if (nrhs == 1) {
3678 blas_gemv<T>(CblasNoTrans,
3679 nrow, ncol, // based on a
3680 alpha,
3681 a, lda,
3682 xi + ii, 1,
3683 beta,
3684 yi + jj, 1);
3685 }
3686 else {
3687 blas_gemm<T>(CblasNoTrans,
3688 CblasNoTrans,
3689 nrow, nrhs, ncol, // based on yi[]
3690 alpha,
3691 a, lda,
3692 xi + ii, ldb,
3693 beta,
3694 yi + jj, ldc);
3695 }
3696 }
3697 } // if (isLocalDiag)
3698 }
3699 template
3700 void C_DenseFwBw_offdiag<double>(void *arg_);
3701
3702 template
3703 void C_DenseFwBw_offdiag<quadruple>(void *arg_);
3704
3705 template
3706 void C_DenseFwBw_offdiag<complex<double> >(void *arg_);
3707
3708 template
3709 void C_DenseFwBw_offdiag<complex<quadruple> >(void *arg_);
3710
3711 template
3712 void C_DenseFwBw_offdiag<float>(void *arg_);
3713
3714 template
3715 void C_DenseFwBw_offdiag<complex<float> >(void *arg_);
3716 //
3717
3718 template<typename T>
3719 void C_StripsFwBw_offdiag(void *arg_)
3720 {
3721 C_StripsFwBwOffdiag_arg<T> *arg = (C_StripsFwBwOffdiag_arg<T> *)arg_;
3722 const bool isTrans = **(arg->isTrans);
3723 const int nrhs = **(arg->nrhs);
3724 const int ldb = arg->ldb;
3725 const int ldc = arg->ldc;
3726 const int ii = arg->ii;
3727 const int jj = arg->jj;
3728 const T alpha = arg->alpha;
3729 const T beta = arg->beta;
3730 // const bool trans = arg->trans;
3731 const bool isLower = arg->isLower;
3732
3733 T *xi = *(arg->xi);
3734 T *yi = *(arg->yi);
3735
3736 RectBlockMatrix<T> *aa = isTrans ? arg->lower : arg->upper;
3737 const int i_block = isLower ? arg->i_block : arg->j_block;
3738 const int j_block = isLower ? arg->j_block : arg->i_block;
3739
3740 if (isLower) {
3741 if (nrhs == 1) {
3742 // nrow and ncol are based on geometrical size of the block
3743 // data storage is transposed in the case of the lower block
3744 blas_gemv<T>(CblasTrans,
3745 aa->nrowBlock(i_block), // based on matrix A
3746 aa->ncolBlock(j_block), //
3747 alpha,
3748 aa->addrCoefBlock(i_block, j_block),
3749 aa->nrowBlock(i_block), // lda,
3750 xi + ii, 1,
3751 beta,
3752 yi + jj, 1);
3753 }
3754 else {
3755 blas_gemm<T>(CblasTrans,
3756 CblasNoTrans,
3757 aa->ncolBlock(j_block), // based on yi[]
3758 nrhs,
3759 aa->nrowBlock(i_block), //
3760 alpha,
3761 aa->addrCoefBlock(i_block, j_block),
3762 aa->nrowBlock(i_block), // lda,
3763 xi + ii, ldb,
3764 beta,
3765 yi + jj, ldc);
3766 }
3767 }
3768 else {
3769 const int nblocks_col = aa->num_blocks_c();
3770 if (nrhs == 1) {
3771 for (int j = 0; j < nblocks_col; j++) { // sequential operation.
3772 int jjj = aa->IndexBlock_c(j);
3773 blas_gemv<T>(CblasNoTrans,
3774 // nrow, ncol, // based on a
3775 aa->nrowBlock(i_block), // nrow,
3776 aa->ncolBlock(j), // ncol,
3777 alpha,
3778 aa->addrCoefBlock(i_block, j),
3779 aa->nrowBlock(i_block), // lda
3780 xi + jjj, 1,
3781 beta,
3782 yi + jj, 1);
3783 }
3784 }
3785 else {
3786 for (int j = 0; j < nblocks_col; j++) { // sequential operation.
3787 int jjj = aa->IndexBlock_c(j);
3788 blas_gemm<T>(CblasNoTrans,
3789 CblasNoTrans,
3790 aa->nrowBlock(i_block), // nrow,
3791 nrhs,
3792 aa->ncolBlock(j), // ncol, // based on yi[]
3793 alpha,
3794 aa->addrCoefBlock(i_block, j),
3795 aa->nrowBlock(i_block), // lda,
3796 xi + jjj, ldb,
3797 beta,
3798 yi + jj, ldc);
3799 }
3800 } // if (nrhs == 1)
3801 } // if (isLower)
3802 }
3803 template
3804 void C_StripsFwBw_offdiag<double>(void *arg_);
3805
3806 template
3807 void C_StripsFwBw_offdiag<quadruple>(void *arg_);
3808
3809 template
3810 void C_StripsFwBw_offdiag<complex<double> >(void *arg_);
3811
3812 template
3813 void C_StripsFwBw_offdiag<complex<quadruple> >(void *arg_);
3814
3815 template
3816 void C_StripsFwBw_offdiag<float>(void *arg_);
3817
3818 template
3819 void C_StripsFwBw_offdiag<complex<float> >(void *arg_);
3820 //
3821 template<typename T, typename U>
3822 void erase_task(C_task *& task)
3823 {
3824 bool flag = false;
3825 switch(task->task_id) {
3826 case C_DSUB:
3827 {
3828 list<C_Dsub_task<T>* > *tt = (list<C_Dsub_task<T>* > *)task->func_arg;
3829 for (typename list<C_Dsub_task<T>* >::iterator kt = tt->begin();
3830 kt != tt->end(); ++kt) {
3831 delete (*kt); // C_Dsub_task *tmp = new C_Dsub_task( ... )
3832 (*kt) = NULL;
3833 }
3834 flag = true;
3835 // fprintf(stderr, "%s %d : %s\n", __FILE__, __LINE__, task->task_name);
3836 delete tt;
3837 tt = NULL;
3838 }
3839 break;
3840 case C_SPARSESYMBFACT:
3841 {
3842 C_SparseSymbFact_arg<T, U> *tt = (C_SparseSymbFact_arg<T, U> *)task->func_arg;
3843 delete tt;
3844 tt = NULL;
3845 }
3846 break;
3847 case C_SPARSENUMFACT:
3848 {
3849 C_SparseNumFact_arg<T, U> *tt = (C_SparseNumFact_arg<T, U> *)task->func_arg;
3850 delete tt;
3851 tt = NULL;
3852 }
3853 break;
3854 case C_SPARSESCHUR:
3855 {
3856 C_SparseNumFact_arg<T, U> *tt = (C_SparseNumFact_arg<T, U> *)task->func_arg;
3857 delete tt;
3858 tt = NULL;
3859 }
3860 break;
3861 case C_FILLMATRIX:
3862 {
3863 C_FillMatrix_arg<T> *tt = (C_FillMatrix_arg<T> *)task->func_arg;
3864 delete tt;
3865 tt = NULL;
3866 }
3867 break;
3868 case C_DFULL_SYM_GAUSS:
3869 {
3870 C_dfull_gauss_arg<T, U> *tt = (C_dfull_gauss_arg<T, U> *)task->func_arg;
3871 delete tt;
3872 tt = NULL;
3873 }
3874 break;
3875 case C_DINV_DL_TIMESU:
3876 {
3877 C_dinvDL_timesU_arg<T> *tt = (C_dinvDL_timesU_arg<T> *)task->func_arg;
3878 delete tt;
3879 tt = NULL;
3880 }
3881 break;
3882 case C_DHALF_SCHUR_B:
3883 {
3884 C_dupdateb_Schur_arg<T> *tt = (C_dupdateb_Schur_arg<T> *)task->func_arg;
3885 delete tt;
3886 tt = NULL;
3887 }
3888 break;
3889 case C_DHALF_SCHUR_BT:
3890 {
3891 C_dupdateb_Schur_arg<T> *tt = (C_dupdateb_Schur_arg<T> *)task->func_arg;
3892 delete tt;
3893 tt = NULL;
3894 }
3895 break;
3896 case C_DTRSMSCALE:
3897 {
3898 DTRSMScale_arg<T> *tt = (DTRSMScale_arg<T> *)task->func_arg;
3899 delete tt;
3900 tt = NULL;
3901 }
3902 break;
3903 case C_DGEMM_LOCAL_MULT:
3904 {
3905 DSchurGEMM_arg<T> *tt = (DSchurGEMM_arg<T> *)task->func_arg;
3906 delete tt;
3907 tt = NULL;
3908 }
3909 break;
3910 case C_DGEMM_LOCAL_TWO:
3911 {
3912 DSchurGEMM_arg<T> *tt = (DSchurGEMM_arg<T> *)task->func_arg;
3913 delete tt;
3914 tt = NULL;
3915 }
3916 break;
3917 case C_DGEMM_DIRECT_TWO:
3918 {
3919 DSchurGEMM_two_arg<T> *tt = (DSchurGEMM_two_arg<T> *)task->func_arg;
3920 delete tt;
3921 tt = NULL;
3922 }
3923 break;
3924 case C_DEALLOCLOWER:
3925 {
3926 C_deallocLower_arg<T> *tt = (C_deallocLower_arg<T> *)task->func_arg;
3927 delete tt;
3928 tt = NULL;
3929 }
3930 break;
3931 case C_DEALLOCLOCALSCHUR:
3932 {
3933 C_deallocLocalSchur_arg<T> *tt = (C_deallocLocalSchur_arg<T> *)task->func_arg;
3934 delete tt;
3935 tt = NULL;
3936 }
3937 break;
3938
3939 case C_SPARSESYMFW:
3940 {
3941 C_SparseFw_arg<T, U> *tt = (C_SparseFw_arg<T, U> *)task->func_arg;
3942 delete tt;
3943 tt = NULL;
3944 }
3945 break;
3946 case C_DSUB_FWBW:
3947 {
3948 C_Dsub_FwBw_arg<T> *tt = (C_Dsub_FwBw_arg<T> *)task->func_arg;
3949 delete tt;
3950 tt = NULL;
3951 }
3952 break;
3953 case C_DENSE_SYMFW_DIAG:
3954 {
3955 C_DenseFwBw_arg<T> *tt = (C_DenseFwBw_arg<T> *)task->func_arg;
3956 delete tt;
3957 tt = NULL;
3958 }
3959 break;
3960 case C_DENSE_SYMFW_OFFDIAG:
3961 {
3962 C_DenseFwBwOffdiag_arg<T> *tt = (C_DenseFwBwOffdiag_arg<T> *)task->func_arg;
3963 delete tt;
3964 tt = NULL;
3965 }
3966 break;
3967 case C_STRIPS_SYMFW_OFFDIAG:
3968 {
3969 C_StripsFwBwOffdiag_arg<T> *tt = (C_StripsFwBwOffdiag_arg<T> *)task->func_arg;
3970 delete tt;
3971 tt = NULL;
3972 }
3973 break;
3974 case C_DENSE_SYMFILL:
3975 {
3976 C_Dfill_FwBw_arg<T> *tt = (C_Dfill_FwBw_arg<T> *)task->func_arg;
3977 delete tt;
3978 tt = NULL;
3979 }
3980 break;
3981 case C_SPARSESYMBW:
3982 {
3983 C_SparseBw_arg<T, U> *tt = (C_SparseBw_arg<T, U> *)task->func_arg;
3984 delete tt;
3985 tt = NULL;
3986 }
3987 break;
3988 case C_DUMMY:
3989 {
3990 C_dummy_arg *tt = (C_dummy_arg *)task->func_arg;
3991 delete tt;
3992 tt = NULL;
3993 }
3994 break;
3995 }
3996 if (flag) {
3997 delete task->ops_complexity; // allocated in C_Dsub_quee()
3998 }
3999 // cout << task->task_name << endl;
4000 delete task;
4001 task = NULL;
4002 }
4003 template
4004 void erase_task<double, double>(C_task *& task);
4005
4006 template
4007 void erase_task<quadruple, quadruple>(C_task *& task);
4008
4009 template
4010 void erase_task<complex<double>, double>(C_task *& task);
4011
4012 template
4013 void erase_task<complex<quadruple>, quadruple>(C_task *& task);
4014
4015 template
4016 void erase_task<float, float>(C_task *& task);
4017
4018 template
4019 void erase_task<complex<float>, float>(C_task *& task);
4020 //
4021
4022 template<typename T, typename U>
4023 void full_gauss3(int *n0,
4024 T *a,
4025 const int n,
4026 double *pivot,
4027 int *permute,
4028 const bool isSym,
4029 const double eps,
4030 const bool verbose,
4031 FILE *fp)
4032 {
4033 bool flag;
4034 int nn0, nn1;
4035 double fop;
4036
4037 nn1 = *n0;
4038 diss_printf(verbose, fp,
4039 "%s %d : full_sym_gauss3 is not yet implemented %d ",
4040 __FILE__, __LINE__, nn1);
4041 if (isSym) {
4042 diss_printf(verbose, fp,"ldlt_permute\n");
4043 flag = full_ldlt_permute<T, U>(&nn0, nn1, n, a, n, pivot, permute, eps,
4044 &fop);
4045 }
4046 else {
4047 diss_printf(verbose, fp,"ldu_permute\n");
4048 flag = full_ldu_permute<T, U>(&nn0, nn1, n, a, n, pivot, permute, eps,
4049 &fop);
4050 }
4051 *n0 = nn0;
4052 }
4053
4054 template
4055 void full_gauss3<double, double>(int *n0,
4056 double *a,
4057 const int n,
4058 double *pivot,
4059 int *permute,
4060 const bool isSym,
4061 const double eps,
4062 const bool verbose,
4063 FILE *fp);
4064
4065 template
4066 void full_gauss3<quadruple, quadruple>(int *n0,
4067 quadruple *a,
4068 const int n,
4069 double *pivot,
4070 int *permute,
4071 const bool isSym,
4072 const double eps,
4073 const bool verbose,
4074 FILE *fp);
4075
4076 template
4077 void full_gauss3<complex<double>, double >(int *n0,
4078 complex<double> *a,
4079 const int n,
4080 double *pivot,
4081 int *permute,
4082 const bool isSym,
4083 const double eps,
4084 const bool verbose,
4085 FILE *fp);
4086
4087 template
4088 void full_gauss3<complex<quadruple>, quadruple >(int *n0,
4089 complex<quadruple> *a,
4090 const int n,
4091 double *pivot,
4092 int *permute,
4093 const bool isSym,
4094 const double eps,
4095 const bool verbose,
4096 FILE *fp);
4097
4098 template
4099 void full_gauss3<float, float>(int *n0,
4100 float *a,
4101 const int n,
4102 double *pivot,
4103 int *permute,
4104 const bool isSym,
4105 const double eps,
4106 const bool verbose,
4107 FILE *fp);
4108
4109 template
4110 void full_gauss3<complex<float>, float >(int *n0,
4111 complex<float> *a,
4112 const int n,
4113 double *pivot,
4114 int *permute,
4115 const bool isSym,
4116 const double eps,
4117 const bool verbose,
4118 FILE *fp);
4119 //
4120
4121 template<typename T>
4122 void dump_vectors(int nrow, int nn0, T *v, string fname)
4123 {
4124 fprintf(stderr, "%s %d : speci1alized template is not yet defined.\n",
4125 __FILE__, __LINE__);
4126 }
4127
4128 template<>
4129 void dump_vectors<double>(int nrow, int nn0, double *v, string fname)
4130 {
4131 FILE *fp;
4132 if ((fp = fopen(fname.c_str(), "w")) != NULL) {
4133 for (int i = 0 ; i < nrow; i++) {
4134 fprintf(fp, "%d ", i);
4135 for (int j = 0; j < nn0; j++) {
4136 fprintf(fp, "%g ", v[i + j * nrow]);
4137 }
4138 fprintf(fp, "\n");
4139 }
4140 fclose(fp);
4141 }
4142 else {
4143 fprintf(stderr,
4144 "%s %d : fail to open %s\n",
4145 __FILE__, __LINE__, fname.c_str());
4146 }
4147 }
4148
4149 template
4150 void dump_vectors<complex<double> >(int nrow, int nn0, complex<double> *v,
4151 string fname);
4152 template
4153 void dump_vectors<quadruple>(int nrow, int nn0, quadruple *v,
4154 string fname);
4155
4156 template
4157 void dump_vectors<complex<quadruple> >(int nrow, int nn0, complex<quadruple> *v,
4158 string fname);
4159
4160 template
4161 void dump_vectors<float>(int nrow, int nn0, float *v,
4162 string fname);
4163
4164 template
4165 void dump_vectors<complex<float> >(int nrow, int nn0, complex<float> *v,
4166 string fname);
4167
4168 //