我不熟悉python。我想为下面的伪代码并行化外循环:
for(i=1 to N){ // N and n will be taken as input for the shell script.
min=some garbage value
for(j=1 to n){
val= './a.out' // call the executable a.out and take the output in val
if(val
min=val;
}
arr[k++]=min;
}
// Then I want to calculate the sum of the elements of the array 'arr'.我尝试使用shell脚本如下。但是N可能非常大。所以,我需要使用
多线程来并行化外循环。
#!/bin/bash
# set min to some garbage value
N=$1
n=$2
for (( i=1; i<=$N; i++ )); do
min=100000000
for (( j=1; j<=$n; j++ )); do
val=$(/path/to/a.out)
val2=`echo $val | bc` // is this the correct syntax?
if (( $val2 < $min )); then
min=$val2;
fi
done
arr=("${arr[@]}" "$min")
done
# Then I want to calculate the sum of the elements of the array 'arr'.
sum=0
for (( l=0; l
sum=$( expr $sum + ${arr[$l]} )
done
echo "Sum of \$arr = ${sum}"