-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_mg_inputfiles.sh
executable file
·223 lines (188 loc) · 9.55 KB
/
create_mg_inputfiles.sh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash -eu
# Purpose: This file is intended to generate input files for the mg implementations in both grid and ddaamg
# Author: Daniel Richtmann
# Define some paths
declare -r script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -r config_dir=~/configs
declare -r template_dir=$script_dir/templates
declare -r params_dir=$script_dir/params
declare -r output_dir_base=$script_dir/output
# Define some global variables
declare -ar a_codebase=("grid" "ddaamg")
declare -ai a_global_lattsize_x=()
declare -ai a_global_lattsize_y=()
declare -ai a_global_lattsize_z=()
declare -ai a_global_lattsize_t=()
declare -ai a_local_lattsize_x=()
declare -ai a_local_lattsize_y=()
declare -ai a_local_lattsize_z=()
declare -ai a_local_lattsize_t=()
declare -i mpi_decomposition_x
declare -i mpi_decomposition_y
declare -i mpi_decomposition_z
declare -i mpi_decomposition_t
declare -i n_levels
function file_extension() {
local -r usage="
Usage: ${FUNCNAME[0]} <codebase>
PARAMETERS (NECESSARY)
<codebase> must be ∈ (grid, ddaamg)"
if [[ $# != 1 ]]; then
echo "$usage" >> /dev/stderr
return 1
else
local -r codebase=$1
case $codebase in
grid)
echo "xml"
;;
ddaamg)
echo "ini"
;;
*)
echo "$usage" >> /dev/stderr
return 1
esac
fi
}
function print_usage() {
local -r text="
USAGE:
$(basename "$0") <global_lattice> <mpi_decomposition> <levels> [<config>]
PARAMETERS (NECESSARY)
<global_lattice> Global lattice in the form \"X.Y.Z.T\"
<mpi_decomposition> MPI decomposition of the lattice in the form \"X.Y.Z.T\"
<levels> Number of levels to be used (must be ∈ {2,3,4})
PARAMETERS (OPTIONAL)
<config> Path to gauge configuration (if not given, script will construct a canonical path)
"
echo "$text" >> /dev/stderr
}
function convert_to_int() {
local -r boolean="$1"; shift
if [[ "$boolean" == true ]] ; then
echo 1
else
echo 0
fi
}
function calculate_lattice_sizes() {
a_local_lattsize_x[0]=$((a_global_lattsize_x[0] / mpi_decomposition_x))
a_local_lattsize_y[0]=$((a_global_lattsize_y[0] / mpi_decomposition_y))
a_local_lattsize_z[0]=$((a_global_lattsize_z[0] / mpi_decomposition_z))
a_local_lattsize_t[0]=$((a_global_lattsize_t[0] / mpi_decomposition_t))
for (( lvl=1; lvl<n_levels; lvl++ )); do
a_global_lattsize_x[$lvl]=$((a_global_lattsize_x[$((lvl-1))] / a_blocksize_x[$((lvl-1))]))
a_global_lattsize_y[$lvl]=$((a_global_lattsize_y[$((lvl-1))] / a_blocksize_y[$((lvl-1))]))
a_global_lattsize_z[$lvl]=$((a_global_lattsize_z[$((lvl-1))] / a_blocksize_z[$((lvl-1))]))
a_global_lattsize_t[$lvl]=$((a_global_lattsize_t[$((lvl-1))] / a_blocksize_t[$((lvl-1))]))
a_local_lattsize_x[$lvl]=$((a_global_lattsize_x[lvl] / mpi_decomposition_x))
a_local_lattsize_y[$lvl]=$((a_global_lattsize_y[lvl] / mpi_decomposition_y))
a_local_lattsize_z[$lvl]=$((a_global_lattsize_z[lvl] / mpi_decomposition_z))
a_local_lattsize_t[$lvl]=$((a_global_lattsize_t[lvl] / mpi_decomposition_t))
done
}
function replace_parameters_in_file() {
local -r output_file="$1"; shift
local -r codebase="$1"; shift
if [[ ! -w "$output_file" ]]; then
echo "${FUNCNAME[0]}: output file \"$output_file\" not present or not writable" >> /dev/stderr
return 1
fi
for (( lvl=0; lvl<n_levels; lvl++ )); do
sed -ri 's|%GLOBAL_LATTSIZE_'"$lvl"'_X%|'"${a_global_lattsize_x[$lvl]}"'|g' "$output_file"
sed -ri 's|%GLOBAL_LATTSIZE_'"$lvl"'_Y%|'"${a_global_lattsize_y[$lvl]}"'|g' "$output_file"
sed -ri 's|%GLOBAL_LATTSIZE_'"$lvl"'_Z%|'"${a_global_lattsize_z[$lvl]}"'|g' "$output_file"
sed -ri 's|%GLOBAL_LATTSIZE_'"$lvl"'_T%|'"${a_global_lattsize_t[$lvl]}"'|g' "$output_file"
sed -ri 's|%LOCAL_LATTSIZE_'"$lvl"'_X%|'"${a_local_lattsize_x[$lvl]}"'|g' "$output_file"
sed -ri 's|%LOCAL_LATTSIZE_'"$lvl"'_Y%|'"${a_local_lattsize_y[$lvl]}"'|g' "$output_file"
sed -ri 's|%LOCAL_LATTSIZE_'"$lvl"'_Z%|'"${a_local_lattsize_z[$lvl]}"'|g' "$output_file"
sed -ri 's|%LOCAL_LATTSIZE_'"$lvl"'_T%|'"${a_local_lattsize_t[$lvl]}"'|g' "$output_file"
done
for (( lvl=0; lvl<$((n_levels - 1)); lvl++ )); do
sed -ri 's|%BLOCKSIZE_'"$lvl"'_X%|'"${a_blocksize_x[$lvl]}"'|g' "$output_file"
sed -ri 's|%BLOCKSIZE_'"$lvl"'_Y%|'"${a_blocksize_y[$lvl]}"'|g' "$output_file"
sed -ri 's|%BLOCKSIZE_'"$lvl"'_Z%|'"${a_blocksize_z[$lvl]}"'|g' "$output_file"
sed -ri 's|%BLOCKSIZE_'"$lvl"'_T%|'"${a_blocksize_t[$lvl]}"'|g' "$output_file"
sed -ri 's|%SETUP_ITERS_'"$lvl"'%|'"${a_setup_iters[$lvl]}"'|g' "$output_file"
sed -ri 's|%SMOOTHER_TOL_'"$lvl"'%|'"${a_smoother_tol[$lvl]}"'|g' "$output_file"
sed -ri 's|%SMOOTHER_MAX_OUTER_ITER_'"$lvl"'%|'"${a_smoother_max_outer_iter[$lvl]}"'|g' "$output_file"
sed -ri 's|%SMOOTHER_MAX_INNER_ITER_'"$lvl"'%|'"${a_smoother_max_inner_iter[$lvl]}"'|g' "$output_file"
done
if [[ ${codebase} == "grid" ]]; then
sed -ri 's|%START_SUBSPACE_FROM_RANDOM%|'"${start_subspace_from_random}"'|g' "$output_file"
sed -ri 's|%USE_ANTIPERIODIC_BC%|'"${use_antiperiodic_bc}"'|g' "$output_file"
sed -ri 's|%KCYCLE%|'"${kcycle}"'|g' "$output_file"
elif [[ ${codebase} == "ddaamg" ]]; then
sed -ri 's|%START_SUBSPACE_FROM_RANDOM%|'"$(convert_to_int ${start_subspace_from_random})"'|g' "$output_file"
sed -ri 's|%USE_ANTIPERIODIC_BC%|'"$(convert_to_int ${use_antiperiodic_bc})"'|g' "$output_file"
sed -ri 's|%KCYCLE%|'"$(convert_to_int ${kcycle})"'|g' "$output_file"
else
echo "${FUNCNAME[0]}: codebase \"$codebase\" not element of {${a_codebase[@]}}" >> /dev/stderr
exit 1
fi
sed -ri 's|%KCYCLE_TOL%|'"${kcycle_tol}"'|g' "$output_file"
sed -ri 's|%KCYCLE_MAX_OUTER_ITER%|'"${kcycle_max_outer_iter}"'|g' "$output_file"
sed -ri 's|%KCYCLE_MAX_INNER_ITER%|'"${kcycle_max_inner_iter}"'|g' "$output_file"
sed -ri 's|%COARSE_SOLVER_TOL%|'"${coarse_solver_tol}"'|g' "$output_file"
sed -ri 's|%COARSE_SOLVER_MAX_OUTER_ITER%|'"${coarse_solver_max_outer_iter}"'|g' "$output_file"
sed -ri 's|%COARSE_SOLVER_MAX_INNER_ITER%|'"${coarse_solver_max_inner_iter}"'|g' "$output_file"
sed -ri 's|%OUTER_SOLVER_TOL%|'"${outer_solver_tol}"'|g' "$output_file"
sed -ri 's|%OUTER_SOLVER_MAX_OUTER_ITER%|'"${outer_solver_max_outer_iter}"'|g' "$output_file"
sed -ri 's|%OUTER_SOLVER_MAX_INNER_ITER%|'"${outer_solver_max_inner_iter}"'|g' "$output_file"
sed -ri 's|%MASS%|'"${mass}"'|g' "$output_file"
sed -ri 's|%CSW%|'"${csw}"'|g' "$output_file"
sed -ri 's|%CONFIG%|'"${config}"'|g' "$output_file"
if [[ ${codebase} == "ddaamg" ]]; then
case "${source_type}" in
"ones")
source_type=0
;;
"random")
source_type=2
;;
*)
echo "${FUNCNAME[0]}: source_type \"$source_type\" not element of {ones,random}" >> /dev/stderr
exit 1
;;
esac
fi
sed -ri 's|%SOURCE_TYPE%|'"${source_type}"'|g' "$output_file"
}
function create_mg_inputfiles() {
if [[ $# != 3 ]] && [[ $# != 4 ]]; then
print_usage
return 1
fi
local -r global_lattice="$1"; shift
local -r mpi_decomposition="$1"; shift
n_levels="$1"; shift
[[ $# == 1 ]] && local config="$1"; shift || local config=""
local -r OLD_IFS=$IFS
IFS='.' read -r a_global_lattsize_x[0] a_global_lattsize_y[0] a_global_lattsize_z[0] a_global_lattsize_t[0] <<< "$global_lattice"
IFS='.' read -r mpi_decomposition_x mpi_decomposition_y mpi_decomposition_z mpi_decomposition_t <<< "$mpi_decomposition"
IFS="$OLD_IFS"
if [[ $n_levels -lt 2 || $n_levels -gt 4 ]]; then
echo "${FUNCNAME[0]}: number of levels must be ∈ {2,3,4}" >> /dev/stderr
return 1
fi
local -r params_file=$params_dir/${n_levels}_lvls.src
. "$params_file"
local -r lattsize_string=${a_global_lattsize_x[0]}x${a_global_lattsize_y[0]}x${a_global_lattsize_z[0]}x${a_global_lattsize_t[0]}
[[ -z $config ]] && config=$config_dir/grid_gauge_config_hot.sequence_1.latt_size_${lattsize_string}.seeds_1x2x3x4
if [[ ! -r $config ]]; then
echo "${FUNCNAME[0]}: gauge configuration \"$config\" not present or not readable" >> /dev/stderr
return 1
fi
calculate_lattice_sizes
for codebase in "${a_codebase[@]}"; do
local template=$template_dir/$codebase/${n_levels}_lvls."$(file_extension $codebase)"
local output_dir=$output_dir_base/$codebase
local output_file=$output_dir/mg_params.${n_levels}_lvls."$(file_extension $codebase)"
mkdir -p "$output_dir"
cp "$template" "$output_file"
replace_parameters_in_file "$output_file" "$codebase"
echo "Done with file $output_file"
done
}
create_mg_inputfiles "$@"