mpi_col_den.F90 17.3 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11
MODULE m_mpi_col_den
  !
  ! collect all data calculated in cdnval on different pe's on pe 0
  !
CONTAINS
12 13 14
  SUBROUTINE mpi_col_den(mpi,sphhar,atoms,oneD,stars,vacuum,&
       input, noco,l_fmpl,jspin,llpd,rhtxy,rht,qpw,ener,&
       sqal,results,svac,pvac,uu,dd,du,uunmt,ddnmt,udnmt,dunmt,sqlo,&
15
       aclo,bclo,cclo,acnmt,bcnmt,ccnmt,enerlo,orb,mt21,lo21,uloulop21,&
16
       uunmt21,ddnmt21,udnmt21,dunmt21,den,n_mmp)
17 18 19
    !
#include"cpp_double.h"
    USE m_types
20
    USE m_constants
21 22
    IMPLICIT NONE

23 24 25 26 27 28 29 30 31
    TYPE(t_results),INTENT(INOUT):: results
    TYPE(t_mpi),INTENT(IN)       :: mpi
    TYPE(t_oneD),INTENT(IN)      :: oneD 
    TYPE(t_input),INTENT(IN)     :: input 
    TYPE(t_vacuum),INTENT(IN)    :: vacuum 
    TYPE(t_noco),INTENT(IN)      :: noco 
    TYPE(t_stars),INTENT(IN)     :: stars 
    TYPE(t_sphhar),INTENT(IN)    :: sphhar 
    TYPE(t_atoms),INTENT(IN)     :: atoms
32
    TYPE(t_potden),INTENT(INOUT) :: den
33 34 35 36 37 38 39
    INCLUDE 'mpif.h'
    ! ..
    ! ..  Scalar Arguments ..
    INTEGER, INTENT (IN) :: jspin,llpd
    LOGICAL, INTENT (IN) :: l_fmpl
    ! ..
    ! ..  Array Arguments ..
40
    COMPLEX, INTENT (INOUT) :: qpw(stars%ng3)
41 42
    COMPLEX, INTENT (INOUT) :: rhtxy(vacuum%nmzxyd,oneD%odi%n2d-1,2)
    REAL,    INTENT (INOUT) :: rht(vacuum%nmzd,2) 
43
    REAL,    INTENT (INOUT) :: ener(0:3,atoms%ntype),sqal(0:3,atoms%ntype)
44
    REAL,    INTENT (INOUT) :: svac(2),pvac(2)
45 46 47 48 49 50 51 52 53 54 55 56 57
    REAL,  INTENT (INOUT) :: dd(0:atoms%lmaxd,atoms%ntype)
    REAL,  INTENT (INOUT) :: du(0:atoms%lmaxd,atoms%ntype)
    REAL,  INTENT (INOUT) :: uu(0:atoms%lmaxd,atoms%ntype)
    REAL,  INTENT (INOUT) :: ddnmt(0:llpd,sphhar%nlhd,atoms%ntype)
    REAL,  INTENT (INOUT) :: dunmt(0:llpd,sphhar%nlhd,atoms%ntype)
    REAL,  INTENT (INOUT) :: udnmt(0:llpd,sphhar%nlhd,atoms%ntype)
    REAL,  INTENT (INOUT) :: uunmt(0:llpd,sphhar%nlhd,atoms%ntype)
    REAL,  INTENT (INOUT) :: sqlo(atoms%nlod,atoms%ntype),enerlo(atoms%nlod,atoms%ntype)
    REAL,  INTENT (INOUT) :: aclo(atoms%nlod,atoms%ntype),bclo(atoms%nlod,atoms%ntype)
    REAL,  INTENT (INOUT) :: cclo(atoms%nlod,atoms%nlod,atoms%ntype)
    REAL,  INTENT (INOUT) :: acnmt(0:atoms%lmaxd,atoms%nlod,sphhar%nlhd,atoms%ntype)
    REAL,  INTENT (INOUT) :: bcnmt(0:atoms%lmaxd,atoms%nlod,sphhar%nlhd,atoms%ntype)
    REAL,  INTENT (INOUT) :: ccnmt(atoms%nlod,atoms%nlod,sphhar%nlhd,atoms%ntype)
