forked from cp2k/cp2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmc_messages.F
1688 lines (1529 loc) · 81.2 KB
/
tmc_messages.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-2025 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief set up the different message for different tasks
!> A TMC message consists of 3 parts (messages)
!> 1: first a message with task type (STATUS) and SIZES of submessages
!> 2: (if existing) a message with INTEGER values
!> 3: (if existing) a message with REAL values
!> submessages 2 and 3 include relevant data, e.g. positions, box sizes...
!> \par History
!> 11.2012 created [Mandes Schoenherr]
!> \author Mandes
! **************************************************************************************************
MODULE tmc_messages
USE cp_log_handling, ONLY: cp_to_string
USE kinds, ONLY: default_string_length,&
dp
USE message_passing, ONLY: mp_any_source,&
mp_any_tag,&
mp_para_env_type
USE tmc_move_handle, ONLY: add_mv_prob
USE tmc_stati, ONLY: &
TMC_CANCELING_MESSAGE, TMC_CANCELING_RECEIPT, TMC_STATUS_CALCULATING, TMC_STATUS_FAILED, &
TMC_STATUS_STOP_RECEIPT, TMC_STATUS_WAIT_FOR_NEW_TASK, TMC_STATUS_WORKER_INIT, &
TMC_STAT_ANALYSIS_REQUEST, TMC_STAT_ANALYSIS_RESULT, TMC_STAT_APPROX_ENERGY_REQUEST, &
TMC_STAT_APPROX_ENERGY_RESULT, TMC_STAT_ENERGY_REQUEST, TMC_STAT_ENERGY_RESULT, &
TMC_STAT_INIT_ANALYSIS, TMC_STAT_MD_BROADCAST, TMC_STAT_MD_REQUEST, TMC_STAT_MD_RESULT, &
TMC_STAT_NMC_BROADCAST, TMC_STAT_NMC_REQUEST, TMC_STAT_NMC_RESULT, &
TMC_STAT_SCF_STEP_ENER_RECEIVE, TMC_STAT_START_CONF_REQUEST, TMC_STAT_START_CONF_RESULT, &
task_type_gaussian_adaptation
USE tmc_tree_build, ONLY: allocate_new_sub_tree_node
USE tmc_tree_types, ONLY: elem_array_type,&
elem_list_type,&
tree_type
USE tmc_types, ONLY: allocate_tmc_atom_type,&
tmc_atom_type,&
tmc_param_type
#include "../base/base_uses.f90"
IMPLICIT NONE
PRIVATE
LOGICAL, PARAMETER, PUBLIC :: send_msg = .TRUE.
LOGICAL, PARAMETER, PUBLIC :: recv_msg = .FALSE.
INTEGER, PARAMETER :: message_end_flag = 25
INTEGER, PARAMETER :: DEBUG = 0
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_messages'
PUBLIC :: check_if_group_master
PUBLIC :: tmc_message
PUBLIC :: communicate_atom_types
PUBLIC :: stop_whole_group
INTEGER, PARAMETER, PUBLIC :: MASTER_COMM_ID = 0 ! id for master and group master
INTEGER, PARAMETER, PUBLIC :: bcast_group = -1 ! destination flag for broadcasting to other group participants
INTEGER, PARAMETER :: TMC_SEND_INFO_SIZE = 4 ! usually: 1. status, array sizes: 2. int, 3. real, 4. char
TYPE message_send
INTEGER, DIMENSION(TMC_SEND_INFO_SIZE) :: info = -1
REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: task_real
INTEGER, DIMENSION(:), ALLOCATABLE :: task_int
CHARACTER, DIMENSION(:), ALLOCATABLE :: task_char
!should be deleted somewhen
INTEGER, DIMENSION(:), ALLOCATABLE :: elem_stat
END TYPE message_send
CONTAINS
! **************************************************************************************************
!> \brief checks if the core is the group master
!> \param para_env defines the mpi communicator
!> \return return value, logical
!> \author Mandes 01.2013
! **************************************************************************************************
FUNCTION check_if_group_master(para_env) RESULT(master)
TYPE(mp_para_env_type), POINTER :: para_env
LOGICAL :: master
CPASSERT(ASSOCIATED(para_env))
master = .FALSE.
IF (para_env%mepos .EQ. MASTER_COMM_ID) &
master = .TRUE.
END FUNCTION check_if_group_master
! **************************************************************************************************
!> \brief tmc message handling, packing messages with integer and real data
!> type. Send first info message with task type and message sizes and
!> then the int and real messages. The same for receiving
!> \param msg_type defines the message types, see message tags definition
!> \param send_recv 1= send, 0= receive
!> \param dest defines the target or source of message
!> (-1=braodcast, 0= master, 1... working group)
!> \param para_env defines the mpi communicator
!> \param tmc_params stuct with parameters (global settings)
!> \param elem a subtree element from which info are readed or written in
!> \param elem_array ...
!> \param list_elem ...
!> \param result_count ...
!> \param wait_for_message ...
!> \param success ...
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE tmc_message(msg_type, send_recv, dest, para_env, tmc_params, &
elem, elem_array, list_elem, result_count, &
wait_for_message, success)
INTEGER :: msg_type
LOGICAL :: send_recv
INTEGER :: dest
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(tmc_param_type), POINTER :: tmc_params
TYPE(tree_type), OPTIONAL, POINTER :: elem
TYPE(elem_array_type), DIMENSION(:), OPTIONAL :: elem_array
TYPE(elem_list_type), OPTIONAL, POINTER :: list_elem
INTEGER, DIMENSION(:), OPTIONAL, POINTER :: result_count
LOGICAL, OPTIONAL :: wait_for_message, success
INTEGER :: i, message_tag, tmp_tag
LOGICAL :: act_send_recv, flag
TYPE(message_send), POINTER :: m_send
CPASSERT(ASSOCIATED(para_env))
CPASSERT(ASSOCIATED(tmc_params))
ALLOCATE (m_send)
! init
! define send_recv flag for broadcast
IF (dest .EQ. bcast_group) THEN
! master should always send
IF (para_env%mepos .EQ. MASTER_COMM_ID) THEN
act_send_recv = send_msg
ELSE
! worker should always receive
act_send_recv = recv_msg
END IF
ELSE
act_send_recv = send_recv
END IF
message_tag = 0
! =============================
! sending message
! =============================
! creating message to send
IF (act_send_recv .EQV. send_msg) THEN
IF ((DEBUG .GE. 7) .AND. (dest .NE. bcast_group) .AND. &
(dest .NE. MASTER_COMM_ID)) THEN
IF (PRESENT(elem)) THEN
WRITE (*, *) "send element info to ", dest, " of type ", msg_type, "of subtree", elem%sub_tree_nr, &
"elem", elem%nr
ELSE
WRITE (*, *) "send element info to ", dest, " of type ", msg_type
END IF
END IF
SELECT CASE (msg_type)
CASE (TMC_STAT_START_CONF_REQUEST, TMC_STATUS_FAILED, TMC_CANCELING_MESSAGE, &
TMC_CANCELING_RECEIPT, TMC_STATUS_STOP_RECEIPT, &
TMC_STATUS_WAIT_FOR_NEW_TASK, TMC_STATUS_CALCULATING, &
TMC_STAT_ANALYSIS_RESULT)
CALL create_status_message(m_send)
CASE (TMC_STATUS_WORKER_INIT)
CALL create_worker_init_message(tmc_params, m_send)
CASE (TMC_STAT_START_CONF_RESULT, TMC_STAT_INIT_ANALYSIS)
CALL create_start_conf_message(msg_type, elem, result_count, tmc_params, m_send)
CASE (TMC_STAT_ENERGY_REQUEST, TMC_STAT_APPROX_ENERGY_REQUEST)
CALL create_energy_request_message(elem, m_send, tmc_params)
CASE (TMC_STAT_APPROX_ENERGY_RESULT)
CALL create_approx_energy_result_message(elem, m_send, tmc_params)
CASE (TMC_STAT_ENERGY_RESULT)
CALL create_energy_result_message(elem, m_send, tmc_params)
CASE (TMC_STAT_NMC_REQUEST, TMC_STAT_NMC_BROADCAST, &
TMC_STAT_MD_REQUEST, TMC_STAT_MD_BROADCAST)
CALL create_NMC_request_massage(msg_type, elem, m_send, tmc_params)
CASE (TMC_STAT_MD_RESULT, TMC_STAT_NMC_RESULT)
CALL create_NMC_result_massage(msg_type, elem, m_send, tmc_params)
CASE (TMC_STAT_ANALYSIS_REQUEST)
CPASSERT(PRESENT(list_elem))
CALL create_analysis_request_message(list_elem, m_send, tmc_params)
CASE DEFAULT
CPABORT("try to send unknown message type "//cp_to_string(msg_type))
END SELECT
!set message info
message_tag = msg_type
m_send%info(:) = 0
m_send%info(1) = msg_type
IF (ALLOCATED(m_send%task_int)) m_send%info(2) = SIZE(m_send%task_int)
IF (ALLOCATED(m_send%task_real)) m_send%info(3) = SIZE(m_send%task_real)
IF (ALLOCATED(m_send%task_char)) m_send%info(4) = SIZE(m_send%task_char)
END IF
! sending message
IF ((act_send_recv .EQV. send_msg) .AND. (dest .NE. bcast_group)) THEN
CALL para_env%send(m_send%info, dest, message_tag)
IF (m_send%info(2) .GT. 0) THEN
CALL para_env%send(m_send%task_int, dest, message_tag)
END IF
IF (m_send%info(3) .GT. 0) THEN
CALL para_env%send(m_send%task_real, dest, message_tag)
END IF
IF (m_send%info(4) .GT. 0) THEN
CPABORT("")
!TODO send characters CALL para_env%send(m_send%task_char, dest, message_tag)
END IF
IF (DEBUG .GE. 1) &
WRITE (*, *) "TMC|message: ID: ", para_env%mepos, &
" send element info to ", dest, " of stat ", m_send%info(1), &
" with size int/real/char", m_send%info(2:), " with comm ", &
para_env%get_handle(), " and tag ", message_tag
IF (m_send%info(2) .GT. 0) DEALLOCATE (m_send%task_int)
IF (m_send%info(3) .GT. 0) DEALLOCATE (m_send%task_real)
IF (m_send%info(4) .GT. 0) DEALLOCATE (m_send%task_char)
IF (PRESENT(success)) success = .TRUE.
END IF
! =============================
! broadcast
! =============================
IF (dest .EQ. bcast_group) THEN
IF (para_env%num_pe .GT. 1) THEN
CALL para_env%bcast(m_send%info, MASTER_COMM_ID)
IF (m_send%info(2) .GT. 0) THEN
IF (.NOT. act_send_recv) ALLOCATE (m_send%task_int(m_send%info(2)))
CALL para_env%bcast(m_send%task_int, MASTER_COMM_ID)
END IF
IF (m_send%info(3) .GT. 0) THEN
IF (.NOT. act_send_recv) ALLOCATE (m_send%task_real(m_send%info(3)))
CALL para_env%bcast(m_send%task_real, MASTER_COMM_ID)
END IF
IF (m_send%info(4) .GT. 0) THEN
IF (.NOT. act_send_recv) ALLOCATE (m_send%task_char(m_send%info(3)))
CPABORT("")
!TODO bcast char CALL para_env%bcast(m_send%task_char, MASTER_COMM_ID)
END IF
END IF
! sender delete arrays
IF (act_send_recv) THEN
IF (m_send%info(2) .GT. 0) DEALLOCATE (m_send%task_int)
IF (m_send%info(3) .GT. 0) DEALLOCATE (m_send%task_real)
IF (m_send%info(4) .GT. 0) DEALLOCATE (m_send%task_char)
END IF
END IF
! =============================
! receiving message
! =============================
IF ((act_send_recv .EQV. recv_msg) .AND. dest .NE. bcast_group) THEN
flag = .FALSE.
tmp_tag = TMC_STATUS_WAIT_FOR_NEW_TASK
IF (PRESENT(wait_for_message)) THEN
dest = mp_any_source
CALL para_env%probe(dest, tmp_tag)
flag = .TRUE.
ELSE
participant_loop: DO i = 0, para_env%num_pe - 1
IF (i .NE. para_env%mepos) THEN
dest = i
CALL para_env%probe(dest, tmp_tag)
IF (dest .EQ. i) THEN
flag = .TRUE.
EXIT participant_loop
END IF
END IF
END DO participant_loop
END IF
IF (flag .EQV. .FALSE.) THEN
IF (PRESENT(success)) success = .FALSE.
DEALLOCATE (m_send)
RETURN
END IF
IF (tmp_tag .EQ. TMC_STAT_SCF_STEP_ENER_RECEIVE) THEN
! CP2K send back SCF step energies without info message
message_tag = TMC_STAT_SCF_STEP_ENER_RECEIVE
m_send%info(1) = TMC_STAT_SCF_STEP_ENER_RECEIVE
m_send%info(2) = 0 ! no integer values
m_send%info(3) = 1 ! one double values (SCF total energy)
m_send%info(4) = 0 ! no character values
ELSE
message_tag = mp_any_tag
! first get message type and sizes
CALL para_env%recv(m_send%info, dest, message_tag)
END IF
IF (DEBUG .GE. 1) &
WRITE (*, *) "TMC|message: ID: ", para_env%mepos, &
" recv element info from ", dest, " of stat ", m_send%info(1), &
" with size int/real/char", m_send%info(2:)
!-- receive message integer part
IF (m_send%info(2) .GT. 0) THEN
ALLOCATE (m_send%task_int(m_send%info(2)))
CALL para_env%recv(m_send%task_int, dest, message_tag)
END IF
!-- receive message double (floatingpoint) part
IF (m_send%info(3) .GT. 0) THEN
ALLOCATE (m_send%task_real(m_send%info(3)))
CALL para_env%recv(m_send%task_real, dest, message_tag)
END IF
!-- receive message character part
IF (m_send%info(4) .GT. 0) THEN
ALLOCATE (m_send%task_char(m_send%info(4)))
CPABORT("")
!TODO recv characters CALL para_env%recv(m_send%task_char, dest, message_tag)
END IF
END IF
! handling received message
IF (act_send_recv .EQV. recv_msg) THEN
! if the element is supposed to be canceled but received message is not canceling receipt do not handle element
! (because element could be already deallocated, and hence a new element would be created -> not necessary)
IF (PRESENT(elem_array)) THEN
IF (elem_array(dest)%canceled .AND. m_send%info(1) .NE. TMC_CANCELING_RECEIPT) THEN
msg_type = m_send%info(1)
IF (m_send%info(2) .GT. 0) DEALLOCATE (m_send%task_int)
IF (m_send%info(3) .GT. 0) DEALLOCATE (m_send%task_real)
IF (m_send%info(4) .GT. 0) DEALLOCATE (m_send%task_char)
! to check for further messages
IF (PRESENT(success)) success = .TRUE.
DEALLOCATE (m_send)
RETURN
END IF
END IF
msg_type = m_send%info(1)
SELECT CASE (m_send%info(1))
CASE (TMC_STAT_START_CONF_REQUEST, TMC_CANCELING_MESSAGE, &
TMC_CANCELING_RECEIPT, TMC_STATUS_WAIT_FOR_NEW_TASK, &
TMC_STATUS_CALCULATING, TMC_STAT_ANALYSIS_RESULT)
! nothing to do here
CASE (TMC_STATUS_WORKER_INIT)
CALL read_worker_init_message(tmc_params, m_send)
CASE (TMC_STAT_START_CONF_RESULT, TMC_STAT_INIT_ANALYSIS)
IF (PRESENT(elem_array)) THEN
CALL read_start_conf_message(msg_type, elem_array(dest)%elem, &
result_count, m_send, tmc_params)
ELSE
CALL read_start_conf_message(msg_type, elem, result_count, m_send, &
tmc_params)
END IF
CASE (TMC_STAT_APPROX_ENERGY_RESULT)
CALL read_approx_energy_result(elem_array(dest)%elem, m_send, tmc_params)
CASE (TMC_STAT_ENERGY_REQUEST, TMC_STAT_APPROX_ENERGY_REQUEST)
CALL read_energy_request_message(elem, m_send, tmc_params)
CASE (TMC_STAT_ENERGY_RESULT)
IF (PRESENT(elem_array)) &
CALL read_energy_result_message(elem_array(dest)%elem, m_send, tmc_params)
CASE (TMC_STAT_NMC_REQUEST, TMC_STAT_NMC_BROADCAST, &
TMC_STAT_MD_REQUEST, TMC_STAT_MD_BROADCAST)
CALL read_NMC_request_massage(msg_type, elem, m_send, tmc_params)
CASE (TMC_STAT_NMC_RESULT, TMC_STAT_MD_RESULT)
IF (PRESENT(elem_array)) &
CALL read_NMC_result_massage(msg_type, elem_array(dest)%elem, m_send, tmc_params)
CASE (TMC_STATUS_FAILED, TMC_STATUS_STOP_RECEIPT)
! if task is failed, handle situation in outer routine
CASE (TMC_STAT_SCF_STEP_ENER_RECEIVE)
CALL read_scf_step_ener(elem_array(dest)%elem, m_send)
CASE (TMC_STAT_ANALYSIS_REQUEST)
CALL read_analysis_request_message(elem, m_send, tmc_params)
CASE DEFAULT
CALL cp_abort(__LOCATION__, &
"try to receive unknown message type "//cp_to_string(msg_type)// &
"from source "//cp_to_string(dest))
END SELECT
IF (m_send%info(2) .GT. 0) DEALLOCATE (m_send%task_int)
IF (m_send%info(3) .GT. 0) DEALLOCATE (m_send%task_real)
IF (m_send%info(4) .GT. 0) DEALLOCATE (m_send%task_char)
IF (PRESENT(success)) success = .TRUE.
END IF
! ATTENTION there is also an short exit (RETURN) after probing for new messages
DEALLOCATE (m_send)
END SUBROUTINE tmc_message
! **************************************************************************************************
!> \brief set the messege just with an status tag
!> \param m_send the message structure
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE create_status_message(m_send)
TYPE(message_send), POINTER :: m_send
CPASSERT(ASSOCIATED(m_send))
! nothing to do, send just the message tag
CPASSERT(.NOT. ALLOCATED(m_send%task_int))
CPASSERT(.NOT. ALLOCATED(m_send%task_real))
MARK_USED(m_send)
END SUBROUTINE create_status_message
!============================================================================
! message for requesting start configuration
!============================================================================
!! **************************************************************************************************
!!> \brief the message for sending the atom mass
!!> (number of atoms is also tranfered)
!!> atom names have to be done separately,
!!> because character send only with bcast possible
!!> \param tmc_parms th send the cell properties
!!> \param m_send the message structure
!!> \param error variable to control error logging, stopping,...
!!> see module cp_error_handling
!!> \author Mandes 02.2013
!! **************************************************************************************************
! SUBROUTINE create_atom_mass_message(m_send, atoms)
! TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms
! TYPE(message_send), POINTER :: m_send
!
! CHARACTER(LEN=*), PARAMETER :: routineN = 'create_atom_mass_message', &
! routineP = moduleN//':'//routineN
!
! INTEGER :: counter, i, &
! msg_size_real
! LOGICAL :: failure
!
! failure = .FALSE.
!
! CPPrecondition(ASSOCIATED(m_send),cp_failure_level,routineP,failure)
! CPPrecondition(.NOT.ALLOCATED(m_send%task_int),cp_failure_level,routineP,failure)
! CPPrecondition(.NOT.ALLOCATED(m_send%task_real),cp_failure_level,routineP,failure)
! CPPrecondition(.NOT.ALLOCATED(m_send%task_char),cp_failure_level,routineP,failure)
!
! counter =1
! msg_size_real = 1+SIZE(tmc_params%cell%hmat)+ 1+SIZE(atoms) +1
! ALLOCATE(m_send%task_real(msg_size_real))
!
! m_send%task_real(1) = REAL(SIZE(atoms,KIND=dp))
! DO i=1, SIZE(atoms)
! m_send%task_real(counter+i) = atoms(i)%mass
! END DO
! counter = counter + 1+INT(m_send%task_real(counter))
! m_send%task_real(counter) = REAL(message_end_flag, KIND=dp) !message end
! CPPostconditionNoFail(INT(m_send%task_real(msg_size_real)).EQ.message_end_flag,cp_failure_level,routineP)
! END SUBROUTINE create_atom_mass_message
!
!! **************************************************************************************************
!!> \brief the message for reading the atom mass
!!> (number of atoms is also tranfered)
!!> atom names have to be done separately,
!!> because character send only with bcast possible
!!> \param tmc_parms th send the cell properties
!!> \param m_send the message structure
!!> \param error variable to control error logging, stopping,...
!!> see module cp_error_handling
!!> \author Mandes 02.2013
!! **************************************************************************************************
! SUBROUTINE read_atom_mass_message(m_send, atoms)
! TYPE(tmc_atom_type), DIMENSION(:), &
! POINTER :: atoms
! TYPE(message_send), POINTER :: m_send
!
! CHARACTER(LEN=*), PARAMETER :: routineN = 'read_atom_mass_message', &
! routineP = moduleN//':'//routineN
!
! INTEGER :: counter, i, nr_atoms
! LOGICAL :: failure
!
! failure = .FALSE.
!
! CPPrecondition(ASSOCIATED(m_send),cp_failure_level,routineP,failure)
! CPPrecondition(.NOT.ALLOCATED(m_send%task_int),cp_failure_level,routineP,failure)
! CPPrecondition(ALLOCATED(m_send%task_real),cp_failure_level,routineP,failure)
! CPPrecondition(.NOT.ALLOCATED(m_send%task_char),cp_failure_level,routineP,failure)
!
! counter =1
! nr_atoms = m_send%task_real(counter)
! IF(.NOT.ASSOCIATED(atoms)) CALL allocate_tmc_atom_type(atoms, nr_atoms)
! DO i=1, SIZE(atoms)
! atoms(i)%mass = m_send%task_real(counter+i)
! END DO
! counter = counter + 1+INT(m_send%task_real(counter))
! CPPostconditionNoFail(INT(m_send%task_real(counter)).EQ.message_end_flag,cp_failure_level,routineP)
! END SUBROUTINE read_atom_mass_message
! **************************************************************************************************
!> \brief the message for the initial values (cell size) to the workers
!> \param tmc_params to send the cell properties
!> \param m_send the message structure
!> \author Mandes 07.2013
! **************************************************************************************************
SUBROUTINE create_worker_init_message(tmc_params, m_send)
TYPE(tmc_param_type), POINTER :: tmc_params
TYPE(message_send), POINTER :: m_send
INTEGER :: counter, msg_size_int, msg_size_real
CPASSERT(ASSOCIATED(tmc_params))
CPASSERT(ASSOCIATED(m_send))
CPASSERT(.NOT. ALLOCATED(m_send%task_int))
CPASSERT(.NOT. ALLOCATED(m_send%task_real))
CPASSERT(.NOT. ALLOCATED(m_send%task_char))
CPASSERT(ASSOCIATED(tmc_params%cell))
counter = 1
msg_size_int = 1 + SIZE(tmc_params%cell%perd) + 1 + 1 + 1 + 1
ALLOCATE (m_send%task_int(msg_size_int))
m_send%task_int(counter) = SIZE(tmc_params%cell%perd) ! periodicity of the cell
counter = counter + 1 + m_send%task_int(counter)
m_send%task_int(2:counter - 1) = tmc_params%cell%perd(:)
m_send%task_int(counter) = 1
m_send%task_int(counter + 1) = tmc_params%cell%symmetry_id
m_send%task_int(counter + 2) = 0
IF (tmc_params%cell%orthorhombic) m_send%task_int(counter + 2) = 1
counter = counter + 3
m_send%task_int(counter) = message_end_flag
CPASSERT(counter .EQ. SIZE(m_send%task_int))
!float array with cell vectors
msg_size_real = 1 + SIZE(tmc_params%cell%hmat) + 1
ALLOCATE (m_send%task_real(msg_size_real))
counter = 1
m_send%task_real(counter) = SIZE(tmc_params%cell%hmat) ! cell vectors for cell size
m_send%task_real(counter + 1:counter + SIZE(tmc_params%cell%hmat)) = &
RESHAPE(tmc_params%cell%hmat(:, :), &
(/SIZE(tmc_params%cell%hmat)/))
counter = counter + 1 + INT(m_send%task_real(counter))
m_send%task_real(counter) = REAL(message_end_flag, KIND=dp) !message end
CPASSERT(SIZE(m_send%task_real) .EQ. msg_size_real)
CPASSERT(INT(m_send%task_real(msg_size_real)) .EQ. message_end_flag)
END SUBROUTINE create_worker_init_message
! **************************************************************************************************
!> \brief the message for the initial values (cell size) to the workers
!> \param tmc_params to send the cell properties
!> \param m_send the message structure
!> \author Mandes 07.2013
! **************************************************************************************************
SUBROUTINE read_worker_init_message(tmc_params, m_send)
TYPE(tmc_param_type), POINTER :: tmc_params
TYPE(message_send), POINTER :: m_send
INTEGER :: counter
LOGICAL :: flag
CPASSERT(ASSOCIATED(tmc_params))
CPASSERT(ASSOCIATED(m_send))
CPASSERT(m_send%info(3) .GE. 4)
IF (.NOT. ASSOCIATED(tmc_params%cell)) ALLOCATE (tmc_params%cell)
counter = 1
!int array
flag = INT(m_send%task_int(1)) .EQ. SIZE(tmc_params%cell%perd)
CPASSERT(flag)
counter = 1 + m_send%task_int(1) + 1
tmc_params%cell%perd = m_send%task_int(2:counter - 1)
tmc_params%cell%symmetry_id = m_send%task_int(counter + 1)
tmc_params%cell%orthorhombic = .FALSE.
IF (m_send%task_int(counter + 2) .EQ. 1) tmc_params%cell%orthorhombic = .TRUE.
counter = counter + 3
CPASSERT(counter .EQ. m_send%info(2))
CPASSERT(m_send%task_int(counter) .EQ. message_end_flag)
!float array with cell vectors
counter = 1
flag = INT(m_send%task_real(counter)) .EQ. SIZE(tmc_params%cell%hmat)
CPASSERT(flag)
tmc_params%cell%hmat = &
RESHAPE(m_send%task_real(counter + 1:counter + &
SIZE(tmc_params%cell%hmat)), (/3, 3/))
counter = counter + 1 + INT(m_send%task_real(counter))
CPASSERT(counter .EQ. m_send%info(3))
CPASSERT(INT(m_send%task_real(m_send%info(3))) .EQ. message_end_flag)
END SUBROUTINE read_worker_init_message
! **************************************************************************************************
!> \brief the message for sending back the initial configuration
!> \param msg_type the status tag
!> \param elem the initial tree element with initial coordinates and energy
!> (using the approximated potential)
!> \param result_count ...
!> \param tmc_params to send the cell properties
!> \param m_send the message structure
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE create_start_conf_message(msg_type, elem, result_count, &
tmc_params, m_send)
INTEGER :: msg_type
TYPE(tree_type), POINTER :: elem
INTEGER, DIMENSION(:), OPTIONAL, POINTER :: result_count
TYPE(tmc_param_type), POINTER :: tmc_params
TYPE(message_send), POINTER :: m_send
INTEGER :: counter, i, msg_size_int, msg_size_real
CPASSERT(ASSOCIATED(m_send))
CPASSERT(ASSOCIATED(elem))
CPASSERT(ASSOCIATED(tmc_params))
CPASSERT(ASSOCIATED(tmc_params%atoms))
CPASSERT(.NOT. ALLOCATED(m_send%task_int))
CPASSERT(.NOT. ALLOCATED(m_send%task_real))
CPASSERT(.NOT. ALLOCATED(m_send%task_char))
counter = 1
msg_size_int = 1 + SIZE(tmc_params%cell%perd) + 1 + 1 + 1 + 1 + SIZE(elem%mol) + 1
IF (msg_type .EQ. TMC_STAT_INIT_ANALYSIS) THEN
CPASSERT(PRESENT(result_count))
CPASSERT(ASSOCIATED(result_count))
msg_size_int = msg_size_int + 1 + SIZE(result_count(1:))
END IF
ALLOCATE (m_send%task_int(msg_size_int))
m_send%task_int(counter) = SIZE(tmc_params%cell%perd) ! periodicity of the cell
counter = counter + 1 + m_send%task_int(counter)
m_send%task_int(2:counter - 1) = tmc_params%cell%perd(:)
m_send%task_int(counter) = 1
m_send%task_int(counter + 1) = tmc_params%cell%symmetry_id
m_send%task_int(counter + 2) = 0
IF (tmc_params%cell%orthorhombic) m_send%task_int(counter + 2) = 1
counter = counter + 3
m_send%task_int(counter) = SIZE(elem%mol)
m_send%task_int(counter + 1:counter + m_send%task_int(counter)) = elem%mol(:)
counter = counter + 1 + m_send%task_int(counter)
IF (msg_type .EQ. TMC_STAT_INIT_ANALYSIS) THEN
m_send%task_int(counter) = SIZE(result_count(1:))
m_send%task_int(counter + 1:counter + m_send%task_int(counter)) = &
result_count(1:)
counter = counter + 1 + m_send%task_int(counter)
END IF
m_send%task_int(counter) = message_end_flag
CPASSERT(counter .EQ. SIZE(m_send%task_int))
counter = 0
!float array with pos, cell vectors, atom_mass
msg_size_real = 1 + SIZE(elem%pos) + 1 + SIZE(tmc_params%cell%hmat) &
+ 1 + SIZE(tmc_params%atoms) + 1
ALLOCATE (m_send%task_real(msg_size_real))
m_send%task_real(1) = REAL(SIZE(elem%pos), KIND=dp) ! positions
counter = 2 + INT(m_send%task_real(1))
m_send%task_real(2:counter - 1) = elem%pos
m_send%task_real(counter) = SIZE(tmc_params%cell%hmat) ! cell vectors for cell size
m_send%task_real(counter + 1:counter + SIZE(tmc_params%cell%hmat)) = &
RESHAPE(tmc_params%cell%hmat(:, :), &
(/SIZE(tmc_params%cell%hmat)/))
counter = counter + 1 + INT(m_send%task_real(counter))
m_send%task_real(counter) = SIZE(tmc_params%atoms) ! atom mass
DO i = 1, SIZE(tmc_params%atoms)
m_send%task_real(counter + i) = tmc_params%atoms(i)%mass
END DO
counter = counter + 1 + INT(m_send%task_real(counter))
m_send%task_real(counter) = REAL(message_end_flag, KIND=dp) !message end
CPASSERT(SIZE(m_send%task_real) .EQ. msg_size_real)
CPASSERT(INT(m_send%task_real(msg_size_real)) .EQ. message_end_flag)
END SUBROUTINE create_start_conf_message
! **************************************************************************************************
!> \brief the message for sending back the initial configuration
!> \param msg_type the status tag
!> \param elem the initial tree element with initial coordinates and energy
!> (using the approximated potential)
!> \param result_count ...
!> \param m_send the message structure
!> \param tmc_params the param struct with necessary values for allocation
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE read_start_conf_message(msg_type, elem, result_count, m_send, &
tmc_params)
INTEGER :: msg_type
TYPE(tree_type), POINTER :: elem
INTEGER, DIMENSION(:), OPTIONAL, POINTER :: result_count
TYPE(message_send), POINTER :: m_send
TYPE(tmc_param_type), POINTER :: tmc_params
INTEGER :: counter, i
LOGICAL :: flag
CPASSERT(ASSOCIATED(tmc_params))
CPASSERT(.NOT. ASSOCIATED(tmc_params%atoms))
CPASSERT(ASSOCIATED(m_send))
CPASSERT(.NOT. ASSOCIATED(elem))
CPASSERT(m_send%info(3) .GE. 4)
IF (.NOT. ASSOCIATED(tmc_params%cell)) ALLOCATE (tmc_params%cell)
CALL allocate_new_sub_tree_node(tmc_params=tmc_params, next_el=elem, &
nr_dim=NINT(m_send%task_real(1)))
counter = 1
!int array
flag = INT(m_send%task_int(1)) .EQ. SIZE(tmc_params%cell%perd)
CPASSERT(flag)
counter = 1 + m_send%task_int(1) + 1
tmc_params%cell%perd = m_send%task_int(2:counter - 1)
tmc_params%cell%symmetry_id = m_send%task_int(counter + 1)
tmc_params%cell%orthorhombic = .FALSE.
IF (m_send%task_int(counter + 2) .EQ. 1) tmc_params%cell%orthorhombic = .TRUE.
counter = counter + 3
elem%mol(:) = m_send%task_int(counter + 1:counter + m_send%task_int(counter))
counter = counter + 1 + m_send%task_int(counter)
IF (msg_type .EQ. TMC_STAT_INIT_ANALYSIS) THEN
CPASSERT(PRESENT(result_count))
CPASSERT(.NOT. ASSOCIATED(result_count))
ALLOCATE (result_count(m_send%task_int(counter)))
result_count(:) = m_send%task_int(counter + 1:counter + m_send%task_int(counter))
counter = counter + 1 + m_send%task_int(counter)
END IF
CPASSERT(counter .EQ. m_send%info(2))
CPASSERT(m_send%task_int(counter) .EQ. message_end_flag)
counter = 0
!float array with pos, cell vectors, atom_mass
counter = 2 + INT(m_send%task_real(1))
elem%pos = m_send%task_real(2:counter - 1)
flag = INT(m_send%task_real(counter)) .EQ. SIZE(tmc_params%cell%hmat)
CPASSERT(flag)
tmc_params%cell%hmat = &
RESHAPE(m_send%task_real(counter + 1:counter + &
SIZE(tmc_params%cell%hmat)), (/3, 3/))
counter = counter + 1 + INT(m_send%task_real(counter))
CALL allocate_tmc_atom_type(atoms=tmc_params%atoms, &
nr_atoms=INT(m_send%task_real(counter)))
DO i = 1, SIZE(tmc_params%atoms)
tmc_params%atoms(i)%mass = m_send%task_real(counter + i)
END DO
counter = counter + 1 + INT(m_send%task_real(counter))
CPASSERT(counter .EQ. m_send%info(3))
CPASSERT(INT(m_send%task_real(m_send%info(3))) .EQ. message_end_flag)
END SUBROUTINE read_start_conf_message
!============================================================================
! Energy messages
!============================================================================
! **************************************************************************************************
!> \brief creating message for requesting exact energy of new configuration
!> \param elem tree element with new coordinates
!> \param m_send the message structure
!> \param tmc_params stuct with parameters (global settings)
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE create_energy_request_message(elem, m_send, &
tmc_params)
TYPE(tree_type), POINTER :: elem
TYPE(message_send), POINTER :: m_send
TYPE(tmc_param_type), POINTER :: tmc_params
INTEGER :: counter, msg_size_int, msg_size_real
CPASSERT(ASSOCIATED(m_send))
CPASSERT(.NOT. ALLOCATED(m_send%task_int))
CPASSERT(.NOT. ALLOCATED(m_send%task_real))
CPASSERT(ASSOCIATED(elem))
CPASSERT(ASSOCIATED(tmc_params))
counter = 0
!first integer array
msg_size_int = 1 + 1 + 1 + 1 + 1 ! 1+SIZE(elem%sub_tree_nr) +1+SIZE(elem%nr)
ALLOCATE (m_send%task_int(msg_size_int))
counter = 1
m_send%task_int(counter) = 1 !SIZE(elem%sub_tree_nr)
m_send%task_int(counter + 1:counter + m_send%task_int(counter)) = elem%sub_tree_nr
counter = counter + 1 + m_send%task_int(counter)
m_send%task_int(counter) = 1 !SIZE(elem%nr)
m_send%task_int(counter + 1:counter + m_send%task_int(counter)) = elem%nr
counter = counter + 1 + m_send%task_int(counter)
m_send%task_int(counter) = message_end_flag
CPASSERT(SIZE(m_send%task_int) .EQ. msg_size_int)
CPASSERT(m_send%task_int(msg_size_int) .EQ. message_end_flag)
!then float array with pos
msg_size_real = 1 + SIZE(elem%pos) + 1
IF (tmc_params%pressure .GE. 0.0_dp) msg_size_real = msg_size_real + 1 + SIZE(elem%box_scale(:))
ALLOCATE (m_send%task_real(msg_size_real))
m_send%task_real(1) = SIZE(elem%pos)
counter = 2 + INT(m_send%task_real(1))
m_send%task_real(2:counter - 1) = elem%pos
IF (tmc_params%pressure .GE. 0.0_dp) THEN
m_send%task_real(counter) = SIZE(elem%box_scale)
m_send%task_real(counter + 1:counter + INT(m_send%task_real(counter))) = elem%box_scale(:)
counter = counter + 1 + INT(m_send%task_real(counter))
END IF
m_send%task_real(counter) = REAL(message_end_flag, KIND=dp) !message end
CPASSERT(SIZE(m_send%task_real) .EQ. msg_size_real)
CPASSERT(INT(m_send%task_real(msg_size_real)) .EQ. message_end_flag)
END SUBROUTINE create_energy_request_message
! **************************************************************************************************
!> \brief reading message for requesting exact energy of new configuration
!> \param elem tree element with new coordinates
!> \param m_send the message structure
!> \param tmc_params stuct with parameters (global settings)
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE read_energy_request_message(elem, m_send, tmc_params)
TYPE(tree_type), POINTER :: elem
TYPE(message_send), POINTER :: m_send
TYPE(tmc_param_type), POINTER :: tmc_params
INTEGER :: counter
CPASSERT(ASSOCIATED(m_send))
CPASSERT(m_send%info(3) .GT. 0)
CPASSERT(ASSOCIATED(tmc_params))
CPASSERT(.NOT. ASSOCIATED(elem))
! initialize the new sub tree element
IF (.NOT. ASSOCIATED(elem)) THEN
CALL allocate_new_sub_tree_node(next_el=elem, nr_dim=NINT(m_send%task_real(1)), &
tmc_params=tmc_params)
END IF
! read the integer values
CPASSERT(m_send%info(2) .GT. 0)
counter = 1
elem%sub_tree_nr = m_send%task_int(counter + 1)
counter = counter + 1 + m_send%task_int(counter)
elem%nr = m_send%task_int(counter + 1)
counter = counter + 1 + m_send%task_int(counter)
CPASSERT(m_send%task_int(counter) .EQ. message_end_flag)
!float array with pos
counter = 0
counter = 1 + NINT(m_send%task_real(1))
elem%pos = m_send%task_real(2:counter)
counter = counter + 1
IF (tmc_params%pressure .GE. 0.0_dp) THEN
elem%box_scale(:) = m_send%task_real(counter + 1:counter + INT(m_send%task_real(counter)))
counter = counter + 1 + INT(m_send%task_real(counter))
END IF
CPASSERT(counter .EQ. m_send%info(3))
CPASSERT(INT(m_send%task_real(m_send%info(3))) .EQ. message_end_flag)
END SUBROUTINE read_energy_request_message
! **************************************************************************************************
!> \brief creating message for sending back the exact energy of new conf
!> \param elem tree element with calculated energy
!> \param m_send the message structure
!> \param tmc_params stuct with parameters (global settings)
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE create_energy_result_message(elem, m_send, tmc_params)
TYPE(tree_type), POINTER :: elem
TYPE(message_send), POINTER :: m_send
TYPE(tmc_param_type), POINTER :: tmc_params
INTEGER :: counter, msg_size_int, msg_size_real
CPASSERT(ASSOCIATED(m_send))
CPASSERT(.NOT. ALLOCATED(m_send%task_int))
CPASSERT(.NOT. ALLOCATED(m_send%task_real))
CPASSERT(ASSOCIATED(elem))
CPASSERT(ASSOCIATED(tmc_params))
counter = 0
!first integer array
msg_size_int = 0
! for checking the tree element mapping, send back the tree numbers
IF (DEBUG .GT. 0) THEN
msg_size_int = 1 + 1 + 1 + 1 + 1 ! 1+SIZE(elem%sub_tree_nr) +1+SIZE(elem%nr)
ALLOCATE (m_send%task_int(msg_size_int))
counter = 1
m_send%task_int(counter) = 1 !SIZE(elem%sub_tree_nr)
m_send%task_int(counter + 1:counter + m_send%task_int(counter)) = elem%sub_tree_nr
counter = counter + 1 + m_send%task_int(counter)
m_send%task_int(counter) = 1 !SIZE(elem%nr)
m_send%task_int(counter + 1:counter + m_send%task_int(counter)) = elem%nr
counter = counter + m_send%task_int(counter) + 1
m_send%task_int(counter) = message_end_flag !message end
END IF
!then float array with energy of exact potential
msg_size_real = 1 + 1 + 1
IF (tmc_params%print_forces) msg_size_real = msg_size_real + 1 + SIZE(elem%frc)
IF (tmc_params%print_dipole) msg_size_real = msg_size_real + 1 + SIZE(elem%dipole)
ALLOCATE (m_send%task_real(msg_size_real))
m_send%task_real(1) = 1
m_send%task_real(2) = elem%potential
counter = 3
IF (tmc_params%print_forces) THEN
m_send%task_real(counter) = SIZE(elem%frc)
m_send%task_real(counter + 1:counter + NINT(m_send%task_real(counter))) = elem%frc
counter = counter + NINT(m_send%task_real(counter)) + 1
END IF
IF (tmc_params%print_dipole) THEN
m_send%task_real(counter) = SIZE(elem%dipole)
m_send%task_real(counter + 1:counter + NINT(m_send%task_real(counter))) = elem%dipole
counter = counter + NINT(m_send%task_real(counter)) + 1
END IF
m_send%task_real(counter) = REAL(message_end_flag, KIND=dp) !message end
CPASSERT(SIZE(m_send%task_real) .EQ. msg_size_real)
CPASSERT(INT(m_send%task_real(msg_size_real)) .EQ. message_end_flag)
END SUBROUTINE create_energy_result_message
! **************************************************************************************************
!> \brief reading message for sending back the exact energy of new conf
!> \param elem tree element for storing new energy
!> \param m_send the message structure
!> \param tmc_params stuct with parameters (global settings)
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE read_energy_result_message(elem, m_send, tmc_params)
TYPE(tree_type), POINTER :: elem
TYPE(message_send), POINTER :: m_send
TYPE(tmc_param_type), POINTER :: tmc_params
INTEGER :: counter
CPASSERT(ASSOCIATED(elem))
CPASSERT(ASSOCIATED(m_send))
CPASSERT(m_send%info(3) .GT. 0)
CPASSERT(ASSOCIATED(tmc_params))
! read the integer values
! for checking the tree element mapping, check the tree numbers
IF (DEBUG .GT. 0) THEN
counter = 1
IF (elem%sub_tree_nr .NE. m_send%task_int(counter + 1) .OR. &
elem%nr .NE. m_send%task_int(counter + 3)) THEN
WRITE (*, *) "ERROR: read_energy_result: master got energy result of subtree elem ", &
m_send%task_int(counter + 1), m_send%task_int(counter + 3), &
" but expect result of subtree elem", elem%sub_tree_nr, elem%nr
CPABORT("read_energy_result: got energy result from unexpected tree element.")
END IF
ELSE
CPASSERT(m_send%info(2) .EQ. 0)
END IF
!then float array with energy of exact potential
elem%potential = m_send%task_real(2)
counter = 3
IF (tmc_params%print_forces) THEN
elem%frc(:) = m_send%task_real((counter + 1):(counter + NINT(m_send%task_real(counter))))
counter = counter + 1 + NINT(m_send%task_real(counter))
END IF
IF (tmc_params%print_dipole) THEN
elem%dipole(:) = m_send%task_real((counter + 1):(counter + NINT(m_send%task_real(counter))))
counter = counter + 1 + NINT(m_send%task_real(counter))
END IF
CPASSERT(counter .EQ. m_send%info(3))
CPASSERT(INT(m_send%task_real(m_send%info(3))) .EQ. message_end_flag)
END SUBROUTINE read_energy_result_message
! **************************************************************************************************
!> \brief create message for sending back the approximate energy of new conf
!> \param elem tree element with calculated approx energy
!> \param m_send the message structure
!> \param tmc_params stuct with parameters (global settings)
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE create_approx_energy_result_message(elem, m_send, &
tmc_params)
TYPE(tree_type), POINTER :: elem
TYPE(message_send), POINTER :: m_send
TYPE(tmc_param_type), POINTER :: tmc_params
INTEGER :: counter, msg_size_real
CPASSERT(ASSOCIATED(m_send))
CPASSERT(.NOT. ALLOCATED(m_send%task_int))
CPASSERT(.NOT. ALLOCATED(m_send%task_real))
CPASSERT(ASSOCIATED(elem))
CPASSERT(ASSOCIATED(tmc_params))
counter = 0
!then float array with energy of exact potential
msg_size_real = 1 + 1 + 1
IF (tmc_params%pressure .GE. 0.0_dp) msg_size_real = msg_size_real + 1 + SIZE(elem%box_scale(:))
ALLOCATE (m_send%task_real(msg_size_real))
m_send%task_real(1) = 1
m_send%task_real(2) = elem%e_pot_approx
counter = 3
! the box size for NpT
IF (tmc_params%pressure .GE. 0.0_dp) THEN
m_send%task_real(counter) = SIZE(elem%box_scale)
m_send%task_real(counter + 1:counter + INT(m_send%task_real(counter))) = elem%box_scale(:)
counter = counter + 1 + INT(m_send%task_real(counter))
END IF
m_send%task_real(counter) = REAL(message_end_flag, KIND=dp) !message end
CPASSERT(SIZE(m_send%task_real) .EQ. msg_size_real)
CPASSERT(INT(m_send%task_real(msg_size_real)) .EQ. message_end_flag)
END SUBROUTINE create_approx_energy_result_message
! **************************************************************************************************
!> \brief reading message for sending back the exact energy of new conf
!> \param elem tree element for storing new energy
!> \param m_send the message structure
!> \param tmc_params the param struct with necessary parameters
!> \author Mandes 12.2012
! **************************************************************************************************
SUBROUTINE read_approx_energy_result(elem, m_send, tmc_params)
TYPE(tree_type), POINTER :: elem