CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   running OF on local machine with batch script / job scheduler (http://www.cfd-online.com/Forums/openfoam/81646-running-local-machine-batch-script-job-scheduler.html)

val46 November 2, 2010 11:14

running OF on local machine with batch script / job scheduler
 
Hi,
I would like to run simpleFoam in batch mode on a local machine with 4 cores.
Has anyone a simple script with I could use? (My c++ skills are very limited)

Thanks in advance

Best Regards,
Toni

mturcios777 November 2, 2010 13:07

Do you want to run one case on each core? If that is the case then you can probably just use this (assuming you are in a bash environment):

Code:

#!/bin/bash

CASE1=/location/of/1st/case
CASE2=/location/of/2nd/case
CASE3=/location/of/3rd/case
CASE4=/location/of/4th/case

cd $CASE1
foamJob simpleFoam
cd $CASE2
foamJob simpleFoam
cd $CASE3
foamJob simpleFoa
cd $CASE4
foamJob simpleFoam

Scripting is a worthwhile skill to learn. I used this tutorial to get me started:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

val46 November 2, 2010 13:13

Hi Marco,
thanks for your reply.
Quote:

Do you want to run one case on each core?
No, I would like to run a case with 4 nodes and after it has finished a new case (also with 4 nodes) should start automatically.


Regards,
Toni

mturcios777 November 2, 2010 13:27

Ah, then you'll need to use
1. decomposePar to split the simulation domain
2. mpirun to run the solver in parallel

The dam-break tutorial shows you how to work with parallel cases. Once you figure that out, then you should have a clear idea of how to change the above script

val46 November 2, 2010 14:05

No,no! I know how to run a parallel case.
I need a script to start cases automatically.
The script should always check if a case is running or if the cores are "occupied". If so than "wait", if not than "start another case".

Hope you know what I mean.

LarsPT November 2, 2010 14:39

Just write a script, that executes all the OpenFOAM commands and then just write several commands divided by semicolons. The script may look like this! Take care of the paths (relative or absolute, it's your choice). The script below is for relative paths, e.g. your cases are in the OF-run folder.

Code:

/!bin/bash

JOBNAME=$1

cd $JOBNAME

blockMesh
setFields
decomposePar
mpirun -np 4 simpleFoam -parallel > log.simpleFoam
reconstructPar
sample
rm -r processor*

cd ..

Then you can type in a terminal:

Code:

user:~/OpenFOAM/username-1.x/run$ batchOF <JobName1>; batchOF <JobNameN>;
Of course you have to change the username to your username and the version of OF.

Lars

chegdan November 2, 2010 16:58

OpenFoam Built-In run functions
 
How about using OF built in run functions?

they are in

Code:

$WM_PROJECT_DIR/bin/tools/RunFunctions
and are used in all the Allrun scripts in openfoam that are in the tutorials. Take a look at the Allrun script in the interFoam tutorial folder. A simple one I use for simpleFoam is:

Code:

#!/bin/sh
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

cd case1
    runApplication decomposePar
    hostname > system/machines
    runParallel simpleFoam 4 system/machines
    runApplication reconstructPar
cd ..

change the 4 to whatever number of processors you want and make sure it agrees with the decomposeparDict file.

This is assuming that you run it from above the case1 folder (or whatever case name you want), you have a correct decomposeParDict file, and there are no other files that have log.decomposePar, log.simpleFoam, or log.reconstructPar in the case folder or the run functions will detect them and not run. Each of the run functions will wait for the previous one to finish before being executed. Just copy the code to a text file, make the text file executable, and call it with ./(file name without parenthesis).

Alternatively, you can use some of the handy scripts in pyFoam (http://openfoamwiki.net/index.php/Contrib_PyFoam) but that takes some time to set up. Although its really worth it in the end...or at least I like it for some. Hope this helps.

Dan

philippose November 2, 2010 17:49

Hello,

A Good Evening to you!

I would strongly suggest that you consider using a load-balancing system such as Condor or the SUN GridEngine.

Even though you are talking about one local multi-core computer, a system such as Condor can help you quite a bit because you can submit multiple parallel jobs at the same time.... and the jobs go into a Queue which is automatically queried and handled by the software which runs as a service on your Linux system.

Condor runs the first simulation, and once that has been completed, it automatically starts the next job in the queue, and so on.

Later on in the future extending the setup to use more than one computer is trivial, because Condor is basically a "Cluster" tool, and has been designed to work with multiple systems over networks.

Hope this helps.

Philippose

val46 November 4, 2010 04:47

HAHA! Stupid me!
I know about the allrun scripts but somehow I wasn't aware of the fact that they can exactly do what I want.

Thank you for the hint, Dan!


I tried the following:
Code:

runApplication snappyHexMesh -overwrite

runApplication transformPoints -scale "(0.001 0.001 0.001)"

runApplication potentialFoam -writep

runApplication decomposePar -force

hostname > system/machines

runParallel simpleFoam 4 system/machines

runApplication reconstructPar -latestTime

But got an error message from the transformPoints command:

Code:

Wrong number of arguments, expected 0 found 2
Because of that I had to write these additional lines:

Code:

runtransformPoints()
{
    if [ -f log.transformPoints ]
    then
        echo "transformPoints already run on $PWD: remove log file to run"
    else
        echo "transformPoints: converting mesh"
        transformPoints -scale "($1 $2 $3)" > log.transformPoints 2>&1
    fi
}

runtransformPoints 0.001 0.001 0.001

Than it worked but I'm not very happy with it.
Why is the transformPoints command not working in the script?
I also tried ' instead of " but without success.


Best Regards,
Toni

chegdan November 4, 2010 10:57

did you try no quotation marks?
 
Im not near a Linux computer right now...but try

Code:

runApplication transformPoints -scale (0.001 0.001 0.001)
instead of
Code:

runApplication transformPoints -scale "(0.001 0.001 0.001)"
to pass numbers like that in the script you don't need the "" in that case i believe.

Dan

chegdan November 4, 2010 11:17

Scratch that, try

Code:

vector=(0.001 0.001 0.001)
runApplication transformPoints -scale $vector

instead and see what you get.

Dan

Quote:

Originally Posted by chegdan (Post 282155)
Im not near a Linux computer right now...but try

Code:

runApplication transformPoints -scale (0.001 0.001 0.001)
instead of
Code:

runApplication transformPoints -scale "(0.001 0.001 0.001)"
to pass numbers like that in the script you don't need the "" in that case i believe.

Dan


val46 November 9, 2010 05:20

Hi Dan,

I tried what you suggested:
Code:

vector=(0.001 0.001 0.001)
runApplication transformPoints -scale $vector

But I got the following error message:
Code:

--> FOAM FATAL IO ERROR:
Expected a '(' while reading VectorSpace<Form, Cmpt, nCmpt>, found on line 0 the doubleScalar 0.001

file: IStringStream.sourceFile at line 0.

    From function Istream::readBegin(const char*)
    in file db/IOstreams/IOstreams/Istream.C at line 86.

Any ideas?

Regards,
Toni

mgd November 9, 2010 10:24

I believe the correct syntax is

Code:

transformPoints -scale '(0.001 0.001 0.001)'

i.e. you need a single quotes '....' to wrap the vector

val46 November 10, 2010 04:22

Quote:

Originally Posted by mgd (Post 282751)
I believe the correct syntax is

Code:

transformPoints -scale '(0.001 0.001 0.001)'
i.e. you need a single quotes '....' to wrap the vector

This is the correct command in a console but not in a script.


All times are GMT -4. The time now is 15:05.