forked from 2decomp-fft/2decomp-fft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_test.f90
129 lines (107 loc) · 3.46 KB
/
init_test.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
!! SPDX-License-Identifier: BSD-3-Clause
!!!=====================================================
!!!! init_test.f90
!!! Tests initialising the 2decomp&fft library.
!!!=====================================================
program init_test
use MPI
use decomp_2d_constants
use decomp_2d_mpi
use decomp_2d
#if defined(_GPU)
use cudafor
use openacc
#endif
implicit none
integer, parameter :: nx_base = 17, ny_base = 13, nz_base = 11
integer :: nx, ny, nz
integer :: p_row = 0, p_col = 0
integer :: resize_domain
integer :: nranks_tot
integer :: nargin, arg, FNLength, status, DecInd
character(len=80) :: InputFN
integer :: nexpect
integer :: ierror
call MPI_Init(ierror)
! To resize the domain we need to know global number of ranks
! This operation is also done as part of decomp_2d_init
call MPI_COMM_SIZE(MPI_COMM_WORLD, nranks_tot, ierror)
resize_domain = int(nranks_tot / 4) + 1
nx = nx_base * resize_domain
ny = ny_base * resize_domain
nz = nz_base * resize_domain
! Now we can check if user put some inputs
! Handle input file like a boss -- GD
nargin = command_argument_count()
if ((nargin == 0) .or. (nargin == 2) .or. (nargin == 5)) then
do arg = 1, nargin
call get_command_argument(arg, InputFN, FNLength, status)
read (InputFN, *, iostat=status) DecInd
if (arg == 1) then
p_row = DecInd
elseif (arg == 2) then
p_col = DecInd
elseif (arg == 3) then
nx = DecInd
elseif (arg == 4) then
ny = DecInd
elseif (arg == 5) then
nz = DecInd
end if
end do
else
! nrank not yet computed we need to avoid write
! for every rank
call MPI_COMM_RANK(MPI_COMM_WORLD, nrank, ierror)
if (nrank == 0) then
print *, "This Test takes no inputs or 2 inputs as"
print *, " 1) p_row (default=0)"
print *, " 2) p_col (default=0)"
print *, "or 5 inputs as"
print *, " 1) p_row (default=0)"
print *, " 2) p_col (default=0)"
print *, " 3) nx "
print *, " 4) ny "
print *, " 5) nz "
print *, "Number of inputs is not correct and the defult settings"
print *, "will be used"
end if
end if
nexpect = nx * ny * nz
call run(p_row, p_col)
call MPI_Finalize(ierror)
contains
subroutine run(p_row, p_col)
integer, intent(inout) :: p_row, p_col
call decomp_2d_init(nx, ny, nz, p_row, p_col)
call check_axis("X")
call check_axis("Y")
call check_axis("Z")
call decomp_2d_finalize()
end subroutine run
subroutine check_axis(axis)
character(len=*), intent(in) :: axis
integer :: suml
integer :: sumg
integer, dimension(3) :: sizes
if (axis == "X") then
sizes = xsize
else if (axis == "Y") then
sizes = ysize
else if (axis == "Z") then
sizes = zsize
else
sizes = 0
if (nrank == 0) print *, "ERROR: unknown axis requested!"
stop 1
end if
suml = product(sizes)
call MPI_Allreduce(suml, sumg, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierror)
if (sumg /= nexpect) then
if (nrank == 0) print *, "ERROR: got ", sumg, " nodes, expected ", nexpect
stop 1
else
if (nrank == 0) print *, "Init Test pass for axis ", axis
end if
end subroutine check_axis
end program init_test