CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Execution time

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By lebc
  • 2 Post By mzzmrt
  • 1 Post By lebc

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 6, 2019, 14:03
Wink Execution time
  #1
New Member
 
Ximena
Join Date: Apr 2018
Posts: 6
Rep Power: 8
Ximena is on a distinguished road
Hello,

I'm new at openFoam. I could run a simulation and now I'm wondering how I could get the total time that the simulation took.
I open the generated logRun file and it says:

Build : 5.0
Exec : simpleFoam -parallel
Date : Mar 06 2019
Time : 14:37:33
Host : "stro045.vub.ac.be"
PID : 16906
I/O : uncollated
Case : /1234/OpenFOAM/ximena5.0/run/casedirectory3
nProcs : 16
Slaves : 15

Then i suppose that the time that the simpleFoam command took is Time:14:37:33. For me it does not look like real time (hr.min.sec.)
Is that the real time? if not, how can i convert that to real time (sec)?
and how could I get the complete time that my simulation took, I mean generating the blockMesh, snappyHexmexh, decompePar etc? (by the way, I run all the simulation separatelly not just running an Allrun script.

Regards
Ximena
Ximena is offline   Reply With Quote

Old   March 7, 2019, 11:23
Default
  #2
Senior Member
 
Join Date: Oct 2017
Posts: 121
Rep Power: 8
Krapf is on a distinguished road
Hi Ximena,

14:37:33 was the time of the day when simpleFoam started. Some commands print the execution time in its log file, you could add them.

Kind regards,
Krapf
Krapf is offline   Reply With Quote

Old   March 11, 2019, 09:01
Default
  #3
Member
 
Luis Eduardo
Join Date: Jan 2011
Posts: 85
Rep Power: 15
lebc is on a distinguished road
Hi Ximena,

I wrote this Python script to calculate the elapsed time between start and end of any process, you just have to run it before executing the commands and after executing the commands. I should be placed in the same folder as you are running the simulations.

Code:
import time
import os

## Check if the file elapsed_time exists.
## If it doesn't, it is the beginning of execution of the code;
## If it do, it is the end of execution, the elapsed time wil be calculated.

check_file = os.path.exists("elapsed_time")

if check_file == False:
    ## time in seconds since The Epoch, January 1st, 1970
    current_time = time.time()

    get_time_file = open('elapsed_time', 'w')
    get_time_file.write(str(current_time))
    get_time_file.close()

else:
    initial_time_file = open('elapsed_time', 'r')
    lines = initial_time_file.readlines() ## read file
    initial_time = lines[0].split()
    initial_time = float(initial_time[0])
    initial_time_file.close()

    current_time = time.time()
    
    get_time_file = open('elapsed_time', 'w')
    get_time_file.write(str(current_time - initial_time))
    get_time_file.close()
Best Regards,
Luis
Ximena likes this.
lebc is offline   Reply With Quote

Old   March 11, 2019, 14:59
Default
  #4
Senior Member
 
Join Date: Mar 2014
Posts: 112
Rep Power: 12
mzzmrt is on a distinguished road
You can also use the "time" tool in the terminal with any execution for blockMesh, simpleFoam etc. such as;



time simpleFoam


at the end of run the time data will be declared...
jenjo7873 and Ximena like this.
mzzmrt is offline   Reply With Quote

Old   April 4, 2019, 10:24
Default
  #5
New Member
 
Ximena
Join Date: Apr 2018
Posts: 6
Rep Power: 8
Ximena is on a distinguished road
Dear lebc,
Thanks a lot for your reply, I tried to implement your Python script by by adding that in the case directory and executing the command importtime and other variations, unfortunately I did not get any results. What is the right way to make it works?

Regards
Ximena

____________


Dear mzzmrt,
thanks for your reply, it was really useful.
I got the time at the end of the execution as is shown hereunder, by executing the command:
mpirun -np 8 time snappyHexMesh -overwrite -parallel >logMsh &
I just have two more questions, the time the execution time took is 18.31 minutes, didn't it?, it is possible to record thats information into the logFile? because that info was available just on my terminal window.

End
Finalising parallel run
428.14user 626.69system 18:31.63elapsed 94%CPU (0avgtext+0avgdata 352268maxresident)k
0inputs+167672outputs (6major+922154minor)pagefaults 0swaps
419.01user 653.49system 18:31.64elapsed 96%CPU (0avgtext+0avgdata 344700maxresident)k
0inputs+165800outputs (2major+991625minor)pagefaults 0swaps
428.49user 637.03system 18:31.62elapsed 95%CPU (0avgtext+0avgdata 332980maxresident)k
0inputs+167240outputs (6major+938355minor)pagefaults 0swaps.......

Regards
Ximena
Ximena is offline   Reply With Quote

Old   April 5, 2019, 16:31
Default
  #6
Member
 
Luis Eduardo
Join Date: Jan 2011
Posts: 85
Rep Power: 15
lebc is on a distinguished road
You have to save the code I sent you in a .py file and run it before and after your simulation.

Let say that you have an Allrun script that runs everything. This Allrun file would look like something like this:

Code:
python elapsed_time.py

"everything you want to run in OpenFOAM"

python elapsed_time.py
After that, you would have this Allrun file, the .py file and you OpenFOAM case in the same folder, and you just have to open the terminal and put ./Allrun. Make sure you have the permission to run this file.

If you have troubles running it, send me the commands you have to run and I can help you with this Allrun file, I use it all the time!

Best Regards,
Luis
Ximena likes this.
lebc is offline   Reply With Quote

Old   April 11, 2019, 09:11
Default
  #7
New Member
 
Ximena
Join Date: Apr 2018
Posts: 6
Rep Power: 8
Ximena is on a distinguished road
Dear lebc,

I really apreciate your help. I was trying to create Allrun file, but it looks more complicated in parallel (since my case is a little too much for my computer, I run it remotely and in parallel) and those are the commands I run:

1. blockMesh
2. decomposePar
3. mpirun -np 32 time snappyHexMesh -overwrite -parallel >logMesh &
4. tail -f logMesh (to visualise when it is finished)
5. reconstructParMesh -constant
6. cp -r 0.boundaryConditions/* 0/
7. rm -r processor*
8. decomposePar -latestTime
9. mpirun -np 32 time simpleFoam -parallel >logRun &
10. tail -f logRun (to visualise when it is finished)
11. reconstructPar -latestTime
12. checkMesh >logCheck & (to visualise the number of cells)

by the way, I create the python "elapsed_time.py" file just by adding the extension .py to the textedit file and coping that to the remote computer, is that right?
Thanks again for you help
Ximena is offline   Reply With Quote

Old   April 12, 2019, 18:00
Default
  #8
Member
 
Luis Eduardo
Join Date: Jan 2011
Posts: 85
Rep Power: 15
lebc is on a distinguished road
Hi Ximena,

So your Allrun file using the commands you sent should look like this:

Code:
#!/bin/sh
cd ${0%/*} || exit 1    # Run from this directory

python elapsed_time.py

blockMesh 
decomposePar
mpirun -np 32 time snappyHexMesh -overwrite -parallel >logMesh &
tail -f logMesh
reconstructParMesh -constant
cp -r 0.boundaryConditions/* 0/
rm -r processor*
decomposePar -latestTime
mpirun -np 32 time simpleFoam -parallel >logRun &
tail -f logRun
reconstructPar -latestTime
checkMesh >logCheck &

python elapsed_time.py
What you can try, to have a cleaner file, is:


Code:
#!/bin/sh
cd ${0%/*} || exit 1    # Run from this directory

python elapsed_time.py

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

runApplication blockMesh 
runApplication decomposePar
mpirun -np 32 snappyHexMesh -parallel -overwrite < /dev/null > log.snappyHexMesh 2>&1

find . -type f -iname "*level*" -exec rm {} \;
ls -d processor* | xargs -I {} 0.boundaryConditions/* ./{}/0 $1

mpirun -np 32 simpleFoam -parallel < /dev/null > log.mysimpleFoam 2>&1

runApplication reconstructParMesh -constant
runApplication reconstructPar -latestTime

runApplication checkMesh


python elapsed_time.py
You don't need to reconstruct your case after generating the mesh and decompose it again, if you only need to copy the boundary conditions to the processors folder you can use a command for it.

I haven't tested the script, so maybe you will need to adjust one or two commands...

All the logs should be saved in files, so you can check them whenever you want.

Best Regards,
Luis
lebc is offline   Reply With Quote

Old   August 13, 2023, 11:14
Default How can I tweak your python file to show result in minutes?
  #9
Senior Member
 
Alan w
Join Date: Feb 2021
Posts: 264
Rep Power: 6
boffin5 is on a distinguished road
Thanks lebc,

I got your python file to work, for showing the elapsed time for running a simulation. However, the file it creates shows the ET in seconds, and for a
long run time, this can be a large number. In that event, it would be more
meaningful for me to see the result in terms of minutes.
Can you show how your python file could be edited to do this?
boffin5 is offline   Reply With Quote

Old   August 15, 2023, 11:21
Default
  #10
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 670
Rep Power: 14
Tobermory will become famous soon enough
... just divide through by 60!

Code:
get_time_file.write(str((current_time - initial_time)/60))
If you wanted to be fancy, use some conditional statements to check if the time is greater than 100, and if so, divide by 60 to convert to mins. Be sure to add units, so you can keep track of what the number means.
Tobermory is offline   Reply With Quote

Reply

Tags
executiontime, logrun


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
courant number increases to rather large values 6863523 OpenFOAM Running, Solving & CFD 22 July 5, 2023 23:48
Inconsistencies in reading .dat file during run time in new injection model Scram_1 OpenFOAM 0 March 23, 2018 22:29
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 13:58
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 07:56
calculation diverge after continue to run zhajingjing OpenFOAM 0 April 28, 2010 04:35


All times are GMT -4. The time now is 18:21.