58 59 60 61
    COMPLEX,INTENT(INOUT) :: ddnmt21((atoms%lmaxd+1)**2  )
    COMPLEX,INTENT(INOUT) :: dunmt21((atoms%lmaxd+1)**2  )
    COMPLEX,INTENT(INOUT) :: udnmt21((atoms%lmaxd+1)**2  )
    COMPLEX,INTENT(INOUT) :: uunmt21((atoms%lmaxd+1)**2  )
62
    COMPLEX,INTENT(INOUT) :: uloulop21(atoms%nlod,atoms%nlod,atoms%ntype)
63
    COMPLEX,INTENT(INOUT) :: n_mmp(-lmaxU_const:lmaxU_const,-lmaxU_const:lmaxU_const,atoms%n_u)
64
    TYPE (t_orb),  INTENT (INOUT) :: orb
65 66
    TYPE (t_mt21), INTENT (INOUT) :: mt21(0:atoms%lmaxd,atoms%ntype)
    TYPE (t_lo21), INTENT (INOUT) :: lo21(atoms%nlod,atoms%ntype)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    ! ..
    ! ..  Local Scalars ..
    INTEGER :: n
    ! ..
    ! ..  Local Arrays ..
    INTEGER :: ierr(3)
    COMPLEX, ALLOCATABLE :: c_b(:)
    REAL,    ALLOCATABLE :: r_b(:)
    ! ..
    ! ..  External Subroutines
    EXTERNAL CPP_BLAS_scopy,CPP_BLAS_ccopy,MPI_REDUCE

    !
    ! -> Collect qpw()
    !
