|
[Sponsors] |
April 6, 2020, 15:57 |
Debugging OpenFOAMŪ with Visual Studio Code
|
#1 |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Hello All
I have created a guide which will help in setting up Visual Studio Code for OpenFOAM debugging and development. https://github.com/Rvadrabade/Debugg...al-studio-code Suggestions are welcome. Thank you. Rahul Vadrabade |
|
August 17, 2020, 03:26 |
|
#3 |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Yes, I am aware about it. Great work. However, I did not get time to use extension. I will try and surely give you feedback. Looking forward for next update and features.
|
|
April 30, 2021, 00:25 |
|
#4 |
New Member
FOAMraj
Join Date: Apr 2021
Posts: 19
Rep Power: 5 |
Dear Rvadrabade,
I have encountered some errors regarding the fourth step. Here is the image: https://imgur.com/EUc0s51 I have done the third step and I did pretty well. Thank you |
|
April 30, 2021, 01:00 |
|
#5 |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Hi Biraj,
It is not error as such. In general, to debug any executable you have to build the source code with debug flags. Openfoam default ships the optimised code for faster response ( WM_COMPILE_OPTION=Opt) not debug build. So, we have to build the source code with debug flags which is automatically set with WM_COMPILE_OPTION=Debug (step 3) and just execute ./Allwmake from main directory (Note that compilation might take several hours depending on your hardware). Now, all the built solvers have debug symbols which will help to debug executable. I hope this helps you. Thanks |
|
April 30, 2021, 03:17 |
|
#6 |
New Member
FOAMraj
Join Date: Apr 2021
Posts: 19
Rep Power: 5 |
Dear Rvadrabade,
I have already done step3 as you have mentioned. Here is the proof: https://imgur.com/YwlmiFh After this step, the procedure is hard for me to understand. I tried to run Allwmake and got this error. biraj@DESKTOP-3PJCARR:~/OpenFOAM/OpenFOAM-v2006$ ./AllwmakePS: The fourth step is unclear for me. What does that mean? How can I append? Thank you |
|
April 30, 2021, 10:27 |
|
#7 |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Try following commands
sudo apt-get update sudo apt-get install build-essential flex bison cmake zlib1g-dev libboost-system-dev libboost-thread-dev libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev sudo apt-get install qt4-dev-tools libqt4-dev libqt4-opengl-dev freeglut3-dev libqtwebkit-dev sudo apt install make |
|
May 15, 2021, 21:18 |
|
#8 |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
Hi,
Is it possible to debug code that is running in parallel? |
|
May 16, 2021, 00:58 |
Debugging OpenFoam I parallel..
|
#9 |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Hi,
Well, quick answer is NO for a built-in solver with vscode. However, workaround is to modify solver to add sufficient pause so that all the thread can be attached to vscode seperately(like .https://openfoamwiki.net/index.php/H...dditional_Info). But if the number of processors increases it make difficult to do this way. Further, non vscode workaround is to use the mpirunDebug script (https://openfoamwiki.net/index.php/H...ng#mpirunDebug). Also, let the community know if you found better way to debug Openfoam in parallel. |
|
May 16, 2021, 15:46 |
|
#10 |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
Hi again,
So, this is based on several contributions and some peer review of the procedure would be highly appreciated. If you have suggestions to make the procedure better, feel free to do so. Procedure: 1š -> Check this video: https://www.youtube.com/watch?v=lTt02xuD51w 2š -> Here are my .vscode files with some modifications c_cpp_properties.json Code:
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "${FOAM_SRC}" ], "defines": [], "compilerPath": "mpic++", "cStandard": "c11", "cppStandard": "c++11", "intelliSenseMode": "gcc-x64" } ], "version": 4 } Code:
{ "version": "0.2.0", "configurations": [ { "name": "OF-Debug", "type": "cppdbg", "request": "attach", "processId": "${command:pickProcess}", "program": "${env:FOAM_USER_APPBIN}/${fileBasenameNoExtension}", "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "wmake-build", "miDebuggerPath": "/usr/bin/gdb" } ] } Code:
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "wmake-build", "command": "wmake", "problemMatcher": [ "$gcc" ], "group": "build" }, { "type": "cppbuild", "label": "C/C++: cpp build active file", "command": "/usr/bin/cpp", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "/usr/bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "compiler: /usr/bin/cpp" } ] } Code:
int myi = 0; while (0 == myi) Foam::sleep(5); Code:
wmake mySolverFoam Code:
decomposePar && mpirun -np 2 mySolverFoam -parallel 7š -> On your first vsCode window, open your mySolverFoam.C file and go to the Run and Debug tab (control + shift + D). On the top left corner click on Start Debugging (green play button). 8š -> After clicking on Start Debugging, look for your solver name, in this case mySolverFoam. Two processes will appear. Choose one for your first vsCode window. It will ask you if you want to attach the debugger to the process. Type y. 9š -> Perform steps 7 and 8 and choose the second process for the second window. 10 -> Now you are inside the solver. In your first window, press the Pause (F6) button in the debugger. An error message will appear, just press Step Out (Shift + F11) 2 or 3 times and you will be located in your infinite loop. 11š -> Now, you will need to leave the infinite loop. For that, change the value of the variable myi to 1 on the variables -> locals bar (located on the left side of the Run and Debug tab. After changing the value, press on Step Over (F10). You should be outside of you infinite loop. 12š -> Perform steps 10 and 11 on your second vsCode window. You can proceed with your normal debugging activities, but now in parallel. Best Regards, |
|
May 17, 2021, 11:12 |
Debugging OpenFoam In parallel with vscode
|
#11 |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Hi,
Fantastic work. Thanks for putting the efforts to list down all the steps needed to setup vscode environment which will help to debug Openfoam in parallel. These steps surely help community members a lot. However, please note that, invest your time and efforts carefully while debugging OpenFoam in parallel unless you have good reason to do it or doing any research related to HPC. Even though Openfoam is very simple looking code for users,but the underlying implementation is considerably complex specially for parallel architecture. |
|
July 15, 2021, 05:31 |
Error while setting up
|
#12 |
New Member
Gaurav Gokhale
Join Date: Dec 2016
Posts: 1
Rep Power: 0 |
Hello,
I am getting an error "The term 'wmake' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." I followed the steps as mentioned in the guide. Can anyone suggest how to solve it? Edit (SOLVED): I was just trying to step through the simpleFoam solver in vscode. The issue disappeared when I activated the openfoam-debug alias which I had set in bashrc and then opened vscode using "code ." Thanks, Gaurav Gokhale Last edited by gauravgokhale; July 15, 2021 at 14:00. |
|
January 14, 2022, 11:56 |
|
#13 |
New Member
Join Date: Dec 2021
Posts: 23
Rep Power: 4 |
Hello to all,
Shouldn't this be posted into the OpenFOAM wiki? The configuration files are quite useful! |
|
January 14, 2022, 23:26 |
Openfoam wiki
|
#14 | |
Member
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8 |
Quote:
In case you know how can I submit this work then guide me. I will surely take it forward. Thank you, Rahulv |
||
January 15, 2022, 12:12 |
|
#15 | |
New Member
Join Date: Dec 2021
Posts: 23
Rep Power: 4 |
Quote:
Hi, I guess through here https://openfoamwiki.net/index.php/User:Bgschaid. The pages that opens when you click on contacts. To me, your github page was more than enough to get me started: https://github.com/Rvadrabade/Debugg...al-Studio-Code. I would just change line 12 of c_cpp_properties to be c++11 (OF standard) and possibly line 7 to include ""${FOAM_SRC}/**" Additionally, since this will use vscode as a GUI we can use gbd command (data watchpoints) which is also quite useful! |
||
February 3, 2022, 05:51 |
debugging
|
#16 |
Member
Join Date: Nov 2012
Posts: 83
Rep Power: 14 |
A great option to switch between opt and debug branch is to define aliases
Code:
alias of2106='source $HOME/OpenFOAM/OpenFOAM-v2106/etc/bashrc' alias of2106_debug='source $HOME/OpenFOAM/OpenFOAM-v2106/etc/bashrc_debug' export WM_COMPILE_OPTION=Opt to export WM_COMPILE_OPTION=Debug |
|
February 4, 2022, 09:57 |
|
#17 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
Often times for debugging you want to enable FULLDEBUG and perhaps some symbols etc, but don't really want to recompile everything. This is where the '-debug' option comes in handy. For example, Code:
wmake -debug some/source.C This is not only very convenient when debugging a single library or bunch of files, but can also have the advantage keeping the current compiler optimization level (eg, -02, -03). In some low-level code some problems/inconsistencies are not visible with the -O0 level. |
||
September 27, 2022, 01:19 |
How to debug library in OpenFOAM
|
#18 |
New Member
Lei Zhou
Join Date: Nov 2021
Posts: 6
Rep Power: 5 |
Hello, foamers:
I created a new library. And I already used this method to debug the new solver, which linked both the default openfoam library and my new library. When debugging, it could step into the default openfoam by the methods, however, it cannot step into my own new library. What should I do? Thanks in advance. |
|
October 13, 2022, 02:11 |
|
#19 |
New Member
venu
Join Date: May 2019
Posts: 8
Rep Power: 7 |
Hi @zhoulei_3c
I don't have a direct method to step into the custom library. However, you can open your code file in vs code and place a breakpoint somewhere. By doing this vs code will reach a breakpoint and you can debug your code from there. |
|
January 7, 2023, 23:22 |
|
#20 | |
Member
WY
Join Date: Mar 2020
Posts: 36
Rep Power: 6 |
Quote:
I met the same problem with you. I develop a new library based on OpenFOAM 5.X, and if I understand correctly, if I want to use VS code to debug it (proposed by Rvadrabade), I first need to compile OF5 in debugging mode? Or have you found any other more convenient way to debug the new library? Thanks! |
||
Tags |
debugging, vscode |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
The udf.h headers are unable to open- in VISUAL STUDIO 13 | sanjeetlimbu | Fluent UDF and Scheme Programming | 4 | May 2, 2016 06:38 |
freelancer/pay:Coding solidworks flow simulation API using microsoft visual studio | Edreez | CFD Freelancers | 1 | December 8, 2015 12:18 |
Compiling Fluent UDF with Visual Studio | kamnaz | Fluent UDF and Scheme Programming | 0 | August 28, 2014 13:58 |
Error with visual studio installation | akshaymanikjade | FLUENT | 1 | January 31, 2013 00:30 |
error while compiling a udf | rahul | FLUENT | 10 | August 30, 2006 09:33 |