22 #include "../base/base_uses.f90"
27 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'swarm_message'
29 TYPE swarm_message_type
31 TYPE(message_entry_type),
POINTER :: root => null()
32 END TYPE swarm_message_type
34 INTEGER,
PARAMETER :: key_length = 20
36 TYPE message_entry_type
37 CHARACTER(LEN=key_length) :: key =
""
38 TYPE(message_entry_type),
POINTER :: next => null()
39 CHARACTER(LEN=default_string_length),
POINTER :: value_str => null()
40 INTEGER(KIND=int_4),
POINTER :: value_i4 => null()
41 INTEGER(KIND=int_8),
POINTER :: value_i8 => null()
42 REAL(KIND=
real_4),
POINTER :: value_r4 => null()
43 REAL(KIND=
real_8),
POINTER :: value_r8 => null()
44 INTEGER(KIND=int_4),
DIMENSION(:),
POINTER :: value_1d_i4 => null()
45 INTEGER(KIND=int_8),
DIMENSION(:),
POINTER :: value_1d_i8 => null()
46 REAL(KIND=
real_4),
DIMENSION(:),
POINTER :: value_1d_r4 => null()
47 REAL(KIND=
real_8),
DIMENSION(:),
POINTER :: value_1d_r8 => null()
48 END TYPE message_entry_type
54 INTERFACE swarm_message_add
55 MODULE PROCEDURE swarm_message_add_str
56 MODULE PROCEDURE swarm_message_add_i4, swarm_message_add_i8
57 MODULE PROCEDURE swarm_message_add_r4, swarm_message_add_r8
58 MODULE PROCEDURE swarm_message_add_1d_i4, swarm_message_add_1d_i8
59 MODULE PROCEDURE swarm_message_add_1d_r4, swarm_message_add_1d_r8
60 END INTERFACE swarm_message_add
66 INTERFACE swarm_message_get
67 MODULE PROCEDURE swarm_message_get_str
68 MODULE PROCEDURE swarm_message_get_i4, swarm_message_get_i8
69 MODULE PROCEDURE swarm_message_get_r4, swarm_message_get_r8
70 MODULE PROCEDURE swarm_message_get_1d_i4, swarm_message_get_1d_i8
71 MODULE PROCEDURE swarm_message_get_1d_r4, swarm_message_get_1d_r8
72 END INTERFACE swarm_message_get
74 PUBLIC :: swarm_message_type, swarm_message_add, swarm_message_get
88 FUNCTION swarm_message_length(msg)
RESULT(l)
89 TYPE(swarm_message_type),
INTENT(IN) :: msg
92 TYPE(message_entry_type),
POINTER :: curr_entry
95 curr_entry => msg%root
96 DO WHILE (
ASSOCIATED(curr_entry))
98 curr_entry => curr_entry%next
100 END FUNCTION swarm_message_length
110 TYPE(swarm_message_type),
INTENT(IN) :: msg
111 CHARACTER(LEN=*),
INTENT(IN) :: key
114 TYPE(message_entry_type),
POINTER :: curr_entry
117 curr_entry => msg%root
118 DO WHILE (
ASSOCIATED(curr_entry))
119 IF (trim(curr_entry%key) == trim(key))
THEN
123 curr_entry => curr_entry%next
133 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
135 TYPE(message_entry_type),
POINTER :: entry, old_entry
138 DO WHILE (
ASSOCIATED(entry))
139 IF (
ASSOCIATED(entry%value_str))
DEALLOCATE (entry%value_str)
140 IF (
ASSOCIATED(entry%value_i4))
DEALLOCATE (entry%value_i4)
141 IF (
ASSOCIATED(entry%value_i8))
DEALLOCATE (entry%value_i8)
142 IF (
ASSOCIATED(entry%value_r4))
DEALLOCATE (entry%value_r4)
143 IF (
ASSOCIATED(entry%value_r8))
DEALLOCATE (entry%value_r8)
144 IF (
ASSOCIATED(entry%value_1d_i4))
DEALLOCATE (entry%value_1d_i4)
145 IF (
ASSOCIATED(entry%value_1d_i8))
DEALLOCATE (entry%value_1d_i8)
146 IF (
ASSOCIATED(entry%value_1d_r4))
DEALLOCATE (entry%value_1d_r4)
147 IF (
ASSOCIATED(entry%value_1d_r8))
DEALLOCATE (entry%value_1d_r8)
150 DEALLOCATE (old_entry)
155 cpassert(swarm_message_length(msg) == 0)
166 TYPE(swarm_message_type),
INTENT(IN) :: msg1, msg2
169 res = swarm_message_equal_oneway(msg1, msg2) .AND. &
170 swarm_message_equal_oneway(msg2, msg1)
183 TYPE(swarm_message_type),
INTENT(IN) :: msg
184 CLASS(mp_comm_type),
INTENT(IN) :: group
185 INTEGER,
INTENT(IN) :: dest, tag
187 TYPE(message_entry_type),
POINTER :: curr_entry
189 CALL group%send(swarm_message_length(msg), dest, tag)
190 curr_entry => msg%root
191 DO WHILE (
ASSOCIATED(curr_entry))
192 CALL swarm_message_entry_mpi_send(curr_entry, group, dest, tag)
193 curr_entry => curr_entry%next
206 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
207 CLASS(mp_comm_type),
INTENT(IN) :: group
208 INTEGER,
INTENT(INOUT) :: src, tag
211 TYPE(message_entry_type),
POINTER :: new_entry
213 IF (
ASSOCIATED(msg%root)) cpabort(
"message not empty")
214 CALL group%recv(length, src, tag)
217 CALL swarm_message_entry_mpi_recv(new_entry, group, src, tag)
218 new_entry%next => msg%root
219 msg%root => new_entry
232 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
233 INTEGER,
INTENT(IN) :: src
234 CLASS(mp_comm_type),
INTENT(IN) :: group
237 TYPE(message_entry_type),
POINTER :: curr_entry
239 associate(mepos => group%mepos)
241 IF (mepos /= src .AND.
ASSOCIATED(msg%root)) cpabort(
"message not empty")
242 length = swarm_message_length(msg)
243 CALL group%bcast(length, src)
245 IF (mepos == src) curr_entry => msg%root
248 IF (mepos /= src)
ALLOCATE (curr_entry)
250 CALL swarm_message_entry_mpi_bcast(curr_entry, src, group, mepos)
252 IF (mepos == src)
THEN
253 curr_entry => curr_entry%next
255 curr_entry%next => msg%root
256 msg%root => curr_entry
270 TYPE(swarm_message_type),
INTENT(IN) :: msg
271 INTEGER,
INTENT(IN) :: unit
274 TYPE(message_entry_type),
POINTER :: curr_entry
276 IF (unit <= 0)
RETURN
278 CALL timeset(
"swarm_message_file_write", handle)
279 WRITE (unit,
"(A)")
"BEGIN SWARM_MESSAGE"
280 WRITE (unit,
"(A,I10)")
"msg_length: ", swarm_message_length(msg)
282 curr_entry => msg%root
283 DO WHILE (
ASSOCIATED(curr_entry))
284 CALL swarm_message_entry_file_write(curr_entry, unit)
285 curr_entry => curr_entry%next
288 WRITE (unit,
"(A)")
"END SWARM_MESSAGE"
290 CALL timestop(handle)
301 TYPE(swarm_message_type),
INTENT(OUT) :: msg
302 TYPE(cp_parser_type),
INTENT(INOUT) :: parser
303 LOGICAL,
INTENT(INOUT) :: at_end
307 CALL timeset(
"swarm_message_file_read", handle)
308 CALL swarm_message_file_read_low(msg, parser, at_end)
309 CALL timestop(handle)
319 SUBROUTINE swarm_message_file_read_low(msg, parser, at_end)
320 TYPE(swarm_message_type),
INTENT(OUT) :: msg
321 TYPE(cp_parser_type),
INTENT(INOUT) :: parser
322 LOGICAL,
INTENT(INOUT) :: at_end
324 CHARACTER(LEN=20) :: label
326 TYPE(message_entry_type),
POINTER :: new_entry
328 CALL parser_get_next_line(parser, 1, at_end)
329 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
331 cpassert(trim(parser%input_line(1:20)) ==
"BEGIN SWARM_MESSAGE")
333 CALL parser_get_next_line(parser, 1, at_end)
334 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
336 READ (parser%input_line(1:40), *) label, length
337 cpassert(trim(label) ==
"msg_length:")
341 CALL swarm_message_entry_file_read(new_entry, parser, at_end)
342 new_entry%next => msg%root
343 msg%root => new_entry
346 CALL parser_get_next_line(parser, 1, at_end)
347 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
349 cpassert(trim(parser%input_line(1:20)) ==
"END SWARM_MESSAGE")
351 END SUBROUTINE swarm_message_file_read_low
360 FUNCTION swarm_message_equal_oneway(msg1, msg2)
RESULT(res)
361 TYPE(swarm_message_type),
INTENT(IN) :: msg1, msg2
365 TYPE(message_entry_type),
POINTER :: entry1, entry2
371 DO WHILE (
ASSOCIATED(entry1))
376 DO WHILE (
ASSOCIATED(entry2))
377 IF (trim(entry2%key) == trim(entry1%key))
THEN
381 entry2 => entry2%next
383 IF (.NOT. found)
RETURN
386 IF (
ASSOCIATED(entry1%value_str))
THEN
387 IF (.NOT.
ASSOCIATED(entry2%value_str))
RETURN
388 IF (trim(entry1%value_str) /= trim(entry2%value_str))
RETURN
390 ELSE IF (
ASSOCIATED(entry1%value_i4))
THEN
391 IF (.NOT.
ASSOCIATED(entry2%value_i4))
RETURN
392 IF (entry1%value_i4 /= entry2%value_i4)
RETURN
394 ELSE IF (
ASSOCIATED(entry1%value_i8))
THEN
395 IF (.NOT.
ASSOCIATED(entry2%value_i8))
RETURN
396 IF (entry1%value_i8 /= entry2%value_i8)
RETURN
398 ELSE IF (
ASSOCIATED(entry1%value_r4))
THEN
399 IF (.NOT.
ASSOCIATED(entry2%value_r4))
RETURN
400 IF (abs(entry1%value_r4 - entry2%value_r4) > 1e-5)
RETURN
402 ELSE IF (
ASSOCIATED(entry1%value_r8))
THEN
403 IF (.NOT.
ASSOCIATED(entry2%value_r8))
RETURN
404 IF (abs(entry1%value_r8 - entry2%value_r8) > 1e-10)
RETURN
406 ELSE IF (
ASSOCIATED(entry1%value_1d_i4))
THEN
407 IF (.NOT.
ASSOCIATED(entry2%value_1d_i4))
RETURN
408 IF (any(entry1%value_1d_i4 /= entry2%value_1d_i4))
RETURN
410 ELSE IF (
ASSOCIATED(entry1%value_1d_i8))
THEN
411 IF (.NOT.
ASSOCIATED(entry2%value_1d_i8))
RETURN
412 IF (any(entry1%value_1d_i8 /= entry2%value_1d_i8))
RETURN
414 ELSE IF (
ASSOCIATED(entry1%value_1d_r4))
THEN
415 IF (.NOT.
ASSOCIATED(entry2%value_1d_r4))
RETURN
416 IF (any(abs(entry1%value_1d_r4 - entry2%value_1d_r4) > 1e-5))
RETURN
418 ELSE IF (
ASSOCIATED(entry1%value_1d_r8))
THEN
419 IF (.NOT.
ASSOCIATED(entry2%value_1d_r8))
RETURN
420 IF (any(abs(entry1%value_1d_r8 - entry2%value_1d_r8) > 1e-10))
RETURN
422 cpabort(
"no value ASSOCIATED")
425 entry1 => entry1%next
430 END FUNCTION swarm_message_equal_oneway
440 SUBROUTINE swarm_message_entry_mpi_send(ENTRY, group, dest, tag)
441 TYPE(message_entry_type),
INTENT(IN) :: entry
442 CLASS(mp_comm_type),
INTENT(IN) :: group
443 INTEGER,
INTENT(IN) :: dest, tag
445 INTEGER,
DIMENSION(default_string_length) :: value_str_arr
446 INTEGER,
DIMENSION(key_length) :: key_arr
448 key_arr = str2iarr(entry%key)
449 CALL group%send(key_arr, dest, tag)
451 IF (
ASSOCIATED(entry%value_i4))
THEN
452 CALL group%send(1, dest, tag)
453 CALL group%send(entry%value_i4, dest, tag)
455 ELSE IF (
ASSOCIATED(entry%value_i8))
THEN
456 CALL group%send(2, dest, tag)
457 CALL group%send(entry%value_i8, dest, tag)
459 ELSE IF (
ASSOCIATED(entry%value_r4))
THEN
460 CALL group%send(3, dest, tag)
461 CALL group%send(entry%value_r4, dest, tag)
463 ELSE IF (
ASSOCIATED(entry%value_r8))
THEN
464 CALL group%send(4, dest, tag)
465 CALL group%send(entry%value_r8, dest, tag)
467 ELSE IF (
ASSOCIATED(entry%value_1d_i4))
THEN
468 CALL group%send(5, dest, tag)
469 CALL group%send(
SIZE(entry%value_1d_i4), dest, tag)
470 CALL group%send(entry%value_1d_i4, dest, tag)
472 ELSE IF (
ASSOCIATED(entry%value_1d_i8))
THEN
473 CALL group%send(6, dest, tag)
474 CALL group%send(
SIZE(entry%value_1d_i8), dest, tag)
475 CALL group%send(entry%value_1d_i8, dest, tag)
477 ELSE IF (
ASSOCIATED(entry%value_1d_r4))
THEN
478 CALL group%send(7, dest, tag)
479 CALL group%send(
SIZE(entry%value_1d_r4), dest, tag)
480 CALL group%send(entry%value_1d_r4, dest, tag)
482 ELSE IF (
ASSOCIATED(entry%value_1d_r8))
THEN
483 CALL group%send(8, dest, tag)
484 CALL group%send(
SIZE(entry%value_1d_r8), dest, tag)
485 CALL group%send(entry%value_1d_r8, dest, tag)
487 ELSE IF (
ASSOCIATED(entry%value_str))
THEN
488 CALL group%send(9, dest, tag)
489 value_str_arr = str2iarr(entry%value_str)
490 CALL group%send(value_str_arr, dest, tag)
492 cpabort(
"no value ASSOCIATED")
494 END SUBROUTINE swarm_message_entry_mpi_send
504 SUBROUTINE swarm_message_entry_mpi_recv(ENTRY, group, src, tag)
505 TYPE(message_entry_type),
INTENT(INOUT) :: entry
506 CLASS(mp_comm_type),
INTENT(IN) :: group
507 INTEGER,
INTENT(INOUT) :: src, tag
509 INTEGER :: datatype, s
510 INTEGER,
DIMENSION(default_string_length) :: value_str_arr
511 INTEGER,
DIMENSION(key_length) :: key_arr
513 CALL group%recv(key_arr, src, tag)
514 entry%key = iarr2str(key_arr)
516 CALL group%recv(datatype, src, tag)
518 SELECT CASE (datatype)
520 ALLOCATE (entry%value_i4)
521 CALL group%recv(entry%value_i4, src, tag)
523 ALLOCATE (entry%value_i8)
524 CALL group%recv(entry%value_i8, src, tag)
526 ALLOCATE (entry%value_r4)
527 CALL group%recv(entry%value_r4, src, tag)
529 ALLOCATE (entry%value_r8)
530 CALL group%recv(entry%value_r8, src, tag)
532 CALL group%recv(s, src, tag)
533 ALLOCATE (entry%value_1d_i4(s))
534 CALL group%recv(entry%value_1d_i4, src, tag)
536 CALL group%recv(s, src, tag)
537 ALLOCATE (entry%value_1d_i8(s))
538 CALL group%recv(entry%value_1d_i8, src, tag)
540 CALL group%recv(s, src, tag)
541 ALLOCATE (entry%value_1d_r4(s))
542 CALL group%recv(entry%value_1d_r4, src, tag)
544 CALL group%recv(s, src, tag)
545 ALLOCATE (entry%value_1d_r8(s))
546 CALL group%recv(entry%value_1d_r8, src, tag)
548 ALLOCATE (entry%value_str)
549 CALL group%recv(value_str_arr, src, tag)
550 entry%value_str = iarr2str(value_str_arr)
552 cpabort(
"unknown datatype")
554 END SUBROUTINE swarm_message_entry_mpi_recv
564 SUBROUTINE swarm_message_entry_mpi_bcast(ENTRY, src, group, mepos)
565 TYPE(message_entry_type),
INTENT(INOUT) :: entry
566 INTEGER,
INTENT(IN) :: src, mepos
567 CLASS(mp_comm_type),
INTENT(IN) :: group
569 INTEGER :: datasize, datatype
570 INTEGER,
DIMENSION(default_string_length) :: value_str_arr
571 INTEGER,
DIMENSION(key_length) :: key_arr
573 IF (src == mepos) key_arr = str2iarr(entry%key)
574 CALL group%bcast(key_arr, src)
575 IF (src /= mepos) entry%key = iarr2str(key_arr)
577 IF (src == mepos)
THEN
579 IF (
ASSOCIATED(entry%value_i4))
THEN
581 ELSE IF (
ASSOCIATED(entry%value_i8))
THEN
583 ELSE IF (
ASSOCIATED(entry%value_r4))
THEN
585 ELSE IF (
ASSOCIATED(entry%value_r8))
THEN
587 ELSE IF (
ASSOCIATED(entry%value_1d_i4))
THEN
589 datasize =
SIZE(entry%value_1d_i4)
590 ELSE IF (
ASSOCIATED(entry%value_1d_i8))
THEN
592 datasize =
SIZE(entry%value_1d_i8)
593 ELSE IF (
ASSOCIATED(entry%value_1d_r4))
THEN
595 datasize =
SIZE(entry%value_1d_r4)
596 ELSE IF (
ASSOCIATED(entry%value_1d_r8))
THEN
598 datasize =
SIZE(entry%value_1d_r8)
599 ELSE IF (
ASSOCIATED(entry%value_str))
THEN
602 cpabort(
"no value ASSOCIATED")
605 CALL group%bcast(datatype, src)
606 CALL group%bcast(datasize, src)
608 SELECT CASE (datatype)
610 IF (src /= mepos)
ALLOCATE (entry%value_i4)
611 CALL group%bcast(entry%value_i4, src)
613 IF (src /= mepos)
ALLOCATE (entry%value_i8)
614 CALL group%bcast(entry%value_i8, src)
616 IF (src /= mepos)
ALLOCATE (entry%value_r4)
617 CALL group%bcast(entry%value_r4, src)
619 IF (src /= mepos)
ALLOCATE (entry%value_r8)
620 CALL group%bcast(entry%value_r8, src)
622 IF (src /= mepos)
ALLOCATE (entry%value_1d_i4(datasize))
623 CALL group%bcast(entry%value_1d_i4, src)
625 IF (src /= mepos)
ALLOCATE (entry%value_1d_i8(datasize))
626 CALL group%bcast(entry%value_1d_i8, src)
628 IF (src /= mepos)
ALLOCATE (entry%value_1d_r4(datasize))
629 CALL group%bcast(entry%value_1d_r4, src)
631 IF (src /= mepos)
ALLOCATE (entry%value_1d_r8(datasize))
632 CALL group%bcast(entry%value_1d_r8, src)
634 IF (src == mepos) value_str_arr = str2iarr(entry%value_str)
635 CALL group%bcast(value_str_arr, src)
636 IF (src /= mepos)
THEN
637 ALLOCATE (entry%value_str)
638 entry%value_str = iarr2str(value_str_arr)
641 cpabort(
"unknown datatype")
644 END SUBROUTINE swarm_message_entry_mpi_bcast
652 SUBROUTINE swarm_message_entry_file_write(ENTRY, unit)
653 TYPE(message_entry_type),
INTENT(IN) :: entry
654 INTEGER,
INTENT(IN) :: unit
658 WRITE (unit,
"(A,A)")
"key: ", entry%key
659 IF (
ASSOCIATED(entry%value_i4))
THEN
660 WRITE (unit,
"(A)")
"datatype: i4"
661 WRITE (unit,
"(A,I10)")
"value: ", entry%value_i4
663 ELSE IF (
ASSOCIATED(entry%value_i8))
THEN
664 WRITE (unit,
"(A)")
"datatype: i8"
665 WRITE (unit,
"(A,I20)")
"value: ", entry%value_i8
667 ELSE IF (
ASSOCIATED(entry%value_r4))
THEN
668 WRITE (unit,
"(A)")
"datatype: r4"
669 WRITE (unit,
"(A,E30.20)")
"value: ", entry%value_r4
671 ELSE IF (
ASSOCIATED(entry%value_r8))
THEN
672 WRITE (unit,
"(A)")
"datatype: r8"
673 WRITE (unit,
"(A,E30.20)")
"value: ", entry%value_r8
675 ELSE IF (
ASSOCIATED(entry%value_str))
THEN
676 WRITE (unit,
"(A)")
"datatype: str"
677 WRITE (unit,
"(A,A)")
"value: ", entry%value_str
679 ELSE IF (
ASSOCIATED(entry%value_1d_i4))
THEN
680 WRITE (unit,
"(A)")
"datatype: 1d_i4"
681 WRITE (unit,
"(A,I10)")
"size: ",
SIZE(entry%value_1d_i4)
682 DO i = 1,
SIZE(entry%value_1d_i4)
683 WRITE (unit, *) entry%value_1d_i4(i)
686 ELSE IF (
ASSOCIATED(entry%value_1d_i8))
THEN
687 WRITE (unit,
"(A)")
"datatype: 1d_i8"
688 WRITE (unit,
"(A,I20)")
"size: ",
SIZE(entry%value_1d_i8)
689 DO i = 1,
SIZE(entry%value_1d_i8)
690 WRITE (unit, *) entry%value_1d_i8(i)
693 ELSE IF (
ASSOCIATED(entry%value_1d_r4))
THEN
694 WRITE (unit,
"(A)")
"datatype: 1d_r4"
695 WRITE (unit,
"(A,I8)")
"size: ",
SIZE(entry%value_1d_r4)
696 DO i = 1,
SIZE(entry%value_1d_r4)
697 WRITE (unit,
"(1X,E30.20)") entry%value_1d_r4(i)
700 ELSE IF (
ASSOCIATED(entry%value_1d_r8))
THEN
701 WRITE (unit,
"(A)")
"datatype: 1d_r8"
702 WRITE (unit,
"(A,I8)")
"size: ",
SIZE(entry%value_1d_r8)
703 DO i = 1,
SIZE(entry%value_1d_r8)
704 WRITE (unit,
"(1X,E30.20)") entry%value_1d_r8(i)
708 cpabort(
"no value ASSOCIATED")
710 END SUBROUTINE swarm_message_entry_file_write
719 SUBROUTINE swarm_message_entry_file_read(ENTRY, parser, at_end)
720 TYPE(message_entry_type),
INTENT(INOUT) :: entry
721 TYPE(cp_parser_type),
INTENT(INOUT) :: parser
722 LOGICAL,
INTENT(INOUT) :: at_end
724 CHARACTER(LEN=15) :: datatype, label
725 INTEGER :: arr_size, i
728 CALL parser_get_next_line(parser, 1, at_end)
729 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
731 READ (parser%input_line(1:key_length + 10), *) label, entry%key
732 cpassert(trim(label) ==
"key:")
734 CALL parser_get_next_line(parser, 1, at_end)
735 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
737 READ (parser%input_line(1:30), *) label, datatype
738 cpassert(trim(label) ==
"datatype:")
740 CALL parser_get_next_line(parser, 1, at_end)
741 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
745 SELECT CASE (trim(datatype))
747 ALLOCATE (entry%value_i4)
748 READ (parser%input_line(1:40), *) label, entry%value_i4
750 ALLOCATE (entry%value_i8)
751 READ (parser%input_line(1:40), *) label, entry%value_i8
753 ALLOCATE (entry%value_r4)
754 READ (parser%input_line(1:40), *) label, entry%value_r4
756 ALLOCATE (entry%value_r8)
757 READ (parser%input_line(1:40), *) label, entry%value_r8
759 ALLOCATE (entry%value_str)
760 READ (parser%input_line(1:40), *) label, entry%value_str
766 cpassert(trim(label) ==
"value:")
771 READ (parser%input_line(1:30), *) label, arr_size
772 cpassert(trim(label) ==
"size:")
774 SELECT CASE (trim(datatype))
776 ALLOCATE (entry%value_1d_i4(arr_size))
778 ALLOCATE (entry%value_1d_i8(arr_size))
780 ALLOCATE (entry%value_1d_r4(arr_size))
782 ALLOCATE (entry%value_1d_r8(arr_size))
784 cpabort(
"unknown datatype")
788 CALL parser_get_next_line(parser, 1, at_end)
789 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
793 SELECT CASE (trim(datatype))
795 READ (parser%input_line(1:31), *) entry%value_1d_i4(i)
797 READ (parser%input_line(1:31), *) entry%value_1d_i8(i)
799 READ (parser%input_line(1:31), *) entry%value_1d_r4(i)
801 READ (parser%input_line(1:31), *) entry%value_1d_r8(i)
803 cpabort(
"swarm_message_entry_file_read: unknown datatype")
807 END SUBROUTINE swarm_message_entry_file_read
815 PURE FUNCTION str2iarr(str)
RESULT(arr)
816 CHARACTER(LEN=*),
INTENT(IN) :: str
817 INTEGER,
DIMENSION(LEN(str)) :: arr
822 arr(i) = ichar(str(i:i))
824 END FUNCTION str2iarr
832 PURE FUNCTION iarr2str(arr)
RESULT(str)
833 INTEGER,
DIMENSION(:),
INTENT(IN) :: arr
834 CHARACTER(LEN=SIZE(arr)) :: str
839 str(i:i) = char(arr(i))
841 END FUNCTION iarr2str
852 SUBROUTINE swarm_message_add_str (msg, key, value)
853 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
854 CHARACTER(LEN=*),
INTENT(IN) :: key
855 CHARACTER(LEN=*),
INTENT(IN) :: value
857 TYPE(message_entry_type),
POINTER :: new_entry
860 cpabort(
"swarm_message_add_str: key already exists: "//trim(key))
865 ALLOCATE (new_entry%value_str)
867 new_entry%value_str =
value
871 IF (.NOT.
ASSOCIATED(msg%root))
THEN
872 msg%root => new_entry
874 new_entry%next => msg%root
875 msg%root => new_entry
878 END SUBROUTINE swarm_message_add_str
887 SUBROUTINE swarm_message_get_str (msg, key, value)
888 TYPE(swarm_message_type),
INTENT(IN) :: msg
889 CHARACTER(LEN=*),
INTENT(IN) :: key
891 CHARACTER(LEN=default_string_length) :: value
893 TYPE(message_entry_type),
POINTER :: curr_entry
897 curr_entry => msg%root
898 DO WHILE (
ASSOCIATED(curr_entry))
899 IF (trim(curr_entry%key) == trim(key))
THEN
900 IF (.NOT.
ASSOCIATED(curr_entry%value_str)) &
901 cpabort(
"swarm_message_get_str: value not associated key: "//trim(key))
902 value = curr_entry%value_str
906 curr_entry => curr_entry%next
908 cpabort(
"swarm_message_get: key not found: "//trim(key))
909 END SUBROUTINE swarm_message_get_str
919 SUBROUTINE swarm_message_add_i4 (msg, key, value)
920 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
921 CHARACTER(LEN=*),
INTENT(IN) :: key
922 INTEGER(KIND=int_4),
INTENT(IN) :: value
924 TYPE(message_entry_type),
POINTER :: new_entry
927 cpabort(
"swarm_message_add_i4: key already exists: "//trim(key))
932 ALLOCATE (new_entry%value_i4)
934 new_entry%value_i4 =
value
938 IF (.NOT.
ASSOCIATED(msg%root))
THEN
939 msg%root => new_entry
941 new_entry%next => msg%root
942 msg%root => new_entry
945 END SUBROUTINE swarm_message_add_i4
954 SUBROUTINE swarm_message_get_i4 (msg, key, value)
955 TYPE(swarm_message_type),
INTENT(IN) :: msg
956 CHARACTER(LEN=*),
INTENT(IN) :: key
958 INTEGER(KIND=int_4),
INTENT(OUT) :: value
960 TYPE(message_entry_type),
POINTER :: curr_entry
964 curr_entry => msg%root
965 DO WHILE (
ASSOCIATED(curr_entry))
966 IF (trim(curr_entry%key) == trim(key))
THEN
967 IF (.NOT.
ASSOCIATED(curr_entry%value_i4)) &
968 cpabort(
"swarm_message_get_i4: value not associated key: "//trim(key))
969 value = curr_entry%value_i4
973 curr_entry => curr_entry%next
975 cpabort(
"swarm_message_get: key not found: "//trim(key))
976 END SUBROUTINE swarm_message_get_i4
986 SUBROUTINE swarm_message_add_i8 (msg, key, value)
987 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
988 CHARACTER(LEN=*),
INTENT(IN) :: key
989 INTEGER(KIND=int_8),
INTENT(IN) :: value
991 TYPE(message_entry_type),
POINTER :: new_entry
994 cpabort(
"swarm_message_add_i8: key already exists: "//trim(key))
999 ALLOCATE (new_entry%value_i8)
1001 new_entry%value_i8 =
value
1005 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1006 msg%root => new_entry
1008 new_entry%next => msg%root
1009 msg%root => new_entry
1012 END SUBROUTINE swarm_message_add_i8
1021 SUBROUTINE swarm_message_get_i8 (msg, key, value)
1022 TYPE(swarm_message_type),
INTENT(IN) :: msg
1023 CHARACTER(LEN=*),
INTENT(IN) :: key
1025 INTEGER(KIND=int_8),
INTENT(OUT) :: value
1027 TYPE(message_entry_type),
POINTER :: curr_entry
1031 curr_entry => msg%root
1032 DO WHILE (
ASSOCIATED(curr_entry))
1033 IF (trim(curr_entry%key) == trim(key))
THEN
1034 IF (.NOT.
ASSOCIATED(curr_entry%value_i8)) &
1035 cpabort(
"swarm_message_get_i8: value not associated key: "//trim(key))
1036 value = curr_entry%value_i8
1040 curr_entry => curr_entry%next
1042 cpabort(
"swarm_message_get: key not found: "//trim(key))
1043 END SUBROUTINE swarm_message_get_i8
1053 SUBROUTINE swarm_message_add_r4 (msg, key, value)
1054 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
1055 CHARACTER(LEN=*),
INTENT(IN) :: key
1056 REAL(kind=real_4),
INTENT(IN) ::
value
1058 TYPE(message_entry_type),
POINTER :: new_entry
1061 cpabort(
"swarm_message_add_r4: key already exists: "//trim(key))
1063 ALLOCATE (new_entry)
1066 ALLOCATE (new_entry%value_r4)
1068 new_entry%value_r4 =
value
1072 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1073 msg%root => new_entry
1075 new_entry%next => msg%root
1076 msg%root => new_entry
1079 END SUBROUTINE swarm_message_add_r4
1088 SUBROUTINE swarm_message_get_r4 (msg, key, value)
1089 TYPE(swarm_message_type),
INTENT(IN) :: msg
1090 CHARACTER(LEN=*),
INTENT(IN) :: key
1092 REAL(kind=real_4),
INTENT(OUT) ::
value
1094 TYPE(message_entry_type),
POINTER :: curr_entry
1098 curr_entry => msg%root
1099 DO WHILE (
ASSOCIATED(curr_entry))
1100 IF (trim(curr_entry%key) == trim(key))
THEN
1101 IF (.NOT.
ASSOCIATED(curr_entry%value_r4)) &
1102 cpabort(
"swarm_message_get_r4: value not associated key: "//trim(key))
1103 value = curr_entry%value_r4
1107 curr_entry => curr_entry%next
1109 cpabort(
"swarm_message_get: key not found: "//trim(key))
1110 END SUBROUTINE swarm_message_get_r4
1120 SUBROUTINE swarm_message_add_r8 (msg, key, value)
1121 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
1122 CHARACTER(LEN=*),
INTENT(IN) :: key
1123 REAL(kind=real_8),
INTENT(IN) ::
value
1125 TYPE(message_entry_type),
POINTER :: new_entry
1128 cpabort(
"swarm_message_add_r8: key already exists: "//trim(key))
1130 ALLOCATE (new_entry)
1133 ALLOCATE (new_entry%value_r8)
1135 new_entry%value_r8 =
value
1139 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1140 msg%root => new_entry
1142 new_entry%next => msg%root
1143 msg%root => new_entry
1146 END SUBROUTINE swarm_message_add_r8
1155 SUBROUTINE swarm_message_get_r8 (msg, key, value)
1156 TYPE(swarm_message_type),
INTENT(IN) :: msg
1157 CHARACTER(LEN=*),
INTENT(IN) :: key
1159 REAL(kind=real_8),
INTENT(OUT) ::
value
1161 TYPE(message_entry_type),
POINTER :: curr_entry
1165 curr_entry => msg%root
1166 DO WHILE (
ASSOCIATED(curr_entry))
1167 IF (trim(curr_entry%key) == trim(key))
THEN
1168 IF (.NOT.
ASSOCIATED(curr_entry%value_r8)) &
1169 cpabort(
"swarm_message_get_r8: value not associated key: "//trim(key))
1170 value = curr_entry%value_r8
1174 curr_entry => curr_entry%next
1176 cpabort(
"swarm_message_get: key not found: "//trim(key))
1177 END SUBROUTINE swarm_message_get_r8
1187 SUBROUTINE swarm_message_add_1d_i4 (msg, key, value)
1188 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
1189 CHARACTER(LEN=*),
INTENT(IN) :: key
1190 INTEGER(KIND=int_4),
DIMENSION(:),
INTENT(IN) :: value
1192 TYPE(message_entry_type),
POINTER :: new_entry
1195 cpabort(
"swarm_message_add_1d_i4: key already exists: "//trim(key))
1197 ALLOCATE (new_entry)
1200 ALLOCATE (new_entry%value_1d_i4 (
SIZE(
value)))
1202 new_entry%value_1d_i4 =
value
1206 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1207 msg%root => new_entry
1209 new_entry%next => msg%root
1210 msg%root => new_entry
1213 END SUBROUTINE swarm_message_add_1d_i4
1222 SUBROUTINE swarm_message_get_1d_i4 (msg, key, value)
1223 TYPE(swarm_message_type),
INTENT(IN) :: msg
1224 CHARACTER(LEN=*),
INTENT(IN) :: key
1226 INTEGER(KIND=int_4),
DIMENSION(:),
POINTER :: value
1228 TYPE(message_entry_type),
POINTER :: curr_entry
1231 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_i4: value already associated")
1233 curr_entry => msg%root
1234 DO WHILE (
ASSOCIATED(curr_entry))
1235 IF (trim(curr_entry%key) == trim(key))
THEN
1236 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_i4)) &
1237 cpabort(
"swarm_message_get_1d_i4: value not associated key: "//trim(key))
1238 ALLOCATE (value(
SIZE(curr_entry%value_1d_i4)))
1239 value = curr_entry%value_1d_i4
1243 curr_entry => curr_entry%next
1245 cpabort(
"swarm_message_get: key not found: "//trim(key))
1246 END SUBROUTINE swarm_message_get_1d_i4
1256 SUBROUTINE swarm_message_add_1d_i8 (msg, key, value)
1257 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
1258 CHARACTER(LEN=*),
INTENT(IN) :: key
1259 INTEGER(KIND=int_8),
DIMENSION(:),
INTENT(IN) :: value
1261 TYPE(message_entry_type),
POINTER :: new_entry
1264 cpabort(
"swarm_message_add_1d_i8: key already exists: "//trim(key))
1266 ALLOCATE (new_entry)
1269 ALLOCATE (new_entry%value_1d_i8 (
SIZE(
value)))
1271 new_entry%value_1d_i8 =
value
1275 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1276 msg%root => new_entry
1278 new_entry%next => msg%root
1279 msg%root => new_entry
1282 END SUBROUTINE swarm_message_add_1d_i8
1291 SUBROUTINE swarm_message_get_1d_i8 (msg, key, value)
1292 TYPE(swarm_message_type),
INTENT(IN) :: msg
1293 CHARACTER(LEN=*),
INTENT(IN) :: key
1295 INTEGER(KIND=int_8),
DIMENSION(:),
POINTER :: value
1297 TYPE(message_entry_type),
POINTER :: curr_entry
1300 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_i8: value already associated")
1302 curr_entry => msg%root
1303 DO WHILE (
ASSOCIATED(curr_entry))
1304 IF (trim(curr_entry%key) == trim(key))
THEN
1305 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_i8)) &
1306 cpabort(
"swarm_message_get_1d_i8: value not associated key: "//trim(key))
1307 ALLOCATE (value(
SIZE(curr_entry%value_1d_i8)))
1308 value = curr_entry%value_1d_i8
1312 curr_entry => curr_entry%next
1314 cpabort(
"swarm_message_get: key not found: "//trim(key))
1315 END SUBROUTINE swarm_message_get_1d_i8
1325 SUBROUTINE swarm_message_add_1d_r4 (msg, key, value)
1326 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
1327 CHARACTER(LEN=*),
INTENT(IN) :: key
1328 REAL(kind=real_4),
DIMENSION(:),
INTENT(IN) ::
value
1330 TYPE(message_entry_type),
POINTER :: new_entry
1333 cpabort(
"swarm_message_add_1d_r4: key already exists: "//trim(key))
1335 ALLOCATE (new_entry)
1338 ALLOCATE (new_entry%value_1d_r4 (
SIZE(
value)))
1340 new_entry%value_1d_r4 =
value
1344 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1345 msg%root => new_entry
1347 new_entry%next => msg%root
1348 msg%root => new_entry
1351 END SUBROUTINE swarm_message_add_1d_r4
1360 SUBROUTINE swarm_message_get_1d_r4 (msg, key, value)
1361 TYPE(swarm_message_type),
INTENT(IN) :: msg
1362 CHARACTER(LEN=*),
INTENT(IN) :: key
1364 REAL(kind=real_4),
DIMENSION(:),
POINTER ::
value
1366 TYPE(message_entry_type),
POINTER :: curr_entry
1369 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_r4: value already associated")
1371 curr_entry => msg%root
1372 DO WHILE (
ASSOCIATED(curr_entry))
1373 IF (trim(curr_entry%key) == trim(key))
THEN
1374 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_r4)) &
1375 cpabort(
"swarm_message_get_1d_r4: value not associated key: "//trim(key))
1376 ALLOCATE (value(
SIZE(curr_entry%value_1d_r4)))
1377 value = curr_entry%value_1d_r4
1381 curr_entry => curr_entry%next
1383 cpabort(
"swarm_message_get: key not found: "//trim(key))
1384 END SUBROUTINE swarm_message_get_1d_r4
1394 SUBROUTINE swarm_message_add_1d_r8 (msg, key, value)
1395 TYPE(swarm_message_type),
INTENT(INOUT) :: msg
1396 CHARACTER(LEN=*),
INTENT(IN) :: key
1397 REAL(kind=real_8),
DIMENSION(:),
INTENT(IN) ::
value
1399 TYPE(message_entry_type),
POINTER :: new_entry
1402 cpabort(
"swarm_message_add_1d_r8: key already exists: "//trim(key))
1404 ALLOCATE (new_entry)
1407 ALLOCATE (new_entry%value_1d_r8 (
SIZE(
value)))
1409 new_entry%value_1d_r8 =
value
1413 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1414 msg%root => new_entry
1416 new_entry%next => msg%root
1417 msg%root => new_entry
1420 END SUBROUTINE swarm_message_add_1d_r8
1429 SUBROUTINE swarm_message_get_1d_r8 (msg, key, value)
1430 TYPE(swarm_message_type),
INTENT(IN) :: msg
1431 CHARACTER(LEN=*),
INTENT(IN) :: key
1433 REAL(kind=real_8),
DIMENSION(:),
POINTER ::
value
1435 TYPE(message_entry_type),
POINTER :: curr_entry
1438 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_r8: value already associated")
1440 curr_entry => msg%root
1441 DO WHILE (
ASSOCIATED(curr_entry))
1442 IF (trim(curr_entry%key) == trim(key))
THEN
1443 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_r8)) &
1444 cpabort(
"swarm_message_get_1d_r8: value not associated key: "//trim(key))
1445 ALLOCATE (value(
SIZE(curr_entry%value_1d_r8)))
1446 value = curr_entry%value_1d_r8
1450 curr_entry => curr_entry%next
1452 cpabort(
"swarm_message_get: key not found: "//trim(key))
1453 END SUBROUTINE swarm_message_get_1d_r8
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_get_next_line(parser, nline, at_end)
Read the next input line and broadcast the input information. Skip (nline-1) lines and skip also all ...
Utility routines to read data from files. Kept as close as possible to the old parser because.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public default_string_length
integer, parameter, public real_4
integer, parameter, public real_8
integer, parameter, public int_4
Interface to the message passing library MPI.
Swarm-message, a convenient data-container for with build-in serialization.
subroutine, public swarm_message_mpi_send(msg, group, dest, tag)
Sends a swarm message via MPI.
subroutine, public swarm_message_mpi_bcast(msg, src, group)
Broadcasts a swarm message via MPI.
subroutine, public swarm_message_mpi_recv(msg, group, src, tag)
Receives a swarm message via MPI.
subroutine, public swarm_message_file_write(msg, unit)
Write a swarm-message to a given file / unit.
logical function, public swarm_message_equal(msg1, msg2)
Checks if two swarm-messages are equal.
logical function, public swarm_message_haskey(msg, key)
Checks if a swarm-message contains an entry with the given key.
subroutine, public swarm_message_free(msg)
Deallocates all entries contained in a swarm-message.
subroutine, public swarm_message_file_read(msg, parser, at_end)
Reads a swarm-message from a given file / unit.