How can I get the solutions of Minizinc when I run it from command line? - minizinc

I try to run minizinc from command line and limit the time , but I receive =====UNKNOWN===== as output after the time limit passed. When I run it from minizinc IDE it is able to found several solutions in ~10 seconds.
minizinc.exe --solver-time-limit 60000 --solver gecode Model.mzn data.dzn
How can I get the solutions when I am running from command line?

Adding -a option will print all the intermediate solutions.
minizinc.exe -a --solver-time-limit 60000 --solver gecode Model.mzn data.dzn

Related

Solaris 10 time command to find execution time and save in a text file

H,
There is Solaris command "time" to find execution time of command ... e.g.
time command
I need to execute this "time command" command and save output in a file.
I can find -o flag in Linux (e.g. /usr/bin/time -o output.txt COMMAND) but this is not working in Solaris 10.
I would be thankful if some expert guide me to implement it in Solaris.
Best Regards
You need to redirect the output of time command to file:
time command >>output.txt 2>&1
the construction 2>&1 make STDERR also to go in the same file
And this work (with very high probability) on ANY Unix and Linux

How to write intermediate solutions as output in Minizic comand line?

I have been running Minizinc models from the command line, and I get final solutions as output.
I know I can make Minizic print intermedite solutions in the IDE. How can I make the same from the command line, so that they are printed as output like in the IDE? Btw, I'm refering to the output Minizinc prints by default, not to the 'output' (the one that acts like print) that you can include in the code of the model.
To output intermediate solutions you can use the -a flag on optimisation problems. So for example minizinc --solver gecode -a model.mzn data.dzn will solve model.mzn with data.dzn on the Gecode solver and output all intermediate solutions.
Note, however, that the -a flag has has a few peculiarities:
-a for satisfiability will output all solutions instead of intermediate solutions. So while scripting you need to be careful.
Not all solvers support the -a flag. Not all solver will have (or output) intermediate solution.

How to get Matlab output in Jenkins console [duplicate]

This question already has answers here:
Writing log statements to standard output with Matlab
(8 answers)
Closed 6 years ago.
I'm trying to integrate my MATLAB unit tests into Jenkins in a Windows environment. My problem is that I am not able to get the MATLAB output in my Jenkins console, even for a simple disp('Hello World!').
I create a Jenkins free job to execute the following batch command:
matlab -nodisplay -r "disp('Hello World!');exit".
Here is my result:
C:\Jenkins\jobs\runAllTests\workspace>matlab -nodisplay -r "disp('Hello World!');exit"
C:\Jenkins\jobs\runAllTests\workspace>exit 0
Finished: SUCCESS
Of course, I want to use Jenkins to execute a script to run several unit tests. But the problem is the same, I am not able to catch the MATLAB outputs.
Thanks in advance for any help.
I finally manage to get the matlab output in the console.
I follow a tip given in #AndyCampbell blog by #Guy Starbuck:
start /wait matlab -nodesktop -nosplash -minimize -wait -r "disp('Hello World!');exit" -logfile unittestlog.txt
set output=%errorlevel%
MORE unittestlog.txt
EXIT %output%
thanks all for your help.
You need to add -wait to the MATLAB command.
On Windows, Jenkins wraps the command in a batch file that returns immediately, and therefore doesn't capture the output (and by the way, it will also always exit with a success status even if MATLAB itself didn't).
By adding -wait, it will delay the exit until MATLAB has finished, and it will also return with the appropriate exit status.
PS Also see this excellent series of posts by #AndyCampbell on integrating MATLAB with Jenkins.
Edit:
The above works for me. But here's a couple of other things I would check, as they've been gotchas for me when I was getting it set up - perhaps they will help you too:
Make sure the build step is an "Execute Windows batch command" step rather than an "Execute shell" step, as it's a pain to get the unix utilities installed and running on Windows
Make sure that you have the right type of quote marks in the MATLAB build command. They need to be straight quotes, not curly quotes - both the single and double ones
If you copied and pasted the MATLAB build command into Jenkins, make sure you didn't accidentally paste in any extra invisible characters - try typing the command directly into Jenkins
Make sure there are no licensing issues - for example, Jenkins may be running as user1 and will call MATLAB as user1, but MATLAB is licensed to user2. If you call MATLAB with -nodesktop in this case it will just silently fail (and may even leave a zombie MATLAB process hanging around, with an invisible license error dialog, that you can only quit from with Task Manager)
To assist in troubleshooting, you can add -logfile \path\to\logfile.txt to your MATLAB command, which can diagnose some issues. You can also use a startup.m file and/or a finish.m file - these should run at startup (before your build command) and just before exit (after your build command). Finally you could try using a build command that does something simple to the filesystem, rather than a disp (this would diagnose whether it's an issue with MATLAB running at all, or an issue with Jenkins collecting its output).

GNU parallel --jobs option using multiple nodes on cluster with multiple cpus per node

I am using gnu parallel to launch code on a high performance (HPC) computing cluster that has 2 CPUs per node. The cluster uses TORQUE portable batch system (PBS). My question is to clarify how the --jobs option for GNU parallel works in this scenario.
When I run a PBS script calling GNU parallel without the --jobs option, like this:
#PBS -lnodes=2:ppn=2
...
parallel --env $PBS_O_WORKDIR --sshloginfile $PBS_NODEFILE \
matlab -nodiplay -r "\"cd $PBS_O_WORKDIR,primes1({})\"" ::: 10 20 30 40
it looks like it only uses one CPU per core, and also provides the following error stream:
bash: parallel: command not found
parallel: Warning: Could not figure out number of cpus on galles087 (). Using 1.
bash: parallel: command not found
parallel: Warning: Could not figure out number of cpus on galles108 (). Using 1.
This looks like one error for each node. I don't understand the first part (bash: parallel: command not found), but the second part tells me it's using one node.
When I add the option -j2 to the parallel call, the errors go away, and I think that it's using two CPUs per node. I am still a newbie to HPC, so my way of checking this is to output date-time stamps from my code (the dummy matlab code takes 10's of seconds to complete). My questions are:
Am I using the --jobs option correctly? Is it correct to specify -j2 because I have 2 CPUs per node? Or should I be using -jN where N is the total number of CPUs (number of nodes multiplied by number of CPUs per node)?
It appears that GNU parallel attempts to determine the number of CPUs per node on it's own. Is there a way that I can make this work properly?
Is there any meaning to the bash: parallel: command not found message?
Yes: -j is the number of jobs per node.
Yes: Install 'parallel' in your $PATH on the remote hosts.
Yes: It is a consequence from parallel missing from the $PATH.
GNU Parallel logs into the remote machine; tries to determine the number of cores (using parallel --number-of-cores) which fails and then defaults to 1 CPU core per host. By giving -j2 GNU Parallel will not try to determine the number of cores.
Did you know that you can also give the number of cores in the --sshlogin as: 4/myserver ? This is useful if you have a mix of machines with different number of cores.
This is not an answer to the 3 primary questions, but I'd like to point out some other problems with the parallel statement in the first code block.
parallel --env $PBS_O_WORKDIR --sshloginfile $PBS_NODEFILE \
matlab -nodiplay -r "\"cd $PBS_O_WORKDIR,primes1({})\"" ::: 10 20 30 40
The shell expands the $PBS_O_WORKDIR prior to executing parallel. This means two things happen (1) the --env sees a filename rather than an environment variable name and essentially does nothing and (2) expands as part command string eliminating the need to pass $PBS_O_WORKDIR which is why there wasn't an error.
The latest version of parallel 20151022 has a workdir option (although the tutorial lists it as alpha testing) which is probably the easiest solution. The parallel command line would look something like:
parallel --workdir $PBS_O_WORKDIR --sshloginfile $PBS_NODEFILE \
matlab -nodisplay -r "primes1({})" :::: 10 20 30 40
Final note, PBS_NODEFILE may contain hosts listed multiple times if more than one processor is requested by qsub. This many have implications for number of jobs run, etc.

