User Tools

Site Tools


wiki:exercise9

Exercise 9: pktools with multi-core processors

In this exercise the following tools will be used:

  • pktools: pkinfo
  • bash: for loop, xargs, time, sleep, redirection to /dev/null

Create a script /tmp/myscript.sh

INPUT=$1
NOVALUE=$2
pkinfo -i $INPUT --ref -mask $NOVALUE
#sleep 1

Make the script executable

chmod 755 /tmp/myscript.sh

Time the following command using a single processor

time for ((NOVALUE=0;NOVALUE<19;++NOVALUE));do pkinfo -i ${LANDSATDIR}/${LANDSATIMG} --ref -mask $NOVALUE;done>/dev/null

The output should be something like

real	0m18.691s
user	0m17.773s
sys	0m0.776s

Now do the same with a sleep command of 1 second after each iteration

time for ((NOVALUE=0;NOVALUE<19;++NOVALUE));do pkinfo -i ${LANDSATDIR}/${LANDSATIMG} --ref -mask $NOVALUE;sleep 1;done>/dev/null

The output should be something like

real	0m38.022s
user	0m17.669s
sys	0m1.168s

Question: What could be the difference between real and user time?

time for ((NOVALUE=0;NOVALUE<19;++NOVALUE));do echo 19990724_L7E_IP_CW.tif $NOVALUE;done |xargs -n 2 -P 2 /tmp/myscript.sh >/dev/null

Perform the same tasks in parallel with two processors using xargs

time for ((NOVALUE=0;NOVALUE<19;++NOVALUE));do echo 19990724_L7E_IP_CW.tif $NOVALUE;done |xargs -n 2 -P 2 /tmp/myscript.sh >/dev/null

Notice the real time difference

real	0m10.996s
user	0m20.029s
sys	0m0.844s

Uncomment the sleep command in the script and perform the same task

Question: what has happened with the sleep command now?

real	0m21.392s
user	0m20.209s
sys	0m1.284s
wiki/exercise9.txt · Last modified: 2017/12/05 22:53 (external edit)