|
[Sponsors] |
March 6, 2019, 15:03 |
Execution time
|
#1 |
New Member
Ximena
Join Date: Apr 2018
Posts: 6
Rep Power: 8 |
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 |
|
March 7, 2019, 12:23 |
|
#2 |
Senior Member
Join Date: Oct 2017
Posts: 133
Rep Power: 9 |
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 |
|
March 11, 2019, 10:01 |
|
#3 |
Member
Luis Eduardo
Join Date: Jan 2011
Posts: 85
Rep Power: 15 |
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() Luis |
|
March 11, 2019, 15:59 |
|
#4 |
Senior Member
Join Date: Mar 2014
Posts: 112
Rep Power: 12 |
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... |
|
April 4, 2019, 11:24 |
|
#5 |
New Member
Ximena
Join Date: Apr 2018
Posts: 6
Rep Power: 8 |
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 |
|
April 5, 2019, 17:31 |
|
#6 |
Member
Luis Eduardo
Join Date: Jan 2011
Posts: 85
Rep Power: 15 |
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 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 |
|
April 11, 2019, 10:11 |
|
#7 |
New Member
Ximena
Join Date: Apr 2018
Posts: 6
Rep Power: 8 |
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 |
|
April 12, 2019, 19:00 |
|
#8 |
Member
Luis Eduardo
Join Date: Jan 2011
Posts: 85
Rep Power: 15 |
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 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 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 |
|
August 13, 2023, 12:14 |
How can I tweak your python file to show result in minutes?
|
#9 |
Senior Member
Alan w
Join Date: Feb 2021
Posts: 288
Rep Power: 6 |
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? |
|
August 15, 2023, 12:21 |
|
#10 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 746
Rep Power: 14 |
... just divide through by 60!
Code:
get_time_file.write(str((current_time - initial_time)/60)) |
|
Tags |
executiontime, logrun |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
courant number increases to rather large values | 6863523 | OpenFOAM Running, Solving & CFD | 22 | July 6, 2023 00:48 |
Inconsistencies in reading .dat file during run time in new injection model | Scram_1 | OpenFOAM | 0 | March 23, 2018 23:29 |
Micro Scale Pore, icoFoam | gooya_kabir | OpenFOAM Running, Solving & CFD | 2 | November 2, 2013 14:58 |
plot over time | fferroni | OpenFOAM Post-Processing | 7 | June 8, 2012 08:56 |
calculation diverge after continue to run | zhajingjing | OpenFOAM | 0 | April 28, 2010 05:35 |