23#include "../base/base_uses.f90"
28 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'swarm_message'
32 TYPE(message_entry_type),
POINTER :: root => null()
37 TYPE message_entry_type
38 CHARACTER(LEN=key_length) :: key =
""
39 TYPE(message_entry_type),
POINTER :: next => null()
40 CHARACTER(LEN=default_string_length),
POINTER :: value_str => null()
41 INTEGER(KIND=int_4),
POINTER :: value_i4 => null()
42 INTEGER(KIND=int_8),
POINTER :: value_i8 => null()
43 REAL(kind=
real_4),
POINTER :: value_r4 => null()
44 REAL(kind=
real_8),
POINTER :: value_r8 => null()
45 INTEGER(KIND=int_4),
DIMENSION(:),
POINTER :: value_1d_i4 => null()
46 INTEGER(KIND=int_8),
DIMENSION(:),
POINTER :: value_1d_i8 => null()
47 REAL(kind=
real_4),
DIMENSION(:),
POINTER :: value_1d_r4 => null()
48 REAL(kind=
real_8),
DIMENSION(:),
POINTER :: value_1d_r8 => null()
49 END TYPE message_entry_type
56 MODULE PROCEDURE swarm_message_add_str
57 MODULE PROCEDURE swarm_message_add_i4, swarm_message_add_i8
58 MODULE PROCEDURE swarm_message_add_r4, swarm_message_add_r8
59 MODULE PROCEDURE swarm_message_add_1d_i4, swarm_message_add_1d_i8
60 MODULE PROCEDURE swarm_message_add_1d_r4, swarm_message_add_1d_r8
68 MODULE PROCEDURE swarm_message_get_str
69 MODULE PROCEDURE swarm_message_get_i4, swarm_message_get_i8
70 MODULE PROCEDURE swarm_message_get_r4, swarm_message_get_r8
71 MODULE PROCEDURE swarm_message_get_1d_i4, swarm_message_get_1d_i8
72 MODULE PROCEDURE swarm_message_get_1d_r4, swarm_message_get_1d_r8
89 FUNCTION swarm_message_length(msg)
RESULT(l)
90 TYPE(swarm_message_type),
INTENT(IN) :: msg
93 TYPE(message_entry_type),
POINTER :: curr_entry
96 curr_entry => msg%root
97 DO WHILE (
ASSOCIATED(curr_entry))
99 curr_entry => curr_entry%next
101 END FUNCTION swarm_message_length
112 CHARACTER(LEN=*),
INTENT(IN) :: key
115 TYPE(message_entry_type),
POINTER :: curr_entry
118 curr_entry => msg%root
119 DO WHILE (
ASSOCIATED(curr_entry))
120 IF (trim(curr_entry%key) == trim(key))
THEN
124 curr_entry => curr_entry%next
136 TYPE(message_entry_type),
POINTER :: entry, old_entry
139 DO WHILE (
ASSOCIATED(entry))
140 IF (
ASSOCIATED(entry%value_str))
DEALLOCATE (entry%value_str)
141 IF (
ASSOCIATED(entry%value_i4))
DEALLOCATE (entry%value_i4)
142 IF (
ASSOCIATED(entry%value_i8))
DEALLOCATE (entry%value_i8)
143 IF (
ASSOCIATED(entry%value_r4))
DEALLOCATE (entry%value_r4)
144 IF (
ASSOCIATED(entry%value_r8))
DEALLOCATE (entry%value_r8)
145 IF (
ASSOCIATED(entry%value_1d_i4))
DEALLOCATE (entry%value_1d_i4)
146 IF (
ASSOCIATED(entry%value_1d_i8))
DEALLOCATE (entry%value_1d_i8)
147 IF (
ASSOCIATED(entry%value_1d_r4))
DEALLOCATE (entry%value_1d_r4)
148 IF (
ASSOCIATED(entry%value_1d_r8))
DEALLOCATE (entry%value_1d_r8)
151 DEALLOCATE (old_entry)
156 cpassert(swarm_message_length(msg) == 0)
170 res = swarm_message_equal_oneway(msg1, msg2) .AND. &
171 swarm_message_equal_oneway(msg2, msg1)
186 INTEGER,
INTENT(IN) :: dest, tag
188 TYPE(message_entry_type),
POINTER :: curr_entry
190 CALL group%send(swarm_message_length(msg), dest, tag)
191 curr_entry => msg%root
192 DO WHILE (
ASSOCIATED(curr_entry))
193 CALL swarm_message_entry_mpi_send(curr_entry, group, dest, tag)
194 curr_entry => curr_entry%next
209 INTEGER,
INTENT(INOUT) :: src, tag
212 TYPE(message_entry_type),
POINTER :: new_entry
214 IF (
ASSOCIATED(msg%root)) cpabort(
"message not empty")
215 CALL group%recv(length, src, tag)
218 CALL swarm_message_entry_mpi_recv(new_entry, group, src, tag)
219 new_entry%next => msg%root
220 msg%root => new_entry
234 INTEGER,
INTENT(IN) :: src
238 TYPE(message_entry_type),
POINTER :: curr_entry
240 associate(mepos => group%mepos)
242 IF (mepos /= src .AND.
ASSOCIATED(msg%root)) cpabort(
"message not empty")
243 length = swarm_message_length(msg)
244 CALL group%bcast(length, src)
246 IF (mepos == src) curr_entry => msg%root
249 IF (mepos /= src)
ALLOCATE (curr_entry)
251 CALL swarm_message_entry_mpi_bcast(curr_entry, src, group, mepos)
253 IF (mepos == src)
THEN
254 curr_entry => curr_entry%next
256 curr_entry%next => msg%root
257 msg%root => curr_entry
272 INTEGER,
INTENT(IN) :: unit
275 TYPE(message_entry_type),
POINTER :: curr_entry
277 IF (unit <= 0)
RETURN
279 CALL timeset(
"swarm_message_file_write", handle)
280 WRITE (unit,
"(A)")
"BEGIN SWARM_MESSAGE"
281 WRITE (unit,
"(A,I10)")
"msg_length: ", swarm_message_length(msg)
283 curr_entry => msg%root
284 DO WHILE (
ASSOCIATED(curr_entry))
285 CALL swarm_message_entry_file_write(curr_entry, unit)
286 curr_entry => curr_entry%next
289 WRITE (unit,
"(A)")
"END SWARM_MESSAGE"
291 CALL timestop(handle)
303 TYPE(cp_parser_type),
INTENT(INOUT) :: parser
304 LOGICAL,
INTENT(INOUT) :: at_end
308 CALL timeset(
"swarm_message_file_read", handle)
309 CALL swarm_message_file_read_low(msg, parser, at_end)
310 CALL timestop(handle)
320 SUBROUTINE swarm_message_file_read_low(msg, parser, at_end)
322 TYPE(cp_parser_type),
INTENT(INOUT) :: parser
323 LOGICAL,
INTENT(INOUT) :: at_end
325 CHARACTER(LEN=20) :: label
327 TYPE(message_entry_type),
POINTER :: new_entry
329 CALL parser_get_next_line(parser, 1, at_end)
330 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
332 cpassert(trim(parser%input_line(1:20)) ==
"BEGIN SWARM_MESSAGE")
334 CALL parser_get_next_line(parser, 1, at_end)
335 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
337 READ (parser%input_line(1:40), *) label, length
338 cpassert(trim(label) ==
"msg_length:")
342 CALL swarm_message_entry_file_read(new_entry, parser, at_end)
343 new_entry%next => msg%root
344 msg%root => new_entry
347 CALL parser_get_next_line(parser, 1, at_end)
348 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
350 cpassert(trim(parser%input_line(1:20)) ==
"END SWARM_MESSAGE")
352 END SUBROUTINE swarm_message_file_read_low
361 FUNCTION swarm_message_equal_oneway(msg1, msg2)
RESULT(res)
365 REAL(kind=dp),
PARAMETER :: eps_r4 = 1.0e-05_dp, &
369 TYPE(message_entry_type),
POINTER :: entry1, entry2
375 DO WHILE (
ASSOCIATED(entry1))
380 DO WHILE (
ASSOCIATED(entry2))
381 IF (trim(entry2%key) == trim(entry1%key))
THEN
385 entry2 => entry2%next
387 IF (.NOT. found)
RETURN
390 IF (
ASSOCIATED(entry1%value_str))
THEN
391 IF (.NOT.
ASSOCIATED(entry2%value_str))
RETURN
392 IF (trim(entry1%value_str) /= trim(entry2%value_str))
RETURN
394 ELSE IF (
ASSOCIATED(entry1%value_i4))
THEN
395 IF (.NOT.
ASSOCIATED(entry2%value_i4))
RETURN
396 IF (entry1%value_i4 /= entry2%value_i4)
RETURN
398 ELSE IF (
ASSOCIATED(entry1%value_i8))
THEN
399 IF (.NOT.
ASSOCIATED(entry2%value_i8))
RETURN
400 IF (entry1%value_i8 /= entry2%value_i8)
RETURN
402 ELSE IF (
ASSOCIATED(entry1%value_r4))
THEN
403 IF (.NOT.
ASSOCIATED(entry2%value_r4))
RETURN
404 IF (abs(entry1%value_r4 - entry2%value_r4) > eps_r4)
RETURN
406 ELSE IF (
ASSOCIATED(entry1%value_r8))
THEN
407 IF (.NOT.
ASSOCIATED(entry2%value_r8))
RETURN
408 IF (abs(entry1%value_r8 - entry2%value_r8) > eps_r8)
RETURN
410 ELSE IF (
ASSOCIATED(entry1%value_1d_i4))
THEN
411 IF (.NOT.
ASSOCIATED(entry2%value_1d_i4))
RETURN
412 IF (any(entry1%value_1d_i4 /= entry2%value_1d_i4))
RETURN
414 ELSE IF (
ASSOCIATED(entry1%value_1d_i8))
THEN
415 IF (.NOT.
ASSOCIATED(entry2%value_1d_i8))
RETURN
416 IF (any(entry1%value_1d_i8 /= entry2%value_1d_i8))
RETURN
418 ELSE IF (
ASSOCIATED(entry1%value_1d_r4))
THEN
419 IF (.NOT.
ASSOCIATED(entry2%value_1d_r4))
RETURN
420 IF (any(abs(entry1%value_1d_r4 - entry2%value_1d_r4) > eps_r4))
RETURN
422 ELSE IF (
ASSOCIATED(entry1%value_1d_r8))
THEN
423 IF (.NOT.
ASSOCIATED(entry2%value_1d_r8))
RETURN
424 IF (any(abs(entry1%value_1d_r8 - entry2%value_1d_r8) > eps_r8))
RETURN
426 cpabort(
"no value ASSOCIATED")
429 entry1 => entry1%next
434 END FUNCTION swarm_message_equal_oneway
444 SUBROUTINE swarm_message_entry_mpi_send(ENTRY, group, dest, tag)
445 TYPE(message_entry_type),
INTENT(IN) :: entry
446 CLASS(mp_comm_type),
INTENT(IN) :: group
447 INTEGER,
INTENT(IN) :: dest, tag
449 INTEGER,
DIMENSION(default_string_length) :: value_str_arr
450 INTEGER,
DIMENSION(key_length) :: key_arr
452 key_arr = str2iarr(entry%key)
453 CALL group%send(key_arr, dest, tag)
455 IF (
ASSOCIATED(entry%value_i4))
THEN
456 CALL group%send(1, dest, tag)
457 CALL group%send(entry%value_i4, dest, tag)
459 ELSE IF (
ASSOCIATED(entry%value_i8))
THEN
460 CALL group%send(2, dest, tag)
461 CALL group%send(entry%value_i8, dest, tag)
463 ELSE IF (
ASSOCIATED(entry%value_r4))
THEN
464 CALL group%send(3, dest, tag)
465 CALL group%send(entry%value_r4, dest, tag)
467 ELSE IF (
ASSOCIATED(entry%value_r8))
THEN
468 CALL group%send(4, dest, tag)
469 CALL group%send(entry%value_r8, dest, tag)
471 ELSE IF (
ASSOCIATED(entry%value_1d_i4))
THEN
472 CALL group%send(5, dest, tag)
473 CALL group%send(
SIZE(entry%value_1d_i4), dest, tag)
474 CALL group%send(entry%value_1d_i4, dest, tag)
476 ELSE IF (
ASSOCIATED(entry%value_1d_i8))
THEN
477 CALL group%send(6, dest, tag)
478 CALL group%send(
SIZE(entry%value_1d_i8), dest, tag)
479 CALL group%send(entry%value_1d_i8, dest, tag)
481 ELSE IF (
ASSOCIATED(entry%value_1d_r4))
THEN
482 CALL group%send(7, dest, tag)
483 CALL group%send(
SIZE(entry%value_1d_r4), dest, tag)
484 CALL group%send(entry%value_1d_r4, dest, tag)
486 ELSE IF (
ASSOCIATED(entry%value_1d_r8))
THEN
487 CALL group%send(8, dest, tag)
488 CALL group%send(
SIZE(entry%value_1d_r8), dest, tag)
489 CALL group%send(entry%value_1d_r8, dest, tag)
491 ELSE IF (
ASSOCIATED(entry%value_str))
THEN
492 CALL group%send(9, dest, tag)
493 value_str_arr = str2iarr(entry%value_str)
494 CALL group%send(value_str_arr, dest, tag)
496 cpabort(
"no value ASSOCIATED")
498 END SUBROUTINE swarm_message_entry_mpi_send
508 SUBROUTINE swarm_message_entry_mpi_recv(ENTRY, group, src, tag)
509 TYPE(message_entry_type),
INTENT(INOUT) :: entry
510 CLASS(mp_comm_type),
INTENT(IN) :: group
511 INTEGER,
INTENT(INOUT) :: src, tag
513 INTEGER :: datatype, s
514 INTEGER,
DIMENSION(default_string_length) :: value_str_arr
515 INTEGER,
DIMENSION(key_length) :: key_arr
517 CALL group%recv(key_arr, src, tag)
518 entry%key = iarr2str(key_arr)
520 CALL group%recv(datatype, src, tag)
522 SELECT CASE (datatype)
524 ALLOCATE (entry%value_i4)
525 CALL group%recv(entry%value_i4, src, tag)
527 ALLOCATE (entry%value_i8)
528 CALL group%recv(entry%value_i8, src, tag)
530 ALLOCATE (entry%value_r4)
531 CALL group%recv(entry%value_r4, src, tag)
533 ALLOCATE (entry%value_r8)
534 CALL group%recv(entry%value_r8, src, tag)
536 CALL group%recv(s, src, tag)
537 ALLOCATE (entry%value_1d_i4(s))
538 CALL group%recv(entry%value_1d_i4, src, tag)
540 CALL group%recv(s, src, tag)
541 ALLOCATE (entry%value_1d_i8(s))
542 CALL group%recv(entry%value_1d_i8, src, tag)
544 CALL group%recv(s, src, tag)
545 ALLOCATE (entry%value_1d_r4(s))
546 CALL group%recv(entry%value_1d_r4, src, tag)
548 CALL group%recv(s, src, tag)
549 ALLOCATE (entry%value_1d_r8(s))
550 CALL group%recv(entry%value_1d_r8, src, tag)
552 ALLOCATE (entry%value_str)
553 CALL group%recv(value_str_arr, src, tag)
554 entry%value_str = iarr2str(value_str_arr)
556 cpabort(
"unknown datatype")
558 END SUBROUTINE swarm_message_entry_mpi_recv
568 SUBROUTINE swarm_message_entry_mpi_bcast(ENTRY, src, group, mepos)
569 TYPE(message_entry_type),
INTENT(INOUT) :: entry
570 INTEGER,
INTENT(IN) :: src, mepos
571 CLASS(mp_comm_type),
INTENT(IN) :: group
573 INTEGER :: datasize, datatype
574 INTEGER,
DIMENSION(default_string_length) :: value_str_arr
575 INTEGER,
DIMENSION(key_length) :: key_arr
577 IF (src == mepos) key_arr = str2iarr(entry%key)
578 CALL group%bcast(key_arr, src)
579 IF (src /= mepos) entry%key = iarr2str(key_arr)
581 IF (src == mepos)
THEN
583 IF (
ASSOCIATED(entry%value_i4))
THEN
585 ELSE IF (
ASSOCIATED(entry%value_i8))
THEN
587 ELSE IF (
ASSOCIATED(entry%value_r4))
THEN
589 ELSE IF (
ASSOCIATED(entry%value_r8))
THEN
591 ELSE IF (
ASSOCIATED(entry%value_1d_i4))
THEN
593 datasize =
SIZE(entry%value_1d_i4)
594 ELSE IF (
ASSOCIATED(entry%value_1d_i8))
THEN
596 datasize =
SIZE(entry%value_1d_i8)
597 ELSE IF (
ASSOCIATED(entry%value_1d_r4))
THEN
599 datasize =
SIZE(entry%value_1d_r4)
600 ELSE IF (
ASSOCIATED(entry%value_1d_r8))
THEN
602 datasize =
SIZE(entry%value_1d_r8)
603 ELSE IF (
ASSOCIATED(entry%value_str))
THEN
606 cpabort(
"no value ASSOCIATED")
609 CALL group%bcast(datatype, src)
610 CALL group%bcast(datasize, src)
612 SELECT CASE (datatype)
614 IF (src /= mepos)
ALLOCATE (entry%value_i4)
615 CALL group%bcast(entry%value_i4, src)
617 IF (src /= mepos)
ALLOCATE (entry%value_i8)
618 CALL group%bcast(entry%value_i8, src)
620 IF (src /= mepos)
ALLOCATE (entry%value_r4)
621 CALL group%bcast(entry%value_r4, src)
623 IF (src /= mepos)
ALLOCATE (entry%value_r8)
624 CALL group%bcast(entry%value_r8, src)
626 IF (src /= mepos)
ALLOCATE (entry%value_1d_i4(datasize))
627 CALL group%bcast(entry%value_1d_i4, src)
629 IF (src /= mepos)
ALLOCATE (entry%value_1d_i8(datasize))
630 CALL group%bcast(entry%value_1d_i8, src)
632 IF (src /= mepos)
ALLOCATE (entry%value_1d_r4(datasize))
633 CALL group%bcast(entry%value_1d_r4, src)
635 IF (src /= mepos)
ALLOCATE (entry%value_1d_r8(datasize))
636 CALL group%bcast(entry%value_1d_r8, src)
638 IF (src == mepos) value_str_arr = str2iarr(entry%value_str)
639 CALL group%bcast(value_str_arr, src)
640 IF (src /= mepos)
THEN
641 ALLOCATE (entry%value_str)
642 entry%value_str = iarr2str(value_str_arr)
645 cpabort(
"unknown datatype")
648 END SUBROUTINE swarm_message_entry_mpi_bcast
656 SUBROUTINE swarm_message_entry_file_write(ENTRY, unit)
657 TYPE(message_entry_type),
INTENT(IN) :: entry
658 INTEGER,
INTENT(IN) :: unit
662 WRITE (unit,
"(A,A)")
"key: ", entry%key
663 IF (
ASSOCIATED(entry%value_i4))
THEN
664 WRITE (unit,
"(A)")
"datatype: i4"
665 WRITE (unit,
"(A,I10)")
"value: ", entry%value_i4
667 ELSE IF (
ASSOCIATED(entry%value_i8))
THEN
668 WRITE (unit,
"(A)")
"datatype: i8"
669 WRITE (unit,
"(A,I20)")
"value: ", entry%value_i8
671 ELSE IF (
ASSOCIATED(entry%value_r4))
THEN
672 WRITE (unit,
"(A)")
"datatype: r4"
673 WRITE (unit,
"(A,E30.20)")
"value: ", entry%value_r4
675 ELSE IF (
ASSOCIATED(entry%value_r8))
THEN
676 WRITE (unit,
"(A)")
"datatype: r8"
677 WRITE (unit,
"(A,E30.20)")
"value: ", entry%value_r8
679 ELSE IF (
ASSOCIATED(entry%value_str))
THEN
680 WRITE (unit,
"(A)")
"datatype: str"
681 WRITE (unit,
"(A,A)")
"value: ", entry%value_str
683 ELSE IF (
ASSOCIATED(entry%value_1d_i4))
THEN
684 WRITE (unit,
"(A)")
"datatype: 1d_i4"
685 WRITE (unit,
"(A,I10)")
"size: ",
SIZE(entry%value_1d_i4)
686 DO i = 1,
SIZE(entry%value_1d_i4)
687 WRITE (unit, *) entry%value_1d_i4(i)
690 ELSE IF (
ASSOCIATED(entry%value_1d_i8))
THEN
691 WRITE (unit,
"(A)")
"datatype: 1d_i8"
692 WRITE (unit,
"(A,I20)")
"size: ",
SIZE(entry%value_1d_i8)
693 DO i = 1,
SIZE(entry%value_1d_i8)
694 WRITE (unit, *) entry%value_1d_i8(i)
697 ELSE IF (
ASSOCIATED(entry%value_1d_r4))
THEN
698 WRITE (unit,
"(A)")
"datatype: 1d_r4"
699 WRITE (unit,
"(A,I8)")
"size: ",
SIZE(entry%value_1d_r4)
700 DO i = 1,
SIZE(entry%value_1d_r4)
701 WRITE (unit,
"(1X,E30.20)") entry%value_1d_r4(i)
704 ELSE IF (
ASSOCIATED(entry%value_1d_r8))
THEN
705 WRITE (unit,
"(A)")
"datatype: 1d_r8"
706 WRITE (unit,
"(A,I8)")
"size: ",
SIZE(entry%value_1d_r8)
707 DO i = 1,
SIZE(entry%value_1d_r8)
708 WRITE (unit,
"(1X,E30.20)") entry%value_1d_r8(i)
712 cpabort(
"no value ASSOCIATED")
714 END SUBROUTINE swarm_message_entry_file_write
723 SUBROUTINE swarm_message_entry_file_read(ENTRY, parser, at_end)
724 TYPE(message_entry_type),
INTENT(INOUT) :: entry
725 TYPE(cp_parser_type),
INTENT(INOUT) :: parser
726 LOGICAL,
INTENT(INOUT) :: at_end
728 CHARACTER(LEN=15) :: datatype, label
729 INTEGER :: arr_size, i
732 CALL parser_get_next_line(parser, 1, at_end)
733 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
735 READ (parser%input_line(1:
key_length + 10), *) label, entry%key
736 cpassert(trim(label) ==
"key:")
738 CALL parser_get_next_line(parser, 1, at_end)
739 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
741 READ (parser%input_line(1:30), *) label, datatype
742 cpassert(trim(label) ==
"datatype:")
744 CALL parser_get_next_line(parser, 1, at_end)
745 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
749 SELECT CASE (trim(datatype))
751 ALLOCATE (entry%value_i4)
752 READ (parser%input_line(1:40), *) label, entry%value_i4
754 ALLOCATE (entry%value_i8)
755 READ (parser%input_line(1:40), *) label, entry%value_i8
757 ALLOCATE (entry%value_r4)
758 READ (parser%input_line(1:40), *) label, entry%value_r4
760 ALLOCATE (entry%value_r8)
761 READ (parser%input_line(1:40), *) label, entry%value_r8
763 ALLOCATE (entry%value_str)
764 READ (parser%input_line(1:40), *) label, entry%value_str
770 cpassert(trim(label) ==
"value:")
775 READ (parser%input_line(1:30), *) label, arr_size
776 cpassert(trim(label) ==
"size:")
778 SELECT CASE (trim(datatype))
780 ALLOCATE (entry%value_1d_i4(arr_size))
782 ALLOCATE (entry%value_1d_i8(arr_size))
784 ALLOCATE (entry%value_1d_r4(arr_size))
786 ALLOCATE (entry%value_1d_r8(arr_size))
788 cpabort(
"unknown datatype")
792 CALL parser_get_next_line(parser, 1, at_end)
793 at_end = at_end .OR. len_trim(parser%input_line(1:10)) == 0
797 SELECT CASE (trim(datatype))
799 READ (parser%input_line(1:31), *) entry%value_1d_i4(i)
801 READ (parser%input_line(1:31), *) entry%value_1d_i8(i)
803 READ (parser%input_line(1:31), *) entry%value_1d_r4(i)
805 READ (parser%input_line(1:31), *) entry%value_1d_r8(i)
807 cpabort(
"swarm_message_entry_file_read: unknown datatype")
811 END SUBROUTINE swarm_message_entry_file_read
819 PURE FUNCTION str2iarr(str)
RESULT(arr)
820 CHARACTER(LEN=*),
INTENT(IN) :: str
821 INTEGER,
DIMENSION(LEN(str)) :: arr
826 arr(i) = ichar(str(i:i))
828 END FUNCTION str2iarr
836 PURE FUNCTION iarr2str(arr)
RESULT(str)
837 INTEGER,
DIMENSION(:),
INTENT(IN) :: arr
838 CHARACTER(LEN=SIZE(arr)) :: str
843 str(i:i) = char(arr(i))
845 END FUNCTION iarr2str
856 SUBROUTINE swarm_message_add_str (msg, key, value)
858 CHARACTER(LEN=*),
INTENT(IN) :: key
859 CHARACTER(LEN=*),
INTENT(IN) :: value
861 TYPE(message_entry_type),
POINTER :: new_entry
864 cpabort(
"swarm_message_add_str: key already exists: "//trim(key))
870 ALLOCATE (new_entry%value_str)
872 new_entry%value_str =
value
876 IF (.NOT.
ASSOCIATED(msg%root))
THEN
877 msg%root => new_entry
879 new_entry%next => msg%root
880 msg%root => new_entry
883 END SUBROUTINE swarm_message_add_str
892 SUBROUTINE swarm_message_get_str (msg, key, value)
894 CHARACTER(LEN=*),
INTENT(IN) :: key
896 CHARACTER(LEN=default_string_length) :: value
898 TYPE(message_entry_type),
POINTER :: curr_entry
902 curr_entry => msg%root
903 DO WHILE (
ASSOCIATED(curr_entry))
904 IF (trim(curr_entry%key) == trim(key))
THEN
905 IF (.NOT.
ASSOCIATED(curr_entry%value_str))
THEN
906 cpabort(
"swarm_message_get_str: value not associated key: "//trim(key))
908 value = curr_entry%value_str
912 curr_entry => curr_entry%next
914 cpabort(
"swarm_message_get: key not found: "//trim(key))
915 END SUBROUTINE swarm_message_get_str
925 SUBROUTINE swarm_message_add_i4 (msg, key, value)
927 CHARACTER(LEN=*),
INTENT(IN) :: key
928 INTEGER(KIND=int_4),
INTENT(IN) :: value
930 TYPE(message_entry_type),
POINTER :: new_entry
933 cpabort(
"swarm_message_add_i4: key already exists: "//trim(key))
939 ALLOCATE (new_entry%value_i4)
941 new_entry%value_i4 =
value
945 IF (.NOT.
ASSOCIATED(msg%root))
THEN
946 msg%root => new_entry
948 new_entry%next => msg%root
949 msg%root => new_entry
952 END SUBROUTINE swarm_message_add_i4
961 SUBROUTINE swarm_message_get_i4 (msg, key, value)
963 CHARACTER(LEN=*),
INTENT(IN) :: key
965 INTEGER(KIND=int_4),
INTENT(OUT) :: value
967 TYPE(message_entry_type),
POINTER :: curr_entry
971 curr_entry => msg%root
972 DO WHILE (
ASSOCIATED(curr_entry))
973 IF (trim(curr_entry%key) == trim(key))
THEN
974 IF (.NOT.
ASSOCIATED(curr_entry%value_i4))
THEN
975 cpabort(
"swarm_message_get_i4: value not associated key: "//trim(key))
977 value = curr_entry%value_i4
981 curr_entry => curr_entry%next
983 cpabort(
"swarm_message_get: key not found: "//trim(key))
984 END SUBROUTINE swarm_message_get_i4
994 SUBROUTINE swarm_message_add_i8 (msg, key, value)
996 CHARACTER(LEN=*),
INTENT(IN) :: key
997 INTEGER(KIND=int_8),
INTENT(IN) :: value
999 TYPE(message_entry_type),
POINTER :: new_entry
1002 cpabort(
"swarm_message_add_i8: key already exists: "//trim(key))
1005 ALLOCATE (new_entry)
1008 ALLOCATE (new_entry%value_i8)
1010 new_entry%value_i8 =
value
1014 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1015 msg%root => new_entry
1017 new_entry%next => msg%root
1018 msg%root => new_entry
1021 END SUBROUTINE swarm_message_add_i8
1030 SUBROUTINE swarm_message_get_i8 (msg, key, value)
1032 CHARACTER(LEN=*),
INTENT(IN) :: key
1034 INTEGER(KIND=int_8),
INTENT(OUT) :: value
1036 TYPE(message_entry_type),
POINTER :: curr_entry
1040 curr_entry => msg%root
1041 DO WHILE (
ASSOCIATED(curr_entry))
1042 IF (trim(curr_entry%key) == trim(key))
THEN
1043 IF (.NOT.
ASSOCIATED(curr_entry%value_i8))
THEN
1044 cpabort(
"swarm_message_get_i8: value not associated key: "//trim(key))
1046 value = curr_entry%value_i8
1050 curr_entry => curr_entry%next
1052 cpabort(
"swarm_message_get: key not found: "//trim(key))
1053 END SUBROUTINE swarm_message_get_i8
1063 SUBROUTINE swarm_message_add_r4 (msg, key, value)
1065 CHARACTER(LEN=*),
INTENT(IN) :: key
1066 REAL(KIND=real_4),
INTENT(IN) ::
value
1068 TYPE(message_entry_type),
POINTER :: new_entry
1071 cpabort(
"swarm_message_add_r4: key already exists: "//trim(key))
1074 ALLOCATE (new_entry)
1077 ALLOCATE (new_entry%value_r4)
1079 new_entry%value_r4 =
value
1083 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1084 msg%root => new_entry
1086 new_entry%next => msg%root
1087 msg%root => new_entry
1090 END SUBROUTINE swarm_message_add_r4
1099 SUBROUTINE swarm_message_get_r4 (msg, key, value)
1101 CHARACTER(LEN=*),
INTENT(IN) :: key
1103 REAL(KIND=real_4),
INTENT(OUT) ::
value
1105 TYPE(message_entry_type),
POINTER :: curr_entry
1109 curr_entry => msg%root
1110 DO WHILE (
ASSOCIATED(curr_entry))
1111 IF (trim(curr_entry%key) == trim(key))
THEN
1112 IF (.NOT.
ASSOCIATED(curr_entry%value_r4))
THEN
1113 cpabort(
"swarm_message_get_r4: value not associated key: "//trim(key))
1115 value = curr_entry%value_r4
1119 curr_entry => curr_entry%next
1121 cpabort(
"swarm_message_get: key not found: "//trim(key))
1122 END SUBROUTINE swarm_message_get_r4
1132 SUBROUTINE swarm_message_add_r8 (msg, key, value)
1134 CHARACTER(LEN=*),
INTENT(IN) :: key
1135 REAL(KIND=real_8),
INTENT(IN) ::
value
1137 TYPE(message_entry_type),
POINTER :: new_entry
1140 cpabort(
"swarm_message_add_r8: key already exists: "//trim(key))
1143 ALLOCATE (new_entry)
1146 ALLOCATE (new_entry%value_r8)
1148 new_entry%value_r8 =
value
1152 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1153 msg%root => new_entry
1155 new_entry%next => msg%root
1156 msg%root => new_entry
1159 END SUBROUTINE swarm_message_add_r8
1168 SUBROUTINE swarm_message_get_r8 (msg, key, value)
1170 CHARACTER(LEN=*),
INTENT(IN) :: key
1172 REAL(KIND=real_8),
INTENT(OUT) ::
value
1174 TYPE(message_entry_type),
POINTER :: curr_entry
1178 curr_entry => msg%root
1179 DO WHILE (
ASSOCIATED(curr_entry))
1180 IF (trim(curr_entry%key) == trim(key))
THEN
1181 IF (.NOT.
ASSOCIATED(curr_entry%value_r8))
THEN
1182 cpabort(
"swarm_message_get_r8: value not associated key: "//trim(key))
1184 value = curr_entry%value_r8
1188 curr_entry => curr_entry%next
1190 cpabort(
"swarm_message_get: key not found: "//trim(key))
1191 END SUBROUTINE swarm_message_get_r8
1201 SUBROUTINE swarm_message_add_1d_i4 (msg, key, value)
1203 CHARACTER(LEN=*),
INTENT(IN) :: key
1204 INTEGER(KIND=int_4),
DIMENSION(:),
INTENT(IN) :: value
1206 TYPE(message_entry_type),
POINTER :: new_entry
1209 cpabort(
"swarm_message_add_1d_i4: key already exists: "//trim(key))
1212 ALLOCATE (new_entry)
1215 ALLOCATE (new_entry%value_1d_i4 (
SIZE(
value)))
1217 new_entry%value_1d_i4 =
value
1221 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1222 msg%root => new_entry
1224 new_entry%next => msg%root
1225 msg%root => new_entry
1228 END SUBROUTINE swarm_message_add_1d_i4
1237 SUBROUTINE swarm_message_get_1d_i4 (msg, key, value)
1239 CHARACTER(LEN=*),
INTENT(IN) :: key
1241 INTEGER(KIND=int_4),
DIMENSION(:),
POINTER :: value
1243 TYPE(message_entry_type),
POINTER :: curr_entry
1246 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_i4: value already associated")
1248 curr_entry => msg%root
1249 DO WHILE (
ASSOCIATED(curr_entry))
1250 IF (trim(curr_entry%key) == trim(key))
THEN
1251 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_i4))
THEN
1252 cpabort(
"swarm_message_get_1d_i4: value not associated key: "//trim(key))
1254 ALLOCATE (value(
SIZE(curr_entry%value_1d_i4)))
1255 value = curr_entry%value_1d_i4
1259 curr_entry => curr_entry%next
1261 cpabort(
"swarm_message_get: key not found: "//trim(key))
1262 END SUBROUTINE swarm_message_get_1d_i4
1272 SUBROUTINE swarm_message_add_1d_i8 (msg, key, value)
1274 CHARACTER(LEN=*),
INTENT(IN) :: key
1275 INTEGER(KIND=int_8),
DIMENSION(:),
INTENT(IN) :: value
1277 TYPE(message_entry_type),
POINTER :: new_entry
1280 cpabort(
"swarm_message_add_1d_i8: key already exists: "//trim(key))
1283 ALLOCATE (new_entry)
1286 ALLOCATE (new_entry%value_1d_i8 (
SIZE(
value)))
1288 new_entry%value_1d_i8 =
value
1292 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1293 msg%root => new_entry
1295 new_entry%next => msg%root
1296 msg%root => new_entry
1299 END SUBROUTINE swarm_message_add_1d_i8
1308 SUBROUTINE swarm_message_get_1d_i8 (msg, key, value)
1310 CHARACTER(LEN=*),
INTENT(IN) :: key
1312 INTEGER(KIND=int_8),
DIMENSION(:),
POINTER :: value
1314 TYPE(message_entry_type),
POINTER :: curr_entry
1317 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_i8: value already associated")
1319 curr_entry => msg%root
1320 DO WHILE (
ASSOCIATED(curr_entry))
1321 IF (trim(curr_entry%key) == trim(key))
THEN
1322 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_i8))
THEN
1323 cpabort(
"swarm_message_get_1d_i8: value not associated key: "//trim(key))
1325 ALLOCATE (value(
SIZE(curr_entry%value_1d_i8)))
1326 value = curr_entry%value_1d_i8
1330 curr_entry => curr_entry%next
1332 cpabort(
"swarm_message_get: key not found: "//trim(key))
1333 END SUBROUTINE swarm_message_get_1d_i8
1343 SUBROUTINE swarm_message_add_1d_r4 (msg, key, value)
1345 CHARACTER(LEN=*),
INTENT(IN) :: key
1346 REAL(KIND=real_4),
DIMENSION(:),
INTENT(IN) ::
value
1348 TYPE(message_entry_type),
POINTER :: new_entry
1351 cpabort(
"swarm_message_add_1d_r4: key already exists: "//trim(key))
1354 ALLOCATE (new_entry)
1357 ALLOCATE (new_entry%value_1d_r4 (
SIZE(
value)))
1359 new_entry%value_1d_r4 =
value
1363 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1364 msg%root => new_entry
1366 new_entry%next => msg%root
1367 msg%root => new_entry
1370 END SUBROUTINE swarm_message_add_1d_r4
1379 SUBROUTINE swarm_message_get_1d_r4 (msg, key, value)
1381 CHARACTER(LEN=*),
INTENT(IN) :: key
1383 REAL(KIND=real_4),
DIMENSION(:),
POINTER ::
value
1385 TYPE(message_entry_type),
POINTER :: curr_entry
1388 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_r4: value already associated")
1390 curr_entry => msg%root
1391 DO WHILE (
ASSOCIATED(curr_entry))
1392 IF (trim(curr_entry%key) == trim(key))
THEN
1393 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_r4))
THEN
1394 cpabort(
"swarm_message_get_1d_r4: value not associated key: "//trim(key))
1396 ALLOCATE (value(
SIZE(curr_entry%value_1d_r4)))
1397 value = curr_entry%value_1d_r4
1401 curr_entry => curr_entry%next
1403 cpabort(
"swarm_message_get: key not found: "//trim(key))
1404 END SUBROUTINE swarm_message_get_1d_r4
1414 SUBROUTINE swarm_message_add_1d_r8 (msg, key, value)
1416 CHARACTER(LEN=*),
INTENT(IN) :: key
1417 REAL(KIND=real_8),
DIMENSION(:),
INTENT(IN) ::
value
1419 TYPE(message_entry_type),
POINTER :: new_entry
1422 cpabort(
"swarm_message_add_1d_r8: key already exists: "//trim(key))
1425 ALLOCATE (new_entry)
1428 ALLOCATE (new_entry%value_1d_r8 (
SIZE(
value)))
1430 new_entry%value_1d_r8 =
value
1434 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1435 msg%root => new_entry
1437 new_entry%next => msg%root
1438 msg%root => new_entry
1441 END SUBROUTINE swarm_message_add_1d_r8
1450 SUBROUTINE swarm_message_get_1d_r8 (msg, key, value)
1452 CHARACTER(LEN=*),
INTENT(IN) :: key
1454 REAL(KIND=real_8),
DIMENSION(:),
POINTER ::
value
1456 TYPE(message_entry_type),
POINTER :: curr_entry
1459 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_r8: value already associated")
1461 curr_entry => msg%root
1462 DO WHILE (
ASSOCIATED(curr_entry))
1463 IF (trim(curr_entry%key) == trim(key))
THEN
1464 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_r8))
THEN
1465 cpabort(
"swarm_message_get_1d_r8: value not associated key: "//trim(key))
1467 ALLOCATE (value(
SIZE(curr_entry%value_1d_r8)))
1468 value = curr_entry%value_1d_r8
1472 curr_entry => curr_entry%next
1474 cpabort(
"swarm_message_get: key not found: "//trim(key))
1475 END SUBROUTINE swarm_message_get_1d_r8
Adds an entry from a swarm-message.
Returns an entry from a swarm-message.
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 dp
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.
integer, parameter key_length
subroutine, public swarm_message_file_read(msg, parser, at_end)
Reads a swarm-message from a given file / unit.