How to make matlab block the shell in windows?

I use win7 and matlab2012a. I want to write a shell script to test my matlab scripts with different parameters. I use cygwin for this task. For example, alpha is the parameter and the matlab script is getall.m. The matlab script will read parameters from txt file 'param.txt'.
#!/bin/sh
# List=`seq 0.1 0.01 1`
List=`seq 0.1 0.1 0.2`
for alpha in $List
do
echo -ne "20\n61\n80\n1\n0.3\n${alpha}" > param.txt
matlab -nodesktop -r "getall;quit;" #time consuming
done
My problem is that script "getall.m" is time consuming, so I'd like to exec it one at a time. But I found that matlab command returns immediately. So the upper script will start a lot of matlab instances at the same time. I also tried the matlab command in cmd, but nothing changes. In ubuntu, matlab blocks the shell by default.
My question is how to make the matlab command to block the shell in windows?
There's a matlab -wait command line switch on Windows that will make it block.
http://www.mathworks.com/help/matlab/ref/matlabwindows.html
I don't know the "right" way to do this - but I do have a hack for you:
Make the matlab script create a file called "matlabDone" in the /tmp directory just before quitting; your shell script can go around a loop looking for this file. Once it exists, you know matlab is finished. Delete the file, and go around the loop again. Something like this:
List=`seq 0.1 0.1 0.2`
for alpha in $List
do
echo -ne "20\n61\n80\n1\n0.3\n${alpha}" > param.txt
matlab -nodesktop -r "getall;quit;" #time consuming
while [ ! -e /tmp/matlabDone ]
do
sleep 1
done
rm /tmp/matlabDone
done
Then make the last line of your matlab script create the file /tmp/matlabDone...
As I said - it's a hack...
PS I am not 100% sure what functions are available in cygwin. If you can't use sleep, I saw an interesting post suggesting that ping -n 2 127.0.0.1 > /dev/null (or equivalent ... depending on the version of ping you might need -c 2 -i 1 to get "one second per ping, count two") can be an alternative to sleep().