@@ -2,18 +2,27 @@ program test_win_shared_mem
2
2
use libmpifx_module
3
3
implicit none
4
4
5
+ ! global communicator and within each shared memory node
5
6
type (mpifx_comm) :: globalcomm, nodecomm
7
+ ! RMA window, in this case shared memory
6
8
type (mpifx_win) :: win
7
- integer , parameter :: sample_value = 42 , size_rank_0 = 7 , size_rank_other = 4
9
+ ! Value to store for testing
10
+ integer , parameter :: sample_value = 42
11
+ ! Specific local sub-region sizes for one of the tests, either on the leader or followers in a
12
+ ! node
13
+ integer , parameter :: size_rank_0 = 7 , size_rank_other = 4
14
+ ! Global and local sizes of array in window
8
15
integer (MPIFX_SIZE_T) :: global_length, local_length
16
+
9
17
integer :: global_length_int32, local_length_int32
10
18
integer :: rank, ii
19
+ ! Pointer to whole array in window and the local part
11
20
integer , pointer :: global_pointer(:), local_pointer(:)
12
21
13
22
call mpifx_init()
14
23
call globalcomm% init()
15
24
16
- ! Create a new communicator for all ranks on a node first
25
+ ! Create a new communicator for all ranks that are on the same node first
17
26
call globalcomm% split_type(MPI_COMM_TYPE_SHARED, globalcomm% rank, nodecomm)
18
27
19
28
if (nodecomm% lead) then
@@ -23,26 +32,37 @@ program test_win_shared_mem
23
32
end if
24
33
global_length = size_rank_0 + size_rank_other * (nodecomm% size - 1 )
25
34
35
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36
+ ! ! First example, global array, distributed with only one process on the node writing
37
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38
+
39
+ ! Allocate a global window on the node
26
40
call win% allocate_shared(nodecomm, global_length, global_pointer)
27
41
28
- call win% lock ()
42
+ call win% lock_all ()
29
43
30
44
! Only rank 0 writes data into the array
31
45
if (nodecomm% lead) then
32
46
global_pointer(:) = sample_value
33
47
end if
34
48
35
49
call win% sync()
36
- call win% unlock ()
50
+ call win% unlock_all ()
37
51
38
52
! All ranks on the node will read the same value in the global array view
39
53
if (any (global_pointer(1 :global_length) /= sample_value)) then
40
- write (* , " (3(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , global_pointer(1 ), " EXPECTED:" , sample_value
54
+ write (* , " (3(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , global_pointer(1 ),&
55
+ & " EXPECTED:" , sample_value
41
56
call mpifx_abort(globalcomm)
42
57
end if
43
58
44
59
call win% free()
45
60
61
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
62
+ ! ! Second example, global array, lead rank writing to all of it, then local parts being written by
63
+ ! ! individual ranks on the node
64
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65
+
46
66
! Initialize again with specific local length
47
67
call win% allocate_shared(nodecomm, global_length, global_pointer, local_length, local_pointer)
48
68
@@ -57,7 +77,8 @@ program test_win_shared_mem
57
77
58
78
! All ranks on the node will read the same value in their local view
59
79
if (any (local_pointer(1 :local_length) /= sample_value)) then
60
- write (* , " (2(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , local_pointer(1 ), " EXPECTED:" , sample_value
80
+ write (* , " (2(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , local_pointer(1 ),&
81
+ & " EXPECTED:" , sample_value
61
82
call mpifx_abort(globalcomm)
62
83
end if
63
84
@@ -66,25 +87,32 @@ program test_win_shared_mem
66
87
67
88
call win% fence()
68
89
69
- ! All ranks should now read the correct global values
90
+ ! All ranks should now be able to read the correct global values
70
91
if (any (global_pointer(1 :size_rank_0) /= 0 )) then
71
- write (* , " (2(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , global_pointer(1 ), " EXPECTED:" , 0
92
+ write (* , " (2(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , global_pointer(1 ),&
93
+ & " EXPECTED:" , 0
72
94
call mpifx_abort(globalcomm)
73
95
end if
74
96
do rank = 1 , nodecomm% size - 1
75
97
ii = size_rank_0 + 1 + size_rank_other * (rank - 1 )
76
98
if (any (global_pointer(ii:ii+ size_rank_other-1 ) /= rank)) then
77
- write (* , " (2(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , global_pointer(ii), " EXPECTED:" , rank
99
+ write (* , " (2(A,1X,I0,1X))" ) " ERROR! ID:" , nodecomm% rank, " VALUE:" , global_pointer(ii),&
100
+ & " EXPECTED:" , rank
78
101
call mpifx_abort(globalcomm)
79
102
end if
80
103
end do
81
104
82
105
call win% free()
83
106
107
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
108
+ ! ! 32 bit sized indexing as a test
109
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
110
+
84
111
! Initialize again with int32 sizes
85
112
global_length_int32 = global_length
86
113
local_length_int32 = local_length
87
- call win% allocate_shared(nodecomm, global_length_int32, global_pointer, local_length_int32, local_pointer)
114
+ call win% allocate_shared(nodecomm, global_length_int32, global_pointer, local_length_int32,&
115
+ & local_pointer)
88
116
89
117
call win% free()
90
118
call mpifx_finalize()
0 commit comments