我在for循环中运行我的程序,传递给它不同的num_threads值。
for (( j=1; j<9; j++ ))
do
mpirun -n $j ./my_program
done
我知道 bash 会将返回值存储在 $? 自动地。但是,我要做的是在传递 num_threads=1 的参数时获取并行程序的运行时,以便在 num_threads>1 时运行该程序时可以使用此值来查找加速。我需要为此返回一个双精度数,并且我曾尝试从 main() 返回一个双精度数:
double main(int argc, char** argv) {
double run_time;
...
return run_time;
}
但似乎 main() 只能返回一个 int,而我从我的 bash 脚本中得到一个 0。
time=$?
echo $time
output:
0