我正在编写一个程序并尝试分解存储在数组中的数据,以使其运行得更快。我试图这样做:
data_to_analyze=(1 2 3 4 5 6 7 8 9 10)
#original array size
dataSize=(${#data_to_analyze[@]})
#half of that size
let samSmall="$dataSize/2"
#the other half
let samSmall2=("$dataSize - $samSmall -1")
#the first half
smallArray=("${data_to_analyze[@]:0:$samSmall}")
#the rest
smallArray2=("${data_to_analyze[@]:$samSmall:$samSmall2}")
#an array of names(which correspond to arrays)
combArray=(smallArray smallArray2)
sizeComb=(${#combArray[@]})
#for the length of the new array
for ((i=0; i<= $sizeComb ; i++)); do
#through first set of data and then loop back around for the second arrays data?
for sample_name in ${combArray[i]}; do
command
wait
command
wait
done
我想这样做只是首先将第一个数据数组提供给 for 循环。当第一个数组完成后,它应该再次通过第二个数组集。
这给我留下了两个问题。combArray 真的会传递两个较小的数组吗?还有更好的方法吗?