forked from xiaoyeli/superlu_dist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpzgstrs.c
2479 lines (2139 loc) · 69.9 KB
/
pzgstrs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! \file
Copyright (c) 2003, The Regents of the University of California, through
Lawrence Berkeley National Laboratory (subject to receipt of any required
approvals from U.S. Dept. of Energy)
All rights reserved.
The source code is distributed under BSD license, see the file License.txt
at the top-level directory.
*/
/*! @file
* \brief Solves a system of distributed linear equations A*X = B with a
* general N-by-N matrix A using the LU factors computed previously.
*
* <pre>
* -- Distributed SuperLU routine (version 6.1) --
* Lawrence Berkeley National Lab, Univ. of California Berkeley.
* October 15, 2008
* September 18, 2018 version 6.0
* February 8, 2019 version 6.1.1
* </pre>
*/
#include <math.h>
#include "superlu_zdefs.h"
#ifndef CACHELINE
#define CACHELINE 64 /* bytes, Xeon Phi KNL, Cori haswell, Edision */
#endif
/*
* Sketch of the algorithm for L-solve:
* =======================
*
* Self-scheduling loop:
*
* while ( not finished ) { .. use message counter to control
*
* reveive a message;
*
* if ( message is Xk ) {
* perform local block modifications into lsum[];
* lsum[i] -= L_i,k * X[k]
* if all local updates done, Isend lsum[] to diagonal process;
*
* } else if ( message is LSUM ) { .. this must be a diagonal process
* accumulate LSUM;
* if ( all LSUM are received ) {
* perform triangular solve for Xi;
* Isend Xi down to the current process column;
* perform local block modifications into lsum[];
* }
* }
* }
*
*
* Auxiliary data structures: lsum[] / ilsum (pointer to lsum array)
* =======================
*
* lsum[] array (local)
* + lsum has "nrhs" columns, row-wise is partitioned by supernodes
* + stored by row blocks, column wise storage within a row block
* + prepend a header recording the global block number.
*
* lsum[] ilsum[nsupers + 1]
*
* -----
* | | | <- header of size 2 ---
* --------- <--------------------| |
* | | | | | ---
* | | | | | |-----------| |
* | | | | | | ---
* --------- | |-------| |
* | | | <- header | | ---
* --------- <--------| | |----| |
* | | | | | | | ---
* | | | | | | |
* | | | | | | |
* --------- | |
* | | | <- header | |
* --------- <------------| |
* | | | | | |
* | | | | | |
* | | | | | |
* --------- <---------------|
*/
/*#define ISEND_IRECV*/
/*
* Function prototypes
*/
#ifdef _CRAY
fortran void CTRSM(_fcd, _fcd, _fcd, _fcd, int*, int*, doublecomplex*,
doublecomplex*, int*, doublecomplex*, int*);
_fcd ftcs1;
_fcd ftcs2;
_fcd ftcs3;
#endif
/*! \brief
*
* <pre>
* Purpose
* =======
* Re-distribute B on the diagonal processes of the 2D process mesh.
*
* Note
* ====
* This routine can only be called after the routine pxgstrs_init(),
* in which the structures of the send and receive buffers are set up.
*
* Arguments
* =========
*
* B (input) doublecomplex*
* The distributed right-hand side matrix of the possibly
* equilibrated system.
*
* m_loc (input) int (local)
* The local row dimension of matrix B.
*
* nrhs (input) int (global)
* Number of right-hand sides.
*
* ldb (input) int (local)
* Leading dimension of matrix B.
*
* fst_row (input) int (global)
* The row number of B's first row in the global matrix.
*
* ilsum (input) int* (global)
* Starting position of each supernode in a full array.
*
* x (output) doublecomplex*
* The solution vector. It is valid only on the diagonal processes.
*
* ScalePermstruct (input) ScalePermstruct_t*
* The data structure to store the scaling and permutation vectors
* describing the transformations performed to the original matrix A.
*
* grid (input) gridinfo_t*
* The 2D process mesh.
*
* SOLVEstruct (input) SOLVEstruct_t*
* Contains the information for the communication during the
* solution phase.
*
* Return value
* ============
* </pre>
*/
int_t
pzReDistribute_B_to_X(doublecomplex *B, int_t m_loc, int nrhs, int_t ldb,
int_t fst_row, int_t *ilsum, doublecomplex *x,
ScalePermstruct_t *ScalePermstruct,
Glu_persist_t *Glu_persist,
gridinfo_t *grid, SOLVEstruct_t *SOLVEstruct)
{
int *SendCnt, *SendCnt_nrhs, *RecvCnt, *RecvCnt_nrhs;
int *sdispls, *sdispls_nrhs, *rdispls, *rdispls_nrhs;
int *ptr_to_ibuf, *ptr_to_dbuf;
int_t *perm_r, *perm_c; /* row and column permutation vectors */
int_t *send_ibuf, *recv_ibuf;
doublecomplex *send_dbuf, *recv_dbuf;
int_t *xsup, *supno;
int_t i, ii, irow, gbi, j, jj, k, knsupc, l, lk, nbrow;
int p, procs;
pxgstrs_comm_t *gstrs_comm = SOLVEstruct->gstrs_comm;
MPI_Request req_i, req_d, *req_send, *req_recv;
MPI_Status status, *status_send, *status_recv;
int Nreq_recv, Nreq_send, pp, pps, ppr;
double t;
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(grid->iam, "Enter pzReDistribute_B_to_X()");
#endif
/* ------------------------------------------------------------
INITIALIZATION.
------------------------------------------------------------*/
perm_r = ScalePermstruct->perm_r;
perm_c = ScalePermstruct->perm_c;
procs = grid->nprow * grid->npcol;
xsup = Glu_persist->xsup;
supno = Glu_persist->supno;
SendCnt = gstrs_comm->B_to_X_SendCnt;
SendCnt_nrhs = gstrs_comm->B_to_X_SendCnt + procs;
RecvCnt = gstrs_comm->B_to_X_SendCnt + 2*procs;
RecvCnt_nrhs = gstrs_comm->B_to_X_SendCnt + 3*procs;
sdispls = gstrs_comm->B_to_X_SendCnt + 4*procs;
sdispls_nrhs = gstrs_comm->B_to_X_SendCnt + 5*procs;
rdispls = gstrs_comm->B_to_X_SendCnt + 6*procs;
rdispls_nrhs = gstrs_comm->B_to_X_SendCnt + 7*procs;
ptr_to_ibuf = gstrs_comm->ptr_to_ibuf;
ptr_to_dbuf = gstrs_comm->ptr_to_dbuf;
/* ------------------------------------------------------------
NOW COMMUNICATE THE ACTUAL DATA.
------------------------------------------------------------*/
if(procs==1){ // faster memory copy when procs=1
#ifdef _OPENMP
#pragma omp parallel default (shared)
#endif
{
#ifdef _OPENMP
#pragma omp master
#endif
{
// t = SuperLU_timer_();
#ifdef _OPENMP
#pragma omp taskloop private (i,l,irow,k,j,knsupc) untied
#endif
for (i = 0; i < m_loc; ++i) {
irow = perm_c[perm_r[i+fst_row]]; /* Row number in Pc*Pr*B */
k = BlockNum( irow );
knsupc = SuperSize( k );
l = X_BLK( k );
x[l - XK_H].r = k; /* Block number prepended in the header. */
x[l - XK_H].i = 0;
irow = irow - FstBlockC(k); /* Relative row number in X-block */
RHS_ITERATE(j) {
x[l + irow + j*knsupc] = B[i + j*ldb];
}
}
}
}
}else{
k = sdispls[procs-1] + SendCnt[procs-1]; /* Total number of sends */
l = rdispls[procs-1] + RecvCnt[procs-1]; /* Total number of receives */
if ( !(send_ibuf = intMalloc_dist(k + l)) )
ABORT("Malloc fails for send_ibuf[].");
recv_ibuf = send_ibuf + k;
if ( !(send_dbuf = doublecomplexMalloc_dist((k + l)* (size_t)nrhs)) )
ABORT("Malloc fails for send_dbuf[].");
recv_dbuf = send_dbuf + k * nrhs;
if ( !(req_send = (MPI_Request*) SUPERLU_MALLOC(procs*sizeof(MPI_Request))) )
ABORT("Malloc fails for req_send[].");
if ( !(req_recv = (MPI_Request*) SUPERLU_MALLOC(procs*sizeof(MPI_Request))) )
ABORT("Malloc fails for req_recv[].");
if ( !(status_send = (MPI_Status*) SUPERLU_MALLOC(procs*sizeof(MPI_Status))) )
ABORT("Malloc fails for status_send[].");
if ( !(status_recv = (MPI_Status*) SUPERLU_MALLOC(procs*sizeof(MPI_Status))) )
ABORT("Malloc fails for status_recv[].");
for (p = 0; p < procs; ++p) {
ptr_to_ibuf[p] = sdispls[p];
ptr_to_dbuf[p] = sdispls[p] * nrhs;
}
/* Copy the row indices and values to the send buffer. */
// t = SuperLU_timer_();
for (i = 0, l = fst_row; i < m_loc; ++i, ++l) {
irow = perm_c[perm_r[l]]; /* Row number in Pc*Pr*B */
gbi = BlockNum( irow );
p = PNUM( PROW(gbi,grid), PCOL(gbi,grid), grid ); /* Diagonal process */
k = ptr_to_ibuf[p];
send_ibuf[k] = irow;
++ptr_to_ibuf[p];
k = ptr_to_dbuf[p];
RHS_ITERATE(j) { /* RHS is stored in row major in the buffer. */
send_dbuf[k++] = B[i + j*ldb];
}
ptr_to_dbuf[p] += nrhs;
}
// t = SuperLU_timer_() - t;
// printf(".. copy to send buffer time\t%8.4f\n", t);
#if 0
#if 1
/* Communicate the (permuted) row indices. */
MPI_Alltoallv(send_ibuf, SendCnt, sdispls, mpi_int_t,
recv_ibuf, RecvCnt, rdispls, mpi_int_t, grid->comm);
/* Communicate the numerical values. */
MPI_Alltoallv(send_dbuf, SendCnt_nrhs, sdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
recv_dbuf, RecvCnt_nrhs, rdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
grid->comm);
#else
/* Communicate the (permuted) row indices. */
MPI_Ialltoallv(send_ibuf, SendCnt, sdispls, mpi_int_t,
recv_ibuf, RecvCnt, rdispls, mpi_int_t, grid->comm, &req_i);
/* Communicate the numerical values. */
MPI_Ialltoallv(send_dbuf, SendCnt_nrhs, sdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
recv_dbuf, RecvCnt_nrhs, rdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
grid->comm, &req_d);
MPI_Wait(&req_i,&status);
MPI_Wait(&req_d,&status);
#endif
#endif
MPI_Barrier( grid->comm );
Nreq_send=0;
Nreq_recv=0;
for (pp=0;pp<procs;pp++){
pps = grid->iam+1+pp;
if(pps>=procs)pps-=procs;
if(pps<0)pps+=procs;
ppr = grid->iam-1+pp;
if(ppr>=procs)ppr-=procs;
if(ppr<0)ppr+=procs;
if(SendCnt[pps]>0){
MPI_Isend(&send_ibuf[sdispls[pps]], SendCnt[pps], mpi_int_t, pps, 0, grid->comm,
&req_send[Nreq_send] );
Nreq_send++;
}
if(RecvCnt[ppr]>0){
MPI_Irecv(&recv_ibuf[rdispls[ppr]], RecvCnt[ppr], mpi_int_t, ppr, 0, grid->comm,
&req_recv[Nreq_recv] );
Nreq_recv++;
}
}
if(Nreq_send>0)MPI_Waitall(Nreq_send,req_send,status_send);
if(Nreq_recv>0)MPI_Waitall(Nreq_recv,req_recv,status_recv);
Nreq_send=0;
Nreq_recv=0;
for (pp=0;pp<procs;pp++){
pps = grid->iam+1+pp;
if(pps>=procs)pps-=procs;
if(pps<0)pps+=procs;
ppr = grid->iam-1+pp;
if(ppr>=procs)ppr-=procs;
if(ppr<0)ppr+=procs;
if(SendCnt_nrhs[pps]>0){
MPI_Isend(&send_dbuf[sdispls_nrhs[pps]], SendCnt_nrhs[pps], SuperLU_MPI_DOUBLE_COMPLEX, pps, 1, grid->comm,
&req_send[Nreq_send] );
Nreq_send++;
}
if(RecvCnt_nrhs[ppr]>0){
MPI_Irecv(&recv_dbuf[rdispls_nrhs[ppr]], RecvCnt_nrhs[ppr], SuperLU_MPI_DOUBLE_COMPLEX, ppr, 1, grid->comm,
&req_recv[Nreq_recv] );
Nreq_recv++;
}
}
if(Nreq_send>0)MPI_Waitall(Nreq_send,req_send,status_send);
if(Nreq_recv>0)MPI_Waitall(Nreq_recv,req_recv,status_recv);
/* ------------------------------------------------------------
Copy buffer into X on the diagonal processes.
------------------------------------------------------------*/
// t = SuperLU_timer_();
ii = 0;
for (p = 0; p < procs; ++p) {
jj = rdispls_nrhs[p];
for (i = 0; i < RecvCnt[p]; ++i) {
/* Only the diagonal processes do this; the off-diagonal processes
have 0 RecvCnt. */
irow = recv_ibuf[ii]; /* The permuted row index. */
k = BlockNum( irow );
knsupc = SuperSize( k );
lk = LBi( k, grid ); /* Local block number. */
l = X_BLK( lk );
x[l - XK_H].r = k; /* Block number prepended in the header. */
x[l - XK_H].i = 0;
irow = irow - FstBlockC(k); /* Relative row number in X-block */
RHS_ITERATE(j) {
x[l + irow + j*knsupc] = recv_dbuf[jj++];
}
++ii;
}
}
// t = SuperLU_timer_() - t;
// printf(".. copy to x time\t%8.4f\n", t);
SUPERLU_FREE(send_ibuf);
SUPERLU_FREE(send_dbuf);
SUPERLU_FREE(req_send);
SUPERLU_FREE(req_recv);
SUPERLU_FREE(status_send);
SUPERLU_FREE(status_recv);
}
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(grid->iam, "Exit pzReDistribute_B_to_X()");
#endif
return 0;
} /* pzReDistribute_B_to_X */
/*! \brief
*
* <pre>
* Purpose
* =======
* Re-distribute X on the diagonal processes to B distributed on all
* the processes.
*
* Note
* ====
* This routine can only be called after the routine pxgstrs_init(),
* in which the structures of the send and receive buffers are set up.
* </pre>
*/
int_t
pzReDistribute_X_to_B(int_t n, doublecomplex *B, int_t m_loc, int_t ldb, int_t fst_row,
int_t nrhs, doublecomplex *x, int_t *ilsum,
ScalePermstruct_t *ScalePermstruct,
Glu_persist_t *Glu_persist, gridinfo_t *grid,
SOLVEstruct_t *SOLVEstruct)
{
int_t i, ii, irow, j, jj, k, knsupc, nsupers, l, lk;
int_t *xsup, *supno;
int *SendCnt, *SendCnt_nrhs, *RecvCnt, *RecvCnt_nrhs;
int *sdispls, *rdispls, *sdispls_nrhs, *rdispls_nrhs;
int *ptr_to_ibuf, *ptr_to_dbuf;
int_t *send_ibuf, *recv_ibuf;
doublecomplex *send_dbuf, *recv_dbuf;
int_t *row_to_proc = SOLVEstruct->row_to_proc; /* row-process mapping */
pxgstrs_comm_t *gstrs_comm = SOLVEstruct->gstrs_comm;
int iam, p, q, pkk, procs;
int_t num_diag_procs, *diag_procs;
MPI_Request req_i, req_d, *req_send, *req_recv;
MPI_Status status, *status_send, *status_recv;
int Nreq_recv, Nreq_send, pp,pps,ppr;
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(grid->iam, "Enter pzReDistribute_X_to_B()");
#endif
/* ------------------------------------------------------------
INITIALIZATION.
------------------------------------------------------------*/
xsup = Glu_persist->xsup;
supno = Glu_persist->supno;
nsupers = Glu_persist->supno[n-1] + 1;
iam = grid->iam;
procs = grid->nprow * grid->npcol;
SendCnt = gstrs_comm->X_to_B_SendCnt;
SendCnt_nrhs = gstrs_comm->X_to_B_SendCnt + procs;
RecvCnt = gstrs_comm->X_to_B_SendCnt + 2*procs;
RecvCnt_nrhs = gstrs_comm->X_to_B_SendCnt + 3*procs;
sdispls = gstrs_comm->X_to_B_SendCnt + 4*procs;
sdispls_nrhs = gstrs_comm->X_to_B_SendCnt + 5*procs;
rdispls = gstrs_comm->X_to_B_SendCnt + 6*procs;
rdispls_nrhs = gstrs_comm->X_to_B_SendCnt + 7*procs;
ptr_to_ibuf = gstrs_comm->ptr_to_ibuf;
ptr_to_dbuf = gstrs_comm->ptr_to_dbuf;
if(procs==1){ //faster memory copy when procs=1
#ifdef _OPENMP
#pragma omp parallel default (shared)
#endif
{
#ifdef _OPENMP
#pragma omp master
#endif
{
// t = SuperLU_timer_();
#ifdef _OPENMP
#pragma omp taskloop private (k,knsupc,lk,irow,l,i,j) untied
#endif
for (k = 0; k < nsupers; k++) {
knsupc = SuperSize( k );
lk = LBi( k, grid ); /* Local block number */
irow = FstBlockC( k );
l = X_BLK( lk );
for (i = 0; i < knsupc; ++i) {
RHS_ITERATE(j) { /* RHS is stored in row major in the buffer. */
B[irow-fst_row +i + j*ldb] = x[l + i + j*knsupc];
}
}
}
}
}
}else{
k = sdispls[procs-1] + SendCnt[procs-1]; /* Total number of sends */
l = rdispls[procs-1] + RecvCnt[procs-1]; /* Total number of receives */
if ( !(send_ibuf = intMalloc_dist(k + l)) )
ABORT("Malloc fails for send_ibuf[].");
recv_ibuf = send_ibuf + k;
if ( !(send_dbuf = doublecomplexMalloc_dist((k + l)*nrhs)) )
ABORT("Malloc fails for send_dbuf[].");
if ( !(req_send = (MPI_Request*) SUPERLU_MALLOC(procs*sizeof(MPI_Request))) )
ABORT("Malloc fails for req_send[].");
if ( !(req_recv = (MPI_Request*) SUPERLU_MALLOC(procs*sizeof(MPI_Request))) )
ABORT("Malloc fails for req_recv[].");
if ( !(status_send = (MPI_Status*) SUPERLU_MALLOC(procs*sizeof(MPI_Status))) )
ABORT("Malloc fails for status_send[].");
if ( !(status_recv = (MPI_Status*) SUPERLU_MALLOC(procs*sizeof(MPI_Status))) )
ABORT("Malloc fails for status_recv[].");
recv_dbuf = send_dbuf + k * nrhs;
for (p = 0; p < procs; ++p) {
ptr_to_ibuf[p] = sdispls[p];
ptr_to_dbuf[p] = sdispls_nrhs[p];
}
num_diag_procs = SOLVEstruct->num_diag_procs;
diag_procs = SOLVEstruct->diag_procs;
for (p = 0; p < num_diag_procs; ++p) { /* For all diagonal processes. */
pkk = diag_procs[p];
if ( iam == pkk ) {
for (k = p; k < nsupers; k += num_diag_procs) {
knsupc = SuperSize( k );
lk = LBi( k, grid ); /* Local block number */
irow = FstBlockC( k );
l = X_BLK( lk );
for (i = 0; i < knsupc; ++i) {
#if 0
ii = inv_perm_c[irow]; /* Apply X <== Pc'*Y */
#else
ii = irow;
#endif
q = row_to_proc[ii];
jj = ptr_to_ibuf[q];
send_ibuf[jj] = ii;
jj = ptr_to_dbuf[q];
RHS_ITERATE(j) { /* RHS stored in row major in buffer. */
send_dbuf[jj++] = x[l + i + j*knsupc];
}
++ptr_to_ibuf[q];
ptr_to_dbuf[q] += nrhs;
++irow;
}
}
}
}
/* ------------------------------------------------------------
COMMUNICATE THE (PERMUTED) ROW INDICES AND NUMERICAL VALUES.
------------------------------------------------------------*/
#if 0
#if 1
MPI_Alltoallv(send_ibuf, SendCnt, sdispls, mpi_int_t,
recv_ibuf, RecvCnt, rdispls, mpi_int_t, grid->comm);
MPI_Alltoallv(send_dbuf, SendCnt_nrhs, sdispls_nrhs,SuperLU_MPI_DOUBLE_COMPLEX,
recv_dbuf, RecvCnt_nrhs, rdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
grid->comm);
#else
MPI_Ialltoallv(send_ibuf, SendCnt, sdispls, mpi_int_t,
recv_ibuf, RecvCnt, rdispls, mpi_int_t, grid->comm,&req_i);
MPI_Ialltoallv(send_dbuf, SendCnt_nrhs, sdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
recv_dbuf, RecvCnt_nrhs, rdispls_nrhs, SuperLU_MPI_DOUBLE_COMPLEX,
grid->comm,&req_d);
MPI_Wait(&req_i,&status);
MPI_Wait(&req_d,&status);
#endif
#endif
MPI_Barrier( grid->comm );
Nreq_send=0;
Nreq_recv=0;
for (pp=0;pp<procs;pp++){
pps = grid->iam+1+pp;
if(pps>=procs)pps-=procs;
if(pps<0)pps+=procs;
ppr = grid->iam-1+pp;
if(ppr>=procs)ppr-=procs;
if(ppr<0)ppr+=procs;
if(SendCnt[pps]>0){
MPI_Isend(&send_ibuf[sdispls[pps]], SendCnt[pps], mpi_int_t, pps, 0, grid->comm,
&req_send[Nreq_send] );
Nreq_send++;
}
if(RecvCnt[ppr]>0){
MPI_Irecv(&recv_ibuf[rdispls[ppr]], RecvCnt[ppr], mpi_int_t, ppr, 0, grid->comm,
&req_recv[Nreq_recv] );
Nreq_recv++;
}
}
if(Nreq_send>0)MPI_Waitall(Nreq_send,req_send,status_send);
if(Nreq_recv>0)MPI_Waitall(Nreq_recv,req_recv,status_recv);
// MPI_Barrier( grid->comm );
Nreq_send=0;
Nreq_recv=0;
for (pp=0;pp<procs;pp++){
pps = grid->iam+1+pp;
if(pps>=procs)pps-=procs;
if(pps<0)pps+=procs;
ppr = grid->iam-1+pp;
if(ppr>=procs)ppr-=procs;
if(ppr<0)ppr+=procs;
if(SendCnt_nrhs[pps]>0){
MPI_Isend(&send_dbuf[sdispls_nrhs[pps]], SendCnt_nrhs[pps], SuperLU_MPI_DOUBLE_COMPLEX, pps, 1, grid->comm,
&req_send[Nreq_send] );
Nreq_send++;
}
if(RecvCnt_nrhs[ppr]>0){
MPI_Irecv(&recv_dbuf[rdispls_nrhs[ppr]], RecvCnt_nrhs[ppr], SuperLU_MPI_DOUBLE_COMPLEX, ppr, 1, grid->comm,
&req_recv[Nreq_recv] );
Nreq_recv++;
}
}
if(Nreq_send>0)MPI_Waitall(Nreq_send,req_send,status_send);
if(Nreq_recv>0)MPI_Waitall(Nreq_recv,req_recv,status_recv);
// MPI_Barrier( grid->comm );
/* ------------------------------------------------------------
COPY THE BUFFER INTO B.
------------------------------------------------------------*/
for (i = 0, k = 0; i < m_loc; ++i) {
irow = recv_ibuf[i];
irow -= fst_row; /* Relative row number */
RHS_ITERATE(j) { /* RHS is stored in row major in the buffer. */
B[irow + j*ldb] = recv_dbuf[k++];
}
}
SUPERLU_FREE(send_ibuf);
SUPERLU_FREE(send_dbuf);
SUPERLU_FREE(req_send);
SUPERLU_FREE(req_recv);
SUPERLU_FREE(status_send);
SUPERLU_FREE(status_recv);
}
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(grid->iam, "Exit pzReDistribute_X_to_B()");
#endif
return 0;
} /* pzReDistribute_X_to_B */
/*! \brief
*
* <pre>
* Purpose
* =======
* Compute the inverse of the diagonal blocks of the L and U
* triangular matrices.
* </pre>
*/
void
pzCompute_Diag_Inv(int_t n, LUstruct_t *LUstruct,gridinfo_t *grid,
SuperLUStat_t *stat, int *info)
{
#ifdef SLU_HAVE_LAPACK
Glu_persist_t *Glu_persist = LUstruct->Glu_persist;
LocalLU_t *Llu = LUstruct->Llu;
doublecomplex *lusup;
doublecomplex *recvbuf, *tempv;
doublecomplex *Linv;/* Inverse of diagonal block */
doublecomplex *Uinv;/* Inverse of diagonal block */
int_t kcol, krow, mycol, myrow;
int_t i, ii, il, j, jj, k, lb, ljb, lk, lptr, luptr;
int_t nb, nlb,nlb_nodiag, nub, nsupers;
int_t *xsup, *supno, *lsub, *usub;
int_t *ilsum; /* Starting position of each supernode in lsum (LOCAL)*/
int Pc, Pr, iam;
int knsupc, nsupr;
int ldalsum; /* Number of lsum entries locally owned. */
int maxrecvsz, p, pi;
int_t **Lrowind_bc_ptr;
doublecomplex **Lnzval_bc_ptr;
doublecomplex **Linv_bc_ptr;
doublecomplex **Uinv_bc_ptr;
int INFO;
double t;
doublecomplex one = {1.0, 0.0};
doublecomplex zero = {0.0, 0.0};
#if ( PROFlevel>=1 )
t = SuperLU_timer_();
#endif
#if ( PRNTlevel>=2 )
if ( grid->iam==0 ) {
printf("computing inverse of diagonal blocks...\n");
fflush(stdout);
}
#endif
/*
* Initialization.
*/
iam = grid->iam;
Pc = grid->npcol;
Pr = grid->nprow;
myrow = MYROW( iam, grid );
mycol = MYCOL( iam, grid );
xsup = Glu_persist->xsup;
supno = Glu_persist->supno;
nsupers = supno[n-1] + 1;
Lrowind_bc_ptr = Llu->Lrowind_bc_ptr;
Linv_bc_ptr = Llu->Linv_bc_ptr;
Uinv_bc_ptr = Llu->Uinv_bc_ptr;
Lnzval_bc_ptr = Llu->Lnzval_bc_ptr;
nlb = CEILING( nsupers, Pr ); /* Number of local block rows. */
Llu->inv = 1;
/*---------------------------------------------------
* Compute inverse of L(lk,lk).
*---------------------------------------------------*/
for (k = 0; k < nsupers; ++k) {
krow = PROW( k, grid );
if ( myrow == krow ) {
lk = LBi( k, grid ); /* local block number */
kcol = PCOL( k, grid );
if ( mycol == kcol ) { /* diagonal process */
lk = LBj( k, grid ); /* Local block number, column-wise. */
lsub = Lrowind_bc_ptr[lk];
lusup = Lnzval_bc_ptr[lk];
Linv = Linv_bc_ptr[lk];
Uinv = Uinv_bc_ptr[lk];
nsupr = lsub[1];
knsupc = SuperSize( k );
for (j=0 ; j<knsupc; j++){
for (i=0 ; i<knsupc; i++){
Linv[j*knsupc+i] = zero;
Uinv[j*knsupc+i] = zero;
}
}
for (j=0 ; j<knsupc; j++){
Linv[j*knsupc+j] = one;
for (i=j+1 ; i<knsupc; i++){
z_copy(&Linv[j*knsupc+i],&lusup[j*nsupr+i]);
}
for (i=0 ; i<j+1; i++){
z_copy(&Uinv[j*knsupc+i],&lusup[j*nsupr+i]);
}
}
/* Triangular inversion */
ztrtri_("L","U",&knsupc,Linv,&knsupc,&INFO);
ztrtri_("U","N",&knsupc,Uinv,&knsupc,&INFO);
} /* end if (mycol === kcol) */
} /* end if (myrow === krow) */
} /* end fo k = ... nsupers */
#if ( PROFlevel>=1 )
if( grid->iam==0 ) {
t = SuperLU_timer_() - t;
printf(".. L-diag_inv time\t%10.5f\n", t);
fflush(stdout);
}
#endif
return;
#endif /* SLU_HAVE_LAPACK */
}
/*! \brief
*
* <pre>
* Purpose
* =======
*
* PZGSTRS solves a system of distributed linear equations
* A*X = B with a general N-by-N matrix A using the LU factorization
* computed by PZGSTRF.
* If the equilibration, and row and column permutations were performed,
* the LU factorization was performed for A1 where
* A1 = Pc*Pr*diag(R)*A*diag(C)*Pc^T = L*U
* and the linear system solved is
* A1 * Y = Pc*Pr*B1, where B was overwritten by B1 = diag(R)*B, and
* the permutation to B1 by Pc*Pr is applied internally in this routine.
*
* Arguments
* =========
*
* n (input) int (global)
* The order of the system of linear equations.
*
* LUstruct (input) LUstruct_t*
* The distributed data structures storing L and U factors.
* The L and U factors are obtained from PZGSTRF for
* the possibly scaled and permuted matrix A.
* See superlu_zdefs.h for the definition of 'LUstruct_t'.
* A may be scaled and permuted into A1, so that
* A1 = Pc*Pr*diag(R)*A*diag(C)*Pc^T = L*U
*
* grid (input) gridinfo_t*
* The 2D process mesh. It contains the MPI communicator, the number
* of process rows (NPROW), the number of process columns (NPCOL),
* and my process rank. It is an input argument to all the
* parallel routines.
* Grid can be initialized by subroutine SUPERLU_GRIDINIT.
* See superlu_defs.h for the definition of 'gridinfo_t'.
*
* B (input/output) doublecomplex*
* On entry, the distributed right-hand side matrix of the possibly
* equilibrated system. That is, B may be overwritten by diag(R)*B.
* On exit, the distributed solution matrix Y of the possibly
* equilibrated system if info = 0, where Y = Pc*diag(C)^(-1)*X,
* and X is the solution of the original system.
*
* m_loc (input) int (local)
* The local row dimension of matrix B.
*
* fst_row (input) int (global)
* The row number of B's first row in the global matrix.
*
* ldb (input) int (local)
* The leading dimension of matrix B.
*
* nrhs (input) int (global)
* Number of right-hand sides.
*
* SOLVEstruct (input) SOLVEstruct_t* (global)
* Contains the information for the communication during the
* solution phase.
*
* stat (output) SuperLUStat_t*
* Record the statistics about the triangular solves.
* See util.h for the definition of 'SuperLUStat_t'.
*
* info (output) int*
* = 0: successful exit
* < 0: if info = -i, the i-th argument had an illegal value
* </pre>
*/
void
pzgstrs(int_t n, LUstruct_t *LUstruct,
ScalePermstruct_t *ScalePermstruct,
gridinfo_t *grid, doublecomplex *B,
int_t m_loc, int_t fst_row, int_t ldb, int nrhs,
SOLVEstruct_t *SOLVEstruct,
SuperLUStat_t *stat, int *info)
{
Glu_persist_t *Glu_persist = LUstruct->Glu_persist;
LocalLU_t *Llu = LUstruct->Llu;
doublecomplex alpha = {1.0, 0.0};
doublecomplex beta = {0.0, 0.0};
doublecomplex zero = {0.0, 0.0};
doublecomplex *lsum; /* Local running sum of the updates to B-components */
doublecomplex *x; /* X component at step k. */
/* NOTE: x and lsum are of same size. */
doublecomplex *lusup, *dest;
doublecomplex *recvbuf, *recvbuf_on, *tempv,
*recvbufall, *recvbuf_BC_fwd, *recvbuf0, *xin;
doublecomplex *rtemp, *rtemp_loc; /* Result of full matrix-vector multiply. */
doublecomplex *Linv; /* Inverse of diagonal block */
doublecomplex *Uinv; /* Inverse of diagonal block */
int *ipiv;
int_t *leaf_send;
int_t nleaf_send, nleaf_send_tmp;
int_t *root_send;
int_t nroot_send, nroot_send_tmp;
int_t **Ufstnz_br_ptr = Llu->Ufstnz_br_ptr;
/*-- Data structures used for broadcast and reduction trees. --*/
BcTree *LBtree_ptr = Llu->LBtree_ptr;
RdTree *LRtree_ptr = Llu->LRtree_ptr;
BcTree *UBtree_ptr = Llu->UBtree_ptr;
RdTree *URtree_ptr = Llu->URtree_ptr;
int_t *Urbs1; /* Number of row blocks in each block column of U. */
int_t *Urbs = Llu->Urbs; /* Number of row blocks in each block column of U. */
Ucb_indptr_t **Ucb_indptr = Llu->Ucb_indptr;/* Vertical linked list pointing to Uindex[] */
int_t **Ucb_valptr = Llu->Ucb_valptr; /* Vertical linked list pointing to Unzval[] */
int_t kcol, krow, mycol, myrow;
int_t i, ii, il, j, jj, k, kk, lb, ljb, lk, lib, lptr, luptr, gb, nn;
int_t nb, nlb,nlb_nodiag, nub, nsupers, nsupers_j, nsupers_i,maxsuper;
int_t *xsup, *supno, *lsub, *usub;
int_t *ilsum; /* Starting position of each supernode in lsum (LOCAL)*/
int Pc, Pr, iam;
int knsupc, nsupr, nprobe;
int nbtree, nrtree, outcount;
int ldalsum; /* Number of lsum entries locally owned. */
int maxrecvsz, p, pi;
int_t **Lrowind_bc_ptr;
doublecomplex **Lnzval_bc_ptr;
doublecomplex **Linv_bc_ptr;
doublecomplex **Uinv_bc_ptr;
doublecomplex sum;
MPI_Status status,status_on,statusx,statuslsum;
pxgstrs_comm_t *gstrs_comm = SOLVEstruct->gstrs_comm;
SuperLUStat_t **stat_loc;
double tmax;
/*-- Counts used for L-solve --*/
int_t *fmod; /* Modification count for L-solve --
Count the number of local block products to
be summed into lsum[lk]. */
int_t fmod_tmp;
int_t **fsendx_plist = Llu->fsendx_plist;
int_t nfrecvx = Llu->nfrecvx; /* Number of X components to be recv'd. */
int_t nfrecvx_buf=0;
int_t *frecv; /* Count of lsum[lk] contributions to be received
from processes in this row.
It is only valid on the diagonal processes. */
int_t frecv_tmp;
int_t nfrecvmod = 0; /* Count of total modifications to be recv'd. */
int_t nfrecv = 0; /* Count of total messages to be recv'd. */
int_t nbrecv = 0; /* Count of total messages to be recv'd. */
int_t nleaf = 0, nroot = 0;
int_t nleaftmp = 0, nroottmp = 0;
int_t msgsize;
/*-- Counts used for U-solve --*/
int_t *bmod; /* Modification count for U-solve. */
int_t bmod_tmp;
int_t **bsendx_plist = Llu->bsendx_plist;
int_t nbrecvx = Llu->nbrecvx; /* Number of X components to be recv'd. */
int_t nbrecvx_buf=0;
int_t *brecv; /* Count of modifications to be recv'd from
processes in this row. */
int_t nbrecvmod = 0; /* Count of total modifications to be recv'd. */
int_t flagx,flaglsum,flag;
int_t *LBTree_active, *LRTree_active, *LBTree_finish, *LRTree_finish, *leafsups, *rootsups;
int_t TAG;
double t1_sol, t2_sol, t;
#if ( DEBUGlevel>=2 )
int_t Ublocks = 0;
#endif
int_t gik,iklrow,fnz;
int_t *mod_bit = Llu->mod_bit; /* flag contribution from each row block */
int INFO, pad;
int_t tmpresult;
// #if ( PROFlevel>=1 )
double t1, t2;
float msg_vol = 0, msg_cnt = 0;
// #endif
int_t msgcnt[4]; /* Count the size of the message xfer'd in each buffer:
* 0 : transferred in Lsub_buf[]
* 1 : transferred in Lval_buf[]
* 2 : transferred in Usub_buf[]
* 3 : transferred in Uval_buf[]
*/
int iword = sizeof (int_t);
int dword = sizeof (double);
int Nwork;
int_t procs = grid->nprow * grid->npcol;
yes_no_t done;
yes_no_t startforward;
int nbrow;
int_t ik, rel, idx_r, jb, nrbl, irow, pc,iknsupc;
int_t lptr1_tmp, idx_i, idx_v,m;
int_t ready;
static int thread_id;
yes_no_t empty;
int_t sizelsum,sizertemp,aln_d,aln_i;
aln_d = ceil(CACHELINE/(double)dword);
aln_i = ceil(CACHELINE/(double)iword);
int num_thread = 1;
maxsuper = sp_ienv_dist(3);
#ifdef _OPENMP
#pragma omp threadprivate(thread_id)
#endif
#ifdef _OPENMP
#pragma omp parallel default(shared)
{
if (omp_get_thread_num () == 0) {
num_thread = omp_get_num_threads ();
}
thread_id = omp_get_thread_num ();
}
#endif
#if ( PRNTlevel>=1 )
if( grid->iam==0 ) {
printf("num_thread: %5d\n", num_thread);
fflush(stdout);
}
#endif
MPI_Barrier( grid->comm );
t1_sol = SuperLU_timer_();
t = SuperLU_timer_();
/* Test input parameters. */
*info = 0;
if ( n < 0 ) *info = -1;
else if ( nrhs < 0 ) *info = -9;
if ( *info ) {
pxerr_dist("PZGSTRS", grid, -*info);
return;