I made a Python simulator that runs on the basis of user-provided arguments. To use the program, I run multiple random simulations (controlled with a seed value). I use GNU parallel to run the simulator with arguments in a similar manner as shown below:
parallel 'run-sim --seed {1} --power {2}' ::: <seed args> ::: <power args>
Now, there is a third argument --num
that I want to use, but want to link that argument with the seed value. So that, for every seed value only one num value is used. However, the same num argument should not be used with every power value.
In a nutshell, this table should make you understand better:
| Power | Seed | num |
|:-----------|------------:|:------------:|
| 10 | 0 | 100 |
| 10 | 1 | 150 |
| 10 | 2 | 200 |
| 10 | 3 | 250 |
|:-----------|------------:|:------------:|
| 20 | 0 | 300 |
| 20 | 1 | 350 |
| 20 | 2 | 400 |
| 20 | 3 | 450 |
....
(The table format may not be suitable for mobile devices)
If I were to write the above implementation using a for loop, I would do something like:
for p in power:
for s, n in (seed, num[p])
simulate(p, s, n)
Where power is a 1D array, seed is a 1D array and num is a 2D array where a row depicts the corresponding num values for a power p.
My Solution:
Use multiple parallel statements for each power value, and use the --link
parameter of parallel to bind the seed and num arguments.
parallel --link 'run-sim --seed {1} --num {2} --power 10' ::: 0 1 2 3 ::: 100 150 200 250
parallel --link 'run-sim --seed {1} --num {2} --power 20' ::: 0 1 2 3 ::: 300 350 400 450
...
The problem with this solution would be that I would have to limit the number of jobs for each statement based upon the number of power values. My computer can handle 50 extra processes before going into cardiac arrest, therefore for 3 power values, I would have to limit the jobs for each statement to 12.
What I am looking for
A single liner such that I don't have to run multiple parallel statements and fix the number of jobs to 50.