@@ -7,6 +7,12 @@ program main
7
7
integer , parameter :: sender= 1 ! ! co_broadcast source_image
8
8
character (len=* ), parameter :: text= " text" ! ! character message data
9
9
10
+ interface
11
+ function f (x ) result(y)
12
+ real x, y
13
+ end function
14
+ end interface
15
+
10
16
associate(me= >this_image())
11
17
12
18
test_non_allocatable: block
@@ -19,23 +25,53 @@ program main
19
25
end type
20
26
21
27
type, extends(parent) :: child
22
- type (component) a
28
+
29
+ ! Scalar and array derived-type components
30
+ type (component) a, b(1 ,2 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 )
31
+
32
+ ! Scalar and array intrinsic-type components
23
33
character (len= len (text)) :: c= " " , z(0 )
24
34
complex :: i= (0 .,0 .), j(1 )= (0 .,0 .)
25
35
integer :: k= 0 , l(2 ,3 )= 0
26
- real :: r= 0 ., s(3 ,2 ,1 )= 0 .
27
- logical :: t= .false. , u(1 ,2 ,3 , 1 ,2 ,3 , 1 ,2 ,3 , 1 ,2 ,3 , 1 ,2 ,3 )= .false.
36
+ logical :: r= .false. , s(1 ,2 ,3 , 1 ,2 ,3 , 1 ,2 ,3 , 1 ,2 ,3 , 1 ,2 ,3 )= .false.
37
+ real :: t= 0 ., u(3 ,2 ,1 )= 0 .
38
+
39
+ ! Scalar and array pointer components
40
+ character (len= len (text)), pointer :: &
41
+ char_ptr= >null (), char_ptr_maxdim(:,:,:, :,:,:, :,:,:, :,:,:, :,:,:)= >null ()
42
+ complex , pointer :: cplx_ptr= >null (), cplx_ptr_maxdim(:,:,:, :,:,:, :,:,:, :,:,:, :,:,:)= >null ()
43
+ integer , pointer :: int_ptr = >null (), int_ptr_maxdim (:,:,:, :,:,:, :,:,:, :,:,:, :,:,:)= >null ()
44
+ logical , pointer :: bool_ptr= >null (), bool_ptr_maxdim(:,:,:, :,:,:, :,:,:, :,:,:, :,:,:)= >null ()
45
+ real , pointer :: real_ptr= >null (), real_ptr_maxdim(:,:,:, :,:,:, :,:,:, :,:,:, :,:,:)= >null ()
46
+ procedure (f), pointer :: procedure_pointer= >null ()
28
47
end type
29
48
30
49
type (child) message
31
- type (child) :: content = child( &
32
- parent= parent(heritable=- 2 ), a= component(- 1 ), c= text, z= [character (len= len (text)):: ], &
33
- i= (0 .,1 .), j= (2 .,3 .), k= 4 , l= 5 , r= 7 ., s= 8 ., t= .true. , u= .true. &
50
+ type (child) :: content = child( & ! define content using the insrinsic structure constructor
51
+ parent= parent(heritable=- 4 ), & ! parent
52
+ a= component(- 3 ), b= reshape ([component(- 2 ),component(- 1 )], [1 ,2 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 ]), & ! derived types
53
+ c= text, z= [character (len= len (text)):: ], i= (0 .,1 .), j= (2 .,3 .), k= 4 , l= 5 , r= .true. , s= .true. , t= 7 ., u= 8 . & ! intrinsic types
34
54
)
35
- if (me== sender) message = content
55
+ if (me== sender) then
56
+ message = content
57
+ allocate (message% char_ptr, message% char_ptr_maxdim(1 ,1 ,2 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 ), source= text )
58
+ allocate (message% cplx_ptr, message% cplx_ptr_maxdim(1 ,1 ,1 , 1 ,1 ,2 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 ), source= (0 .,1 .))
59
+ allocate (message% int_ptr , message% int_ptr_maxdim (1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,2 , 1 ,1 ,1 , 1 ,1 ,1 ), source= 2 )
60
+ allocate (message% bool_ptr, message% bool_ptr_maxdim(1 ,1 ,1 , 1 ,2 ,1 , 1 ,1 ,1 , 1 ,1 ,2 , 1 ,1 ,1 ), source= .true. )
61
+ allocate (message% real_ptr, message% real_ptr_maxdim(1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,2 ), source= 3 . )
62
+ end if
36
63
37
64
call co_broadcast(message,source_image= sender)
38
65
66
+ if (me== sender) then
67
+ deallocate (message% char_ptr, message% char_ptr_maxdim)
68
+ deallocate (message% cplx_ptr, message% cplx_ptr_maxdim)
69
+ deallocate (message% int_ptr , message% int_ptr_maxdim )
70
+ deallocate (message% bool_ptr, message% bool_ptr_maxdim)
71
+ deallocate (message% real_ptr, message% real_ptr_maxdim)
72
+ end if
73
+
74
+ ! ! Verify correct broadcast of all non-pointer components (pointers become undefined on the receiving image).
39
75
associate( failures = > [ &
40
76
message% parent% heritable /= content% parent% heritable, &
41
77
message% a% subcomponent /= content% a% subcomponent, &
@@ -45,10 +81,10 @@ program main
45
81
message% j /= content% j, &
46
82
message% k /= content% k, &
47
83
message% l /= content% l, &
48
- message% r /= content% r, &
49
- message% s /= content% s, &
50
- message% t .neqv. content% t, &
51
- any ( message% u .neqv. content% u ) &
84
+ message% r .neqv. content% r, &
85
+ message% s .neqv. content% s, &
86
+ message% t /= content% t, &
87
+ any ( message% u /= content% u ) &
52
88
] )
53
89
54
90
if ( any (failures) ) error stop " Test failed in non-allocatable block."
@@ -57,40 +93,43 @@ program main
57
93
58
94
end block test_non_allocatable
59
95
60
- test_allocatable: block
61
- type dynamic
62
- character (len= :), allocatable :: string
63
- complex , allocatable :: scalar
64
- integer , allocatable :: vector(:)
65
- logical , allocatable :: matrix(:,:)
66
- real , allocatable :: superstring(:,:,:, :,:,:, :,:,:, :,:,:, :,:,: )
67
- end type
96
+ test_allocatable: block
97
+ type dynamic
98
+ character (len= :), allocatable :: string
99
+ character (len= len (text)), allocatable :: string_array(:)
100
+ complex , allocatable :: scalar
101
+ integer , allocatable :: vector(:)
102
+ logical , allocatable :: matrix(:,:)
103
+ real , allocatable :: superstring(:,:,:, :,:,:, :,:,:, :,:,:, :,:,: )
104
+ end type
68
105
69
- type (dynamic) alloc_message, alloc_content
106
+ type (dynamic) alloc_message, alloc_content
70
107
71
- alloc_content = dynamic( &
72
- string= text, &
73
- scalar= (0 .,1 .), &
74
- vector= reshape ( [integer :: ], [0 ]), &
75
- matrix= reshape ( [.true. ], [1 ,1 ]), &
76
- superstring= reshape ([1 ,2 ,3 ,4 ], [2 ,1 ,2 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 ]) &
77
- )
108
+ alloc_content = dynamic( &
109
+ string= text, &
110
+ string_array= [text], &
111
+ scalar= (0 .,1 .), &
112
+ vector= reshape ( [integer :: ], [0 ]), &
113
+ matrix= reshape ( [.true. ], [1 ,1 ]), &
114
+ superstring= reshape ([1 ,2 ,3 ,4 ], [2 ,1 ,2 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 , 1 ,1 ,1 ]) &
115
+ )
78
116
79
- if (me== sender) alloc_message = alloc_content
117
+ if (me== sender) alloc_message = alloc_content
80
118
81
- call co_broadcast(alloc_message,source_image= sender)
119
+ call co_broadcast(alloc_message,source_image= sender)
82
120
83
- associate( failures = > [ &
84
- alloc_message% string /= alloc_content% string, &
85
- alloc_message% scalar /= alloc_content% scalar, &
86
- alloc_message% vector /= alloc_content% vector, &
87
- alloc_message% matrix .neqv. alloc_content% matrix, &
88
- alloc_message% superstring /= alloc_content% superstring &
89
- ] )
121
+ associate( failures = > [ &
122
+ alloc_message% string /= alloc_content% string, &
123
+ alloc_message% string_array /= alloc_content% string_array, &
124
+ alloc_message% scalar /= alloc_content% scalar, &
125
+ alloc_message% vector /= alloc_content% vector, &
126
+ alloc_message% matrix .neqv. alloc_content% matrix, &
127
+ alloc_message% superstring /= alloc_content% superstring &
128
+ ] )
90
129
91
- if ( any (failures) ) error stop " Test failed in allocatable block."
130
+ if ( any (failures) ) error stop " Test failed in allocatable block."
92
131
93
- end associate
132
+ end associate
94
133
95
134
end block test_allocatable
96
135
0 commit comments