17 USE omp_lib,
ONLY: omp_get_max_threads
31#include "../base/base_uses.f90"
36 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
37 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_cfm_basic_linalg'
62 REAL(kind=
dp),
EXTERNAL :: zlange, pzlange
65 MODULE PROCEDURE cp_cfm_dscale, cp_cfm_zscale
81 COMPLEX(KIND=dp),
INTENT(OUT) :: det_a
82 COMPLEX(KIND=dp) :: determinant
84 COMPLEX(KIND=dp),
DIMENSION(:, :),
POINTER :: a
85 INTEGER :: n, i, info, p
86 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: ipivot
87 COMPLEX(KIND=dp),
DIMENSION(:),
POINTER :: diag
89#if defined(__parallel)
90 INTEGER :: myprow, nprow, npcol, nrow_local, irow_local, &
91 mypcol, ncol_local, icol_local, j
92 INTEGER,
DIMENSION(9) :: desca
96 matrix_struct=matrix_a%matrix_struct, &
100 a => matrix_lu%local_data
101 n = matrix_lu%matrix_struct%nrow_global
107#if defined(__parallel)
109 desca(:) = matrix_lu%matrix_struct%descriptor(:)
110 CALL pzgetrf(n, n, a(1, 1), 1, 1, desca, ipivot, info)
111 myprow = matrix_lu%matrix_struct%context%mepos(1)
112 mypcol = matrix_lu%matrix_struct%context%mepos(2)
113 nprow = matrix_lu%matrix_struct%context%num_pe(1)
114 npcol = matrix_lu%matrix_struct%context%num_pe(2)
115 nrow_local = matrix_lu%matrix_struct%nrow_locals(myprow)
116 ncol_local = matrix_lu%matrix_struct%ncol_locals(mypcol)
118 DO irow_local = 1, nrow_local
119 i = matrix_lu%matrix_struct%row_indices(irow_local)
120 DO icol_local = 1, ncol_local
121 j = matrix_lu%matrix_struct%col_indices(icol_local)
122 IF (i == j) diag(i) = matrix_lu%local_data(irow_local, icol_local)
125 CALL matrix_lu%matrix_struct%para_env%sum(diag)
126 determinant = product(diag)
127 DO irow_local = 1, nrow_local
128 i = matrix_lu%matrix_struct%row_indices(irow_local)
129 IF (ipivot(irow_local) /= i) p = p + 1
131 CALL matrix_lu%matrix_struct%para_env%sum(p)
135 CALL zgetrf(n, n, a(1, 1), n, ipivot, info)
137 diag(i) = matrix_lu%local_data(i, i)
139 determinant = product(diag)
141 IF (ipivot(i) /= i) p = p + 1
147 det_a = determinant*(-2*mod(p, 2) + 1.0_dp)
158 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b, matrix_c
160 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_schur_product'
162 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a, b, c
163 INTEGER :: handle, icol_local, irow_local, mypcol, &
164 myprow, ncol_local, nrow_local
166 CALL timeset(routinen, handle)
168 myprow = matrix_a%matrix_struct%context%mepos(1)
169 mypcol = matrix_a%matrix_struct%context%mepos(2)
171 a => matrix_a%local_data
172 b => matrix_b%local_data
173 c => matrix_c%local_data
175 nrow_local = matrix_a%matrix_struct%nrow_locals(myprow)
176 ncol_local = matrix_a%matrix_struct%ncol_locals(mypcol)
178 DO icol_local = 1, ncol_local
179 DO irow_local = 1, nrow_local
180 c(irow_local, icol_local) = a(irow_local, icol_local)*b(irow_local, icol_local)
184 CALL timestop(handle)
196 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b, matrix_c
198 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_schur_product_cc'
200 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a, b, c
201 INTEGER :: handle, icol_local, irow_local, mypcol, &
202 myprow, ncol_local, nrow_local
204 CALL timeset(routinen, handle)
206 myprow = matrix_a%matrix_struct%context%mepos(1)
207 mypcol = matrix_a%matrix_struct%context%mepos(2)
209 a => matrix_a%local_data
210 b => matrix_b%local_data
211 c => matrix_c%local_data
213 nrow_local = matrix_a%matrix_struct%nrow_locals(myprow)
214 ncol_local = matrix_a%matrix_struct%ncol_locals(mypcol)
216 DO icol_local = 1, ncol_local
217 DO irow_local = 1, nrow_local
218 c(irow_local, icol_local) = a(irow_local, icol_local)*conjg(b(irow_local, icol_local))
222 CALL timestop(handle)
244 COMPLEX(kind=dp),
INTENT(in) :: alpha
246 COMPLEX(kind=dp),
INTENT(in),
OPTIONAL :: beta
247 TYPE(
cp_cfm_type),
INTENT(IN),
OPTIONAL :: matrix_b
249 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_scale_and_add'
251 COMPLEX(kind=dp) :: my_beta
252 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a, b
253 INTEGER :: handle, icol_local, irow_local, mypcol, &
254 myprow, ncol_local, nrow_local
256 CALL timeset(routinen, handle)
259 IF (
PRESENT(beta)) my_beta = beta
263 myprow = matrix_a%matrix_struct%context%mepos(1)
264 mypcol = matrix_a%matrix_struct%context%mepos(2)
266 nrow_local = matrix_a%matrix_struct%nrow_locals(myprow)
267 ncol_local = matrix_a%matrix_struct%ncol_locals(mypcol)
269 a => matrix_a%local_data
271 IF (my_beta ==
z_zero)
THEN
275 ELSE IF (alpha ==
z_one)
THEN
276 CALL timestop(handle)
279 a(:, :) = alpha*a(:, :)
283 cpassert(
PRESENT(matrix_b))
284 IF (matrix_a%matrix_struct%context /= matrix_b%matrix_struct%context) &
285 cpabort(
"matrixes must be in the same blacs context")
288 matrix_b%matrix_struct))
THEN
290 b => matrix_b%local_data
293 IF (my_beta ==
z_one)
THEN
295 DO icol_local = 1, ncol_local
296 DO irow_local = 1, nrow_local
297 a(irow_local, icol_local) = b(irow_local, icol_local)
302 DO icol_local = 1, ncol_local
303 DO irow_local = 1, nrow_local
304 a(irow_local, icol_local) = my_beta*b(irow_local, icol_local)
308 ELSE IF (alpha ==
z_one)
THEN
309 IF (my_beta ==
z_one)
THEN
311 DO icol_local = 1, ncol_local
312 DO irow_local = 1, nrow_local
313 a(irow_local, icol_local) = a(irow_local, icol_local) + b(irow_local, icol_local)
318 DO icol_local = 1, ncol_local
319 DO irow_local = 1, nrow_local
320 a(irow_local, icol_local) = a(irow_local, icol_local) + my_beta*b(irow_local, icol_local)
326 DO icol_local = 1, ncol_local
327 DO irow_local = 1, nrow_local
328 a(irow_local, icol_local) = alpha*a(irow_local, icol_local) + my_beta*b(irow_local, icol_local)
333 CALL cp_abort(__location__, &
334 "cp_cfm_scale_and_add is not yet implemented for cases "// &
335 "where input two matrix structures are not equivalent")
338 CALL timestop(handle)
353 COMPLEX(kind=dp),
INTENT(in) :: alpha
355 COMPLEX(kind=dp),
INTENT(in) :: beta
358 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_scale_and_add_fm'
360 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a
361 INTEGER :: handle, icol_local, irow_local, mypcol, &
362 myprow, ncol_local, nrow_local
363 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: b
365 CALL timeset(routinen, handle)
369 myprow = matrix_a%matrix_struct%context%mepos(1)
370 mypcol = matrix_a%matrix_struct%context%mepos(2)
372 nrow_local = matrix_a%matrix_struct%nrow_locals(myprow)
373 ncol_local = matrix_a%matrix_struct%ncol_locals(mypcol)
375 a => matrix_a%local_data
381 ELSE IF (alpha ==
z_one)
THEN
382 CALL timestop(handle)
385 a(:, :) = alpha*a(:, :)
389 IF (matrix_a%matrix_struct%context /= matrix_b%matrix_struct%context) &
390 cpabort(
"matrices must be in the same blacs context")
393 matrix_b%matrix_struct))
THEN
395 b => matrix_b%local_data
398 IF (beta ==
z_one)
THEN
400 DO icol_local = 1, ncol_local
401 DO irow_local = 1, nrow_local
402 a(irow_local, icol_local) = b(irow_local, icol_local)
407 DO icol_local = 1, ncol_local
408 DO irow_local = 1, nrow_local
409 a(irow_local, icol_local) = beta*b(irow_local, icol_local)
413 ELSE IF (alpha ==
z_one)
THEN
414 IF (beta ==
z_one)
THEN
416 DO icol_local = 1, ncol_local
417 DO irow_local = 1, nrow_local
418 a(irow_local, icol_local) = a(irow_local, icol_local) + b(irow_local, icol_local)
423 DO icol_local = 1, ncol_local
424 DO irow_local = 1, nrow_local
425 a(irow_local, icol_local) = a(irow_local, icol_local) + beta*b(irow_local, icol_local)
431 DO icol_local = 1, ncol_local
432 DO irow_local = 1, nrow_local
433 a(irow_local, icol_local) = alpha*a(irow_local, icol_local) + beta*b(irow_local, icol_local)
438 CALL cp_abort(__location__, &
439 "cp_cfm_scale_and_add_fm is not yet implemented for cases "// &
440 "where two input matrix structures are not equivalent")
443 CALL timestop(handle)
459 COMPLEX(kind=dp),
INTENT(out) :: determinant
461 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_lu_decompose'
463 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a
464 INTEGER :: counter, handle, info, irow, nrow_global
465 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: ipivot
467#if defined(__parallel)
468 INTEGER :: icol, ncol_local, nrow_local
469 INTEGER,
DIMENSION(9) :: desca
470 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
475 CALL timeset(routinen, handle)
477 nrow_global = matrix_a%matrix_struct%nrow_global
478 a => matrix_a%local_data
480 ALLOCATE (ipivot(nrow_global))
481#if defined(__parallel)
482 CALL cp_cfm_get_info(matrix_a, nrow_local=nrow_local, ncol_local=ncol_local, &
483 row_indices=row_indices, col_indices=col_indices)
485 desca(:) = matrix_a%matrix_struct%descriptor(:)
486 CALL pzgetrf(nrow_global, nrow_global, a(1, 1), 1, 1, desca, ipivot, info)
489 DO irow = 1, nrow_local
490 IF (ipivot(irow) /= row_indices(irow)) counter = counter + 1
493 IF (mod(counter, 2) == 0)
THEN
502 DO WHILE (irow <= nrow_local .AND. icol <= ncol_local)
503 IF (row_indices(irow) < col_indices(icol))
THEN
505 ELSE IF (row_indices(irow) > col_indices(icol))
THEN
508 determinant = determinant*a(irow, icol)
513 CALL matrix_a%matrix_struct%para_env%prod(determinant)
516 CALL zgetrf(nrow_global, nrow_global, a(1, 1), lda, ipivot, info)
519 DO irow = 1, nrow_global
520 IF (ipivot(irow) /= irow) counter = counter + 1
521 determinant = determinant*a(irow, irow)
523 IF (mod(counter, 2) == 1) determinant = -1.0_dp*determinant
530 CALL timestop(handle)
560 SUBROUTINE cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, &
561 matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, &
563 CHARACTER(len=1),
INTENT(IN) :: transa, transb
564 INTEGER,
INTENT(IN) :: m, n, k
565 COMPLEX(kind=dp),
INTENT(IN) :: alpha
566 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b
567 COMPLEX(kind=dp),
INTENT(IN) :: beta
569 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
570 b_first_row, c_first_col, c_first_row
572 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_gemm'
574 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a, b, c
575 INTEGER :: handle, i_a, i_b, i_c, j_a, j_b, j_c
576#if defined(__parallel)
577 INTEGER,
DIMENSION(9) :: desca, descb, descc
579 INTEGER :: lda, ldb, ldc
582 CALL timeset(routinen, handle)
583 a => matrix_a%local_data
584 b => matrix_b%local_data
585 c => matrix_c%local_data
588 IF (
PRESENT(a_first_row)) i_a = a_first_row
591 IF (
PRESENT(a_first_col)) j_a = a_first_col
594 IF (
PRESENT(b_first_row)) i_b = b_first_row
597 IF (
PRESENT(b_first_col)) j_b = b_first_col
600 IF (
PRESENT(c_first_row)) i_c = c_first_row
603 IF (
PRESENT(c_first_col)) j_c = c_first_col
605#if defined(__parallel)
606 desca(:) = matrix_a%matrix_struct%descriptor(:)
607 descb(:) = matrix_b%matrix_struct%descriptor(:)
608 descc(:) = matrix_c%matrix_struct%descriptor(:)
610 CALL pzgemm(transa, transb, m, n, k, alpha, a(1, 1), i_a, j_a, desca, &
611 b(1, 1), i_b, j_b, descb, beta, c(1, 1), i_c, j_c, descc)
618 CALL zgemm(transa, transb, m, n, k, alpha, a(i_a, j_a), &
619 lda, b(i_b, j_b), ldb, beta, c(i_c, j_c), ldc)
621 CALL timestop(handle)
636 COMPLEX(kind=dp),
DIMENSION(:),
INTENT(IN) :: scaling
637 INTEGER,
INTENT(IN),
OPTIONAL :: first_col
640 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_column_scale'
642 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a, b
643 INTEGER :: first, handle, i_factor, icol_local, &
644 ncol_local, nrow_local
645 INTEGER,
DIMENSION(:),
POINTER :: col_indices
646 LOGICAL :: compatible_layout
648 CALL timeset(routinen, handle)
650 a => matrix_a%local_data
652 IF (
PRESENT(source))
THEN
654 cpassert(compatible_layout)
655 b => source%local_data
658 IF (
PRESENT(first_col)) first = first_col
660 CALL cp_cfm_get_info(matrix_a, nrow_local=nrow_local, ncol_local=ncol_local, col_indices=col_indices)
662 DO icol_local = 1, ncol_local
663 i_factor = col_indices(icol_local) - first + 1
664 IF (i_factor < 1 .OR. i_factor >
SIZE(scaling)) cycle
665 a(1:nrow_local, icol_local) = scaling(i_factor)*b(1:nrow_local, icol_local)
668 CALL timestop(handle)
677 SUBROUTINE cp_cfm_dscale(alpha, matrix_a)
678 REAL(kind=
dp),
INTENT(IN) :: alpha
681 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_dscale'
683 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a
686 CALL timeset(routinen, handle)
690 a => matrix_a%local_data
692 CALL zdscal(
SIZE(a), alpha, a(1, 1), 1)
694 CALL timestop(handle)
695 END SUBROUTINE cp_cfm_dscale
705 SUBROUTINE cp_cfm_zscale(alpha, matrix_a)
706 COMPLEX(kind=dp),
INTENT(IN) :: alpha
709 CHARACTER(len=*),
PARAMETER :: routineN =
'cp_cfm_zscale'
711 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a
714 CALL timeset(routinen, handle)
718 a => matrix_a%local_data
720 a(:, :) = alpha*a(:, :)
722 CALL timestop(handle)
723 END SUBROUTINE cp_cfm_zscale
735 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, general_a
736 COMPLEX(kind=dp),
OPTIONAL :: determinant
738 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_solve'
740 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: a, a_general
741 INTEGER :: counter, handle, info, irow, nrow_global
742 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: ipivot
744#if defined(__parallel)
745 INTEGER :: icol, ncol_local, nrow_local
746 INTEGER,
DIMENSION(9) :: desca, descb
747 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
752 CALL timeset(routinen, handle)
754 a => matrix_a%local_data
755 a_general => general_a%local_data
756 nrow_global = matrix_a%matrix_struct%nrow_global
757 ALLOCATE (ipivot(nrow_global))
759#if defined(__parallel)
760 desca(:) = matrix_a%matrix_struct%descriptor(:)
761 descb(:) = general_a%matrix_struct%descriptor(:)
762 CALL pzgetrf(nrow_global, nrow_global, a(1, 1), 1, 1, desca, ipivot, info)
763 IF (
PRESENT(determinant))
THEN
764 CALL cp_cfm_get_info(matrix_a, nrow_local=nrow_local, ncol_local=ncol_local, &
765 row_indices=row_indices, col_indices=col_indices)
768 DO irow = 1, nrow_local
769 IF (ipivot(irow) /= row_indices(irow)) counter = counter + 1
772 IF (mod(counter, 2) == 0)
THEN
781 DO WHILE (irow <= nrow_local .AND. icol <= ncol_local)
782 IF (row_indices(irow) < col_indices(icol))
THEN
784 ELSE IF (row_indices(irow) > col_indices(icol))
THEN
787 determinant = determinant*a(irow, icol)
792 CALL matrix_a%matrix_struct%para_env%prod(determinant)
795 CALL pzgetrs(
"N", nrow_global, nrow_global, a(1, 1), 1, 1, desca, &
796 ipivot, a_general(1, 1), 1, 1, descb, info)
799 ldb =
SIZE(a_general, 1)
800 CALL zgetrf(nrow_global, nrow_global, a(1, 1), lda, ipivot, info)
801 IF (
PRESENT(determinant))
THEN
804 DO irow = 1, nrow_global
805 IF (ipivot(irow) /= irow) counter = counter + 1
806 determinant = determinant*a(irow, irow)
808 IF (mod(counter, 2) == 1) determinant = -1.0_dp*determinant
810 CALL zgetrs(
"N", nrow_global, nrow_global, a(1, 1), lda, ipivot, a_general(1, 1), ldb, info)
816 CALL timestop(handle)
828 INTEGER,
INTENT(out),
OPTIONAL :: info_out
830 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_lu_invert'
832 COMPLEX(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: work
833 COMPLEX(kind=dp),
DIMENSION(1) :: work1
834 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: mat
835 INTEGER :: handle, info, lwork, nrows_global
836 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: ipivot
838#if defined(__parallel)
840 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: iwork
841 INTEGER,
DIMENSION(1) :: iwork1
842 INTEGER,
DIMENSION(9) :: desca
847 CALL timeset(routinen, handle)
849 mat => matrix%local_data
850 nrows_global = matrix%matrix_struct%nrow_global
851 cpassert(nrows_global == matrix%matrix_struct%ncol_global)
852 ALLOCATE (ipivot(nrows_global))
855#if defined(__parallel)
856 desca = matrix%matrix_struct%descriptor
857 CALL pzgetrf(nrows_global, nrows_global, &
858 mat(1, 1), 1, 1, desca, ipivot, info)
861 CALL zgetrf(nrows_global, nrows_global, &
862 mat(1, 1), lda, ipivot, info)
865 CALL cp_abort(__location__,
"LU decomposition has failed")
869#if defined(__parallel)
870 CALL pzgetri(nrows_global, mat(1, 1), 1, 1, desca, &
871 ipivot, work1, -1, iwork1, -1, info)
872 lwork = int(work1(1))
873 liwork = int(iwork1(1))
874 ALLOCATE (work(lwork))
875 ALLOCATE (iwork(liwork))
876 CALL pzgetri(nrows_global, mat(1, 1), 1, 1, desca, &
877 ipivot, work, lwork, iwork, liwork, info)
880 CALL zgetri(nrows_global, mat(1, 1), lda, ipivot, work1, -1, info)
881 lwork = int(work1(1))
882 ALLOCATE (work(lwork))
883 CALL zgetri(nrows_global, mat(1, 1), lda, ipivot, work, lwork, info)
888 IF (
PRESENT(info_out))
THEN
892 CALL cp_abort(__location__,
"LU inversion has failed")
895 CALL timestop(handle)
914 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b
915 COMPLEX(kind=dp),
INTENT(out) :: trace
916 LOGICAL,
INTENT(IN),
OPTIONAL :: conjugate_a, local
918 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_trace'
920 INTEGER :: handle, mypcol, myprow, ncol_local, &
921 npcol, nprow, nrow_local
925 CALL timeset(routinen, handle)
927 context => matrix_a%matrix_struct%context
928 myprow = context%mepos(1)
929 mypcol = context%mepos(2)
930 nprow = context%num_pe(1)
931 npcol = context%num_pe(2)
933 nrow_local = min(matrix_a%matrix_struct%nrow_locals(myprow), matrix_b%matrix_struct%nrow_locals(myprow))
934 ncol_local = min(matrix_a%matrix_struct%ncol_locals(mypcol), matrix_b%matrix_struct%ncol_locals(mypcol))
938 matrix_b%local_data(1:nrow_local, 1:ncol_local), conjugate_a=conjugate_a)
941 IF (
PRESENT(local)) reduce = .NOT. local
942 IF (reduce)
CALL matrix_a%matrix_struct%para_env%sum(trace)
944 CALL timestop(handle)
983 transa_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, &
985 TYPE(
cp_cfm_type),
INTENT(IN) :: triangular_matrix, matrix_b
986 CHARACTER,
INTENT(in),
OPTIONAL :: side, transa_tr
987 LOGICAL,
INTENT(in),
OPTIONAL :: invert_tr
988 CHARACTER,
INTENT(in),
OPTIONAL :: uplo_tr
989 LOGICAL,
INTENT(in),
OPTIONAL :: unit_diag_tr
990 INTEGER,
INTENT(in),
OPTIONAL :: n_rows, n_cols
991 COMPLEX(kind=dp),
INTENT(in),
OPTIONAL :: alpha
993 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_triangular_multiply'
995 CHARACTER :: side_char, transa, unit_diag, uplo
996 COMPLEX(kind=dp) :: al
997 INTEGER :: handle, m, n
1000 CALL timeset(routinen, handle)
1008 IF (
PRESENT(side)) side_char = side
1009 IF (
PRESENT(invert_tr)) invert = invert_tr
1010 IF (
PRESENT(uplo_tr)) uplo = uplo_tr
1011 IF (
PRESENT(unit_diag_tr))
THEN
1012 IF (unit_diag_tr)
THEN
1018 IF (
PRESENT(transa_tr)) transa = transa_tr
1019 IF (
PRESENT(alpha)) al = alpha
1020 IF (
PRESENT(n_rows)) m = n_rows
1021 IF (
PRESENT(n_cols)) n = n_cols
1025#if defined(__parallel)
1026 CALL pztrsm(side_char, uplo, transa, unit_diag, m, n, al, &
1027 triangular_matrix%local_data(1, 1), 1, 1, &
1028 triangular_matrix%matrix_struct%descriptor, &
1029 matrix_b%local_data(1, 1), 1, 1, &
1030 matrix_b%matrix_struct%descriptor(1))
1032 CALL ztrsm(side_char, uplo, transa, unit_diag, m, n, al, &
1033 triangular_matrix%local_data(1, 1), &
1034 SIZE(triangular_matrix%local_data, 1), &
1035 matrix_b%local_data(1, 1),
SIZE(matrix_b%local_data, 1))
1040#if defined(__parallel)
1041 CALL pztrmm(side_char, uplo, transa, unit_diag, m, n, al, &
1042 triangular_matrix%local_data(1, 1), 1, 1, &
1043 triangular_matrix%matrix_struct%descriptor, &
1044 matrix_b%local_data(1, 1), 1, 1, &
1045 matrix_b%matrix_struct%descriptor(1))
1047 CALL ztrmm(side_char, uplo, transa, unit_diag, m, n, al, &
1048 triangular_matrix%local_data(1, 1), &
1049 SIZE(triangular_matrix%local_data, 1), &
1050 matrix_b%local_data(1, 1),
SIZE(matrix_b%local_data, 1))
1055 CALL timestop(handle)
1068 CHARACTER,
INTENT(in),
OPTIONAL :: uplo
1069 INTEGER,
INTENT(out),
OPTIONAL :: info_out
1071 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_triangular_invert'
1073 CHARACTER :: unit_diag, my_uplo
1074 INTEGER :: handle, info, ncol_global
1075 COMPLEX(kind=dp),
DIMENSION(:, :), &
1077#if defined(__parallel)
1078 INTEGER,
DIMENSION(9) :: desca
1081 CALL timeset(routinen, handle)
1085 IF (
PRESENT(uplo)) my_uplo = uplo
1087 ncol_global = matrix_a%matrix_struct%ncol_global
1089 a => matrix_a%local_data
1091#if defined(__parallel)
1092 desca(:) = matrix_a%matrix_struct%descriptor(:)
1093 CALL pztrtri(my_uplo, unit_diag, ncol_global, a(1, 1), 1, 1, desca, info)
1095 CALL ztrtri(my_uplo, unit_diag, ncol_global, a(1, 1), ncol_global, info)
1098 IF (
PRESENT(info_out))
THEN
1102 CALL cp_abort(__location__, &
1103 "triangular invert failed: matrix is not positive definite or ill-conditioned")
1106 CALL timestop(handle)
1118 CHARACTER,
INTENT(in) :: trans
1121 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_transpose'
1123 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: aa, cc
1124 INTEGER :: handle, ncol_global, nrow_global
1125#if defined(__parallel)
1126 INTEGER,
DIMENSION(9) :: desca, descc
1127#elif !defined(__MKL)
1131 CALL timeset(routinen, handle)
1133 nrow_global = matrix%matrix_struct%nrow_global
1134 ncol_global = matrix%matrix_struct%ncol_global
1136 cpassert(matrixt%matrix_struct%nrow_global == ncol_global)
1137 cpassert(matrixt%matrix_struct%ncol_global == nrow_global)
1139 aa => matrix%local_data
1140 cc => matrixt%local_data
1142#if defined(__parallel)
1143 desca = matrix%matrix_struct%descriptor
1144 descc = matrixt%matrix_struct%descriptor
1147 CALL pztranu(nrow_global, ncol_global, &
1148 z_one, aa(1, 1), 1, 1, desca, &
1149 z_zero, cc(1, 1), 1, 1, descc)
1151 CALL pztranc(nrow_global, ncol_global, &
1152 z_one, aa(1, 1), 1, 1, desca, &
1153 z_zero, cc(1, 1), 1, 1, descc)
1155 cpabort(
"trans only accepts 'T' or 'C'")
1158 CALL mkl_zomatcopy(
'C', trans, nrow_global, ncol_global, 1.0_dp, aa(1, 1), nrow_global, cc(1, 1), ncol_global)
1162 DO jj = 1, ncol_global
1163 DO ii = 1, nrow_global
1164 cc(ii, jj) = aa(jj, ii)
1168 DO jj = 1, ncol_global
1169 DO ii = 1, nrow_global
1170 cc(ii, jj) = conjg(aa(jj, ii))
1174 cpabort(
"trans only accepts 'T' or 'C'")
1178 CALL timestop(handle)
1193 CHARACTER,
INTENT(IN) :: mode
1194 REAL(kind=
dp) :: res
1196 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_norm'
1198 COMPLEX(kind=dp),
DIMENSION(:, :),
POINTER :: aa
1199 INTEGER :: handle, lwork, ncols, ncols_local, &
1201 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: work
1203#if defined(__parallel)
1204 INTEGER,
DIMENSION(9) :: desca
1209 CALL timeset(routinen, handle)
1212 nrow_global=nrows, &
1213 ncol_global=ncols, &
1214 nrow_local=nrows_local, &
1215 ncol_local=ncols_local)
1216 aa => matrix%local_data
1221 CASE (
'1',
'O',
'o')
1222#if defined(__parallel)
1228#if defined(__parallel)
1233 CASE (
'F',
'f',
'E',
'e')
1236 cpabort(
"mode input is not valid")
1239 ALLOCATE (work(lwork))
1241#if defined(__parallel)
1242 desca = matrix%matrix_struct%descriptor
1243 res = pzlange(mode, nrows, ncols, aa(1, 1), 1, 1, desca, work)
1246 res = zlange(mode, nrows, ncols, aa(1, 1), lda, work)
1250 CALL timestop(handle)
1264 INTEGER,
INTENT(IN) :: irow, jrow
1265 REAL(
dp),
INTENT(IN) :: cs, sn
1267 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_rot_rows'
1268 INTEGER :: handle, ncol
1269 COMPLEX(KIND=dp) :: sn_cmplx
1271#if defined(__parallel)
1272 INTEGER :: info, lwork
1273 INTEGER,
DIMENSION(9) :: desc
1274 REAL(
dp),
DIMENSION(:),
ALLOCATABLE :: work
1276 CALL timeset(routinen, handle)
1278 sn_cmplx = cmplx(sn, 0.0_dp,
dp)
1279#if defined(__parallel)
1280 IF (1 /= matrix%matrix_struct%context%n_pid)
THEN
1282 ALLOCATE (work(lwork))
1283 desc(:) = matrix%matrix_struct%descriptor(:)
1286 matrix%local_data(1, 1), irow, 1, desc, ncol, &
1287 matrix%local_data(1, 1), jrow, 1, desc, ncol, &
1288 cs, sn_cmplx, work, lwork, info)
1293 CALL zrot(ncol, matrix%local_data(irow, 1), ncol, matrix%local_data(jrow, 1), ncol, cs, sn_cmplx)
1294#if defined(__parallel)
1297 CALL timestop(handle)
1311 INTEGER,
INTENT(IN) :: icol, jcol
1312 REAL(
dp),
INTENT(IN) :: cs, sn
1314 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_rot_cols'
1315 INTEGER :: handle, nrow
1316 COMPLEX(KIND=dp) :: sn_cmplx
1318#if defined(__parallel)
1319 INTEGER :: info, lwork
1320 INTEGER,
DIMENSION(9) :: desc
1321 REAL(
dp),
DIMENSION(:),
ALLOCATABLE :: work
1323 CALL timeset(routinen, handle)
1325 sn_cmplx = cmplx(sn, 0.0_dp,
dp)
1326#if defined(__parallel)
1327 IF (1 /= matrix%matrix_struct%context%n_pid)
THEN
1329 ALLOCATE (work(lwork))
1330 desc(:) = matrix%matrix_struct%descriptor(:)
1333 matrix%local_data(1, 1), 1, icol, desc, 1, &
1334 matrix%local_data(1, 1), 1, jcol, desc, 1, &
1335 cs, sn_cmplx, work, lwork, info)
1340 CALL zrot(nrow, matrix%local_data(1, icol), 1, matrix%local_data(1, jcol), 1, cs, sn_cmplx)
1341#if defined(__parallel)
1344 CALL timestop(handle)
1359 TYPE(
cp_cfm_type),
INTENT(IN),
OPTIONAL :: workspace
1360 CHARACTER,
INTENT(IN),
OPTIONAL :: uplo
1362 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cp_cfm_uplo_to_full'
1365 INTEGER :: handle, i_global, iib, j_global, jjb, &
1366 ncol_local, nrow_local
1367 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1370 CALL timeset(routinen, handle)
1372 IF (.NOT.
PRESENT(workspace))
THEN
1379 IF (
PRESENT(uplo)) myuplo = uplo
1383 nrow_local=nrow_local, &
1384 ncol_local=ncol_local, &
1385 row_indices=row_indices, &
1386 col_indices=col_indices)
1388 DO jjb = 1, ncol_local
1389 j_global = col_indices(jjb)
1390 DO iib = 1, nrow_local
1391 i_global = row_indices(iib)
1392 IF (merge(j_global < i_global, j_global > i_global, (myuplo ==
"U") .OR. (myuplo ==
"u")))
THEN
1393 matrix%local_data(iib, jjb) =
z_zero
1394 ELSE IF (j_global == i_global)
THEN
1395 matrix%local_data(iib, jjb) = matrix%local_data(iib, jjb)/(2.0_dp, 0.0_dp)
1404 IF (.NOT.
PRESENT(workspace))
THEN
1408 CALL timestop(handle)
1421 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: norm_array
1422 LOGICAL,
INTENT(IN),
OPTIONAL :: squared
1424 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cp_cfm_vectorsnorm'
1426 INTEGER :: handle, i, j, ncol_local, nrow_local
1429 INTEGER,
DIMENSION(:),
POINTER :: col_indices
1430 LOGICAL :: take_sqrt
1431 REAL(kind=
dp) :: norm_sq
1432 COMPLEX(KIND=dp),
CONTIGUOUS,
DIMENSION(:, :), &
1433 POINTER :: local_data
1435 CALL timeset(routinen, handle)
1437 local_data => matrix%local_data
1438 CALL cp_cfm_get_info(matrix, col_indices=col_indices, nrow_local=nrow_local, &
1439 ncol_local=ncol_local)
1448 DO j = 1, ncol_local
1451 DO i = 1, nrow_local
1452 norm_sq = norm_sq + real(local_data(i, j), kind=
dp)**2 + aimag(local_data(i, j))**2
1455 norm_array(col_indices(j)) = norm_sq
1458 CALL matrix%matrix_struct%para_env%sum(norm_array)
1460 IF (
PRESENT(squared)) take_sqrt = .NOT. squared
1461 IF (take_sqrt) norm_array = sqrt(norm_array)
1463 CALL timestop(handle)
1474 COMPLEX(KIND=dp),
INTENT(IN) :: alpha
1475 INTEGER,
INTENT(IN),
OPTIONAL :: n_active
1477 INTEGER :: i_global, n_diag, ncol_global, nrow_global
1478#if defined(__parallel)
1479 INTEGER :: icol_local, ipcol, iprow, irow, irow_local, &
1480 mypcol, myprow, npcol, nprow, nrow_local
1481 INTEGER,
DIMENSION(9) :: desca
1482 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1486 CALL cp_cfm_get_info(matrix, nrow_global=nrow_global, ncol_global=ncol_global)
1488 n_diag = min(nrow_global, ncol_global)
1489 IF (
PRESENT(n_active)) n_diag = n_active
1490 cpassert(n_diag >= 0 .AND. n_diag <= min(nrow_global, ncol_global))
1492#if defined(__parallel)
1493 CALL cp_cfm_get_info(matrix, nrow_local=nrow_local, row_indices=row_indices)
1494 context => matrix%matrix_struct%context
1495 myprow = context%mepos(1)
1496 mypcol = context%mepos(2)
1497 nprow = context%num_pe(1)
1498 npcol = context%num_pe(2)
1499 desca(:) = matrix%matrix_struct%descriptor(:)
1501 DO irow = 1, nrow_local
1502 i_global = row_indices(irow)
1503 IF (i_global > n_diag)
EXIT
1504 CALL infog2l(i_global, i_global, desca, nprow, npcol, myprow, mypcol, &
1505 irow_local, icol_local, iprow, ipcol)
1506 IF ((iprow == myprow) .AND. (ipcol == mypcol))
THEN
1507 matrix%local_data(irow_local, icol_local) = matrix%local_data(irow_local, icol_local) + alpha
1511 DO i_global = 1, n_diag
1512 matrix%local_data(i_global, i_global) = matrix%local_data(i_global, i_global) + alpha
1528 COMPLEX(KIND=dp),
DIMENSION(:),
INTENT(OUT) :: diag
1529 INTEGER,
INTENT(IN),
OPTIONAL :: n_active
1531 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cp_cfm_get_diag'
1533 INTEGER :: handle, i_global, n_diag, ncol_global, &
1535#if defined(__parallel)
1536 INTEGER :: icol_local, ipcol, iprow, irow, irow_local, &
1537 mypcol, myprow, npcol, nprow, nrow_local
1538 INTEGER,
DIMENSION(9) :: desca
1539 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1543 CALL timeset(routinen, handle)
1545 CALL cp_cfm_get_info(matrix, nrow_global=nrow_global, ncol_global=ncol_global)
1547 n_diag = min(nrow_global, ncol_global)
1548 IF (
PRESENT(n_active)) n_diag = n_active
1549 cpassert(n_diag >= 0 .AND. n_diag <= min(nrow_global, ncol_global))
1550 cpassert(
SIZE(diag) >= n_diag)
1553#if defined(__parallel)
1554 CALL cp_cfm_get_info(matrix, nrow_local=nrow_local, row_indices=row_indices)
1555 context => matrix%matrix_struct%context
1556 myprow = context%mepos(1)
1557 mypcol = context%mepos(2)
1558 nprow = context%num_pe(1)
1559 npcol = context%num_pe(2)
1560 desca(:) = matrix%matrix_struct%descriptor(:)
1562 DO irow = 1, nrow_local
1563 i_global = row_indices(irow)
1564 IF (i_global > n_diag)
EXIT
1565 CALL infog2l(i_global, i_global, desca, nprow, npcol, myprow, mypcol, &
1566 irow_local, icol_local, iprow, ipcol)
1567 IF ((iprow == myprow) .AND. (ipcol == mypcol))
THEN
1568 diag(i_global) = matrix%local_data(irow_local, icol_local)
1572 DO i_global = 1, n_diag
1573 diag(i_global) = matrix%local_data(i_global, i_global)
1576 CALL matrix%matrix_struct%para_env%sum(diag)
1578 CALL timestop(handle)
methods related to the blacs parallel environment
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b).
subroutine, public cp_cfm_lu_invert(matrix, info_out)
Inverts a matrix using LU decomposition. The input matrix will be overwritten.
real(kind=dp) function, public cp_cfm_norm(matrix, mode)
Norm of matrix using (p)zlange.
subroutine, public cp_cfm_vectorsnorm(matrix, norm_array, squared)
find the norm of each column norm_{j}= sqrt( \sum_{i} A_{ij}*conjg(A_{ij}) ) Complex-valued mirror of...
subroutine, public cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, c_first_row)
Performs one of the matrix-matrix operations: matrix_c = alpha * op1( matrix_a ) * op2( matrix_b ) + ...
subroutine, public cp_cfm_solve(matrix_a, general_a, determinant)
Solve the system of linear equations A*b=A_general using LU decomposition. Pay attention that both ma...
subroutine, public cp_cfm_transpose(matrix, trans, matrixt)
Transposes a BLACS distributed complex matrix.
subroutine, public cp_cfm_rot_rows(matrix, irow, jrow, cs, sn)
Applies a planar rotation defined by cs and sn to the i'th and j'th rows.
subroutine, public cp_cfm_scale_and_add_fm(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b). where b is a real matrix (adapted from cp_cf...
subroutine, public cp_cfm_get_diag(matrix, diag, n_active)
returns the diagonal of a complex full matrix: diag(i)= A_{ii}. Each diagonal entry is owned by one p...
subroutine, public cp_cfm_schur_product(matrix_a, matrix_b, matrix_c)
Computes the element-wise (Schur) product of two matrices: C = A \circ B .
subroutine, public cp_cfm_triangular_multiply(triangular_matrix, matrix_b, side, transa_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
Multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
subroutine, public cp_cfm_uplo_to_full(matrix, workspace, uplo)
...
subroutine, public cp_cfm_add_on_diag(matrix, alpha, n_active)
Adds a scalar to the diagonal of a distributed complex full matrix.
subroutine, public cp_cfm_det(matrix_a, det_a)
Computes the determinant (with a correct sign even in parallel environment!) of a complex square matr...
subroutine, public cp_cfm_column_scale(matrix_a, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
subroutine, public cp_cfm_rot_cols(matrix, icol, jcol, cs, sn)
Applies a planar rotation defined by cs and sn to the i'th and j'th columnns.
subroutine, public cp_cfm_trace(matrix_a, matrix_b, trace, conjugate_a, local)
By default, returns the trace of matrix_a^T matrix_b, i.e sum_{i,j}(matrix_a(i,j)*matrix_b(i,...
subroutine, public cp_cfm_schur_product_cc(matrix_a, matrix_b, matrix_c)
Computes the element-wise (Schur) product of two matrices: C = A \circ conjg(B) .
subroutine, public cp_cfm_triangular_invert(matrix_a, uplo, info_out)
Inverts a triangular matrix.
subroutine, public cp_cfm_lu_decompose(matrix_a, determinant)
Computes LU decomposition of a given matrix.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
represent the structure of a full matrix
logical function, public cp_fm_struct_equivalent(fmstruct1, fmstruct2)
returns true if the two matrix structures are equivalent, false otherwise.
represent a full matrix distributed on many processors
various routines to log and control the output. The idea is that decisions about where to log should ...
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.