82
    n = stars%ng3
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
    ALLOCATE(c_b(n))
    CALL MPI_REDUCE(qpw,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_ccopy(n, c_b, 1, qpw, 1)
    ENDIF
    DEALLOCATE (c_b)
    !
    ! -> Collect rhtxy()
    !
    IF (input%film) THEN

       n = vacuum%nmzxyd*(oneD%odi%n2d-1)*2
       ALLOCATE(c_b(n))
       CALL MPI_REDUCE(rhtxy,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_ccopy(n, c_b, 1, rhtxy, 1)
       ENDIF
       DEALLOCATE (c_b)
       !
       ! -> Collect rht()
       !
       n = vacuum%nmzd*2
       ALLOCATE(r_b(n))
       CALL MPI_REDUCE(rht,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, rht, 1)
       ENDIF
       DEALLOCATE (r_b)

    ENDIF
    !
    ! -> Collect uu(),ud() and dd()
    !
116
    n = (atoms%lmaxd+1)*atoms%ntype
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    ALLOCATE(r_b(n))
    CALL MPI_REDUCE(uu,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, uu, 1)
    ENDIF
    CALL MPI_REDUCE(du,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, du, 1)
    ENDIF
    CALL MPI_REDUCE(dd,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, dd, 1)
    ENDIF
    DEALLOCATE (r_b)
    !
    !--> Collect uunmt,udnmt,dunmt,ddnmt
    !
134
    n = (llpd+1)*sphhar%nlhd*atoms%ntype
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    ALLOCATE(r_b(n))
    CALL MPI_REDUCE(uunmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, uunmt, 1)
    ENDIF
    CALL MPI_REDUCE(udnmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, udnmt, 1)
    ENDIF
    CALL MPI_REDUCE(dunmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, dunmt, 1)
    ENDIF
    CALL MPI_REDUCE(ddnmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, ddnmt, 1)
    ENDIF
    DEALLOCATE (r_b)
    !
    !--> ener & sqal
    !
156
    n=4*atoms%ntype
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
    ALLOCATE(r_b(n))
    CALL MPI_REDUCE(ener,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, ener, 1)
    ENDIF
    CALL MPI_REDUCE(sqal,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
    IF (mpi%irank.EQ.0) THEN
       CALL CPP_BLAS_scopy(n, r_b, 1, sqal, 1)
    ENDIF
    DEALLOCATE (r_b)
    !
    !--> svac & pvac
    !
    IF ( input%film ) THEN

       n=2
       ALLOCATE(r_b(n))
       CALL MPI_REDUCE(svac,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, svac, 1)
       ENDIF
       CALL MPI_REDUCE(pvac,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, pvac, 1)
       ENDIF
       DEALLOCATE (r_b)

    ENDIF
    !
    ! -> Collect force
    !   
    IF (input%l_f) THEN

190
       n=3*atoms%ntype
191
       ALLOCATE(r_b(n))
192
       CALL MPI_REDUCE(results%force(1,1,jspin),r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
193
       IF (mpi%irank.EQ.0) THEN
194
          CALL CPP_BLAS_scopy(n, r_b, 1, results%force(1,1,jspin), 1)
195 196 197 198 199 200 201 202 203
       ENDIF
       DEALLOCATE (r_b)

    ENDIF
    !
    ! -> Optional the LO-coefficients: aclo,bclo,enerlo,cclo,acnmt,bcnmt,ccnmt
    !
    IF (atoms%nlod.GE.1) THEN

204
       n=atoms%nlod*atoms%ntype 
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
       ALLOCATE (r_b(n))
       CALL MPI_REDUCE(aclo,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, aclo, 1)
       ENDIF
       CALL MPI_REDUCE(bclo,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, bclo, 1)
       ENDIF
       CALL MPI_REDUCE(enerlo,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, enerlo, 1)
       ENDIF
       CALL MPI_REDUCE(sqlo,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, sqlo, 1)
       ENDIF
       DEALLOCATE (r_b)

224
       n = atoms%nlod * atoms%nlod * atoms%ntype
225 226 227 228 229 230 231
       ALLOCATE (r_b(n))
       CALL MPI_REDUCE(cclo,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, cclo, 1)
       ENDIF
       DEALLOCATE (r_b)

232
       n = (atoms%lmaxd+1) * atoms%ntype * atoms%nlod * sphhar%nlhd
233 234 235 236 237 238 239 240 241 242 243
       ALLOCATE (r_b(n))
       CALL MPI_REDUCE(acnmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, acnmt, 1)
       ENDIF
       CALL MPI_REDUCE(bcnmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, bcnmt, 1)
       ENDIF
       DEALLOCATE (r_b)

244
       n = atoms%ntype * sphhar%nlhd * atoms%nlod**2
245 246 247 248 249 250 251 252 253 254 255 256 257 258
       ALLOCATE (r_b(n))
       CALL MPI_REDUCE(ccnmt,r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_scopy(n, r_b, 1, ccnmt, 1)
       ENDIF
       DEALLOCATE (r_b)

    ENDIF
    !
    ! ->  Now the SOC - stuff: orb, orblo and orblo
    !
    IF (noco%l_soc) THEN
       !
       ! orb
259
       n=(atoms%lmaxd+1)*(2*atoms%lmaxd+1)*atoms%ntype
260
       ALLOCATE (r_b(n))
261
       CALL MPI_REDUCE(orb%uu(:,:,:,jspin),r_b,n,CPP_MPI_REAL, MPI_SUM,0,MPI_COMM_WORLD,ierr)
262
       IF (mpi%irank.EQ.0) THEN
263
          CALL CPP_BLAS_scopy(n, r_b, 1, orb%uu(:,:,:,jspin), 1)
264
       ENDIF
265
       CALL MPI_REDUCE(orb%dd(:,:,:,jspin),r_b,n,CPP_MPI_REAL, MPI_SUM,0,MPI_COMM_WORLD,ierr)
266
       IF (mpi%irank.EQ.0) THEN
267
          CALL CPP_BLAS_scopy(n, r_b, 1, orb%dd(:,:,:,jspin), 1)
268 269 270 271
       ENDIF
       DEALLOCATE (r_b)

       ALLOCATE (c_b(n))
272
       CALL MPI_REDUCE(orb%uup(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
273
       IF (mpi%irank.EQ.0) THEN
274
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%uup(:,:,:,jspin), 1)
275
       ENDIF
276
       CALL MPI_REDUCE(orb%ddp(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
277
       IF (mpi%irank.EQ.0) THEN
278
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%ddp(:,:,:,jspin), 1)
279
       ENDIF
280
       CALL MPI_REDUCE(orb%uum(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
281
       IF (mpi%irank.EQ.0) THEN
282
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%uum(:,:,:,jspin), 1)
283
       ENDIF
284
       CALL MPI_REDUCE(orb%ddm(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
285
       IF (mpi%irank.EQ.0) THEN
286
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%ddm(:,:,:,jspin), 1)
287 288
       ENDIF
       DEALLOCATE (c_b)
289

290
       n = atoms%nlod * (2*atoms%llod+1) * atoms%ntype
291
       ALLOCATE (r_b(n))
292
       CALL MPI_REDUCE(orb%uulo(:,:,:,jspin),r_b,n,CPP_MPI_REAL, MPI_SUM,0,MPI_COMM_WORLD,ierr)
293
       IF (mpi%irank.EQ.0) THEN
294
          CALL CPP_BLAS_scopy(n, r_b, 1, orb%uulo(:,:,:,jspin), 1)
295
       ENDIF
296
       CALL MPI_REDUCE(orb%dulo(:,:,:,jspin),r_b,n,CPP_MPI_REAL, MPI_SUM,0,MPI_COMM_WORLD,ierr)
297
       IF (mpi%irank.EQ.0) THEN
298
          CALL CPP_BLAS_scopy(n, r_b, 1, orb%dulo(:,:,:,jspin), 1)
299 300 301 302
       ENDIF
       DEALLOCATE (r_b)

       ALLOCATE (c_b(n))
303
       CALL MPI_REDUCE(orb%uulop(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
304
       IF (mpi%irank.EQ.0) THEN
305
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%uulop(:,:,:,jspin), 1)
306
       ENDIF
307
       CALL MPI_REDUCE(orb%dulop(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
308
       IF (mpi%irank.EQ.0) THEN
309
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%dulop(:,:,:,jspin), 1)
310
       ENDIF
311
       CALL MPI_REDUCE(orb%uulom(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
312
       IF (mpi%irank.EQ.0) THEN
313
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%uulom(:,:,:,jspin), 1)
314
       ENDIF
315
       CALL MPI_REDUCE(orb%dulom(:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
316
       IF (mpi%irank.EQ.0) THEN
317
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%dulom(:,:,:,jspin), 1)
318 319
       ENDIF
       DEALLOCATE (c_b)
320

321
       n = atoms%nlod * atoms%nlod * (2*atoms%llod+1) * atoms%ntype
322
       ALLOCATE (r_b(n))
323
       CALL MPI_REDUCE(orb%z(:,:,:,:,jspin),r_b,n,CPP_MPI_REAL, MPI_SUM,0,MPI_COMM_WORLD,ierr)
324
       IF (mpi%irank.EQ.0) THEN
325
          CALL CPP_BLAS_scopy(n, r_b, 1, orb%z(:,:,:,:,jspin), 1)
326 327 328 329
       ENDIF
       DEALLOCATE (r_b)

       ALLOCATE (c_b(n))
330
       CALL MPI_REDUCE(orb%p(:,:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
331
       IF (mpi%irank.EQ.0) THEN
332
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%p(:,:,:,:,jspin), 1)
333
       ENDIF
334
       CALL MPI_REDUCE(orb%m(:,:,:,:,jspin),c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
335
       IF (mpi%irank.EQ.0) THEN
336
          CALL CPP_BLAS_ccopy(n, c_b, 1, orb%m(:,:,:,:,jspin), 1)
337 338 339 340 341 342 343 344 345 346
       ENDIF
       DEALLOCATE (c_b)

    ENDIF

    !
    ! -> Collect the noco staff: 
    !
    IF ( noco%l_noco .AND. jspin.EQ.1 ) THEN

347
       n = stars%ng3
348
       ALLOCATE(c_b(n))
349
       CALL MPI_REDUCE(den%pw(:,3),c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0, MPI_COMM_WORLD,ierr)
350
       IF (mpi%irank.EQ.0) THEN
351
          CALL CPP_BLAS_ccopy(n, c_b, 1, den%pw(:,3), 1)
352 353 354 355 356 357 358
       ENDIF
       DEALLOCATE (c_b)
       !
       IF (input%film) THEN

          n = vacuum%nmzxyd*(oneD%odi%n2d-1)*2
          ALLOCATE(c_b(n))
359
          CALL MPI_REDUCE(den%vacxy(:,:,:,3),c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0, MPI_COMM_WORLD,ierr)
360
          IF (mpi%irank.EQ.0) THEN
361
             CALL CPP_BLAS_ccopy(n, c_b, 1, den%vacxy(:,:,:,3), 1)
362 363 364
          ENDIF
          DEALLOCATE (c_b)
          !
365 366 367
          n = vacuum%nmzd*2*2
          ALLOCATE(r_b(n))
          CALL MPI_REDUCE(den%vacz(:,:,3:4),r_b,n,CPP_MPI_REAL,MPI_SUM,0, MPI_COMM_WORLD,ierr)
368
          IF (mpi%irank.EQ.0) THEN
369
             CALL CPP_BLAS_ccopy(n, r_b, 1, den%vacz(:,:,3:4), 1)
370
          ENDIF
371
          DEALLOCATE (r_b)
372 373 374 375 376 377 378 379

       ENDIF ! input%film


       IF (noco%l_mperp) THEN
          !
          ! -->     for (spin)-off diagonal part of muffin-tin
          !
380
          n = (atoms%lmaxd+1) * atoms%ntype
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
          ALLOCATE(c_b(n))
          CALL MPI_REDUCE(mt21(:,:)%uu,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, mt21(:,:)%uu, 1)
          ENDIF
          CALL MPI_REDUCE(mt21(:,:)%ud,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, mt21(:,:)%ud, 1)
          ENDIF
          CALL MPI_REDUCE(mt21(:,:)%du,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, mt21(:,:)%du, 1)
          ENDIF
          CALL MPI_REDUCE(mt21(:,:)%dd,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, mt21(:,:)%dd, 1)
          ENDIF
          DEALLOCATE (c_b)
          !
          ! -->     lo,u coeff's:
          !
402
          n = atoms%nlod * atoms%ntype
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
          ALLOCATE(c_b(n))
          CALL MPI_REDUCE(lo21(:,:)%uulo,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, lo21(:,:)%uulo, 1)
          ENDIF
          CALL MPI_REDUCE(lo21(:,:)%ulou,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, lo21(:,:)%ulou, 1)
          ENDIF
          CALL MPI_REDUCE(lo21(:,:)%dulo,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, lo21(:,:)%dulo, 1)
          ENDIF
          CALL MPI_REDUCE(lo21(:,:)%ulod,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, lo21(:,:)%ulod, 1)
          ENDIF
          DEALLOCATE (c_b)
          !
          ! -->     lo,lo' coeff's:
          !
424
          n = atoms%nlod*atoms%nlod*atoms%ntype
425 426 427 428 429 430 431 432 433 434 435
          ALLOCATE(c_b(n))
          CALL MPI_REDUCE(uloulop21,c_b,n,CPP_MPI_COMPLEX, MPI_SUM,0,MPI_COMM_WORLD,ierr)
          IF (mpi%irank.EQ.0) THEN
             CALL CPP_BLAS_ccopy(n, c_b, 1, uloulop21, 1)
          ENDIF
          DEALLOCATE (c_b)

          IF (l_fmpl) THEN
             !
             !-->        Full magnetization plots: Collect uunmt21, etc.
             !
436
             n = (atoms%lmaxd+1)**2 *sphhar%nlhd*atoms%ntype
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
             ALLOCATE(c_b(n))
             CALL MPI_REDUCE(uunmt21,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0 ,MPI_COMM_WORLD,ierr)
             IF (mpi%irank.EQ.0) THEN
                CALL CPP_BLAS_ccopy(n, c_b, 1, uunmt21, 1)
             ENDIF
             CALL MPI_REDUCE(udnmt21,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0 ,MPI_COMM_WORLD,ierr)
             IF (mpi%irank.EQ.0) THEN
                CALL CPP_BLAS_ccopy(n, c_b, 1, udnmt21, 1)
             ENDIF
             CALL MPI_REDUCE(dunmt21,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0 ,MPI_COMM_WORLD,ierr)
             IF (mpi%irank.EQ.0) THEN
                CALL CPP_BLAS_ccopy(n, c_b, 1, dunmt21, 1)
             ENDIF
             CALL MPI_REDUCE(ddnmt21,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0 ,MPI_COMM_WORLD,ierr)
             IF (mpi%irank.EQ.0) THEN
                CALL CPP_BLAS_ccopy(n, c_b, 1, ddnmt21, 1)
             ENDIF
             DEALLOCATE (c_b)

          ENDIF ! fmpl
       ENDIF  ! mperp
    ENDIF   ! noco

    !+lda+U
    IF ( atoms%n_u.GT.0 ) THEN
       n = 49*atoms%n_u 
       ALLOCATE(c_b(n))
       CALL MPI_REDUCE(n_mmp,c_b,n,CPP_MPI_COMPLEX,MPI_SUM,0, MPI_COMM_WORLD,ierr)
       IF (mpi%irank.EQ.0) THEN
          CALL CPP_BLAS_ccopy(n, c_b, 1, n_mmp, 1)
       ENDIF
       DEALLOCATE (c_b)
    ENDIF
    !-lda+U

    RETURN
  END SUBROUTINE mpi_col_den
END MODULE m_mpi_col_den