-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbse_util.F
1877 lines (1558 loc) · 84.2 KB
/
bse_util.F
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
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Auxiliary routines for GW + Bethe-Salpeter for computing electronic excitations
!> \par History
!> 11.2023 created [Maximilian Graml]
! **************************************************************************************************
MODULE bse_util
USE atomic_kind_types, ONLY: atomic_kind_type
USE cell_types, ONLY: cell_type
USE cp_blacs_env, ONLY: cp_blacs_env_type
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: dbcsr_create,&
dbcsr_init_p,&
dbcsr_p_type,&
dbcsr_set,&
dbcsr_type_symmetric
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
USE cp_dbcsr_operations, ONLY: cp_dbcsr_sm_fm_multiply,&
dbcsr_allocate_matrix_set,&
dbcsr_deallocate_matrix_set
USE cp_fm_basic_linalg, ONLY: cp_fm_trace,&
cp_fm_upper_to_full
USE cp_fm_cholesky, ONLY: cp_fm_cholesky_decompose,&
cp_fm_cholesky_invert
USE cp_fm_struct, ONLY: cp_fm_struct_create,&
cp_fm_struct_release,&
cp_fm_struct_type
USE cp_fm_types, ONLY: cp_fm_create,&
cp_fm_get_info,&
cp_fm_release,&
cp_fm_set_all,&
cp_fm_to_fm_submat,&
cp_fm_to_fm_submat_general,&
cp_fm_type
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type
USE cp_output_handling, ONLY: cp_print_key_finished_output,&
cp_print_key_unit_nr
USE cp_realspace_grid_cube, ONLY: cp_pw_to_cube
USE input_constants, ONLY: bse_screening_alpha,&
bse_screening_rpa,&
bse_screening_tdhf,&
use_mom_ref_coac
USE input_section_types, ONLY: section_vals_type
USE kinds, ONLY: default_path_length,&
dp,&
int_8
USE message_passing, ONLY: mp_para_env_type,&
mp_request_type
USE moments_utils, ONLY: get_reference_point
USE mp2_types, ONLY: integ_mat_buffer_type,&
mp2_type
USE parallel_gemm_api, ONLY: parallel_gemm
USE particle_list_types, ONLY: particle_list_type
USE particle_types, ONLY: particle_type
USE physcon, ONLY: evolt
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_pool_types, ONLY: pw_pool_p_type,&
pw_pool_type
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_collocate_density, ONLY: calculate_wavefunction
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_kind_types, ONLY: qs_kind_type
USE qs_mo_types, ONLY: get_mo_set,&
mo_set_type
USE qs_moments, ONLY: build_local_moment_matrix
USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
USE qs_subsys_types, ONLY: qs_subsys_get,&
qs_subsys_type
USE rpa_communication, ONLY: communicate_buffer
USE util, ONLY: sort,&
sort_unique
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_util'
PUBLIC :: mult_B_with_W, fm_general_add_bse, truncate_fm, &
deallocate_matrices_bse, comp_eigvec_coeff_BSE, sort_excitations, &
estimate_BSE_resources, filter_eigvec_contrib, truncate_BSE_matrices, &
determine_cutoff_indices, adapt_BSE_input_params, get_multipoles_mo, &
reshuffle_eigvec, print_bse_nto_cubes, trace_exciton_descr
CONTAINS
! **************************************************************************************************
!> \brief Multiplies B-matrix (RI-3c-Integrals) with W (screening) to obtain \bar{B}
!> \param fm_mat_S_ij_bse ...
!> \param fm_mat_S_ia_bse ...
!> \param fm_mat_S_bar_ia_bse ...
!> \param fm_mat_S_bar_ij_bse ...
!> \param fm_mat_Q_static_bse_gemm ...
!> \param dimen_RI ...
!> \param homo ...
!> \param virtual ...
! **************************************************************************************************
SUBROUTINE mult_B_with_W(fm_mat_S_ij_bse, fm_mat_S_ia_bse, fm_mat_S_bar_ia_bse, &
fm_mat_S_bar_ij_bse, fm_mat_Q_static_bse_gemm, &
dimen_RI, homo, virtual)
TYPE(cp_fm_type), INTENT(IN) :: fm_mat_S_ij_bse, fm_mat_S_ia_bse
TYPE(cp_fm_type), INTENT(OUT) :: fm_mat_S_bar_ia_bse, fm_mat_S_bar_ij_bse
TYPE(cp_fm_type), INTENT(IN) :: fm_mat_Q_static_bse_gemm
INTEGER, INTENT(IN) :: dimen_RI, homo, virtual
CHARACTER(LEN=*), PARAMETER :: routineN = 'mult_B_with_W'
INTEGER :: handle, i_global, iiB, info_chol, &
j_global, jjB, ncol_local, nrow_local
INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
TYPE(cp_fm_type) :: fm_work
CALL timeset(routineN, handle)
CALL cp_fm_create(fm_mat_S_bar_ia_bse, fm_mat_S_ia_bse%matrix_struct)
CALL cp_fm_set_all(fm_mat_S_bar_ia_bse, 0.0_dp)
CALL cp_fm_create(fm_mat_S_bar_ij_bse, fm_mat_S_ij_bse%matrix_struct)
CALL cp_fm_set_all(fm_mat_S_bar_ij_bse, 0.0_dp)
CALL cp_fm_create(fm_work, fm_mat_Q_static_bse_gemm%matrix_struct)
CALL cp_fm_set_all(fm_work, 0.0_dp)
! get info of fm_mat_Q_static_bse and compute ((1+Q(0))^-1-1)
CALL cp_fm_get_info(matrix=fm_mat_Q_static_bse_gemm, &
nrow_local=nrow_local, &
ncol_local=ncol_local, &
row_indices=row_indices, &
col_indices=col_indices)
DO jjB = 1, ncol_local
j_global = col_indices(jjB)
DO iiB = 1, nrow_local
i_global = row_indices(iiB)
IF (j_global == i_global .AND. i_global <= dimen_RI) THEN
fm_mat_Q_static_bse_gemm%local_data(iiB, jjB) = fm_mat_Q_static_bse_gemm%local_data(iiB, jjB) + 1.0_dp
END IF
END DO
END DO
! calculate Trace(Log(Matrix)) as Log(DET(Matrix)) via cholesky decomposition
CALL cp_fm_cholesky_decompose(matrix=fm_mat_Q_static_bse_gemm, n=dimen_RI, info_out=info_chol)
CPASSERT(info_chol == 0)
! calculate [1+Q(i0)]^-1
CALL cp_fm_cholesky_invert(fm_mat_Q_static_bse_gemm)
! symmetrize the result
CALL cp_fm_upper_to_full(fm_mat_Q_static_bse_gemm, fm_work)
CALL parallel_gemm(transa="N", transb="N", m=dimen_RI, n=homo**2, k=dimen_RI, alpha=1.0_dp, &
matrix_a=fm_mat_Q_static_bse_gemm, matrix_b=fm_mat_S_ij_bse, beta=0.0_dp, &
matrix_c=fm_mat_S_bar_ij_bse)
! fm_mat_S_bar_ia_bse has a different blacs_env as fm_mat_S_ij_bse since we take
! fm_mat_S_ia_bse from RPA. Therefore, we also need a different fm_mat_Q_static_bse_gemm
CALL parallel_gemm(transa="N", transb="N", m=dimen_RI, n=homo*virtual, k=dimen_RI, alpha=1.0_dp, &
matrix_a=fm_mat_Q_static_bse_gemm, matrix_b=fm_mat_S_ia_bse, beta=0.0_dp, &
matrix_c=fm_mat_S_bar_ia_bse)
CALL cp_fm_release(fm_work)
CALL timestop(handle)
END SUBROUTINE
! **************************************************************************************************
!> \brief Adds and reorders full matrices with a combined index structure, e.g. adding W_ij,ab
!> to A_ia, jb which needs MPI communication.
!> \param fm_out ...
!> \param fm_in ...
!> \param beta ...
!> \param nrow_secidx_in ...
!> \param ncol_secidx_in ...
!> \param nrow_secidx_out ...
!> \param ncol_secidx_out ...
!> \param unit_nr ...
!> \param reordering ...
!> \param mp2_env ...
! **************************************************************************************************
SUBROUTINE fm_general_add_bse(fm_out, fm_in, beta, nrow_secidx_in, ncol_secidx_in, &
nrow_secidx_out, ncol_secidx_out, unit_nr, reordering, mp2_env)
TYPE(cp_fm_type), INTENT(INOUT) :: fm_out
TYPE(cp_fm_type), INTENT(IN) :: fm_in
REAL(kind=dp) :: beta
INTEGER, INTENT(IN) :: nrow_secidx_in, ncol_secidx_in, &
nrow_secidx_out, ncol_secidx_out
INTEGER :: unit_nr
INTEGER, DIMENSION(4) :: reordering
TYPE(mp2_type), INTENT(IN) :: mp2_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'fm_general_add_bse'
INTEGER :: col_idx_loc, dummy, handle, handle2, i_entry_rec, idx_col_out, idx_row_out, ii, &
iproc, jj, ncol_block_in, ncol_block_out, ncol_local_in, ncol_local_out, nprocs, &
nrow_block_in, nrow_block_out, nrow_local_in, nrow_local_out, proc_send, row_idx_loc, &
send_pcol, send_prow
INTEGER, ALLOCATABLE, DIMENSION(:) :: entry_counter, num_entries_rec, &
num_entries_send
INTEGER, DIMENSION(4) :: indices_in
INTEGER, DIMENSION(:), POINTER :: col_indices_in, col_indices_out, &
row_indices_in, row_indices_out
TYPE(integ_mat_buffer_type), ALLOCATABLE, &
DIMENSION(:) :: buffer_rec, buffer_send
TYPE(mp_para_env_type), POINTER :: para_env_out
TYPE(mp_request_type), DIMENSION(:, :), POINTER :: req_array
CALL timeset(routineN, handle)
CALL timeset(routineN//"_1_setup", handle2)
para_env_out => fm_out%matrix_struct%para_env
! A_iajb
! We start by moving data from local parts of W_ijab to the full matrix A_iajb using buffers
CALL cp_fm_get_info(matrix=fm_out, &
nrow_local=nrow_local_out, &
ncol_local=ncol_local_out, &
row_indices=row_indices_out, &
col_indices=col_indices_out, &
nrow_block=nrow_block_out, &
ncol_block=ncol_block_out)
ALLOCATE (num_entries_rec(0:para_env_out%num_pe - 1))
ALLOCATE (num_entries_send(0:para_env_out%num_pe - 1))
num_entries_rec(:) = 0
num_entries_send(:) = 0
dummy = 0
CALL cp_fm_get_info(matrix=fm_in, &
nrow_local=nrow_local_in, &
ncol_local=ncol_local_in, &
row_indices=row_indices_in, &
col_indices=col_indices_in, &
nrow_block=nrow_block_in, &
ncol_block=ncol_block_in)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A14,A10,T71,I10)') 'BSE|DEBUG|', 'Row number of ', fm_out%name, &
fm_out%matrix_struct%nrow_global
WRITE (unit_nr, '(T2,A10,T13,A17,A10,T71,I10)') 'BSE|DEBUG|', 'Column number of ', fm_out%name, &
fm_out%matrix_struct%ncol_global
WRITE (unit_nr, '(T2,A10,T13,A18,A10,T71,I10)') 'BSE|DEBUG|', 'Row block size of ', fm_out%name, nrow_block_out
WRITE (unit_nr, '(T2,A10,T13,A21,A10,T71,I10)') 'BSE|DEBUG|', 'Column block size of ', fm_out%name, ncol_block_out
WRITE (unit_nr, '(T2,A10,T13,A14,A10,T71,I10)') 'BSE|DEBUG|', 'Row number of ', fm_in%name, &
fm_in%matrix_struct%nrow_global
WRITE (unit_nr, '(T2,A10,T13,A17,A10,T71,I10)') 'BSE|DEBUG|', 'Column number of ', fm_in%name, &
fm_in%matrix_struct%ncol_global
WRITE (unit_nr, '(T2,A10,T13,A18,A10,T71,I10)') 'BSE|DEBUG|', 'Row block size of ', fm_in%name, nrow_block_in
WRITE (unit_nr, '(T2,A10,T13,A21,A10,T71,I10)') 'BSE|DEBUG|', 'Column block size of ', fm_in%name, ncol_block_in
END IF
! Use scalapack wrapper to find process index in fm_out
! To that end, we obtain the global index in fm_out from the level indices
indices_in(:) = 0
DO row_idx_loc = 1, nrow_local_in
indices_in(1) = (row_indices_in(row_idx_loc) - 1)/nrow_secidx_in + 1
indices_in(2) = MOD(row_indices_in(row_idx_loc) - 1, nrow_secidx_in) + 1
DO col_idx_loc = 1, ncol_local_in
indices_in(3) = (col_indices_in(col_idx_loc) - 1)/ncol_secidx_in + 1
indices_in(4) = MOD(col_indices_in(col_idx_loc) - 1, ncol_secidx_in) + 1
idx_row_out = indices_in(reordering(2)) + (indices_in(reordering(1)) - 1)*nrow_secidx_out
idx_col_out = indices_in(reordering(4)) + (indices_in(reordering(3)) - 1)*ncol_secidx_out
send_prow = fm_out%matrix_struct%g2p_row(idx_row_out)
send_pcol = fm_out%matrix_struct%g2p_col(idx_col_out)
proc_send = fm_out%matrix_struct%context%blacs2mpi(send_prow, send_pcol)
num_entries_send(proc_send) = num_entries_send(proc_send) + 1
END DO
END DO
CALL timestop(handle2)
CALL timeset(routineN//"_2_comm_entry_nums", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A27)') 'BSE|DEBUG|', 'Communicating entry numbers'
END IF
CALL para_env_out%alltoall(num_entries_send, num_entries_rec, 1)
CALL timestop(handle2)
CALL timeset(routineN//"_3_alloc_buffer", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A18)') 'BSE|DEBUG|', 'Allocating buffers'
END IF
! Buffers for entries and their indices
ALLOCATE (buffer_rec(0:para_env_out%num_pe - 1))
ALLOCATE (buffer_send(0:para_env_out%num_pe - 1))
! allocate data message and corresponding indices
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_rec(iproc)%msg(num_entries_rec(iproc)))
buffer_rec(iproc)%msg = 0.0_dp
END DO
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_send(iproc)%msg(num_entries_send(iproc)))
buffer_send(iproc)%msg = 0.0_dp
END DO
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_rec(iproc)%indx(num_entries_rec(iproc), 2))
buffer_rec(iproc)%indx = 0
END DO
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_send(iproc)%indx(num_entries_send(iproc), 2))
buffer_send(iproc)%indx = 0
END DO
CALL timestop(handle2)
CALL timeset(routineN//"_4_buf_from_fmin_"//fm_out%name, handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A18,A10,A13)') 'BSE|DEBUG|', 'Writing data from ', fm_in%name, ' into buffers'
END IF
ALLOCATE (entry_counter(0:para_env_out%num_pe - 1))
entry_counter(:) = 0
! Now we can write the actual data and indices to the send-buffer
DO row_idx_loc = 1, nrow_local_in
indices_in(1) = (row_indices_in(row_idx_loc) - 1)/nrow_secidx_in + 1
indices_in(2) = MOD(row_indices_in(row_idx_loc) - 1, nrow_secidx_in) + 1
DO col_idx_loc = 1, ncol_local_in
indices_in(3) = (col_indices_in(col_idx_loc) - 1)/ncol_secidx_in + 1
indices_in(4) = MOD(col_indices_in(col_idx_loc) - 1, ncol_secidx_in) + 1
idx_row_out = indices_in(reordering(2)) + (indices_in(reordering(1)) - 1)*nrow_secidx_out
idx_col_out = indices_in(reordering(4)) + (indices_in(reordering(3)) - 1)*ncol_secidx_out
send_prow = fm_out%matrix_struct%g2p_row(idx_row_out)
send_pcol = fm_out%matrix_struct%g2p_col(idx_col_out)
proc_send = fm_out%matrix_struct%context%blacs2mpi(send_prow, send_pcol)
entry_counter(proc_send) = entry_counter(proc_send) + 1
buffer_send(proc_send)%msg(entry_counter(proc_send)) = &
fm_in%local_data(row_idx_loc, col_idx_loc)
buffer_send(proc_send)%indx(entry_counter(proc_send), 1) = idx_row_out
buffer_send(proc_send)%indx(entry_counter(proc_send), 2) = idx_col_out
END DO
END DO
ALLOCATE (req_array(1:para_env_out%num_pe, 4))
CALL timestop(handle2)
CALL timeset(routineN//"_5_comm_buffer", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A21)') 'BSE|DEBUG|', 'Communicating buffers'
END IF
! communicate the buffer
CALL communicate_buffer(para_env_out, num_entries_rec, num_entries_send, buffer_rec, &
buffer_send, req_array)
CALL timestop(handle2)
CALL timeset(routineN//"_6_buffer_to_fmout"//fm_out%name, handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A24,A10)') 'BSE|DEBUG|', 'Writing from buffers to ', fm_out%name
END IF
! fill fm_out with the entries from buffer_rec, i.e. buffer_rec are parts of fm_in
nprocs = para_env_out%num_pe
!$OMP PARALLEL DO DEFAULT(NONE) &
!$OMP SHARED(fm_out, nprocs, num_entries_rec, buffer_rec, beta) &
!$OMP PRIVATE(iproc, i_entry_rec, ii, jj)
DO iproc = 0, nprocs - 1
DO i_entry_rec = 1, num_entries_rec(iproc)
ii = fm_out%matrix_struct%g2l_row(buffer_rec(iproc)%indx(i_entry_rec, 1))
jj = fm_out%matrix_struct%g2l_col(buffer_rec(iproc)%indx(i_entry_rec, 2))
fm_out%local_data(ii, jj) = fm_out%local_data(ii, jj) + beta*buffer_rec(iproc)%msg(i_entry_rec)
END DO
END DO
!$OMP END PARALLEL DO
CALL timestop(handle2)
CALL timeset(routineN//"_7_cleanup", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A41)') 'BSE|DEBUG|', 'Starting cleanup of communication buffers'
END IF
!Clean up all the arrays from the communication process
DO iproc = 0, para_env_out%num_pe - 1
DEALLOCATE (buffer_rec(iproc)%msg)
DEALLOCATE (buffer_rec(iproc)%indx)
DEALLOCATE (buffer_send(iproc)%msg)
DEALLOCATE (buffer_send(iproc)%indx)
END DO
DEALLOCATE (buffer_rec, buffer_send)
DEALLOCATE (req_array)
DEALLOCATE (entry_counter)
DEALLOCATE (num_entries_rec, num_entries_send)
CALL timestop(handle2)
CALL timestop(handle)
END SUBROUTINE fm_general_add_bse
! **************************************************************************************************
!> \brief Routine for truncating a full matrix as given by the energy cutoffs in the input file.
!> Logic: Matrices have some dimension dimen_RI x nrow_in*ncol_in for the incoming (untruncated) matrix
!> and dimen_RI x nrow_out*ncol_out for the truncated matrix. The truncation is done by resorting the indices
!> via parallel communication.
!> \param fm_out ...
!> \param fm_in ...
!> \param ncol_in ...
!> \param nrow_out ...
!> \param ncol_out ...
!> \param unit_nr ...
!> \param mp2_env ...
!> \param nrow_offset ...
!> \param ncol_offset ...
! **************************************************************************************************
SUBROUTINE truncate_fm(fm_out, fm_in, ncol_in, &
nrow_out, ncol_out, unit_nr, mp2_env, &
nrow_offset, ncol_offset)
TYPE(cp_fm_type), INTENT(INOUT) :: fm_out
TYPE(cp_fm_type), INTENT(IN) :: fm_in
INTEGER :: ncol_in, nrow_out, ncol_out, unit_nr
TYPE(mp2_type), INTENT(INOUT) :: mp2_env
INTEGER, INTENT(IN), OPTIONAL :: nrow_offset, ncol_offset
CHARACTER(LEN=*), PARAMETER :: routineN = 'truncate_fm'
INTEGER :: col_idx_loc, dummy, handle, handle2, i_entry_rec, idx_col_first, idx_col_in, &
idx_col_out, idx_col_sec, idx_row_in, ii, iproc, jj, ncol_block_in, ncol_block_out, &
ncol_local_in, ncol_local_out, nprocs, nrow_block_in, nrow_block_out, nrow_local_in, &
nrow_local_out, proc_send, row_idx_loc, send_pcol, send_prow
INTEGER, ALLOCATABLE, DIMENSION(:) :: entry_counter, num_entries_rec, &
num_entries_send
INTEGER, DIMENSION(:), POINTER :: col_indices_in, col_indices_out, &
row_indices_in, row_indices_out
LOGICAL :: correct_ncol, correct_nrow
TYPE(integ_mat_buffer_type), ALLOCATABLE, &
DIMENSION(:) :: buffer_rec, buffer_send
TYPE(mp_para_env_type), POINTER :: para_env_out
TYPE(mp_request_type), DIMENSION(:, :), POINTER :: req_array
CALL timeset(routineN, handle)
CALL timeset(routineN//"_1_setup", handle2)
correct_nrow = .FALSE.
correct_ncol = .FALSE.
!In case of truncation in the occupied space, we need to correct the interval of indices
IF (PRESENT(nrow_offset)) THEN
correct_nrow = .TRUE.
END IF
IF (PRESENT(ncol_offset)) THEN
correct_ncol = .TRUE.
END IF
para_env_out => fm_out%matrix_struct%para_env
CALL cp_fm_get_info(matrix=fm_out, &
nrow_local=nrow_local_out, &
ncol_local=ncol_local_out, &
row_indices=row_indices_out, &
col_indices=col_indices_out, &
nrow_block=nrow_block_out, &
ncol_block=ncol_block_out)
ALLOCATE (num_entries_rec(0:para_env_out%num_pe - 1))
ALLOCATE (num_entries_send(0:para_env_out%num_pe - 1))
num_entries_rec(:) = 0
num_entries_send(:) = 0
dummy = 0
CALL cp_fm_get_info(matrix=fm_in, &
nrow_local=nrow_local_in, &
ncol_local=ncol_local_in, &
row_indices=row_indices_in, &
col_indices=col_indices_in, &
nrow_block=nrow_block_in, &
ncol_block=ncol_block_in)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A14,A10,T71,I10)') 'BSE|DEBUG|', 'Row number of ', fm_out%name, &
fm_out%matrix_struct%nrow_global
WRITE (unit_nr, '(T2,A10,T13,A17,A10,T71,I10)') 'BSE|DEBUG|', 'Column number of ', fm_out%name, &
fm_out%matrix_struct%ncol_global
WRITE (unit_nr, '(T2,A10,T13,A18,A10,T71,I10)') 'BSE|DEBUG|', 'Row block size of ', fm_out%name, nrow_block_out
WRITE (unit_nr, '(T2,A10,T13,A21,A10,T71,I10)') 'BSE|DEBUG|', 'Column block size of ', fm_out%name, ncol_block_out
WRITE (unit_nr, '(T2,A10,T13,A14,A10,T71,I10)') 'BSE|DEBUG|', 'Row number of ', fm_in%name, &
fm_in%matrix_struct%nrow_global
WRITE (unit_nr, '(T2,A10,T13,A17,A10,T71,I10)') 'BSE|DEBUG|', 'Column number of ', fm_in%name, &
fm_in%matrix_struct%ncol_global
WRITE (unit_nr, '(T2,A10,T13,A18,A10,T71,I10)') 'BSE|DEBUG|', 'Row block size of ', fm_in%name, nrow_block_in
WRITE (unit_nr, '(T2,A10,T13,A21,A10,T71,I10)') 'BSE|DEBUG|', 'Column block size of ', fm_in%name, ncol_block_in
END IF
! We find global indices in S with nrow_in and ncol_in for truncation
DO col_idx_loc = 1, ncol_local_in
idx_col_in = col_indices_in(col_idx_loc)
idx_col_first = (idx_col_in - 1)/ncol_in + 1
idx_col_sec = MOD(idx_col_in - 1, ncol_in) + 1
! If occupied orbitals are included, these have to be handled differently
! due to their reversed indexing
IF (correct_nrow) THEN
idx_col_first = idx_col_first - nrow_offset + 1
IF (idx_col_first .LE. 0) CYCLE
ELSE
IF (idx_col_first > nrow_out) EXIT
END IF
IF (correct_ncol) THEN
idx_col_sec = idx_col_sec - ncol_offset + 1
IF (idx_col_sec .LE. 0) CYCLE
ELSE
IF (idx_col_sec > ncol_out) CYCLE
END IF
idx_col_out = idx_col_sec + (idx_col_first - 1)*ncol_out
DO row_idx_loc = 1, nrow_local_in
idx_row_in = row_indices_in(row_idx_loc)
send_prow = fm_out%matrix_struct%g2p_row(idx_row_in)
send_pcol = fm_out%matrix_struct%g2p_col(idx_col_out)
proc_send = fm_out%matrix_struct%context%blacs2mpi(send_prow, send_pcol)
num_entries_send(proc_send) = num_entries_send(proc_send) + 1
END DO
END DO
CALL timestop(handle2)
CALL timeset(routineN//"_2_comm_entry_nums", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A27)') 'BSE|DEBUG|', 'Communicating entry numbers'
END IF
CALL para_env_out%alltoall(num_entries_send, num_entries_rec, 1)
CALL timestop(handle2)
CALL timeset(routineN//"_3_alloc_buffer", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A18)') 'BSE|DEBUG|', 'Allocating buffers'
END IF
! Buffers for entries and their indices
ALLOCATE (buffer_rec(0:para_env_out%num_pe - 1))
ALLOCATE (buffer_send(0:para_env_out%num_pe - 1))
! allocate data message and corresponding indices
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_rec(iproc)%msg(num_entries_rec(iproc)))
buffer_rec(iproc)%msg = 0.0_dp
END DO
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_send(iproc)%msg(num_entries_send(iproc)))
buffer_send(iproc)%msg = 0.0_dp
END DO
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_rec(iproc)%indx(num_entries_rec(iproc), 2))
buffer_rec(iproc)%indx = 0
END DO
DO iproc = 0, para_env_out%num_pe - 1
ALLOCATE (buffer_send(iproc)%indx(num_entries_send(iproc), 2))
buffer_send(iproc)%indx = 0
END DO
CALL timestop(handle2)
CALL timeset(routineN//"_4_buf_from_fmin_"//fm_out%name, handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A18,A10,A13)') 'BSE|DEBUG|', 'Writing data from ', fm_in%name, ' into buffers'
END IF
ALLOCATE (entry_counter(0:para_env_out%num_pe - 1))
entry_counter(:) = 0
! Now we can write the actual data and indices to the send-buffer
DO col_idx_loc = 1, ncol_local_in
idx_col_in = col_indices_in(col_idx_loc)
idx_col_first = (idx_col_in - 1)/ncol_in + 1
idx_col_sec = MOD(idx_col_in - 1, ncol_in) + 1
! If occupied orbitals are included, these have to be handled differently
! due to their reversed indexing
IF (correct_nrow) THEN
idx_col_first = idx_col_first - nrow_offset + 1
IF (idx_col_first .LE. 0) CYCLE
ELSE
IF (idx_col_first > nrow_out) EXIT
END IF
IF (correct_ncol) THEN
idx_col_sec = idx_col_sec - ncol_offset + 1
IF (idx_col_sec .LE. 0) CYCLE
ELSE
IF (idx_col_sec > ncol_out) CYCLE
END IF
idx_col_out = idx_col_sec + (idx_col_first - 1)*ncol_out
DO row_idx_loc = 1, nrow_local_in
idx_row_in = row_indices_in(row_idx_loc)
send_prow = fm_out%matrix_struct%g2p_row(idx_row_in)
send_pcol = fm_out%matrix_struct%g2p_col(idx_col_out)
proc_send = fm_out%matrix_struct%context%blacs2mpi(send_prow, send_pcol)
entry_counter(proc_send) = entry_counter(proc_send) + 1
buffer_send(proc_send)%msg(entry_counter(proc_send)) = &
fm_in%local_data(row_idx_loc, col_idx_loc)
!No need to create row_out, since it is identical to incoming
!We dont change the RI index for any fm_mat_XX_BSE
buffer_send(proc_send)%indx(entry_counter(proc_send), 1) = idx_row_in
buffer_send(proc_send)%indx(entry_counter(proc_send), 2) = idx_col_out
END DO
END DO
ALLOCATE (req_array(1:para_env_out%num_pe, 4))
CALL timestop(handle2)
CALL timeset(routineN//"_5_comm_buffer", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A21)') 'BSE|DEBUG|', 'Communicating buffers'
END IF
! communicate the buffer
CALL communicate_buffer(para_env_out, num_entries_rec, num_entries_send, buffer_rec, &
buffer_send, req_array)
CALL timestop(handle2)
CALL timeset(routineN//"_6_buffer_to_fmout"//fm_out%name, handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A24,A10)') 'BSE|DEBUG|', 'Writing from buffers to ', fm_out%name
END IF
! fill fm_out with the entries from buffer_rec, i.e. buffer_rec are parts of fm_in
nprocs = para_env_out%num_pe
!$OMP PARALLEL DO DEFAULT(NONE) &
!$OMP SHARED(fm_out, nprocs, num_entries_rec, buffer_rec) &
!$OMP PRIVATE(iproc, i_entry_rec, ii, jj)
DO iproc = 0, nprocs - 1
DO i_entry_rec = 1, num_entries_rec(iproc)
ii = fm_out%matrix_struct%g2l_row(buffer_rec(iproc)%indx(i_entry_rec, 1))
jj = fm_out%matrix_struct%g2l_col(buffer_rec(iproc)%indx(i_entry_rec, 2))
fm_out%local_data(ii, jj) = fm_out%local_data(ii, jj) + buffer_rec(iproc)%msg(i_entry_rec)
END DO
END DO
!$OMP END PARALLEL DO
CALL timestop(handle2)
CALL timeset(routineN//"_7_cleanup", handle2)
IF (unit_nr > 0 .AND. mp2_env%bse%bse_debug_print) THEN
WRITE (unit_nr, '(T2,A10,T13,A41)') 'BSE|DEBUG|', 'Starting cleanup of communication buffers'
END IF
!Clean up all the arrays from the communication process
DO iproc = 0, para_env_out%num_pe - 1
DEALLOCATE (buffer_rec(iproc)%msg)
DEALLOCATE (buffer_rec(iproc)%indx)
DEALLOCATE (buffer_send(iproc)%msg)
DEALLOCATE (buffer_send(iproc)%indx)
END DO
DEALLOCATE (buffer_rec, buffer_send)
DEALLOCATE (req_array)
DEALLOCATE (entry_counter)
DEALLOCATE (num_entries_rec, num_entries_send)
CALL timestop(handle2)
CALL timestop(handle)
END SUBROUTINE truncate_fm
! **************************************************************************************************
!> \brief ...
!> \param fm_mat_S_bar_ia_bse ...
!> \param fm_mat_S_bar_ij_bse ...
!> \param fm_mat_S_trunc ...
!> \param fm_mat_S_ij_trunc ...
!> \param fm_mat_S_ab_trunc ...
!> \param fm_mat_Q_static_bse_gemm ...
!> \param mp2_env ...
! **************************************************************************************************
SUBROUTINE deallocate_matrices_bse(fm_mat_S_bar_ia_bse, fm_mat_S_bar_ij_bse, &
fm_mat_S_trunc, fm_mat_S_ij_trunc, fm_mat_S_ab_trunc, &
fm_mat_Q_static_bse_gemm, mp2_env)
TYPE(cp_fm_type), INTENT(INOUT) :: fm_mat_S_bar_ia_bse, fm_mat_S_bar_ij_bse, fm_mat_S_trunc, &
fm_mat_S_ij_trunc, fm_mat_S_ab_trunc, fm_mat_Q_static_bse_gemm
TYPE(mp2_type) :: mp2_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'deallocate_matrices_bse'
INTEGER :: handle
CALL timeset(routineN, handle)
CALL cp_fm_release(fm_mat_S_bar_ia_bse)
CALL cp_fm_release(fm_mat_S_bar_ij_bse)
CALL cp_fm_release(fm_mat_S_trunc)
CALL cp_fm_release(fm_mat_S_ij_trunc)
CALL cp_fm_release(fm_mat_S_ab_trunc)
CALL cp_fm_release(fm_mat_Q_static_bse_gemm)
IF (mp2_env%bse%do_nto_analysis) THEN
DEALLOCATE (mp2_env%bse%bse_nto_state_list_final)
END IF
CALL timestop(handle)
END SUBROUTINE deallocate_matrices_bse
! **************************************************************************************************
!> \brief Routine for computing the coefficients of the eigenvectors of the BSE matrix from a
!> multiplication with the eigenvalues
!> \param fm_work ...
!> \param eig_vals ...
!> \param beta ...
!> \param gamma ...
!> \param do_transpose ...
! **************************************************************************************************
SUBROUTINE comp_eigvec_coeff_BSE(fm_work, eig_vals, beta, gamma, do_transpose)
TYPE(cp_fm_type), INTENT(INOUT) :: fm_work
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(IN) :: eig_vals
REAL(KIND=dp), INTENT(IN) :: beta
REAL(KIND=dp), INTENT(IN), OPTIONAL :: gamma
LOGICAL, INTENT(IN), OPTIONAL :: do_transpose
CHARACTER(LEN=*), PARAMETER :: routineN = 'comp_eigvec_coeff_BSE'
INTEGER :: handle, i_row_global, ii, j_col_global, &
jj, ncol_local, nrow_local
INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
LOGICAL :: my_do_transpose
REAL(KIND=dp) :: coeff, my_gamma
CALL timeset(routineN, handle)
IF (PRESENT(gamma)) THEN
my_gamma = gamma
ELSE
my_gamma = 2.0_dp
END IF
IF (PRESENT(do_transpose)) THEN
my_do_transpose = do_transpose
ELSE
my_do_transpose = .FALSE.
END IF
CALL cp_fm_get_info(matrix=fm_work, &
nrow_local=nrow_local, &
ncol_local=ncol_local, &
row_indices=row_indices, &
col_indices=col_indices)
IF (my_do_transpose) THEN
DO jj = 1, ncol_local
j_col_global = col_indices(jj)
DO ii = 1, nrow_local
coeff = (eig_vals(j_col_global)**beta)/my_gamma
fm_work%local_data(ii, jj) = fm_work%local_data(ii, jj)*coeff
END DO
END DO
ELSE
DO jj = 1, ncol_local
DO ii = 1, nrow_local
i_row_global = row_indices(ii)
coeff = (eig_vals(i_row_global)**beta)/my_gamma
fm_work%local_data(ii, jj) = fm_work%local_data(ii, jj)*coeff
END DO
END DO
END IF
CALL timestop(handle)
END SUBROUTINE
! **************************************************************************************************
!> \brief ...
!> \param idx_prim ...
!> \param idx_sec ...
!> \param eigvec_entries ...
! **************************************************************************************************
SUBROUTINE sort_excitations(idx_prim, idx_sec, eigvec_entries)
INTEGER, ALLOCATABLE, DIMENSION(:) :: idx_prim, idx_sec
REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigvec_entries
CHARACTER(LEN=*), PARAMETER :: routineN = 'sort_excitations'
INTEGER :: handle, ii, kk, num_entries, num_mults
INTEGER, ALLOCATABLE, DIMENSION(:) :: idx_prim_work, idx_sec_work, tmp_index
LOGICAL :: unique_entries
REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigvec_entries_work
CALL timeset(routineN, handle)
num_entries = SIZE(idx_prim)
ALLOCATE (tmp_index(num_entries))
CALL sort(idx_prim, num_entries, tmp_index)
ALLOCATE (idx_sec_work(num_entries))
ALLOCATE (eigvec_entries_work(num_entries))
DO ii = 1, num_entries
idx_sec_work(ii) = idx_sec(tmp_index(ii))
eigvec_entries_work(ii) = eigvec_entries(tmp_index(ii))
END DO
DEALLOCATE (tmp_index)
DEALLOCATE (idx_sec)
DEALLOCATE (eigvec_entries)
CALL MOVE_ALLOC(idx_sec_work, idx_sec)
CALL MOVE_ALLOC(eigvec_entries_work, eigvec_entries)
!Now check for multiple entries in first idx to check necessity of sorting in second idx
CALL sort_unique(idx_prim, unique_entries)
IF (.NOT. unique_entries) THEN
ALLOCATE (idx_prim_work(num_entries))
idx_prim_work(:) = idx_prim(:)
! Find duplicate entries in idx_prim
DO ii = 1, num_entries
IF (idx_prim_work(ii) == 0) CYCLE
num_mults = COUNT(idx_prim_work == idx_prim_work(ii))
IF (num_mults > 1) THEN
!Set all duplicate entries to 0
idx_prim_work(ii:ii + num_mults - 1) = 0
!Start sorting in secondary index
ALLOCATE (idx_sec_work(num_mults))
ALLOCATE (eigvec_entries_work(num_mults))
idx_sec_work(:) = idx_sec(ii:ii + num_mults - 1)
eigvec_entries_work(:) = eigvec_entries(ii:ii + num_mults - 1)
ALLOCATE (tmp_index(num_mults))
CALL sort(idx_sec_work, num_mults, tmp_index)
!Now write newly sorted indices to original arrays
DO kk = ii, ii + num_mults - 1
idx_sec(kk) = idx_sec_work(kk - ii + 1)
eigvec_entries(kk) = eigvec_entries_work(tmp_index(kk - ii + 1))
END DO
!Deallocate work arrays
DEALLOCATE (tmp_index)
DEALLOCATE (idx_sec_work)
DEALLOCATE (eigvec_entries_work)
END IF
idx_prim_work(ii) = idx_prim(ii)
END DO
DEALLOCATE (idx_prim_work)
END IF
CALL timestop(handle)
END SUBROUTINE sort_excitations
! **************************************************************************************************
!> \brief Roughly estimates the needed runtime and memory during the BSE run
!> \param homo_red ...
!> \param virtual_red ...
!> \param unit_nr ...
!> \param bse_abba ...
!> \param para_env ...
!> \param diag_runtime_est ...
! **************************************************************************************************
SUBROUTINE estimate_BSE_resources(homo_red, virtual_red, unit_nr, bse_abba, &
para_env, diag_runtime_est)
INTEGER :: homo_red, virtual_red, unit_nr
LOGICAL :: bse_abba
TYPE(mp_para_env_type), POINTER :: para_env
REAL(KIND=dp) :: diag_runtime_est
CHARACTER(LEN=*), PARAMETER :: routineN = 'estimate_BSE_resources'
INTEGER :: handle, num_BSE_matrices
INTEGER(KIND=int_8) :: full_dim
REAL(KIND=dp) :: mem_est, mem_est_per_rank
CALL timeset(routineN, handle)
! Number of matrices with size of A in TDA is 2 (A itself and W_ijab)
num_BSE_matrices = 2
! With the full diagonalization of ABBA, we need several auxiliary matrices in the process
! The maximum number is 2 + 2 + 6 (additional B and C matrix as well as 6 matrices to create C)
IF (bse_abba) THEN
num_BSE_matrices = 10
END IF
full_dim = (INT(homo_red, KIND=int_8)**2*INT(virtual_red, KIND=int_8)**2)*INT(num_BSE_matrices, KIND=int_8)
mem_est = REAL(8*full_dim, KIND=dp)/REAL(1024**3, KIND=dp)
mem_est_per_rank = REAL(mem_est/para_env%num_pe, KIND=dp)
IF (unit_nr > 0) THEN
! WRITE (unit_nr, '(T2,A4,T7,A40,T68,F13.3)') 'BSE|', 'Total peak memory estimate from BSE [GB]', &
! mem_est
WRITE (unit_nr, '(T2,A4,T7,A40,T68,ES13.3)') 'BSE|', 'Total peak memory estimate from BSE [GB]', &
mem_est
WRITE (unit_nr, '(T2,A4,T7,A47,T68,F13.3)') 'BSE|', 'Peak memory estimate per MPI rank from BSE [GB]', &
mem_est_per_rank
WRITE (unit_nr, '(T2,A4)') 'BSE|'
END IF
! Rough estimation of diagonalization runtimes. Baseline was a full BSE Naphthalene
! run with 11000x11000 entries in A/B/C, which took 10s on 32 ranks
diag_runtime_est = REAL(INT(homo_red, KIND=int_8)*INT(virtual_red, KIND=int_8)/11000_int_8, KIND=dp)**3* &
10*32/REAL(para_env%num_pe, KIND=dp)
CALL timestop(handle)
END SUBROUTINE estimate_BSE_resources
! **************************************************************************************************
!> \brief Filters eigenvector entries above a given threshold to describe excitations in the
!> singleparticle basis
!> \param fm_eigvec ...
!> \param idx_homo ...
!> \param idx_virt ...
!> \param eigvec_entries ...
!> \param i_exc ...
!> \param virtual ...
!> \param num_entries ...
!> \param mp2_env ...
! **************************************************************************************************
SUBROUTINE filter_eigvec_contrib(fm_eigvec, idx_homo, idx_virt, eigvec_entries, &
i_exc, virtual, num_entries, mp2_env)
TYPE(cp_fm_type), INTENT(IN) :: fm_eigvec
INTEGER, ALLOCATABLE, DIMENSION(:) :: idx_homo, idx_virt
REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigvec_entries
INTEGER :: i_exc, virtual, num_entries
TYPE(mp2_type), INTENT(INOUT) :: mp2_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'filter_eigvec_contrib'
INTEGER :: eigvec_idx, handle, ii, iproc, jj, kk, &