3
4
5
6
7
8
9
10
11
12 INTEGER INFO, JA, LAF, LWORK, N
13
14
15 INTEGER DESCA( * )
16 COMPLEX AF( * ), E( * ), WORK( * )
17 REAL D( * )
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 REAL ONE, ZERO
355 parameter( one = 1.0e+0 )
356 parameter( zero = 0.0e+0 )
357 COMPLEX CONE, CZERO
358 parameter( cone = ( 1.0e+0, 0.0e+0 ) )
359 parameter( czero = ( 0.0e+0, 0.0e+0 ) )
360 INTEGER INT_ONE
361 parameter( int_one = 1 )
362 INTEGER DESCMULT, BIGNUM
363 parameter(descmult = 100, bignum = descmult * descmult)
364 INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
365 $ LLD_, MB_, M_, NB_, N_, RSRC_
366 parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
367 $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
368 $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
369
370
371 INTEGER COMM_PROC, CSRC, FIRST_PROC, I, ICTXT,
372 $ ICTXT_NEW, ICTXT_SAVE, IDUM3, INT_TEMP, JA_NEW,
373 $ LAF_MIN, LEVEL_DIST, LLDA, MYCOL, MYROW,
374 $ MY_NUM_COLS, NB, NP, NPCOL, NPROW, NP_SAVE,
375 $ ODD_SIZE, PART_OFFSET, PART_SIZE, RETURN_CODE,
376 $ STORE_N_A, TEMP, WORK_SIZE_MIN
377
378
379 INTEGER DESCA_1XP( 7 ), PARAM_CHECK( 7, 3 )
380
381
382 EXTERNAL blacs_get, blacs_gridexit, blacs_gridinfo,
383 $ caxpy, cgemm, cgerv2d, cgesd2d, clamov,
384 $
clatcpy, cpbtrf, cpotrf, csyrk, ctbtrs, ctrmm,
387
388
389 LOGICAL LSAME
390 INTEGER NUMROC
392
393
394 INTRINSIC ichar,
min, mod
395
396
397
398
399
400 info = 0
401
402
403
404
405 desca_1xp( 1 ) = 501
406
407 temp = desca( dtype_ )
408 IF( temp .EQ. 502 ) THEN
409
410 desca( dtype_ ) = 501
411 ENDIF
412
414
415 desca( dtype_ ) = temp
416
417 IF( return_code .NE. 0) THEN
418 info = -( 5*100 + 2 )
419 ENDIF
420
421
422
423 ictxt = desca_1xp( 2 )
424 csrc = desca_1xp( 5 )
425 nb = desca_1xp( 4 )
426 llda = desca_1xp( 6 )
427 store_n_a = desca_1xp( 3 )
428
429
430
431
432 CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
433 np = nprow * npcol
434
435
436
437 IF( lwork .LT. -1) THEN
438 info = -9
439 ELSE IF ( lwork .EQ. -1 ) THEN
440 idum3 = -1
441 ELSE
442 idum3 = 1
443 ENDIF
444
445 IF( n .LT. 0 ) THEN
446 info = -1
447 ENDIF
448
449 IF( n+ja-1 .GT. store_n_a ) THEN
450 info = -( 5*100 + 6 )
451 ENDIF
452
453
454
455 IF( nprow .NE. 1 ) THEN
456 info = -( 5*100+2 )
457 ENDIF
458
459 IF( n .GT. np*nb-mod( ja-1, nb )) THEN
460 info = -( 1 )
462 $ 'PCPTTRF, D&C alg.: only 1 block per proc',
463 $ -info )
464 RETURN
465 ENDIF
466
467 IF((ja+n-1.GT.nb) .AND. ( nb.LT.2*int_one )) THEN
468 info = -( 5*100+4 )
470 $ 'PCPTTRF, D&C alg.: NB too small',
471 $ -info )
472 RETURN
473 ENDIF
474
475
476
477
478 laf_min = (12*npcol + 3*nb)
479
480 IF( laf .LT. laf_min ) THEN
481 info = -7
482
483 af( 1 ) = laf_min
485 $ 'PCPTTRF: auxiliary storage error ',
486 $ -info )
487 RETURN
488 ENDIF
489
490
491
492 work_size_min = 8*npcol
493
494 work( 1 ) = work_size_min
495
496 IF( lwork .LT. work_size_min ) THEN
497 IF( lwork .NE. -1 ) THEN
498 info = -9
500 $ 'PCPTTRF: worksize error ',
501 $ -info )
502 ENDIF
503 RETURN
504 ENDIF
505
506
507
508 param_check( 7, 1 ) = desca(5)
509 param_check( 6, 1 ) = desca(4)
510 param_check( 5, 1 ) = desca(3)
511 param_check( 4, 1 ) = desca(1)
512 param_check( 3, 1 ) = ja
513 param_check( 2, 1 ) = n
514 param_check( 1, 1 ) = idum3
515
516 param_check( 7, 2 ) = 505
517 param_check( 6, 2 ) = 504
518 param_check( 5, 2 ) = 503
519 param_check( 4, 2 ) = 501
520 param_check( 3, 2 ) = 4
521 param_check( 2, 2 ) = 1
522 param_check( 1, 2 ) = 9
523
524
525
526
527
528 IF( info.GE.0 ) THEN
529 info = bignum
530 ELSE IF( info.LT.-descmult ) THEN
531 info = -info
532 ELSE
533 info = -info * descmult
534 END IF
535
536
537
538 CALL globchk( ictxt, 7, param_check, 7,
539 $ param_check( 1, 3 ), info )
540
541
542
543
544 IF( info.EQ.bignum ) THEN
545 info = 0
546 ELSE IF( mod( info, descmult ) .EQ. 0 ) THEN
547 info = -info / descmult
548 ELSE
549 info = -info
550 END IF
551
552 IF( info.LT.0 ) THEN
553 CALL pxerbla( ictxt,
'PCPTTRF', -info )
554 RETURN
555 END IF
556
557
558
559 IF( n.EQ.0 )
560 $ RETURN
561
562
563
564
565
566 part_offset = nb*( (ja-1)/(npcol*nb) )
567
568 IF ( (mycol-csrc) .LT. (ja-part_offset-1)/nb ) THEN
569 part_offset = part_offset + nb
570 ENDIF
571
572 IF ( mycol .LT. csrc ) THEN
573 part_offset = part_offset - nb
574 ENDIF
575
576
577
578
579
580
581
582 first_proc = mod( ( ja-1 )/nb+csrc, npcol )
583
584
585
586 ja_new = mod( ja-1, nb ) + 1
587
588
589
590 np_save = np
591 np = ( ja_new+n-2 )/nb + 1
592
593
594
595 CALL reshape( ictxt, int_one, ictxt_new, int_one,
596 $ first_proc, int_one, np )
597
598
599
600 ictxt_save = ictxt
601 ictxt = ictxt_new
602 desca_1xp( 2 ) = ictxt_new
603
604
605
606 CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
607
608
609
610 IF( myrow .LT. 0 ) THEN
611 GOTO 1234
612 ENDIF
613
614
615
616
617
618
619 part_size = nb
620
621
622
623 my_num_cols =
numroc( n, part_size, mycol, 0, npcol )
624
625
626
627 IF ( mycol .EQ. 0 ) THEN
628 part_offset = part_offset+mod( ja_new-1, part_size )
629 my_num_cols = my_num_cols - mod(ja_new-1, part_size )
630 ENDIF
631
632
633
634 odd_size = my_num_cols
635 IF ( mycol .LT. np-1 ) THEN
636 odd_size = odd_size - int_one
637 ENDIF
638
639
640
641
642 DO 10 i=1, laf_min
643 af( i ) = czero
644 10 CONTINUE
645
646
647
648
649
650
651
652
653
654 IF ( mycol .LT. np-1 ) THEN
655
656
657
658
659
660 CALL ctrsd2d( ictxt, 'U', 'N', 1, 1,
661 $ e( part_offset+odd_size+1 ), llda-1, 0,
662 $ mycol+1 )
663
664 ENDIF
665
666
667
668
669
670 CALL cpttrf( odd_size, d( part_offset+1 ), e( part_offset+1 ),
671 $ info )
672
673 IF( info.NE.0 ) THEN
674 info = mycol+1
675 GOTO 1500
676 ENDIF
677
678
679 IF ( mycol .LT. np-1 ) THEN
680
681
682
683
684
685
686 e( part_offset+odd_size ) = e( part_offset+odd_size )/
687 $ d( part_offset+odd_size )
688
689
690
691
692
693
694 d( part_offset+odd_size+1 ) = d( part_offset+odd_size+1 )-
695 $ d( part_offset+odd_size )*real( e( part_offset+odd_size )*
696 $ conjg( e( part_offset+odd_size ) ) )
697
698 ENDIF
699
700
701
702 1500 CONTINUE
703
704
705 IF ( mycol .NE. 0 ) THEN
706
707
708
709
710
711
712 CALL ctrrv2d( ictxt, 'U', 'N', 1, 1, af( 1 ), odd_size, 0,
713 $ mycol-1 )
714
715 IF (info.EQ.0) THEN
716
717
718
719 CALL cpttrsv(
'L',
'N', odd_size, int_one, d( part_offset+1 ),
720 $ e( part_offset+1 ), af( 1 ), odd_size, info )
721
722
723
724 DO 20 i=1, odd_size
725 af( i ) = af( i )/d( part_offset+i )
726 20 CONTINUE
727
728
729
730
731
732
733
734
735 int_temp = odd_size*int_one+2+1
736 af( int_temp ) = 0
737
738 DO 30 i=1, odd_size
739 af( int_temp ) = af( int_temp )-d( part_offset+i )*
740 $ ( af( i )*conjg( af( i ) ) )
741 30 CONTINUE
742
743
744
745
746
747 CALL cgesd2d( ictxt, int_one, int_one, af( odd_size+3 ),
748 $ int_one, 0, mycol-1 )
749
750
751 IF ( mycol .LT. np-1 ) THEN
752
753
754
755
756
757
758 af( odd_size+1 ) =
759 $ - d( part_offset+odd_size )
760 $ * conjg( e( part_offset+odd_size )
761 $ * af( odd_size ) )
762
763
764 ENDIF
765
766 ENDIF
767
768
769 ENDIF
770
771
772
773
774
775 CALL igamx2d( ictxt, 'A', ' ', 1, 1, info, 1, info, info,
776 $ -1, 0, 0 )
777
778 IF( mycol.EQ.0 ) THEN
779 CALL igebs2d( ictxt, 'A', ' ', 1, 1, info, 1 )
780 ELSE
781 CALL igebr2d( ictxt, 'A', ' ', 1, 1, info, 1, 0, 0 )
782 ENDIF
783
784 IF ( info.NE.0 ) THEN
785 GOTO 1000
786 ENDIF
787
788
789
790
791
792
793
794
795
796
797
798
799 IF( mycol .EQ. npcol-1 ) THEN
800 GOTO 14
801 ENDIF
802
803
804
805
806
807 IF( (mod( mycol+1, 2 ) .EQ. 0) .AND. ( mycol .GT. 0 ) ) THEN
808
809 CALL cgesd2d( ictxt, int_one, int_one,
810 $ af( odd_size+1 ),
811 $ int_one, 0, mycol-1 )
812
813 ENDIF
814
815
816
817
818 af( odd_size+2 ) =
819 $
cmplx( d( part_offset+odd_size+1 ) )
820
821
822
823 IF( mycol.LT. npcol-1 ) THEN
824
825 CALL cgerv2d( ictxt, int_one, int_one,
826 $ af( odd_size+2+1 ),
827 $ int_one, 0,
828 $ mycol+1 )
829
830
831
832 af( odd_size+2 ) = af( odd_size+2 )+af( odd_size+3 )
833
834 ENDIF
835
836
837
838
839
840
841
842 level_dist = 1
843
844
845
846 12 CONTINUE
847 IF( mod( (mycol+1)/level_dist, 2) .NE. 0 ) GOTO 11
848
849
850
851 IF( mycol-level_dist .GE. 0 ) THEN
852 CALL cgerv2d( ictxt, int_one, int_one, work( 1 ),
853 $ int_one, 0, mycol-level_dist )
854
855 af( odd_size+2 ) = af( odd_size+2 )+work( 1 )
856
857 ENDIF
858
859
860
861 IF( mycol+level_dist .LT. npcol-1 ) THEN
862 CALL cgerv2d( ictxt, int_one, int_one, work( 1 ),
863 $ int_one, 0, mycol+level_dist )
864
865 af( odd_size+2 ) = af( odd_size+2 )+work( 1 )
866
867 ENDIF
868
869 level_dist = level_dist*2
870
871 GOTO 12
872 11 CONTINUE
873
874
875
876
877
878 IF( af( odd_size+2 ) .EQ. czero ) THEN
879 info = npcol + mycol
880 ENDIF
881
882
883
884
885
886
887 IF( level_dist .EQ. 1 )THEN
888 comm_proc = mycol + 1
889
890
891
892
893 af( odd_size+3 ) = af( odd_size+1 )
894
895 ELSE
896 comm_proc = mycol + level_dist/2
897 ENDIF
898
899 IF( mycol/level_dist .LE. (npcol-1)/level_dist-2 )THEN
900
901 CALL cgerv2d( ictxt, int_one, int_one,
902 $ af( odd_size+1 ),
903 $ int_one, 0, comm_proc )
904
905 IF( info .EQ. 0 ) THEN
906
907
908
909
910
911 af( odd_size+1 ) = af( odd_size+1 )/af( odd_size+2 )
912
913 ENDIF
914
915
916
917
918 work( 1 ) = -one*af( odd_size+1 )*af( odd_size+2 )
919 $ *conjg( af( odd_size+1 ) )
920
921
922
923 CALL cgesd2d( ictxt, int_one, int_one, work( 1 ), int_one,
924 $ 0, mycol+level_dist )
925
926 ENDIF
927
928
929
930
931
932
933
934 IF( (mycol/level_dist .GT. 0 ).AND.
935 $ ( mycol/level_dist .LE. (npcol-1)/level_dist-1 ) ) THEN
936
937 IF( level_dist .GT. 1)THEN
938
939
940
941
942 CALL cgerv2d( ictxt, int_one, int_one,
943 $ af( odd_size+2+1 ),
944 $ int_one, 0, mycol-level_dist/2 )
945
946 ENDIF
947
948
949 IF( info.EQ.0 ) THEN
950
951
952
953 af( odd_size+3 ) = ( af( odd_size+3 ) )
954 $ /af( odd_size+2 )
955
956 ENDIF
957
958
959
960
961
962 work( 1 ) = -one*af( odd_size+3 )*af( odd_size+2 )
963 $ *conjg( af( odd_size+3 ) )
964
965
966
967 CALL cgesd2d( ictxt, int_one, int_one, work( 1 ), int_one,
968 $ 0, mycol-level_dist )
969
970
971
972 IF( mycol/level_dist .LE. (npcol-1)/level_dist-2 ) THEN
973
974
975
976 IF( ( mod( mycol/( 2*level_dist ),2 )) .EQ.0 ) THEN
977 comm_proc = mycol + level_dist
978 ELSE
979 comm_proc = mycol - level_dist
980 ENDIF
981
982
983
984
985
986 work( 1 ) = -one*af( odd_size+3 )
987 $ * af( odd_size+2 )
988 $ * af( odd_size+1 )
989
990
991
992 CALL cgesd2d( ictxt, int_one, int_one, work( 1 ), int_one,
993 $ 0, comm_proc )
994
995 ENDIF
996
997 ENDIF
998
999
1000 14 CONTINUE
1001
1002
1003 1000 CONTINUE
1004
1005
1006
1007
1008 IF( ictxt_save .NE. ictxt_new ) THEN
1009 CALL blacs_gridexit( ictxt_new )
1010 ENDIF
1011
1012 1234 CONTINUE
1013
1014
1015
1016 ictxt = ictxt_save
1017 np = np_save
1018
1019
1020
1021 work( 1 ) = work_size_min
1022
1023
1024
1025 CALL igamx2d( ictxt, 'A', ' ', 1, 1, info, 1, info, info,
1026 $ -1, 0, 0 )
1027
1028 IF( mycol.EQ.0 ) THEN
1029 CALL igebs2d( ictxt, 'A', ' ', 1, 1, info, 1 )
1030 ELSE
1031 CALL igebr2d( ictxt, 'A', ' ', 1, 1, info, 1, 0, 0 )
1032 ENDIF
1033
1034
1035 RETURN
1036
1037
1038
subroutine clatcpy(uplo, m, n, a, lda, b, ldb)
subroutine cpttrsv(uplo, trans, n, nrhs, d, e, b, ldb, info)
subroutine desc_convert(desc_in, desc_out, info)
integer function numroc(n, nb, iproc, isrcproc, nprocs)
subroutine globchk(ictxt, n, x, ldx, iwork, info)
subroutine pxerbla(ictxt, srname, info)
void reshape(Int *context_in, Int *major_in, Int *context_out, Int *major_out, Int *first_proc, Int *nprow_new, Int *npcol_new)