
我有一個腳本看起來像:
for simplify in 0.1 ;do
for lmbda in 0.9 1.1 1.3;do
for mu in 2.1 3.4 4.2;do
rm eci.out;
csce.py --mu $mu --lmbda $lmbda --simplify $simplify \
--favor-low-energy 0.01 --bias-stable \
--save-energies ce-energies.dat --save-weights ce-weights.dat \
--casm-eci-file eci.in eci.out --save-hull ce-hull.dat \
--preserve-ground-state 100
done
done
done
順序運行時,會輸出
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.0002 --lmbda 0.005 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.0002, lambda = 0.005, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.03952735 0.04380240 0.02230235 -0.00185235
230 clusters 0.03734292 0.04294355 0.02049885 -0.00162721
Leave-one-out CV score wrt. input : 13.8588
Leave-one-out CV score wrt. full fit: 0.2201
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.0002 --lmbda 0.5 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.0002, lambda = 0.5, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.04017143 0.04451601 0.02267050 -0.00188774
219 clusters 0.03826959 0.04392544 0.02088397 -0.00166322
Leave-one-out CV score wrt. input : 7.9875
Leave-one-out CV score wrt. full fit: 0.1674
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.002 --lmbda 0.5 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.002, lambda = 0.5, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.14367173 0.15893736 0.07206284 -0.00912716
237 clusters 0.12351319 0.17167930 0.05376677 -0.00158861
Leave-one-out CV score wrt. input : 5.4561
Leave-one-out CV score wrt. full fit: 0.1119
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.002 --lmbda 0.005 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.002, lambda = 0.005, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.14299857 0.15820042 0.07228279 -0.00898964
237 clusters 0.12292319 0.17103283 0.05359447 -0.00138365
Leave-one-out CV score wrt. input : 5.3224
Leave-one-out CV score wrt. full fit: 0.1104
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.02 --lmbda 0.5 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.02, lambda = 0.5, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.19027749 0.20991052 0.09677830 -0.01602039
237 clusters 0.17531289 0.27618581 0.06910020 0.00220309
Leave-one-out CV score wrt. input : 2.4223
Leave-one-out CV score wrt. full fit: 0.0638
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.2 --lmbda 0.5 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.2, lambda = 0.5, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.26328087 0.28804954 0.15654138 -0.03325137
237 clusters 0.20897747 0.39607952 0.07887236 0.00877210
Leave-one-out CV score wrt. input : 1.9517
Leave-one-out CV score wrt. full fit: 0.0477
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.02 --lmbda 0.005 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.02, lambda = 0.005, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.18831434 0.20789816 0.09380533 -0.01523797
237 clusters 0.17809687 0.28067519 0.06919726 0.00308981
Leave-one-out CV score wrt. input : 2.4420
Leave-one-out CV score wrt. full fit: 0.0642
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.0002 --lmbda 0.05 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.0002, lambda = 0.05, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.03972713 0.04402288 0.02232628 -0.00187813
220 clusters 0.03735457 0.04295330 0.02008527 -0.00161760
Leave-one-out CV score wrt. input : 9.9223
Leave-one-out CV score wrt. full fit: 0.1863
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.2 --lmbda 0.005 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.2, lambda = 0.005, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.23518508 0.25836295 0.13669345 -0.02483126
237 clusters 0.21460451 0.36901059 0.08558721 0.00618068
Leave-one-out CV score wrt. input : 1.7372
Leave-one-out CV score wrt. full fit: 0.0490
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.002 --lmbda 0.05 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.002, lambda = 0.05, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.14375418 0.15902969 0.07218794 -0.00912434
237 clusters 0.12364959 0.17204399 0.05379933 -0.00144881
Leave-one-out CV score wrt. input : 5.5220
Leave-one-out CV score wrt. full fit: 0.1124
Writing CV energies to file `cv-energies.dat'.
/home1/03631/key01027/local_python_lib/bin/csce.py --mu 0.02 --lmbda 0.05 --simplify 0.1 --favor-low-energy 0.01 --bias-stable --save-energies ce-energies.dat --save-weights ce-weights.dat --casm-eci-file eci.in eci.out --save-hull ce-hull.dat --preserve-ground-state 100
Split-Bregman Input Parameters: mu = 0.02, lambda = 0.05, eci_cutoff = 1e-08
Attempting to simplify the CE using a target RMSE of 0.1
Warning: Unable to achieve target RMSE of 0.1
RMSE RMSE (no wght) MAE ME
237 clusters 0.19066043 0.21033595 0.09672442 -0.01606650
237 clusters 0.17565376 0.27643274 0.06917755 0.00238796
Leave-one-out CV score wrt. input : 2.4257
Leave-one-out CV score wrt. full fit: 0.0639
Writing CV energies to file `cv-energies.dat'.
然而,為了使計算更有效,我知道我們可以與“&”同時運行它:
for simplify in 0.1 ;do
for lmbda in 0.9 1.1 1.3;do
for mu in 2.1 3.4 4.2;do
rm eci.out;
csce.py --mu $mu --lmbda $lmbda --simplify $simplify \
--favor-low-energy 0.01 --bias-stable \
--save-energies ce-energies.dat --save-weights ce-weights.dat \
--casm-eci-file eci.in eci.out --save-hull ce-hull.dat \
--preserve-ground-state 100 &
done
done
done
但這樣它的輸出就會變得混亂......我能做什麼才能使其輸出在同時運行這些的同時按順序排列?謝謝。
答案1
如果您分叉所有這些命令,則 STDOUT 的輸出將不按順序,因為分叉不會按順序運行。
您可以將所有呼叫重定向csce.py
到單一文件,然後追蹤這些文件。使用檔案名稱的循環變數來了解哪個檔案代表哪個進程。
但為了可擴展性和控制,使用GNU並行可能值得嘗試。
順便說一句,文件的名稱*.dat
不取決於調用的參數,因此根據 python 腳本的工作方式,這些文件可能會被破壞(覆蓋)或隨著每次調用腳本而增長。
答案2
是的,GNU並行會很好地工作,但是如果你想透過&運算子來做到這一點,你需要知道分叉進程只有在獲得資源時才會運行,因為資源共享相同的標準輸出,所以輸出看起來很混亂。