Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2158 Discussions

Setting up Visual Studio for C++ MPI in WSL2

flgilbert
Beginner
4,945 Views

I know Intel does not support OneAPI on Windows Subsystem for Linux, but I almost managed to setup Visual Studio 2022 to develop with MPI. The only remaining thing is the debugging, which should work but I get a segmentation error on MPI::Init()

Here's the recipe so far:

1) setup Visual Studio for WSL2 as instructed by Microsoft https://docs.microsoft.com/en-us/cpp/linux/download-install-and-setup-the-linux-development-workload

2) Install OneAPI base and HPC toolkits on the WSL instance (mine uses Ubuntu 20.04LTS)

3) setup a CMAKE project in visual studio
4) In CMakeLists.txt, add the MPI directives:
find_package(MPI REQUIRED)
target_link_libraries(myTestProgram MPI::MPI_CXX)


5) in CMakePresets.json, modify the "Linux Debug" preset by adding the following settings:
"environment": {
"PATH": "$penv{PATH}:/opt/intel/oneapi/compiler/latest/linux/bin/intel64/:/opt/intel/oneapi/mpi/latest/bin/",
"I_MPI_ROOT": "/opt/intel/oneapi/mpi/latest"
}
And replacing the cacheVariables with this:

"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_C_COMPILER": "icc", // Optional: use the Intel compiler.
"CMAKE_CXX_COMPILER": "icpc" //Optional: use the Intel compiler.
}

With these steps, Visual Studio compiles the example test.cpp without errors and Intellisense "sees" the MPI header file.

When I use the WSL2 shell to run the resulting executable, I get no errors and it works as expected. I also can use gdb on it this way without problem.

The problem comes when I try to start the debugging session in Visual Studio: I systematically get a Segmentation fault on the MPI::Init line.

Did anybody make this work? What did I miss?

Labels (2)
0 Kudos
11 Replies
VarshaS_Intel
Moderator
4,864 Views

Hi,


Thanks for reaching out to us.


Could you please let us know the Intel oneAPI and MPI versions you are using?


Could you please provide us with the complete CMAKE File, complete sample reproducer(test.cpp mentioned in the post) along with the steps and commands to reproduce the issue at our end? 


And also, could you please provide us with the screenshot of the error you are facing?


Thanks & Regards,

Varsha



0 Kudos
flgilbert
Beginner
4,838 Views

Hi,

The versions of software installed on Ubuntu are the following:

  • mpiexec --version replies Intel(R) MPI Library for Linux* OS, Version 2021.5 Build 20211102 (id: 9279b7d62)
  • icpc (ICC) 2021.5.0 20211109
  • icpc (ICC) 2021.5.0 20211109
  • GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2

 

 

 

0 Kudos
flgilbert
Beginner
4,762 Views

I am still working on this, and now I can launch the MPI program without problem.

I believe the problem was using the basic gdb instead of the gdb distributed with OneAPI.

To make Visual Studio use gdb-oneapi, I added a debug configuration to my project.  Visual Studio keeps these in launch.vs.json.  The new configuration sources setvars.sh, then starts the OneAPI debugger.  The SEGFAULT is no more, and I can do all the normal debugging actions (single-stepping, inspecting vars, etc.)

Here is the configuration:

{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "cppgdb",
"name": "testMPI",
"project": "CMakeLists.txt",
"projectTarget": "testMPI",
"debuggerConfiguration": "gdb",
"gdbPath": "/opt/intel/oneapi/debugger/latest/gdb/intel64/bin/gdb-oneapi",
"preDebugCommand": "source /opt/intel/oneapi/setvars.sh",
"args": [],
"env": {}
}
]
}

 

The last thing that is still missing is starting the program with mpiexec and setting the number of processors and threads.

0 Kudos
flgilbert
Beginner
4,733 Views

The other option is launching the program with mpiexec, but then Visual Studio can't seem to set the breakpoints.

 

{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "cppgdb",
"name": "testMPI",
"project": "CMakeLists.txt",
"projectTarget": "testMPI",
"debuggerConfiguration": "gdb",
"gdbPath": "/opt/intel/oneapi/debugger/latest/gdb/intel64/bin/gdb-oneapi",
"preDebugCommand": "source /opt/intel/oneapi/setvars.sh",
"program": "mpiexec",
"args": [ "-n", "3", "${debugInfo.fullTargetPath}" ], //Launches 3 threads. VS can't debug with this :(
"env": {}
}
]
}
0 Kudos
VarshaS_Intel
Moderator
4,700 Views

Hi,

 

Thanks for providing the information.

 

Could you please let us know the detailed steps that you have followed to set up WSL2 with Intel oneAPI, Ubuntu, and Visual Studio?

 

>> The SEGFAULT is no more, and I can do all the normal debugging actions(single-stepping, inspecting vars, etc.)

Glad to know that one of your issues is resolved. Could you please confirm if it works with the -n(number of processes) is 1?

 

>>//Launches 3 threads. VS can't debug with this

Could you please elaborate on the above statement?

 

Could you please provide us with a screenshot of the error you are facing?

 

Thanks & Regards,

Varsha

 

0 Kudos
flgilbert
Beginner
4,678 Views

I'll start with the questions, which are quick.

 

>> The SEGFAULT is no more, and I can do all the normal debugging actions(single-stepping, inspecting vars, etc.)

> Glad to know that one of your issues is resolved. Could you please confirm if it works with the -n(number of processes) is 1?

I just checked, and it works even with -n 1.  

 

>>//Launches 3 threads. VS can't debug with this

This is the last remaining hole in this setup:  if I use mpiexec, the Visual Studio debugger does not seem to be able to attach to the process:  any breakpoints I set are never triggered.  I tried adding the "-gdb" option to the arguments of mpiexec, but I get a weird output in the console;  you will find a screenshot with this message.

 

As for the setup instructions, I do not remember doing anything more than outlined in my first post.  I do see I have skipped one detail in my first post:  in step (2), I used the apt package manager inside the WSL console, following the instructions outlined here:  https://www.intel.com/content/www/us/en/develop/documentation/installation-guide-for-intel-oneapi-toolkits-linux/top/installation/install-using-package-managers/apt.html

0 Kudos
VarshaS_Intel
Moderator
4,550 Views

Hi,


>>but then Visual Studio can't seem to set the breakpoints.

We are able to reproduce it. We are in discussion with the development team and will get back to you soon.


Thanks & Regards,

Varsha


0 Kudos
VarshaS_Intel
Moderator
4,471 Views

Hi,


We are working on your issue and will get back to you soon.


Thanks & Regards,

Varsha


0 Kudos
VarshaS_Intel
Moderator
4,347 Views

Hi,

 

We are able to get the expected results using the gdb-oneapi debugger with breakpoints in WSL2(Ubuntu 20.04 LTS). Please find the below screenshot while running the Sample Hello World MPI code:

mpiGDB.png

Hence, the error seems to be with Visual Studio IDE and not with Intel oneAPI gdb- debugger & this forum is intended to support the queries related to Intel OneAPI. Please let us know if we can go ahead and close this thread.

 

Thanks & Regards,

Varsha

 

0 Kudos
flgilbert
Beginner
4,340 Views

Do you at least plan to integrate this function in the Visual Studio integration for OneAPI?

0 Kudos
VarshaS_Intel
Moderator
4,096 Views

Hi,

 

>>Do you at least plan to integrate this function

We have reported this issue to the concerned development team. They are looking into your issue.

 

Thanks & Regards,

Varsha

 

0 Kudos
Reply