Can't make MSMPI to work. It always says "mpi.h: No such file or directory gcc"

101 Views Asked by At

So I've tried multiple times to make MSMPI to work, however it still says that it can't find mpi.h

I've added to Include Path for C\C++ Extension in VS Code ${MSMPI_INC} and configured tasks.json, as people said (added "-I", "${MSMPI_INC}", "-L","${MSMPI_LIB64}", "-lmsmpi") but it still says that there is no mpi.h Seen similar topic, but they all were about mpi for linux, but no one posted answer for MSMPI It all works in CLion, but the free trial ends soon, so I decided to move to VS Code Thanks in advance

UPD: Here's a JSON file

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:/MinGW/bin/gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-I",
            "C:/Program Files (x86)/Microsoft SDKs/MPI/Include/",
            "-L",
            "C:/Program Files (x86)/Microsoft SDKs/MPI/Lib/x64/",
            "-lmsmpi",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "C:/MinGW/bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:/MinGW/bin/gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "C:/MinGW/bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "compiler: C:/MinGW/bin/gcc.exe"
    },
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:/MinGW/bin/gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "C:/MinGW/bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: C:/MinGW/bin/gcc.exe"
    }
],
"version": "2.0.0"
}

And a build log:

C:/MinGW/bin/gcc.exe -fdiagnostics-color=always -g D:\Coding\ParallelProgramming\Test\main.c -o D:\Coding\ParallelProgramming\Test\main.exe
D:\Coding\ParallelProgramming\Test\main.c:5:17: fatal error: mpi.h: No such file or directory
#include <mpi.h>
             ^
compilation terminated.

Build finished with error(s).

UPD2: Changed JSON to

{
"version": "2.0.0",
"tasks": [
    {
        "label": "build with MSMPI",
        "type": "shell",
        "command": "mpiexec",
        "args": [
            "-n",
            "1",
            "gcc",
            "${file}",
            "-I C:/Program Files (x86)/Microsoft SDKs/MPI/Include/",
            "-L C:/Program Files (x86)/Microsoft SDKs/MPI/Lib/x64/",
            "-lmsmpi",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "presentation": {
            "reveal": "silent"
        },
        "problemMatcher": "$gcc"
    }
]
}

It didn't help

1

There are 1 best solutions below

2
ADITYA On BEST ANSWER

I guess, there is some problem in your JSON file task.json adjust the file to properly include the MPI headers and libraries, try this

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build with MSMPI",
            "type": "shell",
            "command": "mpiexec",
            "args": [
                "-n",
                "1",
                "gcc",
                "${file}",
                "-I${MSMPI_INC}",
                "-L${MSMPI_LIB64}",
                "-lmsmpi",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$gcc"
        }
    ]
}

replace ${MSMPI_INC} and ${MSMPI_LIB64} with the correct paths to the MPI include directory and library directory respectively.

edit:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build with MSMPI",
            "type": "shell",
            "command": "mpiexec",
            "args": [
                "-n",
                "1",
                "gcc",
                "${file}",
                "-I",
                "C:/Program Files (x86)/Microsoft SDKs/MPI/Include",
                "-L",
                "C:/Program Files (x86)/Microsoft SDKs/MPI/Lib/x64",
                "-lmsmpi",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$gcc"
        }
    ]
}