Shell script defining for loops of parameters of separate program
Hello everyone,
I've written a program in c++ (program.cpp)that needs to be run multiple times for all combinations of two parameters p1, p2 which are currently manually defined before each run. What I'd like to do is something to the effect of: for(p1=0; p1<p1max; p1++){ for(p2=0; p2<p2max; p2++){}run program.cpp} where I can change the limits of the maximum values so the whole thing can be parallelized. After some searching a shell script seems the best way to do this, but I'm new to unix and so would appreciate some help getting started. Thank you. |
Assuming bash (that's a type of shell) if you ditch the braces for 'do' and 'done' and add a second set of round brackets your set :)
Obviously you would also need to set your max values prior: Code:
p1max=10 |
Quote:
Code:
p1max=10 |
Yes, although if you simply wanted to run a single command 200 times then a single loop is all that is required.
|
Note: the example given runs make - which unless something in the source has changed, will do nothing after the first time.
Normally, such parameters would be passed on the command line, so instead of make, you would put "progname $p1 $p2". And if you were going to run multiple of these in parallel, you need to have different output files... So assuming the output is sent to stdout, that would make the command something like "progname $p1 $p2 >$p1_$p2.result&" Where the trailing & will put each invocation in the background. This COULD (depending on the parameters) overload your system. |
Quote:
Code:
#!/bin/sh |
Yes - they have to be evaluated by the program and set in the appropriate place.
It is just the normal practice. The only times that can get difficult is if they are used to define array dimensions in static structures, which isn't necessary. I only bring the subject up because you indicated you wanted to run them in parallel, and the first scrip could not do that. |
Hi,
you will need to modify your program so that it can take the values of p1 and p2 as arguments on the command line. So your program would look something like Code:
#include <iostream> Code:
g++ -o program program.cpp Code:
for par1 in x y z ; do |
Quote:
|
Quote:
|
Hi,
Quote:
Code:
#include <string> Evo2. |
Quote:
|
Depends on the code.
|
I found the mistake. Thank you very much to all of you for your help. :)
|
All times are GMT -5. The time now is 06:26 PM. |