0

I have done a computation using CUDA and it takes around 12 minutes to complete the whole computation. I am using this command in a .sh file to run the program:

CUDA_VISIBLE_DEVICES=0 ./a1.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=1 ./a2.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=2 ./a3.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=3 ./a4.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=4 ./a5.out | tee -a output.txt &
CUDA_VISIBLE_DEVICES=5 ./a6.out | tee -a output.txt &

Now I want to show a progress bar for this process in the command line window for user. Is there is any way to do it?

David Foerster
  • 36,264
  • 56
  • 94
  • 147
agangwal
  • 103
  • Where would the progress information come from? – muru Jul 12 '17 at 04:40
  • I am expecting if there is some command which can tell me the progress of executable file directly. Otherwise I am taking total of 1000 values into the file output.txt. Maybe it can help in showing progress bar.. – agangwal Jul 12 '17 at 04:57
  • Using what? Magic? – muru Jul 12 '17 at 04:58
  • I am taking total of 1000 values into the file output.txt. Maybe it can help in showing progress bar..but I don't know how to do it. – agangwal Jul 12 '17 at 04:59
  • There is a for loop of 1000 iterations in my code which prints 1000 values in output.txt. Please tell me how can I use this to show progress bar?? – agangwal Jul 12 '17 at 05:02
  • Try something from https://askubuntu.com/questions/747143/create-a-progress-bar-in-bash, and use wc to get the line count from output.txt. – muru Jul 12 '17 at 05:02

1 Answers1

2

Use pv(1) in line mode:

COMMAND | pv --line-mode --size 1000 >> output.txt

or shorter

COMMAND | pv -ls 1000 >> output.txt

-s/--size sets the number of expected output units (bytes by default or lines in line mode).

If you want to capture the output and display the progress of multiple commands running in parallel you can do so with a compound statement:

{ COMMAND1 & COMMAND2 & COMMAND3; } | pv -ls 1000 >> output.txt

In that case you need to specify the number of expected output units of all commands in total.

Demo

for i in {1..200}; do sleep 0.1; echo "$i"; done | pv -ls 200 > /dev/null
David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • This is a good example. But it didn't work with my command. I think it works only when you print output in text file through shell script. Here my code is written in CUDA language and a.out is an executable file and I am printing output of this file into a text file. Do you have any solution for this situation?? – agangwal Jul 13 '17 at 04:34
  • @agangwal: Could you please edit your question to include what exactly you did and what happened? If the example in your question works, that means the programs are writing their output to the standard output file descriptor which can be piped into a different program like tee or pv. It also doesn't matter whether the source end of the pipe is a custom-written program or a shell script since both produce a sequence of bytes and write it to a file descriptor. – David Foerster Jul 13 '17 at 08:44
  • I get it now. I was not printing my output to stdout. I was printing it in a file which causes problem to use pv command. – agangwal Jul 13 '17 at 08:59