wfreq_restart.f90 46.4 KB
Newer Older
Marco Govoni's avatar
Marco Govoni committed
1
!
Marco Govoni's avatar
Marco Govoni committed
2
! Copyright (C) 2015-2021 M. Govoni 
Marco Govoni's avatar
Marco Govoni committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST.
!
! Contributors to this file: 
! Marco Govoni
!
!-----------------------------------------------------------------------
MODULE wfreq_restart
  !----------------------------------------------------------------------------
  !
  USE iotk_module
  USE kinds,                   ONLY : DP
  USE io_files,                ONLY : tmp_dir
  !
  IMPLICIT NONE
  !
  SAVE
  !
25
26
  ! BKS: band, k
  !
Marco Govoni's avatar
Marco Govoni committed
27
  TYPE :: bks_type
28
29
30
31
32
33
34
35
36
37
38
39
40
     INTEGER :: lastdone_ks
     INTEGER :: lastdone_band
     INTEGER :: old_ks
     INTEGER :: old_band
     INTEGER :: max_ks
     INTEGER :: max_band
     INTEGER :: min_ks
     INTEGER :: min_band
  END TYPE bks_type
  !
  ! BKSQ: band, k, q (solve_wfreq_q)
  ! 
  TYPE :: bksq_type
41
     INTEGER :: lastdone_q
Marco Govoni's avatar
Marco Govoni committed
42
43
     INTEGER :: lastdone_ks
     INTEGER :: lastdone_band
44
     INTEGER :: old_q
Marco Govoni's avatar
Marco Govoni committed
45
46
     INTEGER :: old_ks
     INTEGER :: old_band
47
     INTEGER :: max_q
Marco Govoni's avatar
Marco Govoni committed
48
49
     INTEGER :: max_ks
     INTEGER :: max_band
50
     INTEGER :: min_q
Marco Govoni's avatar
Marco Govoni committed
51
52
     INTEGER :: min_ks
     INTEGER :: min_band
53
54
55
56
57
58
  END TYPE bksq_type
  !
  ! BKSKS: band, k, k1 (solve_gfreq_q)
  !
  TYPE :: bksks_type
     INTEGER :: lastdone_ks
59
     INTEGER :: lastdone_kks
60
61
     INTEGER :: lastdone_band
     INTEGER :: old_ks
62
     INTEGER :: old_kks
63
64
     INTEGER :: old_band
     INTEGER :: max_ks
65
     INTEGER :: max_kks
66
67
     INTEGER :: max_band
     INTEGER :: min_ks
68
     INTEGER :: min_kks
69
70
     INTEGER :: min_band
  END TYPE bksks_type
Marco Govoni's avatar
Marco Govoni committed
71
72
  !
  INTERFACE solvewfreq_restart_write
73
     MODULE PROCEDURE solvewfreq_restart_write_real, solvewfreq_restart_write_complex, solvewfreq_restart_write_complex_q
Marco Govoni's avatar
Marco Govoni committed
74
75
76
  END INTERFACE 
  !
  INTERFACE solvewfreq_restart_read
77
     MODULE PROCEDURE solvewfreq_restart_read_real, solvewfreq_restart_read_complex, solvewfreq_restart_read_complex_q
Marco Govoni's avatar
Marco Govoni committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  END INTERFACE 
  !
  CONTAINS
    !
    ! BKS
    !
    !------------------------------------------------------------------------
    SUBROUTINE write_bks(bks,dirname,fname)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type),INTENT(IN) :: bks
