22#include "../base/base_uses.f90"
27 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'swarm_message'
31 TYPE(message_entry_type),
POINTER :: root => null()
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
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
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
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
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
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)
169 res = swarm_message_equal_oneway(msg1, msg2) .AND. &
170 swarm_message_equal_oneway(msg2, msg1)
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
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
233 INTEGER,
INTENT(IN) :: src
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
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)
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)
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)
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)
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))
866 ALLOCATE (new_entry%value_str)
868 new_entry%value_str =
value
872 IF (.NOT.
ASSOCIATED(msg%root))
THEN
873 msg%root => new_entry
875 new_entry%next => msg%root
876 msg%root => new_entry
879 END SUBROUTINE swarm_message_add_str
888 SUBROUTINE swarm_message_get_str (msg, key, value)
890 CHARACTER(LEN=*),
INTENT(IN) :: key
892 CHARACTER(LEN=default_string_length) :: value
894 TYPE(message_entry_type),
POINTER :: curr_entry
898 curr_entry => msg%root
899 DO WHILE (
ASSOCIATED(curr_entry))
900 IF (trim(curr_entry%key) == trim(key))
THEN
901 IF (.NOT.
ASSOCIATED(curr_entry%value_str))
THEN
902 cpabort(
"swarm_message_get_str: value not associated key: "//trim(key))
904 value = curr_entry%value_str
908 curr_entry => curr_entry%next
910 cpabort(
"swarm_message_get: key not found: "//trim(key))
911 END SUBROUTINE swarm_message_get_str
921 SUBROUTINE swarm_message_add_i4 (msg, key, value)
923 CHARACTER(LEN=*),
INTENT(IN) :: key
924 INTEGER(KIND=int_4),
INTENT(IN) :: value
926 TYPE(message_entry_type),
POINTER :: new_entry
929 cpabort(
"swarm_message_add_i4: key already exists: "//trim(key))
935 ALLOCATE (new_entry%value_i4)
937 new_entry%value_i4 =
value
941 IF (.NOT.
ASSOCIATED(msg%root))
THEN
942 msg%root => new_entry
944 new_entry%next => msg%root
945 msg%root => new_entry
948 END SUBROUTINE swarm_message_add_i4
957 SUBROUTINE swarm_message_get_i4 (msg, key, value)
959 CHARACTER(LEN=*),
INTENT(IN) :: key
961 INTEGER(KIND=int_4),
INTENT(OUT) :: value
963 TYPE(message_entry_type),
POINTER :: curr_entry
967 curr_entry => msg%root
968 DO WHILE (
ASSOCIATED(curr_entry))
969 IF (trim(curr_entry%key) == trim(key))
THEN
970 IF (.NOT.
ASSOCIATED(curr_entry%value_i4))
THEN
971 cpabort(
"swarm_message_get_i4: value not associated key: "//trim(key))
973 value = curr_entry%value_i4
977 curr_entry => curr_entry%next
979 cpabort(
"swarm_message_get: key not found: "//trim(key))
980 END SUBROUTINE swarm_message_get_i4
990 SUBROUTINE swarm_message_add_i8 (msg, key, value)
992 CHARACTER(LEN=*),
INTENT(IN) :: key
993 INTEGER(KIND=int_8),
INTENT(IN) :: value
995 TYPE(message_entry_type),
POINTER :: new_entry
998 cpabort(
"swarm_message_add_i8: key already exists: "//trim(key))
1001 ALLOCATE (new_entry)
1004 ALLOCATE (new_entry%value_i8)
1006 new_entry%value_i8 =
value
1010 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1011 msg%root => new_entry
1013 new_entry%next => msg%root
1014 msg%root => new_entry
1017 END SUBROUTINE swarm_message_add_i8
1026 SUBROUTINE swarm_message_get_i8 (msg, key, value)
1028 CHARACTER(LEN=*),
INTENT(IN) :: key
1030 INTEGER(KIND=int_8),
INTENT(OUT) :: value
1032 TYPE(message_entry_type),
POINTER :: curr_entry
1036 curr_entry => msg%root
1037 DO WHILE (
ASSOCIATED(curr_entry))
1038 IF (trim(curr_entry%key) == trim(key))
THEN
1039 IF (.NOT.
ASSOCIATED(curr_entry%value_i8))
THEN
1040 cpabort(
"swarm_message_get_i8: value not associated key: "//trim(key))
1042 value = curr_entry%value_i8
1046 curr_entry => curr_entry%next
1048 cpabort(
"swarm_message_get: key not found: "//trim(key))
1049 END SUBROUTINE swarm_message_get_i8
1059 SUBROUTINE swarm_message_add_r4 (msg, key, value)
1061 CHARACTER(LEN=*),
INTENT(IN) :: key
1062 REAL(KIND=real_4),
INTENT(IN) ::
value
1064 TYPE(message_entry_type),
POINTER :: new_entry
1067 cpabort(
"swarm_message_add_r4: key already exists: "//trim(key))
1070 ALLOCATE (new_entry)
1073 ALLOCATE (new_entry%value_r4)
1075 new_entry%value_r4 =
value
1079 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1080 msg%root => new_entry
1082 new_entry%next => msg%root
1083 msg%root => new_entry
1086 END SUBROUTINE swarm_message_add_r4
1095 SUBROUTINE swarm_message_get_r4 (msg, key, value)
1097 CHARACTER(LEN=*),
INTENT(IN) :: key
1099 REAL(KIND=real_4),
INTENT(OUT) ::
value
1101 TYPE(message_entry_type),
POINTER :: curr_entry
1105 curr_entry => msg%root
1106 DO WHILE (
ASSOCIATED(curr_entry))
1107 IF (trim(curr_entry%key) == trim(key))
THEN
1108 IF (.NOT.
ASSOCIATED(curr_entry%value_r4))
THEN
1109 cpabort(
"swarm_message_get_r4: value not associated key: "//trim(key))
1111 value = curr_entry%value_r4
1115 curr_entry => curr_entry%next
1117 cpabort(
"swarm_message_get: key not found: "//trim(key))
1118 END SUBROUTINE swarm_message_get_r4
1128 SUBROUTINE swarm_message_add_r8 (msg, key, value)
1130 CHARACTER(LEN=*),
INTENT(IN) :: key
1131 REAL(KIND=real_8),
INTENT(IN) ::
value
1133 TYPE(message_entry_type),
POINTER :: new_entry
1136 cpabort(
"swarm_message_add_r8: key already exists: "//trim(key))
1139 ALLOCATE (new_entry)
1142 ALLOCATE (new_entry%value_r8)
1144 new_entry%value_r8 =
value
1148 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1149 msg%root => new_entry
1151 new_entry%next => msg%root
1152 msg%root => new_entry
1155 END SUBROUTINE swarm_message_add_r8
1164 SUBROUTINE swarm_message_get_r8 (msg, key, value)
1166 CHARACTER(LEN=*),
INTENT(IN) :: key
1168 REAL(KIND=real_8),
INTENT(OUT) ::
value
1170 TYPE(message_entry_type),
POINTER :: curr_entry
1174 curr_entry => msg%root
1175 DO WHILE (
ASSOCIATED(curr_entry))
1176 IF (trim(curr_entry%key) == trim(key))
THEN
1177 IF (.NOT.
ASSOCIATED(curr_entry%value_r8))
THEN
1178 cpabort(
"swarm_message_get_r8: value not associated key: "//trim(key))
1180 value = curr_entry%value_r8
1184 curr_entry => curr_entry%next
1186 cpabort(
"swarm_message_get: key not found: "//trim(key))
1187 END SUBROUTINE swarm_message_get_r8
1197 SUBROUTINE swarm_message_add_1d_i4 (msg, key, value)
1199 CHARACTER(LEN=*),
INTENT(IN) :: key
1200 INTEGER(KIND=int_4),
DIMENSION(:),
INTENT(IN) :: value
1202 TYPE(message_entry_type),
POINTER :: new_entry
1205 cpabort(
"swarm_message_add_1d_i4: key already exists: "//trim(key))
1208 ALLOCATE (new_entry)
1211 ALLOCATE (new_entry%value_1d_i4 (
SIZE(
value)))
1213 new_entry%value_1d_i4 =
value
1217 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1218 msg%root => new_entry
1220 new_entry%next => msg%root
1221 msg%root => new_entry
1224 END SUBROUTINE swarm_message_add_1d_i4
1233 SUBROUTINE swarm_message_get_1d_i4 (msg, key, value)
1235 CHARACTER(LEN=*),
INTENT(IN) :: key
1237 INTEGER(KIND=int_4),
DIMENSION(:),
POINTER :: value
1239 TYPE(message_entry_type),
POINTER :: curr_entry
1242 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_i4: value already associated")
1244 curr_entry => msg%root
1245 DO WHILE (
ASSOCIATED(curr_entry))
1246 IF (trim(curr_entry%key) == trim(key))
THEN
1247 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_i4))
THEN
1248 cpabort(
"swarm_message_get_1d_i4: value not associated key: "//trim(key))
1250 ALLOCATE (value(
SIZE(curr_entry%value_1d_i4)))
1251 value = curr_entry%value_1d_i4
1255 curr_entry => curr_entry%next
1257 cpabort(
"swarm_message_get: key not found: "//trim(key))
1258 END SUBROUTINE swarm_message_get_1d_i4
1268 SUBROUTINE swarm_message_add_1d_i8 (msg, key, value)
1270 CHARACTER(LEN=*),
INTENT(IN) :: key
1271 INTEGER(KIND=int_8),
DIMENSION(:),
INTENT(IN) :: value
1273 TYPE(message_entry_type),
POINTER :: new_entry
1276 cpabort(
"swarm_message_add_1d_i8: key already exists: "//trim(key))
1279 ALLOCATE (new_entry)
1282 ALLOCATE (new_entry%value_1d_i8 (
SIZE(
value)))
1284 new_entry%value_1d_i8 =
value
1288 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1289 msg%root => new_entry
1291 new_entry%next => msg%root
1292 msg%root => new_entry
1295 END SUBROUTINE swarm_message_add_1d_i8
1304 SUBROUTINE swarm_message_get_1d_i8 (msg, key, value)
1306 CHARACTER(LEN=*),
INTENT(IN) :: key
1308 INTEGER(KIND=int_8),
DIMENSION(:),
POINTER :: value
1310 TYPE(message_entry_type),
POINTER :: curr_entry
1313 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_i8: value already associated")
1315 curr_entry => msg%root
1316 DO WHILE (
ASSOCIATED(curr_entry))
1317 IF (trim(curr_entry%key) == trim(key))
THEN
1318 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_i8))
THEN
1319 cpabort(
"swarm_message_get_1d_i8: value not associated key: "//trim(key))
1321 ALLOCATE (value(
SIZE(curr_entry%value_1d_i8)))
1322 value = curr_entry%value_1d_i8
1326 curr_entry => curr_entry%next
1328 cpabort(
"swarm_message_get: key not found: "//trim(key))
1329 END SUBROUTINE swarm_message_get_1d_i8
1339 SUBROUTINE swarm_message_add_1d_r4 (msg, key, value)
1341 CHARACTER(LEN=*),
INTENT(IN) :: key
1342 REAL(KIND=real_4),
DIMENSION(:),
INTENT(IN) ::
value
1344 TYPE(message_entry_type),
POINTER :: new_entry
1347 cpabort(
"swarm_message_add_1d_r4: key already exists: "//trim(key))
1350 ALLOCATE (new_entry)
1353 ALLOCATE (new_entry%value_1d_r4 (
SIZE(
value)))
1355 new_entry%value_1d_r4 =
value
1359 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1360 msg%root => new_entry
1362 new_entry%next => msg%root
1363 msg%root => new_entry
1366 END SUBROUTINE swarm_message_add_1d_r4
1375 SUBROUTINE swarm_message_get_1d_r4 (msg, key, value)
1377 CHARACTER(LEN=*),
INTENT(IN) :: key
1379 REAL(KIND=real_4),
DIMENSION(:),
POINTER ::
value
1381 TYPE(message_entry_type),
POINTER :: curr_entry
1384 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_r4: value already associated")
1386 curr_entry => msg%root
1387 DO WHILE (
ASSOCIATED(curr_entry))
1388 IF (trim(curr_entry%key) == trim(key))
THEN
1389 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_r4))
THEN
1390 cpabort(
"swarm_message_get_1d_r4: value not associated key: "//trim(key))
1392 ALLOCATE (value(
SIZE(curr_entry%value_1d_r4)))
1393 value = curr_entry%value_1d_r4
1397 curr_entry => curr_entry%next
1399 cpabort(
"swarm_message_get: key not found: "//trim(key))
1400 END SUBROUTINE swarm_message_get_1d_r4
1410 SUBROUTINE swarm_message_add_1d_r8 (msg, key, value)
1412 CHARACTER(LEN=*),
INTENT(IN) :: key
1413 REAL(KIND=real_8),
DIMENSION(:),
INTENT(IN) ::
value
1415 TYPE(message_entry_type),
POINTER :: new_entry
1418 cpabort(
"swarm_message_add_1d_r8: key already exists: "//trim(key))
1421 ALLOCATE (new_entry)
1424 ALLOCATE (new_entry%value_1d_r8 (
SIZE(
value)))
1426 new_entry%value_1d_r8 =
value
1430 IF (.NOT.
ASSOCIATED(msg%root))
THEN
1431 msg%root => new_entry
1433 new_entry%next => msg%root
1434 msg%root => new_entry
1437 END SUBROUTINE swarm_message_add_1d_r8
1446 SUBROUTINE swarm_message_get_1d_r8 (msg, key, value)
1448 CHARACTER(LEN=*),
INTENT(IN) :: key
1450 REAL(KIND=real_8),
DIMENSION(:),
POINTER ::
value
1452 TYPE(message_entry_type),
POINTER :: curr_entry
1455 IF (
ASSOCIATED(
value)) cpabort(
"swarm_message_get_1d_r8: value already associated")
1457 curr_entry => msg%root
1458 DO WHILE (
ASSOCIATED(curr_entry))
1459 IF (trim(curr_entry%key) == trim(key))
THEN
1460 IF (.NOT.
ASSOCIATED(curr_entry%value_1d_r8))
THEN
1461 cpabort(
"swarm_message_get_1d_r8: value not associated key: "//trim(key))
1463 ALLOCATE (value(
SIZE(curr_entry%value_1d_r8)))
1464 value = curr_entry%value_1d_r8
1468 curr_entry => curr_entry%next
1470 cpabort(
"swarm_message_get: key not found: "//trim(key))
1471 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 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.