Skip to content

Commit 6c4b523

Browse files
committed
Add missing testcase's source.
1 parent 3b40479 commit 6c4b523

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

src/tests/unit/simple/random_init.f90

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
! random init test
2+
!
3+
! Copyright (c) 2021-2021, Sourcery, Inc.
4+
! All rights reserved.
5+
!
6+
! Redistribution and use in source and binary forms, with or without
7+
! modification, are permitted provided that the following conditions are met:
8+
! * Redistributions of source code must retain the above copyright
9+
! notice, this list of conditions and the following disclaimer.
10+
! * Redistributions in binary form must reproduce the above copyright
11+
! notice, this list of conditions and the following disclaimer in the
12+
! documentation and/or other materials provided with the distribution.
13+
! * Neither the name of the Sourcery, Inc., nor the
14+
! names of its contributors may be used to endorse or promote products
15+
! derived from this software without specific prior written permission.
16+
!
17+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
! DISCLAIMED. IN NO EVENT SHALL SOURCERY, INC., BE LIABLE FOR ANY
21+
! DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24+
! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
!
27+
28+
program test_random_init
29+
implicit none
30+
integer :: me,np
31+
integer(kind=4), dimension(:), allocatable :: random_num, from_master
32+
integer(kind=4) :: seed_size
33+
integer :: seed_eq
34+
35+
me = this_image()
36+
np = num_images()
37+
38+
if (np .lt. 1) then
39+
error stop "Need at least two images."
40+
end if
41+
42+
call random_seed(size=seed_size)
43+
allocate(random_num(1:seed_size))
44+
allocate(from_master(1:seed_size))
45+
46+
call random_init(.true., .true.)
47+
48+
sync all
49+
call random_seed(get=random_num)
50+
if (me .eq. 1) then
51+
from_master = random_num
52+
end if
53+
call co_broadcast(from_master, 1)
54+
if (me .eq. 1) then
55+
seed_eq = 0
56+
else
57+
seed_eq = any(random_num .eq. from_master)
58+
end if
59+
call co_max(seed_eq, 1)
60+
61+
if (me .eq. 1 .and. seed_eq .eq. 1) then
62+
error stop "Test failed. (T,T)"
63+
end if
64+
65+
call random_init(.false., .true.)
66+
67+
sync all
68+
call random_seed(get=random_num)
69+
if (me .eq. 1) then
70+
from_master = random_num
71+
end if
72+
call co_broadcast(from_master, 1)
73+
if (me .eq. 1) then
74+
seed_eq = 0
75+
else
76+
seed_eq = any(random_num .eq. from_master)
77+
end if
78+
call co_max(seed_eq, 1)
79+
80+
if (me .eq. 1 .and. seed_eq .eq. 1) then
81+
error stop "Test failed. (F,T)"
82+
end if
83+
84+
sync all
85+
86+
call random_init(.false., .false.)
87+
88+
sync all
89+
call random_seed(get=random_num)
90+
if (me .eq. 1) then
91+
from_master = random_num
92+
end if
93+
call co_broadcast(from_master, 1)
94+
seed_eq = all(random_num .eq. from_master)
95+
call co_min(seed_eq, 1)
96+
97+
print *,"me=", me, ", rand_num=", random_num, ", from_master=", from_master, ", seed_eq=", seed_eq
98+
if (me .eq. 1 .and. seed_eq .eq. 0) then
99+
error stop "Test failed. (F,F)"
100+
end if
101+
102+
sync all
103+
104+
call random_init(.true., .false.)
105+
106+
sync all
107+
call random_seed(get=random_num)
108+
if (me .eq. 1) then
109+
from_master = random_num
110+
end if
111+
call co_broadcast(from_master, 1)
112+
seed_eq = all(random_num .eq. from_master)
113+
call co_min(seed_eq, 1)
114+
115+
if (me .eq. 1 .and. seed_eq .eq. 0) then
116+
error stop "Test failed. (T,F)"
117+
end if
118+
119+
sync all
120+
121+
if (me .eq. 1) print *,"Test passed."
122+
123+
end program test_random_init
124+

0 commit comments

Comments
 (0)