99
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
Marco Govoni's avatar
Marco Govoni committed
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
      INTEGER :: iunout
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         ! ... open XML descriptor
         !
         CALL iotk_free_unit( iunout, ierr )
         CALL iotk_open_write( iunout, FILE = TRIM( dirname ) // '/' // TRIM(fname) , BINARY = .FALSE., IERR = ierr )
         !
      END IF
      !
      CALL mp_bcast( ierr, root, world_comm )
      !
      CALL errore( 'wfreq_restart', 'cannot open restart file for writing', ierr )
      !
      IF ( mpime == root ) THEN  
         !
         CALL iotk_write_begin( iunout, "BKS-SUMMARY" )
         CALL iotk_write_dat( iunout, "lastdone_ks"  , bks%lastdone_ks   )
         CALL iotk_write_dat( iunout, "lastdone_band", bks%lastdone_band )
         CALL iotk_write_dat( iunout, "old_ks"       , bks%old_ks       )
         CALL iotk_write_dat( iunout, "old_band"     , bks%old_band     )
         CALL iotk_write_dat( iunout, "max_ks"       , bks%max_ks       )
         CALL iotk_write_dat( iunout, "max_band"     , bks%max_band     )
         CALL iotk_write_dat( iunout, "min_ks"       , bks%min_ks       )
         CALL iotk_write_dat( iunout, "min_band"     , bks%min_band     )
         CALL iotk_write_end( iunout, "BKS-SUMMARY"  )
         !
         CALL iotk_close_write( iunout )
         !
      END IF
      !
      CALL mp_barrier(world_comm)
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
141
    SUBROUTINE write_bksq(bksq,dirname,fname)
142
143
144
145
146
147
148
149
150
151
152
153
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
154
      TYPE(bksq_type),INTENT(IN) :: bksq
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
      INTEGER :: iunout
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         ! ... open XML descriptor
         !
         CALL iotk_free_unit( iunout, ierr )
         CALL iotk_open_write( iunout, FILE = TRIM( dirname ) // '/' // TRIM(fname) , BINARY = .FALSE., IERR = ierr )
         !
      END IF
      !
      CALL mp_bcast( ierr, root, world_comm )
      !
      CALL errore( 'wfreq_restart', 'cannot open restart file for writing', ierr )
      !
      IF ( mpime == root ) THEN  
         !
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
         CALL iotk_write_begin( iunout, "BKSQ-SUMMARY" )
         CALL iotk_write_dat( iunout, "lastdone_q"   , bksq%lastdone_q   )
         CALL iotk_write_dat( iunout, "lastdone_ks"  , bksq%lastdone_ks  )
         CALL iotk_write_dat( iunout, "lastdone_band", bksq%lastdone_band)
         CALL iotk_write_dat( iunout, "old_q"        , bksq%old_q        )
         CALL iotk_write_dat( iunout, "old_ks"       , bksq%old_ks       )
         CALL iotk_write_dat( iunout, "old_band"     , bksq%old_band     )
         CALL iotk_write_dat( iunout, "max_q"        , bksq%max_q        )
         CALL iotk_write_dat( iunout, "max_ks"       , bksq%max_ks       )
         CALL iotk_write_dat( iunout, "max_band"     , bksq%max_band     )
         CALL iotk_write_dat( iunout, "min_q"        , bksq%min_q        )
         CALL iotk_write_dat( iunout, "min_ks"       , bksq%min_ks       )
         CALL iotk_write_dat( iunout, "min_band"     , bksq%min_band     )
         CALL iotk_write_end( iunout, "BKSQ-SUMMARY"  )
         !
         CALL iotk_close_write( iunout )
         !
      END IF
      !
      CALL mp_barrier(world_comm)
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
    SUBROUTINE write_bksks(bksks,dirname,fname)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bksks_type),INTENT(IN) :: bksks
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
      INTEGER :: iunout
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         ! ... open XML descriptor
         !
         CALL iotk_free_unit( iunout, ierr )
         CALL iotk_open_write( iunout, FILE = TRIM( dirname ) // '/' // TRIM(fname) , BINARY = .FALSE., IERR = ierr )
         !
      END IF
      !
      CALL mp_bcast( ierr, root, world_comm )
      !
      CALL errore( 'wfreq_restart', 'cannot open restart file for writing', ierr )
      !
      IF ( mpime == root ) THEN  
         !
         CALL iotk_write_begin( iunout, "BKSKS-SUMMARY" )
         CALL iotk_write_dat( iunout, "lastdone_ks"  , bksks%lastdone_ks  )
239
         CALL iotk_write_dat( iunout, "lastdone_kks" , bksks%lastdone_kks )
240
241
         CALL iotk_write_dat( iunout, "lastdone_band", bksks%lastdone_band)
         CALL iotk_write_dat( iunout, "old_ks"       , bksks%old_ks       )
242
         CALL iotk_write_dat( iunout, "old_kks"      , bksks%old_kks      )
243
244
         CALL iotk_write_dat( iunout, "old_band"     , bksks%old_band     )
         CALL iotk_write_dat( iunout, "max_ks"       , bksks%max_ks       )
245
         CALL iotk_write_dat( iunout, "max_kks"      , bksks%max_kks      )
246
247
         CALL iotk_write_dat( iunout, "max_band"     , bksks%max_band     )
         CALL iotk_write_dat( iunout, "min_ks"       , bksks%min_ks       )
248
         CALL iotk_write_dat( iunout, "min_kks"      , bksks%min_kks      )
249
250
         CALL iotk_write_dat( iunout, "min_band"     , bksks%min_band     )
         CALL iotk_write_end( iunout, "BKSKS-SUMMARY"  )
251
252
253
254
255
256
257
258
259
260
         !
         CALL iotk_close_write( iunout )
         !
      END IF
      !
      CALL mp_barrier(world_comm)
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
Marco Govoni's avatar
Marco Govoni committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
    SUBROUTINE read_bks(bks,dirname,fname)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type),INTENT(OUT) :: bks
275
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
Marco Govoni's avatar
Marco Govoni committed
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
      INTEGER :: iunout
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         ! ... open XML descriptor
         !
         CALL iotk_free_unit( iunout, ierr )
         CALL iotk_open_read( iunout, FILE = TRIM( dirname ) // '/' // TRIM(fname) , BINARY = .FALSE., IERR = ierr )
         !
      END IF
      !
      CALL mp_bcast( ierr, root, world_comm )
      !
      CALL errore( 'wfreq_restart', 'cannot open restart file for reading', ierr )
      !
      IF ( mpime == root ) THEN  
         !
         CALL iotk_scan_begin( iunout, "BKS-SUMMARY" )
         CALL iotk_scan_dat( iunout, "lastdone_ks"  , bks%lastdone_ks   )
         CALL iotk_scan_dat( iunout, "lastdone_band", bks%lastdone_band )
         CALL iotk_scan_dat( iunout, "old_ks"       , bks%old_ks        )
         CALL iotk_scan_dat( iunout, "old_band"     , bks%old_band      )
         CALL iotk_scan_dat( iunout, "max_ks"       , bks%max_ks        )
         CALL iotk_scan_dat( iunout, "max_band"     , bks%max_band      )
         CALL iotk_scan_dat( iunout, "min_ks"       , bks%min_ks        )
         CALL iotk_scan_dat( iunout, "min_band"     , bks%min_band      )
         CALL iotk_scan_end( iunout, "BKS-SUMMARY"  )
         !
         CALL iotk_close_read( iunout )
         !
      END IF
      !
      CALL mp_bcast( bks%lastdone_ks   , root , world_comm )
      CALL mp_bcast( bks%lastdone_band , root , world_comm )
      CALL mp_bcast( bks%old_ks        , root , world_comm )
      CALL mp_bcast( bks%old_band      , root , world_comm )
      CALL mp_bcast( bks%max_ks        , root , world_comm )
      CALL mp_bcast( bks%max_band      , root , world_comm )
      CALL mp_bcast( bks%min_ks        , root , world_comm )
      CALL mp_bcast( bks%min_band      , root , world_comm )
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
324
    SUBROUTINE read_bksq(bksq,dirname,fname)
325
326
327
328
329
330
331
332
333
334
335
336
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
337
      TYPE(bksq_type),INTENT(OUT) :: bksq
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
      INTEGER :: iunout
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         ! ... open XML descriptor
         !
         CALL iotk_free_unit( iunout, ierr )
         CALL iotk_open_read( iunout, FILE = TRIM( dirname ) // '/' // TRIM(fname) , BINARY = .FALSE., IERR = ierr )
         !
      END IF
      !
      CALL mp_bcast( ierr, root, world_comm )
      !
      CALL errore( 'wfreq_restart', 'cannot open restart file for reading', ierr )
      !
      IF ( mpime == root ) THEN  
         !
360
361
362
363
364
365
366
367
368
369
370
371
372
373
         CALL iotk_scan_begin( iunout, "BKSQ-SUMMARY" )
         CALL iotk_scan_dat( iunout, "lastdone_q"   , bksq%lastdone_q    )
         CALL iotk_scan_dat( iunout, "lastdone_ks"  , bksq%lastdone_ks   )
         CALL iotk_scan_dat( iunout, "lastdone_band", bksq%lastdone_band )
         CALL iotk_scan_dat( iunout, "old_q"        , bksq%old_q         )
         CALL iotk_scan_dat( iunout, "old_ks"       , bksq%old_ks        )
         CALL iotk_scan_dat( iunout, "old_band"     , bksq%old_band      )
         CALL iotk_scan_dat( iunout, "max_q"        , bksq%max_q         )
         CALL iotk_scan_dat( iunout, "max_ks"       , bksq%max_ks        )
         CALL iotk_scan_dat( iunout, "max_band"     , bksq%max_band      )
         CALL iotk_scan_dat( iunout, "min_q"        , bksq%min_q         )
         CALL iotk_scan_dat( iunout, "min_ks"       , bksq%min_ks        )
         CALL iotk_scan_dat( iunout, "min_band"     , bksq%min_band      )
         CALL iotk_scan_end( iunout, "BKSQ-SUMMARY"  )
374
375
376
377
378
         !
         CALL iotk_close_read( iunout )
         !
      END IF
      !
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
      CALL mp_bcast( bksq%lastdone_q    , root , world_comm )
      CALL mp_bcast( bksq%lastdone_ks   , root , world_comm )
      CALL mp_bcast( bksq%lastdone_band , root , world_comm )
      CALL mp_bcast( bksq%old_q         , root , world_comm )
      CALL mp_bcast( bksq%old_ks        , root , world_comm )
      CALL mp_bcast( bksq%old_band      , root , world_comm )
      CALL mp_bcast( bksq%max_q         , root , world_comm )
      CALL mp_bcast( bksq%max_ks        , root , world_comm )
      CALL mp_bcast( bksq%max_band      , root , world_comm )
      CALL mp_bcast( bksq%min_q         , root , world_comm )
      CALL mp_bcast( bksq%min_ks        , root , world_comm )
      CALL mp_bcast( bksq%min_band      , root , world_comm )
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
    SUBROUTINE read_bksks(bksks,dirname,fname)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bksks_type),INTENT(OUT) :: bksks
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
      INTEGER :: iunout
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         ! ... open XML descriptor
         !
         CALL iotk_free_unit( iunout, ierr )
         CALL iotk_open_read( iunout, FILE = TRIM( dirname ) // '/' // TRIM(fname) , BINARY = .FALSE., IERR = ierr )
         !
      END IF
      !
      CALL mp_bcast( ierr, root, world_comm )
      !
      CALL errore( 'wfreq_restart', 'cannot open restart file for reading', ierr )
      !
      IF ( mpime == root ) THEN  
         !
         CALL iotk_scan_begin( iunout, "BKSKS-SUMMARY" )
         CALL iotk_scan_dat( iunout, "lastdone_ks"  , bksks%lastdone_ks   )
433
         CALL iotk_scan_dat( iunout, "lastdone_kks" , bksks%lastdone_kks  )
434
435
         CALL iotk_scan_dat( iunout, "lastdone_band", bksks%lastdone_band )
         CALL iotk_scan_dat( iunout, "old_ks"       , bksks%old_ks        )
436
         CALL iotk_scan_dat( iunout, "old_kks"      , bksks%old_kks       )
437
438
         CALL iotk_scan_dat( iunout, "old_band"     , bksks%old_band      )
         CALL iotk_scan_dat( iunout, "max_ks"       , bksks%max_ks        )
439
         CALL iotk_scan_dat( iunout, "max_kks"      , bksks%max_kks       )
440
441
         CALL iotk_scan_dat( iunout, "max_band"     , bksks%max_band      )
         CALL iotk_scan_dat( iunout, "min_ks"       , bksks%min_ks        )
442
         CALL iotk_scan_dat( iunout, "min_kks"      , bksks%min_kks       )
443
444
445
446
447
448
449
450
         CALL iotk_scan_dat( iunout, "min_band"     , bksks%min_band      )
         CALL iotk_scan_end( iunout, "BKSKS-SUMMARY"  )
         !
         CALL iotk_close_read( iunout )
         !
      END IF
      !
      CALL mp_bcast( bksks%lastdone_ks   , root , world_comm )
451
      CALL mp_bcast( bksks%lastdone_kks  , root , world_comm )
452
453
      CALL mp_bcast( bksks%lastdone_band , root , world_comm )
      CALL mp_bcast( bksks%old_ks        , root , world_comm )
454
      CALL mp_bcast( bksks%old_kks       , root , world_comm )
455
456
      CALL mp_bcast( bksks%old_band      , root , world_comm )
      CALL mp_bcast( bksks%max_ks        , root , world_comm )
457
      CALL mp_bcast( bksks%max_kks       , root , world_comm )
458
459
      CALL mp_bcast( bksks%max_band      , root , world_comm )
      CALL mp_bcast( bksks%min_ks        , root , world_comm )
460
      CALL mp_bcast( bksks%min_kks       , root , world_comm )
461
      CALL mp_bcast( bksks%min_band      , root , world_comm )
462
463
464
465
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
Marco Govoni's avatar
Marco Govoni committed
466
467
468
469
470
471
472
473
474
475
476
477
478
    SUBROUTINE clear_bks(dirname,fname)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
479
      CHARACTER(LEN=512),INTENT(IN) :: dirname, fname
Marco Govoni's avatar
Marco Govoni committed
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
      !
      ! Workspace
      !
      INTEGER :: ierr
      !
      IF ( mpime == root ) THEN
         !
         CALL delete_if_present( TRIM( dirname ) // '/' // TRIM(fname) ) 
         !
      END IF
      !
      CALL mp_barrier( world_comm )
      !
    END SUBROUTINE
    !
    !
    ! SOLVEWFREQ
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvewfreq_restart_write_real(bks,dmat,zmat,npg,npl)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      USE distribution_center,  ONLY : ifr,rfr
      USE west_io,              ONLY : serial_data_write 
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type),INTENT(IN) :: bks
      INTEGER, INTENT(IN) :: npg, npl
      REAL(DP), INTENT(IN) :: dmat(npg,npl,ifr%nloc)
      COMPLEX(DP), INTENT(IN) :: zmat(npg,npl,rfr%nloc)
      !
      ! Workspace
      !
      INTEGER :: ierr
523
      CHARACTER(LEN=512) :: dirname,fname
Marco Govoni's avatar
Marco Govoni committed
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
      CHARACTER(29) :: my_label
      CHARACTER(33) :: my_label2
      INTEGER :: local_j,global_j
      INTEGER :: ip, ip_glob
      REAL(DP),ALLOCATABLE :: tmp_dmat(:,:,:) 
      COMPLEX(DP),ALLOCATABLE :: tmp_zmat(:,:,:) 
      LOGICAL :: lproc
      INTEGER :: iunit
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      CALL start_clock('sw_restart')
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !  
      ! DMAT
      !
      ALLOCATE( tmp_dmat( npg, npl, ifr%nglob ))
      tmp_dmat = 0._DP
      DO ip = 1, ifr%nloc
         ip_glob = ifr%l2g(ip)
         tmp_dmat(:,:,ip_glob) = dmat(:,:,ip)
      ENDDO
      CALL mp_sum( tmp_dmat, intra_bgrp_comm ) 
      !
      WRITE(my_label,'("dmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label)
      iunit = 2000 + my_image_id
      lproc = (me_bgrp == 0)
      CALL serial_data_write(lproc,iunit,fname,tmp_dmat,npg,npl,ifr%nglob)
      !
      DEALLOCATE(tmp_dmat)
      !
      ! ZMAT
      !
      ALLOCATE( tmp_zmat( npg, npl, rfr%nglob ))
      tmp_zmat = 0._DP
      DO ip = 1, rfr%nloc
         ip_glob = rfr%l2g(ip)
         tmp_zmat(:,:,ip_glob) = zmat(:,:,ip)
      ENDDO
      CALL mp_sum( tmp_zmat, intra_bgrp_comm ) 
      !   
      WRITE(my_label,'("zmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label)
      iunit = 2000 + my_image_id
      lproc = (me_bgrp == 0)
      CALL serial_data_write(lproc,iunit,fname,tmp_zmat,npg,npl,rfr%nglob)
      !
      DEALLOCATE(tmp_zmat)
      !
      ! CLEAR
      !
      IF(bks%old_ks/=0.AND.bks%old_band/=0) THEN
         IF( me_bgrp == 0 ) THEN
            WRITE(my_label2,'("dmat_iks",i5.5,"_iv",i5.5,"_I",i6.6,".raw")') &
            & bks%old_ks, bks%old_band, my_image_id
            fname=TRIM(my_label2)
            CALL delete_if_present( TRIM( dirname ) // '/' // TRIM( fname ) )
            WRITE(my_label2,'("zmat_iks",i5.5,"_iv",i5.5,"_I",i6.6,".raw")') & 
            & bks%old_ks, bks%old_band, my_image_id
            fname=TRIM(my_label2)
            CALL delete_if_present( TRIM( dirname ) // '/' // TRIM( fname ) )
         ENDIF
      ENDIF
      !
      ! CREATE THE SUMMARY FILE
      !
      fname = "summary_w.xml"
      CALL write_bks( bks, dirname, fname ) 
      !
      CALL stop_clock('sw_restart')
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvewfreq_restart_write_complex(bks,dmat,zmat,npg,npl)
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      USE distribution_center,  ONLY : ifr,rfr
      USE west_io,              ONLY : serial_data_write 
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type),INTENT(IN) :: bks
      INTEGER, INTENT(IN) :: npg, npl
      COMPLEX(DP), INTENT(IN) :: dmat(npg,npl,ifr%nloc)
      COMPLEX(DP), INTENT(IN) :: zmat(npg,npl,rfr%nloc)
      !
      ! Workspace
      !
      INTEGER :: ierr
628
      CHARACTER(LEN=512) :: dirname,fname
Marco Govoni's avatar
Marco Govoni committed
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
      CHARACTER(29) :: my_label
      CHARACTER(33) :: my_label2
      INTEGER :: local_j,global_j
      INTEGER :: ip, ip_glob
      COMPLEX(DP),ALLOCATABLE :: tmp_dmat(:,:,:) 
      COMPLEX(DP),ALLOCATABLE :: tmp_zmat(:,:,:) 
      LOGICAL :: lproc
      INTEGER :: iunit
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      CALL start_clock('sw_restart')
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !  
      ! DMAT
      !
      ALLOCATE( tmp_dmat( npg, npl, ifr%nglob ))
      tmp_dmat = 0._DP
      DO ip = 1, ifr%nloc
         ip_glob = ifr%l2g(ip)
         tmp_dmat(:,:,ip_glob) = dmat(:,:,ip)
      ENDDO
      CALL mp_sum( tmp_dmat, intra_bgrp_comm ) 
      !
      WRITE(my_label,'("dmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label)
      iunit = 2000 + my_image_id
      lproc = (me_bgrp == 0)
      CALL serial_data_write(lproc,iunit,fname,tmp_dmat,npg,npl,ifr%nglob)
      !
      DEALLOCATE(tmp_dmat)
      !
      ! ZMAT
      !
      ALLOCATE( tmp_zmat( npg, npl, rfr%nglob ))
      tmp_zmat = 0._DP
      DO ip = 1, rfr%nloc
         ip_glob = rfr%l2g(ip)
         tmp_zmat(:,:,ip_glob) = zmat(:,:,ip)
      ENDDO
      CALL mp_sum( tmp_zmat, intra_bgrp_comm ) 
      !   
      WRITE(my_label,'("zmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label)
      iunit = 2000 + my_image_id
      lproc = (me_bgrp == 0)
      CALL serial_data_write(lproc,iunit,fname,tmp_zmat,npg,npl,rfr%nglob)
      !
      DEALLOCATE(tmp_zmat)
      !
      ! CLEAR
      !
      IF(bks%old_ks/=0.AND.bks%old_band/=0) THEN
         IF( me_bgrp == 0 ) THEN
            WRITE(my_label2,'("dmat_iks",i5.5,"_iv",i5.5,"_I",i6.6,".raw")') &
            & bks%old_ks, bks%old_band, my_image_id
            fname=TRIM(my_label2)
            CALL delete_if_present( TRIM( dirname ) // '/' // TRIM( fname ) )
            WRITE(my_label2,'("zmat_iks",i5.5,"_iv",i5.5,"_I",i6.6,".raw")') & 
            & bks%old_ks, bks%old_band, my_image_id
            fname=TRIM(my_label2)
            CALL delete_if_present( TRIM( dirname ) // '/' // TRIM( fname ) )
         ENDIF
      ENDIF
      !
      ! CREATE THE SUMMARY FILE
      !
      fname = "summary_w.xml"
      CALL write_bks( bks, dirname, fname ) 
      !
      CALL stop_clock('sw_restart')
      !
    END SUBROUTINE
    !
708
    !------------------------------------------------------------------------
709
    SUBROUTINE solvewfreq_restart_write_complex_q(bksq,dmat,zmat,npg,npl)
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get,mp_sum
      USE io_files,             ONLY : delete_if_present
      USE distribution_center,  ONLY : ifr,rfr
      USE west_io,              ONLY : serial_data_write 
      USE types_bz_grid,        ONLY : q_grid
      !
      IMPLICIT NONE
      !
      ! I/O
      !
726
      TYPE(bksq_type),INTENT(IN) :: bksq
727
      INTEGER, INTENT(IN) :: npg, npl
728
729
      COMPLEX(DP), INTENT(IN) :: dmat(npg,npl,ifr%nloc,q_grid%np)
      COMPLEX(DP), INTENT(IN) :: zmat(npg,npl,rfr%nloc,q_grid%np)
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
      !
      ! Workspace
      !
      INTEGER :: ierr
      CHARACTER(LEN=512) :: dirname,fname
      CHARACTER(37) :: my_label
      CHARACTER(41) :: my_label2
      INTEGER :: local_j,global_j
      INTEGER :: ip, ip_glob, iq
      COMPLEX(DP),ALLOCATABLE :: tmp_dmat(:,:,:,:) 
      COMPLEX(DP),ALLOCATABLE :: tmp_zmat(:,:,:,:) 
      LOGICAL :: lproc
      INTEGER :: iunit
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      CALL start_clock('sw_restart')
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !  
      ! DMAT
      !
756
      ALLOCATE( tmp_dmat( npg, npl, ifr%nglob, q_grid%np ))
757
      tmp_dmat = 0._DP
758
      DO iq = 1, q_grid%np
759
760
761
762
763
764
765
         DO ip = 1, ifr%nloc
            ip_glob = ifr%l2g(ip)
            tmp_dmat(:,:,ip_glob,iq) = dmat(:,:,ip,iq)
         ENDDO
      ENDDO
      CALL mp_sum( tmp_dmat, intra_bgrp_comm ) 
      !
766
      WRITE(my_label,'("dmat_iq",i5.5,"_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bksq%lastdone_q,bksq%lastdone_ks,bksq%lastdone_band,&
767
768
769
770
                                                                          & my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label)
      iunit = 2000 + my_image_id
      lproc = (me_bgrp == 0)
771
      CALL serial_data_write(lproc,iunit,fname,tmp_dmat,npg,npl,ifr%nglob,q_grid%np)
772
773
774
775
776
      !
      DEALLOCATE(tmp_dmat)
      !
      ! ZMAT
      !
777
      ALLOCATE( tmp_zmat( npg, npl, rfr%nglob, q_grid%np ))
778
      tmp_zmat = 0._DP
779
      DO iq = 1, q_grid%np
780
781
782
783
784
785
786
         DO ip = 1, rfr%nloc
            ip_glob = rfr%l2g(ip)
            tmp_zmat(:,:,ip_glob,iq) = zmat(:,:,ip,iq)
         ENDDO
      ENDDO
      CALL mp_sum( tmp_zmat, intra_bgrp_comm ) 
      !   
787
      WRITE(my_label,'("zmat_iq",i5.5,"_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bksq%lastdone_q,bksq%lastdone_ks,bksq%lastdone_band,&
788
789
790
791
                                                                          & my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label)
      iunit = 2000 + my_image_id
      lproc = (me_bgrp == 0)
792
      CALL serial_data_write(lproc,iunit,fname,tmp_zmat,npg,npl,rfr%nglob,q_grid%np)
793
794
795
796
797
      !
      DEALLOCATE(tmp_zmat)
      !
      ! CLEAR
      !
798
      IF(bksq%old_q/=0.AND.bksq%old_ks/=0.AND.bksq%old_band/=0) THEN
799
800
         IF( me_bgrp == 0 ) THEN
            WRITE(my_label2,'("dmat_iq",i5.5,"_iks",i5.5,"_iv",i5.5,"_I",i6.6,".raw")') &
801
            & bksq%old_q, bksq%old_ks, bksq%old_band, my_image_id
802
803
804
            fname=TRIM(my_label2)
            CALL delete_if_present( TRIM( dirname ) // '/' // TRIM( fname ) )
            WRITE(my_label2,'("zmat_iq",i5.5,"_iks",i5.5,"_iv",i5.5,"_I",i6.6,".raw")') & 
805
            & bksq%old_q, bksq%old_ks, bksq%old_band, my_image_id
806
807
808
809
810
811
812
813
            fname=TRIM(my_label2)
            CALL delete_if_present( TRIM( dirname ) // '/' // TRIM( fname ) )
         ENDIF
      ENDIF
      !
      ! CREATE THE SUMMARY FILE
      !
      fname = "summary_w.xml"
814
      CALL write_bksq ( bksq, dirname, fname ) 
815
816
817
818
819
820
      !
      CALL stop_clock('sw_restart')
      !
    END SUBROUTINE
    !
    !
Marco Govoni's avatar
Marco Govoni committed
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
    !
    !
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvewfreq_restart_read_real( bks, dmat, zmat, npg, npl )
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      USE distribution_center,  ONLY : ifr,rfr
      USE west_io,              ONLY : serial_data_read 
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type), INTENT(OUT) :: bks
      INTEGER, INTENT(IN) :: npg, npl
      REAL(DP), INTENT(OUT) :: dmat(npg,npl,ifr%nloc)
      COMPLEX(DP), INTENT(OUT) :: zmat(npg,npl,rfr%nloc)
      !
      ! Workspace
      !
      INTEGER :: ierr
848
      CHARACTER(LEN=512) :: dirname,fname
Marco Govoni's avatar
Marco Govoni committed
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
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      CHARACTER(29) :: my_label
      INTEGER :: local_j,global_j
      INTEGER :: ip,ip_glob
      REAL(DP),ALLOCATABLE :: tmp_dmat(:,:,:)
      COMPLEX(DP),ALLOCATABLE :: tmp_zmat(:,:,:)
      LOGICAL :: lproc
      INTEGER :: iunit
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sw_restart')
      time_spent(1)=get_clock('sw_restart')
      !
      ! CREATE THE SUMMARY FILE
      !
      fname = "summary_w.xml"
      CALL read_bks( bks, dirname, fname )
      !
      ! READ
      !
      ALLOCATE( tmp_dmat( npg, npl, ifr%nglob ))
      !
      WRITE(my_label,'("dmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label) 
      lproc = (me_bgrp==0) 
      iunit = 2000 + my_image_id
      CALL serial_data_read(lproc,iunit,fname,tmp_dmat,npg,npl,ifr%nglob)
      !
      CALL mp_bcast( tmp_dmat, 0, intra_bgrp_comm)
      DO ip = 1, ifr%nloc
         ip_glob = ifr%l2g(ip)
         dmat(:,:,ip) = tmp_dmat(:,:,ip_glob)
      ENDDO
      DEALLOCATE(tmp_dmat)
      !
      ALLOCATE( tmp_zmat( npg, npl, rfr%nglob ))
      !
      WRITE(my_label,'("zmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label) 
      lproc = (me_bgrp==0) 
      iunit = 2000 + my_image_id
      CALL serial_data_read(lproc,iunit,fname,tmp_zmat,npg,npl,rfr%nglob)
      !
      CALL mp_bcast( tmp_zmat, 0, intra_bgrp_comm)
      DO ip = 1, rfr%nloc
         ip_glob = rfr%l2g(ip)
         zmat(:,:,ip) = tmp_zmat(:,:,ip_glob)
      ENDDO
      DEALLOCATE(tmp_zmat)
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      time_spent(2)=get_clock('sw_restart')
      CALL stop_clock('sw_restart')
      !
      WRITE(stdout,'(1/, 5x,"[I/O] -------------------------------------------------------")')
      WRITE(stdout, "(5x, '[I/O] RESTART read in ',a20)") human_readable_time(time_spent(2)-time_spent(1)) 
      WRITE(stdout, "(5x, '[I/O] In location : ',a)") TRIM( dirname )  
      WRITE(stdout,'(5x,"[I/O] -------------------------------------------------------")')
      !
    END SUBROUTINE
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvewfreq_restart_read_complex( bks, dmat, zmat, npg, npl )
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      USE distribution_center,  ONLY : ifr,rfr
      USE west_io,              ONLY : serial_data_read 
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type), INTENT(OUT) :: bks
      INTEGER, INTENT(IN) :: npg, npl
      COMPLEX(DP), INTENT(OUT) :: dmat(npg,npl,ifr%nloc)
      COMPLEX(DP), INTENT(OUT) :: zmat(npg,npl,rfr%nloc)
      !
      ! Workspace
      !
      INTEGER :: ierr
946
      CHARACTER(LEN=512) :: dirname,fname
Marco Govoni's avatar
Marco Govoni committed
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      CHARACTER(29) :: my_label
      INTEGER :: local_j,global_j
      INTEGER :: ip,ip_glob
      COMPLEX(DP),ALLOCATABLE :: tmp_dmat(:,:,:)
      COMPLEX(DP),ALLOCATABLE :: tmp_zmat(:,:,:)
      LOGICAL :: lproc
      INTEGER :: iunit
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sw_restart')
      time_spent(1)=get_clock('sw_restart')
      !
      ! CREATE THE SUMMARY FILE
      !
      fname = "summary_w.xml"
      CALL read_bks( bks, dirname, fname )
      !
      ! READ
      !
      ALLOCATE( tmp_dmat( npg, npl, ifr%nglob ))
      !
      WRITE(my_label,'("dmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label) 
      lproc = (me_bgrp==0) 
      iunit = 2000 + my_image_id
      CALL serial_data_read(lproc,iunit,fname,tmp_dmat,npg,npl,ifr%nglob)
      !
      CALL mp_bcast( tmp_dmat, 0, intra_bgrp_comm)
      DO ip = 1, ifr%nloc
         ip_glob = ifr%l2g(ip)
         dmat(:,:,ip) = tmp_dmat(:,:,ip_glob)
      ENDDO
      DEALLOCATE(tmp_dmat)
      !
      ALLOCATE( tmp_zmat( npg, npl, rfr%nglob ))
      !
      WRITE(my_label,'("zmat_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bks%lastdone_ks, bks%lastdone_band, my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label) 
      lproc = (me_bgrp==0) 
      iunit = 2000 + my_image_id
      CALL serial_data_read(lproc,iunit,fname,tmp_zmat,npg,npl,rfr%nglob)
      !
      CALL mp_bcast( tmp_zmat, 0, intra_bgrp_comm)
      DO ip = 1, rfr%nloc
         ip_glob = rfr%l2g(ip)
         zmat(:,:,ip) = tmp_zmat(:,:,ip_glob)
      ENDDO
      DEALLOCATE(tmp_zmat)
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      time_spent(2)=get_clock('sw_restart')
      CALL stop_clock('sw_restart')
      !
      WRITE(stdout,'(1/, 5x,"[I/O] -------------------------------------------------------")')
      WRITE(stdout, "(5x, '[I/O] RESTART read in ',a20)") human_readable_time(time_spent(2)-time_spent(1)) 
      WRITE(stdout, "(5x, '[I/O] In location : ',a)") TRIM( dirname )  
      WRITE(stdout,'(5x,"[I/O] -------------------------------------------------------")')
      !
    END SUBROUTINE
    !
1020
    !------------------------------------------------------------------------
1021
    SUBROUTINE solvewfreq_restart_read_complex_q( bksq, dmat, zmat, npg, npl )
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage,intra_bgrp_comm
      USE mp_world,             ONLY : mpime,root,world_comm
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      USE distribution_center,  ONLY : ifr,rfr
      USE west_io,              ONLY : serial_data_read 
      USE types_bz_grid,        ONLY : q_grid
      !
      IMPLICIT NONE
      !
      ! I/O
      !
1037
      TYPE(bksq_type), INTENT(OUT) :: bksq
1038
      INTEGER, INTENT(IN) :: npg, npl
1039
1040
      COMPLEX(DP), INTENT(OUT) :: dmat(npg,npl,ifr%nloc,q_grid%np)
      COMPLEX(DP), INTENT(OUT) :: zmat(npg,npl,rfr%nloc,q_grid%np)
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
      !
      ! Workspace
      !
      INTEGER :: ierr
      CHARACTER(LEN=512) :: dirname,fname
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      CHARACTER(37) :: my_label
      INTEGER :: local_j,global_j
      INTEGER :: ip,ip_glob,iq
      COMPLEX(DP),ALLOCATABLE :: tmp_dmat(:,:,:,:)
      COMPLEX(DP),ALLOCATABLE :: tmp_zmat(:,:,:,:)
      LOGICAL :: lproc
      INTEGER :: iunit
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sw_restart')
      time_spent(1)=get_clock('sw_restart')
      !
      ! CREATE THE SUMMARY FILE
      !
      fname = "summary_w.xml"
1072
      CALL read_bksq( bksq, dirname, fname )
1073
1074
1075
      !
      ! READ
      !
1076
      ALLOCATE( tmp_dmat( npg, npl, ifr%nglob, q_grid%np ))
1077
      !
1078
      WRITE(my_label,'("dmat_iq",i5.5,"_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bksq%lastdone_q,bksq%lastdone_ks,bksq%lastdone_band,&
1079
1080
1081
1082
                                                                          & my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label) 
      lproc = (me_bgrp==0) 
      iunit = 2000 + my_image_id
1083
      CALL serial_data_read(lproc,iunit,fname,tmp_dmat,npg,npl,ifr%nglob,q_grid%np)
1084
1085
      !
      CALL mp_bcast( tmp_dmat, 0, intra_bgrp_comm)
1086
      DO iq = 1, q_grid%np
1087
1088
1089
1090
1091
1092
1093
         DO ip = 1, ifr%nloc
            ip_glob = ifr%l2g(ip)
            dmat(:,:,ip,iq) = tmp_dmat(:,:,ip_glob,iq)
         ENDDO
      ENDDO
      DEALLOCATE(tmp_dmat)
      !
1094
      ALLOCATE( tmp_zmat( npg, npl, rfr%nglob, q_grid%np ))
1095
      !
1096
      WRITE(my_label,'("zmat_iq",i5.5,"_iks",i5.5,"_iv",i5.5,"_I",i6.6)') bksq%lastdone_q,bksq%lastdone_ks,bksq%lastdone_band,&
1097
1098
1099
1100
                                                                          & my_image_id
      fname=TRIM( dirname ) // '/' // TRIM(my_label) 
      lproc = (me_bgrp==0) 
      iunit = 2000 + my_image_id
1101
      CALL serial_data_read(lproc,iunit,fname,tmp_zmat,npg,npl,rfr%nglob,q_grid%np)
1102
1103
      !
      CALL mp_bcast( tmp_zmat, 0, intra_bgrp_comm)
1104
      DO iq = 1, q_grid%np
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
         DO ip = 1, rfr%nloc
            ip_glob = rfr%l2g(ip)
            zmat(:,:,ip,iq) = tmp_zmat(:,:,ip_glob,iq)
         ENDDO
      ENDDO
      DEALLOCATE(tmp_zmat)
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      time_spent(2)=get_clock('sw_restart')
      CALL stop_clock('sw_restart')
      !
      WRITE(stdout,'(1/, 5x,"[I/O] -------------------------------------------------------")')
      WRITE(stdout, "(5x, '[I/O] RESTART read in ',a20)") human_readable_time(time_spent(2)-time_spent(1)) 
      WRITE(stdout, "(5x, '[I/O] In location : ',a)") TRIM( dirname )  
      WRITE(stdout,'(5x,"[I/O] -------------------------------------------------------")')
      !
    END SUBROUTINE
    !
Marco Govoni's avatar
Marco Govoni committed
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
    !
    ! GFREQ
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvegfreq_restart_write( bks )
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type), INTENT(IN) :: bks
      !
      ! Workspace
      !
      INTEGER :: ierr
1148
      CHARACTER(LEN=512) :: dirname,fname
Marco Govoni's avatar
Marco Govoni committed
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sg_restart')
      !
      fname = "summary_g.xml"
      CALL write_bks( bks, dirname, fname )
      !
      CALL stop_clock('sg_restart')
      !
    END SUBROUTINE
    !
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
    !------------------------------------------------------------------------
    SUBROUTINE solvegfreq_restart_write_q( bksks )
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage
      USE mp_world,             ONLY : mpime,root,world_comm,nproc
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      USE io_files,             ONLY : delete_if_present
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bksks_type), INTENT(IN) :: bksks
      !
      ! Workspace
      !
      INTEGER :: ierr
      CHARACTER(LEN=512) :: dirname,fname
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sg_restart')
      !
      fname = "summary_g.xml"
      CALL write_bksks( bksks, dirname, fname )
      !
      CALL stop_clock('sg_restart')
      !
    END SUBROUTINE
Marco Govoni's avatar
Marco Govoni committed
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
    !
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvegfreq_restart_read( bks )
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage
      USE mp_world,             ONLY : mpime,root,world_comm
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bks_type),INTENT(OUT) :: bks 
      !
      ! Workspace
      !
      INTEGER :: ierr
1234
      CHARACTER(LEN=512) :: dirname,fname
Marco Govoni's avatar
Marco Govoni committed
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sg_restart')
      time_spent(1)=get_clock('sg_restart')
      !
      fname = "summary_g.xml"
      CALL read_bks( bks, dirname, fname ) 
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      time_spent(2)=get_clock('sg_restart')
      CALL stop_clock('sg_restart')
      !
      WRITE(stdout,'(1/, 5x,"[I/O] -------------------------------------------------------")')
      WRITE(stdout, "(5x, '[I/O] RESTART read in ',a20)") human_readable_time(time_spent(2)-time_spent(1)) 
      WRITE(stdout, "(5x, '[I/O] In location : ',a)") TRIM( dirname )  
      WRITE(stdout,'(5x,"[I/O] -------------------------------------------------------")')
      !
    END SUBROUTINE
    !
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
    !
    !
    !------------------------------------------------------------------------
    SUBROUTINE solvegfreq_restart_read_q( bksks )
      !------------------------------------------------------------------------
      !
      USE mp_global,            ONLY : my_image_id,me_bgrp,inter_image_comm,nimage
      USE mp_world,             ONLY : mpime,root,world_comm
      USE io_global,            ONLY : stdout 
      USE westcom,              ONLY : west_prefix
      USE mp,                   ONLY : mp_barrier,mp_bcast,mp_get
      !
      IMPLICIT NONE
      !
      ! I/O
      !
      TYPE(bksks_type),INTENT(OUT) :: bksks
      !
      ! Workspace
      !
      INTEGER :: ierr
      CHARACTER(LEN=512) :: dirname,fname
      REAL(DP), EXTERNAL :: GET_CLOCK
      REAL(DP) :: time_spent(2)
      CHARACTER(20),EXTERNAL :: human_readable_time
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      !
      ! MKDIR 
      !
      dirname = TRIM( tmp_dir ) // TRIM( west_prefix ) // '.wfreq.restart'
      CALL my_mkdir( dirname )
      !
      CALL start_clock('sg_restart')
      time_spent(1)=get_clock('sg_restart')
      !
      fname = "summary_g.xml"
      CALL read_bksks( bksks, dirname, fname ) 
      !
      ! BARRIER
      !
      CALL mp_barrier(world_comm)
      time_spent(2)=get_clock('sg_restart')
      CALL stop_clock('sg_restart')
      !
      WRITE(stdout,'(1/, 5x,"[I/O] -------------------------------------------------------")')
      WRITE(stdout, "(5x, '[I/O] RESTART read in ',a20)") human_readable_time(time_spent(2)-time_spent(1)) 
      WRITE(stdout, "(5x, '[I/O] In location : ',a)") TRIM( dirname )  
      WRITE(stdout,'(5x,"[I/O] -------------------------------------------------------")')
      !
    END SUBROUTINE
    !
Marco Govoni's avatar
Marco Govoni committed
1321
END MODULE