Re: Inserting Parallel argument into command script

2020-06-19 Thread Ernst, Kevin
(reply below)

On 18.06.20 at 19:49, Miriam Dixon wrote:
> parallel runSim.sh --projAngles {1} ::: 0 45 90 135
>
> This seemed to work, in that it started my runSim.sh, but it didn't 
> use the value from projAngles within the script,
> time=$(bc -l <<< "$projAngles*$timePerProjection")
>
> Is there a way in the script or in parallel to insert the particular 
> projAngles value for that run, and use it to calculate the next step?

Hi Miriam,

Your 'parallel' command seems perfectly fine (you /could/ leave out the 
"1" in the "{}" as it's optional when there's only one argument, but 
that's up to you). Perhaps it's a shell scripting error?

Doing my best to imagine what the inside of your 'runSim.sh' script 
might look like, I came up with this:

     #!/bin/bash
     timePerProjection=10
     projAngles=${2:?Missing argument}
     time=$(bc -l <<< "$projAngles*$timePerProjection")
     echo $time

And running Parallel 20200122, I get (what I expected to be) the proper 
result

     $ parallel ./runSim.sh --projAngles {1} ::: 0 45 90 135
     0
     450
     900
     1350

It might help to just put

     echo $projAngles
     exit

somewhere early on in your script, just so you can be sure that the 
variable is being assigned properly given the option to the 
'--projAngles' command-line argument.

Also, adding 'set -u' at the top of your script will cause it to 
terminate (with an error message) any time a variable is used without 
being defined first. I add this to the top of all of my Bash scripts, 
for sanity's sake.

Lastly, as an aside, I find the '--dry-run' option to Parallel itself 
really handy when I'm preparing to run something with Parallel.

Hope this helps.

—Kevin

Re: Inserting Parallel argument into command script

2020-06-19 Thread Shlomi Fish
Hi Miriam,

Please reply to list:

https://www.shlomifish.org/philosophy/computers/netiquette/email/reply-to-list.html

On Fri, 19 Jun 2020 11:49:22 +1200
Miriam Dixon  wrote:

> Hi,
> 
> I am very new to Parallel, Linux, and computing in general but I need to
> use it for my Masters Thesis, so I am doing my best to learn quickly.
> 

Welcome aboard!

> For my project, I am running a simulation using GATE, and I have a shell
> script to run the simulation for each of four different projection angles.
> I want to run each projection angle simulation on a different core, to
> speed things along and use the computer memory efficiently. I tried to do
> this by pulling projAngles out of my script and calling it as a parallel
> argument.
> parallel runSim.sh --projAngles {1} ::: 0 45 90 135
> 
> This seemed to work, in that it started my runSim.sh, but it didn't use the
> value from projAngles within the script,
> time=$(bc -l <<< "$projAngles*$timePerProjection")
> 

As far as I know "--projAngles" in the shell script's command line arguments
does not automatically propagate to a shell variable. E.g:

```
[shlomif@telaviv1 ~]$ cat miriam-test.bash  
#! /bin/bash
#
# miriam-test.bash
# Copyright (C) 2020 Shlomi Fish 
#
# Distributed under the terms of the MIT license.
#
echo "argv = < $@ >"
echo "projAngles = < $projAngles >"
[shlomif@telaviv1 ~]$ bash miriam-test.bash --projAngles 500
argv = < --projAngles 500 >
projAngles = <  >
[shlomif@telaviv1 ~]$ projAngles=500 bash miriam-test.bash  
argv = <  >
projAngles = < 500 >
[shlomif@telaviv1 ~]$  
```

#bash on freenode has these links in its topic:

Topic for #bash is: http://mywiki.wooledge.org/BashFAQ
| http://mywiki.wooledge.org/BashGuide | http://gnu.org/s/bash/manual |
http://wiki.bash-hackers.org/ | http://mywiki.wooledge.org/Quotes |
http://www.shellcheck.net/ | https://lists.gnu.org/mailman/listinfo/help-bash |
https://git.savannah.gnu.org/cgit/bash.git?h=devel

Jun 19 10:32:21 *
Topic for #bash set by izabera (Wed Dec 25 11:08:20 2019) Jun 19 10:32:21
-ChanServ-  [#bash] Welcome to #bash, we discuss the GNU bash shell.  Be
explicit if your question is about another shell.  Don't trust the Internet on
bash, learn from the resources in the topic instead.  You must be identified to
send to the channel.

You may wish to peruse some of them as well as
https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ_with_ToC__generated.md
and https://perl-begin.org/FAQs/freenode-perl/ .

> Is there a way in the script or in parallel to insert the particular
> projAngles value for that run, and use it to calculate the next step?
> 

Either parse the cmd line arguments (using $1 / shift / $@ / etc.) or pass them
to the script using https://en.wikipedia.org/wiki/Environment_variable .

> Cheers,
> Miriam



-- 

Shlomi Fish   https://www.shlomifish.org/
Star Trek: “We, the Living Dead” - https://shlom.in/st-wtld

 Absolutely. Also: a German dog barks “wau” and a cat meows “miau”
 Su-Shee: German animals are true German patriots.

Please reply to list if it's a mailing list post - https://shlom.in/reply .



Inserting Parallel argument into command script

2020-06-18 Thread Miriam Dixon
Hi,

I am very new to Parallel, Linux, and computing in general but I need to
use it for my Masters Thesis, so I am doing my best to learn quickly.

For my project, I am running a simulation using GATE, and I have a shell
script to run the simulation for each of four different projection angles.
I want to run each projection angle simulation on a different core, to
speed things along and use the computer memory efficiently. I tried to do
this by pulling projAngles out of my script and calling it as a parallel
argument.
parallel runSim.sh --projAngles {1} ::: 0 45 90 135

This seemed to work, in that it started my runSim.sh, but it didn't use the
value from projAngles within the script,
time=$(bc -l <<< "$projAngles*$timePerProjection")

Is there a way in the script or in parallel to insert the particular
projAngles value for that run, and use it to calculate the next step?

Cheers,
Miriam